Downloads · 30 days
0
Dhiaul/Gemma-4-E4B-GLM5.1-distill
Gemma-4-E4B-GLM5.1-distill is a text generation model from Dhiaul. Use it when you need the model to write or continue text. It is set up for peft. The card lists the license as gemma.
A full SFT fine-tune of google/gemma-4-E4B-it on the complete open-source GLM-5.1-1000000x dataset (~614k conversations), trained with LoRA + DDP across 6× A100-40GB GPUs.
Downloads · 30 days
0
Access
Public
Updated May 2, 2026
Parameters
8B
16 GB on disk
Likes
4
Public
Click a slice to open those files.
.safetensors16 GB · 100%
From the Hugging Face model README
A full SFT fine-tune of google/gemma-4-E4B-it on the complete open-source GLM-5.1-1000000x dataset (~614k conversations), trained with LoRA + DDP across 6× A100-40GB GPUs.
This is a merged model — no PEFT or adapter files needed. Load it directly like any standard HuggingFace model.
The model produces structured, step-by-step chain-of-thought reasoning in the GLM-5.1 style, covering multi-step mathematics, PhD-level science, and multilingual STEM problems.
The recommended way to run this model is via vLLM, which gives you an OpenAI-compatible API server with full 128k context support.
pip install vllm
vllm serve Dhiaul/Gemma-4-E4B-GLM5.1-distill \
--dtype bfloat16 \
--max-model-len 131072 \
--gpu-memory-utilization 0.92 \
--enable-chunked-prefill \
--max-num-batched-tokens 8192 \
--served-model-name gemma4-glm \
--host 0.0.0.0 \
--port 8000
GPU memory: A single A100-40GB or H100-80GB is enough. For concurrency beyond ~5 simultaneous 128k requests, add
--tensor-parallel-size 2and two GPUs.
curl http://localhost:8000/v1/chat/completions \
-H "Content-Type: application/json" \
-d '{
"model": "gemma4-glm",
"messages": [
{"role": "user", "content": "Prove that sqrt(2) is irrational, step by step."}
],
"max_tokens": 2048
}'
from openai import OpenAI
client = OpenAI(base_url="http://localhost:8000/v1", api_key="unused")
response = client.chat.completions.create(
model="gemma4-glm",
messages=[{
"role": "user",
"content": "Solve: A train travels 120 km at 60 km/h, then 80 km at 40 km/h. What is the average speed for the whole journey? Show all steps."
}],
max_tokens=1024,
temperature=1.0,
top_p=0.95,
)
print(response.choices[0].message.content)
from transformers import AutoModelForCausalLM, AutoTokenizer
import torch
model_id = "Dhiaul/Gemma-4-E4B-GLM5.1-distill"
tokenizer = AutoTokenizer.from_pretrained(model_id)
model = AutoModelForCausalLM.from_pretrained(
model_id,
torch_dtype=torch.bfloat16,
device_map="auto",
)
messages = [{"role": "user", "content": "If f(x) = 3x² - 2x + 1, find f'(x) and explain each step."}]
prompt = tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
with torch.no_grad():
outputs = model.generate(
**inputs,
max_new_tokens=1024,
do_sample=True,
temperature=1.0,
top_p=0.95,
)
response = outputs[0][inputs.input_ids.shape[1]:]
print(tokenizer.decode(response, skip_special_tokens=True))
| Scenario | Command flags |
|---|---|
| Single GPU, standard use | (defaults above) |
| Two GPUs, higher concurrency | add --tensor-parallel-size 2 |
| Lower VRAM (reduce KV cache) | change --max-model-len 65536 |
| Higher throughput batching | increase --max-num-batched-tokens 16384 |
| Disable chunked prefill (older vLLM) | remove --enable-chunked-prefill |
Minimum requirements for vLLM:
--enable-chunked-prefill is required for long-context (128k) prompts — without it, large prefills OOM| Attribute | Value |
|---|---|
| Base model | google/gemma-4-E4B-it |
| Fine-tuning method | LoRA (merged — no PEFT needed at inference) |
| Training dataset | GLM-5.1-1000000x (open-source, Apache 2.0) |
| Dataset subsets | main + PHD-Science + Multilingual-STEM (all 3) |
| Training samples | 614,645 train / 32,350 validation |
| Training hardware | 6× NVIDIA A100-40GB PCIe |
| Training epochs | 1 |
| Total tokens seen | ~1.14 billion |
| Wall-clock | ~48.6 hours |
| Final train loss | 0.7189 |
| Final eval loss | 0.6879 |
| Final eval token accuracy | 79.5% |
GLM-5.1-1000000x is an open-source (Apache 2.0) dataset of distilled long-form reasoning traces in the GLM style. We used all three available subsets:
| Subset | Rows (train) | Domain |
|---|---|---|
main | ~438k | General reasoning, math, coding |
PHD-Science | ~99k | PhD-level science questions |
Multilingual-STEM | ~77k | STEM in multiple languages |
Preprocessing applied:
tokenizer.apply_chat_template)LoraConfig(
r=16,
lora_alpha=32,
lora_dropout=0.05,
target_modules=["q_proj", "k_proj", "v_proj", "o_proj",
"gate_proj", "up_proj", "down_proj"],
# Gemma 4 vision/audio towers use Gemma4ClippableLinear — not LoRA-injectable
exclude_modules=r".*(?:vision_tower|audio_tower|embed_vision|embed_audio).*",
bias="none",
task_type="CAUSAL_LM",
)
SFTConfig(
num_train_epochs=1,
per_device_train_batch_size=1,
per_device_eval_batch_size=1,
gradient_accumulation_steps=8, # effective batch = 1 × 8 × 6 GPUs = 48
learning_rate=2e-4,
lr_scheduler_type="cosine",
warmup_ratio=0.03,
max_length=2048,
bf16=True,
gradient_checkpointing=True,
optim="adamw_torch_fused",
ddp_find_unused_parameters=False,
)
Framework versions: TRL 1.3.0 · PEFT 0.19.1 · Transformers 5.6.2 · Accelerate 1.13.0 · PyTorch 2.11.0
Full code and step-by-step instructions: github.com/Dhiaul/Gemma-4-E4B-GLM5.1-distill
Key non-obvious detail for multi-GPU reproduction: pre-tokenize your parquet files before training (scripts/tokenize_parquet.py). TRL's dataset preparation runs inside a main_process_first() barrier — rank 0 tokenizes all 614k rows while other ranks wait at an NCCL barrier. Without pre-tokenization this takes ~30 minutes and hits PyTorch's 1800s NCCL timeout, killing the job silently.
This fine-tune inherits the Gemma license from the base model. The training dataset is Apache 2.0.