RuntimeError: Python builtin <built-in method apply of FunctionMeta object at 0x55dad1b31680> is currently not supported in Torchscript:

username: JachinMa
cooked: <p>I was running others code in <a href="https://github.com/Xilinx/brevitas/tree/master/examples,and" rel="nofollow noopener">https://github.com/Xilinx/brevitas/tree/master/examples,and</a> encounted this question.Is anyone know how to deal with that?</p>
<p>my pytorch version is 1.4 for GPU,and it works well.CUDA version is 10.1,GPU is 2080ti.</p>
<p>very thanks</p>
<p>Traceback (most recent call last):<br>
File “imagenet_val.py”, line 146, in <br>
main()<br>
File “imagenet_val.py”, line 42, in main<br>
model = models<a>arch</a><br>
File “/home/mjx/brevitasmaster/examples/models/mobilenetv1.py”, line 121, in quant_mobilenet_v1<br>
net = MobileNet(channels=channels,first_stage_stride=first_stage_stride,bit_width=bit_width)<br>
File “/home/mjx/brevitasmaster/examples/models/mobilenetv1.py”, line 75, in <strong>init</strong><br>
weight_bit_width=FIRST_LAYER_BIT_WIDTH,                        activation_scaling_per_channel=True,act_bit_width=bit_width)<br>
File “/home/mjx/brevitasmaster/examples/models/mobilenetv1.py”, line 28, in <strong>init</strong><br>
self.conv = make_quant_conv2d(in_channels=in_channels,out_channels=out_channels,kernel_size=kernel_size,stride=stride,padding=padding,groups=groups,bias=False,bit_width=weight_bit_width)<br>
File “/home/mjx/brevitasmaster/examples/models/common.py”, line 74, in make_quant_conv2d<br>
weight_scaling_min_val=weight_scaling_min_val)<br>
File “/home/mjx/brevitasmaster/brevitas/nn/quant_conv.py”, line 179, in <strong>init</strong><br>
override_pretrained_bit_width=weight_override_pretrained_bit_width)<br>
File “/home/mjx/brevitasmaster/brevitas/proxy/parameter_quant.py”, line 357, in <strong>init</strong><br>
self.re_init_tensor_quant()<br>
File “/home/mjx/brevitasmaster/brevitas/proxy/parameter_quant.py”, line 360, in re_init_tensor_quant<br>
self.tensor_quant = self.lazy_tensor_quant_init(tracked_parameter_list=self._tracked_parameter_list)<br>
File “/home/mjx/brevitasmaster/brevitas/proxy/parameter_quant.py”, line 146, in _weight_quant_init_impl<br>
affine=scaling_impl_type == ScalingImplType.AFFINE_STATS)<br>
File “/home/mjx/.conda/envs/py/lib/python3.7/site-packages/torch/jit/<strong>init</strong>.py”, line 1453, in init_then_script<br>
original_init(self, *args, **kwargs)<br>
File “/home/mjx/brevitasmaster/brevitas/core/scaling.py”, line 246, in <strong>init</strong><br>
stats_output_shape=stats_output_shape)<br>
File “/home/mjx/.conda/envs/py/lib/python3.7/site-packages/torch/jit/<strong>init</strong>.py”, line 1453, in init_then_script<br>
original_init(self, *args, **kwargs)<br>
File “/home/mjx/brevitasmaster/brevitas/core/scaling.py”, line 171, in <strong>init</strong><br>
self.restrict_scaling = RestrictValue(restrict_scaling_type, FloatToIntImplType.CEIL, scaling_min_val)<br>
File “/home/mjx/.conda/envs/py/lib/python3.7/site-packages/torch/jit/<strong>init</strong>.py”, line 1453, in init_then_script<br>
original_init(self, *args, **kwargs)<br>
File “/home/mjx/brevitasmaster/brevitas/core/restrict_val.py”, line 82, in <strong>init</strong><br>
float_to_int_impl = CeilSte()<br>
File “/home/mjx/.conda/envs/py/lib/python3.7/site-packages/torch/jit/<strong>init</strong>.py”, line 1456, in init_then_script<br>
self.<strong>dict</strong>["_actual_script_module"] = torch.jit._recursive.create_script_module(self, stubs)<br>
File “/home/mjx/.conda/envs/py/lib/python3.7/site-packages/torch/jit/_recursive.py”, line 296, in create_script_module<br>
return create_script_module_impl(nn_module, concrete_type, cpp_module, stubs)<br>
File “/home/mjx/.conda/envs/py/lib/python3.7/site-packages/torch/jit/_recursive.py”, line 340, in create_script_module_impl<br>
create_methods_from_stubs(concrete_type, stubs)<br>
File “/home/mjx/.conda/envs/py/lib/python3.7/site-packages/torch/jit/_recursive.py”, line 259, in create_methods_from_stubs<br>
concrete_type._create_methods(defs, rcbs, defaults)<br>
File “/home/mjx/.conda/envs/py/lib/python3.7/site-packages/torch/jit/_recursive.py”, line 555, in try_compile_fn<br>
return torch.jit.script(fn, _rcb=rcb)<br>
File “/home/mjx/.conda/envs/py/lib/python3.7/site-packages/torch/jit/<strong>init</strong>.py”, line 1281, in script<br>
fn = torch._C._jit_script_compile(qualified_name, ast, _rcb, get_default_args(obj))<br>
RuntimeError:<br>
Python builtin &lt;built-in method apply of FunctionMeta object at 0x55dad1b31680&gt; is currently not supported in Torchscript:<br>
File “/home/mjx/brevitasmaster/brevitas/function/ops_ste.py”, line 93</p>
<pre><code>"""
return ceil_ste_fn.apply(x)
       ~~~~~~~~~~~~~~~~~ &lt;--- HERE
</code></pre>
<p>‘ceil_ste’ is being compiled since it was called from ‘CeilSte.forward’<br>
File “/home/mjx/brevitasmaster/brevitas/core/function_wrapper.py”, line 79<br>
<span class="mention">@torch.jit.script_method</span><br>
def forward(self, x: torch.Tensor):<br>
return ceil_ste(x)<br>
~~~~~~~~~~ &lt;— HERE</p>

username: albanD
cooked: <p>Hi,</p>
<p>I don’t think torchscript supports custom autograd Function. Was that working before?</p>

username: JachinMa
cooked: <p>Sorry I dont know，I run other guy‘s code。</p>
<p>so maybe I can try to modify that</p>
<p>thanks a lot</p>