🐻🔥 Model Rampage
model-rampage/BareTorch-Qwen3.5-2B-Hybrid
Building Hardware-Portable, Pure-GEMM Sub-Quadratic LLM Architectures for the Edge & Cloud
🌟 Overview
model-rampage/BareTorch-Qwen3.5-2B-Hybrid is a high-efficiency CS-LRAD (Chunked Selective Low-Rank Associative Delta) hybrid language model surgically distilled from Qwen/Qwen3.5-2B and up-distilled from Qwen/Qwen3.5-4B using the multi-stage BareTorch Layerwise Up-Distillation Engine.
While existing sub-quadratic architectures (such as Mamba-2, RWKV, and Gated DeltaNet) rely on hardware-locked C++/CUDA/Triton extensions (causal-conv1d, flash-linear-attention) that fail to port cleanly to systolic arrays and edge devices, BareTorch formulates sub-quadratic sequence mixing using 100% standard matrix multiplications (GEMMs) and an exact $O(1)$ low-rank recurrent associative state update for decoding.
By replacing 75% of the backbone's token mixers (18 of 24 layers) with pure-PyTorch torch.compile-compatible low-rank (r=32, chunk_size=64) associative recurrent blocks while preserving 6 interleaved Full-Attention anchor layers, model-rampage/BareTorch-Qwen3.5-2B-Hybrid delivers:
- 105.0% Retention (+3.05%) over
Qwen/Qwen3.5-2Bon the 10-tasklm-evaluation-harnesssuite (64.45%vs.61.40%macro average). - 117.7% Retention (+3.83%) over
Qwen/Qwen3.5-2Bon the 5-task<think>Generative Reasoning & Python Coding suite (25.50%vs.21.67%macro average, including24.20%MBPP Pass@1 and25.67%GPQA-Diamond). - Up to 1.63x faster prefill, 1.09x faster autoregressive decoding, 2.3x smaller short-context cache, and 310 MB lower 32K Peak VRAM than native
Qwen3.5-2Bon an NVIDIA RTX 4090—with zero custom CUDA/Triton C++ dependencies (causal-conv1d/flanot required).
🏗️ Architecture Highlights
| Property | Value |
|---|---|
| Architecture Type | 3:1 Interleaved Hybrid (18 CS-LRAD Recurrent + 6 Full-Attention) |
| Active Parameters | 1899.7M (bf16, Static Weights VRAM: ~3.71 GB) |
Hidden Dimension (d_model) | 2048 (8 Query Heads, 2 KV Heads) |
CS-LRAD Low-Rank State (r) | rank = 32, chunk_size = 64 |
| Context Window | 32,768 tokens (512 chunks) |
| Base Architecture Teacher | Qwen/Qwen3.5-2B |
| Stage 4B/4C Skew-KD Teacher | Qwen/Qwen3.5-4B (Top-64 Skew-KL + Skew-RKL + 4-Pillar <think> Dr. GRPO) |
| Distillation Pipeline Repo | github.com/martin-kbcc/BareTorch_Layerwise_Distill |
🚀 Quickstart: Loading & Inference (transformers + torch.compile)
No external custom C++/CUDA packages are required—only torch and transformers. Simply pass trust_remote_code=True, and call model.compile_cs_lrad() to enable TorchInductor kernel fusion across all CS-LRAD blocks (accelerating both prefill and decoding with dynamic=True so variable prompt lengths never trigger recompilation stalls):
1. Single-Prompt Inference (With model.compile_cs_lrad() Hardware Acceleration)
import torch
from transformers import AutoTokenizer, AutoModelForCausalLM
model_id = "model-rampage/BareTorch-Qwen3.5-2B-Hybrid"
device = "cuda" if torch.cuda.is_available() else "cpu"
tokenizer = AutoTokenizer.from_pretrained(model_id, trust_remote_code=True)
model = AutoModelForCausalLM.from_pretrained(
model_id,
dtype=torch.bfloat16,
device_map=device,
trust_remote_code=True,
).eval()
# Compile all CS-LRAD blocks (chunk_forward, RMSNorms, SwiGLU MLPs) with dynamic=True
# Note: First call takes ~10s to JIT-compile fused Triton kernels; subsequent calls run at peak speed!
if torch.cuda.is_available():
model.compile_cs_lrad(mode="default", dynamic=True)
# Example: Step-by-Step <think> Math / Scientific Reasoning
reasoning_prompt = (
"Question: A store sells notebooks for $4 each and pens for $1.50 each. "
"If Maria buys 6 notebooks and 8 pens, how much change does she get from a $50 bill?\n"
"Answer: <think>\n"
)
inputs = tokenizer(reasoning_prompt, return_tensors="pt").to(device)
with torch.no_grad():
outputs = model.generate(
**inputs,
max_new_tokens=256,
do_sample=False,
use_cache=True,
pad_token_id=tokenizer.eos_token_id,
)
print(tokenizer.decode(outputs[0, inputs["input_ids"].shape[1]:], skip_special_tokens=True))
2. Batched Multi-Prompt Generation
prompts = [
"Question: What is the primary function of mitochondria in eukaryotic cells?\nAnswer:",
"Question: Solve for x: 4x + 9 = 33.\nAnswer: <think>\n",
"You are an expert Python programmer, and here is your task: Write a function `is_palindrome(s)` that returns True if a string is a palindrome.\n",
]
tokenizer.padding_side = "left"
if tokenizer.pad_token_id is None:
tokenizer.pad_token_id = tokenizer.eos_token_id
batch_inputs = tokenizer(prompts, return_tensors="pt", padding=True).to(device)
prompt_padded_len = batch_inputs["input_ids"].shape[1]
with torch.no_grad():
batch_outputs = model.generate(
**batch_inputs,
max_new_tokens=192,
do_sample=False,
use_cache=True,
pad_token_id=tokenizer.pad_token_id,
)
for i, prompt in enumerate(prompts):
generated_text = tokenizer.decode(batch_outputs[i, prompt_padded_len:], skip_special_tokens=True)
print(f"=== Prompt {i+1} ===\n{generated_text}\n")
📊 Benchmark Results
1. Non-Generative Benchmarks (lm-evaluation-harness 10-Task Suite)
| Benchmark | Metric | Base Teacher (Qwen/Qwen3.5-2B) | BareTorch Hybrid (2B) | Delta (S - T) | Retention |
|---|---|---|---|---|---|
| ARC-Challenge | acc_norm | 41.38% | 53.84% | +12.46% | 130.1% |
| ARC-Easy | acc_norm | 66.25% | 81.40% | +15.15% | 122.9% |
| BoolQ | acc | 71.80% | 79.88% | +8.07% | 111.2% |
| HellaSwag | acc_norm | 62.05% | 58.19% | -3.86% | 93.8% |
| LAMBADA (OpenAI) | acc | 53.29% | 46.81% | -6.48% | 87.8% |
| MMLU (57 Subjects) | acc | 59.17% | 49.50% | -9.67% | 83.7% |
| MMLU - Humanities | acc | 52.35% | 43.97% | -8.37% | 84.0% |
| MMLU - Other | acc | 63.12% | 53.14% | -9.98% | 84.2% |
| MMLU - Social Sciences | acc | 67.86% | 58.04% | -9.81% | 85.5% |
| MMLU - STEM | acc | 56.99% | 45.83% | -11.16% | 80.4% |
| OpenBookQA | acc_norm | 35.60% | 38.40% | +2.80% | 107.9% |
| PIQA | acc_norm | 72.85% | 73.83% | +0.98% | 101.3% |
| SciQ | acc_norm | 88.50% | 97.00% | +8.50% | 109.6% |
| WinoGrande | acc | 63.06% | 65.67% | +2.60% | 104.1% |
| 10-Task Macro Average | mean_acc | 61.40% | 64.45% | +3.05% | 105.0% |
2. Generative Reasoning & Coding Suite (5-Task <think> & Unit-Test Suite)
| Generative Benchmark | Metric | Base Teacher (Qwen/Qwen3.5-2B) | BareTorch Hybrid (2B) | Delta (S - T) | Retention |
|---|---|---|---|---|---|
GSM8K (<think> CoT Math) | exact_match | 65.60% | 47.40% | -18.20% | 72.3% |
MATH-500 (<think> Boxed) | boxed_match | 20.60% | 15.60% | -5.00% | 75.7% |
| GPQA-Diamond (PhD STEM) | mc_think | 4.69% | 25.67% | +20.98% | 547.6% |
| MBPP (Python Synthesis) | pass@1 | 1.60% | 24.20% | +22.60% | 1512.5% |
| HumanEval (Python Synthesis) | pass@1 | 15.85% | 14.63% | -1.22% | 92.3% |
| 5-Task Generative Average | macro_avg | 21.67% | 25.50% | +3.83% | 117.7% |
3. Hardware Speed & Memory Footprint (BareTorch-Qwen3.5-2B-Hybrid vs. Native Qwen3.5-2B on NVIDIA RTX 4090 — 512 to 32,768 Context)
| Context Length | Model | TTFT (ms) | Prefill (tok/s) | Decode (tok/s) | KV-Cache (MB) | Peak VRAM (GB) | Speedup / Memory Savings |
|---|---|---|---|---|---|---|---|
| 512 | BareTorch-Qwen3.5-2B-Hybrid (r=32, Compiled) | 24.4 ms | 20,967 tok/s | 47.6 tok/s | 11.2 MB | 3.65 GB | 1.63x Prefill, 1.07x Decode, 2.3x Smaller Cache |
| 512 | Qwen3.5-2B (Native) | 39.9 ms | 12,827 tok/s | 44.5 tok/s | 25.6 MB | 3.57 GB | Baseline |
| 1,024 | BareTorch-Qwen3.5-2B-Hybrid (r=32, Compiled) | 31.4 ms | 32,618 tok/s | 47.9 tok/s | 17.2 MB | 3.62 GB | 1.27x Prefill, 1.07x Decode, 1.8x Smaller Cache |
| 1,024 | Qwen3.5-2B (Native) | 39.8 ms | 25,706 tok/s | 44.8 tok/s | 31.6 MB | 3.61 GB | Baseline |
| 2,048 | BareTorch-Qwen3.5-2B-Hybrid (r=32, Compiled) | 61.6 ms | 33,237 tok/s | 47.0 tok/s | 29.2 MB | 3.70 GB | 1.00x Prefill, 1.05x Decode, 1.5x Smaller Cache |
| 2,048 | Qwen3.5-2B (Native) | 61.7 ms | 33,166 tok/s | 44.7 tok/s | 43.6 MB | 3.70 GB | Baseline |
| 4,096 | BareTorch-Qwen3.5-2B-Hybrid (r=32, Compiled) | 119.9 ms | 34,169 tok/s | 47.8 tok/s | 53.2 MB | 3.84 GB | 1.03x Prefill, 1.05x Decode, 1.3x Smaller Cache |
| 4,096 | Qwen3.5-2B (Native) | 123.1 ms | 33,263 tok/s | 45.5 tok/s | 67.6 MB | 3.86 GB | Baseline |
| 8,192 | BareTorch-Qwen3.5-2B-Hybrid (r=32, Compiled) | 253.3 ms | 32,343 tok/s | 47.7 tok/s | 101.2 MB | 4.13 GB | 1.07x Prefill, 1.05x Decode, 1.1x Smaller Cache |
| 8,192 | Qwen3.5-2B (Native) | 271.3 ms | 30,198 tok/s | 45.6 tok/s | 115.6 MB | 4.19 GB | Baseline |
| 16,384 | BareTorch-Qwen3.5-2B-Hybrid (r=32, Compiled) | 534.2 ms | 30,672 tok/s | 48.1 tok/s | 197.2 MB | 4.71 GB | 1.08x Prefill, 1.09x Decode, 140 MB Less VRAM |
| 16,384 | Qwen3.5-2B (Native) | 577.0 ms | 28,395 tok/s | 44.2 tok/s | 211.6 MB | 4.85 GB | Baseline |
| 32,768 | BareTorch-Qwen3.5-2B-Hybrid (r=32, Compiled) | 1191.9 ms | 27,493 tok/s | 46.8 tok/s | 389.2 MB | 5.87 GB | 1.06x Prefill, 1.03x Decode, 310 MB Less VRAM |
| 32,768 | Qwen3.5-2B (Native) | 1262.6 ms | 25,952 tok/s | 45.3 tok/s | 403.6 MB | 6.18 GB | Baseline |
🔗 Resources & Citation
- Layerwise Distillation & GRPO Pipeline Repository: github.com/martin-kbcc/BareTorch_Layerwise_Distill
- Core BareTorch Engine (PyTorch & MLX): github.com/martin-kbcc/baretorch
- Technical Whitepaper: Read Technical Report (PDF)
@article{kovacevic2026baretorch,
title={BareTorch: Challenging State-of-The-Art Sequence Mixing Topologies via Kernel-Free, Pure GEMM-Compliant Architectures},
author={Kovacevic Buvinic, Martin Ignacio},
journal={BareTorch Framework Laboratory Technical Report},
year={2026},
url={https://github.com/martin-kbcc/baretorch}
}