Text Generation
Transformers
Safetensors
GGUF
English
gemma3
q4-k-m
tinygemma
tinystories
validation
test-suite
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 Desktop
- 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
Upload README.md with huggingface_hub
Browse files
README.md
CHANGED
|
@@ -66,16 +66,43 @@ No custom Gemma 3 modeling code is used.
|
|
| 66 |
import torch
|
| 67 |
from transformers import Gemma3ForCausalLM, PreTrainedTokenizerFast
|
| 68 |
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 81 |
```
|
|
|
|
| 66 |
import torch
|
| 67 |
from transformers import Gemma3ForCausalLM, PreTrainedTokenizerFast
|
| 68 |
|
| 69 |
+
def main():
|
| 70 |
+
repo_id = "shibatch/tinygemma3-2m"
|
| 71 |
+
|
| 72 |
+
print("Loading tokenizer...")
|
| 73 |
+
tokenizer = PreTrainedTokenizerFast.from_pretrained(repo_id, subfolder="hf")
|
| 74 |
+
|
| 75 |
+
print("Loading Gemma3 model weights...")
|
| 76 |
+
device = "cuda" if torch.cuda.is_available() else "cpu"
|
| 77 |
+
|
| 78 |
+
model = Gemma3ForCausalLM.from_pretrained(
|
| 79 |
+
repo_id,
|
| 80 |
+
subfolder="hf",
|
| 81 |
+
torch_dtype=torch.bfloat16 if device == "cuda" else torch.float32,
|
| 82 |
+
).to(device)
|
| 83 |
+
model.eval()
|
| 84 |
+
|
| 85 |
+
prompt = "Once upon"
|
| 86 |
+
print(f"\nInput prompt: {prompt}")
|
| 87 |
+
|
| 88 |
+
input_ids = tokenizer.encode(prompt, add_special_tokens=False)
|
| 89 |
+
input_ids = [tokenizer.bos_token_id] + input_ids
|
| 90 |
+
input_ids = torch.tensor([input_ids], dtype=torch.long, device=device)
|
| 91 |
+
|
| 92 |
+
with torch.no_grad():
|
| 93 |
+
outputs = model.generate(
|
| 94 |
+
input_ids,
|
| 95 |
+
max_new_tokens=100,
|
| 96 |
+
do_sample=False,
|
| 97 |
+
repetition_penalty=1.0,
|
| 98 |
+
top_p=1.0,
|
| 99 |
+
pad_token_id=tokenizer.pad_token_id or tokenizer.bos_token_id,
|
| 100 |
+
eos_token_id=tokenizer.eos_token_id,
|
| 101 |
+
)
|
| 102 |
+
|
| 103 |
+
generated_text = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
| 104 |
+
print(f"Generated output: {generated_text}")
|
| 105 |
+
|
| 106 |
+
if __name__ == "__main__":
|
| 107 |
+
main()
|
| 108 |
```
|