import os os.environ.setdefault("CUBLAS_WORKSPACE_CONFIG", ":4096:8") import torchfrom PIL import Imagefrom transformers import AutoModelForCausalLM, AutoProcessor model_id = "tieubaoca/PaddleOCR-VL-1.6-Vietnamese-Merged"processor = AutoProcessor.from_pretrained( model_id, trust_remote_code=True, use_fast=False,)model = AutoModelForCausalLM.from_pretrained( model_id, trust_remote_code=True, torch_dtype=torch.bfloat16, attn_implementation="eager",).to("cuda").eval() messages = [ { "role": "user", "content": [ {"type": "image", "image": "document.png"}, {"type": "text", "text": "OCR:"}, ], }]prompt = processor.apply_chat_template( messages, tokenize=False, add_generation_prompt=True,)with Image.open("document.png") as source: image = source.convert("RGB").copy()inputs = processor(text=[prompt], images=[image], return_tensors="pt")inputs = {name: value.to("cuda") for name, value in inputs.items()}prompt_length = inputs["input_ids"].shape[1] with torch.inference_mode(): generated_ids = model.generate( **inputs, do_sample=False, num_beams=1, max_new_tokens=256, use_cache=True, )text = processor.batch_decode( generated_ids[:, prompt_length:], skip_special_tokens=True, clean_up_tokenization_spaces=False,)[0].strip()print(text)