Torchscript C++ Inference Error
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 17.9k
- Forks
- 7.3k
- Avg merge
- 1d 15h
- Merged PRs (30d)
- 13
Description
🐛 Describe the bug
I saved a Detectron2 Torchscript model using the following code:
fields = {
"proposal_boxes": Boxes,
"objectness_logits": Tensor,
"pred_boxes": Boxes,
"scores": Tensor,
"pred_classes": Tensor,
"pred_masks": Tensor,
"pred_keypoints": torch.Tensor,
"pred_keypoint_heatmaps": torch.Tensor,
}
torch_script_module = scripting_with_instances(torch_model, fields)
extra_files = {}
extra_files["module_info.json"] = json.dumps({"input_names": ["data"], "output_names": ["predicted"]})
torch.jit.save(torch_script_module, os.path.join(outdir, "model.pt"), _extra_files=extra_files)
However, when I tried to load it in C++, I'm getting the following error:
terminate called after throwing an instance of 'torch::jit::ErrorReport'
what():
Unknown type name 'NoneType':
Serialized File "code/__torch__/detectron2/modeling/backbone/fpn.py", line 4
__parameters__ = []
__buffers__ = []
_is_full_backward_hook : NoneType
~~~~~~~~ <--- HERE
in_features : Tuple[str, str, str, str]
_out_feature_strides : Dict[str, int]
I've tried to remove the _is_full_backward_hook field in torch_script_module, but seems like it will still be initialized as "None" when I load the model (in both Python and C++). What's the best way to resolve this issue?
Versions
Collecting environment information...
PyTorch version: 1.9.0a0+gitdfbd030
Is debug build: False
CUDA used to build PyTorch: 11.0
ROCM used to build PyTorch: N/A
OS: Ubuntu 16.04.7 LTS (x86_64)
GCC version: (Ubuntu 5.4.0-6ubuntu1~16.04.12) 5.4.0 20160609
Clang version: Could not collect
CMake version: version 3.5.1
Libc version: glibc-2.2.5
Python version: 3.7.5 (default, Aug 26 2021, 16:53:13) [GCC 5.4.0 20160609] (64-bit runtime)
Python platform: Linux-4.15.0-1065-aws-x86_64-with-debian-stretch-sid
Is CUDA available: True
CUDA runtime version: 11.0.221
GPU models and configuration:
GPU 0: Tesla V100-SXM2-32GB
GPU 1: Tesla V100-SXM2-32GB
GPU 2: Tesla V100-SXM2-32GB
GPU 3: Tesla V100-SXM2-32GB
GPU 4: Tesla V100-SXM2-32GB
GPU 5: Tesla V100-SXM2-32GB
GPU 6: Tesla V100-SXM2-32GB
GPU 7: Tesla V100-SXM2-32GB
Nvidia driver version: 450.142.00
cuDNN version: Probably one of the following:
/usr/lib/x86_64-linux-gnu/libcudnn.so.8.0.5
/usr/lib/x86_64-linux-gnu/libcudnn_adv_infer.so.8.0.5
/usr/lib/x86_64-linux-gnu/libcudnn_adv_train.so.8.0.5
/usr/lib/x86_64-linux-gnu/libcudnn_cnn_infer.so.8.0.5
/usr/lib/x86_64-linux-gnu/libcudnn_cnn_train.so.8.0.5
/usr/lib/x86_64-linux-gnu/libcudnn_ops_infer.so.8.0.5
/usr/lib/x86_64-linux-gnu/libcudnn_ops_train.so.8.0.5
HIP runtime version: N/A
MIOpen runtime version: N/A
Versions of relevant libraries:
[pip3] botorch==0.4.0
[pip3] gpytorch==1.5.1
[pip3] mypy-extensions==0.4.3
[pip3] mypy-protobuf==2.4
[pip3] numpy==1.19.4
[pip3] pytorch-lamb==1.0.0
[pip3] torch==1.9.0a0+gitdfbd030
[pip3] torch-tb-profiler==0.3.1
[pip3] torchfile==0.1.0
[pip3] torchmetrics==0.3.1
[pip3] torchscript==0.2.10
[pip3] torchvision==0.8.0a0+2f40a48
[conda] Could not collect
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the reported torch.jit.save flow and the C++ model-loading path, then inspect the serialized code/torch/detectron2/modeling/backbone/fpn.py entry where _is_full_backward_hook is declared as NoneType. Done means the saved model loads in C++ without this error and the inference path works.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp, python, pytorch
- Domain
- computer-vision, machine-learning
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100