Gemma-4-E2B-Polyglot-Reasoner (Standalone Merged Model)

A high-density 2026 reasoning and systems-programming SLM, fine-tuned on Google's Gemma 4:E2B architecture using Unsloth Studio.


🎯 Model Overview

Gemma-4-E2B-Polyglot-Reasoner is a specialized, fully merged 16-bit standalone model built for deep mathematical deduction and modern high-performance systems engineering.

By pruning low-utility natural language overhead and enforcing a strict Complete-Cycle Reasoning Constraint, this model achieves closed-loop deductive reasoning without getting trapped in mid-thought monologue loops.

  • Base Architecture: Google Gemma 4:E2B (35 transformer blocks, 128k native context window, 20 shared KV layers).
  • Target Parameter Footprint: 5.14 Billion total parameters (~2.3B active text parameters).
  • Precision: 16-bit bfloat16 merged standalone weights (model.safetensors).
  • Hardware Requirement: Runs in ~5.8 GB VRAM (single RTX 4070 Ti, RTX 4080, RTX 4090, or Apple Silicon Mac).

🔬 Training Curriculum: What Was Trained

The model underwent a two-phase specialized fine-tuning curriculum on 4,600 verified complete-cycle reasoning pairs:

                          ┌────────────────────────┐
                          │   Gemma 4:E2B Base     │
                          └───────────┬────────────┘
                                      │
                 ┌────────────────────┴────────────────────┐
                 ▼                                         ▼
   ┌───────────────────────────┐             ┌───────────────────────────┐
   │  Formal Reasoning & Math  │             │   Tri-Language Systems    │
   ├───────────────────────────┤             ├───────────────────────────┤
   │ • Number Theory & Proofs  │             │ • C++20 Concurrency/Atomics│
   │ • Diophantine Equations   │             │ • Python 3.12+ Algorithmic│
   │ • Combinatorics & Bounds  │             │ • Java 21 Structured Tasks│
   └───────────────────────────┘             └───────────────────────────┘
  1. Phase 1: Mathematical Proof Deduction (Bespoke-Stratos-17k & OpenThoughts-114k)
    • Diophantine modular arithmetic, geometric invariants, graph bounds, and inductive number theory proofs.
  2. Phase 2: Tri-Language Systems Specialization (Magicoder-OSS-Instruct-75K)
    • High-throughput concurrency, modern memory models, and zero-overhead abstractions.
  3. Response-Only Loss Masking:
    • User turn prompts were masked (loss = 0). Gradients were computed exclusively on internal <thought> ... </thought> steps and the resulting code/proofs.
    • Training loss converged from 0.90 down to 0.5578.

⚡ Core Capabilities

1. Modern C++20 / C++23 Systems Programming

  • Lock-Free Concurrency: Single-Producer Single-Consumer (SPSC) and Multi-Producer Multi-Consumer (MPMC) ring buffers.
  • Memory Models: Precise application of std::memory_order_acquire, std::memory_order_release, std::memory_order_relaxed, and atomic fences.
  • Hardware-Aware Layouts: Cacheline alignment (std::hardware_destructive_interference_size, alignas(64)), custom arena allocators, and SIMD intrinsics (<immintrin.h>).
  • Metaprogramming: C++20 Concepts, requires clauses, constexpr/consteval evaluation, and std::span.

2. Python 3.12+ High-Performance Compute

  • GPU Kernel Dispatch: Writing custom Triton kernels (fused attention, RMSNorm, matrix multiplication).
  • Low-Latency IPC: Zero-copy shared memory (multiprocessing.shared_memory), memoryviews, and PyBind11 / CFFI native extensions.
  • Internals & Algorithms: Abstract Syntax Tree (AST) transformations, bytecode optimization (dis), and async event loops.

3. Java 21+ Enterprise Concurrency

  • Project Loom & Virtual Threads: StructuredTaskScope, ScopedValue, and massive-scale asynchronous task fan-out.
  • Project Panama (Foreign Function & Memory API): Direct off-heap MemorySegment manipulation and zero-overhead native C interoperability (replacing legacy JNI).
  • JVM Hardware Acceleration: Java Vector API for SIMD data parallelism and lock-free VarHandle operations.

✂️ What Was Optimized vs. What Was Pruned

🚀 What Was Optimized:

  1. 20 Shared Key-Value Layers (num_kv_shared_layers = 20):
    • Uses Unsloth Zoo dynamic cache proxy (_Gemma4KVSharedSafeProxy) to eliminate cache slice errors and maximize memory bandwidth.
  2. Interleaved Hybrid Attention:
    • Alternates between 512-token sliding window attention and global full attention.
  3. Tied Vocabulary Embeddings:
    • Tied representations across the 262,144 vocabulary with proportional RoPE scaling ($\theta = 1,000,000$, factor 0.25).
  4. Complete-Cycle Constraint ($30 \le \text{thought} \le 3500\text{ chars} \land \text{solution} \ge 40\text{ chars}$):
    • Eliminates infinite internal monologue loops by forcing every thought block to close and emit a verifiable solution.

✂️ What Was Removed / Suppressed:

  • Low-Resource / Obscure Dialects: Parameter weights for dozens of rare, non-technical natural languages were pruned from active routing to maximize coding density.
  • Mid-Thought Truncation Artifacts: Eliminated malformed data samples that lacked closing tags or boxed solutions.
  • Conversational Preamble Bloat: Suppressed conversational filler ("Sure, I can help you with that!") in favor of direct technical output.

🌐 What Was Preserved:

  • Top 5 Global Languages: Deep technical fluency is retained in English, Russian (Русский), Japanese (日本語), Chinese (中文), and Spanish (Español).
  • Native Multimodal Channels: Reserved token hooks for vision (<image>), speech (<audio>), and video (<video>) remain intact in the model architecture.

💻 How to Use This Model Standalone

1. In Ollama

# Deliberation mode (full <thought> stream):
ollama run polyglot-reasoner

# Direct code mode (instant code output):
ollama run polyglot-direct

2. In Python (transformers)

import torch
from transformers import AutoModelForCausalLM, AutoTokenizer

model_path = "/home/ubuntu/Downloads/unsloth/gemma4_e2b_reasoner_merged"

tokenizer = AutoTokenizer.from_pretrained(model_path)
model = AutoModelForCausalLM.from_pretrained(
    model_path,
    torch_dtype=torch.bfloat16,
    device_map="cuda"
)

prompt = "<start_of_turn>user\nWrite a lock-free SPSC ring buffer in C++20.<end_of_turn>\n<start_of_turn>model\n"
inputs = tokenizer(prompt, return_tensors="pt").to("cuda")

with torch.no_grad():
    outputs = model.generate(**inputs, max_new_tokens=512)

print(tokenizer.decode(outputs[0][inputs.input_ids.shape[1]:]))

3. In vLLM (OpenAI-Compatible Local Server)

vllm serve /home/ubuntu/Downloads/unsloth/gemma4_e2b_reasoner_merged --port 8000

📜 Citation & Attribution

Downloads last month
425
Safetensors
Model size
5B params
Tensor type
BF16
·
Inference Providers NEW
This model isn't deployed by any Inference Provider. 🙋 Ask for provider support

Model tree for icysunny/gemma4_e2b_reasoner_merged

Finetuned
(346)
this model

Space using icysunny/gemma4_e2b_reasoner_merged 1