I try to TorchScript my function with @torch.jit.script
decoration, which itself calls other functions from another module. But I ended up with the following error.
File “/venv/lib/python3.7/site-packages/torch/jit/init.py”, line 1551, in script
fn = torch._C._jit_script_compile(qualified_name, ast, _rcb, get_default_args(obj))
File “/venv/lib/python3.7/site-packages/torch/jit/_recursive.py”, line 583, in try_compile_fn
return torch.jit.script(fn, _rcb=rcb)
File “/venv/lib/python3.7/site-packages/torch/jit/init.py”, line 1547, in script
ast = get_jit_def(obj, obj.name)
File “/venv/lib/python3.7/site-packages/torch/jit/frontend.py”, line 185, in get_jit_def
return build_def(ctx, fn_def, type_line, def_name, self_name=self_name)
File “/venv/lib/python3.7/site-packages/torch/jit/frontend.py”, line 219, in build_def
build_stmts(ctx, body))
File “/venv/lib/python3.7/site-packages/torch/jit/frontend.py”, line 126, in build_stmts
stmts = [build_stmt(ctx, s) for s in stmts]
File “/venv/lib/python3.7/site-packages/torch/jit/frontend.py”, line 126, in
stmts = [build_stmt(ctx, s) for s in stmts]
File “/venv/lib/python3.7/site-packages/torch/jit/frontend.py”, line 193, in call
return method(ctx, node)
File “/venv/lib/python3.7/site-packages/torch/jit/frontend.py”, line 384, in build_If
build_stmts(ctx, stmt.body),
File “/venv/lib/python3.7/site-packages/torch/jit/frontend.py”, line 126, in build_stmts
stmts = [build_stmt(ctx, s) for s in stmts]
File “/venv/lib/python3.7/site-packages/torch/jit/frontend.py”, line 126, in
stmts = [build_stmt(ctx, s) for s in stmts]
File “/venv/lib/python3.7/site-packages/torch/jit/frontend.py”, line 193, in call
return method(ctx, node)
File “/venv/lib/python3.7/site-packages/torch/jit/frontend.py”, line 384, in build_If
build_stmts(ctx, stmt.body),
File “/venv/lib/python3.7/site-packages/torch/jit/frontend.py”, line 126, in build_stmts
stmts = [build_stmt(ctx, s) for s in stmts]
File “/venv/lib/python3.7/site-packages/torch/jit/frontend.py”, line 126, in
stmts = [build_stmt(ctx, s) for s in stmts]
File “/venv/lib/python3.7/site-packages/torch/jit/frontend.py”, line 193, in call
return method(ctx, node)
File “/venv/lib/python3.7/site-packages/torch/jit/frontend.py”, line 385, in build_If
build_stmts(ctx, stmt.orelse))
File “/venv/lib/python3.7/site-packages/torch/jit/frontend.py”, line 126, in build_stmts
stmts = [build_stmt(ctx, s) for s in stmts]
File “/venv/lib/python3.7/site-packages/torch/jit/frontend.py”, line 126, in
stmts = [build_stmt(ctx, s) for s in stmts]
File “/venv/lib/python3.7/site-packages/torch/jit/frontend.py”, line 193, in call
return method(ctx, node)
File “/venv/lib/python3.7/site-packages/torch/jit/frontend.py”, line 384, in build_If
build_stmts(ctx, stmt.body),
File “/venv/lib/python3.7/site-packages/torch/jit/frontend.py”, line 126, in build_stmts
stmts = [build_stmt(ctx, s) for s in stmts]
File “/venv/lib/python3.7/site-packages/torch/jit/frontend.py”, line 126, in
stmts = [build_stmt(ctx, s) for s in stmts]
File “/venv/lib/python3.7/site-packages/torch/jit/frontend.py”, line 193, in call
return method(ctx, node)
File “/venv/lib/python3.7/site-packages/torch/jit/frontend.py”, line 413, in build_With
return With(r, build_withitems(ctx, stmt.items), build_stmts(ctx, stmt.body))
File “/venv/lib/python3.7/site-packages/torch/jit/frontend.py”, line 121, in build_withitems
items = [build_withitem(ctx, i) for i in items]
File “/venv/lib/python3.7/site-packages/torch/jit/frontend.py”, line 121, in
items = [build_withitem(ctx, i) for i in items]
File “/venv/lib/python3.7/site-packages/torch/jit/frontend.py”, line 193, in call
return method(ctx, node)
File “/venv/lib/python3.7/site-packages/torch/jit/frontend.py”, line 282, in build_withitem
end = start + len(item.context_expr.id)
AttributeError: ‘Call’ object has no attribute ‘id’
The qualified_name
in torch._C._jit_script_compile(qualified_name, ast, _rcb, get_default_args(obj))
is referenced to a simple function which does not call any PyTorch
module.
I use PyTorch 1.6.0
with Python 3.7
. Any idea?