🐻🔥 Model Rampage
model-rampage/BareTorch-Qwen3.5-4B-Hybrid
Building Hardware-Portable, Pure-GEMM Sub-Quadratic LLM Architectures for the Edge & Cloud
🌟 Overview
model-rampage/BareTorch-Qwen3.5-4B-Hybrid is our flagship 4B-scale CS-LRAD (Chunked Selective Low-Rank Associative Delta) hybrid language model surgically distilled from Qwen/Qwen3.5-4B and up-distilled from Qwen/Qwen3.5-9B 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 (24 of 32 layers) with pure-PyTorch torch.compile-compatible low-rank (r=32, chunk_size=64) associative recurrent blocks while preserving 8 interleaved Full-Attention anchor layers, model-rampage/BareTorch-Qwen3.5-4B-Hybrid delivers:
- 102.6% Retention (+1.82%) over
Qwen/Qwen3.5-4Bon the 10-tasklm-evaluation-harnesssuite (73.01%vs.71.19%macro average, beating the native teacher across 7 of 10 benchmarks including86.78%on ARC-Easy,65.36%on ARC-Challenge,97.30%on SciQ,86.36%on BoolQ,78.56%on PIQA,44.00%on OpenBookQA, and75.45%on WinoGrande). - 113.5% Retention (+4.83%) over
Qwen/Qwen3.5-4Bon the 5-task<think>Generative Reasoning & Python Coding suite (40.63%vs.35.80%macro average, including79.60%on GSM8K,37.80%on MATH-500,35.37%Pass@1 on HumanEval (1.87x teacher), and35.20%Pass@1 on MBPP (1.63x teacher)). - Up to 1.35x faster prefill, 1.18x faster autoregressive decoding, 2.6x smaller short-context cache, and 1.67 GB lower 32K Peak VRAM (-13.0%) than native
Qwen3.5-4Bon an NVIDIA RTX 4090 (11.22 GBvs.12.89 GB)—with zero custom CUDA/Triton C++ dependencies (causal-conv1d/flanot required).
🏗️ Architecture Highlights
| Property | Value |
|---|---|
| Architecture Type | 3:1 Interleaved Hybrid (24 CS-LRAD Recurrent + 8 Full-Attention) |
| Active Parameters | 4045.7M (bf16, Static Weights VRAM: ~7.90 GB) |
Hidden Dimension (d_model) | 2560 (16 Query Heads, 4 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-4B |
| Stage 4B/4C Skew-KD Teacher | Qwen/Qwen3.5-9B (Top-64 Skew-KL + Skew-RKL + 2,100-Step 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-4B-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-4B) | BareTorch Hybrid (4B) | Delta (S - T) | Retention |
|---|---|---|---|---|---|
| ARC-Challenge | acc_norm | 54.01% | 65.36% | +11.35% | 121.0% |
| ARC-Easy | acc_norm | 75.59% | 86.78% | +11.20% | 114.8% |
| BoolQ | acc | 86.18% | 86.36% | +0.18% | 100.2% |
| HellaSwag | acc_norm | 73.11% | 71.36% | -1.75% | 97.6% |
| LAMBADA (OpenAI) | acc | 64.70% | 59.38% | -5.32% | 91.8% |
| MMLU (57 Subjects) | acc | 74.37% | 65.54% | -8.83% | 88.1% |
| MMLU - Humanities | acc | 65.99% | 57.70% | -8.29% | 87.4% |
| MMLU - Other | acc | 78.15% | 69.17% | -8.98% | 88.5% |
| MMLU - Social Sciences | acc | 83.78% | 76.41% | -7.38% | 91.2% |
| MMLU - STEM | acc | 73.96% | 63.05% | -10.91% | 85.2% |
| OpenBookQA | acc_norm | 40.60% | 44.00% | +3.40% | 108.4% |
| PIQA | acc_norm | 78.40% | 78.56% | +0.16% | 100.2% |
| SciQ | acc_norm | 95.50% | 97.30% | +1.80% | 101.9% |
| WinoGrande | acc | 69.46% | 75.45% | +6.00% | 108.6% |
| 10-Task Macro Average | mean_acc | 71.19% | 73.01% | +1.82% | 102.6% |
2. Generative Reasoning & Coding Suite (5-Task <think> & Unit-Test Suite)
| Generative Benchmark | Metric | Base Teacher (Qwen/Qwen3.5-4B) | BareTorch Hybrid (4B) | Delta (S - T) | Retention |
|---|---|---|---|---|---|
GSM8K (<think> CoT Math) | exact_match | 90.00% | 79.60% | -10.40% | 88.4% |
MATH-500 (<think> Boxed) | boxed_match | 47.40% | 37.80% | -9.60% | 79.7% |
| GPQA-Diamond (PhD STEM) | mc_think | 1.12% | 15.18% | +14.06% | 1360.0% |
| MBPP (Python Synthesis) | pass@1 | 21.60% | 35.20% | +13.60% | 163.0% |
| HumanEval (Python Synthesis) | pass@1 | 18.90% | 35.37% | +16.46% | 187.1% |
| 5-Task Generative Average | macro_avg | 35.80% | 40.63% | +4.83% | 113.5% |
3. Hardware Speed & Memory Footprint (BareTorch-Qwen3.5-4B-Hybrid vs. Native Qwen3.5-4B 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-4B-Hybrid (r=32, Compiled) | 39.8 ms | 12,877 tok/s | 37.2 tok/s | 25.5 MB | 7.67 GB | 1.35x Prefill, 1.15x Decode, 2.6x Smaller Cache |
| 512 | Qwen3.5-4B (Native) | 53.5 ms | 9,568 tok/s | 32.3 tok/s | 67.5 MB | 7.97 GB | Baseline |
| 1,024 | BareTorch-Qwen3.5-4B-Hybrid (r=32, Compiled) | 68.4 ms | 14,962 tok/s | 37.9 tok/s | 41.5 MB | 7.67 GB | 1.10x Prefill, 1.17x Decode, 2.0x Smaller Cache |
| 1,024 | Qwen3.5-4B (Native) | 75.4 ms | 13,585 tok/s | 32.5 tok/s | 83.5 MB | 8.05 GB | Baseline |
| 2,048 | BareTorch-Qwen3.5-4B-Hybrid (r=32, Compiled) | 132.5 ms | 15,461 tok/s | 36.9 tok/s | 73.5 MB | 7.78 GB | 1.11x Prefill, 1.18x Decode, 1.6x Smaller Cache |
| 2,048 | Qwen3.5-4B (Native) | 147.0 ms | 13,928 tok/s | 31.4 tok/s | 115.5 MB | 8.20 GB | Baseline |
| 4,096 | BareTorch-Qwen3.5-4B-Hybrid (r=32, Compiled) | 274.9 ms | 14,899 tok/s | 37.1 tok/s | 137.5 MB | 8.01 GB | 1.11x Prefill, 1.13x Decode, 1.3x Smaller Cache |
| 4,096 | Qwen3.5-4B (Native) | 306.0 ms | 13,385 tok/s | 32.7 tok/s | 179.5 MB | 8.52 GB | Baseline |
| 8,192 | BareTorch-Qwen3.5-4B-Hybrid (r=32, Compiled) | 579.8 ms | 14,128 tok/s | 37.3 tok/s | 265.5 MB | 8.47 GB | 1.13x Prefill, 1.17x Decode, 670 MB Less VRAM |
| 8,192 | Qwen3.5-4B (Native) | 655.3 ms | 12,502 tok/s | 31.8 tok/s | 307.5 MB | 9.14 GB | Baseline |
| 16,384 | BareTorch-Qwen3.5-4B-Hybrid (r=32, Compiled) | 1235.8 ms | 13,257 tok/s | 37.0 tok/s | 521.5 MB | 9.38 GB | 1.12x Prefill, 1.12x Decode, 1.01 GB Less VRAM |
| 16,384 | Qwen3.5-4B (Native) | 1389.9 ms | 11,788 tok/s | 32.9 tok/s | 563.5 MB | 10.39 GB | Baseline |
| 32,768 | BareTorch-Qwen3.5-4B-Hybrid (r=32, Compiled) | 2839.9 ms | 11,538 tok/s | 37.0 tok/s | 1033.5 MB | 11.22 GB | 1.08x Prefill, 1.12x Decode, 1.67 GB Less VRAM (-13.0%) |
| 32,768 | Qwen3.5-4B (Native) | 3071.2 ms | 10,669 tok/s | 33.0 tok/s | 1075.5 MB | 12.89 GB | Baseline |
🔗 Resources & Citation
- Interactive ZeroGPU Demo: huggingface.co/spaces/martin-kb-rampage/BareTorch-Qwen3.5-Playground
- 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}
}