Skip to content

Add --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#2459

Open
Copilot wants to merge 63 commits into
mainfrom
copilot/fr-add-model-to-config-json
Open

Add --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#2459
Copilot wants to merge 63 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.
  • 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:

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
Copilot AI requested a review from xadupre May 25, 2026 14:58
@xadupre
Copy link
Copy Markdown
Member

xadupre commented May 25, 2026

/azp run

@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines successfully started running 1 pipeline(s).

Comment thread docs/source/how-to/cli/cli-fast-test.md
@xadupre
Copy link
Copy Markdown
Member

xadupre commented May 25, 2026

/azp run

@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines successfully started running 1 pipeline(s).

Comment thread olive/common/hf/utils.py Fixed
Comment thread test/cli/test_cli_test_model_smoke.py Fixed
Comment thread test/cli/test_cli_test_model_smoke.py Fixed
Comment thread test/cli/test_cli_test_model_smoke.py Fixed
Comment thread test/common/test_hf.py Fixed
Comment thread test/cli/test_cli_test_model_smoke.py Fixed
Comment thread test/cli/test_cli_test_model_smoke.py Fixed
Comment thread olive/common/hf/utils.py Fixed
…ments in a call'

Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
@xadupre
Copy link
Copy Markdown
Member

xadupre commented May 26, 2026

/azp run

@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines successfully started running 1 pipeline(s).

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 16 out of 16 changed files in this pull request and generated 4 comments.

Comment thread olive/cli/run.py Outdated
Comment thread olive/common/hf/utils.py Outdated
Comment thread test/cli/test_cli_test_model_smoke.py Outdated
Comment thread olive/cli/base.py
xadupre and others added 4 commits May 26, 2026 12:28
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@xadupre
Copy link
Copy Markdown
Member

xadupre commented May 26, 2026

/azp run

@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines successfully started running 1 pipeline(s).

@xadupre
Copy link
Copy Markdown
Member

xadupre commented May 26, 2026

/azp run

@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines successfully started running 1 pipeline(s).

Comment thread .github/workflows/test-model-fast.yml
@xadupre
Copy link
Copy Markdown
Member

xadupre commented May 27, 2026

/azp run

@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines successfully started running 1 pipeline(s).

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

6 participants