В pytorch, как отладить информацию об ошибке JIT «RuntimeError: из отслеживаемых функций могут быть выведены только тензоры или кортежи тензоров»? - PullRequest
0 голосов
/ 12 октября 2019

Я написал простой модуль Pytorch Sequential, для которого планирую конвертировать в 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.

Я использую Pytorch 1.3.0 только с поддержкой процессора

...