Instructions to use google/gemma-7b-it with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use google/gemma-7b-it with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="google/gemma-7b-it") messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("google/gemma-7b-it") model = AutoModelForCausalLM.from_pretrained("google/gemma-7b-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]:])) - llama-cpp-python
How to use google/gemma-7b-it with llama-cpp-python:
# !pip install llama-cpp-python from llama_cpp import Llama llm = Llama.from_pretrained( repo_id="google/gemma-7b-it", filename="gemma-7b-it.gguf", )
llm.create_chat_completion( messages = [ { "role": "user", "content": "What is the capital of France?" } ] ) - Inference
- Local Apps Settings
- llama.cpp
How to use google/gemma-7b-it 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 google/gemma-7b-it # Run inference directly in the terminal: llama cli -hf google/gemma-7b-it
Install from WinGet (Windows)
winget install llama.cpp # Start a local OpenAI-compatible server with a web UI: llama serve -hf google/gemma-7b-it # Run inference directly in the terminal: llama cli -hf google/gemma-7b-it
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 google/gemma-7b-it # Run inference directly in the terminal: ./llama-cli -hf google/gemma-7b-it
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 google/gemma-7b-it # Run inference directly in the terminal: ./build/bin/llama-cli -hf google/gemma-7b-it
Use Docker
docker model run hf.co/google/gemma-7b-it
- LM Studio
- Jan
- vLLM
How to use google/gemma-7b-it with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "google/gemma-7b-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/gemma-7b-it", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/google/gemma-7b-it
- SGLang
How to use google/gemma-7b-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/gemma-7b-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/gemma-7b-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/gemma-7b-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/gemma-7b-it", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Ollama
How to use google/gemma-7b-it with Ollama:
ollama run hf.co/google/gemma-7b-it
- Unsloth Studio
How to use google/gemma-7b-it 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 google/gemma-7b-it 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 google/gemma-7b-it to start chatting
Using HuggingFace Spaces for Unsloth
# No setup required # Open https://huggingface.co/spaces/unsloth/studio in your browser # Search for google/gemma-7b-it to start chatting
- Atomic Chat new
- Docker Model Runner
How to use google/gemma-7b-it with Docker Model Runner:
docker model run hf.co/google/gemma-7b-it
- Lemonade
How to use google/gemma-7b-it with Lemonade:
Pull the model
# Download Lemonade from https://lemonade-server.ai/ lemonade pull google/gemma-7b-it
Run and chat with the model
lemonade run user.gemma-7b-it-{{QUANT_TAG}}List all available models
lemonade list
Access to the gated repo & gemma-7b-it model from hugging face
I want to access the model so that, I can complete my project which is translating the text from English to various otherlanguages.
This model is linked to a GitHub repository, as per below link, I am cloning this repository in my local machine VS code. GitHub repo link: https://github.com/doctranslate-io/viet-translation-llm.
It gives me error as below:
OSError: You are trying to access a gated repo.
Make sure to have access to it at https://huggingface.co/google/gemma-7b-it.
401 Client Error. (Request ID: Root=1-67057062-38b576a8416d6a5720107b86;9d47d074-89e2-45ba-86a9-809d9cd8250e)
Cannot access gated repo for url https://huggingface.co/google/gemma-7b-it/resolve/main/config.json.
Access to model google/gemma-7b-it is restricted. You must have access to it and be authenticated to access it. Please log in.
P.S. Can someone help me point in right direction whom I should request for this access.
Hi @hk199
You're requesting access to a gated Gemma model. Here's how to authenticate from your server-side/local-machine environment:
Important: Accessing gated models directly from client-side environments (like web browsers) is not supported due to security risks.
Here's how to authenticate on your server/machine:
Step 1: Generate a Hugging Face User Access Token
Go to your Hugging Face settings: https://huggingface.co/settings/tokens
Click "New token".
Give your token a descriptive name (e.g., "HF_TOKEN").
We recommend keeping the default "Read" access.
Click "Generate a token" and copy the token to your clipboard.
Step 2: Set Up Authentication in Your Server-Side/local-machine Code
You'll need to set the HF_TOKEN environment variable within your server-side environment. How you do this depends on your specific setup, but here's a general example:
from transformers import AutoTokenizer, AutoModelForCausalLM
import torch
import os
# Set the access token as an environment variable
os.environ["HF_TOKEN"] = "YOUR_TOKEN_HERE"
tokenizer = AutoTokenizer.from_pretrained("google/gemma-7b-it")
model = AutoModelForCausalLM.from_pretrained(
"google/gemma-7b-it",
torch_dtype=torch.bfloat16,
use_auth_token=True
)
input_text = "Write me a poem about Machine Learning."
input_ids = tokenizer(input_text, return_tensors="pt")
outputs = model.generate(**input_ids)
print(tokenizer.decode(outputs[0]))
If you encounter any further issues or have specific questions about your local machine-side setup, feel free to ask!
