Commit 0c888a8
Add
## Describe your changes
Adds a CLI test path for Hugging Face models so generated `config.json`
can carry a lightweight random-model definition instead of always using
pretrained weights. When `--test` is passed, Olive now preserves the
source architecture, instantiates a random model with 2 hidden layers,
and can persist that test model for reuse.
- **CLI/config support**
- Added `--test` to HF-backed CLI commands using shared input-model
options.
- `--test` now accepts an optional folder path where the generated test
model is saved for reuse.
- Emitted `input_model.test_model_config` into generated run configs,
and now also emits `input_model.test_model_path` when a save folder is
provided or derived.
```json
{
"input_model": {
"type": "HfModel",
"model_path": "model-id",
"test_model_config": { "hidden_layers": 2 },
"test_model_path": "path/to/test_model"
}
}
```
- When `--test` is used without an explicit folder, Olive uses
`<output_path>/test_model`.
- If `--test` is used in a context where no output path is available,
Olive now fails clearly instead of silently skipping persistence.
- **`olive run` support**
- Extended `olive run --test` so it can apply the same lightweight HF
test-model override to an existing Hugging Face `input_model` already
present in a workflow config.
- When `olive run --test` is used without an explicit folder, it derives
the saved test-model location from the effective workflow output path.
- `olive run --test` now fails clearly when the workflow config does not
contain a Hugging Face `input_model`.
- **HF model loading**
- Extended HF config loading to accept `test_model_config`.
- Derived a lightweight config from the original model config by
overriding the architecture-specific hidden-layer field
(`num_hidden_layers`, `num_layers`, `n_layer`, `n_layers`).
- For Qwen-style configs that carry per-layer metadata, Olive now also
trims `layer_types` to match the reduced hidden-layer count so the saved
reduced config remains valid when reloaded.
- Switched test-model loading to instantiate from config (`from_config`)
so the model is random-initialized rather than loaded from pretrained
weights.
- Updated the test-model path to fail fast if the selected model class
cannot be instantiated from the reduced config, instead of falling back
to another candidate class that could produce a misleading larger model.
- Refactored the `from_config` loading path to avoid nested `try/except`
handling by only passing `trust_remote_code` when the model class
signature supports it.
- Added persistence/reuse support for test models: if `test_model_path`
already contains a saved HF model, Olive loads that model instead of
recreating it; otherwise it creates the reduced model once and saves it
there.
- **ModelBuilder support**
- Updated the ModelBuilder pass so `--test` workflows export from the
saved reduced Hugging Face test checkpoint instead of still using the
original full checkpoint.
- When `test_model_config` is present, ModelBuilder now materializes or
reuses `test_model_path` before export and passes that saved checkpoint
to the builder.
- This fixes the smoke-test flow so it avoids the original full-model
dtype path instead of only deferring the same failure.
- **IO config / dummy input propagation**
- Threaded `test_model_config` through HF IO-config and dummy-input
generation so the reduced-layer model shape metadata stays consistent
with the generated test model.
- **Documentation**
- Added a new how-to page showing how to convert a Qwen LLM with a quick
`--test` smoke check first, then rerun the full conversion.
- Linked the new how-to page from the docs How Tos index.
- Updated the how-to flow to use `olive optimize --dry_run` followed by
`olive run --test`, matching the new CLI support.
- Clarified the smoke-test commands so the generated ONNX artifacts are
written to a dedicated output folder and are easy to find.
- Updated the example model from Phi to `Qwen/Qwen3-0.6B` and renamed
the how-to page and index entry to match.
- **Merge conflict resolution**
- Merged `origin/main` into this PR branch and resolved the conflict in
`test/passes/onnx/test_model_builder.py`.
- Preserved both the upstream `ModelBuilder` fallback/multi-file output
test coverage and this PR's saved test-model-path coverage.
- Updated the upstream mock-based `ModelBuilder` tests to define the new
Hugging Face test-model attributes used by this PR (`test_model_config`
and `test_model_path`).
- **Targeted coverage**
- Added focused tests for:
- CLI config generation with `--test`
- input-model config serialization of `test_model_config`
- input-model config serialization of `test_model_path`
- validation when `--test` needs an explicit folder
- `olive run --test` overriding an existing HF `input_model` from a
workflow config
- validation when `olive run --test` is used on a non-HF workflow config
- HF random-model instantiation for multiple config naming conventions
- fail-fast behavior when test-model instantiation cannot use the
expected model class
- conditional `trust_remote_code` handling for supported, omitted, and
unsupported `from_config` signatures
- saving and reusing a persisted HF test model
- ModelBuilder exporting from the saved reduced test-model checkpoint
when `test_model_config` is active
- a CLI smoke-flow test that follows the documented `olive optimize
--dry_run` then `olive run --test` commands with
`hf-internal-testing/tiny-random-LlamaForCausalLM` and verifies an ONNX
artifact is produced
- a Qwen3 regression test that verifies reduced test-model configs keep
`layer_types` aligned with the reduced hidden-layer count and can be
reloaded successfully
- conflict-resolved `ModelBuilder` tests covering saved test-model
reuse, single-file annotation fallback, and multi-file output component
naming
Examples:
```bash
olive optimize \
-m Qwen/Qwen3-0.6B \
--test out/test_model \
--dry_run \
-o out
```
```bash
olive run \
--config out/config.json \
--test out/test_model \
--output_path out/qwen-smoke-run
```
## Checklist before requesting a review
- [x] Add unit tests for this change.
- [x] Make sure all tests can pass.
- [x] Update documents if necessary.
- [x] Lint and apply fixes to your code by running `lintrunner -a`
- [x] Is this a user-facing change? If yes, give a description of this
change to be included in the release notes.
Release notes: Added a `--test` option for Hugging Face CLI workflows
that can take a folder path, writes a lightweight 2-layer random-model
config, saves and reuses the generated HF test model from that folder,
fails fast if the reduced test model cannot be instantiated from the
expected model class, only passes `trust_remote_code` when the target
`from_config` supports it, and now keeps Qwen-style `layer_types`
metadata aligned with reduced test-model layer counts so saved reduced
configs reload cleanly. Also added `olive run --test` support for
workflow configs with Hugging Face input models, updated ModelBuilder to
export from the saved reduced test checkpoint for `--test` flows, and
added a Qwen3 0.6B how-to page for running a quick smoke test before the
full conversion with an explicit output path for the generated ONNX
files.
## (Optional) Issue link
---------
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: xadupre <22452781+xadupre@users.noreply.github.com>
Co-authored-by: Xavier Dupré <xadupre@microsoft.com>
Co-authored-by: Xavier Dupré <xadupre@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>--test HF CLI path for 2-layer random model configs, olive run and ModelBuilder support, Qwen how-to/layer-types fix, and merge conflict resolution (microsoft#2459)1 parent 04ef7d2 commit 0c888a8
16 files changed
Lines changed: 1009 additions & 20 deletions
File tree
- .github/workflows
- docs/source/how-to
- cli
- olive
- cli
- common/hf
- model/handler
- mixin
- passes/onnx
- test
- cli
- common
- model
- passes/onnx
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
| 15 | + | |
15 | 16 | | |
16 | 17 | | |
17 | 18 | | |
| |||
43 | 44 | | |
44 | 45 | | |
45 | 46 | | |
| 47 | + | |
46 | 48 | | |
47 | 49 | | |
48 | 50 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
17 | 17 | | |
18 | 18 | | |
19 | 19 | | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
20 | 66 | | |
21 | 67 | | |
22 | 68 | | |
| |||
33 | 79 | | |
34 | 80 | | |
35 | 81 | | |
| 82 | + | |
36 | 83 | | |
37 | 84 | | |
38 | 85 | | |
39 | 86 | | |
40 | 87 | | |
41 | 88 | | |
42 | 89 | | |
| 90 | + | |
| 91 | + | |
43 | 92 | | |
44 | 93 | | |
45 | 94 | | |
| 95 | + | |
| 96 | + | |
46 | 97 | | |
47 | 98 | | |
48 | 99 | | |
| |||
82 | 133 | | |
83 | 134 | | |
84 | 135 | | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
85 | 151 | | |
86 | 152 | | |
87 | 153 | | |
| |||
105 | 171 | | |
106 | 172 | | |
107 | 173 | | |
108 | | - | |
| 174 | + | |
109 | 175 | | |
110 | 176 | | |
111 | 177 | | |
| |||
371 | 437 | | |
372 | 438 | | |
373 | 439 | | |
| 440 | + | |
| 441 | + | |
| 442 | + | |
| 443 | + | |
| 444 | + | |
| 445 | + | |
| 446 | + | |
| 447 | + | |
| 448 | + | |
| 449 | + | |
374 | 450 | | |
375 | 451 | | |
376 | 452 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
| 9 | + | |
9 | 10 | | |
10 | 11 | | |
11 | 12 | | |
12 | 13 | | |
| 14 | + | |
| 15 | + | |
13 | 16 | | |
14 | 17 | | |
15 | 18 | | |
| |||
59 | 62 | | |
60 | 63 | | |
61 | 64 | | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
62 | 73 | | |
63 | 74 | | |
64 | 75 | | |
| |||
68 | 79 | | |
69 | 80 | | |
70 | 81 | | |
| 82 | + | |
| 83 | + | |
71 | 84 | | |
72 | 85 | | |
73 | 86 | | |
74 | 87 | | |
75 | 88 | | |
76 | 89 | | |
| 90 | + | |
| 91 | + | |
77 | 92 | | |
78 | 93 | | |
79 | 94 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
27 | 27 | | |
28 | 28 | | |
29 | 29 | | |
| 30 | + | |
30 | 31 | | |
31 | 32 | | |
32 | 33 | | |
| |||
35 | 36 | | |
36 | 37 | | |
37 | 38 | | |
| 39 | + | |
38 | 40 | | |
39 | 41 | | |
40 | 42 | | |
| |||
68 | 70 | | |
69 | 71 | | |
70 | 72 | | |
71 | | - | |
| 73 | + | |
72 | 74 | | |
73 | 75 | | |
74 | 76 | | |
| |||
92 | 94 | | |
93 | 95 | | |
94 | 96 | | |
| 97 | + | |
95 | 98 | | |
96 | 99 | | |
97 | 100 | | |
| |||
100 | 103 | | |
101 | 104 | | |
102 | 105 | | |
| 106 | + | |
103 | 107 | | |
104 | 108 | | |
105 | 109 | | |
| |||
133 | 137 | | |
134 | 138 | | |
135 | 139 | | |
136 | | - | |
| 140 | + | |
137 | 141 | | |
138 | 142 | | |
139 | 143 | | |
| |||
0 commit comments