Skip to content

Commit fcd5b3b

Browse files
justinchubyCopilot
andauthored
Add exact BitNet, embedding, and Talkie GGUF tasks (#641)
## Summary - add an exact dedicated BitNet graph with post-attention/post-FFN subnorms, ternary TQ1_0/TQ2_0 float-import proof, scalar projection-scale folding, and cached prefill/decode parity - add dedicated stateless bidirectional `gemma-embedding` and `llama-embed` feature-extraction graphs with pooling/output ABI, exact attention schedules/scales, optional Gemma dense heads, and package metadata - add an exact Talkie causal graph with weight-free RMSNorm, inverse NeoX RoPE, post-RoPE Q/K normalization, learned Q gain and embedding skip, logit scaling, and dynamic/static KV-cache behavior - add strict pre-build metadata/tensor closure, architecture-owned mappings, real-config YAML evidence, generated support docs, and fail-closed residual blockers ## Promotion boundaries - **BitNet:** exact float import only. Packed preservation remains rejected because available target operators cannot encode ternary codebooks plus scalar sidecars exactly; runtime packaging remains deferred. - **gemma-embedding:** exact dense split-QKV profile, including symmetric local/full attention schedule and optional post-pooling dense modules. - **llama-embed:** exact dense, split-QKV, unbiased, full-head, default-RoPE profile. The pinned Nemotron artifact's factor-8 Llama 3 RoPE remains explicitly blocked. - **Talkie:** exact pinned scalar-gain/skip profile only. The public PocketAI artifact's hidden-width skip vector and missing pinned logit scale remain explicitly blocked. - Quantized embedding and Talkie imports remain rejected. Quantized BitNet claims are limited to value-proven dequantized float import; no packed runtime claim is made. ## Evidence - nonzero NumPy/ORT Talkie prefill and decode parity, including cached normalized/RoPE K/V values - deterministic embedding parity proving future-token visibility, padding, local windows, pooling, dense projection, and no-cache ABI - synthetic package-level GGUF builds for both embedding architectures and Talkie - value-level TQ1_0/TQ2_0 packed decoding and BitNet HF/ORT cached parity - pinned real-artifact configs with explicit waivers where public files fall outside promoted closure ## Validation - initialized all-files lint: clean - focused specialized gate: `62 passed, 1607 deselected` - broad serial non-integration: `8297 passed, 57 skipped, 12 deselected, 1 subtest passed` - direct GPT-5.6 Sol medium architecture/regression review completed; fixed fail-open Gemma dense-without-pooling profile and reran affected/full gates Base: `6617fe2b69aa9b2cd1a08dbe18a7563ac4ad7f32` --------- Signed-off-by: Justin Chu <[email protected]> Co-authored-by: Copilot App <[email protected]> Copilot-Session: 6f7146cd-ceda-48ee-a494-06d3b12bc12d
1 parent 6617fe2 commit fcd5b3b

29 files changed

Lines changed: 2468 additions & 30 deletions

‎docs/api/build_from_gguf.md‎

Lines changed: 5 additions & 5 deletions
Large diffs are not rendered by default.

‎src/mobius/_configs/_base.py‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -486,6 +486,8 @@ class ArchitectureConfig(BaseModelConfig):
486486
encoder_extra_attention_norm: bool = False
487487
encoder_fused_geglu: bool = False
488488
pooling_type: int = 0
489+
embedding_dense_2_out: int | None = None
490+
embedding_dense_3_in: int | None = None
489491

490492
# Encoder-decoder config
491493
num_decoder_layers: int | None = None

‎src/mobius/_registry.py‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
from mobius.models import (
5151
ApertusCausalLMModel,
5252
ArceeCausalLMModel,
53+
BitNetCausalLMModel,
5354
CausalLMModel,
5455
ChatGLMCausalLMModel,
5556
CodeShellCausalLMModel,
@@ -158,6 +159,7 @@
158159
from mobius.models.falcon_h1 import FalconH1ForCausalLM
159160
from mobius.models.fun_asr import FunASRForConditionalGeneration
160161
from mobius.models.gemma3n import Gemma3nCausalLMModel, Gemma3nMultiModalModel
162+
from mobius.models.gguf_embeddings import GemmaEmbeddingGGUFModel, LlamaEmbedGGUFModel
161163
from mobius.models.gguf_encoders import (
162164
EuroBertGGUFModel,
163165
JinaBertV2GGUFModel,
@@ -198,6 +200,7 @@
198200
from mobius.models.sensevoice_small import SenseVoiceSmallModel
199201
from mobius.models.starcoder2 import StarCoder2CausalLMModel
200202
from mobius.models.t5 import T5EncoderModel, T5ForConditionalGeneration
203+
from mobius.models.talkie import TalkieForCausalLM
201204
from mobius.models.trocr import TrOCRForConditionalGeneration
202205
from mobius.models.vit import ViTModel
203206
from mobius.models.wav2vec2 import Wav2Vec2Model
@@ -465,6 +468,8 @@ def _detect_fallback_registration(hf_config) -> ModelRegistration | None:
465468
# --- Text Generation (architecture-specific) ---
466469
"apertus": ModelRegistration(ApertusCausalLMModel),
467470
"arcee": ModelRegistration(ArceeCausalLMModel),
471+
"bitnet": ModelRegistration(BitNetCausalLMModel),
472+
"talkie": ModelRegistration(TalkieForCausalLM),
468473
"bloom": ModelRegistration(BloomCausalLMModel),
469474
"orion": ModelRegistration(LayerNormCausalLMModel),
470475
"chatglm": ModelRegistration(ChatGLMCausalLMModel),
@@ -846,6 +851,12 @@ def _detect_fallback_registration(hf_config) -> ModelRegistration | None:
846851
"nomic_bert_gguf": ModelRegistration(
847852
NomicBertGGUFModel, task="gguf-encoder-feature-extraction"
848853
),
854+
"gemma_embedding_gguf": ModelRegistration(
855+
GemmaEmbeddingGGUFModel, task="gguf-embedding-feature-extraction"
856+
),
857+
"llama_embed_gguf": ModelRegistration(
858+
LlamaEmbedGGUFModel, task="gguf-embedding-feature-extraction"
859+
),
849860
"mpnet": ModelRegistration(BertModel, task="feature-extraction"),
850861
"mra": ModelRegistration(BertModel, task="feature-extraction"),
851862
"nezha": ModelRegistration(BertModel, task="feature-extraction"),
@@ -1040,6 +1051,8 @@ def _create_default_registry() -> ModelRegistry:
10401051
"baichuan": "baichuan-inc/Baichuan2-7B-Chat",
10411052
"apertus": "swiss-ai/Apertus-8B-Instruct-2509",
10421053
"arcee": "arcee-ai/AFM-4.5B-Base",
1054+
"bitnet": "microsoft/bitnet-b1.58-2B-4T",
1055+
"talkie": "PocketAiHub/talkie-1930-13b-it-GGUF",
10431056
"diffllama": "kajuma/DiffLlama-0.3B-handcut",
10441057
"doge": "SmallDoge/Doge-20M",
10451058
"dots1": "rednote-hilab/dots.llm1.inst",
@@ -1076,13 +1089,15 @@ def _create_default_registry() -> ModelRegistry:
10761089
"gemma2": "google/gemma-2-2b",
10771090
"gemma3": "google/gemma-3-4b-it",
10781091
"gemma3_text": "google/gemma-3-1b-pt",
1092+
"gemma_embedding_gguf": "unsloth/embeddinggemma-300m-GGUF",
10791093
# No text-only gemma3n checkpoint was ever published; the -it releases are
10801094
# multimodal, and "gemma3n_text" reaches the text path via _TEXT_ONLY_MODEL_TYPE.
10811095
"gemma3n": "google/gemma-3n-E4B-it",
10821096
"gemma3n_text": "google/gemma-3n-E2B-it",
10831097
"gemma4_text": "google/gemma-4-E2B-it",
10841098
"granite": "ibm-granite/granite-3.3-2b-instruct",
10851099
"internlm2": "internlm/internlm2_5-7b-chat",
1100+
"llama_embed_gguf": "mradermacher/llama-embed-nemotron-8b-GGUF",
10861101
"nemotron": "nvidia/Nemotron-Mini-4B-Instruct",
10871102
"olmo": "allenai/OLMo-1B-hf",
10881103
"olmo2": "allenai/OLMo-2-1124-7B",

‎src/mobius/components/_attention.py‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -399,9 +399,13 @@ def forward(
399399
static_cache=static_cache,
400400
)
401401

402-
attn_output = self.o_proj(op, attn_output)
402+
attn_output = self._project_output(op, attn_output)
403403
return attn_output, (present_key, present_value)
404404

405+
def _project_output(self, op: OpBuilder, attn_output: ir.Value) -> ir.Value:
406+
"""Apply architecture-specific processing before the output projection."""
407+
return self.o_proj(op, attn_output)
408+
405409
def _forward_gqa(
406410
self,
407411
op: OpBuilder,
@@ -458,7 +462,7 @@ def _forward_gqa(
458462
**gqa_attrs,
459463
)
460464

461-
attn_out = self.o_proj(op, attn_out)
465+
attn_out = self._project_output(op, attn_out)
462466
return attn_out, (present_key, present_value)
463467

464468

‎src/mobius/integrations/gguf/_arch_registry.py‎

Lines changed: 92 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,16 @@
9393
"weights. Use keep_quantized=False for explicit float import."
9494
)
9595

96+
_BITNET_IMPORT_REASON = (
97+
"The exact float route is implemented: TQ1_0/TQ2_0 blocks are dequantized by "
98+
"the pinned gguf reader, optional scalar projection scales are folded into those "
99+
"values, and the dedicated graph owns both sub-norms. Quantization-preserving "
100+
"import is rejected because the current MatMulNBits ABI is affine and cannot "
101+
"represent BitNet's ternary codebook plus architecture-level scalar sidecars "
102+
"without an independently value-proven repack. Runtime packaging remains "
103+
"deferred pending real full-logit prefill and cached-decode parity."
104+
)
105+
96106
_ARCTIC_GGUF_GRAPH_REASON = (
97107
"The pinned Arctic graph is not a standard pre-norm MoE block: every layer runs a "
98108
"dense parallel SwiGLU branch, then adds a separately normalized routed-expert branch "
@@ -395,11 +405,6 @@
395405
"conditional Q/K norms for large variants, tied output, and logit scaling. The "
396406
"canonical command-r and cohere2 GGUF contracts are distinct and cannot alias."
397407
),
398-
"gemma-embedding": (
399-
"Gemma Embedding is a bidirectional stateless embedding graph with alternating "
400-
"sliding-window attention, four norm sites, sqrt(hidden) embedding scaling, and "
401-
"optional pooling/dense modules. Causal Gemma3 text/VLM tasks expose the wrong ABI."
402-
),
403408
"gptneox": (
404409
"GPT-NeoX GGUF requires fused biased QKV, bias-bearing LayerNorm/GELU blocks, "
405410
"partial RoPE, and metadata-selected parallel versus sequential residual topology. "
@@ -513,12 +518,6 @@
513518
"correction-biased routed/shared experts. Mobius has no exact graph or iSWA cache "
514519
"contract."
515520
),
516-
"llama-embed": (
517-
"llama-embed is a canonical embedding architecture that inherits Llama's "
518-
"conditional tensor loader but exposes the embedding graph rather than causal "
519-
"logits. Mobius has no GGUF embedding task/package contract for this ID, so it "
520-
"must not alias ordinary llama."
521-
),
522521
"mellum": (
523522
"Mellum requires an untied head, Q/K norms, routed experts in every layer, and a "
524523
"metadata-defined full/sliding attention schedule with distinct RoPE behavior. "
@@ -621,6 +620,18 @@
621620

622621

623622
_SPECS: tuple[GGUFArchitectureSpec, ...] = (
623+
# --------------------------------------------------------------- BitNet
624+
GGUFArchitectureSpec(
625+
gguf_arch="bitnet",
626+
model_type="bitnet",
627+
tensor_map_recipe=("bitnet",),
628+
tensor_processor="bitnet",
629+
llama_qk_permute=True,
630+
required_metadata=("attention.layer_norm_rms_epsilon",),
631+
quantized_import=Support.REJECTED,
632+
runtime=Support.DEFERRED,
633+
reason=_BITNET_IMPORT_REASON,
634+
),
624635
# ---------------------------------------------------------------- Llama
625636
GGUFArchitectureSpec(
626637
gguf_arch="llama",
@@ -1426,6 +1437,49 @@
14261437
"quantization route; use keep_quantized=False."
14271438
),
14281439
),
1440+
GGUFArchitectureSpec(
1441+
gguf_arch="gemma-embedding",
1442+
model_type="gemma3_text",
1443+
module_type="gemma_embedding_gguf",
1444+
tensor_map_recipe=("gemma_embedding",),
1445+
config_postprocessor="gguf_embedding",
1446+
required_metadata=(
1447+
"attention.causal",
1448+
"attention.layer_norm_rms_epsilon",
1449+
"attention.sliding_window",
1450+
"rope.freq_base",
1451+
"rope.dimension_count",
1452+
),
1453+
runtime=Support.DEFERRED,
1454+
quantized_import=Support.REJECTED,
1455+
reason=(
1456+
"The exact float embedding graph and package ABI are covered, but no "
1457+
"onnxruntime-genai embedding package schema/runtime evidence is recorded. "
1458+
"Packed projection preservation is deliberately rejected pending value-level "
1459+
"proof for this dedicated graph; use keep_quantized=False."
1460+
),
1461+
),
1462+
GGUFArchitectureSpec(
1463+
gguf_arch="llama-embed",
1464+
model_type="llama",
1465+
module_type="llama_embed_gguf",
1466+
tensor_map_recipe=("llama_embedding",),
1467+
config_postprocessor="gguf_embedding",
1468+
required_metadata=(
1469+
"attention.causal",
1470+
"attention.layer_norm_rms_epsilon",
1471+
"rope.freq_base",
1472+
"rope.dimension_count",
1473+
),
1474+
runtime=Support.DEFERRED,
1475+
quantized_import=Support.REJECTED,
1476+
reason=(
1477+
"Only the complete dense, split-QKV, unbiased, default-RoPE float profile is "
1478+
"promoted. MoE, fused-QKV, bias-bearing, and rope-factor/scaled variants fail "
1479+
"closed before config extraction. Runtime packaging and packed value "
1480+
"preservation remain unproven; use keep_quantized=False."
1481+
),
1482+
),
14291483
*(
14301484
GGUFArchitectureSpec(
14311485
gguf_arch=architecture,
@@ -2157,11 +2211,31 @@
21572211
),
21582212
GGUFArchitectureSpec(
21592213
gguf_arch="talkie",
2160-
config=Support.DEFERRED,
2161-
tensor_map=Support.DEFERRED,
2162-
graph=Support.DEFERRED,
2214+
model_type="talkie",
2215+
tensor_map_recipe=("talkie",),
2216+
config_postprocessor="talkie",
2217+
required_metadata=(
2218+
"context_length",
2219+
"embedding_length",
2220+
"feed_forward_length",
2221+
"block_count",
2222+
"attention.head_count",
2223+
"attention.head_count_kv",
2224+
"attention.layer_norm_rms_epsilon",
2225+
"rope.freq_base",
2226+
"rope.dimension_count",
2227+
"logit_scale",
2228+
),
21632229
runtime=Support.DEFERRED,
2164-
reason=_TALKIE_GRAPH_REASON,
2230+
quantized_import=Support.REJECTED,
2231+
reason=(
2232+
"The exact pinned scalar-sidecar float graph is covered, including weight-free "
2233+
"RMSNorm, inverse NeoX RoPE, post-RoPE Q/K normalization, per-head Q gain, "
2234+
"embedding skip, causal KV cache, and logit scaling. The public GGUF stores "
2235+
"embedding skip as a hidden-width vector and omits pinned logit_scale metadata, "
2236+
"so it is not evidence for this promoted scalar profile. Runtime packaging and "
2237+
"packed projection preservation remain deferred; use keep_quantized=False."
2238+
),
21652239
),
21662240
GGUFArchitectureSpec(
21672241
gguf_arch="wavtokenizer-dec",
@@ -2183,11 +2257,13 @@
21832257
for architecture, reason in _FINAL_CENSUS_DEFERRED_REASONS.items()
21842258
if architecture
21852259
not in {
2260+
"bitnet",
21862261
"codeshell",
21872262
"command-r",
21882263
"ernie4_5",
21892264
"gptneox",
21902265
"jais",
2266+
"gemma-embedding",
21912267
"jais2",
21922268
"minicpm",
21932269
"plm",
@@ -2196,6 +2272,7 @@
21962272
"qwen",
21972273
"refact",
21982274
"starcoder",
2275+
"llama-embed",
21992276
"xverse",
22002277
}
22012278
),

‎src/mobius/integrations/gguf/_arch_registry_test.py‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,10 @@
6060
#: Number of importable architectures. Pinned so that adding support is a
6161
#: deliberate act that also updates the documented support matrix, and so that
6262
#: accidentally losing an architecture is a failure rather than a silence.
63-
_EXPECTED_SUPPORTED_COUNT = 85
63+
_EXPECTED_SUPPORTED_COUNT = 89
6464
_PROMOTED_CONVENTIONAL_DECODERS = frozenset(
6565
{
66+
"bitnet",
6667
"codeshell",
6768
"command-r",
6869
"ernie4_5",
@@ -77,6 +78,8 @@
7778
"plm",
7879
"qwen",
7980
"refact",
81+
"gemma-embedding",
82+
"llama-embed",
8083
"starcoder",
8184
"xverse",
8285
}
@@ -302,12 +305,15 @@ def test_every_float_importable_architecture_has_a_quantized_verdict(self) -> No
302305
}
303306
assert set(actual) == set(supported_architectures())
304307
rejected = {
308+
"bitnet",
305309
"chatglm",
306310
"ernie4_5",
307311
"eurobert",
312+
"gemma-embedding",
308313
"granitehybrid",
309314
"internlm2",
310315
"jina-bert-v2",
316+
"llama-embed",
311317
"lfm2moe",
312318
"mamba",
313319
"mamba2",
@@ -327,6 +333,7 @@ def test_every_float_importable_architecture_has_a_quantized_verdict(self) -> No
327333
"qwen",
328334
"refact",
329335
"starcoder",
336+
"talkie",
330337
"xverse",
331338
}
332339
assert all(actual[arch] is Support.REJECTED for arch in rejected)
@@ -949,7 +956,6 @@ def test_wavtokenizer_heterogeneous_stacks_are_literal(self) -> None:
949956
[
950957
"pockettts",
951958
"qwen3tts",
952-
"talkie",
953959
"wavtokenizer-dec",
954960
],
955961
)

0 commit comments

Comments
 (0)