ResNeSt icon indicating copy to clipboard operation
ResNeSt copied to clipboard

Unable to export resnest model to torch script

Open lessw2020 opened this issue 4 years ago • 3 comments

Very impressed with the ResNest accuracy and want to move a model to production. However, in trying to script it, I hit the following issue:

`~\anaconda3\envs\fastai2\lib\site-packages\torch\jit_recursive.py in create_script_module_impl(nn_module, concrete_type, stubs_fn) 359 # Compile methods if necessary 360 if concrete_type not in concrete_type_store.methods_compiled: --> 361 create_methods_from_stubs(concrete_type, stubs) 362 torch._C._run_emit_module_hook(cpp_module) 363 concrete_type_store.methods_compiled.add(concrete_type)

~\anaconda3\envs\fastai2\lib\site-packages\torch\jit_recursive.py in create_methods_from_stubs(concrete_type, stubs) 277 rcbs = [m.resolution_callback for m in stubs] 278 defaults = [get_default_args(m.original_method) for m in stubs] --> 279 concrete_type._create_methods(defs, rcbs, defaults) 280 281 def create_script_module(nn_module, stubs_fn, share_types=True):

RuntimeError: Can't redefine method: forward on class: torch.resnest.torch.splat.SplAtConv2d

`

Is there any input on how to export to script so we can use in production?
Thanks very much!

lessw2020 avatar May 21 '20 20:05 lessw2020

Sorry that I am not familiar with torch script.

zhanghang1989 avatar May 21 '20 21:05 zhanghang1989

Thanks @zhanghang1989 - I'm going to run it in eager mode for now and may see if I can take a crack at the jit aspect next week. Congrats btw on the resnest model. I'm super impressed with the results from it!

lessw2020 avatar May 22 '20 01:05 lessw2020

Hi @zhanghang1989 - good news in that @rwightman was able to make the fix to support JIT fix with ResNeST, and I've been able to export as JIT and run live on our server.

Here's the link to his version of your ResNest with JIT fix: https://github.com/rwightman/pytorch-image-models/blob/master/timm/models/resnest.py

I think the fix is adding a dummy self.bn2 in the split attention conv2d to keep JIT happy but you'll be better able to determine looking at the code or checking with Ross directly.

Anyway, thanks again for making ResNeST - it's accuracy is the best of the models I've tested in my work!

lessw2020 avatar May 30 '20 01:05 lessw2020