lavita/ChatDoctor-HealthCareMagic-100k
Viewer • Updated • 112k • 9.37k • 114
How to use halame/chatdoctor-llama3-lora with PEFT:
from peft import PeftModel
from transformers import AutoModelForCausalLM
base_model = AutoModelForCausalLM.from_pretrained("./models/llama3-8b")
model = PeftModel.from_pretrained(base_model, "halame/chatdoctor-llama3-lora")How to use halame/chatdoctor-llama3-lora with Transformers:
# Use a pipeline as a high-level helper
from transformers import pipeline
pipe = pipeline("text-generation", model="halame/chatdoctor-llama3-lora")
messages = [
{"role": "user", "content": "Who are you?"},
]
pipe(messages) # Load model directly
from transformers import AutoModel
model = AutoModel.from_pretrained("halame/chatdoctor-llama3-lora", device_map="auto")How to use halame/chatdoctor-llama3-lora with vLLM:
# Install vLLM from pip:
pip install vllm
# Start the vLLM server:
vllm serve "halame/chatdoctor-llama3-lora"
# Call the server using curl (OpenAI-compatible API):
curl -X POST "http://localhost:8000/v1/chat/completions" \
-H "Content-Type: application/json" \
--data '{
"model": "halame/chatdoctor-llama3-lora",
"messages": [
{
"role": "user",
"content": "What is the capital of France?"
}
]
}'docker model run hf.co/halame/chatdoctor-llama3-lora
How to use halame/chatdoctor-llama3-lora with SGLang:
# Install SGLang from pip:
pip install sglang
# Start the SGLang server:
python3 -m sglang.launch_server \
--model-path "halame/chatdoctor-llama3-lora" \
--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": "halame/chatdoctor-llama3-lora",
"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 "halame/chatdoctor-llama3-lora" \
--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": "halame/chatdoctor-llama3-lora",
"messages": [
{
"role": "user",
"content": "What is the capital of France?"
}
]
}'How to use halame/chatdoctor-llama3-lora with Docker Model Runner:
docker model run hf.co/halame/chatdoctor-llama3-lora
A fine-tuned LoRA adapter for medical question answering, achieving BERTScore F1 = 0.845 (best result, exceeds original ChatDoctor paper).
| Model | BERTScore P | BERTScore R | BERTScore F1 |
|---|---|---|---|
| ChatDoctor (Paper) | 0.844 | 0.845 | 0.841 |
| Mistral + LoRA | 0.845 | 0.843 | 0.844 |
| LLaMA-3 + LoRA | 0.844 | 0.846 | 0.845 |
from transformers import AutoModelForCausalLM, AutoTokenizer
from peft import PeftModel
import torch
# Load base model
base_model = AutoModelForCausalLM.from_pretrained(
"NousResearch/Meta-Llama-3-8B-Instruct",
torch_dtype=torch.float16,
device_map="auto"
)
# Load LoRA adapter
model = PeftModel.from_pretrained(base_model, "halame/chatdoctor-llama3-lora")
tokenizer = AutoTokenizer.from_pretrained("halame/chatdoctor-llama3-lora")
# Generate
prompt = "I have headache and fever for 2 days. What should I do?"
inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
outputs = model.generate(**inputs, max_new_tokens=256)
print(tokenizer.decode(outputs[0], skip_special_tokens=True))
Apache 2.0
This model is for research purposes only. Do not use for actual medical diagnosis.
Base model
NousResearch/Meta-Llama-3-8B-Instruct