Skip to content

Commit b6b701e

Browse files
Arm backend: Add docgen script to pre-push hook (pytorch#18284)
This will make sure the generated docs don't drift from the actual documentation. Signed-off-by: Sebastian Larsson <sebastian.larsson@arm.com>
1 parent b1373e8 commit b6b701e

5 files changed

Lines changed: 74 additions & 4 deletions

File tree

backends/arm/scripts/docgen/docgen.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,8 @@ def generate_document(job: DocumentationJob):
123123

124124
content = content.replace(job.placeholder, job.replacement_text)
125125

126-
# Remove multiple new lines at end of document if it exists
127-
if content.endswith("\n\n"):
126+
# Normalize generated docs to a single trailing newline.
127+
while content.endswith("\n\n"):
128128
content = content.removesuffix("\n")
129129

130130
with open(job.output_path, "w") as f:

backends/arm/scripts/docgen/vgf/backends-arm-vgf-overview.md.in

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,8 @@ described in the rest of this guide but with a concrete end-to-end sample.
8181

8282
**→{doc}`/backends/arm-vgf/tutorials/arm-vgf-tutorials` — Tutorials.**
8383

84+
**→{doc}`/backends/arm-vgf/VGF_op_support` — VGF supported operators.**
85+
8486

8587
```{toctree}
8688
:maxdepth: 2
@@ -91,4 +93,5 @@ arm-vgf-partitioner
9193
arm-vgf-quantization
9294
arm-vgf-troubleshooting
9395
tutorials/arm-vgf-tutorials
96+
VGF_op_support
9497
```

backends/arm/scripts/pre-push

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,55 @@ WARNING="${YELLOW}[WARNING]${RESET}"
2121
ERROR="${RED}[ERROR]${RESET}"
2222
SUCCESS="${GREEN}[SUCCESS]${RESET}"
2323

24+
DOCGEN_OUTPUTS=(
25+
"docs/source/backends/arm-ethos-u/arm-ethos-u-overview.md"
26+
"docs/source/backends/arm-ethos-u/arm-ethos-u-partitioner.md"
27+
"docs/source/backends/arm-ethos-u/arm-ethos-u-quantization.md"
28+
"docs/source/backends/arm-ethos-u/tutorials/ethos-u-getting-started.md"
29+
"docs/source/backends/arm-vgf/arm-vgf-overview.md"
30+
"docs/source/backends/arm-vgf/arm-vgf-partitioner.md"
31+
"docs/source/backends/arm-vgf/arm-vgf-quantization.md"
32+
"docs/source/backends/arm-vgf/tutorials/vgf-getting-started.md"
33+
)
34+
35+
RUN_DOCGEN=0
36+
37+
is_docgen_trigger_file() {
38+
local file_path="$1"
39+
case "${file_path}" in
40+
backends/arm/common/arm_compile_spec.py|\
41+
backends/arm/ethosu/*.py|\
42+
backends/arm/quantizer/*.py|\
43+
backends/arm/scripts/docgen/*|\
44+
backends/arm/tosa/partitioner.py|\
45+
backends/arm/vgf/*.py|\
46+
examples/arm/ethos_u_minimal_example.ipynb|\
47+
examples/arm/vgf_minimal_example.ipynb)
48+
return 0
49+
;;
50+
esac
51+
return 1
52+
}
53+
54+
run_docgen_check() {
55+
echo -e "${INFO} Running Arm docgen"
56+
env/bin/python backends/arm/scripts/docgen/docgen.py
57+
if [[ $? -ne 0 ]]; then
58+
echo -e "${ERROR} Failed to run Arm docgen"
59+
FAILED=1
60+
return
61+
fi
62+
63+
if ! git diff --quiet HEAD -- "${DOCGEN_OUTPUTS[@]}"; then
64+
echo -e "${ERROR} Arm docgen updated generated documentation." >&2
65+
echo -e "${INFO} Review and commit the regenerated docs before pushing."
66+
git diff HEAD -- "${DOCGEN_OUTPUTS[@]}"
67+
FAILED=1
68+
else
69+
echo -e "${SUCCESS} Arm docgen OK"
70+
fi
71+
}
72+
2473
# This list of imperative verbs was compiled from the entire list of Executorch
2574
# commits. It should be fairly exhaustive, but add more verbs if you find one
2675
# that's missing.
@@ -92,6 +141,14 @@ for COMMIT in ${COMMITS}; do
92141

93142
commit_files=$(git diff-tree --no-commit-id --name-only \
94143
--diff-filter=ACMR ${COMMIT} -r)
144+
if [[ $RUN_DOCGEN -eq 0 ]]; then
145+
for committed_file in $commit_files; do
146+
if is_docgen_trigger_file "${committed_file}"; then
147+
RUN_DOCGEN=1
148+
break
149+
fi
150+
done
151+
fi
95152

96153
# Check license headers
97154
# We do a simple check of if all committed headers contain
@@ -258,6 +315,12 @@ for COMMIT in ${COMMITS}; do
258315
echo "" # Newline to visually separate commit processing
259316
done
260317

318+
if [[ $RUN_DOCGEN -eq 1 ]]; then
319+
run_docgen_check
320+
else
321+
echo -e "${INFO} Skipping Arm docgen (no public API inputs changed)"
322+
fi
323+
261324
if [[ $FAILED ]]; then
262325
echo -e "${INFO} Fix your commit message errors with"\
263326
"'git commit --amend' or 'git commit --fixup=<SHA>'"

docs/source/backends/arm-ethos-u/arm-ethos-u-quantization.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ Args:
2525
Ethos-U targets.
2626

2727
```python
28-
def EthosUQuantizer.quantize_with_submodules(self, model: 'GraphModule', calibration_samples: 'list[tuple]', is_qat: 'bool' = False):
28+
def EthosUQuantizer.quantize_with_submodules(self, model: 'GraphModule', calibration_samples: 'list[tuple]', is_qat: 'bool' = False, fold_quantize: 'bool' = True):
2929
```
3030
Quantizes a GraphModule in a way such that conditional submodules are
3131
handled properly.
@@ -41,6 +41,8 @@ Args:
4141
model with submodules, at least one sample per code path is
4242
needed.
4343
- **is_qat (bool)**: Whether to do quantization aware training or not.
44+
- **fold_quantize (bool)**: Enables or disables constant folding when quantization
45+
is completed.
4446

4547
Returns:
4648
- **GraphModule**: The quantized model.

docs/source/backends/arm-vgf/arm-vgf-quantization.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ Args:
4444
targets.
4545

4646
```python
47-
def VgfQuantizer.quantize_with_submodules(self, model: 'GraphModule', calibration_samples: 'list[tuple]', is_qat: 'bool' = False):
47+
def VgfQuantizer.quantize_with_submodules(self, model: 'GraphModule', calibration_samples: 'list[tuple]', is_qat: 'bool' = False, fold_quantize: 'bool' = True):
4848
```
4949
Quantizes a GraphModule in a way such that conditional submodules are
5050
handled properly.
@@ -60,6 +60,8 @@ Args:
6060
model with submodules, at least one sample per code path is
6161
needed.
6262
- **is_qat (bool)**: Whether to do quantization aware training or not.
63+
- **fold_quantize (bool)**: Enables or disables constant folding when quantization
64+
is completed.
6365

6466
Returns:
6567
- **GraphModule**: The quantized model.

0 commit comments

Comments
 (0)