-
I created a model using Pytorch, saved it with model.eval()
with torch.no_grad():
torch.onnx.export(
model,
torch.randn(input_shape),
path,
verbose=False,
input_names=["planes"],
output_names=["value", "policy"],
) Rust code loading and running the model: type OnnxModel = TypedRunnableModel<TypedModel>;
fn load_model(model_path: &str) -> TractResult<OnnxModel> {
tract_onnx::onnx()
.model_for_path(model_path)?
.into_optimized()?
.into_runnable()
}
let model = load_model(model_path).unwrap();
let input: Array4<f32> = ...;
let input: Tensor = input.into();
let outputs_res = self.model.run(tvec!(input.into()));
let outputs = outputs_res.unwrap(); // error occurred here The error: called `Result::unwrap()` on an `Err` value: Clashing resolution for expression. 1=1 != 8. What does the error mean? How can I fix it? I think the error should be more informative in any case. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
Hello, thanks for tour interest in tract. In this case, it looks like tract can not make sense of the dimensions of tensor appearing in the network. It may be a tract bug, or something wrong with the model encoding. tract may be more picky than other frameworks with shape determination. To get more details, you can try to dump the Debug form ("{:?}") of the error instead of just using unwrap: see https://github.com/sonos/tract/blob/main/cli/src/main.rs#L291 . it should give you some information about the context at least. |
Beta Was this translation helpful? Give feedback.
There is something I dont get with the error formatting here. Tract error uses anyhow, so the contexts usually stack and are displayed in the Debug form. Unless this is a case where there is just no context specificied in the code, but it will be difficult to find from here without the model.
You need to use ONNX "dynamic axes" to export your model with a flexible batch size. In some cases, you can also "fix" this inside tract after loading the model, before calling into_optimized().