unsloth/Radiology_mini
Viewer • Updated • 2.31k • 827 • 44
How to use YLX1965/llama3-2-11b-xray-v1 with Diffusers:
pip install -U diffusers transformers accelerate
import torch
from diffusers import DiffusionPipeline
# switch to "mps" for apple devices
pipe = DiffusionPipeline.from_pretrained("YLX1965/llama3-2-11b-xray-v1", dtype=torch.bfloat16, device_map="cuda")
prompt = "Hi, what can you help me with?"
image = pipe(prompt).images[0]How to use YLX1965/llama3-2-11b-xray-v1 with Transformers:
# Use a pipeline as a high-level helper
from transformers import pipeline
pipe = pipeline("image-text-to-text", model="YLX1965/llama3-2-11b-xray-v1")
messages = [
{
"role": "user",
"content": [
{"type": "image", "url": "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/p-blog/candy.JPG"},
{"type": "text", "text": "What animal is on the candy?"}
]
},
]
pipe(text=messages) # Load model directly
from transformers import AutoProcessor, AutoModelForMultimodalLM
processor = AutoProcessor.from_pretrained("YLX1965/llama3-2-11b-xray-v1")
model = AutoModelForMultimodalLM.from_pretrained("YLX1965/llama3-2-11b-xray-v1")
messages = [
{
"role": "user",
"content": [
{"type": "image", "url": "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/p-blog/candy.JPG"},
{"type": "text", "text": "What animal is on the candy?"}
]
},
]
inputs = processor.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(processor.decode(outputs[0][inputs["input_ids"].shape[-1]:]))How to use YLX1965/llama3-2-11b-xray-v1 with vLLM:
# Install vLLM from pip:
pip install vllm
# Start the vLLM server:
vllm serve "YLX1965/llama3-2-11b-xray-v1"
# Call the server using curl (OpenAI-compatible API):
curl -X POST "http://localhost:8000/v1/chat/completions" \
-H "Content-Type: application/json" \
--data '{
"model": "YLX1965/llama3-2-11b-xray-v1",
"messages": [
{
"role": "user",
"content": [
{
"type": "text",
"text": "Describe this image in one sentence."
},
{
"type": "image_url",
"image_url": {
"url": "https://cdn.britannica.com/61/93061-050-99147DCE/Statue-of-Liberty-Island-New-York-Bay.jpg"
}
}
]
}
]
}'docker model run hf.co/YLX1965/llama3-2-11b-xray-v1
How to use YLX1965/llama3-2-11b-xray-v1 with SGLang:
# Install SGLang from pip:
pip install sglang
# Start the SGLang server:
python3 -m sglang.launch_server \
--model-path "YLX1965/llama3-2-11b-xray-v1" \
--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": "YLX1965/llama3-2-11b-xray-v1",
"messages": [
{
"role": "user",
"content": [
{
"type": "text",
"text": "Describe this image in one sentence."
},
{
"type": "image_url",
"image_url": {
"url": "https://cdn.britannica.com/61/93061-050-99147DCE/Statue-of-Liberty-Island-New-York-Bay.jpg"
}
}
]
}
]
}'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 "YLX1965/llama3-2-11b-xray-v1" \
--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": "YLX1965/llama3-2-11b-xray-v1",
"messages": [
{
"role": "user",
"content": [
{
"type": "text",
"text": "Describe this image in one sentence."
},
{
"type": "image_url",
"image_url": {
"url": "https://cdn.britannica.com/61/93061-050-99147DCE/Statue-of-Liberty-Island-New-York-Bay.jpg"
}
}
]
}
]
}'How to use YLX1965/llama3-2-11b-xray-v1 with Docker Model Runner:
docker model run hf.co/YLX1965/llama3-2-11b-xray-v1
该模型是 unsloth/Llama-3.2-11B-Vision-Instruct-bnb-4bit 的微调版本,专为分析医学放射影像(X 射线、CT 扫描、超声)而设计。它在 ROCO 放射数据集 (unsloth/Radiology_mini) 的一个子集上进行训练,以生成图像的描述,充当专业的放射技师。
该模型使用 Unsloth 进行微调,以实现 2 倍更快的训练速度并减少内存使用。关键训练细节:
unsloth/Llama-3.2-11B-Vision-Instruct-bnb-4bitunsloth/Radiology_minir = 16lora_alpha = 16lora_dropout = 0learning_rate = 2e-4per_device_train_batch_size = 2gradient_accumulation_steps = 4max_steps = 30 (或 num_train_epochs = 1 用于完整运行)optimizer = adamw_8bitfinetune_vision_layers = Falsefinetune_language_layers = Truefinetune_attention_modules = Truefinetune_mlp_modules = True该模型设计为将图像和文本提示作为输入,并生成文本描述。预期的输入格式是一个对话,如下所示:
from unsloth import FastVisionModel
import torch
from transformers import TextStreamer
# 加载模型 (如果从本地加载,请将 "YLX1965/llama3-2-11b-xray-v1" 替换为您的模型路径)
model, tokenizer = FastVisionModel.from_pretrained(
"YLX1965/llama3-2-11b-xray-v1",
load_in_4bit = True, # 对于 16 位加载,设置为 False
)
FastVisionModel.for_inference(model)
# 示例图像和指令 (替换为您的图像路径)
# from datasets import load_dataset
# dataset = load_dataset("unsloth/Radiology_mini", split="train")
# image = dataset[0]["image"]
image = "path/to/your/image.jpg" # 示例
instruction = "你是一位专业的放射科医生。请准确描述您在这张图片中看到的内容。"
messages = [
{"role": "user", "content": [
{"type": "image"},
{"type": "text", "text": instruction}
]}
]
input_text = tokenizer.apply_chat_template(messages, add_generation_prompt = True)
inputs = tokenizer(
image,
input_text,
add_special_tokens = False,
return_tensors = "pt",
).to("cuda")
text_streamer = TextStreamer(tokenizer, skip_prompt = True)
_ = model.generate(**inputs, streamer = text_streamer, max_new_tokens = 128,
use_cache = True, temperature = 1.5, min_p = 0.1)
Base model
meta-llama/Llama-3.2-11B-Vision-Instruct
Install from pip and serve model
# Install vLLM from pip: pip install vllm# Start the vLLM server: vllm serve "YLX1965/llama3-2-11b-xray-v1"# Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "YLX1965/llama3-2-11b-xray-v1", "messages": [ { "role": "user", "content": [ { "type": "text", "text": "Describe this image in one sentence." }, { "type": "image_url", "image_url": { "url": "https://cdn.britannica.com/61/93061-050-99147DCE/Statue-of-Liberty-Island-New-York-Bay.jpg" } } ] } ] }'