databricks/databricks-dolly-15k
Viewer • Updated • 15k • 42.6k • 997
How to use snowfly/llama2-7b-QLoRA-dolly with Transformers:
# Use a pipeline as a high-level helper
from transformers import pipeline
pipe = pipeline("text-generation", model="snowfly/llama2-7b-QLoRA-dolly") # Load model directly
from transformers import AutoTokenizer, AutoModelForCausalLM
tokenizer = AutoTokenizer.from_pretrained("snowfly/llama2-7b-QLoRA-dolly")
model = AutoModelForCausalLM.from_pretrained("snowfly/llama2-7b-QLoRA-dolly")How to use snowfly/llama2-7b-QLoRA-dolly with vLLM:
# Install vLLM from pip:
pip install vllm
# Start the vLLM server:
vllm serve "snowfly/llama2-7b-QLoRA-dolly"
# Call the server using curl (OpenAI-compatible API):
curl -X POST "http://localhost:8000/v1/completions" \
-H "Content-Type: application/json" \
--data '{
"model": "snowfly/llama2-7b-QLoRA-dolly",
"prompt": "Once upon a time,",
"max_tokens": 512,
"temperature": 0.5
}'docker model run hf.co/snowfly/llama2-7b-QLoRA-dolly
How to use snowfly/llama2-7b-QLoRA-dolly with SGLang:
# Install SGLang from pip:
pip install sglang
# Start the SGLang server:
python3 -m sglang.launch_server \
--model-path "snowfly/llama2-7b-QLoRA-dolly" \
--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": "snowfly/llama2-7b-QLoRA-dolly",
"prompt": "Once upon a time,",
"max_tokens": 512,
"temperature": 0.5
}'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 "snowfly/llama2-7b-QLoRA-dolly" \
--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": "snowfly/llama2-7b-QLoRA-dolly",
"prompt": "Once upon a time,",
"max_tokens": 512,
"temperature": 0.5
}'How to use snowfly/llama2-7b-QLoRA-dolly with Docker Model Runner:
docker model run hf.co/snowfly/llama2-7b-QLoRA-dolly
from datasets import load_dataset
from random import randrange
# 从hub加载数据集并得到一个样本
dataset = load_dataset("databricks/databricks-dolly-15k", split="train")
sample = dataset[randrange(len(dataset))]
from transformers import AutoTokenizer, AutoModelForCausalLM
import torch
model_name_or_path = "snowfly/llama2-7b-QLoRA-dolly"
tokenizer = AutoTokenizer.from_pretrained(pretrained_model_name_or_path=model_name_or_path, trust_remote_code=True)
model = AutoModelForCausalLM.from_pretrained(pretrained_model_name_or_path=model_name_or_path,
trust_remote_code=True,
low_cpu_mem_usage=True,
torch_dtype=torch.float16,
load_in_4bit=True)
model = model.eval()
prompt = f"""### Instruction:
Use the Input below to create an instruction, which could have been used to generate the input using an LLM.
### Input:
{sample['response']}
### Response:
"""
input_ids = tokenizer(prompt, return_tensors="pt", truncation=True).input_ids.cuda()
outputs = model.generate(input_ids=input_ids, max_new_tokens=100, do_sample=True, top_p=0.9,temperature=0.9)
print(f"Prompt:\n{sample['response']}\n")
print(f"Generated instruction:\n{tokenizer.batch_decode(outputs.detach().cpu().numpy(), skip_special_tokens=True)[0][len(prompt):]}")
print(f"Ground truth:\n{sample['instruction']}")