Instructions to use unsloth/llama-3-8b-Instruct-bnb-4bit with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use unsloth/llama-3-8b-Instruct-bnb-4bit with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="unsloth/llama-3-8b-Instruct-bnb-4bit") messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("unsloth/llama-3-8b-Instruct-bnb-4bit") model = AutoModelForCausalLM.from_pretrained("unsloth/llama-3-8b-Instruct-bnb-4bit", device_map="auto") 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]:])) - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use unsloth/llama-3-8b-Instruct-bnb-4bit with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "unsloth/llama-3-8b-Instruct-bnb-4bit" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "unsloth/llama-3-8b-Instruct-bnb-4bit", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/unsloth/llama-3-8b-Instruct-bnb-4bit
- SGLang
How to use unsloth/llama-3-8b-Instruct-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/llama-3-8b-Instruct-bnb-4bit" \ --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": "unsloth/llama-3-8b-Instruct-bnb-4bit", "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 "unsloth/llama-3-8b-Instruct-bnb-4bit" \ --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": "unsloth/llama-3-8b-Instruct-bnb-4bit", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Unsloth Desktop
- Docker Model Runner
How to use unsloth/llama-3-8b-Instruct-bnb-4bit with Docker Model Runner:
docker model run hf.co/unsloth/llama-3-8b-Instruct-bnb-4bit
BitsAndBytesConfig error
Hi, trying to load the model with
model_name = "unsloth/llama-3-8b-Instruct-bnb-4bit"
model, tokenizer = FastLanguageModel.from_pretrained(
model_name = model_name, # Choose ANY! eg teknium/OpenHermes-2.5-Mistral-7B
max_seq_length = max_seq_length,
dtype = dtype,
load_in_4bit = load_in_4bit,
quantization_config=nf4_config,
# token = "hf_...", # use one if using gated models like meta-llama/Llama-2-7b-hf
)
I'm getting an error Unused kwargs: ['_load_in_4bit', '_load_in_8bit', 'quant_method']. These kwargs are not used in <class 'transformers.utils.quantization_config.BitsAndBytesConfig'>.
I'm using transformers-4.40.1.
I don't get the error with transformers-4.39.3.
I see the config.json uses these kwargs
Oh no need to worry on the error - just ignore it - it should still work - I might update all of them to use the new kwargs
Hi There,
i have downloaded this model to use with ollama, i was wondering if you could leave a note on how to do this, And if not possible with ollama then how should i run it. i am new at this as you can tell :) .
thank you
Hi There,
i have downloaded this model to use with ollama, i was wondering if you could leave a note on how to do this, And if not possible with ollama then how should i run it. i am new at this as you can tell :) .
thank you
We have a Wiki which details a bit about Ollama: https://github.com/unslothai/unsloth/wiki#use-unsloth-lora-adapter-with-ollama