Repository navigation
Add component inspection API - #378
Conversation
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]>
🏗️ Architecture Diff
No architecture changes detected. ✅ Legend: ⚪ No change · 🔵 Minor (attrs/inits) · 🟡 Moderate (nodes added/removed) · 🔴 Major (interface changed) |
Performance Comparison
|
There was a problem hiding this comment.
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()andComponentInfoto report component names/kinds (and optional HFsource_pathhints 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 →
mmsmapping). - 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. |
| 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 |
|
The author of this PR, xiaoyu-work, is not an activated member of this organization on Codecov. |
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
| 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 {} | ||
|
|
| 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. |
There was a problem hiding this comment.
Do we need to uninstall the onnxruntime cpu first?
There was a problem hiding this comment.
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 |
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]>
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]>
There was a problem hiding this comment.
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 {}
There was a problem hiding this comment.
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]>
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]>
There was a problem hiding this comment.
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.buildproduces, but some tasks declare config-gated optional components inmodel_roles(e.g. Gemma4Task includesaudio_encodereven thoughbuild()only adds it whenconfig.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 returningtuple[str, ...], but it can returntaskunchanged when an explicit task is passed (which may be aModelTaskinstance perinspect_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 callsclose(), butclose()unconditionally accessesself._tmpdir. If__init__raises before_tmpdiris set (e.g. when a multi-model ModelPackage is passed andValueErroris raised),__del__can raiseAttributeErrorduring GC/shutdown. Guard_tmpdirthe same way_sessionis 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()
There was a problem hiding this comment.
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 {}
|
Is this still needed? |
yes, but the ci keeps failing |
|
@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]>
…r import path Co-authored-by: xiaoyu-work <[email protected]>
Merge conflicts resolved in commit 4db7eea (conflict was in |
| @@ -0,0 +1,579 @@ | |||
| # Copyright (c) Microsoft Corporation. | |||
Co-authored-by: Copilot Autofix powered by AI <223894421+github-code-quality[bot]@users.noreply.github.com> Signed-off-by: Justin Chu <[email protected]>
## 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
Summary
Validation