Update README.md
Browse files18 unmodified lines192021222324252627282930313233343536373839404142434445464720 unmodified lines68697071727318 unmodified lines## Inference```pythonfrom transformers import Qwen2_5_VLForConditionalGeneration, AutoTokenizer, AutoProcessorfrom qwen_vl_utils import process_vision_infomodel_path = "infly/Infinity-Parser-7B"prompt = "Please transform the document’s contents into Markdown format."# default: Load the model on the available device(s)model = Qwen2_5_VLForConditionalGeneration.from_pretrained(model_path, torch_dtype="auto", device_map="auto")# We recommend enabling flash_attention_2 for better acceleration and memory saving, especially in multi-image and video scenarios.# model = Qwen2_5_VLForConditionalGeneration.from_pretrained(# model_path,# torch_dtype=torch.bfloat16,# attn_implementation="flash_attention_2",# device_map="auto",# )min_pixels = 256 * 28 * 28 # 448 * 448max_pixels = 2304 * 28 * 28 # 1344 * 1344processor = AutoProcessor.from_pretrained(model_path, min_pixels=min_pixels, max_pixels=max_pixels)messages = [{"role": "user",20 unmodified lines)inputs = inputs.to("cuda")generated_ids = model.generate(**inputs, max_new_tokens=4096)generated_ids_trimmed = [out_ids[len(in_ids) :] for in_ids, out_ids in zip(inputs.input_ids, generated_ids)18 unmodified lines19202122232425262728293031323334353637383940414243444546474849505152535420 unmodified lines7576777879808118 unmodified lines## Inference```pythonimport torchfrom transformers import Qwen2_5_VLForConditionalGeneration, AutoTokenizer, AutoProcessorfrom qwen_vl_utils import process_vision_infomodel_path = "infly/Infinity-Parser-7B"prompt = "Please transform the document’s contents into Markdown format."print(f"Loading model and processor...")# Default: Load the model on the available device(s)# model = Qwen2_5_VLForConditionalGeneration.from_pretrained(# model_path, torch_dtype="auto", device_map="auto"# )# We recommend enabling flash_attention_2 for better acceleration and memory saving, especially in multi-image and video scenarios.model = Qwen2_5_VLForConditionalGeneration.from_pretrained(model_path,torch_dtype=torch.bfloat16,attn_implementation="flash_attention_2",device_map="auto",)# Default processor# processor = AutoProcessor.from_pretrained(model_path)# Recommended processormin_pixels = 256 * 28 * 28 # 448 * 448max_pixels = 2304 * 28 * 28 # 1344 * 1344processor = AutoProcessor.from_pretrained(model_path, min_pixels=min_pixels, max_pixels=max_pixels)print(f"Preparing messages for inference...")messages = [{"role": "user",20 unmodified lines)inputs = inputs.to("cuda")print(f"Generating results...")generated_ids = model.generate(**inputs, max_new_tokens=4096)generated_ids_trimmed = [out_ids[len(in_ids) :] for in_ids, out_ids in zip(inputs.input_ids, generated_ids)
README.md+17-9