Skip to content

Add exact fail-closed Qwen4Exp GGUF support - #656

Merged
justinchuby merged 12 commits into
mainfrom
justinchuby-add-qwen4exp-gguf
Aug 27, 2026
Merged

Add exact fail-closed Qwen4Exp GGUF support#656
justinchuby merged 12 commits into
mainfrom
justinchuby-add-qwen4exp-gguf

Conversation

@justinchuby

Copy link
Copy Markdown
Member

Stack

Summary

  • register general.architecture=qwen4exp as qwen4_exp_text with the exact Qwen3.8 Flash-Next config, DeltaNet/QSA schedule, hyper-connections, PLE, routed/shared MoE, and output HC mixer metadata
  • pin unsloth/Qwen3.8-Flash-Next-GGUF@d3bc75ee6ccef3efc1e228ec00a6cc2cdb1e2249, all three shard sizes/LFS SHA-256 identities, and the metadata-only shard-0 closure 0 + 595 + 629 = 1224
  • map every GGUF tensor family, including GGUF split indexer Q/K rows reconstructed exactly into Hugging Face's fused index_qk_proj
  • validate every tensor name, logical shape, and dynamic qtype using the complete bounded-header manifest digest 25a1e6a2073caf19d3a3835dd23702a19fa09cc651506e11a13de7b48076359d
  • preserve existing official fused HF indexer checkpoints while accepting only the exact GGUF split representation on the GGUF path
  • fail closed before Hub payload download when header policy cannot be established, source/revision/shard identity differs, or either payload mode is requested

Fail-closed payload policy

The only published UD-IQ1_S route is intentionally not emitted as an executable ONNX payload:

  • per_layer_token_embd.weight is an enormous IQ4_NL embedding with no compatible native gather ABI
  • rank-3 routed expert banks dynamically mix IQ1_S/IQ2_XXS gate/up with IQ4_NL down tensors; released runtime evidence does not establish a matching mixed-format sparse native-block MoE ABI
  • these tensors are not ordinary affine rank-2 MatMulNBits
  • float32 dequantization would materialize roughly 191 GiB for the PLE table alone, exceeding the bounded 8 GiB single-tensor policy

The exact header/config/mapping support is therefore a truthful preflight foundation for future ABI work, not a quantized-runtime claim.

Validation

  • targeted Qwen4Exp/GGUF/registry review suite: 1187 passed, 2 skipped
  • complete GGUF + Qwen4Exp + graph serial suite: 4865 passed, 54 skipped
  • broad serial non-integration suite: 8409 passed, 64 skipped, 12 deselected, 1 subtest passed
  • lintrunner f --output oneline --all-files && lintrunner -a: clean
  • GPT-5.6 Sol medium review run twice; fused-HF compatibility, complete qtype evidence, config pinning, and Hub fallback findings were resolved

Waivers

  • No full payload download, real-weight runtime execution, L4, or L5 claim is made for the GGUF route. The exact pinned artifact is deliberately rejected before its 72+ GB payload is downloaded because neither supported native preservation nor bounded dequantization is truthful under the current Mobius/ORT ABI.
  • Runtime support remains deferred. This PR must not be interpreted as ORT or ORT GenAI execution evidence for the quantized artifact.

@github-actions

github-actions Bot commented Aug 26, 2026

Copy link
Copy Markdown

🏗️ Architecture Diff

Comparing 27c24d3fbc3370

Model Sub-model Changes Status
qwen model 0
qwen (static-cache) model 0

No architecture changes detected.


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

@github-actions

github-actions Bot commented Aug 26, 2026

Copy link
Copy Markdown

Performance Comparison

Comparing 27c24d3fbc3370

Model Metric Baseline Current Delta
bert (feature-extraction) model_size_bytes 359 KB 359 KB +0.0%
bert (feature-extraction) num_nodes 68 68 +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 324 KB 324 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 265 265 +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 127 127 +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 450 450 +0.0%
t5 (seq2seq) model_size_bytes 836 KB 836 KB +0.0%
t5 (seq2seq) num_nodes 176 176 +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.

@justinchuby
justinchuby force-pushed the justinchuby-add-qwen4exp-gguf branch from c1b734e to 1c09bee Compare August 26, 2026 18:22
Base automatically changed from justinchuby-finish-qwen4exp-core to main August 27, 2026 05:09
@justinchuby
justinchuby requested a review from a team August 27, 2026 05:09
justinchuby added a commit that referenced this pull request Aug 27, 2026
## Summary

- classify every unresolved authoritative GGUF architecture, projector,
tokenizer, MTP, and speculative-draft route exactly once
- generate concrete implementation, evidence, ABI/dependency, artifact,
and rejection batches from live registries
- preserve exact registry reasons in machine-readable census records and
reconcile PRs #645, #651, #652, and #656 without claiming open work as
supported
- distinguish ordinary runtime evidence from ORT GenAI
heterogeneous-state schema issue #605
- pin availability-only F16/Q8_0 sidecar identities for LFM2-VL and
Pixtral without implying tensor closure, graph parity, or runtime
support

## Census

- 285 unresolved routes: 144 architectures, 60 projectors, 57
tokenizers, 22 MTP routes, and 2 draft routes
- 67 immediately implementable
- 95 evidence-only
- 100 dependency/runtime-ABI blocked
- 4 artifact unavailable
- 19 intentionally rejected

## Validation

- generated documentation check
- 1,371 focused GGUF tests passed, 1 skipped
- broad deterministic suite: 8,467 passed, 62 skipped, 1 subtest passed
- Ruff/format lint passed
- strict mypy passed for changed source modules
- independent incremental review found no significant issues

## Waivers

- no large model payloads downloaded; availability pins use immutable
repository revisions plus API-reported LFS SHA-256 and byte size
- open PRs #651/#652/#656 are dependency records only and are not
promoted as current-main capability
- no unsupported cache/state ABI is forced; packed quantized support
remains governed by existing fail-closed capability records

Do not merge yet.

---------

Signed-off-by: Justin Chu <justinchuby@users.noreply.github.com>
Copilot-Session: d1a98adf-88cb-471b-8c46-7a84083db24c
Copilot AI lite review requested due to automatic review settings August 27, 2026 05:27
@justinchuby
justinchuby force-pushed the justinchuby-add-qwen4exp-gguf branch from 1c09bee to f049303 Compare August 27, 2026 05:27
Comment thread src/mobius/integrations/gguf/_qwen4_exp.py Fixed
Comment thread src/mobius/integrations/gguf/_qwen4_exp.py Fixed
@justinchuby
justinchuby force-pushed the justinchuby-add-qwen4exp-gguf branch from f049303 to 5c0451b Compare August 27, 2026 05:32

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 Mobius’ GGUF integration to recognize general.architecture=qwen4exp as the existing qwen4_exp_text model type, while enforcing an explicit fail-closed policy that only supports exact header/config/tensor-contract preflight (no executable payload import) for the pinned Unsloth 3-shard artifact.

Changes:

  • Add preflight-only GGUF architecture support for qwen4exp with exact pinned metadata/tensor closure + explicit Hub identity gates that refuse payload download/materialization.
  • Expand sharded GGUF handling: stricter shard-set validation, deterministic merged metadata, shard identity paths for stable hashing across HF snapshot symlinks, and Hub resolution that downloads complete shard sets (with free-space preflight).
  • Add Qwen4Exp-specific GGUF tensor-name mapping and weight preprocessing to fuse GGUF’s split indexer Q/K rows into HF’s fused index_qk_proj.

Reviewed changes

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

Show a summary per file
File Description
src/mobius/models/qwen4_exp.py Fuse split GGUF indexer Q/K projection weights into HF’s fused index_qk_proj during weight preprocessing.
src/mobius/models/qwen4_exp_test.py Add unit coverage for indexer fusion, preservation of official fused weights, and fail-closed validation.
src/mobius/integrations/gguf/_upstream.py Extend the pinned llama.cpp census with an explicit post-census qwen4exp architecture entry.
src/mobius/integrations/gguf/_upstream_gap_test.py Update census closure expectations to include the additional pinned architecture.
src/mobius/integrations/gguf/_tensor_mapping.py Introduce Qwen4Exp GGUF→HF tensor mapping table and allow mapping for preflight-only specs.
src/mobius/integrations/gguf/_spec.py Add preflight_only to the architecture spec contract and enforce internal consistency.
src/mobius/integrations/gguf/_shard_set.py Strengthen local shard discovery/validation, add metadata merging, and expose identity paths + shard tensor source helpers.
src/mobius/integrations/gguf/_shard_set_test.py Add extensive tests for shard discovery, metadata authority rules, Hub shard resolution boundaries, and integrity checks.
src/mobius/integrations/gguf/_runtime_evidence.py Hash sharded artifacts using stable regular-file “identity paths” when available (e.g., HF blob store).
src/mobius/integrations/gguf/_runtime_evidence_test.py Validate identity hashing behavior across snapshot symlinks via identity-path aliases.
src/mobius/integrations/gguf/_reader.py Add _tensor_source() for per-tensor file/offset/record access (used by Tencent Q1_0 parsing).
src/mobius/integrations/gguf/_qwen4_exp.py Add Qwen4Exp pinned Hub identity + exact header/config/tensor contract validation and deliberate payload fail-closed blocker.
src/mobius/integrations/gguf/_qwen4_exp_test.py Add tests for exact config mapping, tensor mapping, manifest digesting, and strict Hub/payload gates.
src/mobius/integrations/gguf/_header.py Add bounded header parsing that also extracts split bookkeeping into GGUFHeaderInfo with clearer truncation errors.
src/mobius/integrations/gguf/_docs.py Document preflight-only routes and clarify split-set discovery and Hub split-set behavior.
src/mobius/integrations/gguf/_docs_test.py Update generated census counts and ensure doc output matches new totals.
src/mobius/integrations/gguf/_config_mapping.py Add Qwen4Exp GGUF→config extraction and postprocessing to construct the exact Qwen4ExpConfig.
src/mobius/integrations/gguf/_builder.py Add full Hub split-set selection/download logic, strict bounded-header preflight paths, and Qwen4Exp fail-closed policy enforcement.
src/mobius/integrations/gguf/_builder_test.py Add tests for sharded quantized builds, bounded-header edge cases, and preflight/download boundary behavior.
src/mobius/integrations/gguf/_arch_registry.py Register qwen4exp as preflight-only (config + tensor-map supported; graph/runtime deferred; quantized import rejected).
src/mobius/integrations/gguf/_arch_registry_test.py Adjust registry invariants to allow preflight-only specs (mapping/config without graph support).
src/mobius/integrations/gguf/init.py Update public usage examples to show local shard paths and Hub shard references.
docs/design/qwen4-exp-text-core.md Document the pinned GGUF artifact identity and explain the explicit payload fail-closed rationale.
docs/api/build_from_gguf.md Update census totals and document split-set handling and the qwen4exp preflight-only route.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread src/mobius/integrations/gguf/_shard_set.py
Comment thread src/mobius/integrations/gguf/_builder.py
@justinchuby
justinchuby force-pushed the justinchuby-add-qwen4exp-gguf branch from e2e2f29 to f1a5be7 Compare August 27, 2026 05:48
justinchuby and others added 12 commits August 26, 2026 22:52
Assemble strict local shard sets as one lazy logical GGUF model and resolve Hub sets at an immutable revision with cache-aware capacity preflight. Preserve quantized tensor paths, deterministic metadata, runtime identity hashing, and single-file behavior.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Signed-off-by: Justin Chu <justinchuby@users.noreply.github.com>
Map the pinned qwen4exp configuration and complete 1,224-tensor header closure, including split QSA index projections and the metadata-only first shard. Reject the published mixed IQ1_S/IQ4_NL payload before download because neither native preservation nor full dequantization has a truthful bounded runtime path.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Signed-off-by: Justin Chu <justinchuby@users.noreply.github.com>
Pin every tensor name, logical shape, and dynamic qtype through the complete header-manifest digest, preserve official fused HF indexer weights, and reject unpinned config metadata. Make Hub header transport and truncation failures stop before payload download so architecture policy cannot be bypassed.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Signed-off-by: Justin Chu <justinchuby@users.noreply.github.com>
Carry immutable Hub LFS manifests through resolution into reader checksum verification, enumerate renamed split siblings from bounded header metadata before download, and make primary-shard semantic metadata authoritative. Mark Qwen4Exp as header/config/tensor preflight-only until an executable ABI exists while preserving generic Hub fallback behavior.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Signed-off-by: Justin Chu <justinchuby@users.noreply.github.com>
Separate split-header parsing from architecture dispatch so unrelated projector files do not poison renamed shard discovery, cap candidate range reads by the declared split count, and reject ambiguous directories mixing split and standalone GGUF models.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Signed-off-by: Justin Chu <justinchuby@users.noreply.github.com>
Reject oversized shard counts before allocation or network probing and enumerate local GGUF suffixes case-insensitively so discovery behaves consistently on Linux and case-insensitive filesystems.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Signed-off-by: Justin Chu <justinchuby@users.noreply.github.com>
Regenerate the support matrix on top of the authoritative remaining-route census and compress the shard-import overview without dropping its validation contract.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Signed-off-by: Justin Chu <justinchuby@users.noreply.github.com>
Keep immutable source pins in the design documentation and remove duplicate runtime constants that were not part of validation or dispatch.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Signed-off-by: Justin Chu <justinchuby@users.noreply.github.com>
Teach direct reader calls to inherit resolved shard paths and immutable Hub manifests, and distinguish bounded-header fallback so renamed ambiguous sets reject before a potentially partial download.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Signed-off-by: Justin Chu <justinchuby@users.noreply.github.com>
Regenerate the support matrix after the latest tokenizer-evidence census and keep the usage guidance below the documented concision limit.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Signed-off-by: Justin Chu <justinchuby@users.noreply.github.com>
Route text-side multimodal GGUF opens through the shard-aware reader and classify Qwen4Exp preflight work as runtime-ABI blocked in the generated remaining-route census.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Signed-off-by: Justin Chu <justinchuby@users.noreply.github.com>
Pin the exact float32 GGUF representation of the RMS epsilon so the real artifact header passes strict metadata validation.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Signed-off-by: Justin Chu <justinchuby@users.noreply.github.com>
@justinchuby
justinchuby force-pushed the justinchuby-add-qwen4exp-gguf branch from f1a5be7 to fbc3370 Compare August 27, 2026 05:58
@justinchuby
justinchuby merged commit 8f902ac into main Aug 27, 2026
23 of 25 checks passed
@justinchuby
justinchuby deleted the justinchuby-add-qwen4exp-gguf branch August 27, 2026 06:11
justinchuby added a commit that referenced this pull request Aug 27, 2026
## Summary

- add the Qwen3.8 Flash-Next/Qwen4Exp three-model image-language package
(`decoder`, `vision_encoder`, `embedding`)
- reuse the source-identical no-DeepStack Qwen3/Qwen3.5 vision tower
with a 2560-wide merger
- preserve independent lexical `ple_input_ids`, fused `inputs_embeds`,
four-channel text + M-RoPE positions, and every heterogeneous
recurrent/KV/QSA/PLE state
- cast processor float32 patches once at the BF16 vision boundary
- emit explicit `mobius.state_manifest` and
`mobius.unsupported_token_ids` contracts for direct ONNX Runtime
orchestration

## Bounded multimodal streaming

Both `qwen4_exp` and `qwen4_exp_text` use the bounded safetensors path;
the eager `_download_weights` route is unreachable. One shard index
validates config-derived deterministic PLE buffers and plans decoder,
embedding, and vision bindings. Each graph is cloned, lazily bound, and
initializer-folded in isolation; the package is updated only after every
staged component succeeds. Missing tensors, corrupt PLE hash buffers, or
fold failures leave the original package untouched.

Parameter payloads remain `LazyTensor`s and no source state dict is
retained. The approximately 95 GiB PLE table is allocated once only when
materialized/serialized and populated one checkpoint shard at a time.
Loader accounting reports model/initializer/lazy counts, deterministic
bytes validated eagerly, and zero retained source tensors.

## Enforced image-only boundary

The checkpoint's source video token is validated, then removed from
normalized runtime metadata. Explicit configs requesting video
capability fail closed and the embedding graph exposes no
`video_features` input. It sanitizes any source video token before
vocabulary lookup, computes a runtime `has_video`, and reshapes one zero
element to `[1 + has_video]`. Valid requests reduce/add zero; video
requests demand two elements and fail ONNX Reshape's element-count
invariant before an EP executes. ORT CUDA uses the shared
`ReshapeHelper` for this check (`onnxruntime@b1f76d58`,
`cuda/tensor/reshape.h`), avoiding CUDA Gather's out-of-range zero-fill
behavior. Optimized CPU is exercised locally and the same test executes
CUDA when available; processor-native mixed input also fails through the
guard.

## Runtime workflow boundary

onnxruntime-genai and the current ONNX GenAI workflow schema cannot
represent Qwen4Exp's `ple_input_ids`, four-axis positions, and
heterogeneous state membership. Both exporters reject before writing
artifacts. ONNX GenAI detection checks package config, explicit config,
and the structural decoder ABI, so a non-Qwen override cannot bypass
preflight or modify an existing output directory. Direct ONNX Runtime
users consume `mobius.state_manifest` instead.

## Source pins

- `Qwen/Qwen3.8-Flash-Next@f5d08274bafd880402bd16f5e3e6c514136ec06c`
- `huggingface/transformers@598d8ba8baaec7fec5a22da0e2844c7bf4ea20e1`

## Final-base rebase

Lower-layer PR #656 was squash-merged to `main` as `8f902ac2`. This
branch replays only #657's multimodal work onto that commit; no
pre-squash lower-layer or GGUF implementation files remain in the PR
diff.

## Validation

- final Qwen4 loader/multimodal/synthetic suite: 47 passed, 6 skipped
- full runtime exporter suites: 263 passed
- pinned HuggingFace image parity plus real image/video boundary tests:
3 passed
- post-rebase GGUF report/shard/runtime regression suite: 831 passed
- Qwen4 component inspection and review-thread regressions: passed
- pinned lintrunner format + lint: clean
- independent GPT-5.6 Sol CUDA-guard rereview: no findings

## Waivers

- **L4/L5 real-weight golden:** the 512-expert checkpoint requires a
large GPU; the immutable YAML case records the CI skip.
- **Released runtime workflows:** ORT GenAI and ONNX GenAI metadata
export fail closed as described above.
- **Full checkpoint CUDA generation:** checkpoint scale makes this
impractical in this session; CUDA's shared Reshape validation is
source-pinned and the guard regression runs on CUDA whenever that EP is
available.

This PR targets `main`, is intentionally non-draft, and must not be
merged by this session.

---------

Signed-off-by: Justin Chu <justinchuby@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
justinchuby added a commit that referenced this pull request Aug 27, 2026
## Summary

- resolve local sharded-GGUF symlinks to their verified regular-file
targets before artifact identity hashing, while retaining logical shard
filenames in the digest
- make missing `split.count`, `split.no`, and `split.tensors.count`
diagnostics deterministic
- add regressions covering the `build_from_gguf` symlink path, artifact
hashing, missing targets, and reversed shard ordering

This follows up on the still-applicable Copilot findings from #652 after
its sharded import functionality was superseded on `main` by #656.

## Validation

- `python -m pytest src/mobius/integrations/gguf/_shard_set_test.py -q
--tb=short` (51 passed)
- `python -m pytest tests/build_graph_test.py tests/cli_test.py src/ -q
-k "not phi4mm and not apply_weights_unknown" --tb=short -n auto` (8627
passed, 64 skipped)
- `lintrunner f --output oneline --all-files`
- independent code review: no findings

---------

Signed-off-by: Justin Chu <justinchuby@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
justinchuby added a commit that referenced this pull request Aug 27, 2026
Derive Granite routed expert width from feed_forward_length exactly, reject contradictory serialized expert widths without lossy numeric conversion, and reconcile the authoritative route census with closed #652 plus merged #656 and #675.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 71862fcb-bc9a-4734-b047-b5376afabc3e
Signed-off-by: Justin Chu <justinchuby@users.noreply.github.com>
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