You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
### My model with dynamic input dimensions doesn't work. Why?
82
82
83
-
Currently, tract requires fully determined input dimensions to optimize a model. There are two options:
83
+
Currently, tract requires has some restrictions on dynamic dimensions. If your model has a dynamic dimension, there's multiple solutions:
84
84
85
-
1.Turn `optimize` off:
85
+
1.Declare a dynamic dimension via an input fact. Input facts are a way to provide additional information about input type and shape that can not be inferred via the model data:
This will however _significantly_ impact performance.
95
+
This dimension must then be made concrete on prediction:
96
+
97
+
```js
98
+
model.predict(input, {
99
+
"s":3// or some other value
100
+
})
101
+
```
102
+
103
+
The API supports multiple dynamic dimensions, but currently it will probably only work with one.
94
104
95
-
2. Set fixed input dimensions via input facts. Input facts are a way to provide additional information about input type and shape that can not be inferred via the model data:
105
+
2. Set fixed input dimensions via input facts. This is of course not ideal because subsequently the model can only be passed inputs with this exact shape:
@@ -104,13 +114,17 @@ const model = await tractjs.load("path/to/your/model", {
104
114
});
105
115
```
106
116
107
-
Be aware that the model will only work properly with inputs of this exact shape though.
117
+
3. Turn `optimize` off. This is the nuclear option. It will turn off all optimizations relying on information about input shape. This will make sure your model work (even with multiple dynamic dimensions) but _significantly_ impact performance:
108
118
109
-
There is ongoing work in tract to allow dynamically sized inputs.
At the time of writing, tractjs is very large for web standards (8.5MB raw, 2.5MB gzipped). This is due to tract being quite large, and due to some overhead from inlining the WASM. But it's not as bad as it sounds. You can load tractjs lazily along your demo, where you will likely have to load significantly large weights too.
127
+
At the time of writing, tractjs is very large for web standards (6.2MB raw, 2.1MB gzipped). This is due to tract being quite large, and due to some overhead from inlining the WASM. But it's not as bad as it sounds. You can load tractjs lazily along your demo, where you will likely have to load significantly large weights too.
114
128
115
129
If you are working on a very size-sensitive application, get in touch and we can work on decreasing the size. There are some more optimizations to be done (e. g. an option not to inline WASM, and removing panics from the build). There is also ongoing work in tract to decrease size.
0 commit comments