Text Generation
Transformers
Safetensors
gemma4_text
feature-extraction
gemma4
text-only
conversational
Instructions to use bRadu/gemma-4-E2B-it-textonly with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use bRadu/gemma-4-E2B-it-textonly with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="bRadu/gemma-4-E2B-it-textonly") messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# Load model directly from transformers import AutoTokenizer, AutoModel tokenizer = AutoTokenizer.from_pretrained("bRadu/gemma-4-E2B-it-textonly") model = AutoModel.from_pretrained("bRadu/gemma-4-E2B-it-textonly") 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
- vLLM
How to use bRadu/gemma-4-E2B-it-textonly with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "bRadu/gemma-4-E2B-it-textonly" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "bRadu/gemma-4-E2B-it-textonly", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/bRadu/gemma-4-E2B-it-textonly
- SGLang
How to use bRadu/gemma-4-E2B-it-textonly 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 "bRadu/gemma-4-E2B-it-textonly" \ --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": "bRadu/gemma-4-E2B-it-textonly", "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 "bRadu/gemma-4-E2B-it-textonly" \ --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": "bRadu/gemma-4-E2B-it-textonly", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use bRadu/gemma-4-E2B-it-textonly with Docker Model Runner:
docker model run hf.co/bRadu/gemma-4-E2B-it-textonly
Gemma 4 E2B-it (Text-Only)
Text-only version of google/gemma-4-E2B-it with the vision and audio encoders removed.
Why?
The original Gemma 4 E2B is a multimodal model (text + vision + audio). When fine-tuning for text-only tasks, the multimodal architecture causes:
- Higher training loss due to the multimodal overhead
- Requires
mm_token_type_idstensors even for text-only inputs - Batch size > 1 crashes during training
- Extra ~450M parameters (vision + audio encoders) that serve no purpose for text tasks
This model extracts just the language model (Gemma4ForCausalLM) and the text tokenizer, making it suitable for standard text-only SFT/DPO/KTO fine-tuning.
Usage
from transformers import AutoModelForCausalLM, AutoTokenizer
model = AutoModelForCausalLM.from_pretrained("bRadu/gemma-4-E2B-it-textonly", torch_dtype="auto", device_map="auto")
tokenizer = AutoTokenizer.from_pretrained("bRadu/gemma-4-E2B-it-textonly")
messages = [
{"role": "user", "content": "Hello!"}
]
inputs = tokenizer.apply_chat_template(messages, return_tensors="pt", add_generation_prompt=True, tokenize=True, return_dict=True).to(model.device)
outputs = model.generate(**inputs, max_new_tokens=128)
print(tokenizer.decode(outputs[0], skip_special_tokens=True))
- Downloads last month
- 166