yyyang commited on
Commit
0b46483
·
verified ·
1 Parent(s): 9e88bcf

awq model upload

Browse files
.gitattributes CHANGED
@@ -33,3 +33,5 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
 
 
 
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
36
+ test_screenshots/amazon.png filter=lfs diff=lfs merge=lfs -text
37
+ tokenizer.json filter=lfs diff=lfs merge=lfs -text
added_tokens.json ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "<|box_end|>": 151649,
3
+ "<|box_start|>": 151648,
4
+ "<|endoftext|>": 151643,
5
+ "<|im_end|>": 151645,
6
+ "<|im_start|>": 151644,
7
+ "<|image_pad|>": 151655,
8
+ "<|object_ref_end|>": 151647,
9
+ "<|object_ref_start|>": 151646,
10
+ "<|quad_end|>": 151651,
11
+ "<|quad_start|>": 151650,
12
+ "<|video_pad|>": 151656,
13
+ "<|vision_end|>": 151653,
14
+ "<|vision_pad|>": 151654,
15
+ "<|vision_start|>": 151652
16
+ }
chat_template.json ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ {
2
+ "chat_template": "{% set image_count = namespace(value=0) %}{% set video_count = namespace(value=0) %}{% for message in messages %}{% if loop.first and message['role'] != 'system' %}<|im_start|>system\nYou are a helpful assistant.<|im_end|>\n{% endif %}<|im_start|>{{ message['role'] }}\n{% if message['content'] is string %}{{ message['content'] }}<|im_end|>\n{% else %}{% for content in message['content'] %}{% if content['type'] == 'image' or 'image' in content or 'image_url' in content %}{% set image_count.value = image_count.value + 1 %}{% if add_vision_id %}Picture {{ image_count.value }}: {% endif %}<|vision_start|><|image_pad|><|vision_end|>{% elif content['type'] == 'video' or 'video' in content %}{% set video_count.value = video_count.value + 1 %}{% if add_vision_id %}Video {{ video_count.value }}: {% endif %}<|vision_start|><|video_pad|><|vision_end|>{% elif 'text' in content %}{{ content['text'] }}{% endif %}{% endfor %}<|im_end|>\n{% endif %}{% endfor %}{% if add_generation_prompt %}<|im_start|>assistant\n{% endif %}"
3
+ }
config.json ADDED
@@ -0,0 +1,59 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "_name_or_path": "/users/difei/mingyu/showui_local/showui-2b_safetensors",
3
+ "architectures": [
4
+ "Qwen2VLForConditionalGeneration"
5
+ ],
6
+ "attention_dropout": 0.0,
7
+ "bos_token_id": 151643,
8
+ "eos_token_id": 151645,
9
+ "hidden_act": "silu",
10
+ "hidden_size": 1536,
11
+ "image_token_id": 151655,
12
+ "initializer_range": 0.02,
13
+ "intermediate_size": 8960,
14
+ "max_position_embeddings": 32768,
15
+ "max_window_layers": 28,
16
+ "model_type": "qwen2_vl",
17
+ "num_attention_heads": 12,
18
+ "num_hidden_layers": 28,
19
+ "num_key_value_heads": 2,
20
+ "quantization_config": {
21
+ "bits": 4,
22
+ "group_size": 128,
23
+ "modules_to_not_convert": [
24
+ "visual"
25
+ ],
26
+ "quant_method": "awq",
27
+ "version": "gemm",
28
+ "zero_point": true
29
+ },
30
+ "rms_norm_eps": 1e-06,
31
+ "rope_scaling": {
32
+ "mrope_section": [
33
+ 16,
34
+ 24,
35
+ 24
36
+ ],
37
+ "rope_type": "default",
38
+ "type": "default"
39
+ },
40
+ "rope_theta": 1000000.0,
41
+ "sliding_window": 32768,
42
+ "tie_word_embeddings": true,
43
+ "tokenizer_model_max_length": 4096,
44
+ "torch_dtype": "float16",
45
+ "transformers_version": "4.47.0",
46
+ "use_cache": true,
47
+ "use_sliding_window": false,
48
+ "video_token_id": 151656,
49
+ "vision_config": {
50
+ "hidden_size": 1536,
51
+ "in_chans": 3,
52
+ "model_type": "qwen2_vl",
53
+ "spatial_patch_size": 14
54
+ },
55
+ "vision_end_token_id": 151653,
56
+ "vision_start_token_id": 151652,
57
+ "vision_token_id": 151654,
58
+ "vocab_size": 151936
59
+ }
generation_config.json ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "_attn_implementation": "eager",
3
+ "bos_token_id": 151643,
4
+ "do_sample": true,
5
+ "eos_token_id": [
6
+ 151645,
7
+ 151643
8
+ ],
9
+ "pad_token_id": 151643,
10
+ "temperature": 0.01,
11
+ "top_k": 1,
12
+ "top_p": 0.001,
13
+ "transformers_version": "4.47.0"
14
+ }
infer.py ADDED
@@ -0,0 +1,162 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import argparse
2
+ import ast
3
+ import torch
4
+ from PIL import Image
5
+ import time
6
+ from transformers import Qwen2VLForConditionalGeneration, AutoProcessor
7
+ from PIL import Image, ImageDraw
8
+
9
+ # Parse command-line arguments
10
+ parser = argparse.ArgumentParser(description="Qwen-VL Inference")
11
+ parser.add_argument("--image_path", type=str, required=False, default="./test_screenshots/amazon.png", help="Path to the input image")
12
+ parser.add_argument("--query", type=str, required=False, default="Click on the 'Chairs'.", help="Text query or instruction")
13
+ parser.add_argument("--model_dir", type=str, default="./showui-2b-awq-4bit", help="Path to the local ShowUI model directory")
14
+ args = parser.parse_args()
15
+
16
+ DEVICE = "cuda:0"
17
+
18
+ # Constants for the processor (adjust as per your model requirements)
19
+ MIN_PIXELS = 256 * 28 * 28
20
+ # MAX_PIXELS = 1024 * 28 * 28
21
+ # MAX_PIXELS = 1280 * 28 * 28
22
+ MAX_PIXELS = 1344 * 28 * 28
23
+
24
+
25
+ def draw_point_on_image(image_path, position, output_path="output_image.png", radius=2, color="red"):
26
+ image = Image.open(image_path).convert("RGB")
27
+ draw = ImageDraw.Draw(image)
28
+ width, height = image.size
29
+ x = int(position[0] * width)
30
+ y = int(position[1] * height)
31
+ draw.ellipse([(x - radius, y - radius), (x + radius, y + radius)], fill=color, outline=color)
32
+ image.save(output_path)
33
+ # print(f"Point drawn at ({x}, {y}) and saved to {output_path}")
34
+
35
+ # Load model and processor
36
+ model = Qwen2VLForConditionalGeneration.from_pretrained(
37
+ args.model_dir,
38
+ torch_dtype=torch.float16,
39
+ # torch_dtype=torch.bfloat16,
40
+ device_map="cpu",
41
+ )
42
+
43
+ print("Model dtype:", model.dtype)
44
+ # print("Model weights dtype:", model.model.layers[0].self_attn.q_proj.weight)
45
+
46
+ processor = AutoProcessor.from_pretrained("Qwen/Qwen2-VL-2B-Instruct", min_pixels=MIN_PIXELS, max_pixels=MAX_PIXELS)
47
+
48
+ # Print CUDA memory usage after model load
49
+ torch.cuda.empty_cache()
50
+
51
+ _NAV_SYSTEM = """You are an assistant trained to navigate the {_APP} screen.
52
+ Given a task instruction, a screen observation, and an action history sequence,
53
+ output the next action and wait for the next observation.
54
+ Here is the action space:
55
+ {_ACTION_SPACE}
56
+ """
57
+
58
+ _ACTION_MAP = """
59
+ 1. CLICK: Click on an element, value is not applicable and the position [x,y] is required.
60
+ 2. INPUT: Type a string into an element, value is a string to type and the position [x,y] is required.
61
+ 3. HOVER: Hover on an element, value is not applicable and the position [x,y] is required.
62
+ 4. ENTER: Enter operation, value and position are not applicable.
63
+ 5. SCROLL: Scroll the screen, value is the direction to scroll and the position is not applicable.
64
+ 6. ESC: ESCAPE operation, value and position are not applicable.
65
+ 7. PRESS: Long click on an element, value is not applicable and the position [x,y] is required.
66
+ """
67
+
68
+ _SYSTEM = _NAV_SYSTEM.format(
69
+ _APP="web",
70
+ _ACTION_SPACE=_ACTION_MAP
71
+ )
72
+
73
+ if args.query:
74
+ _QUERY = args.query
75
+ else:
76
+ _QUERY = "Click on the 'Chairs'."
77
+
78
+ # Construct the input message
79
+ messages = [
80
+ {
81
+ "role": "user",
82
+ "content": [
83
+ {"type": "text", "text": _SYSTEM},
84
+ {"type": "image", "image": args.image_path, "min_pixels": MIN_PIXELS, "max_pixels": MAX_PIXELS},
85
+ {"type": "text", "text": _QUERY}
86
+ ],
87
+ }
88
+ ]
89
+
90
+ # Process the message through the processor
91
+ text = processor.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
92
+
93
+ # The processor automatically handles image loading when `images` parameter is used
94
+ image = Image.open(args.image_path).convert("RGB")
95
+ inputs = processor(
96
+ text=[text],
97
+ images=[image],
98
+ padding=True,
99
+ return_tensors="pt"
100
+ )
101
+
102
+ # Move inputs and model to GPU
103
+ model = model.to(DEVICE)
104
+ inputs = inputs.to(DEVICE)
105
+
106
+ # print("Model dtype after to(DEVICE):", model.model.layers[0].self_attn.q_proj.weight)
107
+ print(f"Max CUDA memory after model load: {torch.cuda.max_memory_allocated(device=DEVICE)/1024**2:.2f} MB")
108
+
109
+ # Reset memory stats before inference
110
+ torch.cuda.reset_peak_memory_stats(device=DEVICE)
111
+
112
+ N_RUNS = 10
113
+ times = []
114
+
115
+ model.eval()
116
+ with torch.no_grad():
117
+
118
+ for i in range(N_RUNS):
119
+ start_time = time.time()
120
+
121
+ generated_ids = model.generate(**inputs, max_new_tokens=128)
122
+
123
+ # Extract the portion of generated_ids corresponding to the new generation
124
+ generated_ids_trimmed = [out_ids[len(in_ids):] for in_ids, out_ids in zip(inputs.input_ids, generated_ids)]
125
+ output_text = processor.batch_decode(
126
+ generated_ids_trimmed, skip_special_tokens=True, clean_up_tokenization_spaces=False
127
+ )[0]
128
+
129
+ # Convert output string to Python object if it's a coordinate
130
+ try:
131
+ result = ast.literal_eval(output_text)
132
+ except:
133
+ result = output_text
134
+
135
+ end_time = time.time()
136
+ times.append(end_time - start_time)
137
+ print(f"Run {i+1}/{N_RUNS} - Time: {end_time - start_time:.4f} s, Output: {result}")
138
+
139
+ # output_str = "{'action': 'CLICK', 'value': None, 'position': [0.28, 0.29]}"
140
+ # parsed_output = ast.literal_eval(result)
141
+ if result['action'].upper() == 'CLICK':
142
+ x, y = result['position'][0], result['position'][1]
143
+ draw_point_on_image(args.image_path, [x, y], output_path="./output_image.png")
144
+
145
+
146
+
147
+ avg_time = sum(times) / len(times)
148
+ print(f"Average per inference time: {avg_time:.4f} seconds")
149
+
150
+ # Print CUDA memory usage after inference
151
+ print(f"Max CUDA memory after inference: {torch.cuda.max_memory_allocated(device=DEVICE)/1024**2:.2f} MB")
152
+
153
+ # Print image size information
154
+ print(f"Input image size: {Image.open(args.image_path).size}")
155
+
156
+
157
+
158
+
159
+
160
+
161
+
162
+
merges.txt ADDED
The diff for this file is too large to render. See raw diff
 
model.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:31600e0be35beae362bc1cb3333486bbff0ba645685d8e7c87ede080093b7b15
3
+ size 2478389712
preprocessor_config.json ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "do_convert_rgb": true,
3
+ "do_normalize": true,
4
+ "do_rescale": true,
5
+ "do_resize": true,
6
+ "image_mean": [
7
+ 0.48145466,
8
+ 0.4578275,
9
+ 0.40821073
10
+ ],
11
+ "image_processor_type": "Qwen2VLImageProcessor",
12
+ "image_std": [
13
+ 0.26862954,
14
+ 0.26130258,
15
+ 0.27577711
16
+ ],
17
+ "max_pixels": 1053696,
18
+ "merge_size": 2,
19
+ "min_pixels": 200704,
20
+ "patch_size": 14,
21
+ "processor_class": "Qwen2VLProcessor",
22
+ "resample": 3,
23
+ "rescale_factor": 0.00392156862745098,
24
+ "size": {
25
+ "max_pixels": 12845056,
26
+ "min_pixels": 3136
27
+ },
28
+ "temporal_patch_size": 2
29
+ }
special_tokens_map.json ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "additional_special_tokens": [
3
+ "<|im_start|>",
4
+ "<|im_end|>",
5
+ "<|object_ref_start|>",
6
+ "<|object_ref_end|>",
7
+ "<|box_start|>",
8
+ "<|box_end|>",
9
+ "<|quad_start|>",
10
+ "<|quad_end|>",
11
+ "<|vision_start|>",
12
+ "<|vision_end|>",
13
+ "<|vision_pad|>",
14
+ "<|image_pad|>",
15
+ "<|video_pad|>"
16
+ ],
17
+ "eos_token": {
18
+ "content": "<|im_end|>",
19
+ "lstrip": false,
20
+ "normalized": false,
21
+ "rstrip": false,
22
+ "single_word": false
23
+ },
24
+ "pad_token": {
25
+ "content": "<|endoftext|>",
26
+ "lstrip": false,
27
+ "normalized": false,
28
+ "rstrip": false,
29
+ "single_word": false
30
+ }
31
+ }
test_screenshots/amazon.png ADDED

Git LFS Details

  • SHA256: 501573053a82438a2439377c0bf3f2d17ac8b34a1ac055468c83d8f16e81cabe
  • Pointer size: 132 Bytes
  • Size of remote file: 2.86 MB
tokenizer.json ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:88a3a6fcb80132f76da8aa40cdc3fccd7e5d8468ef15421f5b0c2715e85217d2
3
+ size 11420538
tokenizer_config.json ADDED
@@ -0,0 +1,147 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "add_prefix_space": false,
3
+ "added_tokens_decoder": {
4
+ "151643": {
5
+ "content": "<|endoftext|>",
6
+ "lstrip": false,
7
+ "normalized": false,
8
+ "rstrip": false,
9
+ "single_word": false,
10
+ "special": true
11
+ },
12
+ "151644": {
13
+ "content": "<|im_start|>",
14
+ "lstrip": false,
15
+ "normalized": false,
16
+ "rstrip": false,
17
+ "single_word": false,
18
+ "special": true
19
+ },
20
+ "151645": {
21
+ "content": "<|im_end|>",
22
+ "lstrip": false,
23
+ "normalized": false,
24
+ "rstrip": false,
25
+ "single_word": false,
26
+ "special": true
27
+ },
28
+ "151646": {
29
+ "content": "<|object_ref_start|>",
30
+ "lstrip": false,
31
+ "normalized": false,
32
+ "rstrip": false,
33
+ "single_word": false,
34
+ "special": true
35
+ },
36
+ "151647": {
37
+ "content": "<|object_ref_end|>",
38
+ "lstrip": false,
39
+ "normalized": false,
40
+ "rstrip": false,
41
+ "single_word": false,
42
+ "special": true
43
+ },
44
+ "151648": {
45
+ "content": "<|box_start|>",
46
+ "lstrip": false,
47
+ "normalized": false,
48
+ "rstrip": false,
49
+ "single_word": false,
50
+ "special": true
51
+ },
52
+ "151649": {
53
+ "content": "<|box_end|>",
54
+ "lstrip": false,
55
+ "normalized": false,
56
+ "rstrip": false,
57
+ "single_word": false,
58
+ "special": true
59
+ },
60
+ "151650": {
61
+ "content": "<|quad_start|>",
62
+ "lstrip": false,
63
+ "normalized": false,
64
+ "rstrip": false,
65
+ "single_word": false,
66
+ "special": true
67
+ },
68
+ "151651": {
69
+ "content": "<|quad_end|>",
70
+ "lstrip": false,
71
+ "normalized": false,
72
+ "rstrip": false,
73
+ "single_word": false,
74
+ "special": true
75
+ },
76
+ "151652": {
77
+ "content": "<|vision_start|>",
78
+ "lstrip": false,
79
+ "normalized": false,
80
+ "rstrip": false,
81
+ "single_word": false,
82
+ "special": true
83
+ },
84
+ "151653": {
85
+ "content": "<|vision_end|>",
86
+ "lstrip": false,
87
+ "normalized": false,
88
+ "rstrip": false,
89
+ "single_word": false,
90
+ "special": true
91
+ },
92
+ "151654": {
93
+ "content": "<|vision_pad|>",
94
+ "lstrip": false,
95
+ "normalized": false,
96
+ "rstrip": false,
97
+ "single_word": false,
98
+ "special": true
99
+ },
100
+ "151655": {
101
+ "content": "<|image_pad|>",
102
+ "lstrip": false,
103
+ "normalized": false,
104
+ "rstrip": false,
105
+ "single_word": false,
106
+ "special": true
107
+ },
108
+ "151656": {
109
+ "content": "<|video_pad|>",
110
+ "lstrip": false,
111
+ "normalized": false,
112
+ "rstrip": false,
113
+ "single_word": false,
114
+ "special": true
115
+ }
116
+ },
117
+ "additional_special_tokens": [
118
+ "<|im_start|>",
119
+ "<|im_end|>",
120
+ "<|object_ref_start|>",
121
+ "<|object_ref_end|>",
122
+ "<|box_start|>",
123
+ "<|box_end|>",
124
+ "<|quad_start|>",
125
+ "<|quad_end|>",
126
+ "<|vision_start|>",
127
+ "<|vision_end|>",
128
+ "<|vision_pad|>",
129
+ "<|image_pad|>",
130
+ "<|video_pad|>"
131
+ ],
132
+ "bos_token": null,
133
+ "chat_template": "{% set image_count = namespace(value=0) %}{% set video_count = namespace(value=0) %}{% for message in messages %}{% if loop.first and message['role'] != 'system' %}<|im_start|>system\nYou are a helpful assistant.<|im_end|>\n{% endif %}<|im_start|>{{ message['role'] }}\n{% if message['content'] is string %}{{ message['content'] }}<|im_end|>\n{% else %}{% for content in message['content'] %}{% if content['type'] == 'image' or 'image' in content or 'image_url' in content %}{% set image_count.value = image_count.value + 1 %}{% if add_vision_id %}Picture {{ image_count.value }}: {% endif %}<|vision_start|><|image_pad|><|vision_end|>{% elif content['type'] == 'video' or 'video' in content %}{% set video_count.value = video_count.value + 1 %}{% if add_vision_id %}Video {{ video_count.value }}: {% endif %}<|vision_start|><|video_pad|><|vision_end|>{% elif 'text' in content %}{{ content['text'] }}{% endif %}{% endfor %}<|im_end|>\n{% endif %}{% endfor %}{% if add_generation_prompt %}<|im_start|>assistant\n{% endif %}",
134
+ "clean_up_tokenization_spaces": false,
135
+ "eos_token": "<|im_end|>",
136
+ "errors": "replace",
137
+ "extra_special_tokens": {},
138
+ "max_pixels": 1053696,
139
+ "min_pixels": 200704,
140
+ "model_max_length": 32768,
141
+ "pad_token": "<|endoftext|>",
142
+ "padding_side": "left",
143
+ "processor_class": "Qwen2VLProcessor",
144
+ "split_special_tokens": false,
145
+ "tokenizer_class": "Qwen2Tokenizer",
146
+ "unk_token": null
147
+ }
vocab.json ADDED
The diff for this file is too large to render. See raw diff