yogkul2000 commited on
Commit
2b78a36
·
verified ·
1 Parent(s): 1cf47ba

Create README.md

Browse files
Files changed (1) hide show
  1. README.md +46 -0
README.md ADDED
@@ -0,0 +1,46 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ```python
2
+ from transformers import Qwen2_5_VLForConditionalGeneration, AutoProcessor
3
+ from qwen_vl_utils import process_vision_info
4
+
5
+ model = Qwen2_5_VLForConditionalGeneration.from_pretrained(
6
+ "/path/to/model",
7
+ torch_dtype="auto",
8
+ device_map="auto"
9
+ )
10
+ processor = AutoProcessor.from_pretrained("/path/to/model")
11
+
12
+ messages = [
13
+ {
14
+ "role": "user",
15
+ "content": [
16
+ {
17
+ "type": "video",
18
+ "video": "/path/to/video.mp4",
19
+ },
20
+ {"type": "text", "text": "Describe this video in detail."},
21
+ ],
22
+ }
23
+ ]
24
+
25
+ text = processor.apply_chat_template(
26
+ messages, tokenize=False, add_generation_prompt=True
27
+ )
28
+ image_inputs, video_inputs, video_kwargs = process_vision_info(messages, return_video_kwargs=True)
29
+ inputs = processor(
30
+ text=[text],
31
+ images=image_inputs,
32
+ videos=video_inputs,
33
+ padding=True,
34
+ return_tensors="pt",
35
+ **video_kwargs,
36
+ )
37
+ inputs = inputs.to("cuda")
38
+
39
+ generated_ids = model.generate(**inputs, max_new_tokens=512)
40
+ generated_ids_trimmed = [
41
+ out_ids[len(in_ids) :] for in_ids, out_ids in zip(inputs.input_ids, generated_ids)
42
+ ]
43
+ output_text = processor.batch_decode(
44
+ generated_ids_trimmed, skip_special_tokens=True, clean_up_tokenization_spaces=False
45
+ )
46
+ print(output_text[0])```