Views
No views yet

| File Name | Size | Description | Upload Status |
|---|---|---|---|
.gitattributes | 1.52 kB | Configures LFS tracking for specific model files. | Initial commit |
README.md | 203 Bytes | Minimal details about the uploaded model. | Updated |
added_tokens.json | 408 Bytes | Additional tokens used by the model tokenizer. | Uploaded |
chat_template.json | 1.05 kB | Template for chat-based model input/output. | Uploaded |
config.json | 1.24 kB | Model configuration metadata. | Uploaded |
generation_config.json | 252 Bytes | Configuration for text generation settings. | Uploaded |
merges.txt | 1.82 MB | BPE merge rules for tokenization. | Uploaded |
model.safetensors | 4.42 GB | Serialized model weights in a secure format. | Uploaded (LFS) |
preprocessor_config.json | 596 Bytes | Preprocessing configuration for input data. | Uploaded |
vocab.json | 2.78 MB | Vocabulary file for tokenization. | Uploaded |
1from transformers import Qwen2VLForConditionalGeneration, AutoTokenizer, AutoProcessor
2from qwen_vl_utils import process_vision_info
3
4# default: Load the model on the available device(s)
5model = Qwen2VLForConditionalGeneration.from_pretrained(
6 "prithivMLmods/Qwen2-VL-Math-Prase-2B-Instruct", torch_dtype="auto", device_map="auto"
7)
8
9# We recommend enabling flash_attention_2 for better acceleration and memory saving, especially in multi-image and video scenarios.
10# model = Qwen2VLForConditionalGeneration.from_pretrained(
11# "prithivMLmods/Qwen2-VL-Math-Prase-2B-Instruct",
12# torch_dtype=torch.bfloat16,
13# attn_implementation="flash_attention_2",
14# device_map="auto",
15# )
16
17# default processer
18processor = AutoProcessor.from_pretrained("prithivMLmods/Qwen2-VL-Math-Prase-2B-Instruct")
19
20# The default range for the number of visual tokens per image in the model is 4-16384. You can set min_pixels and max_pixels according to your needs, such as a token count range of 256-1280, to balance speed and memory usage.
21# min_pixels = 256*28*28
22# max_pixels = 1280*28*28
23# processor = AutoProcessor.from_pretrained("Qwen/Qwen2-VL-2B-Instruct", min_pixels=min_pixels, max_pixels=max_pixels)
24
25messages = [
26 {
27 "role": "user",
28 "content": [
29 {
30 "type": "image",
31 "image": "https://qianwen-res.oss-cn-beijing.aliyuncs.com/Qwen-VL/assets/demo.jpeg",
32 },
33 {"type": "text", "text": "Describe this image."},
34 ],
35 }
36]
37
38# Preparation for inference
39text = processor.apply_chat_template(
40 messages, tokenize=False, add_generation_prompt=True
41)
42image_inputs, video_inputs = process_vision_info(messages)
43inputs = processor(
44 text=[text],
45 images=image_inputs,
46 videos=video_inputs,
47 padding=True,
48 return_tensors="pt",
49)
50inputs = inputs.to("cuda")
51
52# Inference: Generation of the output
53generated_ids = model.generate(**inputs, max_new_tokens=128)
54generated_ids_trimmed = [
55 out_ids[len(in_ids) :] for in_ids, out_ids in zip(inputs.input_ids, generated_ids)
56]
57output_text = processor.batch_decode(
58 generated_ids_trimmed, skip_special_tokens=True, clean_up_tokenization_spaces=False
59)
60print(output_text)