UnboundLocalError: cannot access local variable 'rows' where it is not associated with a value

#90
by JoAmps42i - opened

I am trying to use the model but i get this error
522 elif to_order == "col32":
523 # blocks of 32 columns (padded)
524 cols = 32 * ((cols + 31) // 32)
--> 525 return init_func((rows, cols), dtype=dtype, device=device), state
526 elif to_order == "col_turing":
527 # blocks of 32 columns and 8 rows
528 cols = 32 * ((cols + 31) // 32)

UnboundLocalError: cannot access local variable 'rows' where it is not associated with a value

i have tried various ways, quantized, not quantized etc, stil same error, this is the code, i have also tried the commended part out

import requests
import torch
from PIL import Image
from transformers import AutoProcessor, AutoModelForImageTextToText
from transformers import MllamaForConditionalGeneration, AutoProcessor
from transformers import BitsAndBytesConfig

quantization_config = BitsAndBytesConfig(load_in_8bit=True,
llm_int8_threshold=200.0,llm_int8_enable_fp32_cpu_offload=True)

model_id = "meta-llama/Llama-3.2-11B-Vision-Instruct"
model = AutoModelForImageTextToText.from_pretrained(model_id, quantization_config=quantization_config,torch_dtype=torch.bfloat16, device_map="cuda")
#model = MllamaForConditionalGeneration.from_pretrained(

model_id,

torch_dtype=torch.bfloat16,

device_map="auto",

quantization_config=quantization_config

#)
processor = AutoProcessor.from_pretrained(model_id)

url = "https://huggingface.co./datasets/huggingface/documentation-images/resolve/0052a70beed5bf71b92610a43a52df6d286cd5f3/diffusers/rabbit.jpg"
image = Image.open(requests.get(url, stream=True).raw)

messages = [
{"role": "user", "content": [
{"type": "image"},
{"type": "text", "text": "If I had to write a haiku for this one, it would be: "}
]}
]
input_text = processor.apply_chat_template(messages, add_generation_prompt=True)
inputs = processor(
image,
input_text,
add_special_tokens=False,
return_tensors="pt"
).to(model.device)

output = model.generate(**inputs, max_new_tokens=30)
print(processor.decode(output[0]))

Sign up or log in to comment