Views
No views yet
1from datasets import load_dataset
2from unsloth import FastVisionModel
3
4model, tokenizer = FastVisionModel.from_pretrained(
5 model_name = "MMoshtaghi/Llama-3.2-11B-Vision-LoRAAdpt-Radiology",
6 load_in_4bit = True,
7)
8FastVisionModel.for_inference(model) # Enable for inference!
9
10dataset = load_dataset("unsloth/Radiology_mini", split = "train")
11image = dataset[0]["image"]
12instruction = "You are an expert radiographer. Describe accurately what you see in this image."
13
14messages = [
15 {"role": "user", "content": [
16 {"type": "image"},
17 {"type": "text", "text": instruction}
18 ]}
19]
20input_text = tokenizer.apply_chat_template(messages, add_generation_prompt = True)
21inputs = tokenizer(
22 image,
23 input_text,
24 add_special_tokens = False,
25 return_tensors = "pt",
26).to("cuda")
27
28from transformers import TextStreamer
29text_streamer = TextStreamer(tokenizer, skip_prompt = True)
30_ = model_inf.generate(**inputs, streamer = text_streamer, max_new_tokens = 128,
31 use_cache = True, temperature = 1.5, min_p = 0.1)