Instructions to use icysunny/gemma4_e2b_reasoner_merged with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use icysunny/gemma4_e2b_reasoner_merged with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="icysunny/gemma4_e2b_reasoner_merged") messages = [ { "role": "user", "content": [ {"type": "image", "url": "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/p-blog/candy.JPG"}, {"type": "text", "text": "What animal is on the candy?"} ] }, ] pipe(text=messages)# Load model directly from transformers import AutoProcessor, AutoModelForMultimodalLM processor = AutoProcessor.from_pretrained("icysunny/gemma4_e2b_reasoner_merged") model = AutoModelForMultimodalLM.from_pretrained("icysunny/gemma4_e2b_reasoner_merged", device_map="auto") messages = [ { "role": "user", "content": [ {"type": "image", "url": "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/p-blog/candy.JPG"}, {"type": "text", "text": "What animal is on the candy?"} ] }, ] inputs = processor.apply_chat_template( messages, add_generation_prompt=True, tokenize=True, return_dict=True, return_tensors="pt", ).to(model.device) outputs = model.generate(**inputs, max_new_tokens=40) print(processor.decode(outputs[0][inputs["input_ids"].shape[-1]:])) - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use icysunny/gemma4_e2b_reasoner_merged with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "icysunny/gemma4_e2b_reasoner_merged" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "icysunny/gemma4_e2b_reasoner_merged", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/icysunny/gemma4_e2b_reasoner_merged
- SGLang
How to use icysunny/gemma4_e2b_reasoner_merged with SGLang:
Install from pip and serve model
# Install SGLang from pip: pip install sglang # Start the SGLang server: python3 -m sglang.launch_server \ --model-path "icysunny/gemma4_e2b_reasoner_merged" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "icysunny/gemma4_e2b_reasoner_merged", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker images
docker run --gpus all \ --shm-size 32g \ -p 30000:30000 \ -v ~/.cache/huggingface:/root/.cache/huggingface \ --env "HF_TOKEN=<secret>" \ --ipc=host \ lmsysorg/sglang:latest \ python3 -m sglang.launch_server \ --model-path "icysunny/gemma4_e2b_reasoner_merged" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "icysunny/gemma4_e2b_reasoner_merged", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Unsloth Desktop
- Docker Model Runner
How to use icysunny/gemma4_e2b_reasoner_merged with Docker Model Runner:
docker model run hf.co/icysunny/gemma4_e2b_reasoner_merged
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│
└───────────────────────────┘ └───────────────────────────┘
- Phase 1: Mathematical Proof Deduction (
Bespoke-Stratos-17k&OpenThoughts-114k)- Diophantine modular arithmetic, geometric invariants, graph bounds, and inductive number theory proofs.
- Phase 2: Tri-Language Systems Specialization (
Magicoder-OSS-Instruct-75K)- High-throughput concurrency, modern memory models, and zero-overhead abstractions.
- 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.90down to0.5578.
- User turn prompts were masked (
⚡ 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,
requiresclauses,constexpr/constevalevaluation, andstd::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
MemorySegmentmanipulation and zero-overhead native C interoperability (replacing legacy JNI). - JVM Hardware Acceleration: Java Vector API for SIMD data parallelism and lock-free
VarHandleoperations.
✂️ What Was Optimized vs. What Was Pruned
🚀 What Was Optimized:
- 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.
- Uses Unsloth Zoo dynamic cache proxy (
- Interleaved Hybrid Attention:
- Alternates between 512-token sliding window attention and global full attention.
- Tied Vocabulary Embeddings:
- Tied representations across the 262,144 vocabulary with proportional RoPE scaling ($\theta = 1,000,000$, factor 0.25).
- 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
- Fine-tuned with Unsloth and Unsloth Zoo.
- Base architecture: Google Gemma 4.
- Base weights subject to the Google Gemma Terms of Use.
- Downloads last month
- 425