Image-Text-to-Text
Transformers
Safetensors
English
mllama
text-generation-inference
unsloth
conversational
Instructions to use pollitoconpapass/Llama-3.2-11B-Vision-Radiology-mini with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use pollitoconpapass/Llama-3.2-11B-Vision-Radiology-mini with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("image-text-to-text", model="pollitoconpapass/Llama-3.2-11B-Vision-Radiology-mini") 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("pollitoconpapass/Llama-3.2-11B-Vision-Radiology-mini") model = AutoModelForMultimodalLM.from_pretrained("pollitoconpapass/Llama-3.2-11B-Vision-Radiology-mini", device_map="auto") 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]:])) - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use pollitoconpapass/Llama-3.2-11B-Vision-Radiology-mini with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "pollitoconpapass/Llama-3.2-11B-Vision-Radiology-mini" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "pollitoconpapass/Llama-3.2-11B-Vision-Radiology-mini", "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" } } ] } ] }'Use Docker
docker model run hf.co/pollitoconpapass/Llama-3.2-11B-Vision-Radiology-mini
- SGLang
How to use pollitoconpapass/Llama-3.2-11B-Vision-Radiology-mini with SGLang:
Install from pip and serve model
# Install SGLang from pip: pip install sglang # Start the SGLang server: python3 -m sglang.launch_server \ --model-path "pollitoconpapass/Llama-3.2-11B-Vision-Radiology-mini" \ --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": "pollitoconpapass/Llama-3.2-11B-Vision-Radiology-mini", "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" } } ] } ] }'Use Docker images
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 "pollitoconpapass/Llama-3.2-11B-Vision-Radiology-mini" \ --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": "pollitoconpapass/Llama-3.2-11B-Vision-Radiology-mini", "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" } } ] } ] }' - Unsloth Studio
How to use pollitoconpapass/Llama-3.2-11B-Vision-Radiology-mini with Unsloth Studio:
Install Unsloth Studio (macOS, Linux, WSL)
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 pollitoconpapass/Llama-3.2-11B-Vision-Radiology-mini to start chatting
Install Unsloth Studio (Windows)
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 pollitoconpapass/Llama-3.2-11B-Vision-Radiology-mini to start chatting
Using HuggingFace Spaces for Unsloth
# No setup required # Open https://huggingface.co/spaces/unsloth/studio in your browser # Search for pollitoconpapass/Llama-3.2-11B-Vision-Radiology-mini to start chatting
Load model with FastModel
pip install unsloth from unsloth import FastModel model, tokenizer = FastModel.from_pretrained( model_name="pollitoconpapass/Llama-3.2-11B-Vision-Radiology-mini", max_seq_length=2048, ) - Docker Model Runner
How to use pollitoconpapass/Llama-3.2-11B-Vision-Radiology-mini with Docker Model Runner:
docker model run hf.co/pollitoconpapass/Llama-3.2-11B-Vision-Radiology-mini
Added Implementation Script
Browse files
README.md
CHANGED
|
@@ -19,3 +19,79 @@ language:
|
|
| 19 |
This mllama model was trained 2x faster with [Unsloth](https://github.com/unslothai/unsloth) and Huggingface's TRL library.
|
| 20 |
|
| 21 |
[<img src="https://raw.githubusercontent.com/unslothai/unsloth/main/images/unsloth%20made%20with%20love.png" width="200"/>](https://github.com/unslothai/unsloth)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
This mllama model was trained 2x faster with [Unsloth](https://github.com/unslothai/unsloth) and Huggingface's TRL library.
|
| 20 |
|
| 21 |
[<img src="https://raw.githubusercontent.com/unslothai/unsloth/main/images/unsloth%20made%20with%20love.png" width="200"/>](https://github.com/unslothai/unsloth)
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
# Implementation
|
| 25 |
+
```py
|
| 26 |
+
from datasets import load_dataset
|
| 27 |
+
from unsloth import FastVisionModel
|
| 28 |
+
|
| 29 |
+
model, tokenizer = FastVisionModel.from_pretrained(
|
| 30 |
+
# "unsloth/Llama-3.2-11B-Vision-Instruct",
|
| 31 |
+
"pollitoconpapass/Llama-3.2-11B-Vision-Radiology-mini",
|
| 32 |
+
load_in_4bit = True, # Use 4bit to reduce memory use. False for 16bit LoRA.
|
| 33 |
+
use_gradient_checkpointing = "unsloth", # True or "unsloth" for long context
|
| 34 |
+
)
|
| 35 |
+
|
| 36 |
+
model = FastVisionModel.get_peft_model(
|
| 37 |
+
model,
|
| 38 |
+
finetune_vision_layers = True, # False if not finetuning vision layers
|
| 39 |
+
finetune_language_layers = True, # False if not finetuning language layers
|
| 40 |
+
finetune_attention_modules = True, # False if not finetuning attention layers
|
| 41 |
+
finetune_mlp_modules = True, # False if not finetuning MLP layers
|
| 42 |
+
|
| 43 |
+
r = 16, # The larger, the higher the accuracy, but might overfit
|
| 44 |
+
lora_alpha = 16, # Recommended alpha == r at least
|
| 45 |
+
lora_dropout = 0,
|
| 46 |
+
bias = "none",
|
| 47 |
+
random_state = 3407,
|
| 48 |
+
use_rslora = False, # We support rank stabilized LoRA
|
| 49 |
+
loftq_config = None, # And LoftQ
|
| 50 |
+
# target_modules = "all-linear", # Optional now! Can specify a list if needed
|
| 51 |
+
)
|
| 52 |
+
|
| 53 |
+
dataset = load_dataset("unsloth/Radiology_mini", split = "train")
|
| 54 |
+
instruction = "You are an expert radiographer. Describe accurately what you see in this image."
|
| 55 |
+
|
| 56 |
+
def convert_to_conversation(sample):
|
| 57 |
+
conversation = [
|
| 58 |
+
{ "role": "user",
|
| 59 |
+
"content" : [
|
| 60 |
+
{"type" : "text", "text" : instruction},
|
| 61 |
+
{"type" : "image", "image" : sample["image"]} ]
|
| 62 |
+
},
|
| 63 |
+
{ "role" : "assistant",
|
| 64 |
+
"content" : [
|
| 65 |
+
{"type" : "text", "text" : sample["caption"]} ]
|
| 66 |
+
},
|
| 67 |
+
]
|
| 68 |
+
return { "messages" : conversation }
|
| 69 |
+
pass
|
| 70 |
+
|
| 71 |
+
converted_dataset = [convert_to_conversation(sample) for sample in dataset]
|
| 72 |
+
|
| 73 |
+
FastVisionModel.for_inference(model) # Enable for inference!
|
| 74 |
+
|
| 75 |
+
image = dataset[0]["image"]
|
| 76 |
+
instruction = "You are an expert radiographer. Describe accurately what you see in this image."
|
| 77 |
+
|
| 78 |
+
messages = [
|
| 79 |
+
{"role": "user", "content": [
|
| 80 |
+
{"type": "image"},
|
| 81 |
+
{"type": "text", "text": instruction}
|
| 82 |
+
]}
|
| 83 |
+
]
|
| 84 |
+
input_text = tokenizer.apply_chat_template(messages, add_generation_prompt = True)
|
| 85 |
+
inputs = tokenizer(
|
| 86 |
+
image,
|
| 87 |
+
input_text,
|
| 88 |
+
add_special_tokens = False,
|
| 89 |
+
return_tensors = "pt",
|
| 90 |
+
).to("cuda")
|
| 91 |
+
|
| 92 |
+
from transformers import TextStreamer
|
| 93 |
+
text_streamer = TextStreamer(tokenizer, skip_prompt = True)
|
| 94 |
+
_ = model.generate(**inputs, streamer = text_streamer, max_new_tokens = 500,
|
| 95 |
+
use_cache = True, temperature = 1.5, min_p = 0.1)
|
| 96 |
+
|
| 97 |
+
```
|