syubraj/medical-chat-phi-3.5-instruct-1k
Viewer • Updated • 1.2k • 20 • 2
How to use syubraj/Phi3.5-medicalchat-unsloth with Transformers:
# Use a pipeline as a high-level helper
from transformers import pipeline
pipe = pipeline("text-generation", model="syubraj/Phi3.5-medicalchat-unsloth")
messages = [
{"role": "user", "content": "Who are you?"},
]
pipe(messages) # Load model directly
from transformers import AutoTokenizer, AutoModelForCausalLM
tokenizer = AutoTokenizer.from_pretrained("syubraj/Phi3.5-medicalchat-unsloth")
model = AutoModelForCausalLM.from_pretrained("syubraj/Phi3.5-medicalchat-unsloth", 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]:]))How to use syubraj/Phi3.5-medicalchat-unsloth with vLLM:
# Install vLLM from pip:
pip install vllm
# Start the vLLM server:
vllm serve "syubraj/Phi3.5-medicalchat-unsloth"
# Call the server using curl (OpenAI-compatible API):
curl -X POST "http://localhost:8000/v1/chat/completions" \
-H "Content-Type: application/json" \
--data '{
"model": "syubraj/Phi3.5-medicalchat-unsloth",
"messages": [
{
"role": "user",
"content": "What is the capital of France?"
}
]
}'docker model run hf.co/syubraj/Phi3.5-medicalchat-unsloth
How to use syubraj/Phi3.5-medicalchat-unsloth with SGLang:
# Install SGLang from pip:
pip install sglang
# Start the SGLang server:
python3 -m sglang.launch_server \
--model-path "syubraj/Phi3.5-medicalchat-unsloth" \
--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": "syubraj/Phi3.5-medicalchat-unsloth",
"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 "syubraj/Phi3.5-medicalchat-unsloth" \
--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": "syubraj/Phi3.5-medicalchat-unsloth",
"messages": [
{
"role": "user",
"content": "What is the capital of France?"
}
]
}'How to use syubraj/Phi3.5-medicalchat-unsloth with Docker Model Runner:
docker model run hf.co/syubraj/Phi3.5-medicalchat-unsloth
The MedicalChat-Phi-3.5-mini-instruct- fine-tuned model is designed to simulate doctor-patient conversations, offering medical consultations and suggestions based on patient queries. However, its accuracy may be limited in real-world scenarios, as the training dataset was relatively small.
!pip install unsloth
from unsloth import FastLanguageModel
model, tokenizer = FastLanguageModel.from_pretrained("syubraj/Phi3.5-medicalchat-unsloth",
max_seq_length = 1024,
load_in_4bit = True,
dtype = None
)
user_query = "<Your medical query here>"
system_prompt = """You are a trusted AI-powered medical assistant. Analyze patient queries carefully and provide accurate, professional, and empathetic responses. Prioritize patient safety, adhere to medical best practices, and recommend consulting a healthcare provider when necessary."""
message = [
{"role": "system", "content": system_prompt},
{"role": "human", "content": user_query}
]
# Creating message based on tokenizers chat template
prompt = tokenizer.apply_chat_template(message, tokenize = False, add_generation_prompt = True)
FastLanguageModel.for_inference(model)
# Tokenizing inputs
inputs = tokenizer(prompt, return_tensors = "pt").to("cuda")
# Output Generated
outputs = model.generate(**inputs, max_new_tokens=256, use_cache=True) # Change the `max_new_tokens` according to required objective
tokenizer.batch_decode(outputs)
| Step | Training Loss |
|---|---|
| 10 | 2.53 |
| 20 | 2.20 |
| 30 | 1.95 |
| 40 | 2.01 |
| 50 | 1.97 |
| 60 | 2.02 |
Base model
microsoft/Phi-3.5-mini-instruct