Open jerryzh168 opened 3 years ago
Possible reason: hypothesis
testing module?
Thanks @ansley, yes, this is resolved, this error is caused by hypothesis. cc @zdevito
@jerryzh168 Hi,I met similar problem and the results are:
File "/usr/local/lib64/python3.6/site-packages/torch/nn/modules/module.py", line 889, in _call_impl
result = self.forward(*input, **kwargs)
File "/usr/local/lib64/python3.6/site-packages/torch/nn/parallel/data_parallel.py", line 167, in forward
outputs = self.parallel_apply(replicas, inputs, kwargs)
File "/usr/local/lib64/python3.6/site-packages/torch/nn/parallel/data_parallel.py", line 177, in parallel_apply
return parallel_apply(replicas, inputs, kwargs, self.device_ids[:len(replicas)])
File "/usr/local/lib64/python3.6/site-packages/torch/nn/parallel/parallel_apply.py", line 86, in parallel_apply
output.reraise()
File "/usr/local/lib64/python3.6/site-packages/torch/_utils.py", line 429, in reraise
raise self.exc_type(msg)
RuntimeError: Caught RuntimeError in replica 0 on device 0.
Original Traceback (most recent call last):
File "/usr/local/lib64/python3.6/site-packages/torch/nn/parallel/parallel_apply.py", line 61, in _worker
output = module(*input, **kwargs)
File "/usr/local/lib64/python3.6/site-packages/torch/nn/modules/module.py", line 889, in _call_impl
result = self.forward(*input, **kwargs)
File "/apdcephfs/private_colyban/3D-respool-4Branch-trypara3/models/resnet.py", line 227, in forward
self.module3 = torch.jit.script(self.module3)
File "/usr/local/lib64/python3.6/site-packages/torch/jit/_script.py", line 943, in script
obj, torch.jit._recursive.infer_methods_to_compile
File "/usr/local/lib64/python3.6/site-packages/torch/jit/_recursive.py", line 391, in create_script_module
return create_script_module_impl(nn_module, concrete_type, stubs_fn)
File "/usr/local/lib64/python3.6/site-packages/torch/jit/_recursive.py", line 448, in create_script_module_impl
script_module = torch.jit.RecursiveScriptModule._construct(cpp_module, init_fn)
File "/usr/local/lib64/python3.6/site-packages/torch/jit/_script.py", line 391, in _construct
init_fn(script_module)
File "/usr/local/lib64/python3.6/site-packages/torch/jit/_recursive.py", line 428, in init_fn
scripted = create_script_module_impl(orig_value, sub_concrete_type, stubs_fn)
File "/usr/local/lib64/python3.6/site-packages/torch/jit/_recursive.py", line 448, in create_script_module_impl
script_module = torch.jit.RecursiveScriptModule._construct(cpp_module, init_fn)
File "/usr/local/lib64/python3.6/site-packages/torch/jit/_script.py", line 391, in _construct
init_fn(script_module)
File "/usr/local/lib64/python3.6/site-packages/torch/jit/_recursive.py", line 428, in init_fn
scripted = create_script_module_impl(orig_value, sub_concrete_type, stubs_fn)
File "/usr/local/lib64/python3.6/site-packages/torch/jit/_recursive.py", line 448, in create_script_module_impl
script_module = torch.jit.RecursiveScriptModule._construct(cpp_module, init_fn)
File "/usr/local/lib64/python3.6/site-packages/torch/jit/_script.py", line 391, in _construct
init_fn(script_module)
File "/usr/local/lib64/python3.6/site-packages/torch/jit/_recursive.py", line 428, in init_fn
scripted = create_script_module_impl(orig_value, sub_concrete_type, stubs_fn)
File "/usr/local/lib64/python3.6/site-packages/torch/jit/_recursive.py", line 452, in create_script_module_impl
create_methods_and_properties_from_stubs(concrete_type, method_stubs, property_stubs)
File "/usr/local/lib64/python3.6/site-packages/torch/jit/_recursive.py", line 335, in create_methods_and_properties_from_stubs
concrete_type._create_methods_and_properties(property_defs, property_rcbs, method_defs, method_rcbs, method_defaults)
RuntimeError: Can't redefine method: forward on class: __torch__.torch.nn.modules.fold.Unfold (of Python compilation unit at: 0x3dea450)
This problem have stuck me for weeks.Could you tell me how to solve this?I still puzzled about how to solve this problem.Thank you!
File "/usr/local/lib64/python3.6/site-packages/torch/nn/modules/module.py", line 889, in _call_impl result = self.forward(*input, **kwargs) File "/usr/local/lib64/python3.6/site-packages/torch/nn/parallel/data_parallel.py", line 167, in forward outputs = self.parallel_apply(replicas, inputs, kwargs) File "/usr/local/lib64/python3.6/site-packages/torch/nn/parallel/data_parallel.py", line 177, in parallel_apply return parallel_apply(replicas, inputs, kwargs, self.device_ids[:len(replicas)]) File "/usr/local/lib64/python3.6/site-packages/torch/nn/parallel/parallel_apply.py", line 86, in parallel_apply output.reraise() File "/usr/local/lib64/python3.6/site-packages/torch/_utils.py", line 429, in reraise raise self.exc_type(msg) RuntimeError: Caught RuntimeError in replica 0 on device 0. Original Traceback (most recent call last): File "/usr/local/lib64/python3.6/site-packages/torch/nn/parallel/parallel_apply.py", line 61, in _worker output = module(*input, **kwargs) File "/usr/local/lib64/python3.6/site-packages/torch/nn/modules/module.py", line 889, in _call_impl result = self.forward(*input, **kwargs) File "/apdcephfs/private_colyban/3D-respool-4Branch-trypara3/models/resnet.py", line 227, in forward self.module3 = torch.jit.script(self.module3) File "/usr/local/lib64/python3.6/site-packages/torch/jit/_script.py", line 943, in script obj, torch.jit._recursive.infer_methods_to_compile File "/usr/local/lib64/python3.6/site-packages/torch/jit/_recursive.py", line 391, in create_script_module return create_script_module_impl(nn_module, concrete_type, stubs_fn) File "/usr/local/lib64/python3.6/site-packages/torch/jit/_recursive.py", line 448, in create_script_module_impl script_module = torch.jit.RecursiveScriptModule._construct(cpp_module, init_fn) File "/usr/local/lib64/python3.6/site-packages/torch/jit/_script.py", line 391, in _construct init_fn(script_module) File "/usr/local/lib64/python3.6/site-packages/torch/jit/_recursive.py", line 428, in init_fn scripted = create_script_module_impl(orig_value, sub_concrete_type, stubs_fn) File "/usr/local/lib64/python3.6/site-packages/torch/jit/_recursive.py", line 448, in create_script_module_impl script_module = torch.jit.RecursiveScriptModule._construct(cpp_module, init_fn) File "/usr/local/lib64/python3.6/site-packages/torch/jit/_script.py", line 391, in _construct init_fn(script_module) File "/usr/local/lib64/python3.6/site-packages/torch/jit/_recursive.py", line 428, in init_fn scripted = create_script_module_impl(orig_value, sub_concrete_type, stubs_fn) File "/usr/local/lib64/python3.6/site-packages/torch/jit/_recursive.py", line 448, in create_script_module_impl script_module = torch.jit.RecursiveScriptModule._construct(cpp_module, init_fn) File "/usr/local/lib64/python3.6/site-packages/torch/jit/_script.py", line 391, in _construct init_fn(script_module) File "/usr/local/lib64/python3.6/site-packages/torch/jit/_recursive.py", line 428, in init_fn scripted = create_script_module_impl(orig_value, sub_concrete_type, stubs_fn) File "/usr/local/lib64/python3.6/site-packages/torch/jit/_recursive.py", line 452, in create_script_module_impl create_methods_and_properties_from_stubs(concrete_type, method_stubs, property_stubs) File "/usr/local/lib64/python3.6/site-packages/torch/jit/_recursive.py", line 335, in create_methods_and_properties_from_stubs concrete_type._create_methods_and_properties(property_defs, property_rcbs, method_defs, method_rcbs, method_defaults) RuntimeError: Can't redefine method: forward on class: __torch__.torch.nn.modules.fold.Unfold (of Python compilation unit at: 0x3dea450)
This problem have stuck me for weeks.Could you tell me how to solve this?I still puzzled about how to solve this problem.Thank you!
Hi WUSHUANGPPP,
Could you please provide a minimal repro for the issue? Also, do you mind open a separate issue for easier tracking? Though the error message in your case is similar to this issue, they are different root causes for sure.
I can only infer very limited information from the stack trace you provided. One anti-pattern is calling torch.jit.script
inside forward
, this is not allowed because forward
is executed many times while you only want to torch.jit.script
once.
Thanks for you response!@gmagogsfm, When I moved the torch.jit.script
outside of forward
the problem solved. But I got new error after I solve several bugs yesterday. Now I 'll open a new issue for that.
@gmagogsfm Hi, I met similar problem and result as below:
>>> bert_model_ts = torch.jit.script(model, input_idx) /usr/local/lib/python3.8/site-packages/torch/jit/_script.py:1084: UserWarning:
optimizeis deprecated and has no effect. Use
with torch.jit.optimized_execution() instead
warnings.warn(
Traceback (most recent call last):
File "
Did you get an answer to the above issue? I'm also stuck there. @wangzhaode @gmagogsfm
Did you get an answer to the above issue? I'm also stuck there. @wangzhaode @gmagogsfm
NO!I'm using trace mode now.
@wangzhaode Could you please provide minimal steps to repro? And also your Pytorch configuration according to bug report template? Without them, it is difficult to us to investigate. Thanks
@gmagogsfm Tanks for your reply! My torch version is 1.9.0, and model is from transformer. The step is as below:
pip install transformers
from transformers import BertModel, BertTokenizer, BertConfig
import torch
enc = BertTokenizer.from_pretrained("bert-base-uncased")
text = "[CLS] Who was Jim Henson ? [SEP] Jim Henson was a puppeteer [SEP]" tokenized_text = enc.tokenize(text)
masked_index = 8 tokenized_text[masked_index] = '[MASK]' indexed_tokens = enc.convert_tokens_to_ids(tokenized_text) segments_ids = [0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1]
tokens_tensor = torch.tensor([indexed_tokens]) segments_tensors = torch.tensor([segments_ids]) dummy_input = [tokens_tensor, segments_tensors]
config = BertConfig(vocab_size_or_config_json_file=32000, hidden_size=768, num_hidden_layers=12, num_attention_heads=12, intermediate_size=3072, torchscript=True)
model = BertModel(config)
model.eval()
model = BertModel.from_pretrained("bert-base-uncased", torchscript=True)
script_model = torch.jit.script(model, [tokens_tensor, segments_tensors]) torch.jit.save(script_model, "script_bert.pt")
Hi, guy, Have you resolved this problem.
I have a similar error as @wangzhaode when trying to script a Huggingface diffusers model. Any help on this would be appreciated.
Thanks for you response!@gmagogsfm, When I moved the
torch.jit.script
outside offorward
the problem solved. But I got new error after I solve several bugs yesterday. Now I 'll open a new issue for that.
How did you 'move' the torch.jit.script
'outside' of forward
?
I am trying to save a model using torch.jit.script(model). It is throwing
RuntimeError: Can't redefine method: forward on class: __torch__.fairseq.modules.transformer_layer.TransformerDecoderLayerBase (of Python compilation unit at: 0x7f94cf4d60e8)
I guess I have a similar problem when trying to export an image segmentation model (nnUNet).
model_scripted = torch.jit.script(model)
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/home/chaitanya.kolluru/miniconda3/envs/rsip-env/lib/python3.11/site-packages/torch/jit/_script.py", line 1324, in script
return torch.jit._recursive.create_script_module(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/chaitanya.kolluru/miniconda3/envs/rsip-env/lib/python3.11/site-packages/torch/jit/_recursive.py", line 559, in create_script_module
return create_script_module_impl(nn_module, concrete_type, stubs_fn)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/chaitanya.kolluru/miniconda3/envs/rsip-env/lib/python3.11/site-packages/torch/jit/_recursive.py", line 632, in create_script_module_impl
script_module = torch.jit.RecursiveScriptModule._construct(cpp_module, init_fn)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/chaitanya.kolluru/miniconda3/envs/rsip-env/lib/python3.11/site-packages/torch/jit/_script.py", line 639, in _construct
init_fn(script_module)
File "/home/chaitanya.kolluru/miniconda3/envs/rsip-env/lib/python3.11/site-packages/torch/jit/_recursive.py", line 608, in init_fn
scripted = create_script_module_impl(
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/chaitanya.kolluru/miniconda3/envs/rsip-env/lib/python3.11/site-packages/torch/jit/_recursive.py", line 636, in create_script_module_impl
create_methods_and_properties_from_stubs(
File "/home/chaitanya.kolluru/miniconda3/envs/rsip-env/lib/python3.11/site-packages/torch/jit/_recursive.py", line 469, in create_methods_and_properties_from_stubs
concrete_type._create_methods_and_properties(
RuntimeError: Can't redefine method: forward on class: __torch__.dynamic_network_architectures.building_blocks.plain_conv_encoder.PlainConvEncoder (of Python compilation unit at: 0x676bc80)
🐛 Bug
scripting test failed in https://github.com/pytorch/pytorch/pull/52316 with error
To Reproduce
Expected behavior
Test should pass
cc @gmagogsfm