-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
How to save scripted models? #349
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Same happened to me, got the second error when trying to convert to torchscript. I think the issue isn't solved since you got a workaround and not a real solution hence it should be opened again. |
Yeah, I've just hit a case where the workaround doesn't work (Unet-efficientnet-b0, saving works, loading doesn't). |
I am facing the same issue. @maxfreu have you solved this by now? |
Have you check scripting with timm encoders? |
torch version 1.8.1, smp version 0.2.0 torch.jit.script(smp.Unet("tu-efficientnet_b0"))
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/max/programs/anaconda3/envs/dr2/lib/python3.8/site-packages/torch/jit/_script.py", line 942, in script
return torch.jit._recursive.create_script_module(
File "/home/max/programs/anaconda3/envs/dr2/lib/python3.8/site-packages/torch/jit/_recursive.py", line 391, in create_script_module
return create_script_module_impl(nn_module, concrete_type, stubs_fn)
File "/home/max/programs/anaconda3/envs/dr2/lib/python3.8/site-packages/torch/jit/_recursive.py", line 448, in create_script_module_impl
script_module = torch.jit.RecursiveScriptModule._construct(cpp_module, init_fn)
File "/home/max/programs/anaconda3/envs/dr2/lib/python3.8/site-packages/torch/jit/_script.py", line 391, in _construct
init_fn(script_module)
File "/home/max/programs/anaconda3/envs/dr2/lib/python3.8/site-packages/torch/jit/_recursive.py", line 428, in init_fn
scripted = create_script_module_impl(orig_value, sub_concrete_type, stubs_fn)
File "/home/max/programs/anaconda3/envs/dr2/lib/python3.8/site-packages/torch/jit/_recursive.py", line 403, in create_script_module_impl
method_stubs = stubs_fn(nn_module)
File "/home/max/programs/anaconda3/envs/dr2/lib/python3.8/site-packages/torch/jit/_recursive.py", line 651, in infer_methods_to_compile
stubs.append(make_stub_from_method(nn_module, method))
File "/home/max/programs/anaconda3/envs/dr2/lib/python3.8/site-packages/torch/jit/_recursive.py", line 52, in make_stub_from_method
return make_stub(func, method_name)
File "/home/max/programs/anaconda3/envs/dr2/lib/python3.8/site-packages/torch/jit/_recursive.py", line 37, in make_stub
ast = get_jit_def(func, name, self_name="RecursiveScriptModule")
File "/home/max/programs/anaconda3/envs/dr2/lib/python3.8/site-packages/torch/jit/frontend.py", line 271, in get_jit_def
return build_def(ctx, fn_def, type_line, def_name, self_name=self_name)
File "/home/max/programs/anaconda3/envs/dr2/lib/python3.8/site-packages/torch/jit/frontend.py", line 293, in build_def
param_list = build_param_list(ctx, py_def.args, self_name)
File "/home/max/programs/anaconda3/envs/dr2/lib/python3.8/site-packages/torch/jit/frontend.py", line 320, in build_param_list
raise NotSupportedError(ctx_range, _vararg_kwarg_err)
torch.jit.frontend.NotSupportedError: Compiled functions can't take variable number of arguments or use keyword-only arguments with defaults:
File "/home/max/programs/anaconda3/envs/dr2/lib/python3.8/site-packages/segmentation_models_pytorch/unet/decoder.py", line 108
def forward(self, *features):
~~~~~~~~~ <--- HERE
features = features[1:] # remove first skip with same spatial resolution I think the error message is quite clear here: "NotSupportedError: Compiled functions can't take variable number of arguments or use keyword-only arguments with defaults". So forward should maybe take a list or tuple as input instead of *features. |
This issue is stale because it has been open 60 days with no activity. Remove stale label or comment or this will be closed in 7 days. |
I have the same issue in torch==1.10.2. I'd appreciate to have the scripting logic fixed |
This issue is stale because it has been open 60 days with no activity. Remove stale label or comment or this will be closed in 7 days. |
This issue was closed because it has been stalled for 7 days with no activity. |
I don't think this issue is resolved, right? It would be good for the models in this repository to be 'scriptable'. The models from @qubvel is this something you would accept help on? |
No solution here? |
#755 has a solution |
Hi, I'm trying to script and save the models, but get different errors depending on arch and encoder. Example:
results in:
Click me
smp version 0.1.3
pytorch version 1.6.0
pytorch 1.7 fails like this:
Click me
EDIT: Working with
torch.jit.trace(...)
works as a replacement to circumvent loading the code before loading the weights - therefore closing.The text was updated successfully, but these errors were encountered: