@@ -35,6 +35,16 @@ Read these when you need deeper detail on a specific topic:
3535- Find a small checkpoint on HuggingFace Hub for testing
3636- Have the HuggingFace ` transformers ` source available to reference the
3737 PyTorch implementation
38+ - Pin the checkpoint revision before collecting configs, weights, processors,
39+ parity data, or goldens
40+ - Before a long run, smoke-test the pinned upstream loader in the exact task
41+ interpreter. Record its dependency versions and the selected CUDA provider.
42+ - Use the repository's pinned CI reference dependencies. Assert the validated
43+ layer vocabulary and supported compute dtype for raw JSON and trusted configs;
44+ validators can remap layer names or carry checkpoint storage dtypes.
45+ - If an architecture needs newer upstream code, isolate an immutable reference
46+ pin to its tests; verify installed commit provenance and replay with the
47+ unchanged shared reference dependencies.
3848
3949## Step-by-step
4050
@@ -142,6 +152,9 @@ Standard categories: `"Text Generation"`, `"Mixture of Experts"`,
142152
143153### 3. Identify what's different
144154
155+ Read the actual packed-QKV ordering, gate placement, and RoPE frequency/pair
156+ layout before reusing attention. Similar names or shapes do not prove equivalence.
157+
145158Compare the HuggingFace PyTorch source against ` CausalLMModel ` / ` DecoderLayer ` .
146159Common variations to look for:
147160
@@ -160,6 +173,8 @@ Common variations to look for:
160173| MoE layers | PhiMoE, GPTOSS | See the ** moe-models** skill |
161174| Vision encoder | Gemma3 | See the ** multimodal-models** skill |
162175| Gated attention output | Qwen3.5 | Subclass ` Attention ` with doubled q_proj → Q+gate split |
176+ | Per-head attention gate | LFM3 | Separate head-sized projection; apply gate before output projection |
177+ | Zero-tail partial RoPE | LFM3 | Keep full-head frequency denominator and half-pair layout; do not use compact-prefix rotation |
163178| Hybrid layer types | Qwen3.5 | Use ` config.layer_types ` list to dispatch per-layer |
164179| Fused QKV / gate+up | ModernBERT | Split in ` preprocess_weights ` |
165180| Subclass-only (weight rename) | BLIP, TrOCR | Override only ` preprocess_weights ` |
@@ -183,6 +198,22 @@ class MyCausalLMModel(CausalLMModel):
183198> norms, identity folding), read
184199> [ ` references/weight-preprocessing.md ` ] ( references/weight-preprocessing.md ) .
185200
201+ Before choosing eager preprocessing, estimate the peak memory from the source
202+ checkpoint and transformed tensors. Use an architecture-specific streaming
203+ planner when the checkpoint is large or a packed source must be converted to a
204+ different operator layout. In particular:
205+
206+ - use ` StreamingWeightSource ` for direct one-source/one-target bindings;
207+ - use ` StreamingExpertBankSource ` to assemble per-expert sources;
208+ - use ` StreamingTransformedWeightSource ` for lazy custom repacking;
209+ - distinguish storage semantics explicitly rather than treating every 4-bit,
210+ group-size-32 checkpoint as affine INT4.
211+
212+ The generic streaming engine belongs in ` integrations/_weight_loading.py ` .
213+ Model-specific source names, topology checks, and source-to-target mappings
214+ belong in ` integrations/transformers/_<model>_weights.py ` ; graph math and tensor
215+ transforms belong in the model module.
216+
186217### 5. Register the model
187218
188219Add to ` _create_default_registry() ` in ` src/mobius/_registry.py ` :
@@ -219,6 +250,16 @@ Then add the new module to `src/mobius/_configs/per_model/__init__.py` so its
219250side-effect registration runs at import time. The dispatcher filters hooks by
220251the declared model_type strings, so unrelated models never see your hook.
221252
253+ Match upstream config semantics, not just field names: preserve transformation
254+ order (rounding/scaling), explicit ` None ` , alias precedence, zero-as-disabled
255+ sentinels, and wrapped/unwrapped composite configs. Add focused tests for each
256+ nontrivial transform. Test both trusted/custom config classes and raw pinned
257+ JSON, especially nested decoder fields such as head/layer counts.
258+ Preserve mapping-valued metadata (RoPE, sparse layer overrides, integer-keyed
259+ tables) when adapting config sections. Detect untagged native configs only from
260+ a distinctive complete signature; set compute dtype explicitly and test inherited
261+ ` None ` defaults rather than confusing checkpoint storage dtype with export dtype.
262+
222263### 7. Write tests
223264
224265See the ** writing-tests** skill for full details. At minimum:
@@ -234,10 +275,11 @@ See the **writing-tests** skill for full details. At minimum:
234275 - ` is_representative=True ` if the model has unique behaviour
235276 - ` is_representative=False ` if it's an alias with no special config
236277
237- Then verify: ` pytest tests/build_graph_test.py -k "my_model_type" `
278+ Then verify: ` pytest tests/build_graph -k "my_model_type" `
238279
239- 2 . ** Add a small model to ` tests/integration_test.py ` ** if a small
240- checkpoint exists (< 1B parameters preferred).
280+ 2 . ** Add a small model to the appropriate focused integration suite** if a
281+ small checkpoint exists (< 1B parameters preferred). Generic causal LMs
282+ use ` TEXT_MODELS ` in ` tests/integration/_support.py ` .
241283
2422843 . ** Testing large models with random weights:** Create a reduced HF model:
243285 ``` python
@@ -250,7 +292,7 @@ See the **writing-tests** skill for full details. At minimum:
250292
2512934 . ** Test with the CLI:**
252294 ``` bash
253- mobius build --model org/my-small-model mymodel/output
295+ mobius build --model org/my-small-model --output mymodel/output
254296 ```
255297
256298### 8. Documentation
@@ -269,18 +311,27 @@ see the [quality-checklist skill](../quality-checklist/SKILL.md).
269311- [ ] Class has ` default_task ` and ` category ` attributes (if not standard text-generation)
270312- [ ] Class has a descriptive docstring (first paragraph used in generated docs)
271313- [ ] ` preprocess_weights ` handles any key mismatches
314+ - [ ] Peak checkpoint/transformation memory was assessed; large or packed-layout
315+ conversions use a fail-closed streaming planner
316+ - [ ] Quantized storage semantics are identified from authoritative metadata and
317+ checkpoint headers, not inferred from bit width alone
272318- [ ] Registered in ` _create_default_registry() `
273319- [ ] Exported from ` models/__init__.py `
274320- [ ] Config extraction works (` ArchitectureConfig.from_transformers ` )
275321- [ ] Tiny config in ` tests/_test_configs.py ` (with ` is_representative ` flag)
276- - [ ] L2 YAML test case in ` testdata/cases/ ` with ` test_model_id `
322+ - [ ] Registry ` test_model_id ` and immutable ` test_revision ` set; L2 passes via
323+ ` python -m pytest tests/arch_validation_test.py -k "<model_type>" `
324+ - [ ] Golden YAML in ` testdata/cases/ ` validates against its schema
277325- [ ] L3 synthetic parity passes (` tests/synthetic_parity_test.py -k "<model_type>" ` )
278- - [ ] Integration test in ` tests/integration_test.py ` (if small checkpoint available)
326+ - [ ] Focused integration test in ` tests/integration/ ` (if small checkpoint available)
279327- [ ] L4 golden file generated and committed (` testdata/golden/ ` )
280328- [ ] L5 generation golden file generated and committed
281- - [ ] ORT GenAI test added to ` tests/ort_genai_test.py ` (text-generation and VLM models)
329+ - [ ] Graph-derived ORT GenAI metadata is tested; downstream load/generation is
330+ optional evidence and never an export capability gate
282331- [ ] CLI build works (` mobius build --model ... ` )
283- - [ ] Multi-dtype correctness verified (fp32, fp16, bf16)
332+ - [ ] Each claimed dtype passes full-checkpoint parity, not only tiny tests;
333+ unsupported dtypes fail at construction and graph creation
334+ - [ ] Pinned revision reaches every Hub/processor/weight/golden call
284335
285336** Note:** Default optimizer passes (CSE, deduplicate initializers, identity
286337elimination, remove unused nodes/opsets) are applied automatically.
@@ -347,6 +398,10 @@ long_factor = np.array(config.rope_scaling["long_factor"])
347398long_factor = np.array(config.rope_scaling[" long_factor" ], dtype = np.float32)
348399```
349400
401+ Direct NumPy operands require explicit ONNX constants:
402+ ` op.Constant(value=ir.tensor(long_factor)) ` . Match operator rank contracts too:
403+ ONNX RoPE positions must include the batch axis even if HF broadcasts a 1D input.
404+
350405### 2. Normalization type mismatch (RMSNorm vs LayerNorm)
351406
352407** Symptom:** Large max abs diff (> 0.5) from HuggingFace. Check what norm
@@ -426,6 +481,18 @@ config-driven features for the offending subclass.
426481> embedding table off-by-one), read
427482> [ ` references/weight-preprocessing.md ` ] ( references/weight-preprocessing.md ) .
428483
484+ ### 8. Compatibility and optional dependency traps
485+
486+ - Guard imports of symbols from unpinned dependencies when older supported
487+ versions may not define them.
488+ - If remote code imports an optional package, first prove the selected model
489+ path needs it. Scope any test-only shim to that unused import; do not add a
490+ production fallback or require an irrelevant package.
491+ - When extending a public component, append optional parameters after existing
492+ positional parameters and add a positional-call compatibility test.
493+ - Helpers with rank/shape contracts must receive a value of that rank; do not
494+ rely on incidental compatibility from a higher-rank tensor.
495+
429496## Reference examples
430497
431498| Complexity | File | Why |
0 commit comments