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?" } ] ) - Notebooks
- Google Colab
- Kaggle
- 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
Alignment Issues
Gemma chat versions score far lower on the leaderboard than their foundational models, which isn't surprising since they perform horribly in my testing. Far worse than Mistral 7b.
The primary reason is clear. The alignment is GROSSLY overdone. Not everyone using an LLM is a 3 year old child. Adults use LLMs to, and ask basic questions about a wide variety of things that aren't the least bit illegal or amoral. By training your LLM with 1000s of 'As an AI model I can't answer that' responses you not only cripple the LLM in millions of legitimate use cases, the excessive alignment misfires and bleeds into completely unrelated areas, making the LLM perform much worse in every context.
Even your foundational models are stripped of basic knowledge that isn't remotely illegal or amoral, and which most adults already know, plus can be found in any basic encyclopedia. What's the point of that? Why would anyone turn to your AI models for reference when countless perfectly legal and moral bits of information is stripped from it? Info that can be found in Wikipedia or the first Google result. Even Gemini Pro/Ultra have astonishing blind spots, making them very unreliable sources of help and information despite their otherwise impressive abilities that are sometimes superior to GPT4's.
Again, not everyone who uses AI is a 3 year old child. Please re-consider your obsession with extreme censorship/alignment/moralizing/... Frankly, it's embarrassing.
:)
Gemma chat versions score far lower on the leaderboard than their foundational models, which isn't surprising since they perform horribly in my testing. Far worse than Mistral 7b.
The primary reason is clear. The alignment is GROSSLY overdone. Not everyone using an LLM is a 3 year old child. Adults use LLMs to, and ask basic questions about a wide variety of things that aren't the least bit illegal or amoral. By training your LLM with 1000s of 'As an AI model I can't answer that' responses you not only cripple the LLM in millions of legitimate use cases, the excessive alignment misfires and bleeds into completely unrelated areas, making the LLM perform much worse in every context.
Even your foundational models are stripped of basic knowledge that isn't remotely illegal or amoral, and which most adults already know, plus can be found in any basic encyclopedia. What's the point of that? Why would anyone turn to your AI models for reference when countless perfectly legal and moral bits of information is stripped from it? Info that can be found in Wikipedia or the first Google result. Even Gemini Pro/Ultra have astonishing blind spots, making them very unreliable sources of help and information despite their otherwise impressive abilities that are sometimes superior to GPT4's.
Again, not everyone who uses AI is a 3 year old child. Please re-consider your obsession with extreme censorship/alignment/moralizing/... Frankly, it's embarrassing.
Well you're expecting a model from Google to not be head deep in DEI alignment non-sense. Even Google search is biased lol.
Hi ,
Thank you for sharing your perspective — your feedback is clear, and we appreciate the time you took to write such a detailed critique.
If you're looking for more flexibility or fewer guardrails, we recommend using the foundation models like gemma-3-7b or gemma-3-12b. These are released without alignment, so you're free to fine-tune or prompt them however you like. That’s the best way to avoid the “as an AI…” type responses you're seeing in the chat variants.
Thank you.