[jit][script] handling of 'void' returns, NoneType error

gyt.971027: <p>Hello, I want to optimise a model but I meet the error:</p>
<blockquote>
<p>Traceback (most recent call last):<br>
File “mobile_test.py”, line 129, in <br>
data_loader,bn_list[0],net_config))<br>
File “mobile_test.py”, line 62, in prepare_subnet<br>
script_subnet = torch.jit.script(subnet)<br>
File “/home/yuantian/.local/lib/python3.6/site-packages/torch/jit/_script.py”, line 943, in script<br>
obj, torch.jit._recursive.infer_methods_to_compile<br>
File “/home/yuantian/.local/lib/python3.6/site-packages/torch/jit/_recursive.py”, line 391, in create_script_module<br>
return create_script_module_impl(nn_module, concrete_type, stubs_fn)<br>
File “/home/yuantian/.local/lib/python3.6/site-packages/torch/jit/_recursive.py”, line 448, in create_script_module_impl<br>
script_module = torch.jit.RecursiveScriptModule._construct(cpp_module, init_fn)<br>
File “/home/yuantian/.local/lib/python3.6/site-packages/torch/jit/_script.py”, line 391, in _construct<br>
init_fn(script_module)<br>
File “/home/yuantian/.local/lib/python3.6/site-packages/torch/jit/_recursive.py”, line 428, in init_fn<br>
scripted = create_script_module_impl(orig_value, sub_concrete_type, stubs_fn)<br>
File “/home/yuantian/.local/lib/python3.6/site-packages/torch/jit/_recursive.py”, line 404, in create_script_module_impl<br>
property_stubs = get_property_stubs(nn_module)<br>
File “/home/yuantian/.local/lib/python3.6/site-packages/torch/jit/_recursive.py”, line 697, in get_property_stubs<br>
properties_asts = get_class_properties(module_ty, self_name=“RecursiveScriptModule”)<br>
File “/home/yuantian/.local/lib/python3.6/site-packages/torch/jit/frontend.py”, line 153, in get_class_properties<br>
getter = get_jit_def(prop[1].fget, f"__{prop[0]}_getter", self_name=self_name)<br>
File “/home/yuantian/.local/lib/python3.6/site-packages/torch/jit/frontend.py”, line 271, in get_jit_def<br>
return build_def(ctx, fn_def, type_line, def_name, self_name=self_name)<br>
File “/home/yuantian/.local/lib/python3.6/site-packages/torch/jit/frontend.py”, line 305, in build_def<br>
build_stmts(ctx, body))<br>
File “/home/yuantian/.local/lib/python3.6/site-packages/torch/jit/frontend.py”, line 129, in build_stmts<br>
stmts = [build_stmt(ctx, s) for s in stmts]<br>
File “/home/yuantian/.local/lib/python3.6/site-packages/torch/jit/frontend.py”, line 129, in <br>
stmts = [build_stmt(ctx, s) for s in stmts]<br>
File “/home/yuantian/.local/lib/python3.6/site-packages/torch/jit/frontend.py”, line 279, in <strong>call</strong><br>
return method(ctx, node)<br>
File “/home/yuantian/.local/lib/python3.6/site-packages/torch/jit/frontend.py”, line 445, in build_Return<br>
return Return(r, None if stmt.value is None else build_expr(ctx, stmt.value))<br>
File “/home/yuantian/.local/lib/python3.6/site-packages/torch/jit/frontend.py”, line 279, in <strong>call</strong><br>
return method(ctx, node)<br>
File “/home/yuantian/.local/lib/python3.6/site-packages/torch/jit/frontend.py”, line 781, in build_Dict<br>
return DictLiteral(range, [build_expr(ctx, e) for e in expr.keys],<br>
File “/home/yuantian/.local/lib/python3.6/site-packages/torch/jit/frontend.py”, line 781, in <br>
return DictLiteral(range, [build_expr(ctx, e) for e in expr.keys],<br>
File “/home/yuantian/.local/lib/python3.6/site-packages/torch/jit/frontend.py”, line 278, in <strong>call</strong><br>
raise UnsupportedNodeError(ctx, node)<br>
File “/home/yuantian/.local/lib/python3.6/site-packages/torch/jit/frontend.py”, line 111, in <strong>init</strong><br>
source_range = ctx.make_range(offending_node.lineno,<br>
AttributeError: ‘NoneType’ object has no attribute ‘lineno’</p>
</blockquote>
<p>And this is my code:</p>
<blockquote>
<p>fuse_model(subnet)</p>
<p><span class="hashtag-raw">#quantize</span> model<br>
subnet.qconfig = torch.quantization.default_qconfig<br>
subnet.qconfig = torch.quantization.get_default_qconfig(‘qnnpack’)<br>
torch.backends.quantized.engine = ‘qnnpack’<br>
torch.quantization.prepare(subnet, inplace=True)<br>
<span class="hashtag-raw">#Calibrate</span><br>
print(‘Calibrating…’)<br>
<span class="hashtag-raw">#evaluate_ofa_subnet</span>(subnet,<br>
<span class="hashtag-raw">#imagenet_data_path</span>, net_config, data_loader, batch_size=16)</p>
<p><span class="hashtag-raw">#Convert</span> model<br>
torch.quantization.convert(subnet, inplace=True)<br>
<span class="hashtag-raw">#optimize</span><br>
script_subnet = torch.jit.script(subnet)<br>
script_subnet_optimized = optimize_for_mobile(script_subnet)<br>
return script_subnet_optimized</p>
</blockquote>
<p>My code’s link is here:</p>
<blockquote>
<p><a href="https://drive.google.com/drive/folders/172QoQxYoB1fUPvwjudHWgBmRv-IfE8Mg?usp=sharing" class="inline-onebox" rel="noopener nofollow ugc">time - Google Drive</a></p>
</blockquote>
<p>You can run <code>test.py</code> file to run and should run the same error as me.<br>
So how to solve it?<br>
Kind regards.</p>