在pytorch中,如何调试JIT错误信息“ RuntimeError:仅可从跟踪函数输出张量或张量的元组”?

时间:2019-10-12 01:46:37

标签: python-3.x pytorch jit

我编写了一个简单的pytorch顺序模块,计划将其转换为ONNX以进行可视化和移动部署。第一步是将其转换为JIT版本:

        input = torch.rand(1, 3, 300, 300, dtype=torch.float32, device=device)
        mod = FPNImproved(raw)
        torch.jit.trace(mod, input)

此步骤给我以下错误:

        for method_name, example_inputs in inputs.items():
            # this is needed since Module.__call__ sets up some extra tracing
            func = mod if method_name == "forward" else getattr(mod, method_name)
            example_inputs = make_tuple(example_inputs)
>           module._c._create_method_from_trace(method_name, func, example_inputs, var_lookup_fn, _force_outplace)
E           RuntimeError: Only tensors or tuples of tensors can be output from traced functions (getOutput at /opt/conda/conda-bld/pytorch_1570711556059/work/torch/csrc/jit/tracer.cpp:209)
E           frame #0: c10::Error::Error(c10::SourceLocation, std::string const&) + 0x47 (0x7f35dca71687 in /home/shared/conda3/envs/cv-torch/lib/python3.7/site-packages/torch/lib/libc10.so)
E           frame #1: torch::jit::tracer::TracingState::getOutput(c10::IValue const&) + 0x365 (0x7f35aa607105 in /home/shared/conda3/envs/cv-torch/lib/python3.7/site-packages/torch/lib/libtorch.so)
E           frame #2: torch::jit::tracer::exit(std::vector<c10::IValue, std::allocator<c10::IValue> > const&) + 0x3c (0x7f35aa60740c in /home/shared/conda3/envs/cv-torch/lib/python3.7/site-packages/torch/lib/libtorch.so)
E           frame #3: <unknown function> + 0x57472a (0x7f35e62fd72a in /home/shared/conda3/envs/cv-torch/lib/python3.7/site-packages/torch/lib/libtorch_python.so)
E           frame #4: <unknown function> + 0x58bbb4 (0x7f35e6314bb4 in /home/shared/conda3/envs/cv-torch/lib/python3.7/site-packages/torch/lib/libtorch_python.so)
E           frame #5: <unknown function> + 0x206506 (0x7f35e5f8f506 in /home/shared/conda3/envs/cv-torch/lib/python3.7/site-packages/torch/lib/libtorch_python.so)
E           frame #6: _PyMethodDef_RawFastCallKeywords + 0x254 (0x56498498e744 in /home/shared/conda3/envs/cv-torch/bin/python)
E           frame #7: _PyCFunction_FastCallKeywords + 0x21 (0x56498498e861 in /home/shared/conda3/envs/cv-torch/bin/python)
E           frame #8: _PyEval_EvalFrameDefault + 0x52f8 (0x5649849fa6e8 in /home/shared/conda3/envs/cv-torch/bin/python)
E           frame #9: _PyEval_EvalCodeWithName + 0x2f9 (0x56498493e539 in /home/shared/conda3/envs/cv-torch/bin/python)
E           frame #10: _PyFunction_FastCallKeywords + 0x325 (0x56498498def5 in /home/shared/conda3/envs/cv-torch/bin/python)
E           frame #11: _PyEval_EvalFrameDefault + 0x416 (0x5649849f5806 in /home/shared/conda3/envs/cv-torch/bin/python)
E           frame #12: _PyEval_EvalCodeWithName + 0x2f9 (0x56498493e539 in /home/shared/conda3/envs/cv-torch/bin/python)
E           frame #13: _PyFunction_FastCallKeywords + 0x325 (0x56498498def5 in /home/shared/conda3/envs/cv-torch/bin/python)
E           frame #14: _PyEval_EvalFrameDefault + 0x4b39 (0x5649849f9f29 in /home/shared/conda3/envs/cv-torch/bin/python)
E           frame #15: _PyFunction_FastCallKeywords + 0xfb (0x56498498dccb in /home/shared/conda3/envs/cv-torch/bin/python)
E           frame #16: _PyEval_EvalFrameDefault + 0x416 (0x5649849f5806 in /home/shared/conda3/envs/cv-torch/bin/python)
E           frame #17: _PyEval_EvalCodeWithName + 0x2f9 (0x56498493e539 in /home/shared/conda3/envs/cv-torch/bin/python)
E           frame #18: _PyFunction_FastCallDict + 0x400 (0x56498493f860 in /home/shared/conda3/envs/cv-torch/bin/python)
E           frame #19: _PyObject_Call_Prepend + 0x63 (0x56498495de53 in /home/shared/conda3/envs/cv-torch/bin/python)
E           frame #20: PyObject_Call + 0x6e (0x564984950dbe in /home/shared/conda3/envs/cv-torch/bin/python)
E           frame #21: _PyEval_EvalFrameDefault + 0x1e42 (0x5649849f7232 in /home/shared/conda3/envs/cv-torch/bin/python)
E           frame #22: _PyEval_EvalCodeWithName + 0x2f9 (0x56498493e539 in /home/shared/conda3/envs/cv-torch/bin/python)
E           frame #23: _PyFunction_FastCallDict + 0x400 (0x56498493f860 in /home/shared/conda3/envs/cv-torch/bin/python)
E           frame #24: _PyObject_Call_Prepend + 0x63 (0x56498495de53 in /home/shared/conda3/envs/cv-torch/bin/python)
E           frame #25: <unknown function> + 0x16ba3a (0x564984995a3a in /home/shared/conda3/envs/cv-torch/bin/python)
E           frame #26: _PyObject_FastCallKeywords + 0x49b (0x5649849968fb in /home/shared/conda3/envs/cv-torch/bin/python)
E           frame #27: _PyEval_EvalFrameDefault + 0x569f (0x5649849faa8f in /home/shared/conda3/envs/cv-torch/bin/python)
E           frame #28: _PyFunction_FastCallKeywords + 0xfb (0x56498498dccb in /home/shared/conda3/envs/cv-torch/bin/python)
E           frame #29: _PyEval_EvalFrameDefault + 0x6a3 (0x5649849f5a93 in /home/shared/conda3/envs/cv-torch/bin/python)
E           frame #30: _PyFunction_FastCallDict + 0x10b (0x56498493f56b in /home/shared/conda3/envs/cv-torch/bin/python)
E           frame #31: _PyEval_EvalFrameDefault + 0x1e42 (0x5649849f7232 in /home/shared/conda3/envs/cv-torch/bin/python)
E           frame #32: _PyEval_EvalCodeWithName + 0xac9 (0x56498493ed09 in /home/shared/conda3/envs/cv-torch/bin/python)
E           frame #33: _PyFunction_FastCallKeywords + 0x387 (0x56498498df57 in /home/shared/conda3/envs/cv-torch/bin/python)

不幸的是,此消息无济于事,因为我的印象是模块中的所有层均已具有张量或元组输出。更糟糕的是,错误消息无法告诉我罪魁祸首。

建议pytorch JIT解释的推荐方法是什么?我已经启用了PYTORCH_JIT = 0。

我正在使用仅支持CPU的pytorch 1.3.0

0 个答案:

没有答案