Instructions to use thanglq150188/gemma-4-E2B-mini with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use thanglq150188/gemma-4-E2B-mini with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="thanglq150188/gemma-4-E2B-mini") messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("thanglq150188/gemma-4-E2B-mini") model = AutoModelForCausalLM.from_pretrained("thanglq150188/gemma-4-E2B-mini", device_map="auto") messages = [ {"role": "user", "content": "Who are you?"}, ] inputs = tokenizer.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(tokenizer.decode(outputs[0][inputs["input_ids"].shape[-1]:])) - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- llama.cpp
How to use thanglq150188/gemma-4-E2B-mini with llama.cpp:
Install (macOS, Linux)
curl -LsSf https://llama.app/install.sh | sh # Start a local OpenAI-compatible server with a web UI: llama serve -hf thanglq150188/gemma-4-E2B-mini:Q8_0 # Run inference directly in the terminal: llama cli -hf thanglq150188/gemma-4-E2B-mini:Q8_0
Install from WinGet (Windows)
winget install llama.cpp # Start a local OpenAI-compatible server with a web UI: llama serve -hf thanglq150188/gemma-4-E2B-mini:Q8_0 # Run inference directly in the terminal: llama cli -hf thanglq150188/gemma-4-E2B-mini:Q8_0
Use pre-built binary
# Download pre-built binary from: # https://github.com/ggerganov/llama.cpp/releases # Start a local OpenAI-compatible server with a web UI: ./llama-server -hf thanglq150188/gemma-4-E2B-mini:Q8_0 # Run inference directly in the terminal: ./llama-cli -hf thanglq150188/gemma-4-E2B-mini:Q8_0
Build from source code
git clone https://github.com/ggerganov/llama.cpp.git cd llama.cpp cmake -B build cmake --build build -j --target llama-server llama-cli # Start a local OpenAI-compatible server with a web UI: ./build/bin/llama-server -hf thanglq150188/gemma-4-E2B-mini:Q8_0 # Run inference directly in the terminal: ./build/bin/llama-cli -hf thanglq150188/gemma-4-E2B-mini:Q8_0
Use Docker
docker model run hf.co/thanglq150188/gemma-4-E2B-mini:Q8_0
- LM Studio
- Jan
- vLLM
How to use thanglq150188/gemma-4-E2B-mini with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "thanglq150188/gemma-4-E2B-mini" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "thanglq150188/gemma-4-E2B-mini", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/thanglq150188/gemma-4-E2B-mini:Q8_0
- SGLang
How to use thanglq150188/gemma-4-E2B-mini 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 "thanglq150188/gemma-4-E2B-mini" \ --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": "thanglq150188/gemma-4-E2B-mini", "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 "thanglq150188/gemma-4-E2B-mini" \ --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": "thanglq150188/gemma-4-E2B-mini", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Ollama
How to use thanglq150188/gemma-4-E2B-mini with Ollama:
ollama run hf.co/thanglq150188/gemma-4-E2B-mini:Q8_0
- Unsloth Studio
How to use thanglq150188/gemma-4-E2B-mini with Unsloth Studio:
Install Unsloth Studio (macOS, Linux, WSL)
curl -fsSL https://unsloth.ai/install.sh | sh # Run unsloth studio unsloth studio -H 0.0.0.0 -p 8888 # Then open http://localhost:8888 in your browser # Search for thanglq150188/gemma-4-E2B-mini to start chatting
Install Unsloth Studio (Windows)
irm https://unsloth.ai/install.ps1 | iex # Run unsloth studio unsloth studio -H 0.0.0.0 -p 8888 # Then open http://localhost:8888 in your browser # Search for thanglq150188/gemma-4-E2B-mini to start chatting
Using HuggingFace Spaces for Unsloth
# No setup required # Open https://huggingface.co/spaces/unsloth/studio in your browser # Search for thanglq150188/gemma-4-E2B-mini to start chatting
- Pi
How to use thanglq150188/gemma-4-E2B-mini with Pi:
Start the llama.cpp server
# Install llama.cpp: brew install llama.cpp # Start a local OpenAI-compatible server: llama serve -hf thanglq150188/gemma-4-E2B-mini:Q8_0
Configure the model in Pi
# Install Pi: npm install -g @mariozechner/pi-coding-agent # Add to ~/.pi/agent/models.json: { "providers": { "llama-cpp": { "baseUrl": "http://localhost:8080/v1", "api": "openai-completions", "apiKey": "none", "models": [ { "id": "thanglq150188/gemma-4-E2B-mini:Q8_0" } ] } } }Run Pi
# Start Pi in your project directory: pi
- Docker Model Runner
How to use thanglq150188/gemma-4-E2B-mini with Docker Model Runner:
docker model run hf.co/thanglq150188/gemma-4-E2B-mini:Q8_0
- Lemonade
How to use thanglq150188/gemma-4-E2B-mini with Lemonade:
Pull the model
# Download Lemonade from https://lemonade-server.ai/ lemonade pull thanglq150188/gemma-4-E2B-mini:Q8_0
Run and chat with the model
lemonade run user.gemma-4-E2B-mini-Q8_0
List all available models
lemonade list
- Hermes Agent
How to use thanglq150188/gemma-4-E2B-mini with Hermes Agent:
Start the llama.cpp server
# Install llama.cpp: brew install llama.cpp # Start a local OpenAI-compatible server: llama serve -hf thanglq150188/gemma-4-E2B-mini:Q8_0
Configure Hermes
# Install Hermes: curl -fsSL https://hermes-agent.nousresearch.com/install.sh | bash hermes setup # Point Hermes at the local server: hermes config set model.provider custom hermes config set model.base_url http://127.0.0.1:8080/v1 hermes config set model.default thanglq150188/gemma-4-E2B-mini:Q8_0
Run Hermes
hermes
- Atomic Chat
- OpenClaw
How to use thanglq150188/gemma-4-E2B-mini with OpenClaw:
Start the llama.cpp server
# Install llama.cpp: brew install llama.cpp # Start a local OpenAI-compatible server: llama serve -hf thanglq150188/gemma-4-E2B-mini:Q8_0
Configure OpenClaw
# Install OpenClaw: npm install -g openclaw@latest # Register the local server and set it as the default model: openclaw onboard --non-interactive --mode local \ --auth-choice custom-api-key \ --custom-base-url http://127.0.0.1:8080/v1 \ --custom-model-id "thanglq150188/gemma-4-E2B-mini:Q8_0" \ --custom-provider-id llama-cpp \ --custom-compatibility openai \ --custom-text-input \ --accept-risk \ --skip-health
Run OpenClaw
openclaw agent --local --agent main --message "Hello from Hugging Face"
Configuration Parsing Warning:In config.json: "num_experts" must be a number
Gemma 4 E2B Mini — text-only, vocabulary pruned to English + Vietnamese
A compact, vocabulary-pruned version of Gemma 4 E2B (text-only). The 262,144-token multilingual vocabulary is reduced to the 69,246 tokens used by English + Vietnamese, removing ~44% of the parameters with no measured quality loss on EN/VI. Built for efficient on-device finetuning and serving on a 12 GB GPU.
Built on Google's Gemma 4 (via
principled-intelligence/gemma-4-E2B-it-text-only, the text-only checkpoint). Use is governed by the Gemma Terms of Use and the Gemma Prohibited Use Policy — https://ai.google.dev/gemma/terms . "Gemma is provided under and subject to the Gemma Terms of Use." This derivative keeps the Gemma name and license as required.
What changed vs. the base
| Base (text-only) | This model (Mini) | |
|---|---|---|
| Vocab | 262,144 | 69,246 (EN+VI) |
| Params | 4.63 B | 2.60 B |
| bf16 weights | 9.26 GB | 5.21 GB |
| q8_0 GGUF | 4.6 GB | 2.6 GB |
| EN/VI accuracy (UIT-VSFC, 300) | 0.5567 | 0.5567 (Δ 0, 99.7% agreement) |
59% of the base is vocab-dependent (token embeddings + Per-Layer Embeddings); these are not quantized during QLoRA, so pruning them is the highest-leverage size/VRAM win on small GPUs. It also raises the max QLoRA training context on a 12 GB card from ~1024 to ~7168 tokens.
How it was made
- Keep-set = tokens used by an EN+VI corpus (VI+EN Wikipedia) + all 256 byte-fallback tokens + special tokens + every single EN/VI character token (69,246 total).
- The BPE tokenizer is pruned (merges filtered so every kept merge stays applicable; ids remapped contiguously); byte-fallback remains, so any character is still encodable.
embed_tokens,embed_tokens_per_layer(PLE), and the tiedlm_headare row-sliced to the keep-set. The original rows are kept verbatim, so EN/VI behaviour is unchanged — only the ability to emit other-language tokens is removed.
Usage (transformers)
from transformers import AutoModelForCausalLM, AutoTokenizer
import torch
ID = "thanglq150188/gemma-4-E2B-mini"
tok = AutoTokenizer.from_pretrained(ID)
m = AutoModelForCausalLM.from_pretrained(ID, dtype=torch.bfloat16, device_map="cuda")
msgs = [{"role": "user", "content": "Thủ đô của Việt Nam là thành phố nào?"}]
ids = tok.apply_chat_template(msgs, add_generation_prompt=True,
return_tensors="pt", return_dict=True).to("cuda")
print(tok.decode(m.generate(**ids, max_new_tokens=64)[0, ids["input_ids"].shape[1]:],
skip_special_tokens=True))
Chat format is Gemma 4's <|turn> / <turn|> (not Gemma 2/3's <start_of_turn>).
Usage (llama.cpp / llama-server)
# gemma4-envi-pruned-q8_0.gguf and gemma4_chat.jinja are included in this repo
llama-server -m gemma4-envi-pruned-q8_0.gguf -ngl 99 -fa on \
--parallel 8 --ctx-size 65536 --cont-batching \
--chat-template-file gemma4_chat.jinja
~260 tok/s aggregate at 10 concurrent requests, ~3.0 GB VRAM (8×8192 ctx) on an RTX 3060. The model stays resident (no idle unload).
vsfc-sentiment-lora/ — demo finetune (optional)
QLoRA adapters from finetuning this model on UIT-VSFC Vietnamese sentiment (4k
examples). Lifts accuracy 0.68 → 0.95 on the 300-example test set. Load with
peft.PeftModel.from_pretrained(base, "thanglq150188/gemma-4-E2B-mini", subfolder="vsfc-sentiment-lora").
Error analysis: 0 of 16 mistakes involved a pruned-away token — pruning is not the cause.
Limitations
- English + Vietnamese only by design. Other languages/scripts now fragment into byte-fallback tokens and are not supported (that is the point — the vocab was trimmed).
- Inherits the capabilities and limitations of the base Gemma 4 E2B model.
- Downloads last month
- 80