Skip to content

Commit 4051280

Browse files
committed
feat: implement sequence-length aware path-c routing and add side channel spec support
1 parent 001e868 commit 4051280

34 files changed

Lines changed: 2670 additions & 1528 deletions

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,8 @@ Repo hygiene:
6565
- Keep .venv, __pycache__, pytest caches, .beads, agent logs, and
6666
data/parquet_samples/ out of commits. The Parquet samples are useful for
6767
local real-data smoke tests, but they are large local artifacts, not repo
68-
fixtures.
68+
fixtures and remain not checked-in fixtures. The only parquet files allowed
69+
in git are committed tiny pytest fixtures under tests/fixtures/parquet/.
6970

7071
Non-goals and limits:
7172

cppmega_mlx/data/batch.py

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,31 @@ def as_dict(self, *, include_metadata: bool = False) -> dict[str, Any]:
224224
return data
225225

226226

227+
_DOCUMENT_ID_ALIASES = ("document_ids", "doc_ids", "packing_document_ids")
228+
229+
230+
def _document_ids_from_mapping(batch: Mapping[str, Any]) -> Any | None:
231+
present = [
232+
alias
233+
for alias in _DOCUMENT_ID_ALIASES
234+
if alias in batch and batch[alias] is not None
235+
]
236+
if len(present) > 1:
237+
raise ValueError(
238+
"only one document-id alias may be provided; got "
239+
f"{', '.join(present)}"
240+
)
241+
if not present:
242+
return None
243+
alias = present[0]
244+
value = batch[alias]
245+
has_negative_doc = mx.any(value.astype(mx.int32) < 0)
246+
mx.eval(has_negative_doc)
247+
if bool(has_negative_doc.item()):
248+
raise ValueError(f"{alias} must be non-negative")
249+
return value
250+
251+
227252
def ensure_lm_batch(batch: LMTokenBatch | Mapping[str, Any] | mx.array) -> LMTokenBatch:
228253
"""Normalize supported tiny-trainer batch inputs into LMTokenBatch."""
229254

@@ -239,10 +264,7 @@ def ensure_lm_batch(batch: LMTokenBatch | Mapping[str, Any] | mx.array) -> LMTok
239264
target_tokens=batch.get("target_tokens", batch.get("target_ids")),
240265
attention_mask=batch.get("attention_mask"),
241266
loss_mask=batch.get("loss_mask"),
242-
document_ids=batch.get(
243-
"document_ids",
244-
batch.get("doc_ids", batch.get("packing_document_ids")),
245-
),
267+
document_ids=_document_ids_from_mapping(batch),
246268
structure_ids=batch.get("structure_ids"),
247269
dep_levels=batch.get("dep_levels"),
248270
ast_depth_ids=batch.get("ast_depth_ids"),

cppmega_mlx/models/hybrid_lm.py

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -837,14 +837,12 @@ def path_c_parameter_logical_aliases(self) -> dict[str, tuple[str, ...]]:
837837
}
838838
aliases: dict[str, tuple[str, ...]] = {}
839839

840-
def add(
841-
layer_index: int,
842-
parameter_suffix: str,
840+
def add_parameter(
841+
parameter_name: str,
843842
logical_suffix: str,
844843
*,
845844
block: HybridTinyBlock,
846845
) -> None:
847-
parameter_name = f"layers.{layer_index}.{parameter_suffix}"
848846
if parameter_name not in parameter_names:
849847
return
850848
logical_prefixes = [block.path_c_brick_name]
@@ -855,13 +853,27 @@ def add(
855853
f"{prefix}_{logical_suffix}" for prefix in logical_prefixes
856854
)
857855

858-
for index, block in enumerate(self.layers):
859-
add(
860-
index,
861-
"norm.weight",
856+
def add(
857+
layer_index: int,
858+
parameter_suffix: str,
859+
logical_suffix: str,
860+
*,
861+
block: HybridTinyBlock,
862+
) -> None:
863+
add_parameter(
864+
f"layers.{layer_index}.{parameter_suffix}",
865+
logical_suffix,
866+
block=block,
867+
)
868+
869+
for index, block in enumerate(self.layers[:-1]):
870+
add_parameter(
871+
f"layers.{index + 1}.norm.weight",
862872
"residual_norm_weight",
863873
block=block,
864874
)
875+
876+
for index, block in enumerate(self.layers):
865877
if block.backend == "mamba3":
866878
for parameter_suffix, logical_suffix in (
867879
("block.in_proj.weight", "mamba3_in_proj_weight"),

0 commit comments

Comments
 (0)