Not found on multiline type annotation

I have a preprocess class that has two methods other than forward. when I try to sctrip the model this RunTime error apears:

Traceback (most recent call last):
  File "/projects/src/", line 99, in <module>
    scripted_prep = torch.jit.script(prep)
  File "/home/.conda/envs/GC/lib/python3.6/site-packages/torch/jit/", line 1261, in script
    return torch.jit._recursive.create_script_module(obj, torch.jit._recursive.infer_methods_to_compile)
  File "/home/.conda/envs/GC/lib/python3.6/site-packages/torch/jit/", line 305, in create_script_module
    return create_script_module_impl(nn_module, concrete_type, stubs_fn)
  File "/home/.conda/envs/GC/lib/python3.6/site-packages/torch/jit/", line 361, in create_script_module_impl
    create_methods_from_stubs(concrete_type, stubs)
  File "/home/.conda/envs/GC/lib/python3.6/site-packages/torch/jit/", line 279, in create_methods_from_stubs
    concrete_type._create_methods(defs, rcbs, defaults)
  File "/home/.conda/envs/GC/lib/python3.6/site-packages/torch/jit/", line 583, in compile_unbound_method
    stub = make_stub(fn)
  File "/home/.conda/envs/GC/lib/python3.6/site-packages/torch/jit/", line 34, in make_stub
    ast = torch.jit.get_jit_def(func, self_name="RecursiveScriptModule")
  File "/home/.conda/envs/GC/lib/python3.6/site-packages/torch/jit/", line 171, in get_jit_def
    type_line = torch.jit.annotations.get_type_line(source)
  File "/home/.conda/envs/GC/lib/python3.6/site-packages/torch/jit/", line 202, in get_type_line
    raise RuntimeError("Return type line '# type: (...) -> ...' not found on multiline "
RuntimeError: Return type line '# type: (...) -> ...' not found on multiline type annotation
(See PEP 484

Process finished with exit code 1

I found out that one of the methods makes this error but even I commented the whole method code and just remain:

def from_tensors(self):

still get the same error.

this is my forward code:

    def forward(self, im_in):
        images = im_in.permute(2, 0, 1).to('cpu')        
        images = self.normalizer(images)
        images = self.from_tensors([images], 3)  #this line raises error

        return images

If from_tensors is doing “pass” then calling:
images = self.from_tensors([images], 3)
is setting images to None

But nonetheless, can you post the original implementation of from_tesnsors ? (and normalizer)


thanks for responding.
I found that there is # type in one of my comments and even I commented the whole (code and comments) jit still could see that and took that as a command. after removig that comment the error gone.

1 Like