Instructions to use unsloth/Meta-Llama-3.1-8B-Instruct-bnb-4bit with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use unsloth/Meta-Llama-3.1-8B-Instruct-bnb-4bit with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="unsloth/Meta-Llama-3.1-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/Meta-Llama-3.1-8B-Instruct-bnb-4bit") model = AutoModelForCausalLM.from_pretrained("unsloth/Meta-Llama-3.1-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/Meta-Llama-3.1-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/Meta-Llama-3.1-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/Meta-Llama-3.1-8B-Instruct-bnb-4bit", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/unsloth/Meta-Llama-3.1-8B-Instruct-bnb-4bit
- SGLang
How to use unsloth/Meta-Llama-3.1-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/Meta-Llama-3.1-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/Meta-Llama-3.1-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/Meta-Llama-3.1-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/Meta-Llama-3.1-8B-Instruct-bnb-4bit", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Unsloth Studio
How to use unsloth/Meta-Llama-3.1-8B-Instruct-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/Meta-Llama-3.1-8B-Instruct-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/Meta-Llama-3.1-8B-Instruct-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/Meta-Llama-3.1-8B-Instruct-bnb-4bit to start chatting
Load model with FastModel
pip install unsloth from unsloth import FastModel model, tokenizer = FastModel.from_pretrained( model_name="unsloth/Meta-Llama-3.1-8B-Instruct-bnb-4bit", max_seq_length=2048, ) - Docker Model Runner
How to use unsloth/Meta-Llama-3.1-8B-Instruct-bnb-4bit with Docker Model Runner:
docker model run hf.co/unsloth/Meta-Llama-3.1-8B-Instruct-bnb-4bit
RuntimeError: Unsloth: `unsloth/Meta-Llama-3.1-8B-bnb-4bit` is not a base model or a PEFT model.
Hi there, when trying to fine tune the model, I get the following error:
RuntimeError: Unsloth: unsloth/Meta-Llama-3.1-8B-bnb-4bit is not a base model or a PEFT model.
We could not locate a config.json or adapter_config.json file.
Are you certain the model name is correct? Does it actually exist?
Previous runs with Llama3.0 worked well, however, since trying llama3.1 I am receiving the error. According to the files shared in this repo, it seems that the model does contain a config.json.
Thanks!
Same error here
same error for me too
+1
Encountering the same error for the 405B model as well.
@ewre324 @meabo @VALilly @yorickdejong Apologies on the error!
Could you all try reinstalling Unsloth?
pip uninstall unsloth -y
pip install --upgrade --force-reinstall --no-cache-dir git+https://github.com/unslothai/unsloth.git
@danielhanchen Thanks for sharing an approach to solving the issue by upgrading the unsloth package. Unfortunately, the issue persists after uninstalling and upgrading with the path you shared above.
Currently, I am getting this error message.
/home/devops/miniconda3/envs/emsd_demo/lib/python3.11/site-packages/peft/utils/other.py:581: UserWarning: Unable to fetch remote file due to the following error (ProtocolError('Connection aborted.', RemoteDisconnected('Remote end closed connection without response')), '(Request ID: c9ad27cd-574c-43b8-8c2f-a49f60e4050a)') - silently ignoring the lookup for the file config.json in unsloth/llama-3-8b-bnb-4bit.
warnings.warn(
/home/devops/miniconda3/envs/emsd_demo/lib/python3.11/site-packages/peft/utils/save_and_load.py:154: UserWarning: Could not find a config file in unsloth/llama-3-8b-bnb-4bit - will assume that the vocabulary was not modified.
warnings.warn(
{'train_runtime': 610.2927, 'train_samples_per_second': 5.899, 'train_steps_per_second': 0.492, 'train_loss': 0.5799148793518544, 'epoch': 10.71}
As if this isn't enough, it hasn't been possible to revert to the old package as I keep getting same error message after several trials of reinstalling unsloth
update Transformer.
pip install --upgrade transformers