Instructions to use google/gemma-2-9b with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use google/gemma-2-9b with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="google/gemma-2-9b")# Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("google/gemma-2-9b") model = AutoModelForCausalLM.from_pretrained("google/gemma-2-9b") - Inference
- Notebooks
- Google Colab
- Kaggle
- Local Apps
- vLLM
How to use google/gemma-2-9b with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "google/gemma-2-9b" # 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-2-9b", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/google/gemma-2-9b
- SGLang
How to use google/gemma-2-9b 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-2-9b" \ --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-2-9b", "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-2-9b" \ --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-2-9b", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Docker Model Runner
How to use google/gemma-2-9b with Docker Model Runner:
docker model run hf.co/google/gemma-2-9b
ValueError: Transformers does not recognize this architecture.
ValueError: The checkpoint you are trying to load has model type gemma2 but Transformers does not recognize this architecture. This could be because of an issue with the checkpoint, or because your version of Transformers is out of date.
OS:Ubuntu22.04
nvcc:
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2022 NVIDIA Corporation
Built on Wed_Jun__8_16:49:14_PDT_2022
Cuda compilation tools, release 11.7, V11.7.99
Build cuda_11.7.r11.7/compiler.31442593_0
NVIDIA-smi:
I try update the Transformers
pip install --upgrade transformers
Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simple
Requirement already satisfied: transformers in /root/miniconda3/lib/python3.11/site-packages (4.41.2)
Collecting transformers
Downloading https://pypi.tuna.tsinghua.edu.cn/packages/20/5c/244db59e074e80248fdfa60495eeee257e4d97c3df3487df68be30cd60c8/transformers-4.42.3-py3-none-any.whl (9.3 MB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 9.3/9.3 MB 12.7 MB/s eta 0:00:00
Requirement already satisfied: filelock in /root/miniconda3/lib/python3.11/site-packages (from transformers) (3.13.1)
Requirement already satisfied: huggingface-hub<1.0,>=0.23.2 in /root/miniconda3/lib/python3.11/site-packages (from transformers) (0.23.4)
Requirement already satisfied: numpy<2.0,>=1.17 in /root/miniconda3/lib/python3.11/site-packages (from transformers) (1.26.4)
Requirement already satisfied: packaging>=20.0 in /root/miniconda3/lib/python3.11/site-packages (from transformers) (23.0)
Requirement already satisfied: pyyaml>=5.1 in /root/miniconda3/lib/python3.11/site-packages (from transformers) (6.0.1)
Requirement already satisfied: regex!=2019.12.17 in /root/miniconda3/lib/python3.11/site-packages (from transformers) (2024.5.15)
Requirement already satisfied: requests in /root/miniconda3/lib/python3.11/site-packages (from transformers) (2.32.3)
Requirement already satisfied: safetensors>=0.4.1 in /root/miniconda3/lib/python3.11/site-packages (from transformers) (0.4.3)
Requirement already satisfied: tokenizers<0.20,>=0.19 in /root/miniconda3/lib/python3.11/site-packages (from transformers) (0.19.1)
Requirement already satisfied: tqdm>=4.27 in /root/miniconda3/lib/python3.11/site-packages (from transformers) (4.65.0)
Requirement already satisfied: fsspec>=2023.5.0 in /root/miniconda3/lib/python3.11/site-packages (from huggingface-hub<1.0,>=0.23.2->transformers) (2024.2.0)
Requirement already satisfied: typing-extensions>=3.7.4.3 in /root/miniconda3/lib/python3.11/site-packages (from huggingface-hub<1.0,>=0.23.2->transformers) (4.12.2)
Requirement already satisfied: charset-normalizer<4,>=2 in /root/miniconda3/lib/python3.11/site-packages (from requests->transformers) (2.0.4)
Requirement already satisfied: idna<4,>=2.5 in /root/miniconda3/lib/python3.11/site-packages (from requests->transformers) (3.4)
Requirement already satisfied: urllib3<3,>=1.21.1 in /root/miniconda3/lib/python3.11/site-packages (from requests->transformers) (1.26.16)
Requirement already satisfied: certifi>=2017.4.17 in /root/miniconda3/lib/python3.11/site-packages (from requests->transformers) (2023.5.7)
Installing collected packages: transformers
Attempting uninstall: transformers
Found existing installation: transformers 4.41.2
Uninstalling transformers-4.41.2:
Successfully uninstalled transformers-4.41.2
Successfully installed transformers-4.42.3
But: The Error again!!
So ,How fixed it~~
same problem
Hello! This shouldn't happen and is likely a problem in your environment.
Within your environment, what happens if you do
python
>>> from transformers import __version__
>>> print(__version__)
?
Hi @mike202303 and @carloscaminha , Could you please try again by installing this specific version of transformers 4.42.0 or 4.42.1 as mentioned in this similar issue and let us know if the issue still persists, Thank you.
It worked with v4.42.3. Thanks!
