Update app.py
Browse files
app.py
CHANGED
@@ -10,15 +10,20 @@ from unsloth import FastVisionModel
|
|
10 |
# Define the model and processor
|
11 |
model_id = "0llheaven/Llama-3.2-11B-Vision-Radiology-mini"
|
12 |
|
|
|
|
|
|
|
13 |
# device = "cuda" if torch.cuda.is_available() else "cpu"
|
14 |
model = AutoModelForImageTextToText.from_pretrained(
|
15 |
model_id,
|
16 |
# load_in_4bit=True,
|
17 |
-
torch_dtype=torch.bfloat16,
|
18 |
-
device_map="auto",
|
19 |
-
)
|
20 |
|
21 |
-
|
|
|
|
|
22 |
|
23 |
processor = AutoProcessor.from_pretrained(model_id)
|
24 |
|
@@ -53,7 +58,7 @@ def generate_description(image: Image.Image, instruction: str):
|
|
53 |
input_text,
|
54 |
add_special_tokens=False,
|
55 |
return_tensors="pt"
|
56 |
-
).to(
|
57 |
|
58 |
# Generate the output from the model
|
59 |
# output = model.generate(**inputs, max_new_tokens=256)
|
|
|
10 |
# Define the model and processor
|
11 |
model_id = "0llheaven/Llama-3.2-11B-Vision-Radiology-mini"
|
12 |
|
13 |
+
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
14 |
+
print(f"Using device: {device}")
|
15 |
+
|
16 |
# device = "cuda" if torch.cuda.is_available() else "cpu"
|
17 |
model = AutoModelForImageTextToText.from_pretrained(
|
18 |
model_id,
|
19 |
# load_in_4bit=True,
|
20 |
+
torch_dtype=torch.float32 if device.type == "cpu" else torch.bfloat16,
|
21 |
+
device_map="auto" if device.type == "cuda" else None,
|
22 |
+
).to(device)
|
23 |
|
24 |
+
if device.type == "cuda":
|
25 |
+
model.gradient_checkpointing_enable()
|
26 |
+
# model.gradient_checkpointing_enable()
|
27 |
|
28 |
processor = AutoProcessor.from_pretrained(model_id)
|
29 |
|
|
|
58 |
input_text,
|
59 |
add_special_tokens=False,
|
60 |
return_tensors="pt"
|
61 |
+
).to(device)
|
62 |
|
63 |
# Generate the output from the model
|
64 |
# output = model.generate(**inputs, max_new_tokens=256)
|