β‘ Razor-Spark Combined Foundation Model
Razor-Spark Combined is a unified causal language model combining a 24-layer Differential Multi-Head Latent Attention (Diff-MLA) base controller with 30B Sparse Mixture-of-Experts (MoE) Memory Banks.
Unlike conventional architectures that either inflate memory footprints or lose cross-token attention, Razor-Spark utilizes a gated projection bridge that permanently fuses high-density knowledge shards into selective base attention layers.
π Architecture Overview
βββββββββββββββββββββββββββββββββββββββββ
β Input Tokens (151,936 Vocab, ChatML) β
ββββββββββββββββββββ¬βββββββββββββββββββββ
βΌ
βββββββββββββββββββββββββββββββββββββββββ
β Token Embedding (hidden = 896) β
ββββββββββββββββββββ¬βββββββββββββββββββββ
βΌ
βββββββββββββββββββββββββββββββββββββββββββββββββββ
β Layers 0 - 11: Base Diff-MLA Attention + MLP β
βββββββββββββββββββββββββ¬ββββββββββββββββββββββββββ
βΌ
βββββββββββββββββββββββββββββββββββββββββββββββββββ
β Layers 12, 14, 16, 18, 20, 22 (Fused MoE Banks) β
β β
β x = x + DiffMLA(RMSNorm(x)) β
β x = x + DenseMLP(RMSNorm(x)) β
β x = x + tanh(Ξ±) * W_down(MoE_30B(W_up(Norm))) β
β β
β [31 Routed Experts + 1 Shared Expert, Top-2] β
βββββββββββββββββββββββββ¬ββββββββββββββββββββββββββ
βΌ
βββββββββββββββββββββββββββββββββββββββββββββββββββ
β Layers 13, 15, 17, 19, 21, 23 (Refinement) β
βββββββββββββββββββββββββ¬ββββββββββββββββββββββββββ
βΌ
βββββββββββββββββββββββββββββββββββββββββ
β Final RMSNorm + LM Head (151,936) β
βββββββββββββββββββββββββββββββββββββββββ
Key Architectural Specifications
| Component | Specification |
|---|---|
| Base Hidden Size | 896 |
| Layers | 24 |
| Attention Mechanism | Differential Multi-Head Latent Attention (Diff-MLA) |
| Attention Heads / KV Heads | 14 query heads / 2 KV heads (head_dim = 64) |
| Positional Encodings | Rotary Position Embeddings (RoPE) |
| Base Dense Intermediate Size | 4,864 |
| Fused MoE Layers | Layers [12, 14, 16, 18, 20, 22] |
| MoE Memory Hidden Dimension | 4,096 |
| MoE Intermediate Size | 2,048 |
| Routing Topology | 31 Routed Experts + 1 Shared Expert, Top-2 gating |
| Projection Bridges | $W_{\text{up}} (896 \to 4096)$ and $W_{\text{down}} (4096 \to 896)$ with trainable $\tanh(\alpha)$ |
| Vocabulary Size | 151,936 (BPE with native ChatML special tokens) |
| Inference VRAM Footprint | 6.24 GB (Fits completely on a single 16 GB Tesla T4 or consumer GPU) |
π¬ Benchmark Comparison: Base vs. Combined
| Test Task | Prompt | Detached Base (650M) | Razor-Spark Combined (Base + 30B MoE) |
|---|---|---|---|
| Python Coding | "Write a function to check if a number is prime." | Meta-token loop, invalid logic, no code | 100% Valid Python function (is_prime) |
| Math Reasoning | "Train travels 120 km in 2 hours, what is speed in km/h?" | Fixated on unit text, no calculation | Step-by-step: $120 / 2 = 60 \text{ km/h}$ |
| Concept Definition | "Explain stack vs queue with examples." | Fragmented text | Clear LIFO vs FIFO with application code |
| Algorithm | "Find longest substring without repeating chars." | Failed to follow constraints | Sliding window with hash-map tracking |
| Structured Output | "Extract name, role, location into JSON." | Output unstructured text | Exact JSON matching all schema keys |
π» Quickstart Inference
import torch
from transformers import AutoTokenizer
from razor_spark_combined import RazorSparkCombinedCausalLM
# 1. Load Model and Tokenizer
device = "cuda" if torch.cuda.is_available() else "cpu"
model = RazorSparkCombinedCausalLM.from_pretrained(
base_repo="karthik-a/razor-spark-base",
moe_repo="karthik-a/razor-spark-30b",
device=device
)
tokenizer = AutoTokenizer.from_pretrained("Qwen/Qwen2.5-0.5B-Instruct")
# 2. Format Prompt (ChatML Template)
prompt = (
"<|im_start|>system\n"
"You are Razor-Spark, a helpful and precise AI assistant.<|im_end|>\n"
"<|im_start|>user\n"
"Write a Python function to compute the Fibonacci sequence using memoization.<|im_end|>\n"
"<|im_start|>assistant\n"
)
# 3. Generate
input_ids = tokenizer.encode(prompt, return_tensors="pt").to(device)
output_ids = model.generate(input_ids, max_new_tokens=150, temperature=0.5, top_p=0.9)
response = tokenizer.decode(output_ids[0][input_ids.shape[1]:], skip_special_tokens=True)
print(response)
π Training & Alignment Details
- Phase 1 Alignment: Supervised Fine-Tuning (SFT) on prompt-masked instruction streams (
CodeFeedback-Filtered-Instruction+OpenHermes-2.5). - Loss Convergence: Cross-Entropy loss dropped from 1.0785 to 0.5242 over 150 optimizer steps (600 micro-batches).
- Gate Scalar Evolution: Trainable gate scalars stabilized across all 6 fused layers at $\tanh(\alpha) \approx 0.0507$, creating a balanced dynamic between base contextual attention and MoE memory retrieval.
π£ Roadmap
- Phase 1: Diff-MLA Base + 30B MoE Memory Fusion & Gated Alignment
- Standalone Turnkey Inference Engine (
razor_spark_combined.py) - Phase 2: Post-Fusion Quantization & Knowledge Distillation toward a compact ~1B dense/MoE deployment target (like Qwen).
- Downloads last month
- -