Skip to content

Add component inspection API - #378

Merged
justinchuby merged 23 commits into
mainfrom
xiaoyu/inspect-components-api
Aug 20, 2026
Merged

justinchuby merged 23 commits into
mainfrom
xiaoyu/inspect-components-api

Conversation

@xiaoyu-work

Copy link
Copy Markdown
Member

Summary

  • add mobius.inspect_components and ComponentInfo
  • report ModelPackage component names/kinds without building graphs or loading weights
  • include source_path hints for Qwen VL components

Validation

  • PYTHONPATH=$PWD/src conda run -n olive python -m pytest src/mobius/_inspect_test.py -q

Expose inspect_components so external tools can query the ModelPackage components mobius would build without constructing graphs or loading weights.

Co-authored-by: Copilot <[email protected]>
Signed-off-by: Xiaoyu <[email protected]>
@xiaoyu-work
xiaoyu-work requested review from a team and a lite review from Copilot June 25, 2026 04:55
@github-actions

github-actions Bot commented Jun 25, 2026 •

Copy link
Copy Markdown

🏗️ Architecture Diff

Comparing 2481e3c → b7e3e37

Model Sub-model Changes Status
bert (feature-extraction) model 0 ⚪
falcon model 0 ⚪
gemma2 model 0 ⚪
gemma4 (gemma4) decoder 0 ⚪
gemma4 (gemma4) embedding 0 ⚪
gemma4 (gemma4) vision_encoder 0 ⚪
gemma4_text model 0 ⚪
gpt2 model 0 ⚪
llama model 0 ⚪
llama (static-cache) model 0 ⚪
mamba (ssm-text-generation) model 0 ⚪
phi3 model 0 ⚪
phi3 (static-cache) model 0 ⚪
qwen model 0 ⚪
qwen (static-cache) model 0 ⚪
qwen2 model 0 ⚪
qwen2 (static-cache) model 0 ⚪
qwen2_moe model 0 ⚪
qwen2_moe (static-cache) model 0 ⚪
qwen3 model 0 ⚪
qwen3 (static-cache) model 0 ⚪
qwen3_5_moe (hybrid-text-generation) model 0 ⚪
qwen3_5_text (hybrid-text-generation) model 0 ⚪
qwen3_5_vl (hybrid-qwen-vl) decoder 0 ⚪
qwen3_5_vl (hybrid-qwen-vl) embedding 0 ⚪
qwen3_5_vl (hybrid-qwen-vl) vision_encoder 0 ⚪
qwen3_moe model 0 ⚪
qwen3_moe (static-cache) model 0 ⚪
qwen3_next (hybrid-text-generation) model 0 ⚪
t5 (seq2seq) decoder 0 ⚪
t5 (seq2seq) encoder 0 ⚪
whisper (speech-to-text) decoder 0 ⚪
whisper (speech-to-text) encoder 0 ⚪

No architecture changes detected. ✅


Legend: ⚪ No change · 🔵 Minor (attrs/inits) · 🟡 Moderate (nodes added/removed) · 🔴 Major (interface changed)

@github-actions

github-actions Bot commented Jun 25, 2026 •

Copy link
Copy Markdown

Performance Comparison

Comparing 2481e3c → b7e3e37

Model Metric Baseline Current Delta
bert (feature-extraction) model_size_bytes 359 KB 359 KB +0.0% ⚪
bert (feature-extraction) num_nodes 60 60 +0.0% ⚪
falcon model_size_bytes 364 KB 364 KB +0.0% ⚪
falcon num_nodes 66 66 +0.0% ⚪
gemma2 model_size_bytes 428 KB 428 KB +0.0% ⚪
gemma2 num_nodes 105 105 +0.0% ⚪
gpt2 model_size_bytes 388 KB 388 KB +0.0% ⚪
gpt2 num_nodes 54 54 +0.0% ⚪
llama model_size_bytes 425 KB 425 KB +0.0% ⚪
llama num_nodes 60 60 +0.0% ⚪
llama (static-cache) model_size_bytes 425 KB 425 KB +0.0% ⚪
llama (static-cache) num_nodes 56 56 +0.0% ⚪
mamba (ssm-text-generation) model_size_bytes 296 KB 296 KB +0.0% ⚪
mamba (ssm-text-generation) num_nodes 94 94 +0.0% ⚪
phi3 model_size_bytes 421 KB 421 KB +0.0% ⚪
phi3 num_nodes 58 58 +0.0% ⚪
phi3 (static-cache) model_size_bytes 421 KB 421 KB +0.0% ⚪
phi3 (static-cache) num_nodes 54 54 +0.0% ⚪
qwen2 model_size_bytes 425 KB 425 KB +0.0% ⚪
qwen2 num_nodes 60 60 +0.0% ⚪
qwen2 (static-cache) model_size_bytes 425 KB 425 KB +0.0% ⚪
qwen2 (static-cache) num_nodes 56 56 +0.0% ⚪
qwen3_5_moe (hybrid-text-generation) model_size_bytes 506 KB 506 KB +0.0% ⚪
qwen3_5_moe (hybrid-text-generation) num_nodes 264 264 +0.0% ⚪
qwen3_5_text (hybrid-text-generation) model_size_bytes 458 KB 458 KB +0.0% ⚪
qwen3_5_text (hybrid-text-generation) num_nodes 126 126 +0.0% ⚪
qwen3_5_vl (hybrid-qwen-vl) model_size_bytes 977 KB 977 KB +0.0% ⚪
qwen3_5_vl (hybrid-qwen-vl) num_nodes 428 428 +0.0% ⚪
t5 (seq2seq) model_size_bytes 836 KB 836 KB +0.0% ⚪
t5 (seq2seq) num_nodes 166 166 +0.0% ⚪
whisper (speech-to-text) model_size_bytes 1008 KB 1008 KB +0.0% ⚪
whisper (speech-to-text) num_nodes 128 128 +0.0% ⚪

No performance regressions.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Adds a lightweight public inspection API to determine which ModelPackage components a given HuggingFace model_id would produce (and their optimization “roles”) without constructing ONNX graphs or loading weights. This supports external tooling (e.g., Olive) that wants to plan per-component processing ahead of mobius.build().

Changes:

  • Introduces mobius.inspect_components() and ComponentInfo to report component names/kinds (and optional HF source_path hints for Qwen VL families).
  • Implements model-type/task resolution logic sufficient for component inspection (including special-cases like Qwen3.5-MoE-VL detection and wav2vec/CTC → mms mapping).
  • Adds unit tests validating single-component, VLM, encoder-decoder, explicit-task behavior, and error handling; exports API from mobius.__init__.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
src/mobius/_inspect.py New inspect_components API + ComponentInfo, plus Qwen VL source_path hints and task/model_type resolution.
src/mobius/_inspect_test.py Unit tests covering expected component layouts and resolution edge cases.
src/mobius/init.py Exposes inspect_components and ComponentInfo from the package root.

Comment thread src/mobius/_inspect.py
Comment on lines +84 to +87
raise ValueError(
f"Could not load a HuggingFace config for {model_id!r}. inspect_components supports "
"transformers/registry models; diffusers pipelines are not supported."
) from None
@codecov

codecov Bot commented Jun 25, 2026

Copy link
Copy Markdown

The author of this PR, xiaoyu-work, is not an activated member of this organization on Codecov.
Please activate this user on Codecov to display this PR comment.
Coverage data is still being uploaded to Codecov.io for purposes of overall coverage calculations.
Please don't hesitate to email us at [email protected] with any questions.

Comment thread src/mobius/_inspect.py Resolved
xiaoyu-work and others added 7 commits July 6, 2026 16:44
Move component source metadata to registered model classes and resolve layout-specific named_modules paths without instantiating models. Expand static inspection coverage across multimodal, seq2seq, and speech models.
Use the active CUDA 12 package feed as the sole source for ONNX Runtime GPU wheels. Install the GenAI CUDA package without dependency resolution so it cannot replace ORT with the CUDA 13 PyPI wheel.

Copilot-Session: 8f087f94-098a-4cca-8653-436c45150324
Exercise the wav2vec2 ForCTC remap to the MMS registration. This validates the task-resolution branch and restores patch coverage above the CI threshold.

Copilot-Session: 8f087f94-098a-4cca-8653-436c45150324
Bring the PR onto the latest base before addressing the cross-platform test regression introduced on main.

Copilot-Session: 8f087f94-098a-4cca-8653-436c45150324
Save parity-test models into temporary directories instead of reopening live NamedTemporaryFile handles. Windows denies reopening those handles, causing every Windows test matrix job to fail.

Copilot-Session: 8f087f94-098a-4cca-8653-436c45150324
Copilot AI review requested due to automatic review settings July 21, 2026 01:08

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 30 out of 30 changed files in this pull request and generated 2 comments.

Comment thread src/mobius/_inspect.py
Comment on lines +145 to +150
resolved_task, model_type, hf_config = _resolve_task_model_type_and_config(
model_id, task, trust_remote_code
)
task_obj = get_task(resolved_task)
roles = task_obj.model_roles or {}

Comment on lines +235 to +242
def test_qwen3_5_moe_vl_detected_from_vision_config(monkeypatch):
_patch_autoconfig(
monkeypatch, SimpleNamespace(model_type="qwen3_5_moe", vision_config=SimpleNamespace())
)
names = {c.name for c in inspect_components("fake/qwen-vl")}
assert "vision_encoder" in names and "decoder" in names


- name: Install onnxruntime (GPU)
if: inputs.device == 'cuda'
run: |
# Install after project dependencies so the CPU ORT package cannot overwrite it.

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.

Do we need to uninstall the onnxruntime cpu first?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

onnxruntime cpi is skipped in line 77 for cuda case

pip install -e '.[testing,transformers]'
pip install --pre --extra-index-url https://aiinfra.pkgs.visualstudio.com/PublicPackages/_packaging/ort-cuda-12-nightly/pypi/simple/ onnxruntime-gpu onnxruntime-genai-cuda
# PyPI's ORT 1.27+ wheel requires CUDA 13, while these runners use CUDA 12.
pip install --pre --no-deps --index-url https://aiinfra.pkgs.visualstudio.com/PublicPackages/_packaging/onnxruntime-cuda-12/pypi/simple/ onnxruntime-gpu

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.

Thanks!

Comment thread src/mobius/models/blip2.py Resolved

@justinchuby justinchuby left a comment

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.

Thanks!

Integrate the latest main branch while preserving the branch's CUDA 12 CI setup and Windows-safe ONNX session handling.\n\nAdd HuggingFace source metadata for the new Qwen3-TTS step and prefill embedder roles so inspect_components stays aligned with TTSTask.

Co-authored-by: Copilot <[email protected]>\nCopilot-Session: ad41ef64-d67a-49f7-b340-200b666497f2
Signed-off-by: Xiaoyu <[email protected]>
Copilot AI review requested due to automatic review settings July 23, 2026 21:30
Document the two embedder models added on main so the architecture summary matches TTSTask and inspection metadata.

Co-authored-by: Copilot <[email protected]>
Copilot-Session: ad41ef64-d67a-49f7-b340-200b666497f2
Signed-off-by: Xiaoyu <[email protected]>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 29 out of 29 changed files in this pull request and generated no new comments.

Comments suppressed due to low confidence (1)

src/mobius/_inspect.py:150

  • inspect_components currently derives the component list directly from task_obj.model_roles. For Gemma4Task, build() only includes "audio_encoder" when config.audio is set (driven by HF config.audio_config), but model_roles declares audio_encoder unconditionally. This makes inspect_components report an audio_encoder component even for text+vision-only Gemma4 checkpoints, which contradicts the docstring/PR intent (“plus audio when config.audio is set”) and can mislead downstream tooling.
    task_obj = get_task(resolved_task)
    roles = task_obj.model_roles or {}

Copilot AI review requested due to automatic review settings July 23, 2026 21:35
Copilot AI review requested due to automatic review settings August 4, 2026 17:56

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 32 out of 32 changed files in this pull request and generated no new comments.

Suppressed comments (1)

src/mobius/_inspect.py:150

  • inspect_components currently derives the returned component list solely from task_obj.model_roles. For tasks with config-gated/optional components (e.g. Gemma4Task only builds audio_encoder when config.audio != None; TTSTask only builds speaker_encoder when speaker_encoder_config is present), this can cause inspect_components() to report components that build() will not actually produce for the given HF config.
    resolved_task, model_type, hf_config = _resolve_task_model_type_and_config(
        model_id, task, trust_remote_code
    )
    task_obj = get_task(resolved_task)
    roles = task_obj.model_roles or {}

Match the Fun-ASR YAML case to the registry test_model_id and remove the obsolete CI skip now that the metadata-enabled mirror is used.

Co-authored-by: Copilot <[email protected]>

Copilot-Session: 88ec109e-af0c-46c3-9806-731bc2b7342f
Signed-off-by: Justin Chu <[email protected]>
Copilot AI review requested due to automatic review settings August 4, 2026 18:45
Keep the metadata-enabled mirror for L2 config validation, while pointing the golden YAML at the upstream checkpoint and explicitly skipping the incompatible exact-ID coverage check.

Co-authored-by: Copilot <[email protected]>

Copilot-Session: 88ec109e-af0c-46c3-9806-731bc2b7342f
Signed-off-by: Justin Chu <[email protected]>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 33 out of 33 changed files in this pull request and generated no new comments.

Suppressed comments (3)

src/mobius/_inspect.py:15

  • The module docstring claims inspect_components returns the same component keys that mobius.build produces, but some tasks declare config-gated optional components in model_roles (e.g. Gemma4Task includes audio_encoder even though build() only adds it when config.audio is not None). This makes the statement misleading for callers relying on exact ModelPackage keys; please clarify that the result can be a superset for some tasks/checkpoints.
The component names returned here are the same keys :func:`mobius.build`
produces in its :class:`~mobius._model_package.ModelPackage` (and therefore the
subfolder names ``ModelPackage.save`` writes for multi-component models).
"""

src/mobius/_inspect.py:56

  • _resolve_task_model_type_and_config() is annotated as returning tuple[str, ...], but it can return task unchanged when an explicit task is passed (which may be a ModelTask instance per inspect_components() docstring). This mismatch is likely to trip static type checking; the return type should allow non-str tasks (or the function should normalize tasks to a string).
def _resolve_task_model_type_and_config(
    model_id: str, task, trust_remote_code: bool
) -> tuple[str, str | None, object | None]:
    """Resolve the mobius task name for a model id without building it.

src/mobius/_testing/ort_inference.py:264

  • OnnxModelSession.__del__() always calls close(), but close() unconditionally accesses self._tmpdir. If __init__ raises before _tmpdir is set (e.g. when a multi-model ModelPackage is passed and ValueError is raised), __del__ can raise AttributeError during GC/shutdown. Guard _tmpdir the same way _session is guarded so cleanup is safe for partially-constructed instances.
    def close(self) -> None:
        # Release ORT resources eagerly (not only at Python GC time) so
        # long-running GPU test suites do not accumulate session memory.
        if hasattr(self, "_session"):
            del self._session
        self._tmpdir.cleanup()

Copilot AI review requested due to automatic review settings August 4, 2026 18:51

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 33 out of 33 changed files in this pull request and generated no new comments.

Suppressed comments (1)

src/mobius/_inspect.py:149

  • inspect_components() currently uses the task's static model_roles verbatim. For Gemma4 tasks, build() only includes "audio_encoder" when the HuggingFace config has audio enabled (Gemma4Task.build gates on config.audio), but inspect_components will always report an audio_encoder component due to Gemma4Task.model_roles being static. This makes the new public inspection API disagree with actual ModelPackage contents for non-audio Gemma4 checkpoints, and can also surface source_paths for modules that may not exist at runtime.
    task_obj = get_task(resolved_task)
    roles = task_obj.model_roles or {}

@justinchuby

Copy link
Copy Markdown
Member

Is this still needed?

@xiaoyu-work

Copy link
Copy Markdown
Member Author

Is this still needed?

yes, but the ci keeps failing

@xiaoyu-work

Copy link
Copy Markdown
Member Author

@copilot resolve the merge conflicts in this pull request

…ents-api

Signed-off-by: GitHub <[email protected]>

# Conflicts:
#	src/mobius/models/qwen35.py

Co-authored-by: xiaoyu-work <[email protected]>
Comment thread src/mobius/models/qwen35.py Resolved

Copilot AI commented Aug 18, 2026

Copy link
Copy Markdown
Contributor

@copilot resolve the merge conflicts in this pull request

Merge conflicts resolved in commit 4db7eea (conflict was in src/mobius/models/qwen35.py import ordering). Also updated src/mobius/_inspect.py and its test to use the new mobius.integrations.transformers._config_resolver path since that module moved as part of the merged-in ecosystem refactor. Full non-integration test suite passes (4091 passed, 61 skipped).

@@ -0,0 +1,579 @@
# Copyright (c) Microsoft Corporation.
Comment thread src/mobius/models/qwen35.py Fixed
Co-authored-by: Copilot Autofix powered by AI <223894421+github-code-quality[bot]@users.noreply.github.com>
Signed-off-by: Justin Chu <[email protected]>
@justinchuby
justinchuby merged commit 66e9c5e into main Aug 20, 2026
9 of 14 checks passed
@justinchuby
justinchuby deleted the xiaoyu/inspect-components-api branch August 20, 2026 18:39
justinchuby pushed a commit that referenced this pull request Aug 21, 2026
## Summary

- apply the repository Ruff formatter to two long calls added by #378
- write the asset-patch SHA fixture as exact UTF-8 bytes so Windows
newline translation cannot change LF to CRLF before hashing
- restore the all-files lint job and the four asset-patch tests failing
across all Windows Python versions on `main` and dependent pull requests

## Validation

- `9 passed, 1 subtests passed` —
`src/mobius/upstream_patches/_patches_test.py`
- Ruff check and format passed for both changed test files
- `git diff --check`

Only test formatting/fixture construction changes; runtime behavior is
unchanged.

---------

Copilot-Session: e10674c1-6909-4b09-9f5a-d41b28c89d2d
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.

6 participants