Skip to content

Add --test HF CLI path for 2-layer random model configs, olive run and ModelBuilder support, and Qwen how-to/layer-types fix#2459

Draft
Copilot wants to merge 33 commits into
mainfrom
copilot/fr-add-model-to-config-json
Draft

Add --test HF CLI path for 2-layer random model configs, olive run and ModelBuilder support, and Qwen how-to/layer-types fix#2459
Copilot wants to merge 33 commits into
mainfrom
copilot/fr-add-model-to-config-json

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented May 11, 2026

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.
      {
        "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.
  • 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

Examples:

olive optimize \
  -m Qwen/Qwen3-0.6B \
  --test out/test_model \
  --dry_run \
  -o out
olive run \
  --config out/config.json \
  --test out/test_model \
  --output_path out/qwen-smoke-run

Checklist before requesting a review

  • Add unit tests for this change.
  • Make sure all tests can pass.
  • Update documents if necessary.
  • Lint and apply fixes to your code by running lintrunner -a
  • 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

Copilot AI and others added 3 commits May 11, 2026 08:33
Agent-Logs-Url: https://github.com/microsoft/Olive/sessions/e2149604-9db1-438e-a31f-01a53886093d

Co-authored-by: xadupre <22452781+xadupre@users.noreply.github.com>
Agent-Logs-Url: https://github.com/microsoft/Olive/sessions/e2149604-9db1-438e-a31f-01a53886093d

Co-authored-by: xadupre <22452781+xadupre@users.noreply.github.com>
Agent-Logs-Url: https://github.com/microsoft/Olive/sessions/e2149604-9db1-438e-a31f-01a53886093d

Co-authored-by: xadupre <22452781+xadupre@users.noreply.github.com>
Copilot AI changed the title [WIP] Add section in config.json for random model with 2 hidden layers Add --test HF CLI path for 2-layer random model configs May 11, 2026
Copilot AI requested a review from xadupre May 11, 2026 08:39
Comment thread olive/common/hf/utils.py Outdated
Agent-Logs-Url: https://github.com/microsoft/Olive/sessions/d4221aaf-b4a3-4bed-85fe-30a12dcdfd6e

Co-authored-by: xadupre <22452781+xadupre@users.noreply.github.com>
Copilot AI changed the title Add --test HF CLI path for 2-layer random model configs Add --test HF CLI path for 2-layer random model configs with fail-fast loading May 11, 2026
Copilot AI requested a review from xadupre May 11, 2026 09:22
Copilot AI and others added 2 commits May 11, 2026 09:35
Comment thread olive/cli/base.py
Copilot AI and others added 3 commits May 11, 2026 10:56
Agent-Logs-Url: https://github.com/microsoft/Olive/sessions/cf4d7fdc-1de9-4098-adc3-3bedd436d7d0

Co-authored-by: xadupre <22452781+xadupre@users.noreply.github.com>
Agent-Logs-Url: https://github.com/microsoft/Olive/sessions/cf4d7fdc-1de9-4098-adc3-3bedd436d7d0

Co-authored-by: xadupre <22452781+xadupre@users.noreply.github.com>
Agent-Logs-Url: https://github.com/microsoft/Olive/sessions/cf4d7fdc-1de9-4098-adc3-3bedd436d7d0

Co-authored-by: xadupre <22452781+xadupre@users.noreply.github.com>
Copilot AI changed the title Add --test HF CLI path for 2-layer random model configs with fail-fast loading Add --test HF CLI path for 2-layer random model configs with reusable saved test models May 11, 2026
Copilot AI requested a review from xadupre May 11, 2026 11:03
Comment thread test/common/test_hf.py Fixed
Comment thread test/common/test_hf.py Fixed
Comment thread test/common/test_hf.py Fixed
Comment thread test/common/test_hf.py Fixed
Comment thread test/common/test_hf.py Fixed
Comment thread test/common/test_hf.py Fixed
Comment thread test/common/test_hf.py Fixed
Comment thread test/common/test_hf.py Fixed
Comment thread docs/source/how-to/cli/cli-convert-qwen-test.md
Agent-Logs-Url: https://github.com/microsoft/Olive/sessions/c25a0cd6-d252-4e16-8783-52a5be97f14e

Co-authored-by: xadupre <22452781+xadupre@users.noreply.github.com>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented May 11, 2026

@copilot can you write one how-to page about converting a LLM (one phi for example) and use the option test to quickly check it works first

Updated in 9ba38c7. The Phi how-to page is in place and now also uses a dedicated smoke-test output folder so the generated ONNX artifacts are easy to find.

Copilot AI changed the title Add --test HF CLI path for 2-layer random model configs, olive run support, and Phi how-to Add --test HF CLI path for 2-layer random model configs, olive run and ModelBuilder support, and Phi how-to May 11, 2026
Copilot AI requested a review from xadupre May 11, 2026 14:44
Agent-Logs-Url: https://github.com/microsoft/Olive/sessions/acc48c65-2f6d-44c0-80c1-271e83838437

Co-authored-by: xadupre <22452781+xadupre@users.noreply.github.com>
Copilot AI changed the title Add --test HF CLI path for 2-layer random model configs, olive run and ModelBuilder support, and Phi how-to Add --test HF CLI path for 2-layer random model configs, olive run and ModelBuilder support, and Qwen how-to May 11, 2026
Comment thread test/cli/test_cli.py
Copilot AI and others added 8 commits May 11, 2026 15:14
Agent-Logs-Url: https://github.com/microsoft/Olive/sessions/c421adc3-0615-4d10-bf15-b21d632d70b2

Co-authored-by: xadupre <22452781+xadupre@users.noreply.github.com>
Agent-Logs-Url: https://github.com/microsoft/Olive/sessions/c421adc3-0615-4d10-bf15-b21d632d70b2

Co-authored-by: xadupre <22452781+xadupre@users.noreply.github.com>
Agent-Logs-Url: https://github.com/microsoft/Olive/sessions/c421adc3-0615-4d10-bf15-b21d632d70b2

Co-authored-by: xadupre <22452781+xadupre@users.noreply.github.com>
Agent-Logs-Url: https://github.com/microsoft/Olive/sessions/c421adc3-0615-4d10-bf15-b21d632d70b2

Co-authored-by: xadupre <22452781+xadupre@users.noreply.github.com>
Agent-Logs-Url: https://github.com/microsoft/Olive/sessions/c421adc3-0615-4d10-bf15-b21d632d70b2

Co-authored-by: xadupre <22452781+xadupre@users.noreply.github.com>
Agent-Logs-Url: https://github.com/microsoft/Olive/sessions/c421adc3-0615-4d10-bf15-b21d632d70b2

Co-authored-by: xadupre <22452781+xadupre@users.noreply.github.com>
Agent-Logs-Url: https://github.com/microsoft/Olive/sessions/c421adc3-0615-4d10-bf15-b21d632d70b2

Co-authored-by: xadupre <22452781+xadupre@users.noreply.github.com>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented May 11, 2026

Just as a heads up, I was blocked by some firewall rules while working on your feedback. Expand below for details.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • huggingface.co
    • Triggering command: /usr/bin/python python - (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Copilot AI requested a review from xadupre May 11, 2026 15:32
Use the generated config with `olive run` and pass `--test` so Olive swaps in a reduced random Qwen model.

```bash
olive run \
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot this command generates ValueError: num_hidden_layers (2) must be equal to the number of layer types (28)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in ac7840f. The --test config reduction now trims Qwen layer_types to match the reduced hidden-layer count, and I added a regression test covering reload of the reduced Qwen3 config.

Agent-Logs-Url: https://github.com/microsoft/Olive/sessions/5bd5199d-42fa-4109-94a3-c7995abe72a2

Co-authored-by: xadupre <22452781+xadupre@users.noreply.github.com>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented May 11, 2026

Just as a heads up, I was blocked by some firewall rules while working on your feedback. Expand below for details.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • huggingface.co
    • Triggering command: /home/REDACTED/work/_temp/ghcca-node/node/bin/node /home/REDACTED/work/_temp/ghcca-node/node/bin/node --enable-source-maps /home/REDACTED/work/_temp/copilot-developer-action-main/dist/index.js (dns block)
    • Triggering command: /usr/bin/python python - (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Copilot AI changed the title Add --test HF CLI path for 2-layer random model configs, olive run and ModelBuilder support, and Qwen how-to Add --test HF CLI path for 2-layer random model configs, olive run and ModelBuilder support, and Qwen how-to/layer-types fix May 11, 2026
Copilot AI requested a review from xadupre May 11, 2026 17:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[FR]: add a section in config.json which defines a random model following the same architecture with 2 hidden layers

3 participants