introspection: add list_components for lightweight component discovery - #323
introspection: add list_components for lightweight component discovery#323xiaoyu-work wants to merge 2 commits into
Conversation
Adds mobius.list_components(model_id, *, task=None, trust_remote_code=False) -> list[str] which returns the ONNX component names that mobius.build() would produce, without downloading weights or constructing any graphs. For transformer models it downloads only the HuggingFace config.json (via transformers.AutoConfig) and dispatches via the same registry + task lookup as build(), including the qwen3_5_moe -> qwen3_5_moe_vl override. For diffusers pipelines it downloads only model_index.json and mirrors the iteration, filtering, and sub-package flattening rules of build_diffusers_pipeline so the returned names exactly match the keys of the resulting ModelPackage. Component names are read statically from each task's ComponentSpec (or default to ['model'] for single-component tasks). Tests cover: per-task component lookup, composite-config unwrapping, transformer + diffusers paths, explicit task override, and graceful errors when neither config.json nor model_index.json are usable. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Performance Comparison
|
Co-authored-by: Copilot Autofix powered by AI <223894421+github-code-quality[bot]@users.noreply.github.com> Signed-off-by: Xiaoyu <85524621+xiaoyu-work@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Adds a lightweight introspection API (mobius.list_components) to discover which ONNX sub-model/component names a given HuggingFace model or diffusers pipeline would produce, without downloading weights or building graphs. This fits into mobius as a planning/inspection utility alongside the existing build() / registry-driven dispatch.
Changes:
- Introduces
src/mobius/_introspection.pyimplementinglist_components()plus helper logic for transformer vs diffusers discovery. - Exposes
list_componentsfrommobiustop-level and__all__. - Adds offline unit tests covering task-component lookup, transformer dispatch, diffusers pipeline parsing, and error cases.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
src/mobius/_introspection.py |
New introspection implementation for component-name discovery across transformer models and diffusers pipelines. |
src/mobius/__init__.py |
Exports list_components as a public API. |
tests/introspection_test.py |
Adds unit tests validating the new behavior with mocked network/config loading. |
| from mobius._registry import _detect_fallback_registration, registry | ||
| from mobius.tasks import ModelTask, get_task | ||
|
|
||
|
|
||
| def list_components( | ||
| model_id: str, |
| import transformers | ||
| except ImportError as e: |
|
|
||
| Only HuggingFace metadata files (``config.json`` or ``model_index.json``) | ||
| are downloaded; no weights are fetched and no graphs are built. The | ||
| cost is roughly one HTTP request. |
|
The author of this PR, xiaoyu-work, is not an activated member of this organization on Codecov. |
justinchuby
left a comment
There was a problem hiding this comment.
LGTM thanks. Could you address the copilot reviews? They seem relevant
Adds mobius.list_components(model_id, *, task=None, trust_remote_code=False) -> list[str] which returns the ONNX component names that mobius.build() would produce, without downloading weights or constructing any graphs.
For transformer models it downloads only the HuggingFace config.json (via transformers.AutoConfig) and dispatches via the same registry + task lookup as build(), including the qwen3_5_moe -> qwen3_5_moe_vl override. For diffusers pipelines it downloads only model_index.json and mirrors the iteration, filtering, and sub-package flattening rules of build_diffusers_pipeline so the returned names exactly match the keys of the resulting ModelPackage.
Component names are read statically from each task's ComponentSpec (or default to ['model'] for single-component tasks).
Tests cover: per-task component lookup, composite-config unwrapping, transformer + diffusers paths, explicit task override, and graceful errors when neither config.json nor model_index.json are usable.