mirror of
https://github.com/pytorch/pytorch.git
synced 2025-10-20 21:14:14 +08:00
Debug with gdb
@ -6,22 +6,25 @@ Documentation for developing the PyTorch-ONNX exporter (`torch.onnx`). For an in
|
|||||||
|
|
||||||
<!-- TOC generated with https://github.com/ekalinin/github-markdown-toc -->
|
<!-- TOC generated with https://github.com/ekalinin/github-markdown-toc -->
|
||||||
|
|
||||||
* [Development process](#development-process)
|
- [Table of Contents](#table-of-contents)
|
||||||
* [Environment setup](#environment-setup)
|
- [Development process](#development-process)
|
||||||
* [Fork PyTorch](#fork-pytorch)
|
- [Environment setup](#environment-setup)
|
||||||
* [Build PyTorch](#build-pytorch)
|
- [Fork PyTorch](#fork-pytorch)
|
||||||
* [Optional build tips](#optional-build-tips)
|
- [Build PyTorch](#build-pytorch)
|
||||||
* [Install additional dependencies](#install-additional-dependencies)
|
- [Optional build tips](#optional-build-tips)
|
||||||
* [ONNX and ONNX Runtime](#onnx-and-onnx-runtime)
|
- [Install additional dependencies](#install-additional-dependencies)
|
||||||
* [TorchVision](#torchvision)
|
- [ONNX and ONNX Runtime](#onnx-and-onnx-runtime)
|
||||||
* [Sanity check](#sanity-check)
|
- [TorchVision](#torchvision)
|
||||||
* [VS Code](#vs-code)
|
- [Sanity check](#sanity-check)
|
||||||
* [Pull requests](#pull-requests)
|
- [VS Code](#vs-code)
|
||||||
* [Tests](#tests)
|
- [Recommended settings and extensions](#recommended-settings-and-extensions)
|
||||||
* [Links](#links)
|
- [Debugging with `gdb`](#debugging-with-gdb)
|
||||||
* [Relevant parts of PyTorch repo](#relevant-parts-of-pytorch-repo)
|
- [Pull requests](#pull-requests)
|
||||||
* [Features](#features)
|
- [Tests](#tests)
|
||||||
* [Quantized model export](#quantized-model-export)
|
- [Links](#links)
|
||||||
|
- [Relevant parts of PyTorch repo](#relevant-parts-of-pytorch-repo)
|
||||||
|
- [Features](#features)
|
||||||
|
- [Quantized model export](#quantized-model-export)
|
||||||
|
|
||||||
# Development process
|
# Development process
|
||||||
|
|
||||||
@ -135,6 +138,8 @@ If the second command succeeds, then probably python is finding a PyTorch that w
|
|||||||
|
|
||||||
### VS Code
|
### VS Code
|
||||||
|
|
||||||
|
#### Recommended settings and extensions
|
||||||
|
|
||||||
You can place this recommended `settings.json` under `.vscode/`
|
You can place this recommended `settings.json` under `.vscode/`
|
||||||
|
|
||||||
```jsonc
|
```jsonc
|
||||||
@ -207,17 +212,57 @@ If you use error lens, I recommend the following settings
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
#### Debugging with `gdb`
|
||||||
|
|
||||||
|
You can set up VS Code to run `gdb` and set breakpoints when debugging c++ code. In `launch.json` add the configuration
|
||||||
|
|
||||||
|
```jsonc
|
||||||
|
// ...
|
||||||
|
"configurations": [
|
||||||
|
{
|
||||||
|
"name": "(gdb) Launch",
|
||||||
|
"type": "cppdbg",
|
||||||
|
"request": "launch",
|
||||||
|
"program": "<path to python bin>",
|
||||||
|
"args": [
|
||||||
|
"-m",
|
||||||
|
"pytest",
|
||||||
|
"<test file and test name in pytest format>"
|
||||||
|
],
|
||||||
|
"stopAtEntry": false,
|
||||||
|
"cwd": "path/to/repo/of/pytorch",
|
||||||
|
"environment": [],
|
||||||
|
"externalConsole": false,
|
||||||
|
"MIMode": "gdb",
|
||||||
|
"setupCommands": [
|
||||||
|
{
|
||||||
|
"description": "Enable pretty-printing for gdb",
|
||||||
|
"text": "-enable-pretty-printing",
|
||||||
|
"ignoreFailures": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"description": "Set Disassembly Flavor to Intel",
|
||||||
|
"text": "-gdb-set disassembly-flavor intel",
|
||||||
|
"ignoreFailures": true
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
]
|
||||||
|
```
|
||||||
|
|
||||||
|
You can then set breakpoints in the c++ source and run the debugger in VS Code.
|
||||||
|
|
||||||
## Pull requests
|
## Pull requests
|
||||||
|
|
||||||
PRs should be opened directly against master. PRs can be directly merged into master as long as it satisfies the [ONNX merge rule](https://github.com/pytorch/pytorch/blob/master/.github/merge_rules.json#L3):
|
PRs should be opened directly against master. PRs can be directly merged into master as long as it satisfies the [ONNX merge rule](https://github.com/pytorch/pytorch/blob/master/.github/merge_rules.json#L3):
|
||||||
|
|
||||||
- Approved by one of torch.onnx developers listed in `approved_by` section.
|
* Approved by one of torch.onnx developers listed in `approved_by` section.
|
||||||
- All modified files fall under the `patterns` section.
|
* All modified files fall under the `patterns` section.
|
||||||
|
|
||||||
Pay special attention to the following GitHub checks:
|
Pay special attention to the following GitHub checks:
|
||||||
|
|
||||||
- Has "onnx" in the name, which runs ONNX related tests.
|
* Has "onnx" in the name, which runs ONNX related tests.
|
||||||
- Has "Lint" in the name, which does code format checks.
|
* Has "Lint" in the name, which does code format checks.
|
||||||
|
|
||||||
Regarding other failing checks: if you are certain the failure is unrelated to your change, try rebasing on master. Often these failures are caused by a branch being out of sync with master.
|
Regarding other failing checks: if you are certain the failure is unrelated to your change, try rebasing on master. Often these failures are caused by a branch being out of sync with master.
|
||||||
You can ignore the failing check if it is a regression in master. This can be verified by checking if master is also failing from [CI HUD](https://hud.pytorch.org/ci/pytorch/pytorch/master).
|
You can ignore the failing check if it is a regression in master. This can be verified by checking if master is also failing from [CI HUD](https://hud.pytorch.org/ci/pytorch/pytorch/master).
|
||||||
@ -242,9 +287,9 @@ Most relevant tests are in [test/onnx/](https://github.com/pytorch/pytorch/tree/
|
|||||||
|
|
||||||
The most used test file is [test_pytorch_onnx_onnxruntime.py](https://github.com/pytorch/pytorch/blob/onnx_ms_1/test/onnx/test_pytorch_onnx_onnxruntime.py). The tests in this file generally:
|
The most used test file is [test_pytorch_onnx_onnxruntime.py](https://github.com/pytorch/pytorch/blob/onnx_ms_1/test/onnx/test_pytorch_onnx_onnxruntime.py). The tests in this file generally:
|
||||||
|
|
||||||
- Define a subclass of `torch.nn.Module`.
|
* Define a subclass of `torch.nn.Module`.
|
||||||
- Define some inputs.
|
* Define some inputs.
|
||||||
- Call `self.run_test()` with the instantiated module and inputs.
|
* Call `self.run_test()` with the instantiated module and inputs.
|
||||||
|
|
||||||
`run_test()` converts the module to ONNX and compares the output between PyTorch and ONNX Runtime.
|
`run_test()` converts the module to ONNX and compares the output between PyTorch and ONNX Runtime.
|
||||||
|
|
||||||
@ -267,15 +312,15 @@ python -m pytest -n auto --cov --cov-report "xml:test/coverage.xml" test/onnx/te
|
|||||||
|
|
||||||
# Links
|
# Links
|
||||||
|
|
||||||
- [User-facing docs](https://pytorch.org/docs/master/onnx.html).
|
* [User-facing docs](https://pytorch.org/docs/master/onnx.html).
|
||||||
|
|
||||||
## Relevant parts of PyTorch repo
|
## Relevant parts of PyTorch repo
|
||||||
|
|
||||||
- User-facing doc: [docs/source/onnx.rst](https://github.com/pytorch/pytorch/blob/onnx_ms_1/docs/source/onnx.rst)
|
* User-facing doc: [docs/source/onnx.rst](https://github.com/pytorch/pytorch/blob/onnx_ms_1/docs/source/onnx.rst)
|
||||||
- Python tests: [test/onnx/](https://github.com/pytorch/pytorch/tree/onnx_ms_1/test/onnx)
|
* Python tests: [test/onnx/](https://github.com/pytorch/pytorch/tree/onnx_ms_1/test/onnx)
|
||||||
- More Python tests: [test/jit/test_onnx_export.py](https://github.com/pytorch/pytorch/tree/onnx_ms_1/test/jit/test_onnx_export.py)
|
* More Python tests: [test/jit/test_onnx_export.py](https://github.com/pytorch/pytorch/tree/onnx_ms_1/test/jit/test_onnx_export.py)
|
||||||
- Python code: [torch/onnx/](https://github.com/pytorch/pytorch/tree/onnx_ms_1/torch/onnx)
|
* Python code: [torch/onnx/](https://github.com/pytorch/pytorch/tree/onnx_ms_1/torch/onnx)
|
||||||
- C++ code: [torch/csrc/jit/passes/onnx/](https://github.com/pytorch/pytorch/tree/onnx_ms_1/torch/csrc/jit/passes/onnx)
|
* C++ code: [torch/csrc/jit/passes/onnx/](https://github.com/pytorch/pytorch/tree/onnx_ms_1/torch/csrc/jit/passes/onnx)
|
||||||
|
|
||||||
# Features
|
# Features
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user