Skip to content

build_from_gguf: accept HF repo references; hy_mt1_5 demo is one-shot - #304

Merged
justinchuby merged 5 commits into
mainfrom
hy-mt-auto-download
May 20, 2026
Merged

justinchuby merged 5 commits into
mainfrom
hy-mt-auto-download

Conversation

@justinchuby

Copy link
Copy Markdown
Member

What

build_from_gguf now accepts a HuggingFace Hub reference in addition to a local .gguf path:

build_from_gguf('AngelSlim/Hy-MT1.5-1.8B-2bit-GGUF')           # auto-pick the single .gguf
build_from_gguf('AngelSlim/Hy-MT1.5-1.8B-2bit-GGUF:foo.gguf')  # multi-file repo

Downloads go through huggingface_hub.hf_hub_download into the standard local cache, so re-runs are free. If the repo contains multiple .gguf files and no :filename is given, we raise with a list of available files.

Why

The examples/hy_mt1_5.py script now demos the full mobius pipeline in a single command — handy when handing off to a PM or a teammate:

python examples/hy_mt1_5.py --variant Q1_0 --out ./hy-mt-q1_0-onnx \
    --prompt 'Translate the following Chinese text to English: 黄河之水天上来'
# -> downloads GGUF, builds Q1_0 ONNX + genai_config.json into --out, runs translation
# 'The Yellow River rises from the sky.'

Subsequent runs reuse the build in --out. --build still forces a rebuild; --gguf still accepts a local path.

Tests

  • pytest src/mobius/integrations/gguf/ -q → 144 passed
  • Manual end-to-end on a clean directory: fresh download + build + translation works (output above)

@github-actions

github-actions Bot commented May 20, 2026 •

Copy link
Copy Markdown

🏗️ Architecture Diff

Comparing 42573f4 → 13f3201

Model Sub-model Changes Status

No architecture changes detected. ✅


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

@github-actions

github-actions Bot commented May 20, 2026 •

Copy link
Copy Markdown

Performance Comparison

Comparing 42573f4 → 13f3201

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 107 107 +0.0% ⚪
gpt2 model_size_bytes 388 KB 388 KB +0.0% ⚪
gpt2 num_nodes 53 53 +0.0% ⚪
llama model_size_bytes 425 KB 425 KB +0.0% ⚪
llama num_nodes 61 61 +0.0% ⚪
llama (static-cache) model_size_bytes 425 KB 425 KB +0.0% ⚪
llama (static-cache) num_nodes 58 58 +0.0% ⚪
mamba (ssm-text-generation) model_size_bytes 296 KB 296 KB +0.0% ⚪
mamba (ssm-text-generation) num_nodes 98 98 +0.0% ⚪
phi3 model_size_bytes 421 KB 421 KB +0.0% ⚪
phi3 num_nodes 59 59 +0.0% ⚪
phi3 (static-cache) model_size_bytes 421 KB 421 KB +0.0% ⚪
phi3 (static-cache) num_nodes 56 56 +0.0% ⚪
qwen2 model_size_bytes 425 KB 425 KB +0.0% ⚪
qwen2 num_nodes 61 61 +0.0% ⚪
qwen2 (static-cache) model_size_bytes 425 KB 425 KB +0.0% ⚪
qwen2 (static-cache) num_nodes 58 58 +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 275 275 +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 129 129 +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 413 413 +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.

build_from_gguf now accepts a HuggingFace Hub reference in addition to a
local path:

  build_from_gguf('AngelSlim/Hy-MT1.5-1.8B-2bit-GGUF')           # auto-pick
  build_from_gguf('AngelSlim/Hy-MT1.5-1.8B-2bit-GGUF:foo.gguf')  # explicit

When the repo contains exactly one .gguf the filename is auto-detected;
otherwise the caller must disambiguate with ':<filename>'. Downloads go
through huggingface_hub into the standard local cache, so re-runs are
free.

The hy_mt1_5 example takes advantage of this so that a fresh
'python examples/hy_mt1_5.py --variant Q1_0 --out ./hy-mt-q1_0-onnx'
invocation now: downloads the GGUF, builds the ONNX (Q1_0 + ORT GenAI
config), and runs translation -- all in one step. --build still forces
a rebuild, and --gguf still accepts a local file.

Co-authored-by: Copilot <[email protected]>
Signed-off-by: Justin Chu <[email protected]>
@justinchuby
justinchuby force-pushed the hy-mt-auto-download branch from 7986aca to b8e94a2 Compare May 20, 2026 00: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

This PR extends the GGUF integration so build_from_gguf can accept HuggingFace Hub-style references (in addition to local .gguf paths), and updates the examples/hy_mt1_5.py script to be a one-command end-to-end demo that auto-builds on first run.

Changes:

  • Add GGUF reference resolution that can download a .gguf from HuggingFace Hub into the local cache.
  • Update build_from_gguf docs and wire the resolver into the GGUF build pipeline.
  • Make the Hy-MT1.5 example auto-build/reuse outputs to support a one-shot demo workflow.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
src/mobius/integrations/gguf/_builder.py Adds _resolve_gguf_path() and uses it to allow build_from_gguf to download GGUFs from HuggingFace Hub.
examples/hy_mt1_5.py Updates usage/docs and build logic to auto-build on first use and optionally download GGUF from HF.
Comments suppressed due to low confidence (1)

examples/hy_mt1_5.py:124

  • This failure message is very non-actionable (it doesn’t tell the user what to try next or where the build step failed). Consider including a clearer hint (e.g., that the build step failed, suggest re-running with --build, and/or point to expected files under --out).
    return out


def run_translation(

Comment thread examples/hy_mt1_5.py Resolved
Comment thread examples/hy_mt1_5.py Resolved
1. _resolve_gguf_path: split ':filename' before classifying the input, so
   'owner/repo:weights.gguf' is correctly routed through hf_hub_download
   instead of being misclassified as a local path that ends in .gguf.
   Refactor into _looks_like_hf_repo_id() helper.

2. hy_mt1_5 example: write a .mobius-variant marker file during build
   and refuse to reuse an --out built for a different variant. Without
   this, running --variant Q1_0 against an --out previously built for
   bf16 (or vice-versa) silently ran the wrong model.

3. hy_mt1_5 example: --out --help now describes the new auto-build
   behavior ('if it doesn't contain a built model yet, one is created
   automatically'); the post-build error message is also more
   actionable, pointing at the missing file and the recovery path.

Co-authored-by: Copilot <[email protected]>
Signed-off-by: Justin Chu <[email protected]>
@codecov

codecov Bot commented May 20, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 56.52174% with 10 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/mobius/integrations/gguf/_builder.py 56.52% 9 Missing and 1 partial ⚠️

📢 Thoughts on this report? Let us know!

justinchuby and others added 3 commits May 20, 2026 01:56
huggingface_hub is already a top-level runtime dependency (pyproject.toml)
and is imported at module level elsewhere in mobius (e.g. _weight_loading).
There is no reason to keep it lazy inside _resolve_gguf_path.

Co-authored-by: Copilot <[email protected]>
Signed-off-by: Justin Chu <[email protected]>
Previously _resolve_gguf_path had two near-duplicate code paths -- one
for 'owner/repo:filename' and one for 'owner/repo' (auto-pick) -- each
with its own _looks_like_hf_repo_id() call, logger.info() and
hf_hub_download() call. Restructure to: partition the ':filename'
suffix, classify once, auto-discover the filename if missing, then run
a single download with a single log line.

Co-authored-by: Copilot <[email protected]>
Signed-off-by: Justin Chu <[email protected]>
The previous version wrote a .mobius-variant marker on build and tried
to reuse --out across runs, refusing to silently swap variants. That
added two helpers (_existing_variant, marker file management) for a
small UX win, and was easy to get wrong (e.g. dirty --out from a
half-finished build was silently reused).

Always rebuilding is simpler and effectively just as fast for the demo:
huggingface_hub already caches the safetensors (bf16) and GGUF (Q1_0)
downloads, so 'always download' is a no-op on the network side and the
in-process mobius graph construction runs every time anyway. As a bonus
the --build flag is no longer needed, so it's gone.

Co-authored-by: Copilot <[email protected]>
Signed-off-by: Justin Chu <[email protected]>
@justinchuby
justinchuby merged commit c289382 into main May 20, 2026
22 of 23 checks passed
@justinchuby
justinchuby deleted the hy-mt-auto-download branch May 20, 2026 03:40
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.

2 participants