Skip to content

Commit f188ad8

Browse files
justinchubyCopilot
andcommitted
Reject non-finite Jamba decay tensors
Validate each Jamba Mamba ssm_a tensor before graph construction so non-finite or non-negative values cannot produce invalid A_log initializers. Cover the failure path in the synthetic GGUF importer test. Co-authored-by: Copilot App <[email protected]> Signed-off-by: Justin Chu <[email protected]>
1 parent ecba3ca commit f188ad8

2 files changed

Lines changed: 16 additions & 0 deletions

File tree

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1699,6 +1699,8 @@ def _raise_for_invalid_encoder_tensor_contract(gguf_model) -> None:
16991699

17001700
def _raise_for_invalid_mamba_hybrid_tensor_contract(gguf_model) -> None:
17011701
"""Require the exact dense tensor family for each audited hybrid layer."""
1702+
import numpy as np
1703+
17021704
from mobius.integrations.gguf._config_mapping import _derive_hybrid_layout
17031705

17041706
architecture = gguf_model.architecture
@@ -2027,6 +2029,16 @@ def require_all_or_none(label: str, names: list[str]) -> None:
20272029
)
20282030
if malformed:
20292031
raise ValueError(f"Invalid Jamba GGUF tensor shape(s): {malformed}")
2032+
for index, layer_type in enumerate(layer_types):
2033+
if layer_type != "mamba":
2034+
continue
2035+
decay_name = f"blk.{index}.ssm_a"
2036+
decay = np.asarray(gguf_model.get_tensor(decay_name))
2037+
if not np.all(np.isfinite(decay)) or not np.all(decay < 0):
2038+
raise ValueError(
2039+
f"Malformed Jamba GGUF Mamba decay tensor {decay_name!r}: "
2040+
"ssm_a must contain only finite negative -exp(A_log) values"
2041+
)
20302042

20312043

20322044
def _raise_for_invalid_t5_tensor_contract(gguf_model) -> None:

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -957,6 +957,7 @@ def _write_jamba_gguf(
957957
expert_count: int = 2,
958958
expert_used_count: int = 1,
959959
malformed_shape: str | None = None,
960+
invalid_decay: bool = False,
960961
) -> None:
961962
"""Write a tiny mixed Jamba GGUF with one dense and one routed layer."""
962963
from gguf import GGMLQuantizationType, GGUFWriter
@@ -1007,6 +1008,8 @@ def add_float(
10071008
values = rng.normal(0.0, 0.03, size=shape).astype(np.float32)
10081009
if negative:
10091010
values = -np.exp(values)
1011+
if invalid_decay:
1012+
values.flat[0] = -np.inf
10101013
if expert_order:
10111014
for expert in range(shape[0]):
10121015
values[expert].fill(expert + 1)
@@ -4937,6 +4940,7 @@ def test_quantized_source_keeps_only_compatible_matmul_roles(self, tmp_path: Pat
49374940
({"expert_count": 0, "expert_used_count": 1}, "expert_count"),
49384941
({"expert_count": 1, "expert_used_count": 1}, "not a routed-MoE"),
49394942
({"expert_count": 2, "expert_used_count": 3}, "expert_used_count"),
4943+
({"invalid_decay": True}, "finite negative"),
49404944
({"extra": "blk.0.ssm_in.scale"}, "auxiliary|tensor closure"),
49414945
],
49424946
)

0 commit comments

Comments
 (0)