Skip to content

Add dedicated PLaMo2 model and GGUF import - #612

Merged
justinchuby merged 2 commits into
mainfrom
justinchuby-plamo2-gguf
Aug 25, 2026
Merged

justinchuby merged 2 commits into
mainfrom
justinchuby-plamo2-gguf

Conversation

@justinchuby

Copy link
Copy Markdown
Member

Summary

  • add a dedicated PLaMo2 graph with alternating Mamba1 selective-scan and local-attention layers
  • implement fused per-head [z_h|x_h] projection, normalized B/C/dt recurrence, fused QKV/QK norms/RoPE, fused SwiGLU, and sandwich residual norms
  • add heterogeneous recurrent/KV state threading with bounded sliding-window KV caches and deterministic replay/reorder/rollback semantics
  • add strict GGUF v3 metadata/tensor validation, exact shape-derived attention widths, folded-norm handling, and exact float/Q4 preservation rules
  • register the architecture, document support, and defer ORT GenAI packaging to Close remaining heterogeneous recurrent-state runtime gaps #605

Reference pins

  • llama.cpp: 8d9af256337d1a501250f9bbf4c0859a654bddd6
  • pfnet/plamo-2-1b: 92c75fd6eea9018bcb9c33ee8921589febe071fa

Validation

  • 2598 passed — full GGUF suite
  • 26 passed — focused PLaMo2 graph/model/import suite
  • 7107 passed, 52 skipped — broad non-integration suite; only the two pre-existing glm_moe_dsa shape/checker failures remain
  • focused lint passes
  • pinned full 1B configuration builds (16 layers, 249 initializers, 33 outputs)
  • two independent reviews plus a final verification review completed with all findings resolved

Runtime verdict

Graph construction and GGUF import are supported. Released ORT GenAI cannot faithfully represent the heterogeneous recurrent/KV state ABI, so runtime packaging remains deferred to #605. The smallest public checkpoint is approximately 5.16 GB; this PR does not claim real-checkpoint full-logit or deterministic-generation parity.

@github-actions

github-actions Bot commented Aug 25, 2026 •

Copy link
Copy Markdown

Performance Comparison

Comparing 2b46fc0 → 7743ca4

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 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 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 429 429 +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.

@github-actions

github-actions Bot commented Aug 25, 2026 •

Copy link
Copy Markdown

🏗️ Architecture Diff

Comparing 2b46fc0 → 7743ca4

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)

@justinchuby
justinchuby force-pushed the justinchuby-falcon-h1-gguf branch from ea6f21f to 5db3720 Compare August 25, 2026 17:23
Base automatically changed from justinchuby-falcon-h1-gguf to main August 25, 2026 17:24
@justinchuby
justinchuby requested a review from a team August 25, 2026 17:24
justinchuby and others added 2 commits August 25, 2026 10:25
Implement the dedicated alternating Mamba1 and local-attention graph, mixed recurrent/KV state ABI, strict pinned GGUF conversion, and exact quantization handling. Add reduced numerical parity, ORT state threading, malformed-source, round-trip, CLI, and coverage tests while deferring ORT GenAI packaging to #605.

Co-authored-by: Copilot App <[email protected]>
Signed-off-by: Justin Chu <[email protected]>
Include PLaMo2 in the quantized-import architecture pin introduced by the parent squash merge so the replayed fail-closed policy remains mechanically enforced.\n\nCo-authored-by: Copilot App <[email protected]>

Signed-off-by: Justin Chu <[email protected]>
Copilot AI lite review requested due to automatic review settings August 25, 2026 17:31
@justinchuby
justinchuby force-pushed the justinchuby-plamo2-gguf branch from 64aa8fb to 7743ca4 Compare August 25, 2026 17:31
@justinchuby
justinchuby merged commit c98ee9e into main Aug 25, 2026
12 of 21 checks passed
@justinchuby
justinchuby deleted the justinchuby-plamo2-gguf branch August 25, 2026 17:32
justinchuby added a commit that referenced this pull request Aug 25, 2026
## Summary
- accept the exact legacy scalar-head and tokenizer metadata used by the
pinned public PLaMo2 F32 GGUF
- add an explicit opt-in 5.16 GB import/save/reload integration test
- record immutable source provenance, full tensor comparison, raw ORT
parity results, and ORT GenAI blockers
- keep L4/L5 and packaged runtime support deferred because cached decode
diverges

## Historical evidence
- full 218-tensor provenance comparison completed against the pinned
checkpoint and GGUF revisions
- exact artifact size/SHA, tensor census, package identity, reference
generation, raw ORT CPU results, and ORT GenAI 0.15.2 blockers remain
recorded in `testdata/evidence/causal-lm/plamo2-1b-real.json`
- the opt-in real-artifact round trip previously passed; the exact
artifact is required through `MOBIUS_PLAMO2_REAL_GGUF`

## Post-rebase validation
- rebased as one patch-identical commit onto `c98ee9e` after #612 was
squash-merged
- focused import/tokenizer/cache/schema/evidence selection: 255 passed,
1 expected env-gated skip
- broad non-integration suite: 7,522 passed, 54 skipped, 1 subtest
passed
- initialized pinned `lintrunner` tools: clean
- GPT-only post-rebase review: no actionable findings

Signed-off-by: Justin Chu <[email protected]>
Co-authored-by: Copilot App <[email protected]>
Copilot stopped reviewing on behalf of justinchuby due to an error August 25, 2026 17:42

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

Note

Copilot was unable to run its full agentic suite in this review.

Adds first-class PLaMo2 support across Mobius model building and GGUF import, including a dedicated mixed-state task (alternating Mamba + local attention), strict GGUF tensor-closure validation, and extensive synthetic/runtime tests.

Changes:

  • Introduces Plamo2Config, Plamo2ForCausalLM, and Plamo2CausalLMTask to build PLaMo2 ONNX graphs with heterogeneous per-layer state.
  • Implements GGUF import support for plamo2 (config mapping, tensor mapping/processing, and strict pinned validation), and registers the architecture in registries/docs.
  • Adds comprehensive unit/integration tests for graph correctness, state ABI behavior, and GGUF import (float + quantized).

Reviewed changes

Copilot reviewed 20 out of 20 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
tests/build_graph_test.py Updates initializer heuristics to recognize PLaMo2 attention projections.
tests/_test_configs.py Adds a tiny plamo2 test config entry.
testdata/cases/causal-lm/plamo2-1b.yaml Adds a skipped real-model case with rationale and tracking issue.
src/mobius/tasks/_plamo2.py New PLaMo2 task that builds mixed KV + recurrent state graph I/O.
src/mobius/tasks/init.py Exposes Plamo2CausalLMTask and registers task key.
src/mobius/models/plamo2_test.py Adds correctness + state-semantics tests for PLaMo2 graphs.
src/mobius/models/plamo2.py New PLaMo2 model implementation (attention + Mamba + preprocessing).
src/mobius/models/init.py Exports Plamo2ForCausalLM.
src/mobius/integrations/gguf/_tensor_processors.py Adds PLaMo2-specific GGUF tensor processing hook.
src/mobius/integrations/gguf/_tensor_mapping.py Adds PLaMo2 GGUF→HF tensor name mapping + suffix contract.
src/mobius/integrations/gguf/_reader.py Adds GGUF header parsing and exposes format_version.
src/mobius/integrations/gguf/_config_mapping.py Adds PLaMo2 key map + postprocess to build Plamo2Config.
src/mobius/integrations/gguf/_builder_test.py Adds end-to-end GGUF import tests for PLaMo2 (float/quantized/malformed).
src/mobius/integrations/gguf/_builder.py Adds pinned PLaMo2 GGUF validation + task/static-cache gating.
src/mobius/integrations/gguf/_arch_registry_test.py Updates expected supported-architecture census.
src/mobius/integrations/gguf/_arch_registry.py Upgrades plamo2 arch spec from deferred → graph-importable.
src/mobius/_registry.py Registers PLaMo2 model type and default model id.
src/mobius/_configs/_base.py Adds Plamo2Config with validation and HF-config conversion.
src/mobius/_configs/init.py Exports Plamo2Config.
docs/api/build_from_gguf.md Updates support matrix and narrative to reflect PLaMo2 import support.

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

Comment on lines +171 to +175
self._format_version = (
little_version
if little_version <= 0xFFFF
else int.from_bytes(header[4:], byteorder="big")
)
Comment on lines +104 to +115
present_key = op.Slice(
present_key,
[-self.window_size],
[9223372036854775807],
[2],
)
present_value = op.Slice(
present_value,
[-self.window_size],
[9223372036854775807],
[2],
)
Comment on lines +1179 to +1190
if qkv_name not in actual_shapes or output_name not in actual_shapes:
continue
value_width, value_remainder = divmod(actual_shapes[output_name][1], heads)
key_width, key_remainder = divmod(
actual_shapes[qkv_name][0] - kv_heads * value_width,
heads + kv_heads,
)
if value_remainder or key_remainder or min(key_width, value_width) <= 0:
raise ValueError(
f"PLaMo2 layer {layer} key/value widths cannot be inferred exactly"
)
inferred_widths.add((key_width, value_width))
raise ValueError("PLaMo2 requires attention.layer_norm_rms_epsilon=1e-6")
activation = metadata.get(f"{arch}.feed_forward.activation", "silu")
if activation not in {"silu", "swiglu"}:
raise ValueError(f"PLaMo2 supports only fused SwiGLU, got {activation!r}")
justinchuby added a commit that referenced this pull request Aug 25, 2026
## Summary

- implement exact Jamba mixed attention/Mamba-1 execution with
multi-token prefill, decode, heterogeneous KV/conv/recurrent state
threading, batch reorder, and snapshot replay
- add exact dense/routed-MoE scheduling, float32 full-softmax top-k
routing without selected-weight renormalization, no-RoPE attention,
fused and stacked expert preprocessing, and tied-head handling
- import dense and MoE Jamba GGUFs with strict suffix-aware tensor
closure and logical shape validation; preserve compatible
attention/dense/expert MatMul quantization while dequantizing
Mamba/state-sensitive roles
- keep released generic ORT GenAI packaging deferred to #605 because its
cache schema cannot represent heterogeneous state slots
- update generated support documentation from dense-only to the
evidence-backed routed-MoE subset

## Validation

- `python -m pytest src/mobius/integrations/gguf/ -q --tb=short` — 2608
passed
- `python -m pytest tests/build_graph_test.py
tests/synthetic_parity_test.py
src/mobius/integrations/gguf/_config_mapping_test.py
src/mobius/integrations/gguf/_builder_test.py -k 'jamba' -q --tb=short`
— 34 passed
- `python -m pytest tests/build_graph_test.py tests/cli_test.py src/ -q
-k 'not phi4mm and not apply_weights_unknown and not glm_moe_dsa'
--tb=short -n auto` — 7096 passed, 52 skipped
- initialized `lintrunner` and formatted/linted all changed Python files
- generated GGUF support documentation is current
- two independent reviews completed; all high-confidence findings fixed

The unfiltered broad suite still has the existing `glm_moe_dsa`
symbolic-shape inference/checker failure (2 tests), reproduced
independently and unrelated to these Jamba paths.

## Upstream evidence

Audited llama.cpp at `8d9af256337d1a501250f9bbf4c0859a654bddd6` and
current Transformers Jamba. `ai21labs/Jamba-tiny-dev` at
`ed303361004ac875426a61675edecf8e9d976882` is the smallest suitable
public real-weight follow-up candidate (~637 MB), but this PR makes no
real-checkpoint or runtime-generation support claim without that
separate evidence.

Stacked on #612 (`justinchuby-plamo2-gguf`).

---------

Signed-off-by: Justin Chu <[email protected]>
Co-authored-by: Copilot App <[email protected]>
justinchuby added a commit that referenced this pull request Aug 25, 2026
## Summary

- clean up still-valid typing, documentation, test robustness,
error-message,
  maintainability, and performance findings left by the GGUF PR stack
- preserve the behavioral fixes merged in #625-#632
- hash reused multi-GB GGUF sources once, at the final pre-publication
integrity
  gate, while retaining cheap identity checks around staging

Exact base: `2db9d33debdc254d879a51b14434c9a81c230f4f`

Exact head: `4541ed2bc9d2ab4227484510b4a85b2d9113eb25`

## Reconstructed original 17-item low-priority tranche

The persisted audit retained only the totals, so this list was
reconstructed
from the live threads and current source. All but the already-fixed #596
comment are addressed in this PR.

| PR | Comment | Disposition |
|---|---:|---|
| #550 | 3837144656 | Implemented: correct tuple return annotation |
| #552 | 3837389183 | Implemented: multichannel waveform shape docs |
| #559 | 3837716261 | Implemented: name-based cache assertions |
| #573 | 3854308350 | Implemented: one final GGUF hash, with integrity
regression coverage |
| #574 | 3854345521 | Implemented: `TensorRole \| None` typing |
| #574 | 3854345597 | Implemented: removed obsolete verdict filtering |
| #577 | 3854472859 | Implemented: documented SSM sequence length |
| #578 | 3843112613 | Implemented: documented F64 passthrough |
| #579 | 3854518332 | Implemented: generalized fused-projection error |
| #580 | 3854576300 | Implemented: removed brittle node counts |
| #583 | 3854681386 | Implemented: documented conditional draft outputs
|
| #587 | 3854816872 | Implemented: corrected MTP output contract docs |
| #596 | 3846110059 | Already fixed on base: unambiguous GQA bias
comment |
| #600 | 3855174281 | Implemented: metadata-count-only MTP error |
| #607 | 3855776048 | Implemented: stable route-field assertions |
| #607 | 3855776086 | Implemented: public tensor iterator |
| #609 | 3856486136 | Implemented: fail-closed LM-head comment |

## Current unresolved-thread disposition

This covers all 48 Copilot threads returned by the reproducible
#600-#630
query. The one human #623 thread is excluded.

| PR | Comment | Current-main disposition and evidence |
|---|---:|---|
| #600 | 3855174177 | Already fixed by #629: package cycle and
reserved-sidecar validation |
| #600 | 3855174238 | Already fixed by #629: explicit MTP sidecar
naming/loading |
| #600 | 3855174281 | Implemented here: error no longer invents an
observed block count |
| #602 | 3848155961 | Outside exact stack; already fixed: top-level
`expert_dtype` is classified before early return |
| #602 | 3848155983 | Outside exact stack; still-valid behavioral
block-quant validation, unchanged |
| #602 | 3848156000 | Outside exact stack; still-valid truncated-read
behavioral finding, unchanged |
| #602 | 3848156022 | Outside exact stack; still-valid descriptor
byte/dtype validation, unchanged |
| #602 | 3848156040 | Outside exact stack; still-valid expert-bank
payload validation, unchanged |
| #603 | 3855249765 | Already fixed by #630: runtime preflight preserves
shard sets |
| #603 | 3855249840 | Already fixed by #630: success output follows
durable runtime publication |
| #604 | 3855343082 | Implemented here: graph-only MTP persistence
distinguished from runtime rejection |
| #604 | 3855343131 | Already fixed by #630: runtime success messages
are atomic |
| #607 | 3855776001 | Implemented here: missing generation golden skips
before provenance read |
| #607 | 3855776048 | Implemented here: only stable route fields are
asserted |
| #607 | 3855776086 | Implemented here: tensor count uses
`tensor_items_raw()` |
| #608 | 3856079371 | Still-valid behavioral cache-symlink containment
finding; unchanged |
| #608 | 3856079415 | Still-valid behavioral lowercase-digest validation
finding; unchanged |
| #609 | 3856486136 | Implemented here: comment matches value-preserving
policy |
| #610 | 3855541683 | Already fixed by #628: Falcon bias precedence is
explicit |
| #610 | 3855541761 | Already fixed by #628: CTRL tiny config exercises
projection biases |
| #611 | 3856595840 | Implemented here: runtime test resolves the
distribution providing the module |
| #612 | 3855677383 | Already fixed by #625: supported-version
endianness detection |
| #612 | 3855677427 | Implemented here: shared `INT64_MAX` sentinel |
| #612 | 3855677460 | Implemented here: shared PLaMo2 width inference |
| #612 | 3855677486 | Implemented here: accepted PLaMo2 activation
spellings are explicit |
| #613 | 3855845678 | Implemented here: canonical issue URL |
| #613 | 3855845757 | Implemented here: Mamba-1 function-registration
docs |
| #613 | 3855845806 | Implemented here: test expects the canonical issue
URL |
| #614 | 3855988545 | Implemented here: removed stale Nemotron-H
divergence comments |
| #614 | 3855988597 | Already fixed by #628: zero-head geometry raises
actionable `ValueError` |
| #615 | 3856082290 | Already fixed by #626: dense GraniteHybrid bias
closure |
| #618 | 3856729330 | Implemented here: required routes filter ORT GenAI
evidence |
| #618 | 3856729409 | Implemented here: env-selected runtime version is
authoritative |
| #618 | 3856729490 | Stale/N/A: PR-description-only matrix claim;
repository workflow claims one pinned version |
| #618 | 3856729563 | Implemented here: schema tail restored to normal
indentation |
| #619 | 3856342484 | Already fixed on base: Kimi Linear uses
`/issues/605` |
| #619 | 3856342532 | Already fixed by #628: config rejects convolution
kernels below 2 |
| #619 | 3856342580 | Already fixed by #628: GGUF contract rejects
convolution kernels below 2 |
| #620 | 3855717041 | Already fixed by #627: tied LM-head-only
checkpoints are retained |
| #621 | 3856722324 | Already fixed by #628: Kimi-K3 required metadata
is complete |
| #623 | 3855931210 | N/A to current main: comment belongs to open,
unmerged #623 |
| #623 | 3855939302 | N/A to current main: comment belongs to open,
unmerged #623 |
| #623 | 3855939358 | N/A to current main: comment belongs to open,
unmerged #623 |
| #623 | 3855939394 | N/A to current main: comment belongs to open,
unmerged #623 |
| #624 | 3856777152 | Implemented here: runtime compatibility reuses the
emitted model type |
| #625 | 3857049733 | Implemented here: unsupported header reports both
endian candidates |
| #629 | 3857313182 | Newer post-audit behavioral sidecar-symlink
cleanup finding; unchanged |
| #629 | 3857313251 | Newer post-audit cross-platform path-safety
finding; unchanged |

## Validation

- affected GGUF/package/ORT GenAI/model/schema tests: 1,040 passed
- broad non-integration suite: 7,851 passed, 56 skipped, 1 subtest
passed
- generated GGUF docs checks: 7 passed
- initialized `lintrunner`; full lint/format passed
- GPT-5.6 Sol medium review: one integrity finding fixed; re-review
found no significant issues

Signed-off-by: Justin Chu <[email protected]>
Co-authored-by: Copilot App <[email protected]>
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