| """
|
| DeepX v0.7 — Gated DeltaNet-2 Hyperloop + ColBERT Configuration.
|
|
|
| Architecture:
|
| Begin(4 NarrowA) → Phase1 Loop×2 [WideA + NarrowA×4] → Transition(WideA)
|
| → Phase2 Loop×4 [WideB + NarrowB×4] → End(WideB) = 35 passes
|
|
|
| Gemma 4 E2B layers:
|
| - NarrowA: 8 heads, 1 KV head, head_dim=256, MLP=6144 (layers 0-3, 5-8, 10-13)
|
| - NarrowB: 8 heads, 1 KV head, head_dim=256, MLP=12288 (layers 15-18, 20-23, 25-28, 30-33)
|
| - WideA: 16 heads, 2 KV heads, head_dim=256, MLP=6144 (layers 4, 9, 14)
|
| - WideB: 16 heads, 2 KV heads, head_dim=256, MLP=12288 (layers 19, 24, 29, 34)
|
|
|
| Attention: Gated DeltaNet-2 (dual-path: softmax + delta rule)
|
| Weight Init: Copy Q/K/V/O + MLP from Gemma 4 E2B → ~95% pretrained.
|
| """
|
|
|
| from dataclasses import dataclass
|
| from typing import Optional, List
|
| import torch
|
|
|
|
|
| @dataclass
|
| class NarrowLayerConfig:
|
| """Config for narrow layers (8 heads, 1 KV head)."""
|
| num_heads: int = 8
|
| num_kv_heads: int = 1
|
| head_dim: int = 256
|
| intermediate_size: int = 6144
|
|
|
|
|
| @dataclass
|
| class WideLayerConfig:
|
| """Config for wide layers (16 heads, 2 KV heads)."""
|
| num_heads: int = 16
|
| num_kv_heads: int = 2
|
| head_dim: int = 256
|
| intermediate_size: int = 6144
|
|
|
|
|
| @dataclass
|
| class DeepXConfig:
|
| """
|
| DeepX v0.7 — Gated DeltaNet-2 Hyperloop + ColBERT.
|
|
|
| 35 compute passes matching Gemma 4 E2B depth.
|
| 9 unique layer parameter sets (4 shared cores + 4 begin + 1 end).
|
| """
|
|
|
|
|
| vocab_size: int = 262144
|
| hidden_size: int = 1536
|
| max_position_embeddings: int = 131072
|
|
|
|
|
| dtype: str = "float16"
|
|
|
|
|
|
|
|
|
|
|
| begin_layers: int = 4
|
| phase1_loops: int = 2
|
| phase2_loops: int = 4
|
| end_layers: int = 1
|
|
|
|
|
|
|
|
|
| narrow_a_heads: int = 8
|
| narrow_a_kv_heads: int = 1
|
| narrow_a_head_dim: int = 256
|
| narrow_a_intermediate: int = 6144
|
|
|
|
|
| narrow_b_heads: int = 8
|
| narrow_b_kv_heads: int = 1
|
| narrow_b_head_dim: int = 256
|
| narrow_b_intermediate: int = 12288
|
|
|
|
|
| wide_a_heads: int = 16
|
| wide_a_kv_heads: int = 2
|
| wide_a_head_dim: int = 256
|
| wide_a_intermediate: int = 6144
|
|
|
|
|
| wide_b_heads: int = 16
|
| wide_b_kv_heads: int = 2
|
| wide_b_head_dim: int = 256
|
| wide_b_intermediate: int = 12288
|
|
|
|
|
| chunk_size: int = 64
|
| use_dual_path: bool = True
|
| softmax_init_alpha: float = 2.0
|
| use_short_conv: bool = True
|
| conv_kernel_size: int = 4
|
|
|
|
|
| use_rode: bool = True
|
| depth_rotary_dims: int = 16
|
|
|
|
|
| lora_rank: int = 16
|
| drop_path_rate: float = 0.05
|
|
|
|
|
| rope_theta: float = 1000000.0
|
| rope_scaling_factor: float = 32.0
|
| rope_original_max_position: int = 4096
|
| rope_beta_fast: int = 32
|
| rope_beta_slow: int = 1
|
|
|
|
|
| rms_norm_eps: float = 1e-6
|
| attention_dropout: float = 0.0
|
|
|
|
|
| pooling_strategy: str = "attention"
|
| matryoshka_dims: list = None
|
|
|
|
|
| colbert_dim: int = 128
|
| use_colbert: bool = True
|
|
|
| @property
|
| def torch_dtype(self) -> torch.dtype:
|
| return {"float16": torch.float16, "bfloat16": torch.bfloat16, "float32": torch.float32}[self.dtype]
|
|
|
| def __post_init__(self):
|
| if self.matryoshka_dims is None:
|
| self.matryoshka_dims = [256, 512, 768, 1024, 1536]
|
|
|
|
|
|
|
| HybridEmbeddingConfig = DeepXConfig
|
|
|