Instructions to use google/gemma-2b with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use google/gemma-2b with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="google/gemma-2b")# Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("google/gemma-2b") model = AutoModelForCausalLM.from_pretrained("google/gemma-2b") - llama-cpp-python
How to use google/gemma-2b with llama-cpp-python:
# !pip install llama-cpp-python from llama_cpp import Llama llm = Llama.from_pretrained( repo_id="google/gemma-2b", filename="gemma-2b.gguf", )
output = llm( "Once upon a time,", max_tokens=512, echo=True ) print(output)
- Inference
- Notebooks
- Google Colab
- Kaggle
- Local Apps
- llama.cpp
How to use google/gemma-2b with llama.cpp:
Install from brew
brew install llama.cpp # Start a local OpenAI-compatible server with a web UI: llama-server -hf google/gemma-2b # Run inference directly in the terminal: llama-cli -hf google/gemma-2b
Install from WinGet (Windows)
winget install llama.cpp # Start a local OpenAI-compatible server with a web UI: llama-server -hf google/gemma-2b # Run inference directly in the terminal: llama-cli -hf google/gemma-2b
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-2b # Run inference directly in the terminal: ./llama-cli -hf google/gemma-2b
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-2b # Run inference directly in the terminal: ./build/bin/llama-cli -hf google/gemma-2b
Use Docker
docker model run hf.co/google/gemma-2b
- LM Studio
- Jan
- vLLM
How to use google/gemma-2b with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "google/gemma-2b" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "google/gemma-2b", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/google/gemma-2b
- SGLang
How to use google/gemma-2b 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-2b" \ --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": "google/gemma-2b", "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 "google/gemma-2b" \ --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": "google/gemma-2b", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Ollama
How to use google/gemma-2b with Ollama:
ollama run hf.co/google/gemma-2b
- Unsloth Studio new
How to use google/gemma-2b 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-2b 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-2b 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-2b to start chatting
- Docker Model Runner
How to use google/gemma-2b with Docker Model Runner:
docker model run hf.co/google/gemma-2b
- Lemonade
How to use google/gemma-2b with Lemonade:
Pull the model
# Download Lemonade from https://lemonade-server.ai/ lemonade pull google/gemma-2b
Run and chat with the model
lemonade run user.gemma-2b-{{QUANT_TAG}}List all available models
lemonade list
ImportError: Using `bitsandbytes` 8-bit quantization requires Accelerate: `pip install accelerate` and the latest version of bitsandbytes
Error:
- as following
pip install accelerate bitsandbytesdoesn't work
ImportError: Using `bitsandbytes` 8-bit quantization requires Accelerate: `pip install accelerate` and the latest version of bitsandbytes
Env info
Python 3.12.1
accelerate 0.27.2
bitsandbytes 0.42.0
torch 2.2.1
tqdm 4.65.0
transformers 4.38.2
trl 0.7.11
Someone says we need to downgrade transformers library to version 4.30, on order to fix this error
However, GemmerTokenizer need to upgrade transformers to version 4.38 ...
Can you retry on a fresh new env? Also can you confirm you have access to a GPU device?
I also encountered the same issue
I am having the same issue. I am using Google Colab with an A100 GPU and have tried several versions of bitsandbytes, all >=4.1.3 since only this version supports the quantization method. I had to install version 0.4.2 on Google Colab, and that one worked.
@WQW @HONGMAOLIN I think if you are experimenting this locally. Accelerate requires GPU (Mandatory). without GPU accelerate won't work. You may try that on google colab free T4.
Happening for me on Windows(no GPU) with python 3.11 and:
accelerate 0.28.0
bitsandbytes 0.43.0
transformers 4.38.2
same issue on a mac m1
@thepandapi as far as I know Mac doesn't have a dedicated GPU. Please make sure if you are using the library locally you have a dedicated GPU.
I am having the same issue
packages installed with CUDA 11.8 -
torch - 2.3.0+cu118
llama-index - 0.10.37
llama-index-llms-huggingface - 0.2.0
transformers - 4.39.0
accelerate - 0.27.0
bitsandbytes - 0.43.1
Hi everyone, there are news about this issue? I have the same issue In a windows machine with a dedicated GPU, a rtx 3060 of 20gbs.
Hi , Sorry for the late response, BitsAndBytes 8-bit quantization requires the Accelerate library, which is not installed or an outdated version is being used, Ensure that accelerate is installed with pip install accelerate. and Update bitsandbytes to the latest version with pip install -i . and also use 4-bit quantization instead of 8-bit. It provides better performance, uses less memory, and is often more stable and better supported in recent library versions. Kindly try this version of bitsandbytes, all >=4.1.3 since only this version supports the quantization method.
Kindly try and let me know if issue is still persists. Thank you.