Instructions to use unsloth/gemma-2b-bnb-4bit with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use unsloth/gemma-2b-bnb-4bit with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="unsloth/gemma-2b-bnb-4bit")# Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("unsloth/gemma-2b-bnb-4bit") model = AutoModelForCausalLM.from_pretrained("unsloth/gemma-2b-bnb-4bit", device_map="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use unsloth/gemma-2b-bnb-4bit with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "unsloth/gemma-2b-bnb-4bit" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "unsloth/gemma-2b-bnb-4bit", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/unsloth/gemma-2b-bnb-4bit
- SGLang
How to use unsloth/gemma-2b-bnb-4bit 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 "unsloth/gemma-2b-bnb-4bit" \ --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": "unsloth/gemma-2b-bnb-4bit", "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 "unsloth/gemma-2b-bnb-4bit" \ --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": "unsloth/gemma-2b-bnb-4bit", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Unsloth Studio
How to use unsloth/gemma-2b-bnb-4bit 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 unsloth/gemma-2b-bnb-4bit 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 unsloth/gemma-2b-bnb-4bit to start chatting
Using HuggingFace Spaces for Unsloth
# No setup required # Open https://huggingface.co/spaces/unsloth/studio in your browser # Search for unsloth/gemma-2b-bnb-4bit to start chatting
Load model with FastModel
pip install unsloth from unsloth import FastModel model, tokenizer = FastModel.from_pretrained( model_name="unsloth/gemma-2b-bnb-4bit", max_seq_length=2048, ) - Docker Model Runner
How to use unsloth/gemma-2b-bnb-4bit with Docker Model Runner:
docker model run hf.co/unsloth/gemma-2b-bnb-4bit
Model seems to be not PEFT model
Hi guys,
I ran into the follwoing error during this tutorial https://colab.research.google.com/drive/15gGm7x_jTm017_Ic8e317tdIpDG53Mtu?usp=sharing#scrollTo=2eSvM9zX_2d3. (error is the same for all models, in the test run I used mistral).
Specs:
- Ubuntu 20.04
- conda 24.1.2
As I can neither find any occurrences of the error online, nor seem to be capable of finding the issue myself, I am reaching out to you guys.
Does anyone know where it comes from? Thanks for your help!
HTTPError Traceback (most recent call last)
File ~/anaconda3/envs/unsloth/lib/python3.10/site-packages/huggingface_hub/utils/_errors.py:304, in hf_raise_for_status(response, endpoint_name)
303 try:
--> 304 response.raise_for_status()
305 except HTTPError as e:
File ~/anaconda3/envs/unsloth/lib/python3.10/site-packages/requests/models.py:1024, in Response.raise_for_status(self)
1023 if http_error_msg:
-> 1024 raise HTTPError(http_error_msg, response=self)
HTTPError: 401 Client Error: Unauthorized for url: https://huggingface.co/unsloth/mistral-7b-bnb-4bit/resolve/main/config.json
The above exception was the direct cause of the following exception:
RepositoryNotFoundError Traceback (most recent call last)
File ~/anaconda3/envs/unsloth/lib/python3.10/site-packages/transformers/utils/hub.py:399, in cached_file(path_or_repo_id, filename, cache_dir, force_download, resume_download, proxies, token, revision, local_files_only, subfolder, repo_type, user_agent, _raise_exceptions_for_gated_repo, _raise_exceptions_for_missing_entries, _raise_exceptions_for_connection_errors, _commit_hash, **deprecated_kwargs)
397 try:
398 # Load from URL or cache if already cached
--> 399 resolved_file = hf_hub_download(
400 path_or_repo_id,
401 filename,
402 subfolder=None if len(subfolder) == 0 else subfolder,
403 repo_type=repo_type,
404 revision=revision,
...
--> 102 raise RuntimeError(f"Unsloth: {model_name} is not a full model or a PEFT model.")
104 # Check base model again for PEFT
105 model_name = _get_model_name(peft_config.base_model_name_or_path, load_in_4bit)
RuntimeError: Unsloth: unsloth/mistral-7b-bnb-4bit is not a full model or a PEFT model.
Are you connected to the internet?