Instructions to use shibatch/tinygemma3-2m with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use shibatch/tinygemma3-2m with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="shibatch/tinygemma3-2m")# Load model directly from transformers import AutoModel model = AutoModel.from_pretrained("shibatch/tinygemma3-2m", device_map="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- llama.cpp
How to use shibatch/tinygemma3-2m 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 shibatch/tinygemma3-2m:Q4_K_M # Run inference directly in the terminal: llama cli -hf shibatch/tinygemma3-2m:Q4_K_M
Install from WinGet (Windows)
winget install llama.cpp # Start a local OpenAI-compatible server with a web UI: llama serve -hf shibatch/tinygemma3-2m:Q4_K_M # Run inference directly in the terminal: llama cli -hf shibatch/tinygemma3-2m:Q4_K_M
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 shibatch/tinygemma3-2m:Q4_K_M # Run inference directly in the terminal: ./llama-cli -hf shibatch/tinygemma3-2m:Q4_K_M
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 shibatch/tinygemma3-2m:Q4_K_M # Run inference directly in the terminal: ./build/bin/llama-cli -hf shibatch/tinygemma3-2m:Q4_K_M
Use Docker
docker model run hf.co/shibatch/tinygemma3-2m:Q4_K_M
- LM Studio
- Jan
- vLLM
How to use shibatch/tinygemma3-2m with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "shibatch/tinygemma3-2m" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "shibatch/tinygemma3-2m", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/shibatch/tinygemma3-2m:Q4_K_M
- SGLang
How to use shibatch/tinygemma3-2m 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 "shibatch/tinygemma3-2m" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "shibatch/tinygemma3-2m", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'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 "shibatch/tinygemma3-2m" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "shibatch/tinygemma3-2m", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Ollama
How to use shibatch/tinygemma3-2m with Ollama:
ollama run hf.co/shibatch/tinygemma3-2m:Q4_K_M
- Unsloth Studio
How to use shibatch/tinygemma3-2m 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 shibatch/tinygemma3-2m 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 shibatch/tinygemma3-2m to start chatting
Using HuggingFace Spaces for Unsloth
# No setup required # Open https://huggingface.co/spaces/unsloth/studio in your browser # Search for shibatch/tinygemma3-2m to start chatting
- Docker Model Runner
How to use shibatch/tinygemma3-2m with Docker Model Runner:
docker model run hf.co/shibatch/tinygemma3-2m:Q4_K_M
- Lemonade
How to use shibatch/tinygemma3-2m with Lemonade:
Pull the model
# Download Lemonade from https://lemonade-server.ai/ lemonade pull shibatch/tinygemma3-2m:Q4_K_M
Run and chat with the model
lemonade run user.tinygemma3-2m-Q4_K_M
List all available models
lemonade list
- Atomic Chat
TinyStories Gemma3 2M (HF + Q4_K_M GGUF)
This repository contains a tiny Gemma 3 text-only model trained with official Hugging Face Transformers classes, together with a llama.cpp-compatible Q4_K_M GGUF conversion.
The model has 1,560,064 parameters (the 2m name is an approximate size
label). It is intended for inference-engine validation and small-model
experiments, not for production language quality.
The Hugging Face artifact was downloaded from
shibatch/tinygemma3-2m at
revision 7aab2f4e525707e046799eb5674f344dc74853d6.
Repository contents
hf/: original Hugging Face model and tokenizergguf/tinygemma3-2m-Q4_K_M.gguf: ready-to-run Q4_K_M GGUFconvert_to_gguf.py: reproducible HF -> F16 -> Q4_K_M conversion wrapperconversion_metadata.json: source revisions, quantization details, and validation resultreference/: original deterministic Hugging Face reference tensorsgemma3_text_config_dump.json: normalized configuration dumpsafetensors_keys.json: source tensor names and shapesartifact_metadata.json: original training metadataSHA256SUMS: checksums for the distributed binary artifacts
GGUF quick start
Install a recent llama.cpp build that supports Gemma 3. On Debian systems with the llama.cpp tools package installed, run:
llama-completion \
-m gguf/tinygemma3-2m-Q4_K_M.gguf \
-p "Once upon" \
-n 100 \
--temp 0.8 \
--top-p 0.95 \
--seed 1234
The GGUF was load- and generation-tested with Debian llama.cpp build 8681. For a deterministic smoke test:
llama-completion \
-m gguf/tinygemma3-2m-Q4_K_M.gguf \
-p "Once upon" \
-n 40 \
--temp 0 \
--seed 1234 \
--no-display-prompt
One validated completion was:
a time, there was a little girl named Lily. She loved to play with her toys
and her favorite thing to do was to go to the park. One day, Lily's
Q4_K_M details
The distributed GGUF reports general.file_type = 15 (Q4_K_M) and contains
80 tensors. Because this deliberately tiny architecture has a hidden width of
128 while K-quants use 256-value blocks, llama.cpp applies its normal Q4_K_M
fallback rules to tensors that cannot use Q4_K directly:
| Tensor type | Count |
|---|---|
| F32 | 37 |
| Q5_0 | 34 |
| Q4_K | 4 |
| Q8_0 | 3 |
| Q6_K | 2 |
This mixed tensor layout is the expected llama.cpp representation of the Q4_K_M preset for this model shape. The file is about 1.1 MB, compared with about 3.1 MB for the intermediate F16 GGUF.
Reproduce the GGUF
Requirements:
- a recent llama.cpp source checkout containing
convert_hf_to_gguf.py llama-quantizeonPATH, or its path passed explicitly- the Python packages required by llama.cpp's converter
Run from this repository:
python convert_to_gguf.py \
--llama-cpp /path/to/llama.cpp \
--quantizer /path/to/llama-quantize
The wrapper handles two properties of this validation checkpoint that generic conversion currently does not infer correctly:
- The custom tokenizer is a GPT-2-style ByteLevel BPE whose probe hash is not in llama.cpp's generated pre-tokenizer table.
- The tokenizer has 1,003 entries, but the model intentionally pads its embedding and logits vocabulary to 1,024 rows. Those rows must be retained for Gemma 3 runtime shape checks and for compatibility with the reference logits.
The script validates the tokenizer structure before applying the tokenizer
override. It creates the F16 intermediate inside gguf/ and removes it after
Q4_K_M quantization, including when quantization fails.
Hugging Face usage
from pathlib import Path
import torch
from transformers import Gemma3ForCausalLM, PreTrainedTokenizerFast
model_dir = Path("hf")
tokenizer = PreTrainedTokenizerFast.from_pretrained(model_dir)
model = Gemma3ForCausalLM.from_pretrained(
model_dir,
dtype=torch.float32,
).eval()
prompt = "Once upon"
input_ids = torch.tensor(
[[tokenizer.bos_token_id] + tokenizer.encode(prompt, add_special_tokens=False)]
)
with torch.no_grad():
output = model.generate(
input_ids,
max_new_tokens=100,
do_sample=False,
pad_token_id=tokenizer.pad_token_id,
eos_token_id=tokenizer.eos_token_id,
)
print(tokenizer.decode(output[0], skip_special_tokens=True))
The same example is available as example_generate.py.
Official classes used
Gemma3TextConfigGemma3ForCausalLMTrainer
No custom Gemma 3 modeling code is used by the original HF artifact.
Architecture
model_type: gemma3_text
architecture: Gemma3ForCausalLM
parameter_count: 1,560,064
vocab_size: 1,024
tokenizer_entries: 1,003
hidden_size: 128
intermediate_size: 512
num_hidden_layers: 6
num_attention_heads: 4
num_key_value_heads: 1
head_dim: 32
max_position_embeddings: 256
sliding_window: 32
layer_types:
- sliding_attention
- sliding_attention
- sliding_attention
- sliding_attention
- sliding_attention
- full_attention
tie_word_embeddings: true
The model exercises local/global attention, sliding-window attention, GQA,
per-head q_norm / k_norm, Gemma 3's four-norm decoder structure, a gated
MLP, and a tied output head.
Limitations
This is a synthetic tiny checkpoint. It is not an official Google model and does not contain weights from an original Gemma checkpoint. It is not intended for instruction following, chat, factual recall, safety-critical use, or production deployment. Quantized output may differ from the float32 Hugging Face checkpoint.
- Downloads last month
- -
4-bit
docker model run hf.co/shibatch/tinygemma3-2m:Q4_K_M