Instructions to use google/datagemma-rig-27b-it with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use google/datagemma-rig-27b-it with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="google/datagemma-rig-27b-it") messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("google/datagemma-rig-27b-it") model = AutoModelForCausalLM.from_pretrained("google/datagemma-rig-27b-it") 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 google/datagemma-rig-27b-it with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "google/datagemma-rig-27b-it" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "google/datagemma-rig-27b-it", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/google/datagemma-rig-27b-it
- SGLang
How to use google/datagemma-rig-27b-it 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 "google/datagemma-rig-27b-it" \ --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": "google/datagemma-rig-27b-it", "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 "google/datagemma-rig-27b-it" \ --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": "google/datagemma-rig-27b-it", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use google/datagemma-rig-27b-it with Docker Model Runner:
docker model run hf.co/google/datagemma-rig-27b-it
Why the example prompt doesn't include prompt format?
From the example here:
from transformers import AutoTokenizer, AutoModelForCausalLM
import torch
model_id = 'google/datagemma-rig-27b-it'
tokenizer = AutoTokenizer.from_pretrained(model_id)
model = AutoModelForCausalLM.from_pretrained(
model_id,
device_map='auto',
torch_dtype=torch.bfloat16,
)
input_text = 'What are some interesting trends in Sunnyvale spanning gender, age, race, immigration, health conditions, economic conditions, crime and education?'
inputs = tokenizer(input_text, return_tensors='pt').to('cuda')
outputs = model.generate(**inputs, max_new_tokens=4096)
answer = tokenizer.batch_decode(outputs[:, inputs['input_ids'].shape[1]:], skip_special_tokens=True)[0].strip()
print(answer)
The input_text has no format. I thought it should be
input_text = '<bos><start_of_turn>user\nWhat are some interesting trends in Sunnyvale spanning gender, age, race, immigration, health conditions, economic conditions, crime and education?<end_of_turn>\n<start_of_turn>model\n'
So, what is the right input_text?
Hi @fahadh4ilyas ,
Without a Chat Template: This approach involves tokenizing the input text directly, without adding any context about roles or conversation structure. It’s simply a plain string without any explicit interaction framework.
With a Chat Template: This approach uses a chat template to assign roles and create a structured conversational context for the input. You can ensure the correct chat template is applied by using the tokenizer.apply_chat_template method.
Here’s an example that demonstrates the usage:
This ensures that the input is formatted according to the expected conversational structure when using models like instruction-tuned ones.
Thank you.
Will the response be different between input without chat template vs input with chat template? Which one is recommended to use?
Hi @fahadh4ilyas ,
Response is different. Go with chat template approach because it is more sophisticated and designed for conversations and tasks where roles and multi-turn dialogues are needed, while the standard tokenization is a basic approach suitable for one-off instructions. Could you please refer to this gist
Thank you.
