tatsu-lab/alpaca
Viewer • Updated • 52k • 109k • 975
How to use lxyuan/llama-3-8b-Instruct-lora-merged with Transformers:
# Use a pipeline as a high-level helper
from transformers import pipeline
pipe = pipeline("text-generation", model="lxyuan/llama-3-8b-Instruct-lora-merged")
messages = [
{"role": "user", "content": "Who are you?"},
]
pipe(messages) # Load model directly
from transformers import AutoTokenizer, AutoModelForCausalLM
tokenizer = AutoTokenizer.from_pretrained("lxyuan/llama-3-8b-Instruct-lora-merged")
model = AutoModelForCausalLM.from_pretrained("lxyuan/llama-3-8b-Instruct-lora-merged")
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]:]))How to use lxyuan/llama-3-8b-Instruct-lora-merged with vLLM:
# Install vLLM from pip:
pip install vllm
# Start the vLLM server:
vllm serve "lxyuan/llama-3-8b-Instruct-lora-merged"
# Call the server using curl (OpenAI-compatible API):
curl -X POST "http://localhost:8000/v1/chat/completions" \
-H "Content-Type: application/json" \
--data '{
"model": "lxyuan/llama-3-8b-Instruct-lora-merged",
"messages": [
{
"role": "user",
"content": "What is the capital of France?"
}
]
}'docker model run hf.co/lxyuan/llama-3-8b-Instruct-lora-merged
How to use lxyuan/llama-3-8b-Instruct-lora-merged with SGLang:
# Install SGLang from pip:
pip install sglang
# Start the SGLang server:
python3 -m sglang.launch_server \
--model-path "lxyuan/llama-3-8b-Instruct-lora-merged" \
--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": "lxyuan/llama-3-8b-Instruct-lora-merged",
"messages": [
{
"role": "user",
"content": "What is the capital of France?"
}
]
}'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 "lxyuan/llama-3-8b-Instruct-lora-merged" \
--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": "lxyuan/llama-3-8b-Instruct-lora-merged",
"messages": [
{
"role": "user",
"content": "What is the capital of France?"
}
]
}'How to use lxyuan/llama-3-8b-Instruct-lora-merged with Unsloth Studio:
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 lxyuan/llama-3-8b-Instruct-lora-merged to start chatting
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 lxyuan/llama-3-8b-Instruct-lora-merged to start chatting
# No setup required # Open https://huggingface.co/spaces/unsloth/studio in your browser # Search for lxyuan/llama-3-8b-Instruct-lora-merged to start chatting
pip install unsloth
from unsloth import FastModel
model, tokenizer = FastModel.from_pretrained(
model_name="lxyuan/llama-3-8b-Instruct-lora-merged",
max_seq_length=2048,
)How to use lxyuan/llama-3-8b-Instruct-lora-merged with Docker Model Runner:
docker model run hf.co/lxyuan/llama-3-8b-Instruct-lora-merged
Model Description: Finetuned the Llama-3-8B-Instruct Model using unsloth on Alpaca Dataset for 1000 steps.
import torch
major_version, minor_version = torch.cuda.get_device_capability()
# Must install separately since Colab has torch 2.2.1, which breaks packages
!pip install "unsloth[colab-new] @ git+https://github.com/unslothai/unsloth.git"
if major_version >= 8:
# Use this for new GPUs like Ampere, Hopper GPUs (RTX 30xx, RTX 40xx, A100, H100, L40)
!pip install --no-deps packaging ninja einops flash-attn xformers trl peft accelerate bitsandbytes
else:
# Use this for older GPUs (V100, Tesla T4, RTX 20xx)
!pip install --no-deps xformers trl peft accelerate bitsandbytes
from transformers import pipeline
from unsloth import FastLanguageModel
model, tokenizer = FastLanguageModel.from_pretrained(
model_name = "lxyuan/llama-3-8b-Instruct-lora-merged",
dtype = None, # auto detect
load_in_4bit = True, # default is True
)
FastLanguageModel.for_inference(model) # Enable native 2x faster inference
pipeline = pipeline("text-generation", model=model, tokenizer=tokenizer)
messages = [
{"role": "system", "content": "You are helpful AI bot that follows instruction to complete task."},
{"role": "user", "content": "Write me 10 sentences that end with 'apple"},
]
prompt = tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
terminators = [
tokenizer.eos_token_id,
tokenizer.convert_tokens_to_ids("<|eot_id|>")
]
outputs = pipeline(
prompt,
max_new_tokens=512,
eos_token_id=terminators,
do_sample=True,
temperature=0.6,
top_p=0.9,
)
print(outputs[0]["generated_text"])
<|begin_of_text|><|start_header_id|>system<|end_header_id|>
You are helpful AI bot that follows instruction to complete task.<|eot_id|><|start_header_id|>user<|end_header_id|>
Write me 10 sentences that end with 'apple<|eot_id|><|start_header_id|>assistant<|end_header_id|>
Here are 10 sentences that end with the word "apple":
1. The farmer grew a juicy red apple.
2. She ate a crunchy green apple.
3. The tree bore a ripe yellow apple.
4. He bit into a sweet Granny Smith apple.
5. The basket was filled with fresh apples.
6. The juice was squeezed from a ripe red apple.
7. She picked a perfect autumn apple.
8. The pie was filled with tender Granny Smith apple.
9. The farmer's market sold a variety of apples.
10. The snack was a crisp, juicy apple.
Base model
unsloth/llama-3-8b-Instruct-bnb-4bit