This is a specification document. Implementation has not started. All algorithms, states, and checks are design targets.
Purpose
The analyzer prevents invalid merges before they reach the TensorEngine. It validates architectural alignment, tensor consistency, tokenizer equivalence, and licensing constraints. A failed check at any stage can downgrade the result from COMPATIBLE to CONDITIONALLY_COMPATIBLE or INCOMPATIBLE.Problem Definition
Given a list of N candidate models (N ≥ 2), determine whether the models can participate in a merge operation. The output is a compatibility state per model pair and an aggregated state for the full set.Inputs
Preconditions
- All models are in REGISTERED or higher lifecycle state.
- Config files are present and parseable as JSON.
- State dicts are loadable into memory or via memory-mapped access.
- Tokenizers are present and loadable.
Parameters
Decision Tree
Full Check List
1. Architecture Family
Comparemodel_type fields. Both must be identical (e.g., both llama, both mistral).
2. Model Type
Verifyarchitectures list contains the same class names.
3. Parameter Count
Compute total parameters from state dicts. Reject if ratio exceedsmax_param_ratio.
4. Layer Count
Comparenum_hidden_layers. Must match exactly for COMPATIBLE.
5. Hidden Size
Comparehidden_size. Must match exactly.
6. Intermediate Size
Compareintermediate_size (FFN dimension). Must match exactly.
7. Attention Heads
Comparenum_attention_heads. Must match exactly.
8. KV Heads
Comparenum_key_value_heads. Must match exactly for GQA/MQA models.
9. Embedding Size
Compareembedding_size or hidden_size for embedding layers.
10. Vocabulary Size
Comparevocab_size. Must match exactly if strict_vocab=True.
11. Tokenizer
Compare tokenizer vocabularies, special tokens, and chat templates.12. Special Tokens
Comparebos_token_id, eos_token_id, pad_token_id, unk_token_id.
13. RoPE Configuration
Comparerope_theta, rope_scaling settings.
14. Context Length
Comparemax_position_embeddings.
15. Parameter Names
Compare state dict keys. Must have identical sets for COMPATIBLE.16. Tensor Shapes
For each shared parameter name, compare tensor shapes.17. Dtype
Compare tensor dtypes. Must match ifstrict_dtype=True.
18. Weight Format
Compare serialization format (Safetensors, PyTorch pickle, GGUF).19. Revision / Source
Record model revision, source repository, and download URL.20. License
Verify licenses permit derivative works and redistribution.Output States
Failure Conditions
- Missing config or state dict
- Unparseable JSON
- Unloadable tokenizer
- License prohibits derivative works
- Architecture family mismatch
- Hidden size mismatch
- Layer count mismatch
- Tensor shape mismatch on any shared key
Validation
- Unit test: pair of identical models must return COMPATIBLE.
- Unit test: pair with different
hidden_sizemust return INCOMPATIBLE. - Unit test: pair with same architecture but different tokenizer must return CONDITIONALLY_COMPATIBLE.
- Integration test: feed analyzer output into MergeEngine and verify it rejects INCOMPATIBLE pairs.
Complexity
- Time: O(P) where P is total parameter count (shape inspection only, no data reads).
- Space: O(K) where K is number of state dict keys.
Memory Requirements
Metadata and configs only. No weight data is loaded into GPU memory during compatibility analysis.Numerical Stability
Not applicable. This is a metadata-only check.Precision Considerations
Dtype comparison is symbolic. No numerical values are inspected.Reproducibility
Given identical inputs, the analyzer must produce identical states. No randomness is permitted.Known Limitations
- Does not inspect weight values (only shapes and metadata).
- Does not verify functional equivalence (two models with identical configs may behave differently due to training).
- Does not check for data contamination or benchmark overlap.
Research References
- Model Soups: Wortsman et al. 2022
- Task Arithmetic: Ilharco et al. 2022
- TIES-Merging: Yadav et al. 2023
- DARE: Yu et al. 2023