Skip to content

Commit 0581331

Browse files
BowenBaopytorchmergebot
authored andcommitted
[ONNX] Document ONNX diagnostics (pytorch#88371)
Reference pages: - Landing page: https://docs-preview.pytorch.org/88371/onnx_diagnostics.html - Individual rule: https://docs-preview.pytorch.org/88371/generated/onnx_diagnostics_rules/POE0004%3Aoperator-supported-in-newer-opset-version.html An initial PR to setup the document generation for ONNX diagnostics. * Add document page for ONNX diagnostics. * Add document generation for diagnostics rules from `rules.yaml`. * Add dependency on `myst-parser` for markdown to rst parsing. More content to be added. Pull Request resolved: pytorch#88371 Approved by: https://github.com/abock, https://github.com/justinchuby, https://github.com/malfet, https://github.com/kit1980
1 parent 848e724 commit 0581331

File tree

6 files changed

+80
-4
lines changed

6 files changed

+80
-4
lines changed

docs/Makefile

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,9 @@ figures:
1717
@$(PYCMD) source/scripts/build_activation_images.py
1818
@$(PYCMD) source/scripts/build_quantization_configs.py
1919

20-
onnx_supported_aten_ops:
20+
onnx:
2121
@$(PYCMD) source/scripts/onnx/build_onnx_supported_aten_op_csv_table.py
22+
@$(PYCMD) source/scripts/onnx/build_onnx_diagnostics_rules_md.py $(SOURCEDIR)/generated/onnx_diagnostics_rules
2223

2324
docset: html
2425
doc2dash --name $(SPHINXPROJ) --icon $(SOURCEDIR)/_static/img/pytorch-logo-flame.png --enable-js --online-redirect-url https://pytorch.org/docs/ --force $(BUILDDIR)/html/
@@ -34,11 +35,11 @@ html-stable:
3435
# See conf.py for more details.
3536
RELEASE=1 make html
3637

37-
.PHONY: help Makefile docset onnx_supported_aten_ops
38+
.PHONY: help Makefile docset onnx
3839

3940
# Catch-all target: route all unknown targets to Sphinx using the new
4041
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
41-
%: Makefile figures onnx_supported_aten_ops
42+
%: Makefile figures onnx
4243
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
4344

4445
clean:

docs/requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,4 @@ tensorboard==2.10.0
1010
python-etcd==0.4.5
1111
sphinx-copybutton==0.5.0
1212
sphinx-panels==0.4.1
13+
myst-parser==0.18.1

docs/source/conf.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,8 @@
5858
'sphinxcontrib.katex',
5959
'sphinx.ext.autosectionlabel',
6060
'sphinx_copybutton',
61-
'sphinx_panels'
61+
'sphinx_panels',
62+
'myst_parser',
6263
]
6364

6465
# build the templated autosummary files

docs/source/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ Features described in this documentation are classified by release status:
8585
profiler
8686
nn.init
8787
onnx
88+
onnx_diagnostics
8889
optim
8990
complex_numbers
9091
ddp_comm_hooks

docs/source/onnx_diagnostics.rst

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
torch.onnx diagnostics
2+
======================
3+
4+
.. contents:: :local:
5+
.. automodule:: torch.onnx._internal.diagnostics
6+
.. currentmodule:: torch.onnx._internal.diagnostics
7+
8+
Overview
9+
--------
10+
11+
NOTE: This feature is underdevelopment and is subject to change.
12+
13+
The goal is to improve the diagnostics to help users debug and improve their model export to ONNX.
14+
15+
- The diagnostics are emitted in machine parsable `Static Analysis Results Interchange Format (SARIF) <https://docs.oasis-open.org/sarif/sarif/v2.1.0/sarif-v2.1.0.html>`__.
16+
- A new clearer, structured way to add new and keep track of diagnostic rules.
17+
- Serve as foundation for more future improvements consuming the diagnostics.
18+
19+
20+
Diagnostic Rules
21+
----------------
22+
23+
.. toctree::
24+
:glob:
25+
26+
generated/onnx_diagnostics_rules/*
27+
28+
API Reference
29+
-------------
30+
31+
.. autoclass:: torch.onnx._internal.diagnostics.ExportDiagnostic
32+
:members:
33+
34+
.. autoclass:: torch.onnx._internal.diagnostics.infra.DiagnosticEngine
35+
:members:
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import argparse
2+
import os
3+
from dataclasses import fields
4+
5+
from torch.onnx._internal import diagnostics
6+
from torch.onnx._internal.diagnostics import infra
7+
8+
9+
def gen_docs(out_dir: str):
10+
os.makedirs(out_dir, exist_ok=True)
11+
for field in fields(diagnostics.rules):
12+
rule = getattr(diagnostics.rules, field.name)
13+
if not isinstance(rule, infra.Rule):
14+
continue
15+
title = f"{rule.id}:{rule.name}"
16+
full_description_markdown = rule.full_description_markdown
17+
assert (
18+
full_description_markdown is not None
19+
), f"Expected {title} to have a full description in markdown"
20+
with open(f"{out_dir}/{title}.md", "w") as f:
21+
f.write(f"# {title}\n")
22+
f.write(full_description_markdown)
23+
24+
25+
def main() -> None:
26+
parser = argparse.ArgumentParser(
27+
description="Generate ONNX diagnostics rules doc in markdown."
28+
)
29+
parser.add_argument(
30+
"out_dir", metavar="OUT_DIR", help="path to output directory for docs"
31+
)
32+
args = parser.parse_args()
33+
gen_docs(args.out_dir)
34+
35+
36+
if __name__ == "__main__":
37+
main()

0 commit comments

Comments
 (0)