CoolFace
Modelpublic

icysunny/gemma4_e2b_reasoner_merged

sourceHugging Facegemmaupdated 19d agoView on Hugging Face
0likes460downloads
Model Card

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. 1.Phase 1: Mathematical Proof Deduction (`Bespoke-Stratos-17k` & `OpenThoughts-114k`)
  2. 2.Diophantine modular arithmetic, geometric invariants, graph bounds, and inductive number theory proofs.
  3. 3.Phase 2: Tri-Language Systems Specialization (`Magicoder-OSS-Instruct-75K`)
  4. 4.High-throughput concurrency, modern memory models, and zero-overhead abstractions.
  5. 5.Response-Only Loss Masking:
  6. 6.User turn prompts were masked (loss = 0). Gradients were computed exclusively on internal <thought> ... </thought> steps and the resulting code/proofs.
  7. 7.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. 1.20 Shared Key-Value Layers (`num_kv_shared_layers = 20`):
  2. 2.Uses Unsloth Zoo dynamic cache proxy (_Gemma4KVSharedSafeProxy) to eliminate cache slice errors and maximize memory bandwidth.
  3. 3.Interleaved Hybrid Attention:
  4. 4.Alternates between 512-token sliding window attention and global full attention.
  5. 5.Tied Vocabulary Embeddings:
  6. 6.Tied representations across the 262,144 vocabulary with proportional RoPE scaling ($\theta = 1,000,000$, factor 0.25).
  7. 7.Complete-Cycle Constraint ($30 \le \text{thought} \le 3500\text{ chars} \land \text{solution} \ge 40\text{ chars}$):
  8. 8.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

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

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

2. In Python (transformers)

python
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)

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

πŸ“œ Citation & Attribution