|
| 1 | +# Qualcomm Observatory CLI |
| 2 | + |
| 3 | +Qualcomm-specific Observatory CLI that wraps `devtools/observatory` with QNN backend patches and |
| 4 | +accuracy lenses. Requires a QNN SDK environment (source `$QNN_SDK_ROOT/bin/envsetup.sh` before |
| 5 | +running on-device jobs). |
| 6 | + |
| 7 | +## Usage |
| 8 | + |
| 9 | +### Collection mode (default) |
| 10 | + |
| 11 | +```bash |
| 12 | +python -m executorch.backends.qualcomm.debugger.observatory \ |
| 13 | + [--output-html PATH] [--output-json PATH] SCRIPT [SCRIPT_ARGS...] |
| 14 | +``` |
| 15 | + |
| 16 | +### With accuracy debugging |
| 17 | + |
| 18 | +```bash |
| 19 | +python -m executorch.backends.qualcomm.debugger.observatory \ |
| 20 | + --lens_recipe=accuracy \ |
| 21 | + [--output-html PATH] [--output-json PATH] \ |
| 22 | + SCRIPT [SCRIPT_ARGS...] |
| 23 | +``` |
| 24 | + |
| 25 | +### Visualize mode (JSON → HTML, no re-execution) |
| 26 | + |
| 27 | +```bash |
| 28 | +python -m executorch.backends.qualcomm.debugger.observatory visualize \ |
| 29 | + --input-json report.json --output-html report.html |
| 30 | +``` |
| 31 | + |
| 32 | +## Qualcomm examples |
| 33 | + |
| 34 | +Qualcomm example scripts use only absolute imports and live in directories without `__init__.py`, |
| 35 | +so the Observatory CLI runs them as plain scripts via `runpy.run_path` (no special invocation |
| 36 | +needed). |
| 37 | + |
| 38 | +### Vision model (ImageNet) |
| 39 | + |
| 40 | +```bash |
| 41 | +source $QNN_SDK_ROOT/bin/envsetup.sh |
| 42 | + |
| 43 | +python -m executorch.backends.qualcomm.debugger.observatory \ |
| 44 | + --output-html /tmp/obs_vit/report.html \ |
| 45 | + --output-json /tmp/obs_vit/report.json \ |
| 46 | + --lens_recipe=accuracy \ |
| 47 | + examples/qualcomm/scripts/torchvision_vit.py \ |
| 48 | + -m SM8650 -b ./build-android \ |
| 49 | + --dataset imagenet-mini-val/ \ |
| 50 | + -H mlgtw-linux -s <device_serial> \ |
| 51 | + -a /tmp/obs_vit --seed 1126 --compile_only |
| 52 | +``` |
| 53 | + |
| 54 | +### NLP model (Wikipedia sentences) |
| 55 | + |
| 56 | +```bash |
| 57 | +python -m executorch.backends.qualcomm.debugger.observatory \ |
| 58 | + --output-html /tmp/obs_roberta/report.html \ |
| 59 | + --lens_recipe=accuracy \ |
| 60 | + examples/qualcomm/oss_scripts/roberta.py \ |
| 61 | + -m SM8650 -b ./build-android \ |
| 62 | + -H mlgtw-linux -s <device_serial> \ |
| 63 | + -a /tmp/obs_roberta --compile_only |
| 64 | +``` |
| 65 | + |
| 66 | +### Compile-only (no device required) |
| 67 | + |
| 68 | +Add `--compile_only` to any Qualcomm script to export and lower without pushing to device. |
| 69 | +This is useful for inspecting the compilation pipeline in CI or on a dev machine. |
| 70 | + |
| 71 | +## Available example scripts |
| 72 | + |
| 73 | +### `examples/qualcomm/scripts/` — vision models |
| 74 | + |
| 75 | +| Script | Model | |
| 76 | +|---|---| |
| 77 | +| `torchvision_vit.py` | Vision Transformer | |
| 78 | +| `mobilenet_v2.py` | MobileNetV2 | |
| 79 | +| `mobilenet_v3.py` | MobileNetV3 | |
| 80 | +| `inception_v3.py` | InceptionV3 | |
| 81 | +| `inception_v4.py` | InceptionV4 | |
| 82 | + |
| 83 | +Dataset: ImageNet (pass with `--dataset <path>` or `-d <path>`). |
| 84 | + |
| 85 | +### `examples/qualcomm/oss_scripts/` — NLP/open-source models |
| 86 | + |
| 87 | +| Script | Model | |
| 88 | +|---|---| |
| 89 | +| `roberta.py` | RoBERTa | |
| 90 | +| `bert.py` | BERT | |
| 91 | +| `albert.py` | ALBERT | |
| 92 | +| `distilbert.py` | DistilBERT | |
| 93 | +| `eurobert.py` | EuroBERT | |
| 94 | + |
| 95 | +Dataset: Wikipedia sentences (`wikisent2.txt`). Pass with `-d <path>`. |
| 96 | + |
| 97 | +Common flags: `-m <SOC_MODEL>` (e.g. `SM8650`), `-b <build_folder>`, `-H <host>`, |
| 98 | +`-s <device_serial>`, `-a <artifact_dir>`, `--compile_only`. |
| 99 | + |
| 100 | +## Accuracy lenses (`--lens_recipe=accuracy`) |
| 101 | + |
| 102 | +Registers `AccuracyLens` and `PerLayerAccuracyLens` (with QNN dataset patches) on top of the |
| 103 | +default `PipelineGraphCollectorLens`. These produce: |
| 104 | + |
| 105 | +- Per-stage accuracy metrics (PSNR, cosine similarity, MSE, top-k) |
| 106 | +- Per-layer accuracy heat-map overlaid on the graph |
| 107 | +- Cross-stage diff labels in the left panel of the HTML report |
| 108 | + |
| 109 | +QNN dataset patches (`lenses/qnn_dataset_patches.py`) wire the on-device inference output back |
| 110 | +into the accuracy lens so metrics reflect true QNN outputs, not emulated CPU results. |
| 111 | + |
| 112 | +## Two-step workflow |
| 113 | + |
| 114 | +Collect on-device in CI, visualize locally without re-running: |
| 115 | + |
| 116 | +```bash |
| 117 | +# Step 1 — collect (e.g., in CI with device attached) |
| 118 | +python -m executorch.backends.qualcomm.debugger.observatory \ |
| 119 | + --output-html /tmp/obs/report.html \ |
| 120 | + --output-json /tmp/obs/report.json \ |
| 121 | + examples/qualcomm/scripts/torchvision_vit.py \ |
| 122 | + -m SM8650 -b ./build-android -d imagenet-mini-val/ \ |
| 123 | + -H mlgtw-linux -s <device_serial> -a /tmp/obs |
| 124 | + |
| 125 | +# Step 2 — re-generate HTML from JSON (e.g., locally after lens update) |
| 126 | +python -m executorch.backends.qualcomm.debugger.observatory visualize \ |
| 127 | + --input-json /tmp/obs/report.json \ |
| 128 | + --output-html /tmp/obs/report_v2.html |
| 129 | +``` |
| 130 | + |
| 131 | +## Backend patches |
| 132 | + |
| 133 | +`lenses/qnn_patches.py` installs a monkey-patch on `ptq_calibrate` so the |
| 134 | +`PipelineGraphCollectorLens` can intercept the QNN quantization calibration stage and capture |
| 135 | +the graph at that point. The patch is active only while the Observatory context is open. |
| 136 | + |
| 137 | +`lenses/qnn_dataset_patches.py` wires on-device inference results into `AccuracyLens` so that |
| 138 | +accuracy metrics use real QNN outputs. |
| 139 | + |
| 140 | +## See also |
| 141 | + |
| 142 | +- `backends/qualcomm/debugger/README.md` — broader Qualcomm debugger overview (QAIRT visualizer, |
| 143 | + intermediate output debugger) |
| 144 | +- `devtools/observatory/README.md` — framework overview, Python API, custom lens guide |
| 145 | +- `devtools/observatory/USAGE.md` — full CLI reference |
| 146 | +- `devtools/observatory/lenses/LENSES.md` — built-in lens details |
0 commit comments