[jit][script] torch.jit.script(), UnsupportedNodeError returns NoneType error

gyt.971027: <p>I want to optimize a model but I meet the error:</p>
<pre><code class="lang-auto">Traceback (most recent call last):
  File "mobile_test.py", line 129, in &lt;module&gt;
    data_loader,bn_list[0],net_config))
  File "mobile_test.py", line 62, in prepare_subnet
    script_subnet = torch.jit.script(subnet)
  File "/home/yuantian/.local/lib/python3.6/site-packages/torch/jit/_script.py", line 943, in script
    obj, torch.jit._recursive.infer_methods_to_compile
  File "/home/yuantian/.local/lib/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 "/home/yuantian/.local/lib/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 "/home/yuantian/.local/lib/python3.6/site-packages/torch/jit/_script.py", line 391, in _construct
    init_fn(script_module)
  File "/home/yuantian/.local/lib/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 "/home/yuantian/.local/lib/python3.6/site-packages/torch/jit/_recursive.py", line 404, in create_script_module_impl
    property_stubs = get_property_stubs(nn_module)
  File "/home/yuantian/.local/lib/python3.6/site-packages/torch/jit/_recursive.py", line 697, in get_property_stubs
    properties_asts = get_class_properties(module_ty, self_name="RecursiveScriptModule")
  File "/home/yuantian/.local/lib/python3.6/site-packages/torch/jit/frontend.py", line 153, in get_class_properties
    getter = get_jit_def(prop[1].fget, f"__{prop[0]}_getter", self_name=self_name)
  File "/home/yuantian/.local/lib/python3.6/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/yuantian/.local/lib/python3.6/site-packages/torch/jit/frontend.py", line 305, in build_def
    build_stmts(ctx, body))
  File "/home/yuantian/.local/lib/python3.6/site-packages/torch/jit/frontend.py", line 129, in build_stmts
    stmts = [build_stmt(ctx, s) for s in stmts]
  File "/home/yuantian/.local/lib/python3.6/site-packages/torch/jit/frontend.py", line 129, in &lt;listcomp&gt;
    stmts = [build_stmt(ctx, s) for s in stmts]
  File "/home/yuantian/.local/lib/python3.6/site-packages/torch/jit/frontend.py", line 279, in __call__
    return method(ctx, node)
  File "/home/yuantian/.local/lib/python3.6/site-packages/torch/jit/frontend.py", line 445, in build_Return
    return Return(r, None if stmt.value is None else build_expr(ctx, stmt.value))
  File "/home/yuantian/.local/lib/python3.6/site-packages/torch/jit/frontend.py", line 279, in __call__
    return method(ctx, node)
  File "/home/yuantian/.local/lib/python3.6/site-packages/torch/jit/frontend.py", line 781, in build_Dict
    return DictLiteral(range, [build_expr(ctx, e) for e in expr.keys],
  File "/home/yuantian/.local/lib/python3.6/site-packages/torch/jit/frontend.py", line 781, in &lt;listcomp&gt;
    return DictLiteral(range, [build_expr(ctx, e) for e in expr.keys],
  File "/home/yuantian/.local/lib/python3.6/site-packages/torch/jit/frontend.py", line 278, in __call__
    raise UnsupportedNodeError(ctx, node)
  File "/home/yuantian/.local/lib/python3.6/site-packages/torch/jit/frontend.py", line 111, in __init__
    source_range = ctx.make_range(offending_node.lineno,
AttributeError: 'NoneType' object has no attribute 'lineno'
</code></pre>
<p>And this is my code link:<br>
<a href="https://drive.google.com/drive/folders/172QoQxYoB1fUPvwjudHWgBmRv-IfE8Mg?usp=sharing" rel="noopener nofollow ugc">https://drive.google.com/drive/folders/172QoQxYoB1fUPvwjudHWgBmRv-IfE8Mg?usp=sharing</a></p>
<p>You can run the test1 file to see the error.<br>
I have located the error in source code:<br>
<div class="lightbox-wrapper"><a class="lightbox" href="https://discuss.pytorch.org/uploads/default/original/3X/7/c/7c42f7acea80b593829919f6f42c17404730136e.png" data-download-href="https://discuss.pytorch.org/uploads/default/7c42f7acea80b593829919f6f42c17404730136e" title="839b4d67e2751d1132bdbb066b775c9"><img src="https://discuss.pytorch.org/uploads/default/optimized/3X/7/c/7c42f7acea80b593829919f6f42c17404730136e_2_690x68.png" alt="839b4d67e2751d1132bdbb066b775c9" data-base62-sha1="hJgGnoiFmoVgR7ltwTxt5550fAa" width="690" height="68" srcset="https://discuss.pytorch.org/uploads/default/optimized/3X/7/c/7c42f7acea80b593829919f6f42c17404730136e_2_690x68.png, https://discuss.pytorch.org/uploads/default/original/3X/7/c/7c42f7acea80b593829919f6f42c17404730136e.png 1.5x, https://discuss.pytorch.org/uploads/default/original/3X/7/c/7c42f7acea80b593829919f6f42c17404730136e.png 2x" data-dominant-color="EFF3F2"><div class="meta"><svg class="fa d-icon d-icon-far-image svg-icon" aria-hidden="true"><use href="#far-image"></use></svg><span class="filename">839b4d67e2751d1132bdbb066b775c9</span><span class="informations">713×71 34 KB</span><svg class="fa d-icon d-icon-discourse-expand svg-icon" aria-hidden="true"><use href="#discourse-expand"></use></svg></div></a></div><br>
<img src="https://discuss.pytorch.org/uploads/default/original/3X/8/a/8af249ee0e225140d4ef66391615d4cf49662428.png" alt="a45a9f7294b40945cc03d6618c866b8" data-base62-sha1="jPaZweMw8doT3TT5jRU4tQd8YVq" width="645" height="57"></p>
<p>But we do not know how to solve it.<br>
Kind regards.</p>

wujing: <p>Have you solved your problem? I have encountered the same problem as you. Looking forward to your reply, thank you</p>