Text Generation
Transformers
Safetensors
English
llama
unsloth
llama-2
chat
conversational
text-generation-inference
4-bit precision
bitsandbytes
Instructions to use unsloth/llama-2-7b-chat-bnb-4bit with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use unsloth/llama-2-7b-chat-bnb-4bit with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="unsloth/llama-2-7b-chat-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-2-7b-chat-bnb-4bit") model = AutoModelForCausalLM.from_pretrained("unsloth/llama-2-7b-chat-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-2-7b-chat-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-2-7b-chat-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-2-7b-chat-bnb-4bit", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/unsloth/llama-2-7b-chat-bnb-4bit
- SGLang
How to use unsloth/llama-2-7b-chat-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-2-7b-chat-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-2-7b-chat-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-2-7b-chat-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-2-7b-chat-bnb-4bit", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Unsloth Studio
How to use unsloth/llama-2-7b-chat-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/llama-2-7b-chat-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/llama-2-7b-chat-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/llama-2-7b-chat-bnb-4bit to start chatting
Load model with FastModel
pip install unsloth from unsloth import FastModel model, tokenizer = FastModel.from_pretrained( model_name="unsloth/llama-2-7b-chat-bnb-4bit", max_seq_length=2048, ) - Docker Model Runner
How to use unsloth/llama-2-7b-chat-bnb-4bit with Docker Model Runner:
docker model run hf.co/unsloth/llama-2-7b-chat-bnb-4bit
Upload config
Browse files- README.md +1 -2
- config.json +7 -4
README.md
CHANGED
|
@@ -1,15 +1,14 @@
|
|
| 1 |
---
|
| 2 |
language:
|
| 3 |
- en
|
| 4 |
-
license: apache-2.0
|
| 5 |
library_name: transformers
|
|
|
|
| 6 |
tags:
|
| 7 |
- unsloth
|
| 8 |
- transformers
|
| 9 |
- llama-2
|
| 10 |
- llama
|
| 11 |
- chat
|
| 12 |
-
|
| 13 |
---
|
| 14 |
|
| 15 |
# Finetune Mistral, Gemma, Llama 2-5x faster with 70% less memory via Unsloth!
|
|
|
|
| 1 |
---
|
| 2 |
language:
|
| 3 |
- en
|
|
|
|
| 4 |
library_name: transformers
|
| 5 |
+
license: apache-2.0
|
| 6 |
tags:
|
| 7 |
- unsloth
|
| 8 |
- transformers
|
| 9 |
- llama-2
|
| 10 |
- llama
|
| 11 |
- chat
|
|
|
|
| 12 |
---
|
| 13 |
|
| 14 |
# Finetune Mistral, Gemma, Llama 2-5x faster with 70% less memory via Unsloth!
|
config.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
| 1 |
{
|
| 2 |
-
"_name_or_path": "
|
| 3 |
"architectures": [
|
| 4 |
"LlamaForCausalLM"
|
| 5 |
],
|
|
@@ -12,6 +12,7 @@
|
|
| 12 |
"initializer_range": 0.02,
|
| 13 |
"intermediate_size": 11008,
|
| 14 |
"max_position_embeddings": 4096,
|
|
|
|
| 15 |
"model_type": "llama",
|
| 16 |
"num_attention_heads": 32,
|
| 17 |
"num_hidden_layers": 32,
|
|
@@ -21,7 +22,8 @@
|
|
| 21 |
"quantization_config": {
|
| 22 |
"_load_in_4bit": true,
|
| 23 |
"_load_in_8bit": false,
|
| 24 |
-
"bnb_4bit_compute_dtype": "
|
|
|
|
| 25 |
"bnb_4bit_quant_type": "nf4",
|
| 26 |
"bnb_4bit_use_double_quant": true,
|
| 27 |
"llm_int8_enable_fp32_cpu_offload": false,
|
|
@@ -36,8 +38,9 @@
|
|
| 36 |
"rope_scaling": null,
|
| 37 |
"rope_theta": 10000.0,
|
| 38 |
"tie_word_embeddings": false,
|
| 39 |
-
"torch_dtype": "
|
| 40 |
-
"transformers_version": "4.
|
|
|
|
| 41 |
"use_cache": true,
|
| 42 |
"vocab_size": 32000
|
| 43 |
}
|
|
|
|
| 1 |
{
|
| 2 |
+
"_name_or_path": "unsloth/llama-2-7b-chat",
|
| 3 |
"architectures": [
|
| 4 |
"LlamaForCausalLM"
|
| 5 |
],
|
|
|
|
| 12 |
"initializer_range": 0.02,
|
| 13 |
"intermediate_size": 11008,
|
| 14 |
"max_position_embeddings": 4096,
|
| 15 |
+
"mlp_bias": false,
|
| 16 |
"model_type": "llama",
|
| 17 |
"num_attention_heads": 32,
|
| 18 |
"num_hidden_layers": 32,
|
|
|
|
| 22 |
"quantization_config": {
|
| 23 |
"_load_in_4bit": true,
|
| 24 |
"_load_in_8bit": false,
|
| 25 |
+
"bnb_4bit_compute_dtype": "bfloat16",
|
| 26 |
+
"bnb_4bit_quant_storage": "uint8",
|
| 27 |
"bnb_4bit_quant_type": "nf4",
|
| 28 |
"bnb_4bit_use_double_quant": true,
|
| 29 |
"llm_int8_enable_fp32_cpu_offload": false,
|
|
|
|
| 38 |
"rope_scaling": null,
|
| 39 |
"rope_theta": 10000.0,
|
| 40 |
"tie_word_embeddings": false,
|
| 41 |
+
"torch_dtype": "bfloat16",
|
| 42 |
+
"transformers_version": "4.44.0",
|
| 43 |
+
"unsloth_version": "2024.8",
|
| 44 |
"use_cache": true,
|
| 45 |
"vocab_size": 32000
|
| 46 |
}
|