travis-xia commited on
Commit
e358a10
·
verified ·
1 Parent(s): 07aec7c

Upload folder using huggingface_hub

Browse files
.ipynb_checkpoints/mm_utils-checkpoint.py ADDED
@@ -0,0 +1,855 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from PIL import Image
2
+ from io import BytesIO
3
+ import base64
4
+ import math
5
+ import ast
6
+ import re
7
+ import torch
8
+ from transformers import StoppingCriteria
9
+ from .constants import IMAGE_TOKEN_INDEX
10
+ import random
11
+ import os
12
+ import io
13
+ import av
14
+ import cv2
15
+ import imageio
16
+ from decord import VideoReader
17
+ import numpy as np
18
+ from torchvision.transforms.functional import pil_to_tensor
19
+
20
+
21
+ ######################## load video ########################
22
+
23
+ def get_index(num_frames, num_segments):
24
+ seg_size = float(num_frames - 1) / num_segments
25
+ start = int(seg_size / 2)
26
+ offsets = np.array([
27
+ start + int(np.round(seg_size * idx)) for idx in range(num_segments)
28
+ ])
29
+ return offsets
30
+
31
+
32
+ def pts_to_secs(pts: int, time_base: float, start_pts: int) -> float:
33
+ """
34
+ Converts a present time with the given time base and start_pts offset to seconds.
35
+
36
+ Returns:
37
+ time_in_seconds (float): The corresponding time in seconds.
38
+
39
+ https://github.com/facebookresearch/pytorchvideo/blob/main/pytorchvideo/data/utils.py#L54-L64
40
+ """
41
+ if pts == math.inf:
42
+ return math.inf
43
+
44
+ return int(pts - start_pts) * time_base
45
+
46
+
47
+ def get_pyav_video_duration(video_reader):
48
+ video_stream = video_reader.streams.video[0]
49
+ video_duration = pts_to_secs(
50
+ video_stream.duration,
51
+ video_stream.time_base,
52
+ video_stream.start_time
53
+ )
54
+ return float(video_duration)
55
+
56
+
57
+
58
+ def get_frame_indices(num_frames, vlen, sample='middle', fix_start=None, input_fps=1, min_num_frames=1, max_num_frames=-1, local_num_frames=8):
59
+
60
+ if min_num_frames > vlen:
61
+ if sample == 'dynamic_fps1':
62
+ min_num_frames = (vlen // local_num_frames) * local_num_frames
63
+ else:
64
+ min_num_frames = vlen
65
+
66
+
67
+ if sample == 'dynamic_fps1':
68
+
69
+ duration = float(vlen) / input_fps
70
+ num_segments = int(duration // local_num_frames)
71
+ if num_segments == 0:
72
+ num_frames = local_num_frames
73
+ else:
74
+ num_frames = local_num_frames * num_segments
75
+
76
+ if max_num_frames > 0:
77
+ num_frames = min(num_frames, max_num_frames)
78
+ sample = "middle" # NOTE
79
+
80
+ # logger.info(f"? is OK (img), duation={duration} frames={num_frames}!!!!")
81
+
82
+ num_frames = max(min_num_frames, num_frames)
83
+
84
+ # print(f"\033[0;31m vlen={vlen}, input_fps={input_fps} num_frames={num_frames} \033[0m")
85
+
86
+ if sample in ["rand", "middle"]: # uniform sampling
87
+ acc_samples = min(num_frames, vlen)
88
+ # split the video into `acc_samples` intervals, and sample from each interval.
89
+ intervals = np.linspace(start=0, stop=vlen, num=acc_samples + 1).astype(int)
90
+ ranges = []
91
+ for idx, interv in enumerate(intervals[:-1]):
92
+ ranges.append((interv, intervals[idx + 1] - 1))
93
+ if sample == 'rand':
94
+ try:
95
+ frame_indices = [random.choice(range(x[0], x[1])) for x in ranges]
96
+ except:
97
+ frame_indices = np.random.permutation(vlen)[:acc_samples]
98
+ frame_indices.sort()
99
+ frame_indices = list(frame_indices)
100
+ elif fix_start is not None:
101
+ frame_indices = [x[0] + fix_start for x in ranges]
102
+ elif sample == 'middle':
103
+ frame_indices = [(x[0] + x[1]) // 2 for x in ranges]
104
+ else:
105
+ raise NotImplementedError
106
+
107
+ if len(frame_indices) < num_frames: # padded with last frame
108
+ padded_frame_indices = [frame_indices[-1]] * num_frames
109
+ padded_frame_indices[:len(frame_indices)] = frame_indices
110
+ frame_indices = padded_frame_indices
111
+ elif "fps" in sample: # fps0.5, sequentially sample frames at 0.5 fps
112
+ output_fps = float(sample[3:])
113
+ duration = float(vlen) / input_fps
114
+ delta = 1 / output_fps # gap between frames, this is also the clip length each frame represents
115
+ frame_seconds = np.arange(0 + delta / 2, duration + delta / 2, delta)
116
+ frame_indices = np.around(frame_seconds * input_fps).astype(int)
117
+ frame_indices = [e for e in frame_indices if e < vlen]
118
+ if max_num_frames > 0 and len(frame_indices) > max_num_frames:
119
+ frame_indices = frame_indices[:max_num_frames]
120
+ # frame_indices = np.linspace(0 + delta / 2, duration + delta / 2, endpoint=False, num=max_num_frames)
121
+ else:
122
+ raise ValueError(f"Not support sample type: {sample}")
123
+
124
+
125
+ return frame_indices
126
+
127
+
128
+ def read_frames_av(video_path, num_frames, sample='rand', client=None, fix_start=None, min_num_frames=1, max_num_frames=-1, clip=None, local_num_frames=8):
129
+ if clip is not None:
130
+ raise NotImplementedError("av don't support clip!!!")
131
+ if 's3://' in video_path:
132
+ video_bytes = client.get(video_path)
133
+ byteio = io.BytesIO(video_bytes)
134
+ byteio.seek(0)
135
+ reader = av.open(byteio)
136
+ else:
137
+ byteio = None
138
+ reader = av.open(video_path)
139
+ frames = [f.to_rgb().to_ndarray() for f in reader.decode(video=0)]
140
+ vlen = len(frames)
141
+ duration = get_pyav_video_duration(reader)
142
+ fps = vlen / float(duration)
143
+ frame_indices = get_frame_indices(
144
+ num_frames, vlen, sample=sample, fix_start=fix_start,
145
+ input_fps=fps, min_num_frames=min_num_frames, max_num_frames=max_num_frames, local_num_frames=local_num_frames
146
+ )
147
+ frames = np.stack([frames[idx] for idx in frame_indices]) # (T, H, W, C), torch.uint8
148
+ # frames = frames.permute(0, 3, 1, 2) # (T, C, H, W), torch.uint8
149
+ if byteio != None:
150
+ byteio.close()
151
+
152
+ reader.close()
153
+
154
+ return frames, frame_indices, float(fps), duration
155
+
156
+
157
+ def read_frames_gif(
158
+ video_path, num_frames, sample='rand', fix_start=None,
159
+ min_num_frames=1, max_num_frames=-1, client=None, clip=None, local_num_frames=8
160
+ ):
161
+ if clip is not None:
162
+ raise NotImplementedError("Gif don't support clip!!!")
163
+ if 's3://' in video_path:
164
+ video_bytes = client.get(video_path)
165
+ byteio = io.BytesIO(video_bytes)
166
+ gif = imageio.get_reader(byteio)
167
+ else:
168
+ byteio = None
169
+ gif = imageio.get_reader(video_path)
170
+ vlen = len(gif)
171
+ fps = 1.
172
+ duration = vlen / fps
173
+ frame_indices = get_frame_indices(
174
+ num_frames, vlen, sample=sample, fix_start=fix_start,
175
+ min_num_frames=min_num_frames,
176
+ max_num_frames=max_num_frames, local_num_frames=local_num_frames,
177
+ input_fps=fps
178
+ )
179
+ frames = []
180
+
181
+ min_h = min_w = 100000
182
+ hw_set = set()
183
+ for index, frame in enumerate(gif):
184
+ # for index in frame_idxs:
185
+ if index in frame_indices:
186
+ frame = cv2.cvtColor(frame, cv2.COLOR_RGBA2RGB)
187
+ frame = frame.astype(np.uint8)
188
+ # # (H x W x C) to (C x H x W)
189
+ # frame = frame.permute(2, 0, 1)
190
+ frames.append(frame)
191
+ hw_set.add(frame.shape)
192
+ if frame.shape[0] < min_h:
193
+ min_h = frame.shape[0]
194
+ if frame.shape[1] < min_w:
195
+ min_w = frame.shape[1]
196
+ # print(hw_set, min_h, min_w)
197
+ if len(hw_set) > 1:
198
+ frames = [i[:min_h, :min_w] for i in frames]
199
+
200
+ frames = np.stack(frames) # .float() / 255
201
+
202
+ if byteio != None:
203
+ byteio.close()
204
+
205
+ return frames, frame_indices, float(fps), duration # for tgif
206
+
207
+
208
+
209
+ def read_frames_decord(
210
+ video_path, num_frames, sample='rand', fix_start=None, min_num_frames=1,
211
+ max_num_frames=-1, client=None, clip=None, local_num_frames=8
212
+ ):
213
+
214
+ if video_path.endswith('.avi'):
215
+ return read_frames_av(video_path=video_path, num_frames=num_frames, sample=sample,
216
+ fix_start=fix_start, min_num_frames=min_num_frames, max_num_frames=max_num_frames,
217
+ client=client, clip=clip, local_num_frames=local_num_frames)
218
+ if 's3://' in video_path:
219
+ video_bytes = client.get(video_path)
220
+ if video_bytes is None or len(video_bytes) == 0:
221
+ raise ValueError(f"Can't read byte from {video_path}!")
222
+ byteio = io.BytesIO(video_bytes)
223
+ video_reader = VideoReader(byteio, num_threads=1)
224
+ else:
225
+ byteio = None
226
+ video_reader = VideoReader(video_path, num_threads=1)
227
+ vlen = len(video_reader)
228
+ fps = video_reader.get_avg_fps()
229
+ duration = vlen / float(fps)
230
+
231
+
232
+ if clip:
233
+ start, end = clip
234
+ start = max(0, start)
235
+ end = min(duration - 0.1, end)
236
+ duration = end - start
237
+ vlen = int(duration * fps)
238
+ start_index = int(start * fps)
239
+
240
+ frame_indices = get_frame_indices(
241
+ num_frames, vlen, sample=sample, fix_start=fix_start,
242
+ input_fps=fps, min_num_frames=min_num_frames, max_num_frames=max_num_frames, local_num_frames=local_num_frames
243
+ )
244
+ if clip:
245
+ frame_indices = [f + start_index for f in frame_indices]
246
+
247
+ # print(fps, frame_indices)
248
+ frames = video_reader.get_batch(frame_indices).asnumpy() # (T, H, W, C), torch.uint8
249
+ # https://github.com/dmlc/decord/issues/208
250
+ video_reader.seek(0)
251
+
252
+ if byteio != None:
253
+ byteio.close()
254
+ # frames = frames.permute(0, 3, 1, 2) # (T, C, H, W), torch.uint8
255
+ return frames, frame_indices, float(fps), duration
256
+
257
+
258
+
259
+ def read_frames_img(
260
+ video_path, num_frames, sample='rand', fix_start=None, min_num_frames=1,
261
+ max_num_frames=-1, client=None, clip=None, local_num_frames=8
262
+ ):
263
+ def extract_frame_number(filename):
264
+ # Extract the numeric part from the filename using regular expressions
265
+ if filename.endswith('.jpg'):
266
+ match = re.search(r'_(\d+).jpg$', filename)
267
+ elif filename.endswith('.jpeg'):
268
+ match = re.search(r'_(\d+).jpeg$', filename)
269
+ elif filename.endswith('.png'):
270
+ match = re.search(r'_(\d+).png$', filename)
271
+ else:
272
+ raise NotImplementedError(f"Wrong filename: {filename}")
273
+
274
+ return int(match.group(1)) if match else -1
275
+
276
+
277
+ def sort_frames(frame_paths):
278
+ # Extract filenames from each path and sort by their numeric part
279
+ return sorted(frame_paths, key=lambda x: extract_frame_number(os.path.basename(x)))
280
+
281
+ # img_list=[]
282
+
283
+ if "s3://" in video_path:
284
+ img_list = sort_frames(client.list(video_path))
285
+ else:
286
+ img_list = sort_frames(list(os.listdir(video_path)))
287
+
288
+
289
+ if 'tvqa' in video_path.lower():
290
+ fps = 3.0
291
+ else:
292
+ fps = 1.0
293
+
294
+ if clip is not None:
295
+ start = float(clip[0])
296
+ end = float(clip[1])
297
+ start = max(0, start)
298
+ end = min(len(img_list) / fps, end)
299
+ vlen = (end - start) * fps
300
+ else:
301
+ vlen = len(img_list)
302
+
303
+ duration = vlen / fps
304
+
305
+ if min_num_frames > vlen:
306
+ if sample == 'dynamic_fps1':
307
+ min_num_frames = (vlen // local_num_frames) * local_num_frames
308
+ else:
309
+ min_num_frames = vlen
310
+
311
+ if sample == 'dynamic_fps1':
312
+ num_segments = int(duration // local_num_frames)
313
+ if num_segments == 0:
314
+ num_frames = local_num_frames
315
+ else:
316
+ num_frames = local_num_frames * num_segments
317
+ num_frames = min(num_frames, max_num_frames)
318
+ num_frames = max(min_num_frames, num_frames)
319
+
320
+ num_frames = int(num_frames)
321
+ if clip is not None:
322
+ def _get_index_by_time(start_sec, end_sec, num_segments=8, fps=1., max_frame=9999):
323
+ start_idx = max(1, round(start_sec * fps))
324
+ end_idx = min(round(end_sec * fps), max_frame)
325
+ seg_size = float(end_idx - start_idx) / (num_segments - 1)
326
+ offsets = np.array([start_idx + int(np.round(seg_size * idx)) for idx in range(num_segments)])
327
+ return offsets
328
+
329
+ frame_indices = _get_index_by_time(float(clip[0]), float(clip[1]), num_segments=num_frames, fps=fps, max_frame=len(img_list)-1)
330
+ else:
331
+ frame_indices = get_frame_indices(
332
+ num_frames, vlen, sample=sample, fix_start=fix_start,
333
+ min_num_frames=min_num_frames,
334
+ max_num_frames=max_num_frames, local_num_frames=local_num_frames
335
+ )
336
+
337
+ imgs = []
338
+ for idx in frame_indices:
339
+ frame_fname = os.path.join(video_path, img_list[idx])
340
+ if "s3://" in video_path:
341
+ img_bytes = client.get(frame_fname)
342
+ else:
343
+ with open(frame_fname, 'rb') as f:
344
+ img_bytes = f.read()
345
+ img_np = np.frombuffer(img_bytes, np.uint8)
346
+ img = cv2.imdecode(img_np, cv2.IMREAD_COLOR)
347
+ cv2.cvtColor(img, cv2.COLOR_BGR2RGB, img)
348
+ imgs.append(img)
349
+
350
+ frames = np.array(imgs, dtype=np.uint8)
351
+
352
+
353
+ return frames, frame_indices, fps, duration
354
+
355
+
356
+
357
+ VIDEO_READER_FUNCS = {
358
+ 'av': read_frames_av,
359
+ 'decord': read_frames_decord,
360
+ 'gif': read_frames_gif,
361
+ 'img': read_frames_img,
362
+ 'frame': read_frames_img
363
+ }
364
+
365
+
366
+
367
+ def load_video(video_path, max_num_frames=512, media_dict=None): #, media_dict):
368
+
369
+ if media_dict is None:
370
+ media_dict = {'video_read_type': 'decord'}
371
+
372
+ if type(video_path) != str:
373
+ assert len(video_path) == 1, video_path
374
+ video_path = video_path[0]
375
+
376
+ if 'start' in media_dict:
377
+ clip = [media_dict['start'], media_dict['end']]
378
+ else:
379
+ clip = None
380
+
381
+ if 's3://' in video_path:
382
+ from petrel_client.client import Client
383
+ client = Client(conf_path='~/petreloss.conf')
384
+ else:
385
+ client = None
386
+
387
+ frames, frame_indices, fps, duration = VIDEO_READER_FUNCS[media_dict['video_read_type']](video_path=video_path, num_frames=max_num_frames, sample='dynamic_fps1', fix_start=None, min_num_frames=64, max_num_frames=max_num_frames, client=client, clip=clip, local_num_frames=8)
388
+
389
+ sec = [str(round(f / fps, 1)) for f in frame_indices]
390
+
391
+ msg = f"\nThe video lasts for {duration:.2f} seconds, and {len(sec)} frames are uniformly sampled from it. "
392
+
393
+ return frames, msg
394
+
395
+
396
+ ######################## load video ########################
397
+
398
+
399
+ def resize_and_center_crop(image, shortest_edge_length):
400
+ # Calculate new dimensions and resize
401
+ aspect_ratio = float(image.width) / float(image.height)
402
+ if aspect_ratio > 1:
403
+ new_width = int(shortest_edge_length * aspect_ratio)
404
+ new_height = shortest_edge_length
405
+ else:
406
+ new_width = shortest_edge_length
407
+ new_height = int(shortest_edge_length / aspect_ratio)
408
+ resized_image = image.resize((new_width, new_height), Image.ANTIALIAS)
409
+
410
+ # Calculate the position and perform the center crop
411
+ left = (new_width - shortest_edge_length) / 2
412
+ top = (new_height - shortest_edge_length) / 2
413
+ right = (new_width + shortest_edge_length) / 2
414
+ bottom = (new_height + shortest_edge_length) / 2
415
+ cropped_image = resized_image.crop((left, top, right, bottom))
416
+
417
+ return cropped_image
418
+
419
+
420
+ def auto_pad_images(image, grid_params):
421
+ assert isinstance(image, Image.Image), "Input should be a Pillow Image"
422
+ assert len(grid_params) > 0, "Grid parameters should not be empty"
423
+
424
+ # Step 1: Calculate and find the closest aspect ratio
425
+ input_width, input_height = image.size
426
+ input_aspect_ratio = input_width / input_height
427
+ candidate_resolutions = [(w / h, w, h) for w in grid_params for h in grid_params]
428
+ closest_aspect_ratio = min(candidate_resolutions, key=lambda x: abs(input_aspect_ratio - x[0]))
429
+
430
+ candidate_resolutions = [(x[1], x[2]) for x in candidate_resolutions if abs(x[0] - closest_aspect_ratio[0]) < 1e-3]
431
+
432
+ target_resolution = min(candidate_resolutions, key=lambda res: abs(max(input_width, input_height) / max(res) - 1))
433
+
434
+ resize_width, resize_height = target_resolution
435
+ if input_width > input_height:
436
+ resize_height = int(resize_width / input_aspect_ratio)
437
+ else:
438
+ resize_width = int(resize_height * input_aspect_ratio)
439
+ resized_image = image.resize((resize_width, resize_height), Image.ANTIALIAS)
440
+
441
+ # Step 5: Pad the resized image if necessary to match the target resolution
442
+ pad_width = target_resolution[0] - resize_width
443
+ pad_height = target_resolution[1] - resize_height
444
+ padded_image = Image.new("RGB", target_resolution, color=(0, 0, 0))
445
+ padded_image.paste(resized_image, (pad_width // 2, pad_height // 2))
446
+
447
+ return padded_image
448
+
449
+
450
+ def extract_patches(image, patch_size, overlap_ratio):
451
+ assert isinstance(image, Image.Image), "Input should be a Pillow Image"
452
+ assert patch_size > 0, "Patch size should be greater than 0"
453
+ assert 0 <= overlap_ratio < 1, "Overlap ratio should be between 0 and 1"
454
+
455
+ W, H = image.size
456
+ patches = []
457
+
458
+ stride = int(patch_size * (1 - overlap_ratio))
459
+
460
+ num_patches_y = (H - patch_size) // stride + 1
461
+ num_patches_x = (W - patch_size) // stride + 1
462
+
463
+ y_start = (H - (num_patches_y - 1) * stride - patch_size) // 2
464
+ x_start = (W - (num_patches_x - 1) * stride - patch_size) // 2
465
+
466
+ for y in range(y_start, y_start + num_patches_y * stride, stride):
467
+ for x in range(x_start, x_start + num_patches_x * stride, stride):
468
+ patch = image.crop((x, y, x + patch_size, y + patch_size))
469
+ patches.append(patch)
470
+
471
+ return patches
472
+
473
+
474
+ def process_highres_image_crop_split(image, data_args, processor=None):
475
+ crop_resolution = data_args.image_crop_resolution
476
+ split_resolution = data_args.image_split_resolution
477
+ if processor is None:
478
+ processor = data_args.image_processor
479
+ image_crop = resize_and_center_crop(image, crop_resolution)
480
+ image_patches = extract_patches(image_crop, patch_size=split_resolution, overlap_ratio=0)
481
+ image_patches = [processor.preprocess(image_patch, return_tensors="pt")["pixel_values"][0] for image_patch in image_patches]
482
+ return torch.stack(image_patches, dim=0)
483
+
484
+
485
+ def process_highres_image(image, processor, grid_pinpoints):
486
+ grid_params = [int(x) for x in grid_pinpoints.split(",")]
487
+ width_height = max(image.size)
488
+ fit_grid_params = [x for x in grid_params if x >= width_height]
489
+ if len(fit_grid_params) == 0:
490
+ select_size = max(grid_params)
491
+ else:
492
+ select_size = min(fit_grid_params)
493
+ # FIXME: always select the 448
494
+ select_size = max(grid_params)
495
+ image_padded = expand2square(image, tuple(int(x * 255) for x in processor.image_mean))
496
+
497
+ # FIXME: this seems to be a bug that it always resizes instead of padding
498
+ image_original_resize = image.resize((processor.size["shortest_edge"], processor.size["shortest_edge"]))
499
+ image_padded = image_padded.resize((select_size, select_size))
500
+ image_patches = extract_patches(image_padded, patch_size=processor.size["shortest_edge"], overlap_ratio=0)
501
+ image_patches = [image_original_resize] + image_patches
502
+ image_patches = [processor.preprocess(image_patch, return_tensors="pt")["pixel_values"][0] for image_patch in image_patches]
503
+ return torch.stack(image_patches, dim=0)
504
+
505
+
506
+ def select_best_resolution(original_size, possible_resolutions, max_resolutions, patch_size):
507
+ """
508
+ Selects the best resolution from a list of possible resolutions based on the original size.
509
+
510
+ Args:
511
+ original_size (tuple): The original size of the image in the format (width, height).
512
+ possible_resolutions (list): A list of possible resolutions in the format [(width1, height1), (width2, height2), ...].
513
+
514
+ Returns:
515
+ tuple: The best fit resolution in the format (width, height).
516
+ """
517
+ original_width, original_height = original_size
518
+ best_fit = None
519
+ max_effective_resolution = 0
520
+ min_wasted_resolution = float("inf")
521
+
522
+ for width, height in possible_resolutions:
523
+ if max_resolutions != None and (width * height != patch_size * patch_size):
524
+ if (width * height+patch_size*patch_size) > max_resolutions: # NOTE 要算一个global
525
+ continue
526
+ # Calculate the downscaled size to keep the aspect ratio
527
+ scale = min(width / original_width, height / original_height)
528
+ downscaled_width, downscaled_height = int(original_width * scale), int(original_height * scale)
529
+
530
+ # Calculate effective and wasted resolutions
531
+ effective_resolution = min(downscaled_width * downscaled_height, original_width * original_height)
532
+ wasted_resolution = (width * height) - effective_resolution
533
+
534
+ if effective_resolution > max_effective_resolution or (effective_resolution == max_effective_resolution and wasted_resolution < min_wasted_resolution):
535
+ max_effective_resolution = effective_resolution
536
+ min_wasted_resolution = wasted_resolution
537
+ best_fit = (width, height)
538
+
539
+ # print(f"original_size={original_size}, possible_resolutions={possible_resolutions}, max_resolutions={max_resolutions}, best_fit={best_fit}")
540
+ assert best_fit is not None, f"Can't find suitable fit in {possible_resolutions} at max:{max_resolutions}"
541
+ return best_fit
542
+
543
+
544
+ def resize_and_pad_image(image, target_resolution):
545
+ """
546
+ Resize and pad an image to a target resolution while maintaining aspect ratio.
547
+
548
+ Args:
549
+ image (PIL.Image.Image): The input image.
550
+ target_resolution (tuple): The target resolution (width, height) of the image.
551
+
552
+ Returns:
553
+ PIL.Image.Image: The resized and padded image.
554
+ """
555
+ original_width, original_height = image.size
556
+ target_width, target_height = target_resolution
557
+
558
+ # Determine which dimension (width or height) to fill
559
+ scale_w = target_width / original_width
560
+ scale_h = target_height / original_height
561
+
562
+ if scale_w < scale_h:
563
+ # Width will be filled completely
564
+ new_width = target_width
565
+ new_height = min(math.ceil(original_height * scale_w), target_height)
566
+ else:
567
+ # Height will be filled completely
568
+ new_height = target_height
569
+ new_width = min(math.ceil(original_width * scale_h), target_width)
570
+
571
+ # Resize the image
572
+ resized_image = image.resize((new_width, new_height))
573
+
574
+ # Create a new image with the target size and paste the resized image onto it
575
+ new_image = Image.new("RGB", (target_width, target_height), (0, 0, 0))
576
+ paste_x = (target_width - new_width) // 2
577
+ paste_y = (target_height - new_height) // 2
578
+ new_image.paste(resized_image, (paste_x, paste_y))
579
+
580
+ return new_image
581
+
582
+
583
+ def divide_to_patches(image, patch_size):
584
+ """
585
+ Divides an image into patches of a specified size.
586
+
587
+ Args:
588
+ image (PIL.Image.Image): The input image.
589
+ patch_size (int): The size of each patch.
590
+
591
+ Returns:
592
+ list: A list of PIL.Image.Image objects representing the patches.
593
+ """
594
+ patches = []
595
+ width, height = image.size
596
+ for i in range(0, height, patch_size):
597
+ for j in range(0, width, patch_size):
598
+ box = (j, i, j + patch_size, i + patch_size)
599
+ patch = image.crop(box)
600
+ patches.append(patch)
601
+
602
+ return patches
603
+
604
+
605
+ def get_anyres_image_grid_shape(image_size, grid_pinpoints, patch_size, max_resolutions=None):
606
+ """
607
+ Calculate the shape of the image patch grid after the preprocessing for images of any resolution.
608
+
609
+ Args:
610
+ image_size (tuple): The size of the input image in the format (width, height).
611
+ grid_pinpoints (str): A string representation of a list of possible resolutions.
612
+ patch_size (int): The size of each image patch.
613
+
614
+ Returns:
615
+ tuple: The shape of the image patch grid in the format (width, height).
616
+ """
617
+ if isinstance(grid_pinpoints, str) and "x" in grid_pinpoints:
618
+ assert patch_size in [224, 336, 384, 448, 512], "patch_size should be in [224, 336, 384, 448, 512]"
619
+ # Use regex to extract the range from the input string
620
+ matches = re.findall(r"\((\d+)x(\d+)\)", grid_pinpoints)
621
+ range_start = tuple(map(int, matches[0]))
622
+ range_end = tuple(map(int, matches[-1]))
623
+ # Generate a matrix of tuples from (range_start[0], range_start[1]) to (range_end[0], range_end[1])
624
+ grid_pinpoints = [(i, j) for i in range(range_start[0], range_end[0] + 1) for j in range(range_start[1], range_end[1] + 1)]
625
+ # Multiply all elements by patch_size
626
+ grid_pinpoints = [[dim * patch_size for dim in pair] for pair in grid_pinpoints]
627
+ if type(grid_pinpoints) is list:
628
+ possible_resolutions = grid_pinpoints
629
+ else:
630
+ possible_resolutions = ast.literal_eval(grid_pinpoints)
631
+ width, height = select_best_resolution(image_size, possible_resolutions, max_resolutions=max_resolutions, patch_size=patch_size)
632
+
633
+ # print("get width/patch size", width, patch_size, flush=True)
634
+
635
+ return width // patch_size, height // patch_size
636
+
637
+
638
+ def process_anyres_image(image, processor, grid_pinpoints):
639
+ """
640
+ Process an image with variable resolutions.
641
+
642
+ Args:
643
+ image (PIL.Image.Image): The input image to be processed.
644
+ processor: The image processor object.
645
+ grid_pinpoints (str): A string representation of a list of possible resolutions.
646
+
647
+ Returns:
648
+ torch.Tensor: A tensor containing the processed image patches.
649
+ """
650
+ raise NotImplementedError
651
+ # Convert grid_pinpoints from string to list
652
+ if isinstance(grid_pinpoints, str) and "x" in grid_pinpoints:
653
+ try:
654
+ patch_size = processor.size[0]
655
+ except Exception as e:
656
+ patch_size = processor.size["shortest_edge"]
657
+ assert patch_size in [224, 336, 384, 448, 512], "patch_size should be in [224, 336, 384, 448, 512]"
658
+ # Use regex to extract the range from the input string
659
+ matches = re.findall(r"\((\d+)x(\d+)\)", grid_pinpoints)
660
+ range_start = tuple(map(int, matches[0]))
661
+ range_end = tuple(map(int, matches[-1]))
662
+ # Generate a matrix of tuples from (range_start[0], range_start[1]) to (range_end[0], range_end[1])
663
+ grid_pinpoints = [(i, j) for i in range(range_start[0], range_end[0] + 1) for j in range(range_start[1], range_end[1] + 1)]
664
+ # Multiply all elements by patch_size
665
+ grid_pinpoints = [[dim * patch_size for dim in pair] for pair in grid_pinpoints]
666
+
667
+ if type(grid_pinpoints) is list:
668
+ possible_resolutions = grid_pinpoints
669
+ else:
670
+ possible_resolutions = ast.literal_eval(grid_pinpoints)
671
+ best_resolution = select_best_resolution(image.size, possible_resolutions)
672
+ image_padded = resize_and_pad_image(image, best_resolution)
673
+
674
+ patches = divide_to_patches(image_padded, processor.crop_size["height"])
675
+
676
+ # FIXME: this seems to be a bug that it resizes instead of pad.
677
+ # but to keep it consistent with previous, i will keep it as it is
678
+ # TODO: uncomment below to ablate with the padding
679
+ if isinstance(processor.size, dict):
680
+ shortest_edge = processor.size["shortest_edge"]
681
+ else:
682
+ shortest_edge = min(processor.size)
683
+ image_original_resize = image.resize((shortest_edge, shortest_edge))
684
+ # image_padded_square = expand2square(image, tuple(int(x*255) for x in processor.image_mean))
685
+ # image_original_resize = image_padded_square.resize((processor.size['shortest_edge'], processor.size['shortest_edge']))
686
+
687
+ image_patches = [image_original_resize] + patches
688
+ image_patches = [processor.preprocess(image_patch, return_tensors="pt")["pixel_values"][0] for image_patch in image_patches]
689
+
690
+ # print("image.size", image.size, "len(image_patches):", len(image_patches), "patch_size:", image_patches[0].shape)
691
+ return torch.stack(image_patches, dim=0)
692
+
693
+ def process_anyres_image_nopad(image, processor, grid_pinpoints):
694
+ """
695
+ Process an image with variable resolutions.
696
+
697
+ Args:
698
+ image (PIL.Image.Image): The input image to be processed.
699
+ processor: The image processor object.
700
+ grid_pinpoints (str): A string representation of a list of possible resolutions.
701
+
702
+ Returns:
703
+ torch.Tensor: A tensor containing the processed image patches.
704
+ """
705
+ # Convert grid_pinpoints from string to list
706
+ try:
707
+ patch_size = processor.size[0]
708
+ except Exception as e:
709
+ patch_size = processor.size["shortest_edge"]
710
+
711
+ assert patch_size in [224, 336, 384, 448, 512], "patch_size should be in [224, 336, 384, 448, 512]"
712
+
713
+ if isinstance(grid_pinpoints, str) and "x" in grid_pinpoints:
714
+
715
+ # Use regex to extract the range from the input string
716
+ matches = re.findall(r"\((\d+)x(\d+)\)", grid_pinpoints)
717
+ range_start = tuple(map(int, matches[0]))
718
+ range_end = tuple(map(int, matches[-1]))
719
+ # Generate a matrix of tuples from (range_start[0], range_start[1]) to (range_end[0], range_end[1])
720
+ grid_pinpoints = [(i, j) for i in range(range_start[0], range_end[0] + 1) for j in range(range_start[1], range_end[1] + 1)]
721
+ # Multiply all elements by patch_size
722
+ grid_pinpoints = [[dim * patch_size for dim in pair] for pair in grid_pinpoints]
723
+
724
+ if type(grid_pinpoints) is list:
725
+ possible_resolutions = grid_pinpoints
726
+ else:
727
+ possible_resolutions = ast.literal_eval(grid_pinpoints)
728
+ best_resolution = select_best_resolution(image.size, possible_resolutions, max_resolutions=None, patch_size=patch_size) # 目前图像无限制
729
+ # image_padded = resize_and_pad_image(image, best_resolution)
730
+
731
+ patches = divide_to_patches(image.resize(best_resolution), patch_size)
732
+
733
+ # FIXME: this seems to be a bug that it resizes instead of pad.
734
+ # but to keep it consistent with previous, i will keep it as it is
735
+ # TODO: uncomment below to ablate with the padding
736
+ if isinstance(processor.size, dict):
737
+ shortest_edge = processor.size["shortest_edge"]
738
+ else:
739
+ shortest_edge = min(processor.size)
740
+ image_original_resize = image.resize((shortest_edge, shortest_edge))
741
+ # image_padded_square = expand2square(image, tuple(int(x*255) for x in processor.image_mean))
742
+ # image_original_resize = image_padded_square.resize((processor.size['shortest_edge'], processor.size['shortest_edge']))
743
+
744
+ image_patches = [image_original_resize] + patches
745
+ image_patches = [processor.preprocess(image_patch, return_tensors="pt")["pixel_values"][0] for image_patch in image_patches]
746
+
747
+ # raise ValueError(f"image.size: {image.size} len(image_patches): {len(image_patches)}, patch_size:, {image_patches[0].shape}, possible_resolutions:, {possible_resolutions}, best: {best_resolution}")
748
+ return torch.stack(image_patches, dim=0)
749
+
750
+
751
+ def load_image_from_base64(image):
752
+ return Image.open(BytesIO(base64.b64decode(image)))
753
+
754
+
755
+ def expand2square(pil_img, background_color):
756
+ width, height = pil_img.size
757
+ if width == height:
758
+ return pil_img
759
+ elif width > height:
760
+ result = Image.new(pil_img.mode, (width, width), background_color)
761
+ result.paste(pil_img, (0, (width - height) // 2))
762
+ return result
763
+ else:
764
+ result = Image.new(pil_img.mode, (height, height), background_color)
765
+ result.paste(pil_img, ((height - width) // 2, 0))
766
+ return result
767
+
768
+
769
+ def process_images(images, image_processor, model_cfg):
770
+ image_aspect_ratio = getattr(model_cfg, "image_aspect_ratio", None)
771
+ new_images = []
772
+ if image_aspect_ratio == "highres":
773
+ raise NotImplementedError
774
+ for image in images:
775
+ image = process_highres_image(image, image_processor, model_cfg.image_grid_pinpoints)
776
+ new_images.append(image)
777
+ elif "anyres" in image_aspect_ratio:
778
+ for image in images:
779
+ if "nopad" in image_aspect_ratio:
780
+ image = process_anyres_image_nopad(image, image_processor, model_cfg.image_grid_pinpoints)
781
+ else:
782
+ image = process_anyres_image(image, image_processor, model_cfg.image_grid_pinpoints)
783
+ new_images.append(image)
784
+ elif image_aspect_ratio == "crop_split":
785
+ raise NotImplementedError
786
+ for image in images:
787
+ image = process_highres_image_crop_split(image, model_cfg, image_processor)
788
+ new_images.append(image)
789
+ elif image_aspect_ratio == "pad":
790
+ for image in images:
791
+ image = expand2square(image, tuple(int(x * 255) for x in image_processor.image_mean))
792
+ image = image_processor.preprocess(image, return_tensors="pt")["pixel_values"][0]
793
+ new_images.append(image)
794
+ else:
795
+ return image_processor.preprocess(images, return_tensors="pt")["pixel_values"]
796
+ if all(x.shape == new_images[0].shape for x in new_images):
797
+ new_images = torch.stack(new_images, dim=0)
798
+ return new_images
799
+
800
+
801
+ def tokenizer_image_token(prompt, tokenizer, image_token_index=IMAGE_TOKEN_INDEX, return_tensors=None):
802
+ prompt_chunks = [tokenizer(chunk).input_ids for chunk in prompt.split("<image>")]
803
+
804
+ def insert_separator(X, sep):
805
+ return [ele for sublist in zip(X, [sep] * len(X)) for ele in sublist][:-1]
806
+
807
+ input_ids = []
808
+ offset = 0
809
+ if len(prompt_chunks) > 0 and len(prompt_chunks[0]) > 0 and prompt_chunks[0][0] == tokenizer.bos_token_id:
810
+ offset = 1
811
+ input_ids.append(prompt_chunks[0][0])
812
+
813
+ for x in insert_separator(prompt_chunks, [image_token_index] * (offset + 1)):
814
+ input_ids.extend(x[offset:])
815
+
816
+ if return_tensors is not None:
817
+ if return_tensors == "pt":
818
+ return torch.tensor(input_ids, dtype=torch.long)
819
+ raise ValueError(f"Unsupported tensor type: {return_tensors}")
820
+ return input_ids
821
+
822
+
823
+ def get_model_name_from_path(model_path):
824
+ model_path = model_path.strip("/")
825
+ model_paths = model_path.split("/")
826
+ if model_paths[-1].startswith("checkpoint-"):
827
+ return model_paths[-2] + "_" + model_paths[-1]
828
+ else:
829
+ return model_paths[-1]
830
+
831
+
832
+ class KeywordsStoppingCriteria(StoppingCriteria):
833
+ def __init__(self, keywords, tokenizer, input_ids):
834
+ self.keywords = keywords
835
+ self.keyword_ids = []
836
+ for keyword in keywords:
837
+ cur_keyword_ids = tokenizer(keyword).input_ids
838
+ if len(cur_keyword_ids) > 1 and cur_keyword_ids[0] == tokenizer.bos_token_id:
839
+ cur_keyword_ids = cur_keyword_ids[1:]
840
+ self.keyword_ids.append(torch.tensor(cur_keyword_ids))
841
+ self.tokenizer = tokenizer
842
+ self.start_len = input_ids.shape[1]
843
+
844
+ def __call__(self, output_ids: torch.LongTensor, scores: torch.FloatTensor, **kwargs) -> bool:
845
+ assert output_ids.shape[0] == 1, "Only support batch size 1 (yet)" # TODO
846
+ offset = min(output_ids.shape[1] - self.start_len, 3)
847
+ self.keyword_ids = [keyword_id.to(output_ids.device) for keyword_id in self.keyword_ids]
848
+ for keyword_id in self.keyword_ids:
849
+ if output_ids[0, -keyword_id.shape[0] :] == keyword_id:
850
+ return True
851
+ outputs = self.tokenizer.batch_decode(output_ids[:, -offset:], skip_special_tokens=True)[0]
852
+ for keyword in self.keywords:
853
+ if keyword in outputs:
854
+ return True
855
+ return False
.ipynb_checkpoints/modeling_qwen2_flash-checkpoint.py ADDED
The diff for this file is too large to render. See raw diff
 
added_tokens.json ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "</tool_call>": 151658,
3
+ "<tool_call>": 151657,
4
+ "<|box_end|>": 151649,
5
+ "<|box_start|>": 151648,
6
+ "<|endoftext|>": 151643,
7
+ "<|file_sep|>": 151664,
8
+ "<|fim_middle|>": 151660,
9
+ "<|fim_pad|>": 151662,
10
+ "<|fim_prefix|>": 151659,
11
+ "<|fim_suffix|>": 151661,
12
+ "<|im_end|>": 151645,
13
+ "<|im_start|>": 151644,
14
+ "<|image_pad|>": 151655,
15
+ "<|object_ref_end|>": 151647,
16
+ "<|object_ref_start|>": 151646,
17
+ "<|quad_end|>": 151651,
18
+ "<|quad_start|>": 151650,
19
+ "<|repo_name|>": 151663,
20
+ "<|video_pad|>": 151656,
21
+ "<|vision_end|>": 151653,
22
+ "<|vision_pad|>": 151654,
23
+ "<|vision_start|>": 151652
24
+ }
config.json ADDED
@@ -0,0 +1,231 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "_name_or_path": "/inspire/hdd/ws-f4d69b29-e0a5-44e6-bd92-acf4de9990f0/public-project/xiacheng-240108120111/vcflash0607_brandnew/videochat-flash_qwen2_5_all_compress_train_0",
3
+ "architectures": [
4
+ "VideoChatFlashQwenForCausalLM"
5
+ ],
6
+ "attention_bias": false,
7
+ "attention_dropout": 0.0,
8
+ "auto_map": {
9
+ "AutoConfig": "modeling_videochat_flash.VideoChatFlashQwenConfig",
10
+ "AutoModel": "modeling_videochat_flash.VideoChatFlashQwenForCausalLM"
11
+ },
12
+ "bos_token_id": 151643,
13
+ "dual_chunk_attention_config": {
14
+ "chunk_size": 262144,
15
+ "local_size": 8192,
16
+ "original_max_position_embeddings": 262144
17
+ },
18
+ "eos_token_id": 151645,
19
+ "frame_aspect_ratio": "square",
20
+ "frame_grid_pinpoints": null,
21
+ "hidden_act": "silu",
22
+ "hidden_size": 3584,
23
+ "image_aspect_ratio": "anyres_nopad",
24
+ "image_crop_resolution": null,
25
+ "image_grid_pinpoints": [
26
+ [
27
+ 224,
28
+ 224
29
+ ],
30
+ [
31
+ 224,
32
+ 448
33
+ ],
34
+ [
35
+ 224,
36
+ 672
37
+ ],
38
+ [
39
+ 224,
40
+ 896
41
+ ],
42
+ [
43
+ 224,
44
+ 1120
45
+ ],
46
+ [
47
+ 224,
48
+ 1344
49
+ ],
50
+ [
51
+ 448,
52
+ 224
53
+ ],
54
+ [
55
+ 448,
56
+ 448
57
+ ],
58
+ [
59
+ 448,
60
+ 672
61
+ ],
62
+ [
63
+ 448,
64
+ 896
65
+ ],
66
+ [
67
+ 448,
68
+ 1120
69
+ ],
70
+ [
71
+ 448,
72
+ 1344
73
+ ],
74
+ [
75
+ 672,
76
+ 224
77
+ ],
78
+ [
79
+ 672,
80
+ 448
81
+ ],
82
+ [
83
+ 672,
84
+ 672
85
+ ],
86
+ [
87
+ 672,
88
+ 896
89
+ ],
90
+ [
91
+ 672,
92
+ 1120
93
+ ],
94
+ [
95
+ 672,
96
+ 1344
97
+ ],
98
+ [
99
+ 896,
100
+ 224
101
+ ],
102
+ [
103
+ 896,
104
+ 448
105
+ ],
106
+ [
107
+ 896,
108
+ 672
109
+ ],
110
+ [
111
+ 896,
112
+ 896
113
+ ],
114
+ [
115
+ 896,
116
+ 1120
117
+ ],
118
+ [
119
+ 896,
120
+ 1344
121
+ ],
122
+ [
123
+ 1120,
124
+ 224
125
+ ],
126
+ [
127
+ 1120,
128
+ 448
129
+ ],
130
+ [
131
+ 1120,
132
+ 672
133
+ ],
134
+ [
135
+ 1120,
136
+ 896
137
+ ],
138
+ [
139
+ 1120,
140
+ 1120
141
+ ],
142
+ [
143
+ 1120,
144
+ 1344
145
+ ],
146
+ [
147
+ 1344,
148
+ 224
149
+ ],
150
+ [
151
+ 1344,
152
+ 448
153
+ ],
154
+ [
155
+ 1344,
156
+ 672
157
+ ],
158
+ [
159
+ 1344,
160
+ 896
161
+ ],
162
+ [
163
+ 1344,
164
+ 1120
165
+ ],
166
+ [
167
+ 1344,
168
+ 1344
169
+ ]
170
+ ],
171
+ "image_split_resolution": null,
172
+ "initializer_range": 0.02,
173
+ "intermediate_size": 18944,
174
+ "llm_compress_layer_list": [
175
+ 8,
176
+ 16,
177
+ 24
178
+ ],
179
+ "llm_compress_type": "attention",
180
+ "llm_image_token_ratio_list": [
181
+ 1.0,
182
+ 0.5,
183
+ 0.25,
184
+ 0.125
185
+ ],
186
+ "max_num_pixels": 14745600000,
187
+ "max_position_embeddings": 64000,
188
+ "max_window_layers": 28,
189
+ "min_slow_num_frames": 4,
190
+ "mm_close_init": false,
191
+ "mm_hidden_size": 1024,
192
+ "mm_llm_compress": false,
193
+ "mm_local_num_frames": 4,
194
+ "mm_newline_position": "nothing",
195
+ "mm_num_compress_latents": 128,
196
+ "mm_num_compress_query_type": "learnable",
197
+ "mm_patch_merge_type": "spatial_nopad",
198
+ "mm_pos_num_frames": 8,
199
+ "mm_projector_lr": null,
200
+ "mm_projector_type": "tome16_mlp_hd64",
201
+ "mm_resampler_type": null,
202
+ "mm_spatial_pool_mode": "bilinear",
203
+ "mm_tunable_parts": "mm_vision_tower,mm_mlp_adapter,mm_language_model",
204
+ "mm_use_im_patch_token": false,
205
+ "mm_use_im_start_end": false,
206
+ "mm_vision_select_feature": "patch",
207
+ "mm_vision_select_layer": -2,
208
+ "mm_vision_tower": "umt-large",
209
+ "mm_vision_tower_lr": 2e-06,
210
+ "model_type": "videochat_flash_qwen",
211
+ "num_attention_heads": 28,
212
+ "num_hidden_layers": 28,
213
+ "num_key_value_heads": 4,
214
+ "pos_skipping_range": 4096,
215
+ "rms_norm_eps": 1e-05,
216
+ "rope_scaling": null,
217
+ "rope_theta": 10000000.0,
218
+ "sliding_window": 32768,
219
+ "tie_word_embeddings": false,
220
+ "tokenizer_model_max_length": 32768,
221
+ "tokenizer_padding_side": "right",
222
+ "torch_dtype": "bfloat16",
223
+ "transformers_version": "4.39.2",
224
+ "use_cache": true,
225
+ "use_mm_proj": true,
226
+ "use_pos_skipping": false,
227
+ "use_sliding_window": false,
228
+ "vision_encode_type": "video_image",
229
+ "vision_tower_pretrained": null,
230
+ "vocab_size": 152064
231
+ }
constants.py ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ CONTROLLER_HEART_BEAT_EXPIRATION = 30
2
+ WORKER_HEART_BEAT_INTERVAL = 15
3
+
4
+ LOGDIR = "."
5
+
6
+ # Model Constants
7
+ IGNORE_INDEX = -100
8
+ IMAGE_TOKEN_INDEX = -200
9
+ DEFAULT_IMAGE_TOKEN = "<image>"
10
+ DEFAULT_IMAGE_PATCH_TOKEN = "<im_patch>"
11
+ DEFAULT_IM_START_TOKEN = "<im_start>"
12
+ DEFAULT_IM_END_TOKEN = "<im_end>"
conversation.py ADDED
@@ -0,0 +1,592 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import dataclasses
2
+ from enum import auto, Enum
3
+ from typing import List, Any, Dict, Union, Tuple
4
+ import re
5
+ import base64
6
+ from io import BytesIO
7
+ from PIL import Image
8
+ from transformers import AutoTokenizer
9
+
10
+
11
+ class SeparatorStyle(Enum):
12
+ """Different separator style."""
13
+
14
+ SINGLE = auto()
15
+ TWO = auto()
16
+ MPT = auto()
17
+ PLAIN = auto()
18
+ CHATML = auto()
19
+ LLAMA_2 = auto()
20
+ LLAMA_3 = auto()
21
+ QWEN = auto()
22
+ GEMMA = auto()
23
+
24
+
25
+ @dataclasses.dataclass
26
+ class Conversation:
27
+ """A class that keeps all conversation history."""
28
+
29
+ system: str
30
+ roles: List[str]
31
+ messages: List[List[str]]
32
+ offset: int
33
+ sep_style: SeparatorStyle = SeparatorStyle.SINGLE
34
+ sep: str = "###"
35
+ sep2: str = None
36
+ version: str = "Unknown"
37
+
38
+ tokenizer_id: str = ""
39
+ tokenizer: Any = None
40
+ # Stop criteria (the default one is EOS token)
41
+ stop_str: Union[str, List[str]] = None
42
+ # Stops generation if meeting any token in this list
43
+ stop_token_ids: List[int] = None
44
+
45
+ skip_next: bool = False
46
+
47
+ def get_prompt(self):
48
+ messages = self.messages
49
+ if len(messages) > 0 and type(messages[0][1]) is tuple:
50
+ messages = self.messages.copy()
51
+ init_role, init_msg = messages[0].copy()
52
+ init_msg = init_msg[0]
53
+ if "mmtag" in self.version:
54
+ init_msg = init_msg.replace("<image>", "").strip()
55
+ messages[0] = (init_role, init_msg)
56
+ messages.insert(0, (self.roles[0], "<Image><image></Image>"))
57
+ messages.insert(1, (self.roles[1], "Received."))
58
+ elif not init_msg.startswith("<image>"):
59
+ init_msg = init_msg.replace("<image>", "").strip()
60
+ messages[0] = (init_role, "<image>\n" + init_msg)
61
+ else:
62
+ messages[0] = (init_role, init_msg)
63
+
64
+ if self.sep_style == SeparatorStyle.SINGLE:
65
+ ret = self.system + self.sep
66
+ for role, message in messages:
67
+ if message:
68
+ if type(message) is tuple:
69
+ message, _, _ = message
70
+ ret += role + ": " + message + self.sep
71
+ else:
72
+ ret += role + ":"
73
+
74
+ elif self.sep_style == SeparatorStyle.TWO:
75
+ seps = [self.sep, self.sep2]
76
+ ret = self.system + seps[0]
77
+ for i, (role, message) in enumerate(messages):
78
+ if message:
79
+ if type(message) is tuple:
80
+ message, _, _ = message
81
+ ret += role + ": " + message + seps[i % 2]
82
+ else:
83
+ ret += role + ":"
84
+
85
+ elif self.sep_style == SeparatorStyle.CHATML:
86
+ ret = "" if self.system == "" else self.system + self.sep + "\n"
87
+ for role, message in messages:
88
+ if message:
89
+ if type(message) is tuple:
90
+ message, images, _ = message
91
+ message = "<image>" * len(images) + message
92
+ ret += role + "\n" + message + self.sep + "\n"
93
+ else:
94
+ ret += role + "\n"
95
+ return ret
96
+
97
+ elif self.sep_style == SeparatorStyle.LLAMA_3:
98
+ chat_template_messages = [{"role": "system", "content": self.system}]
99
+ for role, message in messages:
100
+ if message:
101
+ if type(message) is tuple:
102
+ message, images = message
103
+ message = "<image>" * len(images) + message
104
+ chat_template_messages.append({"role": role, "content": message})
105
+
106
+ # print(chat_template_messages)
107
+ return self.tokenizer.apply_chat_template(chat_template_messages, tokenize=False, add_generation_prompt=True)
108
+ # ret = "" if self.system == "" else self.system + self.sep + "\n"
109
+ # for role, message in messages:
110
+ # if message:
111
+ # if type(message) is tuple:
112
+ # message, images = message
113
+ # message = "<image>" * len(images) + message
114
+ # ret += role + "\n" + message + self.sep + "\n"
115
+ # else:
116
+ # ret += role + "\n"
117
+ # return ret
118
+
119
+ elif self.sep_style == SeparatorStyle.MPT:
120
+ ret = self.system + self.sep
121
+ for role, message in messages:
122
+ if message:
123
+ if type(message) is tuple:
124
+ message, _, _ = message
125
+ ret += role + message + self.sep
126
+ else:
127
+ ret += role
128
+
129
+ elif self.sep_style == SeparatorStyle.GEMMA:
130
+ ret = ""
131
+ for i, (role, message) in enumerate(messages):
132
+ assert role == self.roles[i % 2], "Conversation should alternate user/assistant/user/assistant/..."
133
+ if message:
134
+ if type(message) is tuple:
135
+ message, _, _ = message
136
+ ret += role + message + self.sep
137
+ else:
138
+ ret += role
139
+
140
+ elif self.sep_style == SeparatorStyle.LLAMA_2:
141
+ wrap_sys = lambda msg: f"<<SYS>>\n{msg}\n<</SYS>>\n\n" if len(msg) > 0 else msg
142
+ wrap_inst = lambda msg: f"[INST] {msg} [/INST]"
143
+ ret = ""
144
+
145
+ for i, (role, message) in enumerate(messages):
146
+ if i == 0:
147
+ assert message, "first message should not be none"
148
+ assert role == self.roles[0], "first message should come from user"
149
+ if message:
150
+ if type(message) is tuple:
151
+ message, _, _ = message
152
+ if i == 0:
153
+ message = wrap_sys(self.system) + message
154
+ if i % 2 == 0:
155
+ message = wrap_inst(message)
156
+ ret += self.sep + message
157
+ else:
158
+ ret += " " + message + " " + self.sep2
159
+ else:
160
+ ret += ""
161
+ ret = ret.lstrip(self.sep)
162
+
163
+ elif self.sep_style == SeparatorStyle.PLAIN:
164
+ seps = [self.sep, self.sep2]
165
+ ret = self.system
166
+ for i, (role, message) in enumerate(messages):
167
+ if message:
168
+ if type(message) is tuple:
169
+ message, _, _ = message
170
+ ret += message + seps[i % 2]
171
+ else:
172
+ ret += ""
173
+ else:
174
+ raise ValueError(f"Invalid style: {self.sep_style}")
175
+
176
+ return ret
177
+
178
+ def append_message(self, role, message):
179
+ self.messages.append([role, message])
180
+
181
+ def process_image(self, image, image_process_mode, return_pil=False, image_format="PNG"):
182
+ if image_process_mode == "Pad":
183
+
184
+ def expand2square(pil_img, background_color=(122, 116, 104)):
185
+ width, height = pil_img.size
186
+ if width == height:
187
+ return pil_img
188
+ elif width > height:
189
+ result = Image.new(pil_img.mode, (width, width), background_color)
190
+ result.paste(pil_img, (0, (width - height) // 2))
191
+ return result
192
+ else:
193
+ result = Image.new(pil_img.mode, (height, height), background_color)
194
+ result.paste(pil_img, ((height - width) // 2, 0))
195
+ return result
196
+
197
+ image = expand2square(image)
198
+ elif image_process_mode in ["Default", "Crop"]:
199
+ pass
200
+ elif image_process_mode == "Resize":
201
+ image = image.resize((336, 336))
202
+ else:
203
+ raise ValueError(f"Invalid image_process_mode: {image_process_mode}")
204
+
205
+ if type(image) is not Image.Image:
206
+ image = Image.open(image).convert("RGB")
207
+
208
+ max_hw, min_hw = max(image.size), min(image.size)
209
+ aspect_ratio = max_hw / min_hw
210
+ max_len, min_len = 672, 448
211
+ shortest_edge = int(min(max_len / aspect_ratio, min_len, min_hw))
212
+ longest_edge = int(shortest_edge * aspect_ratio)
213
+ W, H = image.size
214
+ if H > W:
215
+ H, W = longest_edge, shortest_edge
216
+ else:
217
+ H, W = shortest_edge, longest_edge
218
+ image = image.resize((W, H))
219
+ if return_pil:
220
+ return image
221
+ else:
222
+ buffered = BytesIO()
223
+ image.save(buffered, format=image_format)
224
+ img_b64_str = base64.b64encode(buffered.getvalue()).decode()
225
+ return img_b64_str
226
+
227
+ def get_images(self, return_pil=False, return_path=False):
228
+ images = []
229
+ for i, (role, msg) in enumerate(self.messages[self.offset :]):
230
+ if i % 2 == 0:
231
+ if type(msg) is tuple:
232
+ msg, image, image_process_mode = msg
233
+ if type(image) != list:
234
+ image = [image]
235
+ for img in image:
236
+ if not return_path and self.is_image_file(img):
237
+ img = self.process_image(img, image_process_mode, return_pil=return_pil)
238
+ else:
239
+ images.append(img)
240
+ return images
241
+
242
+ def is_image_file(self, filename):
243
+ image_extensions = [".png", ".jpg", ".jpeg", ".gif", ".bmp", ".tiff", ".webp"]
244
+ return any(filename.lower().endswith(ext) for ext in image_extensions)
245
+
246
+ def is_video_file(self, filename):
247
+ video_extensions = [".mp4", ".mov", ".avi", ".mkv", ".wmv", ".flv", ".mpeg", ".mpg"]
248
+ return any(filename.lower().endswith(ext) for ext in video_extensions)
249
+
250
+ def to_gradio_chatbot(self):
251
+ ret = []
252
+ for i, (role, msg) in enumerate(self.messages[self.offset :]):
253
+ if i % 2 == 0:
254
+ if type(msg) is tuple:
255
+ msg, image, image_process_mode = msg
256
+ if type(image) != list:
257
+ image = [image]
258
+ if len(image) == 1:
259
+ msg = "<image>\n" + msg.replace("<image>", "").strip()
260
+ else:
261
+ msg = re.sub(r"(<image>)\n(?=<image>)", r"\1 ", msg)
262
+
263
+ img_str_list = []
264
+ for img in image:
265
+ if self.is_image_file(img):
266
+ img_b64_str = self.process_image(img, "Default", return_pil=False, image_format="JPEG")
267
+ img_str = f'<img src="data:image/jpeg;base64,{img_b64_str}" style="max-width: 256px; max-height: 256px; width: auto; height: auto; object-fit: contain;"/>'
268
+ img_str_list.append(img_str)
269
+ elif self.is_video_file(img):
270
+ ret.append(((img,), None))
271
+
272
+ msg = msg.strip()
273
+ img_place_holder = ""
274
+ for img_str in img_str_list:
275
+ img_place_holder += f"{img_str}\n\n"
276
+
277
+ if len(img_str_list) > 0:
278
+ msg = f"{img_place_holder}\n\n{msg}"
279
+
280
+ if len(msg) > 0:
281
+ ret.append([msg, None])
282
+ else:
283
+ ret.append([msg, None])
284
+ else:
285
+ ret[-1][-1] = msg
286
+ return ret
287
+
288
+ def copy(self):
289
+ return Conversation(system=self.system, roles=self.roles, messages=[[x, y] for x, y in self.messages], offset=self.offset, sep_style=self.sep_style, sep=self.sep, sep2=self.sep2, version=self.version)
290
+
291
+ def dict(self):
292
+ if len(self.get_images()) > 0:
293
+ return {
294
+ "system": self.system,
295
+ "roles": self.roles,
296
+ "messages": [[x, y[0] if type(y) is tuple else y] for x, y in self.messages],
297
+ "offset": self.offset,
298
+ "sep": self.sep,
299
+ "sep2": self.sep2,
300
+ }
301
+ return {
302
+ "system": self.system,
303
+ "roles": self.roles,
304
+ "messages": self.messages,
305
+ "offset": self.offset,
306
+ "sep": self.sep,
307
+ "sep2": self.sep2,
308
+ }
309
+
310
+
311
+ conv_vicuna_v0 = Conversation(
312
+ system="A chat between a curious human and an artificial intelligence assistant. " "The assistant gives helpful, detailed, and polite answers to the human's questions.",
313
+ roles=("Human", "Assistant"),
314
+ messages=[
315
+ ["Human", "What are the key differences between renewable and non-renewable energy sources?"],
316
+ [
317
+ "Assistant",
318
+ "Renewable energy sources are those that can be replenished naturally in a relatively "
319
+ "short amount of time, such as solar, wind, hydro, geothermal, and biomass. "
320
+ "Non-renewable energy sources, on the other hand, are finite and will eventually be "
321
+ "depleted, such as coal, oil, and natural gas. Here are some key differences between "
322
+ "renewable and non-renewable energy sources:\n"
323
+ "1. Availability: Renewable energy sources are virtually inexhaustible, while non-renewable "
324
+ "energy sources are finite and will eventually run out.\n"
325
+ "2. Environmental impact: Renewable energy sources have a much lower environmental impact "
326
+ "than non-renewable sources, which can lead to air and water pollution, greenhouse gas emissions, "
327
+ "and other negative effects.\n"
328
+ "3. Cost: Renewable energy sources can be more expensive to initially set up, but they typically "
329
+ "have lower operational costs than non-renewable sources.\n"
330
+ "4. Reliability: Renewable energy sources are often more reliable and can be used in more remote "
331
+ "locations than non-renewable sources.\n"
332
+ "5. Flexibility: Renewable energy sources are often more flexible and can be adapted to different "
333
+ "situations and needs, while non-renewable sources are more rigid and inflexible.\n"
334
+ "6. Sustainability: Renewable energy sources are more sustainable over the long term, while "
335
+ "non-renewable sources are not, and their depletion can lead to economic and social instability.\n",
336
+ ],
337
+ ],
338
+ offset=2,
339
+ sep_style=SeparatorStyle.SINGLE,
340
+ sep="###",
341
+ )
342
+
343
+ conv_vicuna_v1 = Conversation(
344
+ system="A chat between a curious user and an artificial intelligence assistant. " "The assistant gives helpful, detailed, and polite answers to the user's questions.",
345
+ roles=("USER", "ASSISTANT"),
346
+ version="v1",
347
+ messages=[],
348
+ offset=0,
349
+ sep_style=SeparatorStyle.TWO,
350
+ sep=" ",
351
+ sep2="</s>",
352
+ )
353
+
354
+ conv_llama_2 = Conversation(
355
+ system="""You are a helpful, respectful and honest assistant. Always answer as helpfully as possible, while being safe. Your answers should not include any harmful, unethical, racist, sexist, toxic, dangerous, or illegal content. Please ensure that your responses are socially unbiased and positive in nature.
356
+
357
+ If a question does not make any sense, or is not factually coherent, explain why instead of answering something not correct. If you don't know the answer to a question, please don't share false information.""",
358
+ roles=("USER", "ASSISTANT"),
359
+ version="llama_v2",
360
+ messages=[],
361
+ offset=0,
362
+ sep_style=SeparatorStyle.LLAMA_2,
363
+ sep="<s>",
364
+ sep2="</s>",
365
+ )
366
+
367
+ conv_llava_llama_2 = Conversation(
368
+ system="You are a helpful language and vision assistant. " "You are able to understand the visual content that the user provides, " "and assist the user with a variety of tasks using natural language.",
369
+ roles=("USER", "ASSISTANT"),
370
+ version="llama_v2",
371
+ messages=[],
372
+ offset=0,
373
+ sep_style=SeparatorStyle.LLAMA_2,
374
+ sep="<s>",
375
+ sep2="</s>",
376
+ )
377
+
378
+ # conv_llava_llama_3 = Conversation(
379
+ # system="You are a helpful language and vision assistant. " "You are able to understand the visual content that the user provides, " "and assist the user with a variety of tasks using natural language.",
380
+ # roles=("user", "assistant"),
381
+ # version="llama_v3",
382
+ # messages=[],
383
+ # offset=0,
384
+ # sep="<|eot_id|>",
385
+ # sep_style=SeparatorStyle.LLAMA_3,
386
+ # tokenizer_id="meta-llama/Meta-Llama-3-8B-Instruct",
387
+ # tokenizer=AutoTokenizer.from_pretrained("meta-llama/Meta-Llama-3-8B-Instruct"),
388
+ # stop_token_ids=[128009],
389
+ # )
390
+
391
+ conv_mistral_instruct = Conversation(
392
+ system="",
393
+ roles=("USER", "ASSISTANT"),
394
+ version="llama_v2",
395
+ messages=[],
396
+ offset=0,
397
+ sep_style=SeparatorStyle.LLAMA_2,
398
+ sep="",
399
+ sep2="</s>",
400
+ )
401
+
402
+ conv_llava_llama_2_simple = Conversation(
403
+ system="Answer the questions about the visual content that the user provides.",
404
+ roles=("USER", "ASSISTANT"),
405
+ version="llama_v2",
406
+ messages=[],
407
+ offset=0,
408
+ sep_style=SeparatorStyle.LLAMA_2,
409
+ sep="<s>",
410
+ sep2="</s>",
411
+ )
412
+
413
+ conv_llava_llama_2_mmtag = Conversation(
414
+ system="Answer the questions about the visual content that the user provides." "The visual content will be provided with the following format: <Image>visual content</Image>.",
415
+ roles=("USER", "ASSISTANT"),
416
+ version="llama_v2_mmtag",
417
+ messages=[],
418
+ offset=0,
419
+ sep_style=SeparatorStyle.LLAMA_2,
420
+ sep="<s>",
421
+ sep2="</s>",
422
+ )
423
+
424
+ conv_mpt = Conversation(
425
+ system="""<|im_start|>system
426
+ A conversation between a user and an LLM-based AI assistant. The assistant gives helpful and honest answers.""",
427
+ roles=("<|im_start|>user\n", "<|im_start|>assistant\n"),
428
+ version="mpt",
429
+ messages=[],
430
+ offset=0,
431
+ sep_style=SeparatorStyle.MPT,
432
+ sep="<|im_end|>",
433
+ )
434
+
435
+ conv_qwen = Conversation(
436
+ system="""<|im_start|>system
437
+ You are a helpful assistant.""",
438
+ roles=("<|im_start|>user", "<|im_start|>assistant"),
439
+ version="qwen",
440
+ messages=[],
441
+ offset=0,
442
+ sep_style=SeparatorStyle.CHATML,
443
+ sep="<|im_end|>",
444
+ )
445
+
446
+
447
+
448
+ conv_internlm_2 = Conversation(
449
+ system="""<|im_start|>system
450
+ You are a helpful assistant.""",
451
+ roles=("<|im_start|>user", "<|im_start|>assistant"),
452
+ version="internlm_2",
453
+ messages=[],
454
+ offset=0,
455
+ sep_style=SeparatorStyle.CHATML,
456
+ sep="<|im_end|>",
457
+ )
458
+
459
+ conv_gemma_instruct = Conversation(system="", roles=("<start_of_turn>user\n", "<start_of_turn>model\n"), version="gemma", messages=[], offset=0, sep_style=SeparatorStyle.GEMMA, sep="<end_of_turn>\n")
460
+
461
+ conv_llava_plain = Conversation(
462
+ system="",
463
+ roles=("", ""),
464
+ messages=[],
465
+ offset=0,
466
+ sep_style=SeparatorStyle.PLAIN,
467
+ sep="\n",
468
+ )
469
+
470
+ conv_llava_v0 = Conversation(
471
+ system="A chat between a curious human and an artificial intelligence assistant. " "The assistant gives helpful, detailed, and polite answers to the human's questions.",
472
+ roles=("Human", "Assistant"),
473
+ messages=[],
474
+ offset=0,
475
+ sep_style=SeparatorStyle.SINGLE,
476
+ sep="###",
477
+ )
478
+
479
+ conv_llava_v0_mmtag = Conversation(
480
+ system="A chat between a curious user and an artificial intelligence assistant. "
481
+ "The assistant is able to understand the visual content that the user provides, and assist the user with a variety of tasks using natural language."
482
+ "The visual content will be provided with the following format: <Image>visual content</Image>.",
483
+ roles=("Human", "Assistant"),
484
+ messages=[],
485
+ offset=0,
486
+ sep_style=SeparatorStyle.SINGLE,
487
+ sep="###",
488
+ version="v0_mmtag",
489
+ )
490
+
491
+ conv_llava_v1 = Conversation(
492
+ system="A chat between a curious human and an artificial intelligence assistant. " "The assistant gives helpful, detailed, and polite answers to the human's questions.",
493
+ roles=("USER", "ASSISTANT"),
494
+ version="v1",
495
+ messages=[],
496
+ offset=0,
497
+ sep_style=SeparatorStyle.TWO,
498
+ sep=" ",
499
+ sep2="</s>",
500
+ )
501
+
502
+ conv_llava_v1_mmtag = Conversation(
503
+ system="A chat between a curious user and an artificial intelligence assistant. "
504
+ "The assistant is able to understand the visual content that the user provides, and assist the user with a variety of tasks using natural language."
505
+ "The visual content will be provided with the following format: <Image>visual content</Image>.",
506
+ roles=("USER", "ASSISTANT"),
507
+ messages=[],
508
+ offset=0,
509
+ sep_style=SeparatorStyle.TWO,
510
+ sep=" ",
511
+ sep2="</s>",
512
+ version="v1_mmtag",
513
+ )
514
+
515
+ conv_mistral_orca = Conversation(
516
+ system="""<|im_start|>system
517
+ You are MistralOrca, a large language model trained by Alignment Lab AI. Write out your reasoning step-by-step to be sure you get the right answers!""",
518
+ roles=("<|im_start|>user\n", "<|im_start|>assistant\n"),
519
+ version="mpt",
520
+ messages=[],
521
+ offset=0,
522
+ sep_style=SeparatorStyle.MPT,
523
+ sep="<|im_end|>",
524
+ )
525
+
526
+ conv_mistral_zephyr = Conversation(
527
+ system="""<|system|>
528
+ You are a helpful AI assistant.""",
529
+ roles=("<|user|>\n", "<|assistant|>\n"),
530
+ version="mpt",
531
+ messages=[],
532
+ offset=0,
533
+ sep_style=SeparatorStyle.MPT,
534
+ sep="</s>",
535
+ )
536
+
537
+ conv_mistral_direct = Conversation(
538
+ system="""<|im_start|>system
539
+ Answer the questions.""",
540
+ roles=("<|im_start|>user\n", "<|im_start|>assistant\n"),
541
+ version="mpt",
542
+ messages=[],
543
+ offset=0,
544
+ sep_style=SeparatorStyle.MPT,
545
+ sep="<|im_end|>",
546
+ )
547
+
548
+ conv_chatml_direct = Conversation(
549
+ system="""<|im_start|>system
550
+ Answer the questions.""",
551
+ roles=("<|im_start|>user\n", "<|im_start|>assistant\n"),
552
+ version="mpt",
553
+ messages=[],
554
+ offset=0,
555
+ sep_style=SeparatorStyle.MPT,
556
+ sep="<|im_end|>",
557
+ )
558
+
559
+ default_conversation = conv_vicuna_v0
560
+ conv_templates = {
561
+ "default": conv_vicuna_v0,
562
+ "v0": conv_vicuna_v0,
563
+ "v1": conv_vicuna_v1,
564
+ "vicuna_v1": conv_vicuna_v1,
565
+ "llama_2": conv_llama_2,
566
+ "mistral_instruct": conv_mistral_instruct,
567
+ "mistral_orca": conv_mistral_orca,
568
+ "mistral_zephyr": conv_mistral_zephyr,
569
+ "mistral_direct": conv_mistral_direct,
570
+ "plain": conv_llava_plain,
571
+ "v0_plain": conv_llava_plain,
572
+ "chatml_direct": conv_chatml_direct,
573
+ "llava_v0": conv_llava_v0,
574
+ "llava_v0_mmtag": conv_llava_v0_mmtag,
575
+ "llava_v1": conv_llava_v1,
576
+ "llava_v1_mmtag": conv_llava_v1_mmtag,
577
+ "llava_llama_2": conv_llava_llama_2,
578
+ # "llava_llama_3": conv_llava_llama_3,
579
+ "llava_llama_2_simple": conv_llava_llama_2_simple,
580
+ "llava_llama_2_mmtag": conv_llava_llama_2_mmtag,
581
+ "llava_mistral_instruct": conv_mistral_instruct,
582
+ "mpt": conv_mpt,
583
+ "qwen_1_5": conv_qwen,
584
+ "qwen_2": conv_qwen,
585
+ "internlm_2": conv_internlm_2,
586
+ "gemma_instruct": conv_gemma_instruct,
587
+ }
588
+
589
+
590
+ if __name__ == "__main__":
591
+ print(default_conversation.get_prompt())
592
+ print(default_conversation)
generation_config.json ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "_attn_implementation": "flash_attention_2",
3
+ "bos_token_id": 151643,
4
+ "do_sample": true,
5
+ "eos_token_id": [
6
+ 151645,
7
+ 151643
8
+ ],
9
+ "pad_token_id": 151643,
10
+ "repetition_penalty": 1.05,
11
+ "temperature": 0.7,
12
+ "top_k": 20,
13
+ "top_p": 0.8,
14
+ "transformers_version": "4.39.2"
15
+ }
merges.txt ADDED
The diff for this file is too large to render. See raw diff
 
mm_projector_builder.py ADDED
@@ -0,0 +1,165 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import torch
2
+ import torch.nn as nn
3
+ from typing import Callable, Tuple
4
+
5
+
6
+ def bipartite_soft_matching(
7
+ metric: torch.Tensor,
8
+ r: int,
9
+ ) -> Tuple[Callable, Callable]:
10
+ """
11
+ Applies ToMe with a balanced matching set (50%, 50%).
12
+
13
+ Input size is [batch, tokens, channels].
14
+ r indicates the number of tokens to remove (max 50% of tokens).
15
+ """
16
+ protected = 0
17
+
18
+ t = metric.shape[1]
19
+ r = min(r, (t - protected) // 2)
20
+
21
+ assert r > 0, r
22
+
23
+ with torch.no_grad():
24
+ metric = metric / metric.norm(dim=-1, keepdim=True)
25
+ a, b = metric[..., ::2, :], metric[..., 1::2, :]
26
+ scores = a @ b.transpose(-1, -2)
27
+
28
+ node_max, node_idx = scores.max(dim=-1)
29
+ edge_idx = node_max.argsort(dim=-1, descending=True)[..., None]
30
+
31
+ unm_idx = edge_idx[..., r:, :] # Unmerged Tokens
32
+ src_idx = edge_idx[..., :r, :] # Merged Tokens
33
+ dst_idx = node_idx[..., None].gather(dim=-2, index=src_idx)
34
+
35
+ def merge(x: torch.Tensor, mode="mean") -> torch.Tensor:
36
+ src, dst = x[..., ::2, :], x[..., 1::2, :]
37
+ n, t1, c = src.shape
38
+ unm = src.gather(dim=-2, index=unm_idx.expand(n, t1 - r, c))
39
+ src = src.gather(dim=-2, index=src_idx.expand(n, r, c))
40
+ dst = dst.scatter_add(-2, dst_idx.expand(n, r, c), src) # , reduce=mode)
41
+
42
+ return torch.cat([unm, dst], dim=1)
43
+
44
+ def unmerge(x: torch.Tensor) -> torch.Tensor:
45
+ unm_len = unm_idx.shape[1]
46
+ unm, dst = x[..., :unm_len, :], x[..., unm_len:, :]
47
+ n, _, c = unm.shape
48
+
49
+ src = dst.gather(dim=-2, index=dst_idx.expand(n, r, c))
50
+
51
+ out = torch.zeros(n, metric.shape[1], c, device=x.device, dtype=x.dtype)
52
+
53
+ out[..., 1::2, :] = dst
54
+ out.scatter_(dim=-2, index=(2 * unm_idx).expand(n, unm_len, c), src=unm)
55
+ out.scatter_(dim=-2, index=(2 * src_idx).expand(n, r, c), src=src)
56
+
57
+ return out
58
+
59
+ return merge, unmerge
60
+
61
+
62
+ def merge_wavg(
63
+ merge: Callable, x: torch.Tensor, size: torch.Tensor = None
64
+ ) -> Tuple[torch.Tensor, torch.Tensor]:
65
+ """
66
+ Applies the merge function by taking a weighted average based on token size.
67
+ Returns the merged tensor and the new token sizes.
68
+ """
69
+ if size is None:
70
+ size = torch.ones_like(x[..., 0, None])
71
+
72
+ x = merge(x * size, mode="sum")
73
+ size = merge(size, mode="sum")
74
+
75
+ x = x / size
76
+ return x, size
77
+
78
+
79
+
80
+
81
+ class ToMe16_mlp_hd64(nn.Module):
82
+ def __init__(self, config, vision_cfg):
83
+ super().__init__()
84
+ self._config = config
85
+ self.mm_hidden_size = config.mm_hidden_size
86
+ self.hw = vision_cfg.image_size // vision_cfg.patch_size
87
+ self.num_attention_heads = vision_cfg.num_attention_heads
88
+ self.mlp = nn.Sequential(nn.Linear(config.mm_hidden_size, config.hidden_size),
89
+ nn.GELU(),
90
+ nn.Linear(config.hidden_size, config.hidden_size))
91
+ self.max_pos_hw = self.hw
92
+ self.max_pos_num_frames = config.mm_pos_num_frames
93
+ self.num_image_patches_per_side = 8
94
+ self.num_frame_patches_per_side = 4
95
+
96
+ def merge_tokens(self, x, target_num_token):
97
+ r"""
98
+ x = torch.randn(10, 2560, c)
99
+ x = merge_tokens(x, r_merge_list=[1280])
100
+ """
101
+ size = None
102
+ b, p, c = x.shape
103
+ tmp_p = p
104
+ r_merge_list = []
105
+ assert tmp_p > target_num_token, f"{tmp_p} should greater than {target_num_token}"
106
+ while tmp_p != target_num_token:
107
+ if tmp_p - target_num_token <= (tmp_p // 2):
108
+ r_merge_list.append(tmp_p - target_num_token)
109
+ break
110
+ else:
111
+ r_merge_list.append(tmp_p // 2)
112
+ tmp_p = tmp_p - (tmp_p // 2)
113
+
114
+
115
+ head = self.num_attention_heads
116
+
117
+ dim = c // head
118
+ for r in r_merge_list:
119
+ metric = x.reshape(b, p, head, dim).mean(2) # [b, p, c//head]
120
+ merge, _ = bipartite_soft_matching(
121
+ metric,
122
+ r
123
+ )
124
+ x, size = merge_wavg(merge, x, size)
125
+ _, p, _ = x.shape
126
+
127
+ return x
128
+
129
+
130
+
131
+ def forward(self, x, compress=False, local_num_frames=-1): # 单帧64
132
+ height = width = self.hw
133
+ assert height * width == x.shape[1]
134
+
135
+ if local_num_frames != -1 and local_num_frames != 1:
136
+ assert compress is True
137
+ if compress:
138
+ if local_num_frames != -1:
139
+ num_frames = local_num_frames
140
+ x = x.reshape(x.shape[0] // local_num_frames, -1, x.shape[-1])
141
+ else:
142
+ num_frames = x.shape[0]
143
+ x = x.reshape(1, -1, x.shape[-1])
144
+ num_tome_tokens = 16 * num_frames
145
+ else:
146
+ num_tome_tokens = 64
147
+
148
+ x = self.merge_tokens(x, target_num_token=num_tome_tokens)
149
+ x = self.mlp(x)
150
+ return x
151
+
152
+ @property
153
+ def config(self):
154
+ return {"mm_projector_type": "tome16_mlp_hd64"}
155
+
156
+
157
+
158
+
159
+ def build_vision_projector(config, delay_load=False, **kwargs):
160
+ projector_type = getattr(config, "mm_projector_type", "linear")
161
+
162
+ if projector_type == 'tome16_mlp_hd64':
163
+ return ToMe16_mlp_hd64(config, kwargs["vision_cfg"])
164
+
165
+ raise ValueError(f"Unknown projector type: {projector_type}")
mm_utils.py ADDED
@@ -0,0 +1,855 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from PIL import Image
2
+ from io import BytesIO
3
+ import base64
4
+ import math
5
+ import ast
6
+ import re
7
+ import torch
8
+ from transformers import StoppingCriteria
9
+ from .constants import IMAGE_TOKEN_INDEX
10
+ import random
11
+ import os
12
+ import io
13
+ import av
14
+ import cv2
15
+ import imageio
16
+ from decord import VideoReader
17
+ import numpy as np
18
+ from torchvision.transforms.functional import pil_to_tensor
19
+
20
+
21
+ ######################## load video ########################
22
+
23
+ def get_index(num_frames, num_segments):
24
+ seg_size = float(num_frames - 1) / num_segments
25
+ start = int(seg_size / 2)
26
+ offsets = np.array([
27
+ start + int(np.round(seg_size * idx)) for idx in range(num_segments)
28
+ ])
29
+ return offsets
30
+
31
+
32
+ def pts_to_secs(pts: int, time_base: float, start_pts: int) -> float:
33
+ """
34
+ Converts a present time with the given time base and start_pts offset to seconds.
35
+
36
+ Returns:
37
+ time_in_seconds (float): The corresponding time in seconds.
38
+
39
+ https://github.com/facebookresearch/pytorchvideo/blob/main/pytorchvideo/data/utils.py#L54-L64
40
+ """
41
+ if pts == math.inf:
42
+ return math.inf
43
+
44
+ return int(pts - start_pts) * time_base
45
+
46
+
47
+ def get_pyav_video_duration(video_reader):
48
+ video_stream = video_reader.streams.video[0]
49
+ video_duration = pts_to_secs(
50
+ video_stream.duration,
51
+ video_stream.time_base,
52
+ video_stream.start_time
53
+ )
54
+ return float(video_duration)
55
+
56
+
57
+
58
+ def get_frame_indices(num_frames, vlen, sample='middle', fix_start=None, input_fps=1, min_num_frames=1, max_num_frames=-1, local_num_frames=8):
59
+
60
+ if min_num_frames > vlen:
61
+ if sample == 'dynamic_fps1':
62
+ min_num_frames = (vlen // local_num_frames) * local_num_frames
63
+ else:
64
+ min_num_frames = vlen
65
+
66
+
67
+ if sample == 'dynamic_fps1':
68
+
69
+ duration = float(vlen) / input_fps
70
+ num_segments = int(duration // local_num_frames)
71
+ if num_segments == 0:
72
+ num_frames = local_num_frames
73
+ else:
74
+ num_frames = local_num_frames * num_segments
75
+
76
+ if max_num_frames > 0:
77
+ num_frames = min(num_frames, max_num_frames)
78
+ sample = "middle" # NOTE
79
+
80
+ # logger.info(f"? is OK (img), duation={duration} frames={num_frames}!!!!")
81
+
82
+ num_frames = max(min_num_frames, num_frames)
83
+
84
+ # print(f"\033[0;31m vlen={vlen}, input_fps={input_fps} num_frames={num_frames} \033[0m")
85
+
86
+ if sample in ["rand", "middle"]: # uniform sampling
87
+ acc_samples = min(num_frames, vlen)
88
+ # split the video into `acc_samples` intervals, and sample from each interval.
89
+ intervals = np.linspace(start=0, stop=vlen, num=acc_samples + 1).astype(int)
90
+ ranges = []
91
+ for idx, interv in enumerate(intervals[:-1]):
92
+ ranges.append((interv, intervals[idx + 1] - 1))
93
+ if sample == 'rand':
94
+ try:
95
+ frame_indices = [random.choice(range(x[0], x[1])) for x in ranges]
96
+ except:
97
+ frame_indices = np.random.permutation(vlen)[:acc_samples]
98
+ frame_indices.sort()
99
+ frame_indices = list(frame_indices)
100
+ elif fix_start is not None:
101
+ frame_indices = [x[0] + fix_start for x in ranges]
102
+ elif sample == 'middle':
103
+ frame_indices = [(x[0] + x[1]) // 2 for x in ranges]
104
+ else:
105
+ raise NotImplementedError
106
+
107
+ if len(frame_indices) < num_frames: # padded with last frame
108
+ padded_frame_indices = [frame_indices[-1]] * num_frames
109
+ padded_frame_indices[:len(frame_indices)] = frame_indices
110
+ frame_indices = padded_frame_indices
111
+ elif "fps" in sample: # fps0.5, sequentially sample frames at 0.5 fps
112
+ output_fps = float(sample[3:])
113
+ duration = float(vlen) / input_fps
114
+ delta = 1 / output_fps # gap between frames, this is also the clip length each frame represents
115
+ frame_seconds = np.arange(0 + delta / 2, duration + delta / 2, delta)
116
+ frame_indices = np.around(frame_seconds * input_fps).astype(int)
117
+ frame_indices = [e for e in frame_indices if e < vlen]
118
+ if max_num_frames > 0 and len(frame_indices) > max_num_frames:
119
+ frame_indices = frame_indices[:max_num_frames]
120
+ # frame_indices = np.linspace(0 + delta / 2, duration + delta / 2, endpoint=False, num=max_num_frames)
121
+ else:
122
+ raise ValueError(f"Not support sample type: {sample}")
123
+
124
+
125
+ return frame_indices
126
+
127
+
128
+ def read_frames_av(video_path, num_frames, sample='rand', client=None, fix_start=None, min_num_frames=1, max_num_frames=-1, clip=None, local_num_frames=8):
129
+ if clip is not None:
130
+ raise NotImplementedError("av don't support clip!!!")
131
+ if 's3://' in video_path:
132
+ video_bytes = client.get(video_path)
133
+ byteio = io.BytesIO(video_bytes)
134
+ byteio.seek(0)
135
+ reader = av.open(byteio)
136
+ else:
137
+ byteio = None
138
+ reader = av.open(video_path)
139
+ frames = [f.to_rgb().to_ndarray() for f in reader.decode(video=0)]
140
+ vlen = len(frames)
141
+ duration = get_pyav_video_duration(reader)
142
+ fps = vlen / float(duration)
143
+ frame_indices = get_frame_indices(
144
+ num_frames, vlen, sample=sample, fix_start=fix_start,
145
+ input_fps=fps, min_num_frames=min_num_frames, max_num_frames=max_num_frames, local_num_frames=local_num_frames
146
+ )
147
+ frames = np.stack([frames[idx] for idx in frame_indices]) # (T, H, W, C), torch.uint8
148
+ # frames = frames.permute(0, 3, 1, 2) # (T, C, H, W), torch.uint8
149
+ if byteio != None:
150
+ byteio.close()
151
+
152
+ reader.close()
153
+
154
+ return frames, frame_indices, float(fps), duration
155
+
156
+
157
+ def read_frames_gif(
158
+ video_path, num_frames, sample='rand', fix_start=None,
159
+ min_num_frames=1, max_num_frames=-1, client=None, clip=None, local_num_frames=8
160
+ ):
161
+ if clip is not None:
162
+ raise NotImplementedError("Gif don't support clip!!!")
163
+ if 's3://' in video_path:
164
+ video_bytes = client.get(video_path)
165
+ byteio = io.BytesIO(video_bytes)
166
+ gif = imageio.get_reader(byteio)
167
+ else:
168
+ byteio = None
169
+ gif = imageio.get_reader(video_path)
170
+ vlen = len(gif)
171
+ fps = 1.
172
+ duration = vlen / fps
173
+ frame_indices = get_frame_indices(
174
+ num_frames, vlen, sample=sample, fix_start=fix_start,
175
+ min_num_frames=min_num_frames,
176
+ max_num_frames=max_num_frames, local_num_frames=local_num_frames,
177
+ input_fps=fps
178
+ )
179
+ frames = []
180
+
181
+ min_h = min_w = 100000
182
+ hw_set = set()
183
+ for index, frame in enumerate(gif):
184
+ # for index in frame_idxs:
185
+ if index in frame_indices:
186
+ frame = cv2.cvtColor(frame, cv2.COLOR_RGBA2RGB)
187
+ frame = frame.astype(np.uint8)
188
+ # # (H x W x C) to (C x H x W)
189
+ # frame = frame.permute(2, 0, 1)
190
+ frames.append(frame)
191
+ hw_set.add(frame.shape)
192
+ if frame.shape[0] < min_h:
193
+ min_h = frame.shape[0]
194
+ if frame.shape[1] < min_w:
195
+ min_w = frame.shape[1]
196
+ # print(hw_set, min_h, min_w)
197
+ if len(hw_set) > 1:
198
+ frames = [i[:min_h, :min_w] for i in frames]
199
+
200
+ frames = np.stack(frames) # .float() / 255
201
+
202
+ if byteio != None:
203
+ byteio.close()
204
+
205
+ return frames, frame_indices, float(fps), duration # for tgif
206
+
207
+
208
+
209
+ def read_frames_decord(
210
+ video_path, num_frames, sample='rand', fix_start=None, min_num_frames=1,
211
+ max_num_frames=-1, client=None, clip=None, local_num_frames=8
212
+ ):
213
+
214
+ if video_path.endswith('.avi'):
215
+ return read_frames_av(video_path=video_path, num_frames=num_frames, sample=sample,
216
+ fix_start=fix_start, min_num_frames=min_num_frames, max_num_frames=max_num_frames,
217
+ client=client, clip=clip, local_num_frames=local_num_frames)
218
+ if 's3://' in video_path:
219
+ video_bytes = client.get(video_path)
220
+ if video_bytes is None or len(video_bytes) == 0:
221
+ raise ValueError(f"Can't read byte from {video_path}!")
222
+ byteio = io.BytesIO(video_bytes)
223
+ video_reader = VideoReader(byteio, num_threads=1)
224
+ else:
225
+ byteio = None
226
+ video_reader = VideoReader(video_path, num_threads=1)
227
+ vlen = len(video_reader)
228
+ fps = video_reader.get_avg_fps()
229
+ duration = vlen / float(fps)
230
+
231
+
232
+ if clip:
233
+ start, end = clip
234
+ start = max(0, start)
235
+ end = min(duration - 0.1, end)
236
+ duration = end - start
237
+ vlen = int(duration * fps)
238
+ start_index = int(start * fps)
239
+
240
+ frame_indices = get_frame_indices(
241
+ num_frames, vlen, sample=sample, fix_start=fix_start,
242
+ input_fps=fps, min_num_frames=min_num_frames, max_num_frames=max_num_frames, local_num_frames=local_num_frames
243
+ )
244
+ if clip:
245
+ frame_indices = [f + start_index for f in frame_indices]
246
+
247
+ # print(fps, frame_indices)
248
+ frames = video_reader.get_batch(frame_indices).asnumpy() # (T, H, W, C), torch.uint8
249
+ # https://github.com/dmlc/decord/issues/208
250
+ video_reader.seek(0)
251
+
252
+ if byteio != None:
253
+ byteio.close()
254
+ # frames = frames.permute(0, 3, 1, 2) # (T, C, H, W), torch.uint8
255
+ return frames, frame_indices, float(fps), duration
256
+
257
+
258
+
259
+ def read_frames_img(
260
+ video_path, num_frames, sample='rand', fix_start=None, min_num_frames=1,
261
+ max_num_frames=-1, client=None, clip=None, local_num_frames=8
262
+ ):
263
+ def extract_frame_number(filename):
264
+ # Extract the numeric part from the filename using regular expressions
265
+ if filename.endswith('.jpg'):
266
+ match = re.search(r'_(\d+).jpg$', filename)
267
+ elif filename.endswith('.jpeg'):
268
+ match = re.search(r'_(\d+).jpeg$', filename)
269
+ elif filename.endswith('.png'):
270
+ match = re.search(r'_(\d+).png$', filename)
271
+ else:
272
+ raise NotImplementedError(f"Wrong filename: {filename}")
273
+
274
+ return int(match.group(1)) if match else -1
275
+
276
+
277
+ def sort_frames(frame_paths):
278
+ # Extract filenames from each path and sort by their numeric part
279
+ return sorted(frame_paths, key=lambda x: extract_frame_number(os.path.basename(x)))
280
+
281
+ # img_list=[]
282
+
283
+ if "s3://" in video_path:
284
+ img_list = sort_frames(client.list(video_path))
285
+ else:
286
+ img_list = sort_frames(list(os.listdir(video_path)))
287
+
288
+
289
+ if 'tvqa' in video_path.lower():
290
+ fps = 3.0
291
+ else:
292
+ fps = 1.0
293
+
294
+ if clip is not None:
295
+ start = float(clip[0])
296
+ end = float(clip[1])
297
+ start = max(0, start)
298
+ end = min(len(img_list) / fps, end)
299
+ vlen = (end - start) * fps
300
+ else:
301
+ vlen = len(img_list)
302
+
303
+ duration = vlen / fps
304
+
305
+ if min_num_frames > vlen:
306
+ if sample == 'dynamic_fps1':
307
+ min_num_frames = (vlen // local_num_frames) * local_num_frames
308
+ else:
309
+ min_num_frames = vlen
310
+
311
+ if sample == 'dynamic_fps1':
312
+ num_segments = int(duration // local_num_frames)
313
+ if num_segments == 0:
314
+ num_frames = local_num_frames
315
+ else:
316
+ num_frames = local_num_frames * num_segments
317
+ num_frames = min(num_frames, max_num_frames)
318
+ num_frames = max(min_num_frames, num_frames)
319
+
320
+ num_frames = int(num_frames)
321
+ if clip is not None:
322
+ def _get_index_by_time(start_sec, end_sec, num_segments=8, fps=1., max_frame=9999):
323
+ start_idx = max(1, round(start_sec * fps))
324
+ end_idx = min(round(end_sec * fps), max_frame)
325
+ seg_size = float(end_idx - start_idx) / (num_segments - 1)
326
+ offsets = np.array([start_idx + int(np.round(seg_size * idx)) for idx in range(num_segments)])
327
+ return offsets
328
+
329
+ frame_indices = _get_index_by_time(float(clip[0]), float(clip[1]), num_segments=num_frames, fps=fps, max_frame=len(img_list)-1)
330
+ else:
331
+ frame_indices = get_frame_indices(
332
+ num_frames, vlen, sample=sample, fix_start=fix_start,
333
+ min_num_frames=min_num_frames,
334
+ max_num_frames=max_num_frames, local_num_frames=local_num_frames
335
+ )
336
+
337
+ imgs = []
338
+ for idx in frame_indices:
339
+ frame_fname = os.path.join(video_path, img_list[idx])
340
+ if "s3://" in video_path:
341
+ img_bytes = client.get(frame_fname)
342
+ else:
343
+ with open(frame_fname, 'rb') as f:
344
+ img_bytes = f.read()
345
+ img_np = np.frombuffer(img_bytes, np.uint8)
346
+ img = cv2.imdecode(img_np, cv2.IMREAD_COLOR)
347
+ cv2.cvtColor(img, cv2.COLOR_BGR2RGB, img)
348
+ imgs.append(img)
349
+
350
+ frames = np.array(imgs, dtype=np.uint8)
351
+
352
+
353
+ return frames, frame_indices, fps, duration
354
+
355
+
356
+
357
+ VIDEO_READER_FUNCS = {
358
+ 'av': read_frames_av,
359
+ 'decord': read_frames_decord,
360
+ 'gif': read_frames_gif,
361
+ 'img': read_frames_img,
362
+ 'frame': read_frames_img
363
+ }
364
+
365
+
366
+
367
+ def load_video(video_path, max_num_frames=512, media_dict=None): #, media_dict):
368
+
369
+ if media_dict is None:
370
+ media_dict = {'video_read_type': 'decord'}
371
+
372
+ if type(video_path) != str:
373
+ assert len(video_path) == 1, video_path
374
+ video_path = video_path[0]
375
+
376
+ if 'start' in media_dict:
377
+ clip = [media_dict['start'], media_dict['end']]
378
+ else:
379
+ clip = None
380
+
381
+ if 's3://' in video_path:
382
+ from petrel_client.client import Client
383
+ client = Client(conf_path='~/petreloss.conf')
384
+ else:
385
+ client = None
386
+
387
+ frames, frame_indices, fps, duration = VIDEO_READER_FUNCS[media_dict['video_read_type']](video_path=video_path, num_frames=max_num_frames, sample='dynamic_fps1', fix_start=None, min_num_frames=64, max_num_frames=max_num_frames, client=client, clip=clip, local_num_frames=8)
388
+
389
+ sec = [str(round(f / fps, 1)) for f in frame_indices]
390
+
391
+ msg = f"\nThe video lasts for {duration:.2f} seconds, and {len(sec)} frames are uniformly sampled from it. "
392
+
393
+ return frames, msg
394
+
395
+
396
+ ######################## load video ########################
397
+
398
+
399
+ def resize_and_center_crop(image, shortest_edge_length):
400
+ # Calculate new dimensions and resize
401
+ aspect_ratio = float(image.width) / float(image.height)
402
+ if aspect_ratio > 1:
403
+ new_width = int(shortest_edge_length * aspect_ratio)
404
+ new_height = shortest_edge_length
405
+ else:
406
+ new_width = shortest_edge_length
407
+ new_height = int(shortest_edge_length / aspect_ratio)
408
+ resized_image = image.resize((new_width, new_height), Image.ANTIALIAS)
409
+
410
+ # Calculate the position and perform the center crop
411
+ left = (new_width - shortest_edge_length) / 2
412
+ top = (new_height - shortest_edge_length) / 2
413
+ right = (new_width + shortest_edge_length) / 2
414
+ bottom = (new_height + shortest_edge_length) / 2
415
+ cropped_image = resized_image.crop((left, top, right, bottom))
416
+
417
+ return cropped_image
418
+
419
+
420
+ def auto_pad_images(image, grid_params):
421
+ assert isinstance(image, Image.Image), "Input should be a Pillow Image"
422
+ assert len(grid_params) > 0, "Grid parameters should not be empty"
423
+
424
+ # Step 1: Calculate and find the closest aspect ratio
425
+ input_width, input_height = image.size
426
+ input_aspect_ratio = input_width / input_height
427
+ candidate_resolutions = [(w / h, w, h) for w in grid_params for h in grid_params]
428
+ closest_aspect_ratio = min(candidate_resolutions, key=lambda x: abs(input_aspect_ratio - x[0]))
429
+
430
+ candidate_resolutions = [(x[1], x[2]) for x in candidate_resolutions if abs(x[0] - closest_aspect_ratio[0]) < 1e-3]
431
+
432
+ target_resolution = min(candidate_resolutions, key=lambda res: abs(max(input_width, input_height) / max(res) - 1))
433
+
434
+ resize_width, resize_height = target_resolution
435
+ if input_width > input_height:
436
+ resize_height = int(resize_width / input_aspect_ratio)
437
+ else:
438
+ resize_width = int(resize_height * input_aspect_ratio)
439
+ resized_image = image.resize((resize_width, resize_height), Image.ANTIALIAS)
440
+
441
+ # Step 5: Pad the resized image if necessary to match the target resolution
442
+ pad_width = target_resolution[0] - resize_width
443
+ pad_height = target_resolution[1] - resize_height
444
+ padded_image = Image.new("RGB", target_resolution, color=(0, 0, 0))
445
+ padded_image.paste(resized_image, (pad_width // 2, pad_height // 2))
446
+
447
+ return padded_image
448
+
449
+
450
+ def extract_patches(image, patch_size, overlap_ratio):
451
+ assert isinstance(image, Image.Image), "Input should be a Pillow Image"
452
+ assert patch_size > 0, "Patch size should be greater than 0"
453
+ assert 0 <= overlap_ratio < 1, "Overlap ratio should be between 0 and 1"
454
+
455
+ W, H = image.size
456
+ patches = []
457
+
458
+ stride = int(patch_size * (1 - overlap_ratio))
459
+
460
+ num_patches_y = (H - patch_size) // stride + 1
461
+ num_patches_x = (W - patch_size) // stride + 1
462
+
463
+ y_start = (H - (num_patches_y - 1) * stride - patch_size) // 2
464
+ x_start = (W - (num_patches_x - 1) * stride - patch_size) // 2
465
+
466
+ for y in range(y_start, y_start + num_patches_y * stride, stride):
467
+ for x in range(x_start, x_start + num_patches_x * stride, stride):
468
+ patch = image.crop((x, y, x + patch_size, y + patch_size))
469
+ patches.append(patch)
470
+
471
+ return patches
472
+
473
+
474
+ def process_highres_image_crop_split(image, data_args, processor=None):
475
+ crop_resolution = data_args.image_crop_resolution
476
+ split_resolution = data_args.image_split_resolution
477
+ if processor is None:
478
+ processor = data_args.image_processor
479
+ image_crop = resize_and_center_crop(image, crop_resolution)
480
+ image_patches = extract_patches(image_crop, patch_size=split_resolution, overlap_ratio=0)
481
+ image_patches = [processor.preprocess(image_patch, return_tensors="pt")["pixel_values"][0] for image_patch in image_patches]
482
+ return torch.stack(image_patches, dim=0)
483
+
484
+
485
+ def process_highres_image(image, processor, grid_pinpoints):
486
+ grid_params = [int(x) for x in grid_pinpoints.split(",")]
487
+ width_height = max(image.size)
488
+ fit_grid_params = [x for x in grid_params if x >= width_height]
489
+ if len(fit_grid_params) == 0:
490
+ select_size = max(grid_params)
491
+ else:
492
+ select_size = min(fit_grid_params)
493
+ # FIXME: always select the 448
494
+ select_size = max(grid_params)
495
+ image_padded = expand2square(image, tuple(int(x * 255) for x in processor.image_mean))
496
+
497
+ # FIXME: this seems to be a bug that it always resizes instead of padding
498
+ image_original_resize = image.resize((processor.size["shortest_edge"], processor.size["shortest_edge"]))
499
+ image_padded = image_padded.resize((select_size, select_size))
500
+ image_patches = extract_patches(image_padded, patch_size=processor.size["shortest_edge"], overlap_ratio=0)
501
+ image_patches = [image_original_resize] + image_patches
502
+ image_patches = [processor.preprocess(image_patch, return_tensors="pt")["pixel_values"][0] for image_patch in image_patches]
503
+ return torch.stack(image_patches, dim=0)
504
+
505
+
506
+ def select_best_resolution(original_size, possible_resolutions, max_resolutions, patch_size):
507
+ """
508
+ Selects the best resolution from a list of possible resolutions based on the original size.
509
+
510
+ Args:
511
+ original_size (tuple): The original size of the image in the format (width, height).
512
+ possible_resolutions (list): A list of possible resolutions in the format [(width1, height1), (width2, height2), ...].
513
+
514
+ Returns:
515
+ tuple: The best fit resolution in the format (width, height).
516
+ """
517
+ original_width, original_height = original_size
518
+ best_fit = None
519
+ max_effective_resolution = 0
520
+ min_wasted_resolution = float("inf")
521
+
522
+ for width, height in possible_resolutions:
523
+ if max_resolutions != None and (width * height != patch_size * patch_size):
524
+ if (width * height+patch_size*patch_size) > max_resolutions: # NOTE 要算一个global
525
+ continue
526
+ # Calculate the downscaled size to keep the aspect ratio
527
+ scale = min(width / original_width, height / original_height)
528
+ downscaled_width, downscaled_height = int(original_width * scale), int(original_height * scale)
529
+
530
+ # Calculate effective and wasted resolutions
531
+ effective_resolution = min(downscaled_width * downscaled_height, original_width * original_height)
532
+ wasted_resolution = (width * height) - effective_resolution
533
+
534
+ if effective_resolution > max_effective_resolution or (effective_resolution == max_effective_resolution and wasted_resolution < min_wasted_resolution):
535
+ max_effective_resolution = effective_resolution
536
+ min_wasted_resolution = wasted_resolution
537
+ best_fit = (width, height)
538
+
539
+ # print(f"original_size={original_size}, possible_resolutions={possible_resolutions}, max_resolutions={max_resolutions}, best_fit={best_fit}")
540
+ assert best_fit is not None, f"Can't find suitable fit in {possible_resolutions} at max:{max_resolutions}"
541
+ return best_fit
542
+
543
+
544
+ def resize_and_pad_image(image, target_resolution):
545
+ """
546
+ Resize and pad an image to a target resolution while maintaining aspect ratio.
547
+
548
+ Args:
549
+ image (PIL.Image.Image): The input image.
550
+ target_resolution (tuple): The target resolution (width, height) of the image.
551
+
552
+ Returns:
553
+ PIL.Image.Image: The resized and padded image.
554
+ """
555
+ original_width, original_height = image.size
556
+ target_width, target_height = target_resolution
557
+
558
+ # Determine which dimension (width or height) to fill
559
+ scale_w = target_width / original_width
560
+ scale_h = target_height / original_height
561
+
562
+ if scale_w < scale_h:
563
+ # Width will be filled completely
564
+ new_width = target_width
565
+ new_height = min(math.ceil(original_height * scale_w), target_height)
566
+ else:
567
+ # Height will be filled completely
568
+ new_height = target_height
569
+ new_width = min(math.ceil(original_width * scale_h), target_width)
570
+
571
+ # Resize the image
572
+ resized_image = image.resize((new_width, new_height))
573
+
574
+ # Create a new image with the target size and paste the resized image onto it
575
+ new_image = Image.new("RGB", (target_width, target_height), (0, 0, 0))
576
+ paste_x = (target_width - new_width) // 2
577
+ paste_y = (target_height - new_height) // 2
578
+ new_image.paste(resized_image, (paste_x, paste_y))
579
+
580
+ return new_image
581
+
582
+
583
+ def divide_to_patches(image, patch_size):
584
+ """
585
+ Divides an image into patches of a specified size.
586
+
587
+ Args:
588
+ image (PIL.Image.Image): The input image.
589
+ patch_size (int): The size of each patch.
590
+
591
+ Returns:
592
+ list: A list of PIL.Image.Image objects representing the patches.
593
+ """
594
+ patches = []
595
+ width, height = image.size
596
+ for i in range(0, height, patch_size):
597
+ for j in range(0, width, patch_size):
598
+ box = (j, i, j + patch_size, i + patch_size)
599
+ patch = image.crop(box)
600
+ patches.append(patch)
601
+
602
+ return patches
603
+
604
+
605
+ def get_anyres_image_grid_shape(image_size, grid_pinpoints, patch_size, max_resolutions=None):
606
+ """
607
+ Calculate the shape of the image patch grid after the preprocessing for images of any resolution.
608
+
609
+ Args:
610
+ image_size (tuple): The size of the input image in the format (width, height).
611
+ grid_pinpoints (str): A string representation of a list of possible resolutions.
612
+ patch_size (int): The size of each image patch.
613
+
614
+ Returns:
615
+ tuple: The shape of the image patch grid in the format (width, height).
616
+ """
617
+ if isinstance(grid_pinpoints, str) and "x" in grid_pinpoints:
618
+ assert patch_size in [224, 336, 384, 448, 512], "patch_size should be in [224, 336, 384, 448, 512]"
619
+ # Use regex to extract the range from the input string
620
+ matches = re.findall(r"\((\d+)x(\d+)\)", grid_pinpoints)
621
+ range_start = tuple(map(int, matches[0]))
622
+ range_end = tuple(map(int, matches[-1]))
623
+ # Generate a matrix of tuples from (range_start[0], range_start[1]) to (range_end[0], range_end[1])
624
+ grid_pinpoints = [(i, j) for i in range(range_start[0], range_end[0] + 1) for j in range(range_start[1], range_end[1] + 1)]
625
+ # Multiply all elements by patch_size
626
+ grid_pinpoints = [[dim * patch_size for dim in pair] for pair in grid_pinpoints]
627
+ if type(grid_pinpoints) is list:
628
+ possible_resolutions = grid_pinpoints
629
+ else:
630
+ possible_resolutions = ast.literal_eval(grid_pinpoints)
631
+ width, height = select_best_resolution(image_size, possible_resolutions, max_resolutions=max_resolutions, patch_size=patch_size)
632
+
633
+ # print("get width/patch size", width, patch_size, flush=True)
634
+
635
+ return width // patch_size, height // patch_size
636
+
637
+
638
+ def process_anyres_image(image, processor, grid_pinpoints):
639
+ """
640
+ Process an image with variable resolutions.
641
+
642
+ Args:
643
+ image (PIL.Image.Image): The input image to be processed.
644
+ processor: The image processor object.
645
+ grid_pinpoints (str): A string representation of a list of possible resolutions.
646
+
647
+ Returns:
648
+ torch.Tensor: A tensor containing the processed image patches.
649
+ """
650
+ raise NotImplementedError
651
+ # Convert grid_pinpoints from string to list
652
+ if isinstance(grid_pinpoints, str) and "x" in grid_pinpoints:
653
+ try:
654
+ patch_size = processor.size[0]
655
+ except Exception as e:
656
+ patch_size = processor.size["shortest_edge"]
657
+ assert patch_size in [224, 336, 384, 448, 512], "patch_size should be in [224, 336, 384, 448, 512]"
658
+ # Use regex to extract the range from the input string
659
+ matches = re.findall(r"\((\d+)x(\d+)\)", grid_pinpoints)
660
+ range_start = tuple(map(int, matches[0]))
661
+ range_end = tuple(map(int, matches[-1]))
662
+ # Generate a matrix of tuples from (range_start[0], range_start[1]) to (range_end[0], range_end[1])
663
+ grid_pinpoints = [(i, j) for i in range(range_start[0], range_end[0] + 1) for j in range(range_start[1], range_end[1] + 1)]
664
+ # Multiply all elements by patch_size
665
+ grid_pinpoints = [[dim * patch_size for dim in pair] for pair in grid_pinpoints]
666
+
667
+ if type(grid_pinpoints) is list:
668
+ possible_resolutions = grid_pinpoints
669
+ else:
670
+ possible_resolutions = ast.literal_eval(grid_pinpoints)
671
+ best_resolution = select_best_resolution(image.size, possible_resolutions)
672
+ image_padded = resize_and_pad_image(image, best_resolution)
673
+
674
+ patches = divide_to_patches(image_padded, processor.crop_size["height"])
675
+
676
+ # FIXME: this seems to be a bug that it resizes instead of pad.
677
+ # but to keep it consistent with previous, i will keep it as it is
678
+ # TODO: uncomment below to ablate with the padding
679
+ if isinstance(processor.size, dict):
680
+ shortest_edge = processor.size["shortest_edge"]
681
+ else:
682
+ shortest_edge = min(processor.size)
683
+ image_original_resize = image.resize((shortest_edge, shortest_edge))
684
+ # image_padded_square = expand2square(image, tuple(int(x*255) for x in processor.image_mean))
685
+ # image_original_resize = image_padded_square.resize((processor.size['shortest_edge'], processor.size['shortest_edge']))
686
+
687
+ image_patches = [image_original_resize] + patches
688
+ image_patches = [processor.preprocess(image_patch, return_tensors="pt")["pixel_values"][0] for image_patch in image_patches]
689
+
690
+ # print("image.size", image.size, "len(image_patches):", len(image_patches), "patch_size:", image_patches[0].shape)
691
+ return torch.stack(image_patches, dim=0)
692
+
693
+ def process_anyres_image_nopad(image, processor, grid_pinpoints):
694
+ """
695
+ Process an image with variable resolutions.
696
+
697
+ Args:
698
+ image (PIL.Image.Image): The input image to be processed.
699
+ processor: The image processor object.
700
+ grid_pinpoints (str): A string representation of a list of possible resolutions.
701
+
702
+ Returns:
703
+ torch.Tensor: A tensor containing the processed image patches.
704
+ """
705
+ # Convert grid_pinpoints from string to list
706
+ try:
707
+ patch_size = processor.size[0]
708
+ except Exception as e:
709
+ patch_size = processor.size["shortest_edge"]
710
+
711
+ assert patch_size in [224, 336, 384, 448, 512], "patch_size should be in [224, 336, 384, 448, 512]"
712
+
713
+ if isinstance(grid_pinpoints, str) and "x" in grid_pinpoints:
714
+
715
+ # Use regex to extract the range from the input string
716
+ matches = re.findall(r"\((\d+)x(\d+)\)", grid_pinpoints)
717
+ range_start = tuple(map(int, matches[0]))
718
+ range_end = tuple(map(int, matches[-1]))
719
+ # Generate a matrix of tuples from (range_start[0], range_start[1]) to (range_end[0], range_end[1])
720
+ grid_pinpoints = [(i, j) for i in range(range_start[0], range_end[0] + 1) for j in range(range_start[1], range_end[1] + 1)]
721
+ # Multiply all elements by patch_size
722
+ grid_pinpoints = [[dim * patch_size for dim in pair] for pair in grid_pinpoints]
723
+
724
+ if type(grid_pinpoints) is list:
725
+ possible_resolutions = grid_pinpoints
726
+ else:
727
+ possible_resolutions = ast.literal_eval(grid_pinpoints)
728
+ best_resolution = select_best_resolution(image.size, possible_resolutions, max_resolutions=None, patch_size=patch_size) # 目前图像无限制
729
+ # image_padded = resize_and_pad_image(image, best_resolution)
730
+
731
+ patches = divide_to_patches(image.resize(best_resolution), patch_size)
732
+
733
+ # FIXME: this seems to be a bug that it resizes instead of pad.
734
+ # but to keep it consistent with previous, i will keep it as it is
735
+ # TODO: uncomment below to ablate with the padding
736
+ if isinstance(processor.size, dict):
737
+ shortest_edge = processor.size["shortest_edge"]
738
+ else:
739
+ shortest_edge = min(processor.size)
740
+ image_original_resize = image.resize((shortest_edge, shortest_edge))
741
+ # image_padded_square = expand2square(image, tuple(int(x*255) for x in processor.image_mean))
742
+ # image_original_resize = image_padded_square.resize((processor.size['shortest_edge'], processor.size['shortest_edge']))
743
+
744
+ image_patches = [image_original_resize] + patches
745
+ image_patches = [processor.preprocess(image_patch, return_tensors="pt")["pixel_values"][0] for image_patch in image_patches]
746
+
747
+ # raise ValueError(f"image.size: {image.size} len(image_patches): {len(image_patches)}, patch_size:, {image_patches[0].shape}, possible_resolutions:, {possible_resolutions}, best: {best_resolution}")
748
+ return torch.stack(image_patches, dim=0)
749
+
750
+
751
+ def load_image_from_base64(image):
752
+ return Image.open(BytesIO(base64.b64decode(image)))
753
+
754
+
755
+ def expand2square(pil_img, background_color):
756
+ width, height = pil_img.size
757
+ if width == height:
758
+ return pil_img
759
+ elif width > height:
760
+ result = Image.new(pil_img.mode, (width, width), background_color)
761
+ result.paste(pil_img, (0, (width - height) // 2))
762
+ return result
763
+ else:
764
+ result = Image.new(pil_img.mode, (height, height), background_color)
765
+ result.paste(pil_img, ((height - width) // 2, 0))
766
+ return result
767
+
768
+
769
+ def process_images(images, image_processor, model_cfg):
770
+ image_aspect_ratio = getattr(model_cfg, "image_aspect_ratio", None)
771
+ new_images = []
772
+ if image_aspect_ratio == "highres":
773
+ raise NotImplementedError
774
+ for image in images:
775
+ image = process_highres_image(image, image_processor, model_cfg.image_grid_pinpoints)
776
+ new_images.append(image)
777
+ elif "anyres" in image_aspect_ratio:
778
+ for image in images:
779
+ if "nopad" in image_aspect_ratio:
780
+ image = process_anyres_image_nopad(image, image_processor, model_cfg.image_grid_pinpoints)
781
+ else:
782
+ image = process_anyres_image(image, image_processor, model_cfg.image_grid_pinpoints)
783
+ new_images.append(image)
784
+ elif image_aspect_ratio == "crop_split":
785
+ raise NotImplementedError
786
+ for image in images:
787
+ image = process_highres_image_crop_split(image, model_cfg, image_processor)
788
+ new_images.append(image)
789
+ elif image_aspect_ratio == "pad":
790
+ for image in images:
791
+ image = expand2square(image, tuple(int(x * 255) for x in image_processor.image_mean))
792
+ image = image_processor.preprocess(image, return_tensors="pt")["pixel_values"][0]
793
+ new_images.append(image)
794
+ else:
795
+ return image_processor.preprocess(images, return_tensors="pt")["pixel_values"]
796
+ if all(x.shape == new_images[0].shape for x in new_images):
797
+ new_images = torch.stack(new_images, dim=0)
798
+ return new_images
799
+
800
+
801
+ def tokenizer_image_token(prompt, tokenizer, image_token_index=IMAGE_TOKEN_INDEX, return_tensors=None):
802
+ prompt_chunks = [tokenizer(chunk).input_ids for chunk in prompt.split("<image>")]
803
+
804
+ def insert_separator(X, sep):
805
+ return [ele for sublist in zip(X, [sep] * len(X)) for ele in sublist][:-1]
806
+
807
+ input_ids = []
808
+ offset = 0
809
+ if len(prompt_chunks) > 0 and len(prompt_chunks[0]) > 0 and prompt_chunks[0][0] == tokenizer.bos_token_id:
810
+ offset = 1
811
+ input_ids.append(prompt_chunks[0][0])
812
+
813
+ for x in insert_separator(prompt_chunks, [image_token_index] * (offset + 1)):
814
+ input_ids.extend(x[offset:])
815
+
816
+ if return_tensors is not None:
817
+ if return_tensors == "pt":
818
+ return torch.tensor(input_ids, dtype=torch.long)
819
+ raise ValueError(f"Unsupported tensor type: {return_tensors}")
820
+ return input_ids
821
+
822
+
823
+ def get_model_name_from_path(model_path):
824
+ model_path = model_path.strip("/")
825
+ model_paths = model_path.split("/")
826
+ if model_paths[-1].startswith("checkpoint-"):
827
+ return model_paths[-2] + "_" + model_paths[-1]
828
+ else:
829
+ return model_paths[-1]
830
+
831
+
832
+ class KeywordsStoppingCriteria(StoppingCriteria):
833
+ def __init__(self, keywords, tokenizer, input_ids):
834
+ self.keywords = keywords
835
+ self.keyword_ids = []
836
+ for keyword in keywords:
837
+ cur_keyword_ids = tokenizer(keyword).input_ids
838
+ if len(cur_keyword_ids) > 1 and cur_keyword_ids[0] == tokenizer.bos_token_id:
839
+ cur_keyword_ids = cur_keyword_ids[1:]
840
+ self.keyword_ids.append(torch.tensor(cur_keyword_ids))
841
+ self.tokenizer = tokenizer
842
+ self.start_len = input_ids.shape[1]
843
+
844
+ def __call__(self, output_ids: torch.LongTensor, scores: torch.FloatTensor, **kwargs) -> bool:
845
+ assert output_ids.shape[0] == 1, "Only support batch size 1 (yet)" # TODO
846
+ offset = min(output_ids.shape[1] - self.start_len, 3)
847
+ self.keyword_ids = [keyword_id.to(output_ids.device) for keyword_id in self.keyword_ids]
848
+ for keyword_id in self.keyword_ids:
849
+ if output_ids[0, -keyword_id.shape[0] :] == keyword_id:
850
+ return True
851
+ outputs = self.tokenizer.batch_decode(output_ids[:, -offset:], skip_special_tokens=True)[0]
852
+ for keyword in self.keywords:
853
+ if keyword in outputs:
854
+ return True
855
+ return False
model-00001-of-00004.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:537d4d043801ae35a670de1e06426d44c4f5f76309421e29d044076e613e5227
3
+ size 4976862092
model-00002-of-00004.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:12d78ef55e9ed386a42a333a874072a6539ad0cc0c40bdd074fb9a6794e2fd4b
3
+ size 4907184040
model-00003-of-00004.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:b478af52e54e5afeeac088d1577d38380fcde890215d188f5b048c2d0a1fd588
3
+ size 4995708404
model-00004-of-00004.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:6c8e978c21fa37f46e61ce180028db5b3ad3cb7baba61a24d18cc4a7a54bb330
3
+ size 1274188592
model.safetensors.index.json ADDED
@@ -0,0 +1,905 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "metadata": {
3
+ "total_size": 16153832560
4
+ },
5
+ "weight_map": {
6
+ "lm_head.weight": "model-00004-of-00004.safetensors",
7
+ "model.embed_tokens.weight": "model-00001-of-00004.safetensors",
8
+ "model.layers.0.input_layernorm.weight": "model-00001-of-00004.safetensors",
9
+ "model.layers.0.mlp.down_proj.weight": "model-00001-of-00004.safetensors",
10
+ "model.layers.0.mlp.gate_proj.weight": "model-00001-of-00004.safetensors",
11
+ "model.layers.0.mlp.up_proj.weight": "model-00001-of-00004.safetensors",
12
+ "model.layers.0.post_attention_layernorm.weight": "model-00001-of-00004.safetensors",
13
+ "model.layers.0.self_attn.k_b_proj_nope.bias": "model-00001-of-00004.safetensors",
14
+ "model.layers.0.self_attn.k_b_proj_nope.weight": "model-00001-of-00004.safetensors",
15
+ "model.layers.0.self_attn.k_nope_scale_factor": "model-00001-of-00004.safetensors",
16
+ "model.layers.0.self_attn.k_proj.bias": "model-00001-of-00004.safetensors",
17
+ "model.layers.0.self_attn.k_proj.weight": "model-00001-of-00004.safetensors",
18
+ "model.layers.0.self_attn.k_proj_pe.bias": "model-00001-of-00004.safetensors",
19
+ "model.layers.0.self_attn.k_proj_pe.weight": "model-00001-of-00004.safetensors",
20
+ "model.layers.0.self_attn.kv_a_proj_nope.weight": "model-00001-of-00004.safetensors",
21
+ "model.layers.0.self_attn.o_proj.weight": "model-00001-of-00004.safetensors",
22
+ "model.layers.0.self_attn.q_proj.bias": "model-00001-of-00004.safetensors",
23
+ "model.layers.0.self_attn.q_proj.weight": "model-00001-of-00004.safetensors",
24
+ "model.layers.0.self_attn.softmax_temperature": "model-00001-of-00004.safetensors",
25
+ "model.layers.0.self_attn.v_b_proj.bias": "model-00001-of-00004.safetensors",
26
+ "model.layers.0.self_attn.v_b_proj.weight": "model-00001-of-00004.safetensors",
27
+ "model.layers.0.self_attn.v_proj.bias": "model-00001-of-00004.safetensors",
28
+ "model.layers.0.self_attn.v_proj.weight": "model-00001-of-00004.safetensors",
29
+ "model.layers.1.input_layernorm.weight": "model-00001-of-00004.safetensors",
30
+ "model.layers.1.mlp.down_proj.weight": "model-00001-of-00004.safetensors",
31
+ "model.layers.1.mlp.gate_proj.weight": "model-00001-of-00004.safetensors",
32
+ "model.layers.1.mlp.up_proj.weight": "model-00001-of-00004.safetensors",
33
+ "model.layers.1.post_attention_layernorm.weight": "model-00001-of-00004.safetensors",
34
+ "model.layers.1.self_attn.k_b_proj_nope.bias": "model-00001-of-00004.safetensors",
35
+ "model.layers.1.self_attn.k_b_proj_nope.weight": "model-00001-of-00004.safetensors",
36
+ "model.layers.1.self_attn.k_nope_scale_factor": "model-00001-of-00004.safetensors",
37
+ "model.layers.1.self_attn.k_proj.bias": "model-00001-of-00004.safetensors",
38
+ "model.layers.1.self_attn.k_proj.weight": "model-00001-of-00004.safetensors",
39
+ "model.layers.1.self_attn.k_proj_pe.bias": "model-00001-of-00004.safetensors",
40
+ "model.layers.1.self_attn.k_proj_pe.weight": "model-00001-of-00004.safetensors",
41
+ "model.layers.1.self_attn.kv_a_proj_nope.weight": "model-00001-of-00004.safetensors",
42
+ "model.layers.1.self_attn.o_proj.weight": "model-00001-of-00004.safetensors",
43
+ "model.layers.1.self_attn.q_proj.bias": "model-00001-of-00004.safetensors",
44
+ "model.layers.1.self_attn.q_proj.weight": "model-00001-of-00004.safetensors",
45
+ "model.layers.1.self_attn.softmax_temperature": "model-00001-of-00004.safetensors",
46
+ "model.layers.1.self_attn.v_b_proj.bias": "model-00001-of-00004.safetensors",
47
+ "model.layers.1.self_attn.v_b_proj.weight": "model-00001-of-00004.safetensors",
48
+ "model.layers.1.self_attn.v_proj.bias": "model-00001-of-00004.safetensors",
49
+ "model.layers.1.self_attn.v_proj.weight": "model-00001-of-00004.safetensors",
50
+ "model.layers.10.input_layernorm.weight": "model-00002-of-00004.safetensors",
51
+ "model.layers.10.mlp.down_proj.weight": "model-00002-of-00004.safetensors",
52
+ "model.layers.10.mlp.gate_proj.weight": "model-00002-of-00004.safetensors",
53
+ "model.layers.10.mlp.up_proj.weight": "model-00002-of-00004.safetensors",
54
+ "model.layers.10.post_attention_layernorm.weight": "model-00002-of-00004.safetensors",
55
+ "model.layers.10.self_attn.k_b_proj_nope.bias": "model-00002-of-00004.safetensors",
56
+ "model.layers.10.self_attn.k_b_proj_nope.weight": "model-00002-of-00004.safetensors",
57
+ "model.layers.10.self_attn.k_nope_scale_factor": "model-00002-of-00004.safetensors",
58
+ "model.layers.10.self_attn.k_proj.bias": "model-00002-of-00004.safetensors",
59
+ "model.layers.10.self_attn.k_proj.weight": "model-00002-of-00004.safetensors",
60
+ "model.layers.10.self_attn.k_proj_pe.bias": "model-00002-of-00004.safetensors",
61
+ "model.layers.10.self_attn.k_proj_pe.weight": "model-00002-of-00004.safetensors",
62
+ "model.layers.10.self_attn.kv_a_proj_nope.weight": "model-00002-of-00004.safetensors",
63
+ "model.layers.10.self_attn.o_proj.weight": "model-00002-of-00004.safetensors",
64
+ "model.layers.10.self_attn.q_proj.bias": "model-00002-of-00004.safetensors",
65
+ "model.layers.10.self_attn.q_proj.weight": "model-00002-of-00004.safetensors",
66
+ "model.layers.10.self_attn.softmax_temperature": "model-00002-of-00004.safetensors",
67
+ "model.layers.10.self_attn.v_b_proj.bias": "model-00002-of-00004.safetensors",
68
+ "model.layers.10.self_attn.v_b_proj.weight": "model-00002-of-00004.safetensors",
69
+ "model.layers.10.self_attn.v_proj.bias": "model-00002-of-00004.safetensors",
70
+ "model.layers.10.self_attn.v_proj.weight": "model-00002-of-00004.safetensors",
71
+ "model.layers.11.input_layernorm.weight": "model-00002-of-00004.safetensors",
72
+ "model.layers.11.mlp.down_proj.weight": "model-00002-of-00004.safetensors",
73
+ "model.layers.11.mlp.gate_proj.weight": "model-00002-of-00004.safetensors",
74
+ "model.layers.11.mlp.up_proj.weight": "model-00002-of-00004.safetensors",
75
+ "model.layers.11.post_attention_layernorm.weight": "model-00002-of-00004.safetensors",
76
+ "model.layers.11.self_attn.k_b_proj_nope.bias": "model-00002-of-00004.safetensors",
77
+ "model.layers.11.self_attn.k_b_proj_nope.weight": "model-00002-of-00004.safetensors",
78
+ "model.layers.11.self_attn.k_nope_scale_factor": "model-00002-of-00004.safetensors",
79
+ "model.layers.11.self_attn.k_proj.bias": "model-00002-of-00004.safetensors",
80
+ "model.layers.11.self_attn.k_proj.weight": "model-00002-of-00004.safetensors",
81
+ "model.layers.11.self_attn.k_proj_pe.bias": "model-00002-of-00004.safetensors",
82
+ "model.layers.11.self_attn.k_proj_pe.weight": "model-00002-of-00004.safetensors",
83
+ "model.layers.11.self_attn.kv_a_proj_nope.weight": "model-00002-of-00004.safetensors",
84
+ "model.layers.11.self_attn.o_proj.weight": "model-00002-of-00004.safetensors",
85
+ "model.layers.11.self_attn.q_proj.bias": "model-00002-of-00004.safetensors",
86
+ "model.layers.11.self_attn.q_proj.weight": "model-00002-of-00004.safetensors",
87
+ "model.layers.11.self_attn.softmax_temperature": "model-00002-of-00004.safetensors",
88
+ "model.layers.11.self_attn.v_b_proj.bias": "model-00002-of-00004.safetensors",
89
+ "model.layers.11.self_attn.v_b_proj.weight": "model-00002-of-00004.safetensors",
90
+ "model.layers.11.self_attn.v_proj.bias": "model-00002-of-00004.safetensors",
91
+ "model.layers.11.self_attn.v_proj.weight": "model-00002-of-00004.safetensors",
92
+ "model.layers.12.input_layernorm.weight": "model-00002-of-00004.safetensors",
93
+ "model.layers.12.mlp.down_proj.weight": "model-00002-of-00004.safetensors",
94
+ "model.layers.12.mlp.gate_proj.weight": "model-00002-of-00004.safetensors",
95
+ "model.layers.12.mlp.up_proj.weight": "model-00002-of-00004.safetensors",
96
+ "model.layers.12.post_attention_layernorm.weight": "model-00002-of-00004.safetensors",
97
+ "model.layers.12.self_attn.k_b_proj_nope.bias": "model-00002-of-00004.safetensors",
98
+ "model.layers.12.self_attn.k_b_proj_nope.weight": "model-00002-of-00004.safetensors",
99
+ "model.layers.12.self_attn.k_nope_scale_factor": "model-00002-of-00004.safetensors",
100
+ "model.layers.12.self_attn.k_proj.bias": "model-00002-of-00004.safetensors",
101
+ "model.layers.12.self_attn.k_proj.weight": "model-00002-of-00004.safetensors",
102
+ "model.layers.12.self_attn.k_proj_pe.bias": "model-00002-of-00004.safetensors",
103
+ "model.layers.12.self_attn.k_proj_pe.weight": "model-00002-of-00004.safetensors",
104
+ "model.layers.12.self_attn.kv_a_proj_nope.weight": "model-00002-of-00004.safetensors",
105
+ "model.layers.12.self_attn.o_proj.weight": "model-00002-of-00004.safetensors",
106
+ "model.layers.12.self_attn.q_proj.bias": "model-00002-of-00004.safetensors",
107
+ "model.layers.12.self_attn.q_proj.weight": "model-00002-of-00004.safetensors",
108
+ "model.layers.12.self_attn.softmax_temperature": "model-00002-of-00004.safetensors",
109
+ "model.layers.12.self_attn.v_b_proj.bias": "model-00002-of-00004.safetensors",
110
+ "model.layers.12.self_attn.v_b_proj.weight": "model-00002-of-00004.safetensors",
111
+ "model.layers.12.self_attn.v_proj.bias": "model-00002-of-00004.safetensors",
112
+ "model.layers.12.self_attn.v_proj.weight": "model-00002-of-00004.safetensors",
113
+ "model.layers.13.input_layernorm.weight": "model-00002-of-00004.safetensors",
114
+ "model.layers.13.mlp.down_proj.weight": "model-00002-of-00004.safetensors",
115
+ "model.layers.13.mlp.gate_proj.weight": "model-00002-of-00004.safetensors",
116
+ "model.layers.13.mlp.up_proj.weight": "model-00002-of-00004.safetensors",
117
+ "model.layers.13.post_attention_layernorm.weight": "model-00002-of-00004.safetensors",
118
+ "model.layers.13.self_attn.k_b_proj_nope.bias": "model-00002-of-00004.safetensors",
119
+ "model.layers.13.self_attn.k_b_proj_nope.weight": "model-00002-of-00004.safetensors",
120
+ "model.layers.13.self_attn.k_nope_scale_factor": "model-00002-of-00004.safetensors",
121
+ "model.layers.13.self_attn.k_proj.bias": "model-00002-of-00004.safetensors",
122
+ "model.layers.13.self_attn.k_proj.weight": "model-00002-of-00004.safetensors",
123
+ "model.layers.13.self_attn.k_proj_pe.bias": "model-00002-of-00004.safetensors",
124
+ "model.layers.13.self_attn.k_proj_pe.weight": "model-00002-of-00004.safetensors",
125
+ "model.layers.13.self_attn.kv_a_proj_nope.weight": "model-00002-of-00004.safetensors",
126
+ "model.layers.13.self_attn.o_proj.weight": "model-00002-of-00004.safetensors",
127
+ "model.layers.13.self_attn.q_proj.bias": "model-00002-of-00004.safetensors",
128
+ "model.layers.13.self_attn.q_proj.weight": "model-00002-of-00004.safetensors",
129
+ "model.layers.13.self_attn.softmax_temperature": "model-00002-of-00004.safetensors",
130
+ "model.layers.13.self_attn.v_b_proj.bias": "model-00002-of-00004.safetensors",
131
+ "model.layers.13.self_attn.v_b_proj.weight": "model-00002-of-00004.safetensors",
132
+ "model.layers.13.self_attn.v_proj.bias": "model-00002-of-00004.safetensors",
133
+ "model.layers.13.self_attn.v_proj.weight": "model-00002-of-00004.safetensors",
134
+ "model.layers.14.input_layernorm.weight": "model-00002-of-00004.safetensors",
135
+ "model.layers.14.mlp.down_proj.weight": "model-00002-of-00004.safetensors",
136
+ "model.layers.14.mlp.gate_proj.weight": "model-00002-of-00004.safetensors",
137
+ "model.layers.14.mlp.up_proj.weight": "model-00002-of-00004.safetensors",
138
+ "model.layers.14.post_attention_layernorm.weight": "model-00002-of-00004.safetensors",
139
+ "model.layers.14.self_attn.k_b_proj_nope.bias": "model-00002-of-00004.safetensors",
140
+ "model.layers.14.self_attn.k_b_proj_nope.weight": "model-00002-of-00004.safetensors",
141
+ "model.layers.14.self_attn.k_nope_scale_factor": "model-00002-of-00004.safetensors",
142
+ "model.layers.14.self_attn.k_proj.bias": "model-00002-of-00004.safetensors",
143
+ "model.layers.14.self_attn.k_proj.weight": "model-00002-of-00004.safetensors",
144
+ "model.layers.14.self_attn.k_proj_pe.bias": "model-00002-of-00004.safetensors",
145
+ "model.layers.14.self_attn.k_proj_pe.weight": "model-00002-of-00004.safetensors",
146
+ "model.layers.14.self_attn.kv_a_proj_nope.weight": "model-00002-of-00004.safetensors",
147
+ "model.layers.14.self_attn.o_proj.weight": "model-00002-of-00004.safetensors",
148
+ "model.layers.14.self_attn.q_proj.bias": "model-00002-of-00004.safetensors",
149
+ "model.layers.14.self_attn.q_proj.weight": "model-00002-of-00004.safetensors",
150
+ "model.layers.14.self_attn.softmax_temperature": "model-00002-of-00004.safetensors",
151
+ "model.layers.14.self_attn.v_b_proj.bias": "model-00002-of-00004.safetensors",
152
+ "model.layers.14.self_attn.v_b_proj.weight": "model-00002-of-00004.safetensors",
153
+ "model.layers.14.self_attn.v_proj.bias": "model-00002-of-00004.safetensors",
154
+ "model.layers.14.self_attn.v_proj.weight": "model-00002-of-00004.safetensors",
155
+ "model.layers.15.input_layernorm.weight": "model-00002-of-00004.safetensors",
156
+ "model.layers.15.mlp.down_proj.weight": "model-00002-of-00004.safetensors",
157
+ "model.layers.15.mlp.gate_proj.weight": "model-00002-of-00004.safetensors",
158
+ "model.layers.15.mlp.up_proj.weight": "model-00002-of-00004.safetensors",
159
+ "model.layers.15.post_attention_layernorm.weight": "model-00002-of-00004.safetensors",
160
+ "model.layers.15.self_attn.k_b_proj_nope.bias": "model-00002-of-00004.safetensors",
161
+ "model.layers.15.self_attn.k_b_proj_nope.weight": "model-00002-of-00004.safetensors",
162
+ "model.layers.15.self_attn.k_nope_scale_factor": "model-00002-of-00004.safetensors",
163
+ "model.layers.15.self_attn.k_proj.bias": "model-00002-of-00004.safetensors",
164
+ "model.layers.15.self_attn.k_proj.weight": "model-00002-of-00004.safetensors",
165
+ "model.layers.15.self_attn.k_proj_pe.bias": "model-00002-of-00004.safetensors",
166
+ "model.layers.15.self_attn.k_proj_pe.weight": "model-00002-of-00004.safetensors",
167
+ "model.layers.15.self_attn.kv_a_proj_nope.weight": "model-00002-of-00004.safetensors",
168
+ "model.layers.15.self_attn.o_proj.weight": "model-00002-of-00004.safetensors",
169
+ "model.layers.15.self_attn.q_proj.bias": "model-00002-of-00004.safetensors",
170
+ "model.layers.15.self_attn.q_proj.weight": "model-00002-of-00004.safetensors",
171
+ "model.layers.15.self_attn.softmax_temperature": "model-00002-of-00004.safetensors",
172
+ "model.layers.15.self_attn.v_b_proj.bias": "model-00002-of-00004.safetensors",
173
+ "model.layers.15.self_attn.v_b_proj.weight": "model-00002-of-00004.safetensors",
174
+ "model.layers.15.self_attn.v_proj.bias": "model-00002-of-00004.safetensors",
175
+ "model.layers.15.self_attn.v_proj.weight": "model-00002-of-00004.safetensors",
176
+ "model.layers.16.input_layernorm.weight": "model-00002-of-00004.safetensors",
177
+ "model.layers.16.mlp.down_proj.weight": "model-00002-of-00004.safetensors",
178
+ "model.layers.16.mlp.gate_proj.weight": "model-00002-of-00004.safetensors",
179
+ "model.layers.16.mlp.up_proj.weight": "model-00002-of-00004.safetensors",
180
+ "model.layers.16.post_attention_layernorm.weight": "model-00002-of-00004.safetensors",
181
+ "model.layers.16.self_attn.k_b_proj_nope.bias": "model-00002-of-00004.safetensors",
182
+ "model.layers.16.self_attn.k_b_proj_nope.weight": "model-00002-of-00004.safetensors",
183
+ "model.layers.16.self_attn.k_nope_scale_factor": "model-00002-of-00004.safetensors",
184
+ "model.layers.16.self_attn.k_proj.bias": "model-00002-of-00004.safetensors",
185
+ "model.layers.16.self_attn.k_proj.weight": "model-00002-of-00004.safetensors",
186
+ "model.layers.16.self_attn.k_proj_pe.bias": "model-00002-of-00004.safetensors",
187
+ "model.layers.16.self_attn.k_proj_pe.weight": "model-00002-of-00004.safetensors",
188
+ "model.layers.16.self_attn.kv_a_proj_nope.weight": "model-00002-of-00004.safetensors",
189
+ "model.layers.16.self_attn.o_proj.weight": "model-00002-of-00004.safetensors",
190
+ "model.layers.16.self_attn.q_proj.bias": "model-00002-of-00004.safetensors",
191
+ "model.layers.16.self_attn.q_proj.weight": "model-00002-of-00004.safetensors",
192
+ "model.layers.16.self_attn.softmax_temperature": "model-00002-of-00004.safetensors",
193
+ "model.layers.16.self_attn.v_b_proj.bias": "model-00002-of-00004.safetensors",
194
+ "model.layers.16.self_attn.v_b_proj.weight": "model-00002-of-00004.safetensors",
195
+ "model.layers.16.self_attn.v_proj.bias": "model-00002-of-00004.safetensors",
196
+ "model.layers.16.self_attn.v_proj.weight": "model-00002-of-00004.safetensors",
197
+ "model.layers.17.input_layernorm.weight": "model-00002-of-00004.safetensors",
198
+ "model.layers.17.mlp.down_proj.weight": "model-00002-of-00004.safetensors",
199
+ "model.layers.17.mlp.gate_proj.weight": "model-00002-of-00004.safetensors",
200
+ "model.layers.17.mlp.up_proj.weight": "model-00002-of-00004.safetensors",
201
+ "model.layers.17.post_attention_layernorm.weight": "model-00002-of-00004.safetensors",
202
+ "model.layers.17.self_attn.k_b_proj_nope.bias": "model-00002-of-00004.safetensors",
203
+ "model.layers.17.self_attn.k_b_proj_nope.weight": "model-00002-of-00004.safetensors",
204
+ "model.layers.17.self_attn.k_nope_scale_factor": "model-00002-of-00004.safetensors",
205
+ "model.layers.17.self_attn.k_proj.bias": "model-00002-of-00004.safetensors",
206
+ "model.layers.17.self_attn.k_proj.weight": "model-00002-of-00004.safetensors",
207
+ "model.layers.17.self_attn.k_proj_pe.bias": "model-00002-of-00004.safetensors",
208
+ "model.layers.17.self_attn.k_proj_pe.weight": "model-00002-of-00004.safetensors",
209
+ "model.layers.17.self_attn.kv_a_proj_nope.weight": "model-00002-of-00004.safetensors",
210
+ "model.layers.17.self_attn.o_proj.weight": "model-00002-of-00004.safetensors",
211
+ "model.layers.17.self_attn.q_proj.bias": "model-00002-of-00004.safetensors",
212
+ "model.layers.17.self_attn.q_proj.weight": "model-00002-of-00004.safetensors",
213
+ "model.layers.17.self_attn.softmax_temperature": "model-00002-of-00004.safetensors",
214
+ "model.layers.17.self_attn.v_b_proj.bias": "model-00002-of-00004.safetensors",
215
+ "model.layers.17.self_attn.v_b_proj.weight": "model-00002-of-00004.safetensors",
216
+ "model.layers.17.self_attn.v_proj.bias": "model-00002-of-00004.safetensors",
217
+ "model.layers.17.self_attn.v_proj.weight": "model-00002-of-00004.safetensors",
218
+ "model.layers.18.input_layernorm.weight": "model-00003-of-00004.safetensors",
219
+ "model.layers.18.mlp.down_proj.weight": "model-00003-of-00004.safetensors",
220
+ "model.layers.18.mlp.gate_proj.weight": "model-00002-of-00004.safetensors",
221
+ "model.layers.18.mlp.up_proj.weight": "model-00003-of-00004.safetensors",
222
+ "model.layers.18.post_attention_layernorm.weight": "model-00003-of-00004.safetensors",
223
+ "model.layers.18.self_attn.k_b_proj_nope.bias": "model-00002-of-00004.safetensors",
224
+ "model.layers.18.self_attn.k_b_proj_nope.weight": "model-00002-of-00004.safetensors",
225
+ "model.layers.18.self_attn.k_nope_scale_factor": "model-00002-of-00004.safetensors",
226
+ "model.layers.18.self_attn.k_proj.bias": "model-00002-of-00004.safetensors",
227
+ "model.layers.18.self_attn.k_proj.weight": "model-00002-of-00004.safetensors",
228
+ "model.layers.18.self_attn.k_proj_pe.bias": "model-00002-of-00004.safetensors",
229
+ "model.layers.18.self_attn.k_proj_pe.weight": "model-00002-of-00004.safetensors",
230
+ "model.layers.18.self_attn.kv_a_proj_nope.weight": "model-00002-of-00004.safetensors",
231
+ "model.layers.18.self_attn.o_proj.weight": "model-00002-of-00004.safetensors",
232
+ "model.layers.18.self_attn.q_proj.bias": "model-00002-of-00004.safetensors",
233
+ "model.layers.18.self_attn.q_proj.weight": "model-00002-of-00004.safetensors",
234
+ "model.layers.18.self_attn.softmax_temperature": "model-00002-of-00004.safetensors",
235
+ "model.layers.18.self_attn.v_b_proj.bias": "model-00002-of-00004.safetensors",
236
+ "model.layers.18.self_attn.v_b_proj.weight": "model-00002-of-00004.safetensors",
237
+ "model.layers.18.self_attn.v_proj.bias": "model-00002-of-00004.safetensors",
238
+ "model.layers.18.self_attn.v_proj.weight": "model-00002-of-00004.safetensors",
239
+ "model.layers.19.input_layernorm.weight": "model-00003-of-00004.safetensors",
240
+ "model.layers.19.mlp.down_proj.weight": "model-00003-of-00004.safetensors",
241
+ "model.layers.19.mlp.gate_proj.weight": "model-00003-of-00004.safetensors",
242
+ "model.layers.19.mlp.up_proj.weight": "model-00003-of-00004.safetensors",
243
+ "model.layers.19.post_attention_layernorm.weight": "model-00003-of-00004.safetensors",
244
+ "model.layers.19.self_attn.k_b_proj_nope.bias": "model-00003-of-00004.safetensors",
245
+ "model.layers.19.self_attn.k_b_proj_nope.weight": "model-00003-of-00004.safetensors",
246
+ "model.layers.19.self_attn.k_nope_scale_factor": "model-00003-of-00004.safetensors",
247
+ "model.layers.19.self_attn.k_proj.bias": "model-00003-of-00004.safetensors",
248
+ "model.layers.19.self_attn.k_proj.weight": "model-00003-of-00004.safetensors",
249
+ "model.layers.19.self_attn.k_proj_pe.bias": "model-00003-of-00004.safetensors",
250
+ "model.layers.19.self_attn.k_proj_pe.weight": "model-00003-of-00004.safetensors",
251
+ "model.layers.19.self_attn.kv_a_proj_nope.weight": "model-00003-of-00004.safetensors",
252
+ "model.layers.19.self_attn.o_proj.weight": "model-00003-of-00004.safetensors",
253
+ "model.layers.19.self_attn.q_proj.bias": "model-00003-of-00004.safetensors",
254
+ "model.layers.19.self_attn.q_proj.weight": "model-00003-of-00004.safetensors",
255
+ "model.layers.19.self_attn.softmax_temperature": "model-00003-of-00004.safetensors",
256
+ "model.layers.19.self_attn.v_b_proj.bias": "model-00003-of-00004.safetensors",
257
+ "model.layers.19.self_attn.v_b_proj.weight": "model-00003-of-00004.safetensors",
258
+ "model.layers.19.self_attn.v_proj.bias": "model-00003-of-00004.safetensors",
259
+ "model.layers.19.self_attn.v_proj.weight": "model-00003-of-00004.safetensors",
260
+ "model.layers.2.input_layernorm.weight": "model-00001-of-00004.safetensors",
261
+ "model.layers.2.mlp.down_proj.weight": "model-00001-of-00004.safetensors",
262
+ "model.layers.2.mlp.gate_proj.weight": "model-00001-of-00004.safetensors",
263
+ "model.layers.2.mlp.up_proj.weight": "model-00001-of-00004.safetensors",
264
+ "model.layers.2.post_attention_layernorm.weight": "model-00001-of-00004.safetensors",
265
+ "model.layers.2.self_attn.k_b_proj_nope.bias": "model-00001-of-00004.safetensors",
266
+ "model.layers.2.self_attn.k_b_proj_nope.weight": "model-00001-of-00004.safetensors",
267
+ "model.layers.2.self_attn.k_nope_scale_factor": "model-00001-of-00004.safetensors",
268
+ "model.layers.2.self_attn.k_proj.bias": "model-00001-of-00004.safetensors",
269
+ "model.layers.2.self_attn.k_proj.weight": "model-00001-of-00004.safetensors",
270
+ "model.layers.2.self_attn.k_proj_pe.bias": "model-00001-of-00004.safetensors",
271
+ "model.layers.2.self_attn.k_proj_pe.weight": "model-00001-of-00004.safetensors",
272
+ "model.layers.2.self_attn.kv_a_proj_nope.weight": "model-00001-of-00004.safetensors",
273
+ "model.layers.2.self_attn.o_proj.weight": "model-00001-of-00004.safetensors",
274
+ "model.layers.2.self_attn.q_proj.bias": "model-00001-of-00004.safetensors",
275
+ "model.layers.2.self_attn.q_proj.weight": "model-00001-of-00004.safetensors",
276
+ "model.layers.2.self_attn.softmax_temperature": "model-00001-of-00004.safetensors",
277
+ "model.layers.2.self_attn.v_b_proj.bias": "model-00001-of-00004.safetensors",
278
+ "model.layers.2.self_attn.v_b_proj.weight": "model-00001-of-00004.safetensors",
279
+ "model.layers.2.self_attn.v_proj.bias": "model-00001-of-00004.safetensors",
280
+ "model.layers.2.self_attn.v_proj.weight": "model-00001-of-00004.safetensors",
281
+ "model.layers.20.input_layernorm.weight": "model-00003-of-00004.safetensors",
282
+ "model.layers.20.mlp.down_proj.weight": "model-00003-of-00004.safetensors",
283
+ "model.layers.20.mlp.gate_proj.weight": "model-00003-of-00004.safetensors",
284
+ "model.layers.20.mlp.up_proj.weight": "model-00003-of-00004.safetensors",
285
+ "model.layers.20.post_attention_layernorm.weight": "model-00003-of-00004.safetensors",
286
+ "model.layers.20.self_attn.k_b_proj_nope.bias": "model-00003-of-00004.safetensors",
287
+ "model.layers.20.self_attn.k_b_proj_nope.weight": "model-00003-of-00004.safetensors",
288
+ "model.layers.20.self_attn.k_nope_scale_factor": "model-00003-of-00004.safetensors",
289
+ "model.layers.20.self_attn.k_proj.bias": "model-00003-of-00004.safetensors",
290
+ "model.layers.20.self_attn.k_proj.weight": "model-00003-of-00004.safetensors",
291
+ "model.layers.20.self_attn.k_proj_pe.bias": "model-00003-of-00004.safetensors",
292
+ "model.layers.20.self_attn.k_proj_pe.weight": "model-00003-of-00004.safetensors",
293
+ "model.layers.20.self_attn.kv_a_proj_nope.weight": "model-00003-of-00004.safetensors",
294
+ "model.layers.20.self_attn.o_proj.weight": "model-00003-of-00004.safetensors",
295
+ "model.layers.20.self_attn.q_proj.bias": "model-00003-of-00004.safetensors",
296
+ "model.layers.20.self_attn.q_proj.weight": "model-00003-of-00004.safetensors",
297
+ "model.layers.20.self_attn.softmax_temperature": "model-00003-of-00004.safetensors",
298
+ "model.layers.20.self_attn.v_b_proj.bias": "model-00003-of-00004.safetensors",
299
+ "model.layers.20.self_attn.v_b_proj.weight": "model-00003-of-00004.safetensors",
300
+ "model.layers.20.self_attn.v_proj.bias": "model-00003-of-00004.safetensors",
301
+ "model.layers.20.self_attn.v_proj.weight": "model-00003-of-00004.safetensors",
302
+ "model.layers.21.input_layernorm.weight": "model-00003-of-00004.safetensors",
303
+ "model.layers.21.mlp.down_proj.weight": "model-00003-of-00004.safetensors",
304
+ "model.layers.21.mlp.gate_proj.weight": "model-00003-of-00004.safetensors",
305
+ "model.layers.21.mlp.up_proj.weight": "model-00003-of-00004.safetensors",
306
+ "model.layers.21.post_attention_layernorm.weight": "model-00003-of-00004.safetensors",
307
+ "model.layers.21.self_attn.k_b_proj_nope.bias": "model-00003-of-00004.safetensors",
308
+ "model.layers.21.self_attn.k_b_proj_nope.weight": "model-00003-of-00004.safetensors",
309
+ "model.layers.21.self_attn.k_nope_scale_factor": "model-00003-of-00004.safetensors",
310
+ "model.layers.21.self_attn.k_proj.bias": "model-00003-of-00004.safetensors",
311
+ "model.layers.21.self_attn.k_proj.weight": "model-00003-of-00004.safetensors",
312
+ "model.layers.21.self_attn.k_proj_pe.bias": "model-00003-of-00004.safetensors",
313
+ "model.layers.21.self_attn.k_proj_pe.weight": "model-00003-of-00004.safetensors",
314
+ "model.layers.21.self_attn.kv_a_proj_nope.weight": "model-00003-of-00004.safetensors",
315
+ "model.layers.21.self_attn.o_proj.weight": "model-00003-of-00004.safetensors",
316
+ "model.layers.21.self_attn.q_proj.bias": "model-00003-of-00004.safetensors",
317
+ "model.layers.21.self_attn.q_proj.weight": "model-00003-of-00004.safetensors",
318
+ "model.layers.21.self_attn.softmax_temperature": "model-00003-of-00004.safetensors",
319
+ "model.layers.21.self_attn.v_b_proj.bias": "model-00003-of-00004.safetensors",
320
+ "model.layers.21.self_attn.v_b_proj.weight": "model-00003-of-00004.safetensors",
321
+ "model.layers.21.self_attn.v_proj.bias": "model-00003-of-00004.safetensors",
322
+ "model.layers.21.self_attn.v_proj.weight": "model-00003-of-00004.safetensors",
323
+ "model.layers.22.input_layernorm.weight": "model-00003-of-00004.safetensors",
324
+ "model.layers.22.mlp.down_proj.weight": "model-00003-of-00004.safetensors",
325
+ "model.layers.22.mlp.gate_proj.weight": "model-00003-of-00004.safetensors",
326
+ "model.layers.22.mlp.up_proj.weight": "model-00003-of-00004.safetensors",
327
+ "model.layers.22.post_attention_layernorm.weight": "model-00003-of-00004.safetensors",
328
+ "model.layers.22.self_attn.k_b_proj_nope.bias": "model-00003-of-00004.safetensors",
329
+ "model.layers.22.self_attn.k_b_proj_nope.weight": "model-00003-of-00004.safetensors",
330
+ "model.layers.22.self_attn.k_nope_scale_factor": "model-00003-of-00004.safetensors",
331
+ "model.layers.22.self_attn.k_proj.bias": "model-00003-of-00004.safetensors",
332
+ "model.layers.22.self_attn.k_proj.weight": "model-00003-of-00004.safetensors",
333
+ "model.layers.22.self_attn.k_proj_pe.bias": "model-00003-of-00004.safetensors",
334
+ "model.layers.22.self_attn.k_proj_pe.weight": "model-00003-of-00004.safetensors",
335
+ "model.layers.22.self_attn.kv_a_proj_nope.weight": "model-00003-of-00004.safetensors",
336
+ "model.layers.22.self_attn.o_proj.weight": "model-00003-of-00004.safetensors",
337
+ "model.layers.22.self_attn.q_proj.bias": "model-00003-of-00004.safetensors",
338
+ "model.layers.22.self_attn.q_proj.weight": "model-00003-of-00004.safetensors",
339
+ "model.layers.22.self_attn.softmax_temperature": "model-00003-of-00004.safetensors",
340
+ "model.layers.22.self_attn.v_b_proj.bias": "model-00003-of-00004.safetensors",
341
+ "model.layers.22.self_attn.v_b_proj.weight": "model-00003-of-00004.safetensors",
342
+ "model.layers.22.self_attn.v_proj.bias": "model-00003-of-00004.safetensors",
343
+ "model.layers.22.self_attn.v_proj.weight": "model-00003-of-00004.safetensors",
344
+ "model.layers.23.input_layernorm.weight": "model-00003-of-00004.safetensors",
345
+ "model.layers.23.mlp.down_proj.weight": "model-00003-of-00004.safetensors",
346
+ "model.layers.23.mlp.gate_proj.weight": "model-00003-of-00004.safetensors",
347
+ "model.layers.23.mlp.up_proj.weight": "model-00003-of-00004.safetensors",
348
+ "model.layers.23.post_attention_layernorm.weight": "model-00003-of-00004.safetensors",
349
+ "model.layers.23.self_attn.k_b_proj_nope.bias": "model-00003-of-00004.safetensors",
350
+ "model.layers.23.self_attn.k_b_proj_nope.weight": "model-00003-of-00004.safetensors",
351
+ "model.layers.23.self_attn.k_nope_scale_factor": "model-00003-of-00004.safetensors",
352
+ "model.layers.23.self_attn.k_proj.bias": "model-00003-of-00004.safetensors",
353
+ "model.layers.23.self_attn.k_proj.weight": "model-00003-of-00004.safetensors",
354
+ "model.layers.23.self_attn.k_proj_pe.bias": "model-00003-of-00004.safetensors",
355
+ "model.layers.23.self_attn.k_proj_pe.weight": "model-00003-of-00004.safetensors",
356
+ "model.layers.23.self_attn.kv_a_proj_nope.weight": "model-00003-of-00004.safetensors",
357
+ "model.layers.23.self_attn.o_proj.weight": "model-00003-of-00004.safetensors",
358
+ "model.layers.23.self_attn.q_proj.bias": "model-00003-of-00004.safetensors",
359
+ "model.layers.23.self_attn.q_proj.weight": "model-00003-of-00004.safetensors",
360
+ "model.layers.23.self_attn.softmax_temperature": "model-00003-of-00004.safetensors",
361
+ "model.layers.23.self_attn.v_b_proj.bias": "model-00003-of-00004.safetensors",
362
+ "model.layers.23.self_attn.v_b_proj.weight": "model-00003-of-00004.safetensors",
363
+ "model.layers.23.self_attn.v_proj.bias": "model-00003-of-00004.safetensors",
364
+ "model.layers.23.self_attn.v_proj.weight": "model-00003-of-00004.safetensors",
365
+ "model.layers.24.input_layernorm.weight": "model-00003-of-00004.safetensors",
366
+ "model.layers.24.mlp.down_proj.weight": "model-00003-of-00004.safetensors",
367
+ "model.layers.24.mlp.gate_proj.weight": "model-00003-of-00004.safetensors",
368
+ "model.layers.24.mlp.up_proj.weight": "model-00003-of-00004.safetensors",
369
+ "model.layers.24.post_attention_layernorm.weight": "model-00003-of-00004.safetensors",
370
+ "model.layers.24.self_attn.k_b_proj_nope.bias": "model-00003-of-00004.safetensors",
371
+ "model.layers.24.self_attn.k_b_proj_nope.weight": "model-00003-of-00004.safetensors",
372
+ "model.layers.24.self_attn.k_nope_scale_factor": "model-00003-of-00004.safetensors",
373
+ "model.layers.24.self_attn.k_proj.bias": "model-00003-of-00004.safetensors",
374
+ "model.layers.24.self_attn.k_proj.weight": "model-00003-of-00004.safetensors",
375
+ "model.layers.24.self_attn.k_proj_pe.bias": "model-00003-of-00004.safetensors",
376
+ "model.layers.24.self_attn.k_proj_pe.weight": "model-00003-of-00004.safetensors",
377
+ "model.layers.24.self_attn.kv_a_proj_nope.weight": "model-00003-of-00004.safetensors",
378
+ "model.layers.24.self_attn.o_proj.weight": "model-00003-of-00004.safetensors",
379
+ "model.layers.24.self_attn.q_proj.bias": "model-00003-of-00004.safetensors",
380
+ "model.layers.24.self_attn.q_proj.weight": "model-00003-of-00004.safetensors",
381
+ "model.layers.24.self_attn.softmax_temperature": "model-00003-of-00004.safetensors",
382
+ "model.layers.24.self_attn.v_b_proj.bias": "model-00003-of-00004.safetensors",
383
+ "model.layers.24.self_attn.v_b_proj.weight": "model-00003-of-00004.safetensors",
384
+ "model.layers.24.self_attn.v_proj.bias": "model-00003-of-00004.safetensors",
385
+ "model.layers.24.self_attn.v_proj.weight": "model-00003-of-00004.safetensors",
386
+ "model.layers.25.input_layernorm.weight": "model-00003-of-00004.safetensors",
387
+ "model.layers.25.mlp.down_proj.weight": "model-00003-of-00004.safetensors",
388
+ "model.layers.25.mlp.gate_proj.weight": "model-00003-of-00004.safetensors",
389
+ "model.layers.25.mlp.up_proj.weight": "model-00003-of-00004.safetensors",
390
+ "model.layers.25.post_attention_layernorm.weight": "model-00003-of-00004.safetensors",
391
+ "model.layers.25.self_attn.k_b_proj_nope.bias": "model-00003-of-00004.safetensors",
392
+ "model.layers.25.self_attn.k_b_proj_nope.weight": "model-00003-of-00004.safetensors",
393
+ "model.layers.25.self_attn.k_nope_scale_factor": "model-00003-of-00004.safetensors",
394
+ "model.layers.25.self_attn.k_proj.bias": "model-00003-of-00004.safetensors",
395
+ "model.layers.25.self_attn.k_proj.weight": "model-00003-of-00004.safetensors",
396
+ "model.layers.25.self_attn.k_proj_pe.bias": "model-00003-of-00004.safetensors",
397
+ "model.layers.25.self_attn.k_proj_pe.weight": "model-00003-of-00004.safetensors",
398
+ "model.layers.25.self_attn.kv_a_proj_nope.weight": "model-00003-of-00004.safetensors",
399
+ "model.layers.25.self_attn.o_proj.weight": "model-00003-of-00004.safetensors",
400
+ "model.layers.25.self_attn.q_proj.bias": "model-00003-of-00004.safetensors",
401
+ "model.layers.25.self_attn.q_proj.weight": "model-00003-of-00004.safetensors",
402
+ "model.layers.25.self_attn.softmax_temperature": "model-00003-of-00004.safetensors",
403
+ "model.layers.25.self_attn.v_b_proj.bias": "model-00003-of-00004.safetensors",
404
+ "model.layers.25.self_attn.v_b_proj.weight": "model-00003-of-00004.safetensors",
405
+ "model.layers.25.self_attn.v_proj.bias": "model-00003-of-00004.safetensors",
406
+ "model.layers.25.self_attn.v_proj.weight": "model-00003-of-00004.safetensors",
407
+ "model.layers.26.input_layernorm.weight": "model-00003-of-00004.safetensors",
408
+ "model.layers.26.mlp.down_proj.weight": "model-00003-of-00004.safetensors",
409
+ "model.layers.26.mlp.gate_proj.weight": "model-00003-of-00004.safetensors",
410
+ "model.layers.26.mlp.up_proj.weight": "model-00003-of-00004.safetensors",
411
+ "model.layers.26.post_attention_layernorm.weight": "model-00003-of-00004.safetensors",
412
+ "model.layers.26.self_attn.k_b_proj_nope.bias": "model-00003-of-00004.safetensors",
413
+ "model.layers.26.self_attn.k_b_proj_nope.weight": "model-00003-of-00004.safetensors",
414
+ "model.layers.26.self_attn.k_nope_scale_factor": "model-00003-of-00004.safetensors",
415
+ "model.layers.26.self_attn.k_proj.bias": "model-00003-of-00004.safetensors",
416
+ "model.layers.26.self_attn.k_proj.weight": "model-00003-of-00004.safetensors",
417
+ "model.layers.26.self_attn.k_proj_pe.bias": "model-00003-of-00004.safetensors",
418
+ "model.layers.26.self_attn.k_proj_pe.weight": "model-00003-of-00004.safetensors",
419
+ "model.layers.26.self_attn.kv_a_proj_nope.weight": "model-00003-of-00004.safetensors",
420
+ "model.layers.26.self_attn.o_proj.weight": "model-00003-of-00004.safetensors",
421
+ "model.layers.26.self_attn.q_proj.bias": "model-00003-of-00004.safetensors",
422
+ "model.layers.26.self_attn.q_proj.weight": "model-00003-of-00004.safetensors",
423
+ "model.layers.26.self_attn.softmax_temperature": "model-00003-of-00004.safetensors",
424
+ "model.layers.26.self_attn.v_b_proj.bias": "model-00003-of-00004.safetensors",
425
+ "model.layers.26.self_attn.v_b_proj.weight": "model-00003-of-00004.safetensors",
426
+ "model.layers.26.self_attn.v_proj.bias": "model-00003-of-00004.safetensors",
427
+ "model.layers.26.self_attn.v_proj.weight": "model-00003-of-00004.safetensors",
428
+ "model.layers.27.input_layernorm.weight": "model-00003-of-00004.safetensors",
429
+ "model.layers.27.mlp.down_proj.weight": "model-00003-of-00004.safetensors",
430
+ "model.layers.27.mlp.gate_proj.weight": "model-00003-of-00004.safetensors",
431
+ "model.layers.27.mlp.up_proj.weight": "model-00003-of-00004.safetensors",
432
+ "model.layers.27.post_attention_layernorm.weight": "model-00003-of-00004.safetensors",
433
+ "model.layers.27.self_attn.k_b_proj_nope.bias": "model-00003-of-00004.safetensors",
434
+ "model.layers.27.self_attn.k_b_proj_nope.weight": "model-00003-of-00004.safetensors",
435
+ "model.layers.27.self_attn.k_nope_scale_factor": "model-00003-of-00004.safetensors",
436
+ "model.layers.27.self_attn.k_proj.bias": "model-00003-of-00004.safetensors",
437
+ "model.layers.27.self_attn.k_proj.weight": "model-00003-of-00004.safetensors",
438
+ "model.layers.27.self_attn.k_proj_pe.bias": "model-00003-of-00004.safetensors",
439
+ "model.layers.27.self_attn.k_proj_pe.weight": "model-00003-of-00004.safetensors",
440
+ "model.layers.27.self_attn.kv_a_proj_nope.weight": "model-00003-of-00004.safetensors",
441
+ "model.layers.27.self_attn.o_proj.weight": "model-00003-of-00004.safetensors",
442
+ "model.layers.27.self_attn.q_proj.bias": "model-00003-of-00004.safetensors",
443
+ "model.layers.27.self_attn.q_proj.weight": "model-00003-of-00004.safetensors",
444
+ "model.layers.27.self_attn.softmax_temperature": "model-00003-of-00004.safetensors",
445
+ "model.layers.27.self_attn.v_b_proj.bias": "model-00003-of-00004.safetensors",
446
+ "model.layers.27.self_attn.v_b_proj.weight": "model-00003-of-00004.safetensors",
447
+ "model.layers.27.self_attn.v_proj.bias": "model-00003-of-00004.safetensors",
448
+ "model.layers.27.self_attn.v_proj.weight": "model-00003-of-00004.safetensors",
449
+ "model.layers.3.input_layernorm.weight": "model-00001-of-00004.safetensors",
450
+ "model.layers.3.mlp.down_proj.weight": "model-00001-of-00004.safetensors",
451
+ "model.layers.3.mlp.gate_proj.weight": "model-00001-of-00004.safetensors",
452
+ "model.layers.3.mlp.up_proj.weight": "model-00001-of-00004.safetensors",
453
+ "model.layers.3.post_attention_layernorm.weight": "model-00001-of-00004.safetensors",
454
+ "model.layers.3.self_attn.k_b_proj_nope.bias": "model-00001-of-00004.safetensors",
455
+ "model.layers.3.self_attn.k_b_proj_nope.weight": "model-00001-of-00004.safetensors",
456
+ "model.layers.3.self_attn.k_nope_scale_factor": "model-00001-of-00004.safetensors",
457
+ "model.layers.3.self_attn.k_proj.bias": "model-00001-of-00004.safetensors",
458
+ "model.layers.3.self_attn.k_proj.weight": "model-00001-of-00004.safetensors",
459
+ "model.layers.3.self_attn.k_proj_pe.bias": "model-00001-of-00004.safetensors",
460
+ "model.layers.3.self_attn.k_proj_pe.weight": "model-00001-of-00004.safetensors",
461
+ "model.layers.3.self_attn.kv_a_proj_nope.weight": "model-00001-of-00004.safetensors",
462
+ "model.layers.3.self_attn.o_proj.weight": "model-00001-of-00004.safetensors",
463
+ "model.layers.3.self_attn.q_proj.bias": "model-00001-of-00004.safetensors",
464
+ "model.layers.3.self_attn.q_proj.weight": "model-00001-of-00004.safetensors",
465
+ "model.layers.3.self_attn.softmax_temperature": "model-00001-of-00004.safetensors",
466
+ "model.layers.3.self_attn.v_b_proj.bias": "model-00001-of-00004.safetensors",
467
+ "model.layers.3.self_attn.v_b_proj.weight": "model-00001-of-00004.safetensors",
468
+ "model.layers.3.self_attn.v_proj.bias": "model-00001-of-00004.safetensors",
469
+ "model.layers.3.self_attn.v_proj.weight": "model-00001-of-00004.safetensors",
470
+ "model.layers.4.input_layernorm.weight": "model-00001-of-00004.safetensors",
471
+ "model.layers.4.mlp.down_proj.weight": "model-00001-of-00004.safetensors",
472
+ "model.layers.4.mlp.gate_proj.weight": "model-00001-of-00004.safetensors",
473
+ "model.layers.4.mlp.up_proj.weight": "model-00001-of-00004.safetensors",
474
+ "model.layers.4.post_attention_layernorm.weight": "model-00001-of-00004.safetensors",
475
+ "model.layers.4.self_attn.k_b_proj_nope.bias": "model-00001-of-00004.safetensors",
476
+ "model.layers.4.self_attn.k_b_proj_nope.weight": "model-00001-of-00004.safetensors",
477
+ "model.layers.4.self_attn.k_nope_scale_factor": "model-00001-of-00004.safetensors",
478
+ "model.layers.4.self_attn.k_proj.bias": "model-00001-of-00004.safetensors",
479
+ "model.layers.4.self_attn.k_proj.weight": "model-00001-of-00004.safetensors",
480
+ "model.layers.4.self_attn.k_proj_pe.bias": "model-00001-of-00004.safetensors",
481
+ "model.layers.4.self_attn.k_proj_pe.weight": "model-00001-of-00004.safetensors",
482
+ "model.layers.4.self_attn.kv_a_proj_nope.weight": "model-00001-of-00004.safetensors",
483
+ "model.layers.4.self_attn.o_proj.weight": "model-00001-of-00004.safetensors",
484
+ "model.layers.4.self_attn.q_proj.bias": "model-00001-of-00004.safetensors",
485
+ "model.layers.4.self_attn.q_proj.weight": "model-00001-of-00004.safetensors",
486
+ "model.layers.4.self_attn.softmax_temperature": "model-00001-of-00004.safetensors",
487
+ "model.layers.4.self_attn.v_b_proj.bias": "model-00001-of-00004.safetensors",
488
+ "model.layers.4.self_attn.v_b_proj.weight": "model-00001-of-00004.safetensors",
489
+ "model.layers.4.self_attn.v_proj.bias": "model-00001-of-00004.safetensors",
490
+ "model.layers.4.self_attn.v_proj.weight": "model-00001-of-00004.safetensors",
491
+ "model.layers.5.input_layernorm.weight": "model-00001-of-00004.safetensors",
492
+ "model.layers.5.mlp.down_proj.weight": "model-00001-of-00004.safetensors",
493
+ "model.layers.5.mlp.gate_proj.weight": "model-00001-of-00004.safetensors",
494
+ "model.layers.5.mlp.up_proj.weight": "model-00001-of-00004.safetensors",
495
+ "model.layers.5.post_attention_layernorm.weight": "model-00001-of-00004.safetensors",
496
+ "model.layers.5.self_attn.k_b_proj_nope.bias": "model-00001-of-00004.safetensors",
497
+ "model.layers.5.self_attn.k_b_proj_nope.weight": "model-00001-of-00004.safetensors",
498
+ "model.layers.5.self_attn.k_nope_scale_factor": "model-00001-of-00004.safetensors",
499
+ "model.layers.5.self_attn.k_proj.bias": "model-00001-of-00004.safetensors",
500
+ "model.layers.5.self_attn.k_proj.weight": "model-00001-of-00004.safetensors",
501
+ "model.layers.5.self_attn.k_proj_pe.bias": "model-00001-of-00004.safetensors",
502
+ "model.layers.5.self_attn.k_proj_pe.weight": "model-00001-of-00004.safetensors",
503
+ "model.layers.5.self_attn.kv_a_proj_nope.weight": "model-00001-of-00004.safetensors",
504
+ "model.layers.5.self_attn.o_proj.weight": "model-00001-of-00004.safetensors",
505
+ "model.layers.5.self_attn.q_proj.bias": "model-00001-of-00004.safetensors",
506
+ "model.layers.5.self_attn.q_proj.weight": "model-00001-of-00004.safetensors",
507
+ "model.layers.5.self_attn.softmax_temperature": "model-00001-of-00004.safetensors",
508
+ "model.layers.5.self_attn.v_b_proj.bias": "model-00001-of-00004.safetensors",
509
+ "model.layers.5.self_attn.v_b_proj.weight": "model-00001-of-00004.safetensors",
510
+ "model.layers.5.self_attn.v_proj.bias": "model-00001-of-00004.safetensors",
511
+ "model.layers.5.self_attn.v_proj.weight": "model-00001-of-00004.safetensors",
512
+ "model.layers.6.input_layernorm.weight": "model-00001-of-00004.safetensors",
513
+ "model.layers.6.mlp.down_proj.weight": "model-00001-of-00004.safetensors",
514
+ "model.layers.6.mlp.gate_proj.weight": "model-00001-of-00004.safetensors",
515
+ "model.layers.6.mlp.up_proj.weight": "model-00001-of-00004.safetensors",
516
+ "model.layers.6.post_attention_layernorm.weight": "model-00001-of-00004.safetensors",
517
+ "model.layers.6.self_attn.k_b_proj_nope.bias": "model-00001-of-00004.safetensors",
518
+ "model.layers.6.self_attn.k_b_proj_nope.weight": "model-00001-of-00004.safetensors",
519
+ "model.layers.6.self_attn.k_nope_scale_factor": "model-00001-of-00004.safetensors",
520
+ "model.layers.6.self_attn.k_proj.bias": "model-00001-of-00004.safetensors",
521
+ "model.layers.6.self_attn.k_proj.weight": "model-00001-of-00004.safetensors",
522
+ "model.layers.6.self_attn.k_proj_pe.bias": "model-00001-of-00004.safetensors",
523
+ "model.layers.6.self_attn.k_proj_pe.weight": "model-00001-of-00004.safetensors",
524
+ "model.layers.6.self_attn.kv_a_proj_nope.weight": "model-00001-of-00004.safetensors",
525
+ "model.layers.6.self_attn.o_proj.weight": "model-00001-of-00004.safetensors",
526
+ "model.layers.6.self_attn.q_proj.bias": "model-00001-of-00004.safetensors",
527
+ "model.layers.6.self_attn.q_proj.weight": "model-00001-of-00004.safetensors",
528
+ "model.layers.6.self_attn.softmax_temperature": "model-00001-of-00004.safetensors",
529
+ "model.layers.6.self_attn.v_b_proj.bias": "model-00001-of-00004.safetensors",
530
+ "model.layers.6.self_attn.v_b_proj.weight": "model-00001-of-00004.safetensors",
531
+ "model.layers.6.self_attn.v_proj.bias": "model-00001-of-00004.safetensors",
532
+ "model.layers.6.self_attn.v_proj.weight": "model-00001-of-00004.safetensors",
533
+ "model.layers.7.input_layernorm.weight": "model-00001-of-00004.safetensors",
534
+ "model.layers.7.mlp.down_proj.weight": "model-00001-of-00004.safetensors",
535
+ "model.layers.7.mlp.gate_proj.weight": "model-00001-of-00004.safetensors",
536
+ "model.layers.7.mlp.up_proj.weight": "model-00001-of-00004.safetensors",
537
+ "model.layers.7.post_attention_layernorm.weight": "model-00001-of-00004.safetensors",
538
+ "model.layers.7.self_attn.k_b_proj_nope.bias": "model-00001-of-00004.safetensors",
539
+ "model.layers.7.self_attn.k_b_proj_nope.weight": "model-00001-of-00004.safetensors",
540
+ "model.layers.7.self_attn.k_nope_scale_factor": "model-00001-of-00004.safetensors",
541
+ "model.layers.7.self_attn.k_proj.bias": "model-00001-of-00004.safetensors",
542
+ "model.layers.7.self_attn.k_proj.weight": "model-00001-of-00004.safetensors",
543
+ "model.layers.7.self_attn.k_proj_pe.bias": "model-00001-of-00004.safetensors",
544
+ "model.layers.7.self_attn.k_proj_pe.weight": "model-00001-of-00004.safetensors",
545
+ "model.layers.7.self_attn.kv_a_proj_nope.weight": "model-00001-of-00004.safetensors",
546
+ "model.layers.7.self_attn.o_proj.weight": "model-00001-of-00004.safetensors",
547
+ "model.layers.7.self_attn.q_proj.bias": "model-00001-of-00004.safetensors",
548
+ "model.layers.7.self_attn.q_proj.weight": "model-00001-of-00004.safetensors",
549
+ "model.layers.7.self_attn.softmax_temperature": "model-00001-of-00004.safetensors",
550
+ "model.layers.7.self_attn.v_b_proj.bias": "model-00001-of-00004.safetensors",
551
+ "model.layers.7.self_attn.v_b_proj.weight": "model-00001-of-00004.safetensors",
552
+ "model.layers.7.self_attn.v_proj.bias": "model-00001-of-00004.safetensors",
553
+ "model.layers.7.self_attn.v_proj.weight": "model-00001-of-00004.safetensors",
554
+ "model.layers.8.input_layernorm.weight": "model-00002-of-00004.safetensors",
555
+ "model.layers.8.mlp.down_proj.weight": "model-00002-of-00004.safetensors",
556
+ "model.layers.8.mlp.gate_proj.weight": "model-00002-of-00004.safetensors",
557
+ "model.layers.8.mlp.up_proj.weight": "model-00002-of-00004.safetensors",
558
+ "model.layers.8.post_attention_layernorm.weight": "model-00002-of-00004.safetensors",
559
+ "model.layers.8.self_attn.k_b_proj_nope.bias": "model-00001-of-00004.safetensors",
560
+ "model.layers.8.self_attn.k_b_proj_nope.weight": "model-00001-of-00004.safetensors",
561
+ "model.layers.8.self_attn.k_nope_scale_factor": "model-00001-of-00004.safetensors",
562
+ "model.layers.8.self_attn.k_proj.bias": "model-00001-of-00004.safetensors",
563
+ "model.layers.8.self_attn.k_proj.weight": "model-00001-of-00004.safetensors",
564
+ "model.layers.8.self_attn.k_proj_pe.bias": "model-00001-of-00004.safetensors",
565
+ "model.layers.8.self_attn.k_proj_pe.weight": "model-00001-of-00004.safetensors",
566
+ "model.layers.8.self_attn.kv_a_proj_nope.weight": "model-00001-of-00004.safetensors",
567
+ "model.layers.8.self_attn.o_proj.weight": "model-00001-of-00004.safetensors",
568
+ "model.layers.8.self_attn.q_proj.bias": "model-00001-of-00004.safetensors",
569
+ "model.layers.8.self_attn.q_proj.weight": "model-00001-of-00004.safetensors",
570
+ "model.layers.8.self_attn.softmax_temperature": "model-00001-of-00004.safetensors",
571
+ "model.layers.8.self_attn.v_b_proj.bias": "model-00001-of-00004.safetensors",
572
+ "model.layers.8.self_attn.v_b_proj.weight": "model-00001-of-00004.safetensors",
573
+ "model.layers.8.self_attn.v_proj.bias": "model-00001-of-00004.safetensors",
574
+ "model.layers.8.self_attn.v_proj.weight": "model-00001-of-00004.safetensors",
575
+ "model.layers.9.input_layernorm.weight": "model-00002-of-00004.safetensors",
576
+ "model.layers.9.mlp.down_proj.weight": "model-00002-of-00004.safetensors",
577
+ "model.layers.9.mlp.gate_proj.weight": "model-00002-of-00004.safetensors",
578
+ "model.layers.9.mlp.up_proj.weight": "model-00002-of-00004.safetensors",
579
+ "model.layers.9.post_attention_layernorm.weight": "model-00002-of-00004.safetensors",
580
+ "model.layers.9.self_attn.k_b_proj_nope.bias": "model-00002-of-00004.safetensors",
581
+ "model.layers.9.self_attn.k_b_proj_nope.weight": "model-00002-of-00004.safetensors",
582
+ "model.layers.9.self_attn.k_nope_scale_factor": "model-00002-of-00004.safetensors",
583
+ "model.layers.9.self_attn.k_proj.bias": "model-00002-of-00004.safetensors",
584
+ "model.layers.9.self_attn.k_proj.weight": "model-00002-of-00004.safetensors",
585
+ "model.layers.9.self_attn.k_proj_pe.bias": "model-00002-of-00004.safetensors",
586
+ "model.layers.9.self_attn.k_proj_pe.weight": "model-00002-of-00004.safetensors",
587
+ "model.layers.9.self_attn.kv_a_proj_nope.weight": "model-00002-of-00004.safetensors",
588
+ "model.layers.9.self_attn.o_proj.weight": "model-00002-of-00004.safetensors",
589
+ "model.layers.9.self_attn.q_proj.bias": "model-00002-of-00004.safetensors",
590
+ "model.layers.9.self_attn.q_proj.weight": "model-00002-of-00004.safetensors",
591
+ "model.layers.9.self_attn.softmax_temperature": "model-00002-of-00004.safetensors",
592
+ "model.layers.9.self_attn.v_b_proj.bias": "model-00002-of-00004.safetensors",
593
+ "model.layers.9.self_attn.v_b_proj.weight": "model-00002-of-00004.safetensors",
594
+ "model.layers.9.self_attn.v_proj.bias": "model-00002-of-00004.safetensors",
595
+ "model.layers.9.self_attn.v_proj.weight": "model-00002-of-00004.safetensors",
596
+ "model.mm_projector.mlp.0.bias": "model-00004-of-00004.safetensors",
597
+ "model.mm_projector.mlp.0.weight": "model-00004-of-00004.safetensors",
598
+ "model.mm_projector.mlp.2.bias": "model-00004-of-00004.safetensors",
599
+ "model.mm_projector.mlp.2.weight": "model-00004-of-00004.safetensors",
600
+ "model.norm.weight": "model-00003-of-00004.safetensors",
601
+ "model.vision_tower.vision_tower.encoder.blocks.0.attn.proj.bias": "model-00003-of-00004.safetensors",
602
+ "model.vision_tower.vision_tower.encoder.blocks.0.attn.proj.weight": "model-00003-of-00004.safetensors",
603
+ "model.vision_tower.vision_tower.encoder.blocks.0.attn.q_bias": "model-00003-of-00004.safetensors",
604
+ "model.vision_tower.vision_tower.encoder.blocks.0.attn.qkv.weight": "model-00003-of-00004.safetensors",
605
+ "model.vision_tower.vision_tower.encoder.blocks.0.attn.v_bias": "model-00003-of-00004.safetensors",
606
+ "model.vision_tower.vision_tower.encoder.blocks.0.mlp.fc1.bias": "model-00003-of-00004.safetensors",
607
+ "model.vision_tower.vision_tower.encoder.blocks.0.mlp.fc1.weight": "model-00003-of-00004.safetensors",
608
+ "model.vision_tower.vision_tower.encoder.blocks.0.mlp.fc2.bias": "model-00003-of-00004.safetensors",
609
+ "model.vision_tower.vision_tower.encoder.blocks.0.mlp.fc2.weight": "model-00003-of-00004.safetensors",
610
+ "model.vision_tower.vision_tower.encoder.blocks.0.norm1.bias": "model-00003-of-00004.safetensors",
611
+ "model.vision_tower.vision_tower.encoder.blocks.0.norm1.weight": "model-00003-of-00004.safetensors",
612
+ "model.vision_tower.vision_tower.encoder.blocks.0.norm2.bias": "model-00003-of-00004.safetensors",
613
+ "model.vision_tower.vision_tower.encoder.blocks.0.norm2.weight": "model-00003-of-00004.safetensors",
614
+ "model.vision_tower.vision_tower.encoder.blocks.1.attn.proj.bias": "model-00003-of-00004.safetensors",
615
+ "model.vision_tower.vision_tower.encoder.blocks.1.attn.proj.weight": "model-00003-of-00004.safetensors",
616
+ "model.vision_tower.vision_tower.encoder.blocks.1.attn.q_bias": "model-00003-of-00004.safetensors",
617
+ "model.vision_tower.vision_tower.encoder.blocks.1.attn.qkv.weight": "model-00003-of-00004.safetensors",
618
+ "model.vision_tower.vision_tower.encoder.blocks.1.attn.v_bias": "model-00003-of-00004.safetensors",
619
+ "model.vision_tower.vision_tower.encoder.blocks.1.mlp.fc1.bias": "model-00003-of-00004.safetensors",
620
+ "model.vision_tower.vision_tower.encoder.blocks.1.mlp.fc1.weight": "model-00003-of-00004.safetensors",
621
+ "model.vision_tower.vision_tower.encoder.blocks.1.mlp.fc2.bias": "model-00003-of-00004.safetensors",
622
+ "model.vision_tower.vision_tower.encoder.blocks.1.mlp.fc2.weight": "model-00003-of-00004.safetensors",
623
+ "model.vision_tower.vision_tower.encoder.blocks.1.norm1.bias": "model-00003-of-00004.safetensors",
624
+ "model.vision_tower.vision_tower.encoder.blocks.1.norm1.weight": "model-00003-of-00004.safetensors",
625
+ "model.vision_tower.vision_tower.encoder.blocks.1.norm2.bias": "model-00003-of-00004.safetensors",
626
+ "model.vision_tower.vision_tower.encoder.blocks.1.norm2.weight": "model-00003-of-00004.safetensors",
627
+ "model.vision_tower.vision_tower.encoder.blocks.10.attn.proj.bias": "model-00003-of-00004.safetensors",
628
+ "model.vision_tower.vision_tower.encoder.blocks.10.attn.proj.weight": "model-00003-of-00004.safetensors",
629
+ "model.vision_tower.vision_tower.encoder.blocks.10.attn.q_bias": "model-00003-of-00004.safetensors",
630
+ "model.vision_tower.vision_tower.encoder.blocks.10.attn.qkv.weight": "model-00003-of-00004.safetensors",
631
+ "model.vision_tower.vision_tower.encoder.blocks.10.attn.v_bias": "model-00003-of-00004.safetensors",
632
+ "model.vision_tower.vision_tower.encoder.blocks.10.mlp.fc1.bias": "model-00003-of-00004.safetensors",
633
+ "model.vision_tower.vision_tower.encoder.blocks.10.mlp.fc1.weight": "model-00003-of-00004.safetensors",
634
+ "model.vision_tower.vision_tower.encoder.blocks.10.mlp.fc2.bias": "model-00003-of-00004.safetensors",
635
+ "model.vision_tower.vision_tower.encoder.blocks.10.mlp.fc2.weight": "model-00003-of-00004.safetensors",
636
+ "model.vision_tower.vision_tower.encoder.blocks.10.norm1.bias": "model-00003-of-00004.safetensors",
637
+ "model.vision_tower.vision_tower.encoder.blocks.10.norm1.weight": "model-00003-of-00004.safetensors",
638
+ "model.vision_tower.vision_tower.encoder.blocks.10.norm2.bias": "model-00003-of-00004.safetensors",
639
+ "model.vision_tower.vision_tower.encoder.blocks.10.norm2.weight": "model-00003-of-00004.safetensors",
640
+ "model.vision_tower.vision_tower.encoder.blocks.11.attn.proj.bias": "model-00003-of-00004.safetensors",
641
+ "model.vision_tower.vision_tower.encoder.blocks.11.attn.proj.weight": "model-00003-of-00004.safetensors",
642
+ "model.vision_tower.vision_tower.encoder.blocks.11.attn.q_bias": "model-00003-of-00004.safetensors",
643
+ "model.vision_tower.vision_tower.encoder.blocks.11.attn.qkv.weight": "model-00003-of-00004.safetensors",
644
+ "model.vision_tower.vision_tower.encoder.blocks.11.attn.v_bias": "model-00003-of-00004.safetensors",
645
+ "model.vision_tower.vision_tower.encoder.blocks.11.mlp.fc1.bias": "model-00003-of-00004.safetensors",
646
+ "model.vision_tower.vision_tower.encoder.blocks.11.mlp.fc1.weight": "model-00003-of-00004.safetensors",
647
+ "model.vision_tower.vision_tower.encoder.blocks.11.mlp.fc2.bias": "model-00003-of-00004.safetensors",
648
+ "model.vision_tower.vision_tower.encoder.blocks.11.mlp.fc2.weight": "model-00003-of-00004.safetensors",
649
+ "model.vision_tower.vision_tower.encoder.blocks.11.norm1.bias": "model-00003-of-00004.safetensors",
650
+ "model.vision_tower.vision_tower.encoder.blocks.11.norm1.weight": "model-00003-of-00004.safetensors",
651
+ "model.vision_tower.vision_tower.encoder.blocks.11.norm2.bias": "model-00003-of-00004.safetensors",
652
+ "model.vision_tower.vision_tower.encoder.blocks.11.norm2.weight": "model-00003-of-00004.safetensors",
653
+ "model.vision_tower.vision_tower.encoder.blocks.12.attn.proj.bias": "model-00003-of-00004.safetensors",
654
+ "model.vision_tower.vision_tower.encoder.blocks.12.attn.proj.weight": "model-00003-of-00004.safetensors",
655
+ "model.vision_tower.vision_tower.encoder.blocks.12.attn.q_bias": "model-00003-of-00004.safetensors",
656
+ "model.vision_tower.vision_tower.encoder.blocks.12.attn.qkv.weight": "model-00003-of-00004.safetensors",
657
+ "model.vision_tower.vision_tower.encoder.blocks.12.attn.v_bias": "model-00003-of-00004.safetensors",
658
+ "model.vision_tower.vision_tower.encoder.blocks.12.mlp.fc1.bias": "model-00003-of-00004.safetensors",
659
+ "model.vision_tower.vision_tower.encoder.blocks.12.mlp.fc1.weight": "model-00003-of-00004.safetensors",
660
+ "model.vision_tower.vision_tower.encoder.blocks.12.mlp.fc2.bias": "model-00003-of-00004.safetensors",
661
+ "model.vision_tower.vision_tower.encoder.blocks.12.mlp.fc2.weight": "model-00003-of-00004.safetensors",
662
+ "model.vision_tower.vision_tower.encoder.blocks.12.norm1.bias": "model-00003-of-00004.safetensors",
663
+ "model.vision_tower.vision_tower.encoder.blocks.12.norm1.weight": "model-00003-of-00004.safetensors",
664
+ "model.vision_tower.vision_tower.encoder.blocks.12.norm2.bias": "model-00003-of-00004.safetensors",
665
+ "model.vision_tower.vision_tower.encoder.blocks.12.norm2.weight": "model-00003-of-00004.safetensors",
666
+ "model.vision_tower.vision_tower.encoder.blocks.13.attn.proj.bias": "model-00003-of-00004.safetensors",
667
+ "model.vision_tower.vision_tower.encoder.blocks.13.attn.proj.weight": "model-00003-of-00004.safetensors",
668
+ "model.vision_tower.vision_tower.encoder.blocks.13.attn.q_bias": "model-00003-of-00004.safetensors",
669
+ "model.vision_tower.vision_tower.encoder.blocks.13.attn.qkv.weight": "model-00003-of-00004.safetensors",
670
+ "model.vision_tower.vision_tower.encoder.blocks.13.attn.v_bias": "model-00003-of-00004.safetensors",
671
+ "model.vision_tower.vision_tower.encoder.blocks.13.mlp.fc1.bias": "model-00003-of-00004.safetensors",
672
+ "model.vision_tower.vision_tower.encoder.blocks.13.mlp.fc1.weight": "model-00003-of-00004.safetensors",
673
+ "model.vision_tower.vision_tower.encoder.blocks.13.mlp.fc2.bias": "model-00003-of-00004.safetensors",
674
+ "model.vision_tower.vision_tower.encoder.blocks.13.mlp.fc2.weight": "model-00003-of-00004.safetensors",
675
+ "model.vision_tower.vision_tower.encoder.blocks.13.norm1.bias": "model-00003-of-00004.safetensors",
676
+ "model.vision_tower.vision_tower.encoder.blocks.13.norm1.weight": "model-00003-of-00004.safetensors",
677
+ "model.vision_tower.vision_tower.encoder.blocks.13.norm2.bias": "model-00003-of-00004.safetensors",
678
+ "model.vision_tower.vision_tower.encoder.blocks.13.norm2.weight": "model-00003-of-00004.safetensors",
679
+ "model.vision_tower.vision_tower.encoder.blocks.14.attn.proj.bias": "model-00003-of-00004.safetensors",
680
+ "model.vision_tower.vision_tower.encoder.blocks.14.attn.proj.weight": "model-00003-of-00004.safetensors",
681
+ "model.vision_tower.vision_tower.encoder.blocks.14.attn.q_bias": "model-00003-of-00004.safetensors",
682
+ "model.vision_tower.vision_tower.encoder.blocks.14.attn.qkv.weight": "model-00003-of-00004.safetensors",
683
+ "model.vision_tower.vision_tower.encoder.blocks.14.attn.v_bias": "model-00003-of-00004.safetensors",
684
+ "model.vision_tower.vision_tower.encoder.blocks.14.mlp.fc1.bias": "model-00003-of-00004.safetensors",
685
+ "model.vision_tower.vision_tower.encoder.blocks.14.mlp.fc1.weight": "model-00003-of-00004.safetensors",
686
+ "model.vision_tower.vision_tower.encoder.blocks.14.mlp.fc2.bias": "model-00003-of-00004.safetensors",
687
+ "model.vision_tower.vision_tower.encoder.blocks.14.mlp.fc2.weight": "model-00003-of-00004.safetensors",
688
+ "model.vision_tower.vision_tower.encoder.blocks.14.norm1.bias": "model-00003-of-00004.safetensors",
689
+ "model.vision_tower.vision_tower.encoder.blocks.14.norm1.weight": "model-00003-of-00004.safetensors",
690
+ "model.vision_tower.vision_tower.encoder.blocks.14.norm2.bias": "model-00003-of-00004.safetensors",
691
+ "model.vision_tower.vision_tower.encoder.blocks.14.norm2.weight": "model-00003-of-00004.safetensors",
692
+ "model.vision_tower.vision_tower.encoder.blocks.15.attn.proj.bias": "model-00003-of-00004.safetensors",
693
+ "model.vision_tower.vision_tower.encoder.blocks.15.attn.proj.weight": "model-00003-of-00004.safetensors",
694
+ "model.vision_tower.vision_tower.encoder.blocks.15.attn.q_bias": "model-00003-of-00004.safetensors",
695
+ "model.vision_tower.vision_tower.encoder.blocks.15.attn.qkv.weight": "model-00003-of-00004.safetensors",
696
+ "model.vision_tower.vision_tower.encoder.blocks.15.attn.v_bias": "model-00003-of-00004.safetensors",
697
+ "model.vision_tower.vision_tower.encoder.blocks.15.mlp.fc1.bias": "model-00003-of-00004.safetensors",
698
+ "model.vision_tower.vision_tower.encoder.blocks.15.mlp.fc1.weight": "model-00003-of-00004.safetensors",
699
+ "model.vision_tower.vision_tower.encoder.blocks.15.mlp.fc2.bias": "model-00003-of-00004.safetensors",
700
+ "model.vision_tower.vision_tower.encoder.blocks.15.mlp.fc2.weight": "model-00003-of-00004.safetensors",
701
+ "model.vision_tower.vision_tower.encoder.blocks.15.norm1.bias": "model-00003-of-00004.safetensors",
702
+ "model.vision_tower.vision_tower.encoder.blocks.15.norm1.weight": "model-00003-of-00004.safetensors",
703
+ "model.vision_tower.vision_tower.encoder.blocks.15.norm2.bias": "model-00003-of-00004.safetensors",
704
+ "model.vision_tower.vision_tower.encoder.blocks.15.norm2.weight": "model-00003-of-00004.safetensors",
705
+ "model.vision_tower.vision_tower.encoder.blocks.16.attn.proj.bias": "model-00003-of-00004.safetensors",
706
+ "model.vision_tower.vision_tower.encoder.blocks.16.attn.proj.weight": "model-00003-of-00004.safetensors",
707
+ "model.vision_tower.vision_tower.encoder.blocks.16.attn.q_bias": "model-00003-of-00004.safetensors",
708
+ "model.vision_tower.vision_tower.encoder.blocks.16.attn.qkv.weight": "model-00003-of-00004.safetensors",
709
+ "model.vision_tower.vision_tower.encoder.blocks.16.attn.v_bias": "model-00003-of-00004.safetensors",
710
+ "model.vision_tower.vision_tower.encoder.blocks.16.mlp.fc1.bias": "model-00003-of-00004.safetensors",
711
+ "model.vision_tower.vision_tower.encoder.blocks.16.mlp.fc1.weight": "model-00003-of-00004.safetensors",
712
+ "model.vision_tower.vision_tower.encoder.blocks.16.mlp.fc2.bias": "model-00003-of-00004.safetensors",
713
+ "model.vision_tower.vision_tower.encoder.blocks.16.mlp.fc2.weight": "model-00003-of-00004.safetensors",
714
+ "model.vision_tower.vision_tower.encoder.blocks.16.norm1.bias": "model-00003-of-00004.safetensors",
715
+ "model.vision_tower.vision_tower.encoder.blocks.16.norm1.weight": "model-00003-of-00004.safetensors",
716
+ "model.vision_tower.vision_tower.encoder.blocks.16.norm2.bias": "model-00003-of-00004.safetensors",
717
+ "model.vision_tower.vision_tower.encoder.blocks.16.norm2.weight": "model-00003-of-00004.safetensors",
718
+ "model.vision_tower.vision_tower.encoder.blocks.17.attn.proj.bias": "model-00004-of-00004.safetensors",
719
+ "model.vision_tower.vision_tower.encoder.blocks.17.attn.proj.weight": "model-00004-of-00004.safetensors",
720
+ "model.vision_tower.vision_tower.encoder.blocks.17.attn.q_bias": "model-00003-of-00004.safetensors",
721
+ "model.vision_tower.vision_tower.encoder.blocks.17.attn.qkv.weight": "model-00004-of-00004.safetensors",
722
+ "model.vision_tower.vision_tower.encoder.blocks.17.attn.v_bias": "model-00003-of-00004.safetensors",
723
+ "model.vision_tower.vision_tower.encoder.blocks.17.mlp.fc1.bias": "model-00004-of-00004.safetensors",
724
+ "model.vision_tower.vision_tower.encoder.blocks.17.mlp.fc1.weight": "model-00004-of-00004.safetensors",
725
+ "model.vision_tower.vision_tower.encoder.blocks.17.mlp.fc2.bias": "model-00004-of-00004.safetensors",
726
+ "model.vision_tower.vision_tower.encoder.blocks.17.mlp.fc2.weight": "model-00004-of-00004.safetensors",
727
+ "model.vision_tower.vision_tower.encoder.blocks.17.norm1.bias": "model-00003-of-00004.safetensors",
728
+ "model.vision_tower.vision_tower.encoder.blocks.17.norm1.weight": "model-00003-of-00004.safetensors",
729
+ "model.vision_tower.vision_tower.encoder.blocks.17.norm2.bias": "model-00004-of-00004.safetensors",
730
+ "model.vision_tower.vision_tower.encoder.blocks.17.norm2.weight": "model-00004-of-00004.safetensors",
731
+ "model.vision_tower.vision_tower.encoder.blocks.18.attn.proj.bias": "model-00004-of-00004.safetensors",
732
+ "model.vision_tower.vision_tower.encoder.blocks.18.attn.proj.weight": "model-00004-of-00004.safetensors",
733
+ "model.vision_tower.vision_tower.encoder.blocks.18.attn.q_bias": "model-00004-of-00004.safetensors",
734
+ "model.vision_tower.vision_tower.encoder.blocks.18.attn.qkv.weight": "model-00004-of-00004.safetensors",
735
+ "model.vision_tower.vision_tower.encoder.blocks.18.attn.v_bias": "model-00004-of-00004.safetensors",
736
+ "model.vision_tower.vision_tower.encoder.blocks.18.mlp.fc1.bias": "model-00004-of-00004.safetensors",
737
+ "model.vision_tower.vision_tower.encoder.blocks.18.mlp.fc1.weight": "model-00004-of-00004.safetensors",
738
+ "model.vision_tower.vision_tower.encoder.blocks.18.mlp.fc2.bias": "model-00004-of-00004.safetensors",
739
+ "model.vision_tower.vision_tower.encoder.blocks.18.mlp.fc2.weight": "model-00004-of-00004.safetensors",
740
+ "model.vision_tower.vision_tower.encoder.blocks.18.norm1.bias": "model-00004-of-00004.safetensors",
741
+ "model.vision_tower.vision_tower.encoder.blocks.18.norm1.weight": "model-00004-of-00004.safetensors",
742
+ "model.vision_tower.vision_tower.encoder.blocks.18.norm2.bias": "model-00004-of-00004.safetensors",
743
+ "model.vision_tower.vision_tower.encoder.blocks.18.norm2.weight": "model-00004-of-00004.safetensors",
744
+ "model.vision_tower.vision_tower.encoder.blocks.19.attn.proj.bias": "model-00004-of-00004.safetensors",
745
+ "model.vision_tower.vision_tower.encoder.blocks.19.attn.proj.weight": "model-00004-of-00004.safetensors",
746
+ "model.vision_tower.vision_tower.encoder.blocks.19.attn.q_bias": "model-00004-of-00004.safetensors",
747
+ "model.vision_tower.vision_tower.encoder.blocks.19.attn.qkv.weight": "model-00004-of-00004.safetensors",
748
+ "model.vision_tower.vision_tower.encoder.blocks.19.attn.v_bias": "model-00004-of-00004.safetensors",
749
+ "model.vision_tower.vision_tower.encoder.blocks.19.mlp.fc1.bias": "model-00004-of-00004.safetensors",
750
+ "model.vision_tower.vision_tower.encoder.blocks.19.mlp.fc1.weight": "model-00004-of-00004.safetensors",
751
+ "model.vision_tower.vision_tower.encoder.blocks.19.mlp.fc2.bias": "model-00004-of-00004.safetensors",
752
+ "model.vision_tower.vision_tower.encoder.blocks.19.mlp.fc2.weight": "model-00004-of-00004.safetensors",
753
+ "model.vision_tower.vision_tower.encoder.blocks.19.norm1.bias": "model-00004-of-00004.safetensors",
754
+ "model.vision_tower.vision_tower.encoder.blocks.19.norm1.weight": "model-00004-of-00004.safetensors",
755
+ "model.vision_tower.vision_tower.encoder.blocks.19.norm2.bias": "model-00004-of-00004.safetensors",
756
+ "model.vision_tower.vision_tower.encoder.blocks.19.norm2.weight": "model-00004-of-00004.safetensors",
757
+ "model.vision_tower.vision_tower.encoder.blocks.2.attn.proj.bias": "model-00003-of-00004.safetensors",
758
+ "model.vision_tower.vision_tower.encoder.blocks.2.attn.proj.weight": "model-00003-of-00004.safetensors",
759
+ "model.vision_tower.vision_tower.encoder.blocks.2.attn.q_bias": "model-00003-of-00004.safetensors",
760
+ "model.vision_tower.vision_tower.encoder.blocks.2.attn.qkv.weight": "model-00003-of-00004.safetensors",
761
+ "model.vision_tower.vision_tower.encoder.blocks.2.attn.v_bias": "model-00003-of-00004.safetensors",
762
+ "model.vision_tower.vision_tower.encoder.blocks.2.mlp.fc1.bias": "model-00003-of-00004.safetensors",
763
+ "model.vision_tower.vision_tower.encoder.blocks.2.mlp.fc1.weight": "model-00003-of-00004.safetensors",
764
+ "model.vision_tower.vision_tower.encoder.blocks.2.mlp.fc2.bias": "model-00003-of-00004.safetensors",
765
+ "model.vision_tower.vision_tower.encoder.blocks.2.mlp.fc2.weight": "model-00003-of-00004.safetensors",
766
+ "model.vision_tower.vision_tower.encoder.blocks.2.norm1.bias": "model-00003-of-00004.safetensors",
767
+ "model.vision_tower.vision_tower.encoder.blocks.2.norm1.weight": "model-00003-of-00004.safetensors",
768
+ "model.vision_tower.vision_tower.encoder.blocks.2.norm2.bias": "model-00003-of-00004.safetensors",
769
+ "model.vision_tower.vision_tower.encoder.blocks.2.norm2.weight": "model-00003-of-00004.safetensors",
770
+ "model.vision_tower.vision_tower.encoder.blocks.20.attn.proj.bias": "model-00004-of-00004.safetensors",
771
+ "model.vision_tower.vision_tower.encoder.blocks.20.attn.proj.weight": "model-00004-of-00004.safetensors",
772
+ "model.vision_tower.vision_tower.encoder.blocks.20.attn.q_bias": "model-00004-of-00004.safetensors",
773
+ "model.vision_tower.vision_tower.encoder.blocks.20.attn.qkv.weight": "model-00004-of-00004.safetensors",
774
+ "model.vision_tower.vision_tower.encoder.blocks.20.attn.v_bias": "model-00004-of-00004.safetensors",
775
+ "model.vision_tower.vision_tower.encoder.blocks.20.mlp.fc1.bias": "model-00004-of-00004.safetensors",
776
+ "model.vision_tower.vision_tower.encoder.blocks.20.mlp.fc1.weight": "model-00004-of-00004.safetensors",
777
+ "model.vision_tower.vision_tower.encoder.blocks.20.mlp.fc2.bias": "model-00004-of-00004.safetensors",
778
+ "model.vision_tower.vision_tower.encoder.blocks.20.mlp.fc2.weight": "model-00004-of-00004.safetensors",
779
+ "model.vision_tower.vision_tower.encoder.blocks.20.norm1.bias": "model-00004-of-00004.safetensors",
780
+ "model.vision_tower.vision_tower.encoder.blocks.20.norm1.weight": "model-00004-of-00004.safetensors",
781
+ "model.vision_tower.vision_tower.encoder.blocks.20.norm2.bias": "model-00004-of-00004.safetensors",
782
+ "model.vision_tower.vision_tower.encoder.blocks.20.norm2.weight": "model-00004-of-00004.safetensors",
783
+ "model.vision_tower.vision_tower.encoder.blocks.21.attn.proj.bias": "model-00004-of-00004.safetensors",
784
+ "model.vision_tower.vision_tower.encoder.blocks.21.attn.proj.weight": "model-00004-of-00004.safetensors",
785
+ "model.vision_tower.vision_tower.encoder.blocks.21.attn.q_bias": "model-00004-of-00004.safetensors",
786
+ "model.vision_tower.vision_tower.encoder.blocks.21.attn.qkv.weight": "model-00004-of-00004.safetensors",
787
+ "model.vision_tower.vision_tower.encoder.blocks.21.attn.v_bias": "model-00004-of-00004.safetensors",
788
+ "model.vision_tower.vision_tower.encoder.blocks.21.mlp.fc1.bias": "model-00004-of-00004.safetensors",
789
+ "model.vision_tower.vision_tower.encoder.blocks.21.mlp.fc1.weight": "model-00004-of-00004.safetensors",
790
+ "model.vision_tower.vision_tower.encoder.blocks.21.mlp.fc2.bias": "model-00004-of-00004.safetensors",
791
+ "model.vision_tower.vision_tower.encoder.blocks.21.mlp.fc2.weight": "model-00004-of-00004.safetensors",
792
+ "model.vision_tower.vision_tower.encoder.blocks.21.norm1.bias": "model-00004-of-00004.safetensors",
793
+ "model.vision_tower.vision_tower.encoder.blocks.21.norm1.weight": "model-00004-of-00004.safetensors",
794
+ "model.vision_tower.vision_tower.encoder.blocks.21.norm2.bias": "model-00004-of-00004.safetensors",
795
+ "model.vision_tower.vision_tower.encoder.blocks.21.norm2.weight": "model-00004-of-00004.safetensors",
796
+ "model.vision_tower.vision_tower.encoder.blocks.22.attn.proj.bias": "model-00004-of-00004.safetensors",
797
+ "model.vision_tower.vision_tower.encoder.blocks.22.attn.proj.weight": "model-00004-of-00004.safetensors",
798
+ "model.vision_tower.vision_tower.encoder.blocks.22.attn.q_bias": "model-00004-of-00004.safetensors",
799
+ "model.vision_tower.vision_tower.encoder.blocks.22.attn.qkv.weight": "model-00004-of-00004.safetensors",
800
+ "model.vision_tower.vision_tower.encoder.blocks.22.attn.v_bias": "model-00004-of-00004.safetensors",
801
+ "model.vision_tower.vision_tower.encoder.blocks.22.mlp.fc1.bias": "model-00004-of-00004.safetensors",
802
+ "model.vision_tower.vision_tower.encoder.blocks.22.mlp.fc1.weight": "model-00004-of-00004.safetensors",
803
+ "model.vision_tower.vision_tower.encoder.blocks.22.mlp.fc2.bias": "model-00004-of-00004.safetensors",
804
+ "model.vision_tower.vision_tower.encoder.blocks.22.mlp.fc2.weight": "model-00004-of-00004.safetensors",
805
+ "model.vision_tower.vision_tower.encoder.blocks.22.norm1.bias": "model-00004-of-00004.safetensors",
806
+ "model.vision_tower.vision_tower.encoder.blocks.22.norm1.weight": "model-00004-of-00004.safetensors",
807
+ "model.vision_tower.vision_tower.encoder.blocks.22.norm2.bias": "model-00004-of-00004.safetensors",
808
+ "model.vision_tower.vision_tower.encoder.blocks.22.norm2.weight": "model-00004-of-00004.safetensors",
809
+ "model.vision_tower.vision_tower.encoder.blocks.3.attn.proj.bias": "model-00003-of-00004.safetensors",
810
+ "model.vision_tower.vision_tower.encoder.blocks.3.attn.proj.weight": "model-00003-of-00004.safetensors",
811
+ "model.vision_tower.vision_tower.encoder.blocks.3.attn.q_bias": "model-00003-of-00004.safetensors",
812
+ "model.vision_tower.vision_tower.encoder.blocks.3.attn.qkv.weight": "model-00003-of-00004.safetensors",
813
+ "model.vision_tower.vision_tower.encoder.blocks.3.attn.v_bias": "model-00003-of-00004.safetensors",
814
+ "model.vision_tower.vision_tower.encoder.blocks.3.mlp.fc1.bias": "model-00003-of-00004.safetensors",
815
+ "model.vision_tower.vision_tower.encoder.blocks.3.mlp.fc1.weight": "model-00003-of-00004.safetensors",
816
+ "model.vision_tower.vision_tower.encoder.blocks.3.mlp.fc2.bias": "model-00003-of-00004.safetensors",
817
+ "model.vision_tower.vision_tower.encoder.blocks.3.mlp.fc2.weight": "model-00003-of-00004.safetensors",
818
+ "model.vision_tower.vision_tower.encoder.blocks.3.norm1.bias": "model-00003-of-00004.safetensors",
819
+ "model.vision_tower.vision_tower.encoder.blocks.3.norm1.weight": "model-00003-of-00004.safetensors",
820
+ "model.vision_tower.vision_tower.encoder.blocks.3.norm2.bias": "model-00003-of-00004.safetensors",
821
+ "model.vision_tower.vision_tower.encoder.blocks.3.norm2.weight": "model-00003-of-00004.safetensors",
822
+ "model.vision_tower.vision_tower.encoder.blocks.4.attn.proj.bias": "model-00003-of-00004.safetensors",
823
+ "model.vision_tower.vision_tower.encoder.blocks.4.attn.proj.weight": "model-00003-of-00004.safetensors",
824
+ "model.vision_tower.vision_tower.encoder.blocks.4.attn.q_bias": "model-00003-of-00004.safetensors",
825
+ "model.vision_tower.vision_tower.encoder.blocks.4.attn.qkv.weight": "model-00003-of-00004.safetensors",
826
+ "model.vision_tower.vision_tower.encoder.blocks.4.attn.v_bias": "model-00003-of-00004.safetensors",
827
+ "model.vision_tower.vision_tower.encoder.blocks.4.mlp.fc1.bias": "model-00003-of-00004.safetensors",
828
+ "model.vision_tower.vision_tower.encoder.blocks.4.mlp.fc1.weight": "model-00003-of-00004.safetensors",
829
+ "model.vision_tower.vision_tower.encoder.blocks.4.mlp.fc2.bias": "model-00003-of-00004.safetensors",
830
+ "model.vision_tower.vision_tower.encoder.blocks.4.mlp.fc2.weight": "model-00003-of-00004.safetensors",
831
+ "model.vision_tower.vision_tower.encoder.blocks.4.norm1.bias": "model-00003-of-00004.safetensors",
832
+ "model.vision_tower.vision_tower.encoder.blocks.4.norm1.weight": "model-00003-of-00004.safetensors",
833
+ "model.vision_tower.vision_tower.encoder.blocks.4.norm2.bias": "model-00003-of-00004.safetensors",
834
+ "model.vision_tower.vision_tower.encoder.blocks.4.norm2.weight": "model-00003-of-00004.safetensors",
835
+ "model.vision_tower.vision_tower.encoder.blocks.5.attn.proj.bias": "model-00003-of-00004.safetensors",
836
+ "model.vision_tower.vision_tower.encoder.blocks.5.attn.proj.weight": "model-00003-of-00004.safetensors",
837
+ "model.vision_tower.vision_tower.encoder.blocks.5.attn.q_bias": "model-00003-of-00004.safetensors",
838
+ "model.vision_tower.vision_tower.encoder.blocks.5.attn.qkv.weight": "model-00003-of-00004.safetensors",
839
+ "model.vision_tower.vision_tower.encoder.blocks.5.attn.v_bias": "model-00003-of-00004.safetensors",
840
+ "model.vision_tower.vision_tower.encoder.blocks.5.mlp.fc1.bias": "model-00003-of-00004.safetensors",
841
+ "model.vision_tower.vision_tower.encoder.blocks.5.mlp.fc1.weight": "model-00003-of-00004.safetensors",
842
+ "model.vision_tower.vision_tower.encoder.blocks.5.mlp.fc2.bias": "model-00003-of-00004.safetensors",
843
+ "model.vision_tower.vision_tower.encoder.blocks.5.mlp.fc2.weight": "model-00003-of-00004.safetensors",
844
+ "model.vision_tower.vision_tower.encoder.blocks.5.norm1.bias": "model-00003-of-00004.safetensors",
845
+ "model.vision_tower.vision_tower.encoder.blocks.5.norm1.weight": "model-00003-of-00004.safetensors",
846
+ "model.vision_tower.vision_tower.encoder.blocks.5.norm2.bias": "model-00003-of-00004.safetensors",
847
+ "model.vision_tower.vision_tower.encoder.blocks.5.norm2.weight": "model-00003-of-00004.safetensors",
848
+ "model.vision_tower.vision_tower.encoder.blocks.6.attn.proj.bias": "model-00003-of-00004.safetensors",
849
+ "model.vision_tower.vision_tower.encoder.blocks.6.attn.proj.weight": "model-00003-of-00004.safetensors",
850
+ "model.vision_tower.vision_tower.encoder.blocks.6.attn.q_bias": "model-00003-of-00004.safetensors",
851
+ "model.vision_tower.vision_tower.encoder.blocks.6.attn.qkv.weight": "model-00003-of-00004.safetensors",
852
+ "model.vision_tower.vision_tower.encoder.blocks.6.attn.v_bias": "model-00003-of-00004.safetensors",
853
+ "model.vision_tower.vision_tower.encoder.blocks.6.mlp.fc1.bias": "model-00003-of-00004.safetensors",
854
+ "model.vision_tower.vision_tower.encoder.blocks.6.mlp.fc1.weight": "model-00003-of-00004.safetensors",
855
+ "model.vision_tower.vision_tower.encoder.blocks.6.mlp.fc2.bias": "model-00003-of-00004.safetensors",
856
+ "model.vision_tower.vision_tower.encoder.blocks.6.mlp.fc2.weight": "model-00003-of-00004.safetensors",
857
+ "model.vision_tower.vision_tower.encoder.blocks.6.norm1.bias": "model-00003-of-00004.safetensors",
858
+ "model.vision_tower.vision_tower.encoder.blocks.6.norm1.weight": "model-00003-of-00004.safetensors",
859
+ "model.vision_tower.vision_tower.encoder.blocks.6.norm2.bias": "model-00003-of-00004.safetensors",
860
+ "model.vision_tower.vision_tower.encoder.blocks.6.norm2.weight": "model-00003-of-00004.safetensors",
861
+ "model.vision_tower.vision_tower.encoder.blocks.7.attn.proj.bias": "model-00003-of-00004.safetensors",
862
+ "model.vision_tower.vision_tower.encoder.blocks.7.attn.proj.weight": "model-00003-of-00004.safetensors",
863
+ "model.vision_tower.vision_tower.encoder.blocks.7.attn.q_bias": "model-00003-of-00004.safetensors",
864
+ "model.vision_tower.vision_tower.encoder.blocks.7.attn.qkv.weight": "model-00003-of-00004.safetensors",
865
+ "model.vision_tower.vision_tower.encoder.blocks.7.attn.v_bias": "model-00003-of-00004.safetensors",
866
+ "model.vision_tower.vision_tower.encoder.blocks.7.mlp.fc1.bias": "model-00003-of-00004.safetensors",
867
+ "model.vision_tower.vision_tower.encoder.blocks.7.mlp.fc1.weight": "model-00003-of-00004.safetensors",
868
+ "model.vision_tower.vision_tower.encoder.blocks.7.mlp.fc2.bias": "model-00003-of-00004.safetensors",
869
+ "model.vision_tower.vision_tower.encoder.blocks.7.mlp.fc2.weight": "model-00003-of-00004.safetensors",
870
+ "model.vision_tower.vision_tower.encoder.blocks.7.norm1.bias": "model-00003-of-00004.safetensors",
871
+ "model.vision_tower.vision_tower.encoder.blocks.7.norm1.weight": "model-00003-of-00004.safetensors",
872
+ "model.vision_tower.vision_tower.encoder.blocks.7.norm2.bias": "model-00003-of-00004.safetensors",
873
+ "model.vision_tower.vision_tower.encoder.blocks.7.norm2.weight": "model-00003-of-00004.safetensors",
874
+ "model.vision_tower.vision_tower.encoder.blocks.8.attn.proj.bias": "model-00003-of-00004.safetensors",
875
+ "model.vision_tower.vision_tower.encoder.blocks.8.attn.proj.weight": "model-00003-of-00004.safetensors",
876
+ "model.vision_tower.vision_tower.encoder.blocks.8.attn.q_bias": "model-00003-of-00004.safetensors",
877
+ "model.vision_tower.vision_tower.encoder.blocks.8.attn.qkv.weight": "model-00003-of-00004.safetensors",
878
+ "model.vision_tower.vision_tower.encoder.blocks.8.attn.v_bias": "model-00003-of-00004.safetensors",
879
+ "model.vision_tower.vision_tower.encoder.blocks.8.mlp.fc1.bias": "model-00003-of-00004.safetensors",
880
+ "model.vision_tower.vision_tower.encoder.blocks.8.mlp.fc1.weight": "model-00003-of-00004.safetensors",
881
+ "model.vision_tower.vision_tower.encoder.blocks.8.mlp.fc2.bias": "model-00003-of-00004.safetensors",
882
+ "model.vision_tower.vision_tower.encoder.blocks.8.mlp.fc2.weight": "model-00003-of-00004.safetensors",
883
+ "model.vision_tower.vision_tower.encoder.blocks.8.norm1.bias": "model-00003-of-00004.safetensors",
884
+ "model.vision_tower.vision_tower.encoder.blocks.8.norm1.weight": "model-00003-of-00004.safetensors",
885
+ "model.vision_tower.vision_tower.encoder.blocks.8.norm2.bias": "model-00003-of-00004.safetensors",
886
+ "model.vision_tower.vision_tower.encoder.blocks.8.norm2.weight": "model-00003-of-00004.safetensors",
887
+ "model.vision_tower.vision_tower.encoder.blocks.9.attn.proj.bias": "model-00003-of-00004.safetensors",
888
+ "model.vision_tower.vision_tower.encoder.blocks.9.attn.proj.weight": "model-00003-of-00004.safetensors",
889
+ "model.vision_tower.vision_tower.encoder.blocks.9.attn.q_bias": "model-00003-of-00004.safetensors",
890
+ "model.vision_tower.vision_tower.encoder.blocks.9.attn.qkv.weight": "model-00003-of-00004.safetensors",
891
+ "model.vision_tower.vision_tower.encoder.blocks.9.attn.v_bias": "model-00003-of-00004.safetensors",
892
+ "model.vision_tower.vision_tower.encoder.blocks.9.mlp.fc1.bias": "model-00003-of-00004.safetensors",
893
+ "model.vision_tower.vision_tower.encoder.blocks.9.mlp.fc1.weight": "model-00003-of-00004.safetensors",
894
+ "model.vision_tower.vision_tower.encoder.blocks.9.mlp.fc2.bias": "model-00003-of-00004.safetensors",
895
+ "model.vision_tower.vision_tower.encoder.blocks.9.mlp.fc2.weight": "model-00003-of-00004.safetensors",
896
+ "model.vision_tower.vision_tower.encoder.blocks.9.norm1.bias": "model-00003-of-00004.safetensors",
897
+ "model.vision_tower.vision_tower.encoder.blocks.9.norm1.weight": "model-00003-of-00004.safetensors",
898
+ "model.vision_tower.vision_tower.encoder.blocks.9.norm2.bias": "model-00003-of-00004.safetensors",
899
+ "model.vision_tower.vision_tower.encoder.blocks.9.norm2.weight": "model-00003-of-00004.safetensors",
900
+ "model.vision_tower.vision_tower.encoder.patch_embed.proj.bias": "model-00003-of-00004.safetensors",
901
+ "model.vision_tower.vision_tower.encoder.patch_embed.proj.weight": "model-00003-of-00004.safetensors",
902
+ "model.vision_tower.vision_tower.encoder.vision_layernorm.bias": "model-00004-of-00004.safetensors",
903
+ "model.vision_tower.vision_tower.encoder.vision_layernorm.weight": "model-00004-of-00004.safetensors"
904
+ }
905
+ }
modeling_qwen2_flash.py ADDED
The diff for this file is too large to render. See raw diff
 
modeling_videochat_flash.py ADDED
@@ -0,0 +1,729 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright 2024
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ from abc import ABC, abstractmethod
16
+ import re
17
+ import torch
18
+ import torch.nn as nn
19
+ import random
20
+ from typing import List, Optional, Tuple, Union, Dict
21
+
22
+ from transformers import AutoConfig, AutoModelForCausalLM
23
+ from transformers.modeling_outputs import CausalLMOutputWithPast
24
+ from transformers.generation.utils import GenerateOutput
25
+ from transformers import Qwen2Config
26
+
27
+ # from llava.model.language_model.vision_tower_builder import build_vision_tower
28
+ # from llava.model.language_model.mm_projector_builder import build_vision_projector
29
+
30
+ # from llava.constants import IGNORE_INDEX, IMAGE_TOKEN_INDEX, DEFAULT_IMAGE_PATCH_TOKEN, DEFAULT_IM_START_TOKEN, DEFAULT_IM_END_TOKEN, DEFAULT_IMAGE_TOKEN
31
+ # from llava.conversation import conv_templates, SeparatorStyle
32
+ # from llava.mm_utils import tokenizer_image_token, KeywordsStoppingCriteria, get_anyres_image_grid_shape, load_video
33
+ # # from .modeling_qwen2_flash import Qwen2Model_Flash, Qwen2ForCausalLM_Flash
34
+ # # from .modeling_qwen2_flash_v7 import Qwen2Model_Flash, Qwen2ForCausalLM_Flash
35
+ # from llava.model.modeling_qwen2_flash import Qwen2Model_Flash, Qwen2ForCausalLM_Flash
36
+
37
+
38
+ from .vision_tower_builder import build_vision_tower
39
+ from .mm_projector_builder import build_vision_projector
40
+
41
+ from .constants import IGNORE_INDEX, IMAGE_TOKEN_INDEX, DEFAULT_IMAGE_PATCH_TOKEN, DEFAULT_IM_START_TOKEN, DEFAULT_IM_END_TOKEN, DEFAULT_IMAGE_TOKEN
42
+ from .conversation import conv_templates, SeparatorStyle
43
+ from .mm_utils import tokenizer_image_token, KeywordsStoppingCriteria, get_anyres_image_grid_shape, load_video
44
+ # from .modeling_qwen2_flash import Qwen2Model_Flash, Qwen2ForCausalLM_Flash
45
+ # from .modeling_qwen2_flash_v7 import Qwen2Model_Flash, Qwen2ForCausalLM_Flash
46
+ from .modeling_qwen2_flash import Qwen2Model_Flash, Qwen2ForCausalLM_Flash
47
+
48
+
49
+ class LlavaMetaModel:
50
+
51
+ def __init__(self, config):
52
+ super(LlavaMetaModel, self).__init__(config)
53
+
54
+ if hasattr(config, "mm_vision_tower"):
55
+ delay_load = getattr(config, "delay_load", False)
56
+ self.vision_tower = build_vision_tower(config, delay_load=delay_load)
57
+ self.mm_projector = build_vision_projector(config, vision_cfg=self.vision_tower.config)
58
+
59
+ if "unpad" in getattr(config, "mm_patch_merge_type", ""):
60
+ self.image_newline = nn.Parameter(torch.empty(config.hidden_size, dtype=self.dtype))
61
+ if "nopad" in getattr(config, "mm_patch_merge_type", "") and getattr(self.config, "mm_newline_position", "nothing") != "nothing":
62
+ self.frame_newline = nn.Parameter(torch.empty(config.hidden_size, dtype=self.dtype))
63
+
64
+ def get_vision_tower(self):
65
+ vision_tower = getattr(self, "vision_tower", None)
66
+ if type(vision_tower) is list:
67
+ vision_tower = vision_tower[0]
68
+ return vision_tower
69
+
70
+ def initialize_vision_modules(self, model_args, fsdp=None):
71
+ vision_tower = model_args.vision_tower
72
+ mm_vision_select_layer = model_args.mm_vision_select_layer
73
+ mm_vision_select_feature = model_args.mm_vision_select_feature
74
+ pretrain_mm_mlp_adapter = model_args.pretrain_mm_mlp_adapter
75
+ mm_patch_merge_type = model_args.mm_patch_merge_type
76
+
77
+ self.config.mm_vision_tower = vision_tower
78
+ self.config.vision_tower_pretrained = getattr(model_args, "vision_tower_pretrained", "")
79
+
80
+ if self.get_vision_tower() is None:
81
+ vision_tower = build_vision_tower(model_args)
82
+
83
+ if fsdp is not None and len(fsdp) > 0:
84
+ self.vision_tower = [vision_tower]
85
+ else:
86
+ self.vision_tower = vision_tower
87
+ else:
88
+ if fsdp is not None and len(fsdp) > 0:
89
+ vision_tower = self.vision_tower[0]
90
+ else:
91
+ vision_tower = self.vision_tower
92
+ vision_tower.load_model()
93
+
94
+
95
+
96
+ self.config.use_mm_proj = True
97
+ self.config.mm_projector_type = getattr(model_args, "mm_projector_type", "linear")
98
+ self.config.mm_vision_select_layer = mm_vision_select_layer
99
+ self.config.mm_vision_select_feature = mm_vision_select_feature
100
+ self.config.mm_patch_merge_type = mm_patch_merge_type
101
+
102
+ if getattr(self, "mm_projector", None) is None:
103
+ self.mm_projector = build_vision_projector(self.config, vision_cfg=vision_tower.config)
104
+
105
+ if "unpad" in mm_patch_merge_type:
106
+ embed_std = 1 / torch.sqrt(torch.tensor(self.config.hidden_size, dtype=self.dtype))
107
+ self.image_newline = nn.Parameter(torch.randn(self.config.hidden_size, dtype=self.dtype) * embed_std)
108
+ if "nopad" in getattr(self.config, "mm_patch_merge_type", "") and getattr(self.config, "mm_newline_position", "nothing") != "nothing":
109
+ embed_std = 1 / torch.sqrt(torch.tensor(self.config.hidden_size, dtype=self.dtype))
110
+ self.frame_newline = nn.Parameter(torch.randn(self.config.hidden_size, dtype=self.dtype) * embed_std)
111
+ else:
112
+ # In case it is frozen by LoRA
113
+ for p in self.mm_projector.parameters():
114
+ p.requires_grad = True
115
+
116
+ if pretrain_mm_mlp_adapter is not None:
117
+ mm_projector_weights = torch.load(pretrain_mm_mlp_adapter, map_location="cpu")
118
+
119
+ def get_w(weights, keyword):
120
+ return {k.split(keyword + ".")[1]: v for k, v in weights.items() if keyword in k}
121
+
122
+ if self.config.mm_projector_type =='lxh_qformer':
123
+ incompatible_keys = self.mm_projector.load_state_dict(get_w(mm_projector_weights, "mm_projector"), strict=False)
124
+ else:
125
+ incompatible_keys = self.mm_projector.load_state_dict(get_w(mm_projector_weights, "mm_projector"))
126
+ print(f"Loaded mm projector weights from {pretrain_mm_mlp_adapter}. Incompatible keys: {incompatible_keys}")
127
+
128
+
129
+ class LlavaMetaForCausalLM(ABC):
130
+
131
+ @abstractmethod
132
+ def get_model(self):
133
+ pass
134
+
135
+ def get_vision_tower(self):
136
+ return self.get_model().get_vision_tower()
137
+
138
+
139
+ def encode_video_image(self, images_list, video_idx_in_batch):
140
+ # video encoder编码后按图像的connector处理
141
+ bs = len(images_list)
142
+
143
+ concat_images = []
144
+ concat_videos = []
145
+ for idx, image in enumerate(images_list):
146
+ if idx in video_idx_in_batch:
147
+ concat_videos.append(image)
148
+ else:
149
+ concat_images.append(image)
150
+ # print(concat_videos[0].shape)
151
+ has_image = len(concat_images) > 0
152
+ has_video = len(concat_videos) > 0
153
+
154
+ mm_local_num_frames = getattr(self.config, "mm_local_num_frames", -1)
155
+ assert mm_local_num_frames != -1
156
+ if has_image:
157
+ image_split_sizes = [image.shape[0] for image in concat_images]
158
+ concat_images = torch.cat([image.unsqueeze(1) for image in concat_images], dim=0)
159
+ # print("input vit image.shape:", concat_images.shape)
160
+ images_features = self.get_model().get_vision_tower()(concat_images) # B_i, N, D
161
+ images_features = torch.split(images_features, image_split_sizes)
162
+
163
+ if has_video:
164
+ video_split_sizes = [video.shape[0] // mm_local_num_frames for video in concat_videos]
165
+ concat_videos = torch.cat([video.reshape(video.shape[0] // mm_local_num_frames, mm_local_num_frames, video.shape[1], video.shape[2], video.shape[3]) for video in concat_videos], dim=0)
166
+ # print("input vit video.shape:", concat_videos.shape)
167
+ videos_features = self.get_model().get_vision_tower()(concat_videos) # B_v, N, D
168
+ videos_features = [v.reshape(-1, v.shape[-2] // mm_local_num_frames, v.shape[-1]) for v in torch.split(videos_features, video_split_sizes)]
169
+
170
+
171
+ all_videos_or_images_features = []
172
+ img_idx = 0
173
+ vid_idx = 0
174
+
175
+ for idx in range(bs):
176
+
177
+ if idx in video_idx_in_batch:
178
+ feat = self.get_model().mm_projector(videos_features[vid_idx], compress=True, local_num_frames=getattr(self.config, "mm_local_num_frames", -1))
179
+
180
+ vid_idx += 1
181
+ else:
182
+ feat = self.get_model().mm_projector(images_features[img_idx], compress=False)
183
+ img_idx += 1
184
+ # print("video_idx_in_batch:", video_idx_in_batch)
185
+ all_videos_or_images_features.append(feat)
186
+
187
+ if has_video:
188
+ assert vid_idx == len(videos_features), f"vid: {vid_idx} != {len(videos_features)}"
189
+ if has_image:
190
+ assert img_idx == len(images_features), f"img: {img_idx} != {len(images_features)}"
191
+
192
+ return all_videos_or_images_features
193
+
194
+
195
+
196
+ def prepare_inputs_labels_for_multimodal(self, input_ids, position_ids, attention_mask, past_key_values, labels, images, modalities=["image"], image_sizes=None):
197
+ assert type(modalities) is list, modalities
198
+ mm_llm_compress = getattr(self.config, "mm_llm_compress", False)
199
+
200
+ # 初始化这些变量,无论 mm_llm_compress 是否为 True
201
+ first_image_token_position = []
202
+ text_prompt_lens = []
203
+
204
+ if mm_llm_compress:
205
+ self.model.llm_compress_type = getattr(self.config, "llm_compress_type", "attention")
206
+ self.model.llm_compress_layer_list = getattr(self.config, "llm_compress_layer_list", [8, 16, 24])
207
+ self.model.llm_image_token_ratio_list = getattr(self.config, "llm_image_token_ratio_list", [1.0, 0.5, 0.25, 0.125])
208
+ else:
209
+ self.model.llm_compress_type = "attention"
210
+ self.model.llm_compress_layer_list = []
211
+ self.model.llm_image_token_ratio_list = []
212
+
213
+ if images is None:
214
+ return input_ids, position_ids, attention_mask, past_key_values, None, labels
215
+
216
+ vision_tower = self.get_vision_tower()
217
+ # rank_print(modalities)
218
+ if vision_tower is None or images is None or input_ids.shape[1] == 1:
219
+ return input_ids, position_ids, attention_mask, past_key_values, None, labels
220
+
221
+ if type(images) is list or images.ndim == 5:
222
+ if type(images) is list:
223
+ images = [x.unsqueeze(0) if x.ndim == 3 else x for x in images]
224
+
225
+ video_idx_in_batch = []
226
+ for _ in range(len(modalities)):
227
+ if modalities[_] == "video":
228
+ video_idx_in_batch.append(_)
229
+
230
+ images_list = []
231
+ for image in images:
232
+ if image.ndim == 4:
233
+ images_list.append(image)
234
+ else:
235
+ images_list.append(image.unsqueeze(0))
236
+
237
+
238
+ vision_encode_type = getattr(self.config, "vision_encode_type", "image")
239
+ mm_patch_merge_type = getattr(self.config, "mm_patch_merge_type", "flat")
240
+ image_aspect_ratio = getattr(self.config, "image_aspect_ratio", "square")
241
+ frame_aspect_ratio = getattr(self.config, "frame_aspect_ratio", "square")
242
+ mm_newline_position = getattr(self.config, "mm_newline_position", "nothing")
243
+
244
+
245
+ if vision_encode_type == "video_image": # video backbone, process video with compress
246
+ image_features = self.encode_video_image(images_list, video_idx_in_batch=video_idx_in_batch)
247
+ else:
248
+ raise NotImplementedError(vision_encode_type)
249
+
250
+
251
+ if mm_patch_merge_type == "flat":
252
+ image_features = [x.flatten(0, 1) for x in image_features]
253
+ elif mm_patch_merge_type.startswith("spatial"):
254
+ new_image_features = []
255
+ for image_idx, image_feature in enumerate(image_features):
256
+
257
+ if image_idx in video_idx_in_batch: # video operations
258
+
259
+ if "anyres" in frame_aspect_ratio:
260
+ raise NotImplementedError
261
+ else:
262
+ frame_feature = image_feature
263
+
264
+ if "pad" in mm_patch_merge_type:
265
+ if mm_newline_position == 'one_token':
266
+ frame_feature = frame_feature.flatten(0, 1)
267
+ if "unpad" in mm_patch_merge_type:
268
+ frame_feature = torch.cat((frame_feature, self.model.image_newline[None].to(frame_feature.device)), dim=0)
269
+ else:
270
+ frame_feature = torch.cat((frame_feature, self.model.frame_newline[None].to(frame_feature.device)), dim=0)
271
+ elif mm_newline_position == 'nothing':
272
+ frame_feature = frame_feature.flatten(0, 1)
273
+ else:
274
+ raise NotImplementedError("add pad please!!")
275
+ else:
276
+ frame_feature = frame_feature.flatten(0, 1)
277
+
278
+ # print(f"final video frame_feature.shape: {frame_feature.shape}")
279
+ image_feature = frame_feature
280
+
281
+ elif image_feature.shape[0] > 1: # multi patches and multi images operations
282
+ base_image_feature = image_feature[0]
283
+ image_feature = image_feature[1:]
284
+ origin_size = image_feature.shape
285
+
286
+ height = width = self.get_model().mm_projector.num_image_patches_per_side
287
+ assert height * width == base_image_feature.shape[0], f"height:{height}, width: {width}, base_image_feature: {base_image_feature.shape}"
288
+
289
+ if "anyres_max" in image_aspect_ratio:
290
+ matched_anyres_max_num_patches = re.match(r"anyres_max_(\d+)", image_aspect_ratio)
291
+ if matched_anyres_max_num_patches:
292
+ max_num_patches = int(matched_anyres_max_num_patches.group(1))
293
+
294
+ if "anyres" in image_aspect_ratio:
295
+ if hasattr(self.get_vision_tower(), "image_size"):
296
+ vision_tower_image_size = self.get_vision_tower().image_size
297
+ else:
298
+ raise ValueError("vision_tower_image_size is not found in the vision tower.")
299
+ try:
300
+ num_patch_width, num_patch_height = get_anyres_image_grid_shape(image_sizes[image_idx], self.config.image_grid_pinpoints, vision_tower_image_size, max_resolutions=None)
301
+ except Exception as e:
302
+ print(f"Error: {e}")
303
+ raise e
304
+ # num_patch_width, num_patch_height = 2, 2
305
+
306
+ image_feature = image_feature.view(num_patch_height, num_patch_width, height, width, -1)
307
+ else:
308
+ raise NotImplementedError(image_aspect_ratio)
309
+ image_feature = image_feature.view(2, 2, height, width, -1)
310
+
311
+ if "maxpool2x2" in mm_patch_merge_type:
312
+ raise NotImplementedError
313
+ elif "unpad" in mm_patch_merge_type and "anyres_max" in image_aspect_ratio and matched_anyres_max_num_patches:
314
+ raise NotImplementedError
315
+ elif "unpad" in mm_patch_merge_type:
316
+ raise NotImplementedError
317
+ else:
318
+ image_feature = image_feature.permute(0, 2, 1, 3, 4).contiguous()
319
+ image_feature = image_feature.flatten(0, 3)
320
+ if "nobase" in mm_patch_merge_type:
321
+ pass
322
+ else:
323
+ try:
324
+ image_feature = torch.cat((base_image_feature, image_feature), dim=0)
325
+ except Exception as e:
326
+ raise ValueError(f"{num_patch_width} {num_patch_height} now: base_image_feature: {base_image_feature.shape}, {image_feature.shape}, image_sizes[image_idx]: {image_sizes[image_idx]}, origin_size: {origin_size}, {image_sizes[image_idx]}, {self.config.image_grid_pinpoints}, {vision_tower_image_size}")
327
+ else: # single image operations
328
+ image_feature = image_feature[0]
329
+ if "unpad" in mm_patch_merge_type:
330
+ image_feature = torch.cat((image_feature, self.model.image_newline[None]), dim=0)
331
+
332
+ # print(f"image/video_feature.shape: {image_feature.shape}")
333
+ new_image_features.append(image_feature)
334
+ image_features = new_image_features
335
+ else:
336
+ raise ValueError(f"Unexpected mm_patch_merge_type: {self.config.mm_patch_merge_type}")
337
+ else:
338
+ # raise NotImplementedError(f"images.shape={images.shape}, modalities={modalities}")
339
+ image_features = self.encode_image(images)
340
+
341
+ # TODO: image start / end is not implemented here to support pretraining.
342
+ if getattr(self.config, "tune_mm_mlp_adapter", False) and getattr(self.config, "mm_use_im_start_end", False):
343
+ raise NotImplementedError
344
+ # print(f"Total images len(image_features: {len(image_features)}")
345
+
346
+ # Let's just add dummy tensors if they do not exist,
347
+ # it is a headache to deal with None all the time.
348
+ # But it is not ideal, and if you have a better idea,
349
+ # please open an issue / submit a PR, thanks.
350
+ _labels = labels
351
+ _position_ids = position_ids
352
+ _attention_mask = attention_mask
353
+ if attention_mask is None:
354
+ attention_mask = torch.ones_like(input_ids, dtype=torch.bool)
355
+ else:
356
+ attention_mask = attention_mask.bool()
357
+ if position_ids is None:
358
+ position_ids = torch.arange(0, input_ids.shape[1], dtype=torch.long, device=input_ids.device)
359
+ if labels is None:
360
+ labels = torch.full_like(input_ids, IGNORE_INDEX)
361
+
362
+
363
+ input_ids = [cur_input_ids[cur_attention_mask] for cur_input_ids, cur_attention_mask in zip(input_ids, attention_mask)]
364
+ labels = [cur_labels[cur_attention_mask] for cur_labels, cur_attention_mask in zip(labels, attention_mask)]
365
+
366
+ new_input_embeds = []
367
+ new_labels = []
368
+ cur_image_idx = 0
369
+
370
+ # rank_print("Inserting Images embedding")
371
+ for batch_idx, cur_input_ids in enumerate(input_ids):
372
+ num_images = (cur_input_ids == IMAGE_TOKEN_INDEX).sum()
373
+
374
+ # 无论 mm_llm_compress 是否为 True,都记录图像位置信息
375
+ image_index = torch.where(cur_input_ids == IMAGE_TOKEN_INDEX)[0].tolist()
376
+ if mm_llm_compress and len(image_index) > 1:
377
+ # 只有在 mm_llm_compress 模式下才检查单图像/视频限制
378
+ assert len(image_index) == 1, f"Only support single image/video: {image_index}"
379
+
380
+ if len(image_index) == 0:
381
+ first_image_token_position.append(-1)
382
+ else:
383
+ first_image_token_position.append(image_index[0])
384
+
385
+ # 记录输入指令长度
386
+ if not self.training:
387
+ if len(image_index) == 0:
388
+ assert num_images == 0, num_images
389
+ else:
390
+ if mm_llm_compress:
391
+ assert num_images == 1, f"num_images={num_images}"
392
+ text_prompt_lens.append(cur_input_ids.shape[0] - num_images)
393
+
394
+ # print(f"num_images={num_images}")
395
+ if num_images == 0:
396
+ cur_image_features = image_features[cur_image_idx]
397
+ cur_input_embeds_1 = self.get_model().embed_tokens(cur_input_ids)
398
+ cur_input_embeds = torch.cat([cur_input_embeds_1, cur_image_features[0:0]], dim=0)
399
+ new_input_embeds.append(cur_input_embeds)
400
+ new_labels.append(labels[batch_idx])
401
+ cur_image_idx += 1
402
+ continue
403
+
404
+ image_token_indices = [-1] + torch.where(cur_input_ids == IMAGE_TOKEN_INDEX)[0].tolist() + [cur_input_ids.shape[0]]
405
+ cur_input_ids_noim = []
406
+ cur_labels = labels[batch_idx]
407
+ cur_labels_noim = []
408
+ for i in range(len(image_token_indices) - 1):
409
+ cur_input_ids_noim.append(cur_input_ids[image_token_indices[i] + 1 : image_token_indices[i + 1]])
410
+ cur_labels_noim.append(cur_labels[image_token_indices[i] + 1 : image_token_indices[i + 1]])
411
+ split_sizes = [x.shape[0] for x in cur_labels_noim]
412
+ cur_input_embeds = self.get_model().embed_tokens(torch.cat(cur_input_ids_noim))
413
+ cur_input_embeds_no_im = torch.split(cur_input_embeds, split_sizes, dim=0)
414
+ cur_new_input_embeds = []
415
+ cur_new_labels = []
416
+
417
+ for i in range(num_images + 1):
418
+ cur_new_input_embeds.append(cur_input_embeds_no_im[i])
419
+ cur_new_labels.append(cur_labels_noim[i])
420
+ if i < num_images:
421
+ try:
422
+ cur_image_features = image_features[cur_image_idx]
423
+ except IndexError:
424
+ print(f"cur_image_idx={cur_image_idx} is not ok")
425
+ cur_image_features = image_features[cur_image_idx - 1]
426
+ cur_image_idx += 1
427
+ cur_new_input_embeds.append(cur_image_features)
428
+ cur_new_labels.append(torch.full((cur_image_features.shape[0],), IGNORE_INDEX, device=cur_labels.device, dtype=cur_labels.dtype))
429
+
430
+ cur_new_input_embeds = [x.to(self.device) for x in cur_new_input_embeds]
431
+
432
+ # import pdb; pdb.set_trace()
433
+ cur_new_input_embeds = torch.cat(cur_new_input_embeds)
434
+ cur_new_labels = torch.cat(cur_new_labels)
435
+
436
+ new_input_embeds.append(cur_new_input_embeds)
437
+ new_labels.append(cur_new_labels)
438
+
439
+
440
+ # 无论 mm_llm_compress 是否为 True,都设置这些属性
441
+ self.model.first_image_token_position = first_image_token_position
442
+ self.model.text_prompt_lens = text_prompt_lens
443
+ self.model.num_image_token_lens = [image_feature.shape[0] for image_feature in image_features]
444
+ self.model.image_sizes = image_sizes # 保存图片尺寸信息
445
+
446
+ # Truncate sequences to max length as image embeddings can make the sequence longer
447
+ tokenizer_model_max_length = getattr(self.config, "tokenizer_model_max_length", None)
448
+ # rank_print("Finishing Inserting")
449
+
450
+ new_input_embeds = [x[:tokenizer_model_max_length] for x, modality in zip(new_input_embeds, modalities)]
451
+ new_labels = [x[:tokenizer_model_max_length] for x, modality in zip(new_labels, modalities)]
452
+
453
+ # Combine them
454
+ max_len = max(x.shape[0] for x in new_input_embeds)
455
+ batch_size = len(new_input_embeds)
456
+
457
+ new_input_embeds_padded = []
458
+ new_labels_padded = torch.full((batch_size, max_len), IGNORE_INDEX, dtype=new_labels[0].dtype, device=new_labels[0].device)
459
+ attention_mask = torch.zeros((batch_size, max_len), dtype=attention_mask.dtype, device=attention_mask.device)
460
+ position_ids = torch.zeros((batch_size, max_len), dtype=position_ids.dtype, device=position_ids.device)
461
+ # print("Prepare pos id")
462
+
463
+ for i, (cur_new_embed, cur_new_labels) in enumerate(zip(new_input_embeds, new_labels)):
464
+ cur_len = cur_new_embed.shape[0]
465
+ if getattr(self.config, "tokenizer_padding_side", "right") == "left":
466
+ new_input_embeds_padded.append(torch.cat((torch.zeros((max_len - cur_len, cur_new_embed.shape[1]), dtype=cur_new_embed.dtype, device=cur_new_embed.device), cur_new_embed), dim=0))
467
+ if cur_len > 0:
468
+ new_labels_padded[i, -cur_len:] = cur_new_labels
469
+ attention_mask[i, -cur_len:] = True
470
+ position_ids[i, -cur_len:] = torch.arange(0, cur_len, dtype=position_ids.dtype, device=position_ids.device)
471
+ else:
472
+ new_input_embeds_padded.append(torch.cat((cur_new_embed, torch.zeros((max_len - cur_len, cur_new_embed.shape[1]), dtype=cur_new_embed.dtype, device=cur_new_embed.device)), dim=0))
473
+ if cur_len > 0:
474
+ new_labels_padded[i, :cur_len] = cur_new_labels
475
+ attention_mask[i, :cur_len] = True
476
+ position_ids[i, :cur_len] = torch.arange(0, cur_len, dtype=position_ids.dtype, device=position_ids.device)
477
+
478
+ new_input_embeds = torch.stack(new_input_embeds_padded, dim=0)
479
+ # print("tokenizer padding")
480
+
481
+ if _labels is None:
482
+ new_labels = None
483
+ else:
484
+ new_labels = new_labels_padded
485
+
486
+ if _attention_mask is None:
487
+ attention_mask = None
488
+ else:
489
+ attention_mask = attention_mask.to(dtype=_attention_mask.dtype)
490
+
491
+ if _position_ids is None:
492
+ position_ids = None
493
+ if getattr(self.config, "use_pos_skipping", False) and self.training:
494
+ position_ids = torch.arange(new_input_embeds.size(1), device=new_input_embeds.device).unsqueeze(0).to(new_input_embeds.device)
495
+ split_position = random.randint(0, new_input_embeds.size(1))
496
+ left_add = random.randint(0, self.config.pos_skipping_range)
497
+ right_add = random.randint(left_add, self.config.pos_skipping_range)
498
+ position_ids[:, :split_position] += left_add
499
+ position_ids[:, split_position:] += right_add
500
+ # import pdb; pdb.set_trace()
501
+ # print("Finish preparing")
502
+ return None, position_ids, attention_mask, past_key_values, new_input_embeds, new_labels
503
+
504
+ def initialize_vision_tokenizer(self, model_args, tokenizer):
505
+ if model_args.mm_use_im_patch_token:
506
+ tokenizer.add_tokens([DEFAULT_IMAGE_PATCH_TOKEN], special_tokens=True)
507
+ self.resize_token_embeddings(len(tokenizer))
508
+
509
+ if model_args.mm_use_im_start_end:
510
+ num_new_tokens = tokenizer.add_tokens([DEFAULT_IM_START_TOKEN, DEFAULT_IM_END_TOKEN], special_tokens=True)
511
+ self.resize_token_embeddings(len(tokenizer))
512
+
513
+ if num_new_tokens > 0:
514
+ input_embeddings = self.get_input_embeddings().weight.data
515
+ output_embeddings = self.get_output_embeddings().weight.data
516
+
517
+ input_embeddings_avg = input_embeddings[:-num_new_tokens].mean(dim=0, keepdim=True)
518
+ output_embeddings_avg = output_embeddings[:-num_new_tokens].mean(dim=0, keepdim=True)
519
+
520
+ input_embeddings[-num_new_tokens:] = input_embeddings_avg
521
+ output_embeddings[-num_new_tokens:] = output_embeddings_avg
522
+
523
+ if model_args.tune_mm_mlp_adapter:
524
+ for p in self.get_input_embeddings().parameters():
525
+ p.requires_grad = True
526
+ for p in self.get_output_embeddings().parameters():
527
+ p.requires_grad = False
528
+
529
+ if model_args.pretrain_mm_mlp_adapter:
530
+ mm_projector_weights = torch.load(model_args.pretrain_mm_mlp_adapter, map_location="cpu")
531
+ embed_tokens_weight = mm_projector_weights["model.embed_tokens.weight"]
532
+ assert num_new_tokens == 2
533
+ if input_embeddings.shape == embed_tokens_weight.shape:
534
+ input_embeddings[-num_new_tokens:] = embed_tokens_weight[-num_new_tokens:]
535
+ elif embed_tokens_weight.shape[0] == num_new_tokens:
536
+ input_embeddings[-num_new_tokens:] = embed_tokens_weight
537
+ else:
538
+ raise ValueError(f"Unexpected embed_tokens_weight shape. Pretrained: {embed_tokens_weight.shape}. Current: {input_embeddings.shape}. Numer of new tokens: {num_new_tokens}.")
539
+ elif model_args.mm_use_im_patch_token:
540
+ if model_args.tune_mm_mlp_adapter:
541
+ for p in self.get_input_embeddings().parameters():
542
+ p.requires_grad = False
543
+ for p in self.get_output_embeddings().parameters():
544
+ p.requires_grad = False
545
+
546
+
547
+
548
+ class VideoChatFlashQwenConfig(Qwen2Config):
549
+ model_type = "videochat_flash_qwen"
550
+
551
+
552
+ class VideoChatFlashQwenModel(LlavaMetaModel, Qwen2Model_Flash):
553
+ config_class = VideoChatFlashQwenConfig
554
+
555
+ def __init__(self, config: VideoChatFlashQwenConfig):
556
+ super(VideoChatFlashQwenModel, self).__init__(config)
557
+
558
+
559
+ class VideoChatFlashQwenForCausalLM(LlavaMetaForCausalLM, Qwen2ForCausalLM_Flash):
560
+ config_class = VideoChatFlashQwenConfig
561
+
562
+ def __init__(self, config):
563
+ print("#######using VideoChatFlashQwenForCausalLM#######")
564
+ # super(Qwen2ForCausalLM, self).__init__(config)
565
+ Qwen2ForCausalLM_Flash.__init__(self, config)
566
+ config.model_type = "videochat_flash_qwen"
567
+ # config.rope_scaling = None
568
+
569
+ self.model = VideoChatFlashQwenModel(config)
570
+ self.lm_head = nn.Linear(config.hidden_size, config.vocab_size, bias=False)
571
+ # Initialize weights and apply final processing
572
+ self.post_init()
573
+
574
+ def get_model(self):
575
+ return self.model
576
+
577
+ def forward(
578
+ self,
579
+ input_ids: torch.LongTensor = None,
580
+ attention_mask: Optional[torch.Tensor] = None,
581
+ position_ids: Optional[torch.LongTensor] = None,
582
+ past_key_values: Optional[List[torch.FloatTensor]] = None,
583
+ inputs_embeds: Optional[torch.FloatTensor] = None,
584
+ labels: Optional[torch.LongTensor] = None,
585
+ use_cache: Optional[bool] = None,
586
+ output_attentions: Optional[bool] = None,
587
+ output_hidden_states: Optional[bool] = None,
588
+ images: Optional[torch.FloatTensor] = None,
589
+ image_sizes: Optional[List[List[int]]] = None,
590
+ return_dict: Optional[bool] = None,
591
+ modalities: Optional[List[str]] = ["image"],
592
+ dpo_forward: Optional[bool] = False,
593
+ cache_position=None,
594
+ ) -> Union[Tuple, CausalLMOutputWithPast]:
595
+
596
+ if inputs_embeds is None:
597
+ (input_ids, position_ids, attention_mask, past_key_values, inputs_embeds, labels) = self.prepare_inputs_labels_for_multimodal(input_ids, position_ids, attention_mask, past_key_values, labels, images, modalities, image_sizes)
598
+
599
+ # print("inputs_embeds.shape:", inputs_embeds.shape)
600
+ if dpo_forward:
601
+ raise NotImplementedError
602
+ else:
603
+ return super().forward(
604
+ input_ids=input_ids,
605
+ attention_mask=attention_mask,
606
+ position_ids=position_ids,
607
+ past_key_values=past_key_values,
608
+ inputs_embeds=inputs_embeds,
609
+ labels=labels,
610
+ use_cache=use_cache,
611
+ output_attentions=output_attentions,
612
+ output_hidden_states=output_hidden_states,
613
+ return_dict=return_dict,
614
+ )
615
+
616
+ @torch.no_grad()
617
+ def generate(
618
+ self,
619
+ inputs: Optional[torch.Tensor] = None,
620
+ images: Optional[torch.Tensor] = None,
621
+ image_sizes: Optional[torch.Tensor] = None,
622
+ modalities: Optional[List[str]] = ["image"],
623
+ **kwargs,
624
+ ) -> Union[GenerateOutput, torch.LongTensor]:
625
+ position_ids = kwargs.pop("position_ids", None)
626
+ attention_mask = kwargs.pop("attention_mask", None)
627
+ if "inputs_embeds" in kwargs:
628
+ raise NotImplementedError("`inputs_embeds` is not supported")
629
+
630
+ if images is not None:
631
+ (inputs, position_ids, attention_mask, _, inputs_embeds, _) = self.prepare_inputs_labels_for_multimodal(inputs, position_ids, attention_mask, None, None, images, modalities, image_sizes=image_sizes)
632
+ else:
633
+ self.model.image_token_posi = [-1]
634
+ self.model.prompt_len = None
635
+ self.model.image_tokens = [0]
636
+ inputs_embeds = self.get_model().embed_tokens(inputs)
637
+
638
+ return super().generate(position_ids=position_ids, attention_mask=attention_mask, inputs_embeds=inputs_embeds, **kwargs)
639
+
640
+ @torch.no_grad()
641
+ def chat(self,
642
+ video_path,
643
+ tokenizer,
644
+ user_prompt,
645
+ chat_history=None,
646
+ return_history=True,
647
+ max_num_frames=512,
648
+ media_dict=None,
649
+ generation_config={}):
650
+
651
+ frames, time_msg = load_video(video_path, max_num_frames=max_num_frames, media_dict=media_dict)
652
+
653
+ image_sizes = [frames[0].shape[:2]]
654
+
655
+ frames = [self.get_vision_tower().image_processor.preprocess(frames, return_tensors="pt")["pixel_values"].to(self.model.dtype).cuda()]
656
+
657
+ conv = conv_templates["qwen_2"].copy()
658
+
659
+ if chat_history is None or len(chat_history) == 0:
660
+ user_prompt = f'{DEFAULT_IMAGE_TOKEN}\n{time_msg.strip()} {user_prompt}'
661
+ else:
662
+ assert DEFAULT_IMAGE_TOKEN in chat_history[0]['content'], chat_history
663
+ for msg in chat_history:
664
+ conv.append_message(msg['role'], msg['content'])
665
+
666
+ conv.append_message(conv.roles[0], user_prompt)
667
+ conv.append_message(conv.roles[1], None)
668
+
669
+ prompt = conv.get_prompt()
670
+
671
+ input_ids = tokenizer_image_token(prompt, tokenizer, IMAGE_TOKEN_INDEX, return_tensors="pt").unsqueeze(0).cuda()
672
+
673
+ if tokenizer.pad_token_id is None:
674
+ if "qwen" in tokenizer.name_or_path.lower():
675
+ print("Setting pad token to bos token for qwen model.")
676
+ tokenizer.pad_token_id = 151643
677
+
678
+ attention_masks = input_ids.ne(tokenizer.pad_token_id).long().cuda()
679
+
680
+ stop_str = conv.sep if conv.sep_style != SeparatorStyle.TWO else conv.sep2
681
+ keywords = [stop_str]
682
+ stopping_criteria = KeywordsStoppingCriteria(keywords, tokenizer, input_ids)
683
+
684
+ with torch.inference_mode():
685
+ output_ids = self.generate(
686
+ inputs=input_ids,
687
+ images=frames,
688
+ attention_mask=attention_masks,
689
+ modalities=["video"],
690
+ image_sizes=image_sizes,
691
+ use_cache=True,
692
+ stopping_criteria=[stopping_criteria],
693
+ **generation_config
694
+ )
695
+
696
+ outputs = tokenizer.batch_decode(output_ids, skip_special_tokens=True)[0].strip()
697
+ if outputs.endswith(stop_str):
698
+ outputs = outputs[: -len(stop_str)]
699
+
700
+ outputs = outputs.strip()
701
+
702
+ # print(f"\033[91m== Question: \033[0m\n{prompt}\n")
703
+ # print(f"\033[91m== Response: \033[0m\n{outputs}\n")
704
+
705
+ if chat_history is None:
706
+ chat_history = []
707
+
708
+ chat_history.append({"role":conv.roles[0], "content":user_prompt})
709
+ chat_history.append({"role":conv.roles[1], "content":outputs})
710
+ if return_history:
711
+ return outputs, chat_history
712
+ else:
713
+ return outputs
714
+
715
+
716
+
717
+ def prepare_inputs_for_generation(self, input_ids, past_key_values=None, inputs_embeds=None, **kwargs):
718
+ images = kwargs.pop("images", None)
719
+ image_sizes = kwargs.pop("image_sizes", None)
720
+ inputs = super().prepare_inputs_for_generation(input_ids, past_key_values=past_key_values, inputs_embeds=inputs_embeds, **kwargs)
721
+ if images is not None:
722
+ inputs["images"] = images
723
+ if image_sizes is not None:
724
+ inputs["image_sizes"] = image_sizes
725
+ return inputs
726
+
727
+
728
+ AutoConfig.register("videochat_flash_qwen", VideoChatFlashQwenConfig)
729
+ AutoModelForCausalLM.register(VideoChatFlashQwenConfig, VideoChatFlashQwenForCausalLM)
optimizer.pt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:48697e6f44f6bdfe0ad925a45a9a2df793a136b4c53c1e41f11ef68e2d9a824c
3
+ size 617358074
rng_state_0.pth ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:ad8a35afd8967cbb748405387e44426e43ad127028e826eddc9b67d2ca873c85
3
+ size 15984
rng_state_1.pth ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:f338ce80d7c441076bfc8c53b84067a0181f5a14e80c13d5acb8150b659f4d73
3
+ size 15984
rng_state_2.pth ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:c9fbc9fa428939be10b46779f0eb5cd833e0da426b1cbdee77b3a55b6952235b
3
+ size 15984
rng_state_3.pth ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:ac55dba0b79d5fa4699d239da2f966d52040d576d31234ac8d4632e6956481bc
3
+ size 15984
rng_state_4.pth ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:af2d0c015100768ffa23faf3b6c2d54ea89eb045603e30e55cd211e06ff34972
3
+ size 15984
rng_state_5.pth ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:c60a1b40608e34bc801c8231f97b81c53b5290dfaed1b9cd0ccbeca29574a991
3
+ size 15984
rng_state_6.pth ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:3ad6a142a403eb9aafc4a3a9a856bca648fe31fd22d796867baca31fb13656aa
3
+ size 15984
rng_state_7.pth ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:38bc23a138cc800b22881742c0f3f9a71731a9a7111c6058a0077e6274d21773
3
+ size 15984
scheduler.pt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:d4eb3584f7b416bcaf3353a3f8d191c7b44eaba6cf7f601a4d00ebf29a582e0d
3
+ size 1064
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
+ }
tokenizer.json ADDED
The diff for this file is too large to render. See raw diff
 
tokenizer_config.json ADDED
@@ -0,0 +1,208 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "add_bos_token": false,
3
+ "add_prefix_space": false,
4
+ "added_tokens_decoder": {
5
+ "151643": {
6
+ "content": "<|endoftext|>",
7
+ "lstrip": false,
8
+ "normalized": false,
9
+ "rstrip": false,
10
+ "single_word": false,
11
+ "special": true
12
+ },
13
+ "151644": {
14
+ "content": "<|im_start|>",
15
+ "lstrip": false,
16
+ "normalized": false,
17
+ "rstrip": false,
18
+ "single_word": false,
19
+ "special": true
20
+ },
21
+ "151645": {
22
+ "content": "<|im_end|>",
23
+ "lstrip": false,
24
+ "normalized": false,
25
+ "rstrip": false,
26
+ "single_word": false,
27
+ "special": true
28
+ },
29
+ "151646": {
30
+ "content": "<|object_ref_start|>",
31
+ "lstrip": false,
32
+ "normalized": false,
33
+ "rstrip": false,
34
+ "single_word": false,
35
+ "special": true
36
+ },
37
+ "151647": {
38
+ "content": "<|object_ref_end|>",
39
+ "lstrip": false,
40
+ "normalized": false,
41
+ "rstrip": false,
42
+ "single_word": false,
43
+ "special": true
44
+ },
45
+ "151648": {
46
+ "content": "<|box_start|>",
47
+ "lstrip": false,
48
+ "normalized": false,
49
+ "rstrip": false,
50
+ "single_word": false,
51
+ "special": true
52
+ },
53
+ "151649": {
54
+ "content": "<|box_end|>",
55
+ "lstrip": false,
56
+ "normalized": false,
57
+ "rstrip": false,
58
+ "single_word": false,
59
+ "special": true
60
+ },
61
+ "151650": {
62
+ "content": "<|quad_start|>",
63
+ "lstrip": false,
64
+ "normalized": false,
65
+ "rstrip": false,
66
+ "single_word": false,
67
+ "special": true
68
+ },
69
+ "151651": {
70
+ "content": "<|quad_end|>",
71
+ "lstrip": false,
72
+ "normalized": false,
73
+ "rstrip": false,
74
+ "single_word": false,
75
+ "special": true
76
+ },
77
+ "151652": {
78
+ "content": "<|vision_start|>",
79
+ "lstrip": false,
80
+ "normalized": false,
81
+ "rstrip": false,
82
+ "single_word": false,
83
+ "special": true
84
+ },
85
+ "151653": {
86
+ "content": "<|vision_end|>",
87
+ "lstrip": false,
88
+ "normalized": false,
89
+ "rstrip": false,
90
+ "single_word": false,
91
+ "special": true
92
+ },
93
+ "151654": {
94
+ "content": "<|vision_pad|>",
95
+ "lstrip": false,
96
+ "normalized": false,
97
+ "rstrip": false,
98
+ "single_word": false,
99
+ "special": true
100
+ },
101
+ "151655": {
102
+ "content": "<|image_pad|>",
103
+ "lstrip": false,
104
+ "normalized": false,
105
+ "rstrip": false,
106
+ "single_word": false,
107
+ "special": true
108
+ },
109
+ "151656": {
110
+ "content": "<|video_pad|>",
111
+ "lstrip": false,
112
+ "normalized": false,
113
+ "rstrip": false,
114
+ "single_word": false,
115
+ "special": true
116
+ },
117
+ "151657": {
118
+ "content": "<tool_call>",
119
+ "lstrip": false,
120
+ "normalized": false,
121
+ "rstrip": false,
122
+ "single_word": false,
123
+ "special": false
124
+ },
125
+ "151658": {
126
+ "content": "</tool_call>",
127
+ "lstrip": false,
128
+ "normalized": false,
129
+ "rstrip": false,
130
+ "single_word": false,
131
+ "special": false
132
+ },
133
+ "151659": {
134
+ "content": "<|fim_prefix|>",
135
+ "lstrip": false,
136
+ "normalized": false,
137
+ "rstrip": false,
138
+ "single_word": false,
139
+ "special": false
140
+ },
141
+ "151660": {
142
+ "content": "<|fim_middle|>",
143
+ "lstrip": false,
144
+ "normalized": false,
145
+ "rstrip": false,
146
+ "single_word": false,
147
+ "special": false
148
+ },
149
+ "151661": {
150
+ "content": "<|fim_suffix|>",
151
+ "lstrip": false,
152
+ "normalized": false,
153
+ "rstrip": false,
154
+ "single_word": false,
155
+ "special": false
156
+ },
157
+ "151662": {
158
+ "content": "<|fim_pad|>",
159
+ "lstrip": false,
160
+ "normalized": false,
161
+ "rstrip": false,
162
+ "single_word": false,
163
+ "special": false
164
+ },
165
+ "151663": {
166
+ "content": "<|repo_name|>",
167
+ "lstrip": false,
168
+ "normalized": false,
169
+ "rstrip": false,
170
+ "single_word": false,
171
+ "special": false
172
+ },
173
+ "151664": {
174
+ "content": "<|file_sep|>",
175
+ "lstrip": false,
176
+ "normalized": false,
177
+ "rstrip": false,
178
+ "single_word": false,
179
+ "special": false
180
+ }
181
+ },
182
+ "additional_special_tokens": [
183
+ "<|im_start|>",
184
+ "<|im_end|>",
185
+ "<|object_ref_start|>",
186
+ "<|object_ref_end|>",
187
+ "<|box_start|>",
188
+ "<|box_end|>",
189
+ "<|quad_start|>",
190
+ "<|quad_end|>",
191
+ "<|vision_start|>",
192
+ "<|vision_end|>",
193
+ "<|vision_pad|>",
194
+ "<|image_pad|>",
195
+ "<|video_pad|>"
196
+ ],
197
+ "bos_token": null,
198
+ "chat_template": "{%- if tools %}\n {{- '<|im_start|>system\\n' }}\n {%- if messages[0]['role'] == 'system' %}\n {{- messages[0]['content'] }}\n {%- else %}\n {{- 'You are a helpful assistant.' }}\n {%- endif %}\n {{- \"\\n\\n# Tools\\n\\nYou may call one or more functions to assist with the user query.\\n\\nYou are provided with function signatures within <tools></tools> XML tags:\\n<tools>\" }}\n {%- for tool in tools %}\n {{- \"\\n\" }}\n {{- tool | tojson }}\n {%- endfor %}\n {{- \"\\n</tools>\\n\\nFor each function call, return a json object with function name and arguments within <tool_call></tool_call> XML tags:\\n<tool_call>\\n{\\\"name\\\": <function-name>, \\\"arguments\\\": <args-json-object>}\\n</tool_call><|im_end|>\\n\" }}\n{%- else %}\n {%- if messages[0]['role'] == 'system' %}\n {{- '<|im_start|>system\\n' + messages[0]['content'] + '<|im_end|>\\n' }}\n {%- else %}\n {{- '<|im_start|>system\\nYou are a helpful assistant.<|im_end|>\\n' }}\n {%- endif %}\n{%- endif %}\n{%- for message in messages %}\n {%- if (message.role == \"user\") or (message.role == \"system\" and not loop.first) or (message.role == \"assistant\" and not message.tool_calls) %}\n {{- '<|im_start|>' + message.role + '\\n' + message.content + '<|im_end|>' + '\\n' }}\n {%- elif message.role == \"assistant\" %}\n {{- '<|im_start|>' + message.role }}\n {%- if message.content %}\n {{- '\\n' + message.content }}\n {%- endif %}\n {%- for tool_call in message.tool_calls %}\n {%- if tool_call.function is defined %}\n {%- set tool_call = tool_call.function %}\n {%- endif %}\n {{- '\\n<tool_call>\\n{\"name\": \"' }}\n {{- tool_call.name }}\n {{- '\", \"arguments\": ' }}\n {{- tool_call.arguments | tojson }}\n {{- '}\\n</tool_call>' }}\n {%- endfor %}\n {{- '<|im_end|>\\n' }}\n {%- elif message.role == \"tool\" %}\n {%- if (loop.index0 == 0) or (messages[loop.index0 - 1].role != \"tool\") %}\n {{- '<|im_start|>user' }}\n {%- endif %}\n {{- '\\n<tool_response>\\n' }}\n {{- message.content }}\n {{- '\\n</tool_response>' }}\n {%- if loop.last or (messages[loop.index0 + 1].role != \"tool\") %}\n {{- '<|im_end|>\\n' }}\n {%- endif %}\n {%- endif %}\n{%- endfor %}\n{%- if add_generation_prompt %}\n {{- '<|im_start|>assistant\\n' }}\n{%- endif %}\n",
199
+ "clean_up_tokenization_spaces": false,
200
+ "eos_token": "<|im_end|>",
201
+ "errors": "replace",
202
+ "model_max_length": 32768,
203
+ "pad_token": "<|endoftext|>",
204
+ "padding_side": "left",
205
+ "split_special_tokens": false,
206
+ "tokenizer_class": "Qwen2Tokenizer",
207
+ "unk_token": null
208
+ }
trainer_state.json ADDED
@@ -0,0 +1,2821 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "best_metric": null,
3
+ "best_model_checkpoint": null,
4
+ "epoch": 1.4840235588739972,
5
+ "eval_steps": 500,
6
+ "global_step": 4000,
7
+ "is_hyper_param_search": false,
8
+ "is_local_process_zero": true,
9
+ "is_world_process_zero": true,
10
+ "log_history": [
11
+ {
12
+ "epoch": 0.0,
13
+ "grad_norm": 25.625,
14
+ "learning_rate": 6.180469715698394e-07,
15
+ "loss": 1.7354,
16
+ "step": 10
17
+ },
18
+ {
19
+ "epoch": 0.01,
20
+ "grad_norm": 27.0,
21
+ "learning_rate": 1.2360939431396788e-06,
22
+ "loss": 1.7147,
23
+ "step": 20
24
+ },
25
+ {
26
+ "epoch": 0.01,
27
+ "grad_norm": 23.375,
28
+ "learning_rate": 1.854140914709518e-06,
29
+ "loss": 1.7215,
30
+ "step": 30
31
+ },
32
+ {
33
+ "epoch": 0.01,
34
+ "grad_norm": 22.375,
35
+ "learning_rate": 2.4721878862793575e-06,
36
+ "loss": 1.6731,
37
+ "step": 40
38
+ },
39
+ {
40
+ "epoch": 0.02,
41
+ "grad_norm": 18.875,
42
+ "learning_rate": 3.090234857849197e-06,
43
+ "loss": 1.6182,
44
+ "step": 50
45
+ },
46
+ {
47
+ "epoch": 0.02,
48
+ "grad_norm": 15.3125,
49
+ "learning_rate": 3.708281829419036e-06,
50
+ "loss": 1.5128,
51
+ "step": 60
52
+ },
53
+ {
54
+ "epoch": 0.03,
55
+ "grad_norm": 9.9375,
56
+ "learning_rate": 4.326328800988875e-06,
57
+ "loss": 1.4061,
58
+ "step": 70
59
+ },
60
+ {
61
+ "epoch": 0.03,
62
+ "grad_norm": 7.46875,
63
+ "learning_rate": 4.944375772558715e-06,
64
+ "loss": 1.332,
65
+ "step": 80
66
+ },
67
+ {
68
+ "epoch": 0.03,
69
+ "grad_norm": 4.46875,
70
+ "learning_rate": 5.562422744128554e-06,
71
+ "loss": 1.1765,
72
+ "step": 90
73
+ },
74
+ {
75
+ "epoch": 0.04,
76
+ "grad_norm": 4.25,
77
+ "learning_rate": 6.180469715698394e-06,
78
+ "loss": 1.165,
79
+ "step": 100
80
+ },
81
+ {
82
+ "epoch": 0.04,
83
+ "grad_norm": 2.140625,
84
+ "learning_rate": 6.798516687268234e-06,
85
+ "loss": 1.0473,
86
+ "step": 110
87
+ },
88
+ {
89
+ "epoch": 0.04,
90
+ "grad_norm": 1.390625,
91
+ "learning_rate": 7.416563658838072e-06,
92
+ "loss": 0.9959,
93
+ "step": 120
94
+ },
95
+ {
96
+ "epoch": 0.05,
97
+ "grad_norm": 0.93359375,
98
+ "learning_rate": 8.034610630407912e-06,
99
+ "loss": 1.0219,
100
+ "step": 130
101
+ },
102
+ {
103
+ "epoch": 0.05,
104
+ "grad_norm": 0.82421875,
105
+ "learning_rate": 8.65265760197775e-06,
106
+ "loss": 0.9495,
107
+ "step": 140
108
+ },
109
+ {
110
+ "epoch": 0.06,
111
+ "grad_norm": 0.6796875,
112
+ "learning_rate": 9.27070457354759e-06,
113
+ "loss": 0.9312,
114
+ "step": 150
115
+ },
116
+ {
117
+ "epoch": 0.06,
118
+ "grad_norm": 0.66796875,
119
+ "learning_rate": 9.88875154511743e-06,
120
+ "loss": 0.94,
121
+ "step": 160
122
+ },
123
+ {
124
+ "epoch": 0.06,
125
+ "grad_norm": 0.71484375,
126
+ "learning_rate": 1.0506798516687269e-05,
127
+ "loss": 0.9317,
128
+ "step": 170
129
+ },
130
+ {
131
+ "epoch": 0.07,
132
+ "grad_norm": 0.703125,
133
+ "learning_rate": 1.1124845488257108e-05,
134
+ "loss": 0.9579,
135
+ "step": 180
136
+ },
137
+ {
138
+ "epoch": 0.07,
139
+ "grad_norm": 0.59375,
140
+ "learning_rate": 1.1742892459826947e-05,
141
+ "loss": 0.8969,
142
+ "step": 190
143
+ },
144
+ {
145
+ "epoch": 0.07,
146
+ "grad_norm": 0.64453125,
147
+ "learning_rate": 1.2360939431396788e-05,
148
+ "loss": 0.9221,
149
+ "step": 200
150
+ },
151
+ {
152
+ "epoch": 0.08,
153
+ "grad_norm": 0.5859375,
154
+ "learning_rate": 1.2978986402966625e-05,
155
+ "loss": 0.8965,
156
+ "step": 210
157
+ },
158
+ {
159
+ "epoch": 0.08,
160
+ "grad_norm": 0.62890625,
161
+ "learning_rate": 1.3597033374536467e-05,
162
+ "loss": 0.9268,
163
+ "step": 220
164
+ },
165
+ {
166
+ "epoch": 0.09,
167
+ "grad_norm": 0.53515625,
168
+ "learning_rate": 1.4215080346106304e-05,
169
+ "loss": 0.9049,
170
+ "step": 230
171
+ },
172
+ {
173
+ "epoch": 0.09,
174
+ "grad_norm": 0.6171875,
175
+ "learning_rate": 1.4833127317676143e-05,
176
+ "loss": 0.9096,
177
+ "step": 240
178
+ },
179
+ {
180
+ "epoch": 0.09,
181
+ "grad_norm": 0.64453125,
182
+ "learning_rate": 1.5451174289245984e-05,
183
+ "loss": 0.8934,
184
+ "step": 250
185
+ },
186
+ {
187
+ "epoch": 0.1,
188
+ "grad_norm": 0.671875,
189
+ "learning_rate": 1.6069221260815823e-05,
190
+ "loss": 0.8824,
191
+ "step": 260
192
+ },
193
+ {
194
+ "epoch": 0.1,
195
+ "grad_norm": 0.84765625,
196
+ "learning_rate": 1.6687268232385662e-05,
197
+ "loss": 0.9045,
198
+ "step": 270
199
+ },
200
+ {
201
+ "epoch": 0.1,
202
+ "grad_norm": 0.5625,
203
+ "learning_rate": 1.73053152039555e-05,
204
+ "loss": 0.8949,
205
+ "step": 280
206
+ },
207
+ {
208
+ "epoch": 0.11,
209
+ "grad_norm": 0.625,
210
+ "learning_rate": 1.792336217552534e-05,
211
+ "loss": 0.8893,
212
+ "step": 290
213
+ },
214
+ {
215
+ "epoch": 0.11,
216
+ "grad_norm": 0.482421875,
217
+ "learning_rate": 1.854140914709518e-05,
218
+ "loss": 0.8906,
219
+ "step": 300
220
+ },
221
+ {
222
+ "epoch": 0.12,
223
+ "grad_norm": 0.54296875,
224
+ "learning_rate": 1.915945611866502e-05,
225
+ "loss": 0.8883,
226
+ "step": 310
227
+ },
228
+ {
229
+ "epoch": 0.12,
230
+ "grad_norm": 0.828125,
231
+ "learning_rate": 1.977750309023486e-05,
232
+ "loss": 0.8665,
233
+ "step": 320
234
+ },
235
+ {
236
+ "epoch": 0.12,
237
+ "grad_norm": 0.66015625,
238
+ "learning_rate": 2.0395550061804696e-05,
239
+ "loss": 0.8452,
240
+ "step": 330
241
+ },
242
+ {
243
+ "epoch": 0.13,
244
+ "grad_norm": 0.51953125,
245
+ "learning_rate": 2.1013597033374538e-05,
246
+ "loss": 0.8943,
247
+ "step": 340
248
+ },
249
+ {
250
+ "epoch": 0.13,
251
+ "grad_norm": 0.490234375,
252
+ "learning_rate": 2.1631644004944377e-05,
253
+ "loss": 0.8802,
254
+ "step": 350
255
+ },
256
+ {
257
+ "epoch": 0.13,
258
+ "grad_norm": 0.5234375,
259
+ "learning_rate": 2.2249690976514216e-05,
260
+ "loss": 0.8798,
261
+ "step": 360
262
+ },
263
+ {
264
+ "epoch": 0.14,
265
+ "grad_norm": 0.46484375,
266
+ "learning_rate": 2.2867737948084055e-05,
267
+ "loss": 0.8778,
268
+ "step": 370
269
+ },
270
+ {
271
+ "epoch": 0.14,
272
+ "grad_norm": 0.55859375,
273
+ "learning_rate": 2.3485784919653894e-05,
274
+ "loss": 0.8314,
275
+ "step": 380
276
+ },
277
+ {
278
+ "epoch": 0.14,
279
+ "grad_norm": 0.494140625,
280
+ "learning_rate": 2.4103831891223736e-05,
281
+ "loss": 0.8829,
282
+ "step": 390
283
+ },
284
+ {
285
+ "epoch": 0.15,
286
+ "grad_norm": 0.46484375,
287
+ "learning_rate": 2.4721878862793575e-05,
288
+ "loss": 0.8734,
289
+ "step": 400
290
+ },
291
+ {
292
+ "epoch": 0.15,
293
+ "grad_norm": 0.5078125,
294
+ "learning_rate": 2.5339925834363414e-05,
295
+ "loss": 0.8421,
296
+ "step": 410
297
+ },
298
+ {
299
+ "epoch": 0.16,
300
+ "grad_norm": 0.51953125,
301
+ "learning_rate": 2.595797280593325e-05,
302
+ "loss": 0.8636,
303
+ "step": 420
304
+ },
305
+ {
306
+ "epoch": 0.16,
307
+ "grad_norm": 0.51953125,
308
+ "learning_rate": 2.6576019777503092e-05,
309
+ "loss": 0.856,
310
+ "step": 430
311
+ },
312
+ {
313
+ "epoch": 0.16,
314
+ "grad_norm": 0.50390625,
315
+ "learning_rate": 2.7194066749072934e-05,
316
+ "loss": 0.8537,
317
+ "step": 440
318
+ },
319
+ {
320
+ "epoch": 0.17,
321
+ "grad_norm": 0.56640625,
322
+ "learning_rate": 2.781211372064277e-05,
323
+ "loss": 0.8738,
324
+ "step": 450
325
+ },
326
+ {
327
+ "epoch": 0.17,
328
+ "grad_norm": 0.47265625,
329
+ "learning_rate": 2.843016069221261e-05,
330
+ "loss": 0.8548,
331
+ "step": 460
332
+ },
333
+ {
334
+ "epoch": 0.17,
335
+ "grad_norm": 0.484375,
336
+ "learning_rate": 2.904820766378245e-05,
337
+ "loss": 0.8214,
338
+ "step": 470
339
+ },
340
+ {
341
+ "epoch": 0.18,
342
+ "grad_norm": 0.52734375,
343
+ "learning_rate": 2.9666254635352287e-05,
344
+ "loss": 0.8489,
345
+ "step": 480
346
+ },
347
+ {
348
+ "epoch": 0.18,
349
+ "grad_norm": 0.474609375,
350
+ "learning_rate": 3.0284301606922126e-05,
351
+ "loss": 0.8641,
352
+ "step": 490
353
+ },
354
+ {
355
+ "epoch": 0.19,
356
+ "grad_norm": 0.50390625,
357
+ "learning_rate": 3.090234857849197e-05,
358
+ "loss": 0.8443,
359
+ "step": 500
360
+ },
361
+ {
362
+ "epoch": 0.19,
363
+ "grad_norm": 0.546875,
364
+ "learning_rate": 3.1520395550061804e-05,
365
+ "loss": 0.9063,
366
+ "step": 510
367
+ },
368
+ {
369
+ "epoch": 0.19,
370
+ "grad_norm": 0.68359375,
371
+ "learning_rate": 3.2138442521631646e-05,
372
+ "loss": 0.8458,
373
+ "step": 520
374
+ },
375
+ {
376
+ "epoch": 0.2,
377
+ "grad_norm": 0.494140625,
378
+ "learning_rate": 3.275648949320149e-05,
379
+ "loss": 0.8552,
380
+ "step": 530
381
+ },
382
+ {
383
+ "epoch": 0.2,
384
+ "grad_norm": 0.5,
385
+ "learning_rate": 3.3374536464771324e-05,
386
+ "loss": 0.825,
387
+ "step": 540
388
+ },
389
+ {
390
+ "epoch": 0.2,
391
+ "grad_norm": 0.51171875,
392
+ "learning_rate": 3.3992583436341166e-05,
393
+ "loss": 0.8666,
394
+ "step": 550
395
+ },
396
+ {
397
+ "epoch": 0.21,
398
+ "grad_norm": 0.54296875,
399
+ "learning_rate": 3.4610630407911e-05,
400
+ "loss": 0.8252,
401
+ "step": 560
402
+ },
403
+ {
404
+ "epoch": 0.21,
405
+ "grad_norm": 0.69921875,
406
+ "learning_rate": 3.522867737948084e-05,
407
+ "loss": 0.86,
408
+ "step": 570
409
+ },
410
+ {
411
+ "epoch": 0.22,
412
+ "grad_norm": 0.4921875,
413
+ "learning_rate": 3.584672435105068e-05,
414
+ "loss": 0.8664,
415
+ "step": 580
416
+ },
417
+ {
418
+ "epoch": 0.22,
419
+ "grad_norm": 0.431640625,
420
+ "learning_rate": 3.646477132262052e-05,
421
+ "loss": 0.8137,
422
+ "step": 590
423
+ },
424
+ {
425
+ "epoch": 0.22,
426
+ "grad_norm": 0.5,
427
+ "learning_rate": 3.708281829419036e-05,
428
+ "loss": 0.8572,
429
+ "step": 600
430
+ },
431
+ {
432
+ "epoch": 0.23,
433
+ "grad_norm": 0.466796875,
434
+ "learning_rate": 3.77008652657602e-05,
435
+ "loss": 0.8617,
436
+ "step": 610
437
+ },
438
+ {
439
+ "epoch": 0.23,
440
+ "grad_norm": 0.46875,
441
+ "learning_rate": 3.831891223733004e-05,
442
+ "loss": 0.8579,
443
+ "step": 620
444
+ },
445
+ {
446
+ "epoch": 0.23,
447
+ "grad_norm": 0.451171875,
448
+ "learning_rate": 3.893695920889988e-05,
449
+ "loss": 0.8581,
450
+ "step": 630
451
+ },
452
+ {
453
+ "epoch": 0.24,
454
+ "grad_norm": 0.462890625,
455
+ "learning_rate": 3.955500618046972e-05,
456
+ "loss": 0.8633,
457
+ "step": 640
458
+ },
459
+ {
460
+ "epoch": 0.24,
461
+ "grad_norm": 0.478515625,
462
+ "learning_rate": 4.0173053152039556e-05,
463
+ "loss": 0.852,
464
+ "step": 650
465
+ },
466
+ {
467
+ "epoch": 0.24,
468
+ "grad_norm": 0.478515625,
469
+ "learning_rate": 4.079110012360939e-05,
470
+ "loss": 0.8598,
471
+ "step": 660
472
+ },
473
+ {
474
+ "epoch": 0.25,
475
+ "grad_norm": 0.61328125,
476
+ "learning_rate": 4.1409147095179234e-05,
477
+ "loss": 0.844,
478
+ "step": 670
479
+ },
480
+ {
481
+ "epoch": 0.25,
482
+ "grad_norm": 0.51953125,
483
+ "learning_rate": 4.2027194066749076e-05,
484
+ "loss": 0.834,
485
+ "step": 680
486
+ },
487
+ {
488
+ "epoch": 0.26,
489
+ "grad_norm": 0.4453125,
490
+ "learning_rate": 4.264524103831891e-05,
491
+ "loss": 0.8257,
492
+ "step": 690
493
+ },
494
+ {
495
+ "epoch": 0.26,
496
+ "grad_norm": 0.50390625,
497
+ "learning_rate": 4.3263288009888754e-05,
498
+ "loss": 0.8337,
499
+ "step": 700
500
+ },
501
+ {
502
+ "epoch": 0.26,
503
+ "grad_norm": 0.431640625,
504
+ "learning_rate": 4.3881334981458596e-05,
505
+ "loss": 0.819,
506
+ "step": 710
507
+ },
508
+ {
509
+ "epoch": 0.27,
510
+ "grad_norm": 0.455078125,
511
+ "learning_rate": 4.449938195302843e-05,
512
+ "loss": 0.8306,
513
+ "step": 720
514
+ },
515
+ {
516
+ "epoch": 0.27,
517
+ "grad_norm": 0.47265625,
518
+ "learning_rate": 4.511742892459827e-05,
519
+ "loss": 0.8521,
520
+ "step": 730
521
+ },
522
+ {
523
+ "epoch": 0.27,
524
+ "grad_norm": 0.54296875,
525
+ "learning_rate": 4.573547589616811e-05,
526
+ "loss": 0.8355,
527
+ "step": 740
528
+ },
529
+ {
530
+ "epoch": 0.28,
531
+ "grad_norm": 0.486328125,
532
+ "learning_rate": 4.635352286773795e-05,
533
+ "loss": 0.8552,
534
+ "step": 750
535
+ },
536
+ {
537
+ "epoch": 0.28,
538
+ "grad_norm": 0.455078125,
539
+ "learning_rate": 4.697156983930779e-05,
540
+ "loss": 0.814,
541
+ "step": 760
542
+ },
543
+ {
544
+ "epoch": 0.29,
545
+ "grad_norm": 0.4296875,
546
+ "learning_rate": 4.758961681087763e-05,
547
+ "loss": 0.832,
548
+ "step": 770
549
+ },
550
+ {
551
+ "epoch": 0.29,
552
+ "grad_norm": 0.447265625,
553
+ "learning_rate": 4.820766378244747e-05,
554
+ "loss": 0.8399,
555
+ "step": 780
556
+ },
557
+ {
558
+ "epoch": 0.29,
559
+ "grad_norm": 0.447265625,
560
+ "learning_rate": 4.882571075401731e-05,
561
+ "loss": 0.7969,
562
+ "step": 790
563
+ },
564
+ {
565
+ "epoch": 0.3,
566
+ "grad_norm": 0.4296875,
567
+ "learning_rate": 4.944375772558715e-05,
568
+ "loss": 0.8477,
569
+ "step": 800
570
+ },
571
+ {
572
+ "epoch": 0.3,
573
+ "grad_norm": 0.49609375,
574
+ "learning_rate": 4.99999941211936e-05,
575
+ "loss": 0.8282,
576
+ "step": 810
577
+ },
578
+ {
579
+ "epoch": 0.3,
580
+ "grad_norm": 0.5,
581
+ "learning_rate": 4.999928866777183e-05,
582
+ "loss": 0.8227,
583
+ "step": 820
584
+ },
585
+ {
586
+ "epoch": 0.31,
587
+ "grad_norm": 0.412109375,
588
+ "learning_rate": 4.999740749108744e-05,
589
+ "loss": 0.8077,
590
+ "step": 830
591
+ },
592
+ {
593
+ "epoch": 0.31,
594
+ "grad_norm": 0.4453125,
595
+ "learning_rate": 4.99943506796127e-05,
596
+ "loss": 0.8447,
597
+ "step": 840
598
+ },
599
+ {
600
+ "epoch": 0.32,
601
+ "grad_norm": 0.52734375,
602
+ "learning_rate": 4.999011837711028e-05,
603
+ "loss": 0.8327,
604
+ "step": 850
605
+ },
606
+ {
607
+ "epoch": 0.32,
608
+ "grad_norm": 0.427734375,
609
+ "learning_rate": 4.998471078262649e-05,
610
+ "loss": 0.8341,
611
+ "step": 860
612
+ },
613
+ {
614
+ "epoch": 0.32,
615
+ "grad_norm": 0.43359375,
616
+ "learning_rate": 4.997812815048196e-05,
617
+ "loss": 0.8469,
618
+ "step": 870
619
+ },
620
+ {
621
+ "epoch": 0.33,
622
+ "grad_norm": 0.453125,
623
+ "learning_rate": 4.9970370790259646e-05,
624
+ "loss": 0.8331,
625
+ "step": 880
626
+ },
627
+ {
628
+ "epoch": 0.33,
629
+ "grad_norm": 0.458984375,
630
+ "learning_rate": 4.9961439066790275e-05,
631
+ "loss": 0.8161,
632
+ "step": 890
633
+ },
634
+ {
635
+ "epoch": 0.33,
636
+ "grad_norm": 0.404296875,
637
+ "learning_rate": 4.995133340013522e-05,
638
+ "loss": 0.8255,
639
+ "step": 900
640
+ },
641
+ {
642
+ "epoch": 0.34,
643
+ "grad_norm": 0.4375,
644
+ "learning_rate": 4.994005426556668e-05,
645
+ "loss": 0.8595,
646
+ "step": 910
647
+ },
648
+ {
649
+ "epoch": 0.34,
650
+ "grad_norm": 0.44140625,
651
+ "learning_rate": 4.99276021935454e-05,
652
+ "loss": 0.8391,
653
+ "step": 920
654
+ },
655
+ {
656
+ "epoch": 0.35,
657
+ "grad_norm": 0.419921875,
658
+ "learning_rate": 4.991397776969566e-05,
659
+ "loss": 0.8364,
660
+ "step": 930
661
+ },
662
+ {
663
+ "epoch": 0.35,
664
+ "grad_norm": 0.439453125,
665
+ "learning_rate": 4.989918163477778e-05,
666
+ "loss": 0.8018,
667
+ "step": 940
668
+ },
669
+ {
670
+ "epoch": 0.35,
671
+ "grad_norm": 0.427734375,
672
+ "learning_rate": 4.9883214484657957e-05,
673
+ "loss": 0.8303,
674
+ "step": 950
675
+ },
676
+ {
677
+ "epoch": 0.36,
678
+ "grad_norm": 0.470703125,
679
+ "learning_rate": 4.986607707027556e-05,
680
+ "loss": 0.837,
681
+ "step": 960
682
+ },
683
+ {
684
+ "epoch": 0.36,
685
+ "grad_norm": 0.466796875,
686
+ "learning_rate": 4.9847770197607784e-05,
687
+ "loss": 0.8289,
688
+ "step": 970
689
+ },
690
+ {
691
+ "epoch": 0.36,
692
+ "grad_norm": 0.4453125,
693
+ "learning_rate": 4.982829472763177e-05,
694
+ "loss": 0.8273,
695
+ "step": 980
696
+ },
697
+ {
698
+ "epoch": 0.37,
699
+ "grad_norm": 0.470703125,
700
+ "learning_rate": 4.9807651576284104e-05,
701
+ "loss": 0.7904,
702
+ "step": 990
703
+ },
704
+ {
705
+ "epoch": 0.37,
706
+ "grad_norm": 0.458984375,
707
+ "learning_rate": 4.9785841714417734e-05,
708
+ "loss": 0.8293,
709
+ "step": 1000
710
+ },
711
+ {
712
+ "epoch": 0.37,
713
+ "grad_norm": 0.421875,
714
+ "learning_rate": 4.976286616775634e-05,
715
+ "loss": 0.8347,
716
+ "step": 1010
717
+ },
718
+ {
719
+ "epoch": 0.38,
720
+ "grad_norm": 0.439453125,
721
+ "learning_rate": 4.973872601684604e-05,
722
+ "loss": 0.8279,
723
+ "step": 1020
724
+ },
725
+ {
726
+ "epoch": 0.38,
727
+ "grad_norm": 0.470703125,
728
+ "learning_rate": 4.971342239700462e-05,
729
+ "loss": 0.8283,
730
+ "step": 1030
731
+ },
732
+ {
733
+ "epoch": 0.39,
734
+ "grad_norm": 0.474609375,
735
+ "learning_rate": 4.9686956498268114e-05,
736
+ "loss": 0.8311,
737
+ "step": 1040
738
+ },
739
+ {
740
+ "epoch": 0.39,
741
+ "grad_norm": 0.439453125,
742
+ "learning_rate": 4.9659329565334854e-05,
743
+ "loss": 0.8081,
744
+ "step": 1050
745
+ },
746
+ {
747
+ "epoch": 0.39,
748
+ "grad_norm": 0.41796875,
749
+ "learning_rate": 4.963054289750693e-05,
750
+ "loss": 0.8201,
751
+ "step": 1060
752
+ },
753
+ {
754
+ "epoch": 0.4,
755
+ "grad_norm": 0.4765625,
756
+ "learning_rate": 4.960059784862905e-05,
757
+ "loss": 0.8056,
758
+ "step": 1070
759
+ },
760
+ {
761
+ "epoch": 0.4,
762
+ "grad_norm": 0.55859375,
763
+ "learning_rate": 4.956949582702492e-05,
764
+ "loss": 0.8262,
765
+ "step": 1080
766
+ },
767
+ {
768
+ "epoch": 0.4,
769
+ "grad_norm": 0.4765625,
770
+ "learning_rate": 4.953723829543095e-05,
771
+ "loss": 0.8043,
772
+ "step": 1090
773
+ },
774
+ {
775
+ "epoch": 0.41,
776
+ "grad_norm": 0.412109375,
777
+ "learning_rate": 4.950382677092754e-05,
778
+ "loss": 0.8074,
779
+ "step": 1100
780
+ },
781
+ {
782
+ "epoch": 0.41,
783
+ "grad_norm": 0.41796875,
784
+ "learning_rate": 4.946926282486766e-05,
785
+ "loss": 0.8122,
786
+ "step": 1110
787
+ },
788
+ {
789
+ "epoch": 0.42,
790
+ "grad_norm": 0.4609375,
791
+ "learning_rate": 4.943354808280298e-05,
792
+ "loss": 0.7852,
793
+ "step": 1120
794
+ },
795
+ {
796
+ "epoch": 0.42,
797
+ "grad_norm": 0.447265625,
798
+ "learning_rate": 4.9396684224407404e-05,
799
+ "loss": 0.8119,
800
+ "step": 1130
801
+ },
802
+ {
803
+ "epoch": 0.42,
804
+ "grad_norm": 0.466796875,
805
+ "learning_rate": 4.9358672983398105e-05,
806
+ "loss": 0.8018,
807
+ "step": 1140
808
+ },
809
+ {
810
+ "epoch": 0.43,
811
+ "grad_norm": 0.390625,
812
+ "learning_rate": 4.931951614745395e-05,
813
+ "loss": 0.7945,
814
+ "step": 1150
815
+ },
816
+ {
817
+ "epoch": 0.43,
818
+ "grad_norm": 0.431640625,
819
+ "learning_rate": 4.927921555813148e-05,
820
+ "loss": 0.8152,
821
+ "step": 1160
822
+ },
823
+ {
824
+ "epoch": 0.43,
825
+ "grad_norm": 0.4453125,
826
+ "learning_rate": 4.92377731107782e-05,
827
+ "loss": 0.8117,
828
+ "step": 1170
829
+ },
830
+ {
831
+ "epoch": 0.44,
832
+ "grad_norm": 0.427734375,
833
+ "learning_rate": 4.919519075444358e-05,
834
+ "loss": 0.7931,
835
+ "step": 1180
836
+ },
837
+ {
838
+ "epoch": 0.44,
839
+ "grad_norm": 0.427734375,
840
+ "learning_rate": 4.915147049178726e-05,
841
+ "loss": 0.7958,
842
+ "step": 1190
843
+ },
844
+ {
845
+ "epoch": 0.45,
846
+ "grad_norm": 0.427734375,
847
+ "learning_rate": 4.910661437898493e-05,
848
+ "loss": 0.8202,
849
+ "step": 1200
850
+ },
851
+ {
852
+ "epoch": 0.45,
853
+ "grad_norm": 0.4453125,
854
+ "learning_rate": 4.906062452563165e-05,
855
+ "loss": 0.8097,
856
+ "step": 1210
857
+ },
858
+ {
859
+ "epoch": 0.45,
860
+ "grad_norm": 0.4453125,
861
+ "learning_rate": 4.901350309464256e-05,
862
+ "loss": 0.7959,
863
+ "step": 1220
864
+ },
865
+ {
866
+ "epoch": 0.46,
867
+ "grad_norm": 0.44140625,
868
+ "learning_rate": 4.8965252302151234e-05,
869
+ "loss": 0.7805,
870
+ "step": 1230
871
+ },
872
+ {
873
+ "epoch": 0.46,
874
+ "grad_norm": 0.443359375,
875
+ "learning_rate": 4.8915874417405394e-05,
876
+ "loss": 0.8031,
877
+ "step": 1240
878
+ },
879
+ {
880
+ "epoch": 0.46,
881
+ "grad_norm": 0.41015625,
882
+ "learning_rate": 4.886537176266024e-05,
883
+ "loss": 0.8371,
884
+ "step": 1250
885
+ },
886
+ {
887
+ "epoch": 0.47,
888
+ "grad_norm": 0.427734375,
889
+ "learning_rate": 4.881374671306917e-05,
890
+ "loss": 0.8063,
891
+ "step": 1260
892
+ },
893
+ {
894
+ "epoch": 0.47,
895
+ "grad_norm": 0.4609375,
896
+ "learning_rate": 4.8761001696572166e-05,
897
+ "loss": 0.7884,
898
+ "step": 1270
899
+ },
900
+ {
901
+ "epoch": 0.47,
902
+ "grad_norm": 0.40234375,
903
+ "learning_rate": 4.87071391937815e-05,
904
+ "loss": 0.7977,
905
+ "step": 1280
906
+ },
907
+ {
908
+ "epoch": 0.48,
909
+ "grad_norm": 0.4609375,
910
+ "learning_rate": 4.865216173786517e-05,
911
+ "loss": 0.8154,
912
+ "step": 1290
913
+ },
914
+ {
915
+ "epoch": 0.48,
916
+ "grad_norm": 0.50390625,
917
+ "learning_rate": 4.859607191442768e-05,
918
+ "loss": 0.8157,
919
+ "step": 1300
920
+ },
921
+ {
922
+ "epoch": 0.49,
923
+ "grad_norm": 0.435546875,
924
+ "learning_rate": 4.853887236138851e-05,
925
+ "loss": 0.792,
926
+ "step": 1310
927
+ },
928
+ {
929
+ "epoch": 0.49,
930
+ "grad_norm": 0.42578125,
931
+ "learning_rate": 4.8480565768857995e-05,
932
+ "loss": 0.8177,
933
+ "step": 1320
934
+ },
935
+ {
936
+ "epoch": 0.49,
937
+ "grad_norm": 0.43359375,
938
+ "learning_rate": 4.842115487901086e-05,
939
+ "loss": 0.8022,
940
+ "step": 1330
941
+ },
942
+ {
943
+ "epoch": 0.5,
944
+ "grad_norm": 0.41796875,
945
+ "learning_rate": 4.8360642485957195e-05,
946
+ "loss": 0.8069,
947
+ "step": 1340
948
+ },
949
+ {
950
+ "epoch": 0.5,
951
+ "grad_norm": 0.396484375,
952
+ "learning_rate": 4.829903143561113e-05,
953
+ "loss": 0.7789,
954
+ "step": 1350
955
+ },
956
+ {
957
+ "epoch": 0.5,
958
+ "grad_norm": 0.453125,
959
+ "learning_rate": 4.823632462555691e-05,
960
+ "loss": 0.7911,
961
+ "step": 1360
962
+ },
963
+ {
964
+ "epoch": 0.51,
965
+ "grad_norm": 0.46875,
966
+ "learning_rate": 4.817252500491264e-05,
967
+ "loss": 0.8172,
968
+ "step": 1370
969
+ },
970
+ {
971
+ "epoch": 0.51,
972
+ "grad_norm": 0.435546875,
973
+ "learning_rate": 4.810763557419164e-05,
974
+ "loss": 0.8421,
975
+ "step": 1380
976
+ },
977
+ {
978
+ "epoch": 0.52,
979
+ "grad_norm": 0.447265625,
980
+ "learning_rate": 4.8041659385161255e-05,
981
+ "loss": 0.8011,
982
+ "step": 1390
983
+ },
984
+ {
985
+ "epoch": 0.52,
986
+ "grad_norm": 0.5078125,
987
+ "learning_rate": 4.7974599540699386e-05,
988
+ "loss": 0.8185,
989
+ "step": 1400
990
+ },
991
+ {
992
+ "epoch": 0.52,
993
+ "grad_norm": 0.416015625,
994
+ "learning_rate": 4.7906459194648545e-05,
995
+ "loss": 0.7877,
996
+ "step": 1410
997
+ },
998
+ {
999
+ "epoch": 0.53,
1000
+ "grad_norm": 0.462890625,
1001
+ "learning_rate": 4.783724155166751e-05,
1002
+ "loss": 0.7888,
1003
+ "step": 1420
1004
+ },
1005
+ {
1006
+ "epoch": 0.53,
1007
+ "grad_norm": 0.423828125,
1008
+ "learning_rate": 4.7766949867080624e-05,
1009
+ "loss": 0.8004,
1010
+ "step": 1430
1011
+ },
1012
+ {
1013
+ "epoch": 0.53,
1014
+ "grad_norm": 0.412109375,
1015
+ "learning_rate": 4.76955874467247e-05,
1016
+ "loss": 0.8045,
1017
+ "step": 1440
1018
+ },
1019
+ {
1020
+ "epoch": 0.54,
1021
+ "grad_norm": 0.4921875,
1022
+ "learning_rate": 4.762315764679353e-05,
1023
+ "loss": 0.7865,
1024
+ "step": 1450
1025
+ },
1026
+ {
1027
+ "epoch": 0.54,
1028
+ "grad_norm": 0.458984375,
1029
+ "learning_rate": 4.754966387368008e-05,
1030
+ "loss": 0.782,
1031
+ "step": 1460
1032
+ },
1033
+ {
1034
+ "epoch": 0.55,
1035
+ "grad_norm": 0.4453125,
1036
+ "learning_rate": 4.747510958381623e-05,
1037
+ "loss": 0.7674,
1038
+ "step": 1470
1039
+ },
1040
+ {
1041
+ "epoch": 0.55,
1042
+ "grad_norm": 0.41796875,
1043
+ "learning_rate": 4.739949828351028e-05,
1044
+ "loss": 0.805,
1045
+ "step": 1480
1046
+ },
1047
+ {
1048
+ "epoch": 0.55,
1049
+ "grad_norm": 0.427734375,
1050
+ "learning_rate": 4.7322833528782e-05,
1051
+ "loss": 0.7571,
1052
+ "step": 1490
1053
+ },
1054
+ {
1055
+ "epoch": 0.56,
1056
+ "grad_norm": 0.44921875,
1057
+ "learning_rate": 4.7245118925195374e-05,
1058
+ "loss": 0.8033,
1059
+ "step": 1500
1060
+ },
1061
+ {
1062
+ "epoch": 0.56,
1063
+ "grad_norm": 0.447265625,
1064
+ "learning_rate": 4.716635812768911e-05,
1065
+ "loss": 0.821,
1066
+ "step": 1510
1067
+ },
1068
+ {
1069
+ "epoch": 0.56,
1070
+ "grad_norm": 0.431640625,
1071
+ "learning_rate": 4.7086554840404676e-05,
1072
+ "loss": 0.8236,
1073
+ "step": 1520
1074
+ },
1075
+ {
1076
+ "epoch": 0.57,
1077
+ "grad_norm": 0.451171875,
1078
+ "learning_rate": 4.7005712816512096e-05,
1079
+ "loss": 0.7947,
1080
+ "step": 1530
1081
+ },
1082
+ {
1083
+ "epoch": 0.57,
1084
+ "grad_norm": 0.51953125,
1085
+ "learning_rate": 4.6923835858033495e-05,
1086
+ "loss": 0.7978,
1087
+ "step": 1540
1088
+ },
1089
+ {
1090
+ "epoch": 0.58,
1091
+ "grad_norm": 0.4921875,
1092
+ "learning_rate": 4.684092781566422e-05,
1093
+ "loss": 0.7876,
1094
+ "step": 1550
1095
+ },
1096
+ {
1097
+ "epoch": 0.58,
1098
+ "grad_norm": 0.408203125,
1099
+ "learning_rate": 4.6756992588591775e-05,
1100
+ "loss": 0.7836,
1101
+ "step": 1560
1102
+ },
1103
+ {
1104
+ "epoch": 0.58,
1105
+ "grad_norm": 0.408203125,
1106
+ "learning_rate": 4.667203412431245e-05,
1107
+ "loss": 0.7749,
1108
+ "step": 1570
1109
+ },
1110
+ {
1111
+ "epoch": 0.59,
1112
+ "grad_norm": 0.419921875,
1113
+ "learning_rate": 4.658605641844564e-05,
1114
+ "loss": 0.8152,
1115
+ "step": 1580
1116
+ },
1117
+ {
1118
+ "epoch": 0.59,
1119
+ "grad_norm": 0.431640625,
1120
+ "learning_rate": 4.6499063514545934e-05,
1121
+ "loss": 0.7645,
1122
+ "step": 1590
1123
+ },
1124
+ {
1125
+ "epoch": 0.59,
1126
+ "grad_norm": 0.447265625,
1127
+ "learning_rate": 4.6411059503913e-05,
1128
+ "loss": 0.7905,
1129
+ "step": 1600
1130
+ },
1131
+ {
1132
+ "epoch": 0.6,
1133
+ "grad_norm": 0.44921875,
1134
+ "learning_rate": 4.63220485253991e-05,
1135
+ "loss": 0.7851,
1136
+ "step": 1610
1137
+ },
1138
+ {
1139
+ "epoch": 0.6,
1140
+ "grad_norm": 0.435546875,
1141
+ "learning_rate": 4.623203476521445e-05,
1142
+ "loss": 0.809,
1143
+ "step": 1620
1144
+ },
1145
+ {
1146
+ "epoch": 0.6,
1147
+ "grad_norm": 0.400390625,
1148
+ "learning_rate": 4.6141022456730395e-05,
1149
+ "loss": 0.7852,
1150
+ "step": 1630
1151
+ },
1152
+ {
1153
+ "epoch": 0.61,
1154
+ "grad_norm": 0.44140625,
1155
+ "learning_rate": 4.604901588028024e-05,
1156
+ "loss": 0.7987,
1157
+ "step": 1640
1158
+ },
1159
+ {
1160
+ "epoch": 0.61,
1161
+ "grad_norm": 0.48046875,
1162
+ "learning_rate": 4.5956019362958006e-05,
1163
+ "loss": 0.8158,
1164
+ "step": 1650
1165
+ },
1166
+ {
1167
+ "epoch": 0.62,
1168
+ "grad_norm": 0.43359375,
1169
+ "learning_rate": 4.586203727841488e-05,
1170
+ "loss": 0.8109,
1171
+ "step": 1660
1172
+ },
1173
+ {
1174
+ "epoch": 0.62,
1175
+ "grad_norm": 0.408203125,
1176
+ "learning_rate": 4.576707404665356e-05,
1177
+ "loss": 0.7697,
1178
+ "step": 1670
1179
+ },
1180
+ {
1181
+ "epoch": 0.62,
1182
+ "grad_norm": 0.423828125,
1183
+ "learning_rate": 4.567113413382034e-05,
1184
+ "loss": 0.791,
1185
+ "step": 1680
1186
+ },
1187
+ {
1188
+ "epoch": 0.63,
1189
+ "grad_norm": 0.43359375,
1190
+ "learning_rate": 4.5574222051995085e-05,
1191
+ "loss": 0.7941,
1192
+ "step": 1690
1193
+ },
1194
+ {
1195
+ "epoch": 0.63,
1196
+ "grad_norm": 0.412109375,
1197
+ "learning_rate": 4.547634235897906e-05,
1198
+ "loss": 0.8203,
1199
+ "step": 1700
1200
+ },
1201
+ {
1202
+ "epoch": 0.63,
1203
+ "grad_norm": 0.451171875,
1204
+ "learning_rate": 4.5377499658080525e-05,
1205
+ "loss": 0.8188,
1206
+ "step": 1710
1207
+ },
1208
+ {
1209
+ "epoch": 0.64,
1210
+ "grad_norm": 0.42578125,
1211
+ "learning_rate": 4.527769859789825e-05,
1212
+ "loss": 0.8146,
1213
+ "step": 1720
1214
+ },
1215
+ {
1216
+ "epoch": 0.64,
1217
+ "grad_norm": 0.392578125,
1218
+ "learning_rate": 4.5176943872102915e-05,
1219
+ "loss": 0.7621,
1220
+ "step": 1730
1221
+ },
1222
+ {
1223
+ "epoch": 0.65,
1224
+ "grad_norm": 0.451171875,
1225
+ "learning_rate": 4.5075240219216336e-05,
1226
+ "loss": 0.801,
1227
+ "step": 1740
1228
+ },
1229
+ {
1230
+ "epoch": 0.65,
1231
+ "grad_norm": 0.4765625,
1232
+ "learning_rate": 4.4972592422388634e-05,
1233
+ "loss": 0.7702,
1234
+ "step": 1750
1235
+ },
1236
+ {
1237
+ "epoch": 0.65,
1238
+ "grad_norm": 0.390625,
1239
+ "learning_rate": 4.486900530917329e-05,
1240
+ "loss": 0.7888,
1241
+ "step": 1760
1242
+ },
1243
+ {
1244
+ "epoch": 0.66,
1245
+ "grad_norm": 0.44921875,
1246
+ "learning_rate": 4.476448375130004e-05,
1247
+ "loss": 0.7873,
1248
+ "step": 1770
1249
+ },
1250
+ {
1251
+ "epoch": 0.66,
1252
+ "grad_norm": 0.455078125,
1253
+ "learning_rate": 4.4659032664445856e-05,
1254
+ "loss": 0.7647,
1255
+ "step": 1780
1256
+ },
1257
+ {
1258
+ "epoch": 0.66,
1259
+ "grad_norm": 0.455078125,
1260
+ "learning_rate": 4.4552657008003676e-05,
1261
+ "loss": 0.7822,
1262
+ "step": 1790
1263
+ },
1264
+ {
1265
+ "epoch": 0.67,
1266
+ "grad_norm": 0.458984375,
1267
+ "learning_rate": 4.4445361784849195e-05,
1268
+ "loss": 0.7746,
1269
+ "step": 1800
1270
+ },
1271
+ {
1272
+ "epoch": 0.67,
1273
+ "grad_norm": 0.458984375,
1274
+ "learning_rate": 4.43371520411056e-05,
1275
+ "loss": 0.8167,
1276
+ "step": 1810
1277
+ },
1278
+ {
1279
+ "epoch": 0.68,
1280
+ "grad_norm": 0.431640625,
1281
+ "learning_rate": 4.42280328659062e-05,
1282
+ "loss": 0.8368,
1283
+ "step": 1820
1284
+ },
1285
+ {
1286
+ "epoch": 0.68,
1287
+ "grad_norm": 0.427734375,
1288
+ "learning_rate": 4.4118009391155124e-05,
1289
+ "loss": 0.8029,
1290
+ "step": 1830
1291
+ },
1292
+ {
1293
+ "epoch": 0.68,
1294
+ "grad_norm": 0.396484375,
1295
+ "learning_rate": 4.400708679128596e-05,
1296
+ "loss": 0.8033,
1297
+ "step": 1840
1298
+ },
1299
+ {
1300
+ "epoch": 0.69,
1301
+ "grad_norm": 0.42578125,
1302
+ "learning_rate": 4.389527028301836e-05,
1303
+ "loss": 0.7797,
1304
+ "step": 1850
1305
+ },
1306
+ {
1307
+ "epoch": 0.69,
1308
+ "grad_norm": 0.412109375,
1309
+ "learning_rate": 4.378256512511277e-05,
1310
+ "loss": 0.8037,
1311
+ "step": 1860
1312
+ },
1313
+ {
1314
+ "epoch": 0.69,
1315
+ "grad_norm": 0.4921875,
1316
+ "learning_rate": 4.366897661812304e-05,
1317
+ "loss": 0.8031,
1318
+ "step": 1870
1319
+ },
1320
+ {
1321
+ "epoch": 0.7,
1322
+ "grad_norm": 0.46875,
1323
+ "learning_rate": 4.355451010414716e-05,
1324
+ "loss": 0.7943,
1325
+ "step": 1880
1326
+ },
1327
+ {
1328
+ "epoch": 0.7,
1329
+ "grad_norm": 0.41796875,
1330
+ "learning_rate": 4.343917096657606e-05,
1331
+ "loss": 0.7925,
1332
+ "step": 1890
1333
+ },
1334
+ {
1335
+ "epoch": 0.7,
1336
+ "grad_norm": 0.427734375,
1337
+ "learning_rate": 4.3322964629840344e-05,
1338
+ "loss": 0.7984,
1339
+ "step": 1900
1340
+ },
1341
+ {
1342
+ "epoch": 0.71,
1343
+ "grad_norm": 0.4453125,
1344
+ "learning_rate": 4.320589655915527e-05,
1345
+ "loss": 0.8129,
1346
+ "step": 1910
1347
+ },
1348
+ {
1349
+ "epoch": 0.71,
1350
+ "grad_norm": 0.427734375,
1351
+ "learning_rate": 4.308797226026364e-05,
1352
+ "loss": 0.7955,
1353
+ "step": 1920
1354
+ },
1355
+ {
1356
+ "epoch": 0.72,
1357
+ "grad_norm": 0.42578125,
1358
+ "learning_rate": 4.296919727917692e-05,
1359
+ "loss": 0.8326,
1360
+ "step": 1930
1361
+ },
1362
+ {
1363
+ "epoch": 0.72,
1364
+ "grad_norm": 0.439453125,
1365
+ "learning_rate": 4.284957720191438e-05,
1366
+ "loss": 0.8345,
1367
+ "step": 1940
1368
+ },
1369
+ {
1370
+ "epoch": 0.72,
1371
+ "grad_norm": 0.3828125,
1372
+ "learning_rate": 4.272911765424039e-05,
1373
+ "loss": 0.7972,
1374
+ "step": 1950
1375
+ },
1376
+ {
1377
+ "epoch": 0.73,
1378
+ "grad_norm": 0.412109375,
1379
+ "learning_rate": 4.260782430139984e-05,
1380
+ "loss": 0.7851,
1381
+ "step": 1960
1382
+ },
1383
+ {
1384
+ "epoch": 0.73,
1385
+ "grad_norm": 0.44140625,
1386
+ "learning_rate": 4.248570284785172e-05,
1387
+ "loss": 0.8103,
1388
+ "step": 1970
1389
+ },
1390
+ {
1391
+ "epoch": 0.73,
1392
+ "grad_norm": 0.466796875,
1393
+ "learning_rate": 4.236275903700078e-05,
1394
+ "loss": 0.8216,
1395
+ "step": 1980
1396
+ },
1397
+ {
1398
+ "epoch": 0.74,
1399
+ "grad_norm": 0.431640625,
1400
+ "learning_rate": 4.223899865092749e-05,
1401
+ "loss": 0.8012,
1402
+ "step": 1990
1403
+ },
1404
+ {
1405
+ "epoch": 0.74,
1406
+ "grad_norm": 0.443359375,
1407
+ "learning_rate": 4.2114427510116036e-05,
1408
+ "loss": 0.7701,
1409
+ "step": 2000
1410
+ },
1411
+ {
1412
+ "epoch": 0.75,
1413
+ "grad_norm": 0.44921875,
1414
+ "learning_rate": 4.198905147318065e-05,
1415
+ "loss": 0.7926,
1416
+ "step": 2010
1417
+ },
1418
+ {
1419
+ "epoch": 0.75,
1420
+ "grad_norm": 0.43359375,
1421
+ "learning_rate": 4.186287643659005e-05,
1422
+ "loss": 0.8113,
1423
+ "step": 2020
1424
+ },
1425
+ {
1426
+ "epoch": 0.75,
1427
+ "grad_norm": 0.423828125,
1428
+ "learning_rate": 4.1735908334390085e-05,
1429
+ "loss": 0.8093,
1430
+ "step": 2030
1431
+ },
1432
+ {
1433
+ "epoch": 0.76,
1434
+ "grad_norm": 0.3828125,
1435
+ "learning_rate": 4.1608153137924723e-05,
1436
+ "loss": 0.7778,
1437
+ "step": 2040
1438
+ },
1439
+ {
1440
+ "epoch": 0.76,
1441
+ "grad_norm": 0.427734375,
1442
+ "learning_rate": 4.147961685555517e-05,
1443
+ "loss": 0.8171,
1444
+ "step": 2050
1445
+ },
1446
+ {
1447
+ "epoch": 0.76,
1448
+ "grad_norm": 0.43359375,
1449
+ "learning_rate": 4.1350305532377334e-05,
1450
+ "loss": 0.8025,
1451
+ "step": 2060
1452
+ },
1453
+ {
1454
+ "epoch": 0.77,
1455
+ "grad_norm": 0.404296875,
1456
+ "learning_rate": 4.122022524993747e-05,
1457
+ "loss": 0.7875,
1458
+ "step": 2070
1459
+ },
1460
+ {
1461
+ "epoch": 0.77,
1462
+ "grad_norm": 0.41015625,
1463
+ "learning_rate": 4.108938212594622e-05,
1464
+ "loss": 0.7867,
1465
+ "step": 2080
1466
+ },
1467
+ {
1468
+ "epoch": 0.78,
1469
+ "grad_norm": 0.4375,
1470
+ "learning_rate": 4.095778231399086e-05,
1471
+ "loss": 0.7849,
1472
+ "step": 2090
1473
+ },
1474
+ {
1475
+ "epoch": 0.78,
1476
+ "grad_norm": 0.470703125,
1477
+ "learning_rate": 4.08254320032459e-05,
1478
+ "loss": 0.8028,
1479
+ "step": 2100
1480
+ },
1481
+ {
1482
+ "epoch": 0.78,
1483
+ "grad_norm": 0.44921875,
1484
+ "learning_rate": 4.0692337418182014e-05,
1485
+ "loss": 0.8001,
1486
+ "step": 2110
1487
+ },
1488
+ {
1489
+ "epoch": 0.79,
1490
+ "grad_norm": 0.474609375,
1491
+ "learning_rate": 4.055850481827329e-05,
1492
+ "loss": 0.8469,
1493
+ "step": 2120
1494
+ },
1495
+ {
1496
+ "epoch": 0.79,
1497
+ "grad_norm": 0.43359375,
1498
+ "learning_rate": 4.042394049770286e-05,
1499
+ "loss": 0.7858,
1500
+ "step": 2130
1501
+ },
1502
+ {
1503
+ "epoch": 0.79,
1504
+ "grad_norm": 0.400390625,
1505
+ "learning_rate": 4.0288650785066886e-05,
1506
+ "loss": 0.8021,
1507
+ "step": 2140
1508
+ },
1509
+ {
1510
+ "epoch": 0.8,
1511
+ "grad_norm": 0.4453125,
1512
+ "learning_rate": 4.0152642043076884e-05,
1513
+ "loss": 0.8165,
1514
+ "step": 2150
1515
+ },
1516
+ {
1517
+ "epoch": 0.8,
1518
+ "grad_norm": 0.43359375,
1519
+ "learning_rate": 4.0015920668260544e-05,
1520
+ "loss": 0.7834,
1521
+ "step": 2160
1522
+ },
1523
+ {
1524
+ "epoch": 0.81,
1525
+ "grad_norm": 0.435546875,
1526
+ "learning_rate": 3.987849309066085e-05,
1527
+ "loss": 0.8018,
1528
+ "step": 2170
1529
+ },
1530
+ {
1531
+ "epoch": 0.81,
1532
+ "grad_norm": 0.3984375,
1533
+ "learning_rate": 3.9740365773533704e-05,
1534
+ "loss": 0.7935,
1535
+ "step": 2180
1536
+ },
1537
+ {
1538
+ "epoch": 0.81,
1539
+ "grad_norm": 0.4453125,
1540
+ "learning_rate": 3.960154521304394e-05,
1541
+ "loss": 0.7974,
1542
+ "step": 2190
1543
+ },
1544
+ {
1545
+ "epoch": 0.82,
1546
+ "grad_norm": 0.439453125,
1547
+ "learning_rate": 3.946203793795982e-05,
1548
+ "loss": 0.7654,
1549
+ "step": 2200
1550
+ },
1551
+ {
1552
+ "epoch": 0.82,
1553
+ "grad_norm": 0.4375,
1554
+ "learning_rate": 3.9321850509345946e-05,
1555
+ "loss": 0.7982,
1556
+ "step": 2210
1557
+ },
1558
+ {
1559
+ "epoch": 0.82,
1560
+ "grad_norm": 0.458984375,
1561
+ "learning_rate": 3.9180989520254785e-05,
1562
+ "loss": 0.8053,
1563
+ "step": 2220
1564
+ },
1565
+ {
1566
+ "epoch": 0.83,
1567
+ "grad_norm": 0.42578125,
1568
+ "learning_rate": 3.903946159541647e-05,
1569
+ "loss": 0.8066,
1570
+ "step": 2230
1571
+ },
1572
+ {
1573
+ "epoch": 0.83,
1574
+ "grad_norm": 0.447265625,
1575
+ "learning_rate": 3.889727339092736e-05,
1576
+ "loss": 0.8322,
1577
+ "step": 2240
1578
+ },
1579
+ {
1580
+ "epoch": 0.83,
1581
+ "grad_norm": 0.453125,
1582
+ "learning_rate": 3.875443159393689e-05,
1583
+ "loss": 0.7522,
1584
+ "step": 2250
1585
+ },
1586
+ {
1587
+ "epoch": 0.84,
1588
+ "grad_norm": 0.48046875,
1589
+ "learning_rate": 3.861094292233316e-05,
1590
+ "loss": 0.8174,
1591
+ "step": 2260
1592
+ },
1593
+ {
1594
+ "epoch": 0.84,
1595
+ "grad_norm": 0.455078125,
1596
+ "learning_rate": 3.8466814124426945e-05,
1597
+ "loss": 0.8254,
1598
+ "step": 2270
1599
+ },
1600
+ {
1601
+ "epoch": 0.85,
1602
+ "grad_norm": 0.419921875,
1603
+ "learning_rate": 3.8322051978634325e-05,
1604
+ "loss": 0.7808,
1605
+ "step": 2280
1606
+ },
1607
+ {
1608
+ "epoch": 0.85,
1609
+ "grad_norm": 0.42578125,
1610
+ "learning_rate": 3.817666329315792e-05,
1611
+ "loss": 0.7936,
1612
+ "step": 2290
1613
+ },
1614
+ {
1615
+ "epoch": 0.85,
1616
+ "grad_norm": 0.451171875,
1617
+ "learning_rate": 3.803065490566667e-05,
1618
+ "loss": 0.8087,
1619
+ "step": 2300
1620
+ },
1621
+ {
1622
+ "epoch": 0.86,
1623
+ "grad_norm": 0.4296875,
1624
+ "learning_rate": 3.788403368297426e-05,
1625
+ "loss": 0.8025,
1626
+ "step": 2310
1627
+ },
1628
+ {
1629
+ "epoch": 0.86,
1630
+ "grad_norm": 0.453125,
1631
+ "learning_rate": 3.773680652071619e-05,
1632
+ "loss": 0.8164,
1633
+ "step": 2320
1634
+ },
1635
+ {
1636
+ "epoch": 0.86,
1637
+ "grad_norm": 0.447265625,
1638
+ "learning_rate": 3.758898034302547e-05,
1639
+ "loss": 0.8024,
1640
+ "step": 2330
1641
+ },
1642
+ {
1643
+ "epoch": 0.87,
1644
+ "grad_norm": 0.439453125,
1645
+ "learning_rate": 3.7440562102206924e-05,
1646
+ "loss": 0.7758,
1647
+ "step": 2340
1648
+ },
1649
+ {
1650
+ "epoch": 0.87,
1651
+ "grad_norm": 0.419921875,
1652
+ "learning_rate": 3.7291558778410314e-05,
1653
+ "loss": 0.7855,
1654
+ "step": 2350
1655
+ },
1656
+ {
1657
+ "epoch": 0.88,
1658
+ "grad_norm": 0.423828125,
1659
+ "learning_rate": 3.714197737930199e-05,
1660
+ "loss": 0.7729,
1661
+ "step": 2360
1662
+ },
1663
+ {
1664
+ "epoch": 0.88,
1665
+ "grad_norm": 0.400390625,
1666
+ "learning_rate": 3.699182493973532e-05,
1667
+ "loss": 0.8203,
1668
+ "step": 2370
1669
+ },
1670
+ {
1671
+ "epoch": 0.88,
1672
+ "grad_norm": 0.453125,
1673
+ "learning_rate": 3.684110852141991e-05,
1674
+ "loss": 0.8143,
1675
+ "step": 2380
1676
+ },
1677
+ {
1678
+ "epoch": 0.89,
1679
+ "grad_norm": 0.44921875,
1680
+ "learning_rate": 3.668983521258938e-05,
1681
+ "loss": 0.7886,
1682
+ "step": 2390
1683
+ },
1684
+ {
1685
+ "epoch": 0.89,
1686
+ "grad_norm": 0.470703125,
1687
+ "learning_rate": 3.65380121276681e-05,
1688
+ "loss": 0.804,
1689
+ "step": 2400
1690
+ },
1691
+ {
1692
+ "epoch": 0.89,
1693
+ "grad_norm": 0.43359375,
1694
+ "learning_rate": 3.638564640693654e-05,
1695
+ "loss": 0.7876,
1696
+ "step": 2410
1697
+ },
1698
+ {
1699
+ "epoch": 0.9,
1700
+ "grad_norm": 0.478515625,
1701
+ "learning_rate": 3.623274521619549e-05,
1702
+ "loss": 0.8019,
1703
+ "step": 2420
1704
+ },
1705
+ {
1706
+ "epoch": 0.9,
1707
+ "grad_norm": 0.4140625,
1708
+ "learning_rate": 3.607931574642902e-05,
1709
+ "loss": 0.8213,
1710
+ "step": 2430
1711
+ },
1712
+ {
1713
+ "epoch": 0.91,
1714
+ "grad_norm": 0.43359375,
1715
+ "learning_rate": 3.5925365213466314e-05,
1716
+ "loss": 0.7727,
1717
+ "step": 2440
1718
+ },
1719
+ {
1720
+ "epoch": 0.91,
1721
+ "grad_norm": 0.451171875,
1722
+ "learning_rate": 3.5770900857642306e-05,
1723
+ "loss": 0.8027,
1724
+ "step": 2450
1725
+ },
1726
+ {
1727
+ "epoch": 0.91,
1728
+ "grad_norm": 0.44140625,
1729
+ "learning_rate": 3.561592994345715e-05,
1730
+ "loss": 0.7515,
1731
+ "step": 2460
1732
+ },
1733
+ {
1734
+ "epoch": 0.92,
1735
+ "grad_norm": 0.431640625,
1736
+ "learning_rate": 3.546045975923458e-05,
1737
+ "loss": 0.7791,
1738
+ "step": 2470
1739
+ },
1740
+ {
1741
+ "epoch": 0.92,
1742
+ "grad_norm": 0.423828125,
1743
+ "learning_rate": 3.530449761677911e-05,
1744
+ "loss": 0.7931,
1745
+ "step": 2480
1746
+ },
1747
+ {
1748
+ "epoch": 0.92,
1749
+ "grad_norm": 0.484375,
1750
+ "learning_rate": 3.514805085103222e-05,
1751
+ "loss": 0.8273,
1752
+ "step": 2490
1753
+ },
1754
+ {
1755
+ "epoch": 0.93,
1756
+ "grad_norm": 0.4453125,
1757
+ "learning_rate": 3.499112681972734e-05,
1758
+ "loss": 0.7935,
1759
+ "step": 2500
1760
+ },
1761
+ {
1762
+ "epoch": 0.93,
1763
+ "grad_norm": 0.41796875,
1764
+ "learning_rate": 3.4833732903043806e-05,
1765
+ "loss": 0.8248,
1766
+ "step": 2510
1767
+ },
1768
+ {
1769
+ "epoch": 0.93,
1770
+ "grad_norm": 0.470703125,
1771
+ "learning_rate": 3.467587650325981e-05,
1772
+ "loss": 0.8168,
1773
+ "step": 2520
1774
+ },
1775
+ {
1776
+ "epoch": 0.94,
1777
+ "grad_norm": 0.416015625,
1778
+ "learning_rate": 3.4517565044404266e-05,
1779
+ "loss": 0.8103,
1780
+ "step": 2530
1781
+ },
1782
+ {
1783
+ "epoch": 0.94,
1784
+ "grad_norm": 0.421875,
1785
+ "learning_rate": 3.4358805971907593e-05,
1786
+ "loss": 0.8084,
1787
+ "step": 2540
1788
+ },
1789
+ {
1790
+ "epoch": 0.95,
1791
+ "grad_norm": 0.412109375,
1792
+ "learning_rate": 3.4199606752251634e-05,
1793
+ "loss": 0.8073,
1794
+ "step": 2550
1795
+ },
1796
+ {
1797
+ "epoch": 0.95,
1798
+ "grad_norm": 0.41796875,
1799
+ "learning_rate": 3.403997487261846e-05,
1800
+ "loss": 0.7934,
1801
+ "step": 2560
1802
+ },
1803
+ {
1804
+ "epoch": 0.95,
1805
+ "grad_norm": 0.427734375,
1806
+ "learning_rate": 3.3879917840538265e-05,
1807
+ "loss": 0.7868,
1808
+ "step": 2570
1809
+ },
1810
+ {
1811
+ "epoch": 0.96,
1812
+ "grad_norm": 0.45703125,
1813
+ "learning_rate": 3.371944318353626e-05,
1814
+ "loss": 0.8131,
1815
+ "step": 2580
1816
+ },
1817
+ {
1818
+ "epoch": 0.96,
1819
+ "grad_norm": 0.408203125,
1820
+ "learning_rate": 3.355855844877869e-05,
1821
+ "loss": 0.8016,
1822
+ "step": 2590
1823
+ },
1824
+ {
1825
+ "epoch": 0.96,
1826
+ "grad_norm": 0.51171875,
1827
+ "learning_rate": 3.3397271202717834e-05,
1828
+ "loss": 0.784,
1829
+ "step": 2600
1830
+ },
1831
+ {
1832
+ "epoch": 0.97,
1833
+ "grad_norm": 0.427734375,
1834
+ "learning_rate": 3.323558903073623e-05,
1835
+ "loss": 0.795,
1836
+ "step": 2610
1837
+ },
1838
+ {
1839
+ "epoch": 0.97,
1840
+ "grad_norm": 0.435546875,
1841
+ "learning_rate": 3.307351953678986e-05,
1842
+ "loss": 0.7958,
1843
+ "step": 2620
1844
+ },
1845
+ {
1846
+ "epoch": 0.98,
1847
+ "grad_norm": 0.466796875,
1848
+ "learning_rate": 3.2911070343050555e-05,
1849
+ "loss": 0.7914,
1850
+ "step": 2630
1851
+ },
1852
+ {
1853
+ "epoch": 0.98,
1854
+ "grad_norm": 0.41796875,
1855
+ "learning_rate": 3.274824908954756e-05,
1856
+ "loss": 0.7871,
1857
+ "step": 2640
1858
+ },
1859
+ {
1860
+ "epoch": 0.98,
1861
+ "grad_norm": 0.458984375,
1862
+ "learning_rate": 3.258506343380815e-05,
1863
+ "loss": 0.785,
1864
+ "step": 2650
1865
+ },
1866
+ {
1867
+ "epoch": 0.99,
1868
+ "grad_norm": 0.412109375,
1869
+ "learning_rate": 3.242152105049758e-05,
1870
+ "loss": 0.8188,
1871
+ "step": 2660
1872
+ },
1873
+ {
1874
+ "epoch": 0.99,
1875
+ "grad_norm": 0.427734375,
1876
+ "learning_rate": 3.2257629631058066e-05,
1877
+ "loss": 0.7935,
1878
+ "step": 2670
1879
+ },
1880
+ {
1881
+ "epoch": 0.99,
1882
+ "grad_norm": 0.466796875,
1883
+ "learning_rate": 3.20933968833471e-05,
1884
+ "loss": 0.8115,
1885
+ "step": 2680
1886
+ },
1887
+ {
1888
+ "epoch": 1.0,
1889
+ "grad_norm": 0.43359375,
1890
+ "learning_rate": 3.1928830531274935e-05,
1891
+ "loss": 0.8129,
1892
+ "step": 2690
1893
+ },
1894
+ {
1895
+ "epoch": 1.0,
1896
+ "grad_norm": 0.392578125,
1897
+ "learning_rate": 3.176393831444131e-05,
1898
+ "loss": 0.7732,
1899
+ "step": 2700
1900
+ },
1901
+ {
1902
+ "epoch": 1.01,
1903
+ "grad_norm": 0.435546875,
1904
+ "learning_rate": 3.159872798777149e-05,
1905
+ "loss": 0.794,
1906
+ "step": 2710
1907
+ },
1908
+ {
1909
+ "epoch": 1.01,
1910
+ "grad_norm": 0.421875,
1911
+ "learning_rate": 3.143320732115153e-05,
1912
+ "loss": 0.7794,
1913
+ "step": 2720
1914
+ },
1915
+ {
1916
+ "epoch": 1.01,
1917
+ "grad_norm": 0.40234375,
1918
+ "learning_rate": 3.126738409906284e-05,
1919
+ "loss": 0.7922,
1920
+ "step": 2730
1921
+ },
1922
+ {
1923
+ "epoch": 1.02,
1924
+ "grad_norm": 0.451171875,
1925
+ "learning_rate": 3.110126612021613e-05,
1926
+ "loss": 0.7881,
1927
+ "step": 2740
1928
+ },
1929
+ {
1930
+ "epoch": 1.02,
1931
+ "grad_norm": 0.427734375,
1932
+ "learning_rate": 3.093486119718455e-05,
1933
+ "loss": 0.7701,
1934
+ "step": 2750
1935
+ },
1936
+ {
1937
+ "epoch": 1.02,
1938
+ "grad_norm": 0.4140625,
1939
+ "learning_rate": 3.076817715603634e-05,
1940
+ "loss": 0.7826,
1941
+ "step": 2760
1942
+ },
1943
+ {
1944
+ "epoch": 1.03,
1945
+ "grad_norm": 0.451171875,
1946
+ "learning_rate": 3.060122183596676e-05,
1947
+ "loss": 0.7625,
1948
+ "step": 2770
1949
+ },
1950
+ {
1951
+ "epoch": 1.03,
1952
+ "grad_norm": 0.435546875,
1953
+ "learning_rate": 3.0434003088929354e-05,
1954
+ "loss": 0.7932,
1955
+ "step": 2780
1956
+ },
1957
+ {
1958
+ "epoch": 1.04,
1959
+ "grad_norm": 0.40625,
1960
+ "learning_rate": 3.0266528779266722e-05,
1961
+ "loss": 0.7694,
1962
+ "step": 2790
1963
+ },
1964
+ {
1965
+ "epoch": 1.04,
1966
+ "grad_norm": 0.453125,
1967
+ "learning_rate": 3.0098806783340644e-05,
1968
+ "loss": 0.7738,
1969
+ "step": 2800
1970
+ },
1971
+ {
1972
+ "epoch": 1.04,
1973
+ "grad_norm": 0.4140625,
1974
+ "learning_rate": 2.993084498916165e-05,
1975
+ "loss": 0.7805,
1976
+ "step": 2810
1977
+ },
1978
+ {
1979
+ "epoch": 1.05,
1980
+ "grad_norm": 0.43359375,
1981
+ "learning_rate": 2.9762651296018047e-05,
1982
+ "loss": 0.7879,
1983
+ "step": 2820
1984
+ },
1985
+ {
1986
+ "epoch": 1.05,
1987
+ "grad_norm": 0.435546875,
1988
+ "learning_rate": 2.9594233614104412e-05,
1989
+ "loss": 0.814,
1990
+ "step": 2830
1991
+ },
1992
+ {
1993
+ "epoch": 1.05,
1994
+ "grad_norm": 0.3984375,
1995
+ "learning_rate": 2.942559986414957e-05,
1996
+ "loss": 0.789,
1997
+ "step": 2840
1998
+ },
1999
+ {
2000
+ "epoch": 1.06,
2001
+ "grad_norm": 0.439453125,
2002
+ "learning_rate": 2.925675797704411e-05,
2003
+ "loss": 0.815,
2004
+ "step": 2850
2005
+ },
2006
+ {
2007
+ "epoch": 1.06,
2008
+ "grad_norm": 0.388671875,
2009
+ "learning_rate": 2.908771589346731e-05,
2010
+ "loss": 0.7808,
2011
+ "step": 2860
2012
+ },
2013
+ {
2014
+ "epoch": 1.06,
2015
+ "grad_norm": 0.447265625,
2016
+ "learning_rate": 2.89184815635138e-05,
2017
+ "loss": 0.7706,
2018
+ "step": 2870
2019
+ },
2020
+ {
2021
+ "epoch": 1.07,
2022
+ "grad_norm": 0.427734375,
2023
+ "learning_rate": 2.8749062946319576e-05,
2024
+ "loss": 0.7939,
2025
+ "step": 2880
2026
+ },
2027
+ {
2028
+ "epoch": 1.07,
2029
+ "grad_norm": 0.419921875,
2030
+ "learning_rate": 2.857946800968773e-05,
2031
+ "loss": 0.7898,
2032
+ "step": 2890
2033
+ },
2034
+ {
2035
+ "epoch": 1.08,
2036
+ "grad_norm": 0.51953125,
2037
+ "learning_rate": 2.8409704729713694e-05,
2038
+ "loss": 0.8139,
2039
+ "step": 2900
2040
+ },
2041
+ {
2042
+ "epoch": 1.08,
2043
+ "grad_norm": 0.431640625,
2044
+ "learning_rate": 2.8239781090410133e-05,
2045
+ "loss": 0.8046,
2046
+ "step": 2910
2047
+ },
2048
+ {
2049
+ "epoch": 1.08,
2050
+ "grad_norm": 0.4765625,
2051
+ "learning_rate": 2.806970508333146e-05,
2052
+ "loss": 0.7808,
2053
+ "step": 2920
2054
+ },
2055
+ {
2056
+ "epoch": 1.09,
2057
+ "grad_norm": 0.4296875,
2058
+ "learning_rate": 2.789948470719798e-05,
2059
+ "loss": 0.7892,
2060
+ "step": 2930
2061
+ },
2062
+ {
2063
+ "epoch": 1.09,
2064
+ "grad_norm": 0.416015625,
2065
+ "learning_rate": 2.772912796751972e-05,
2066
+ "loss": 0.7499,
2067
+ "step": 2940
2068
+ },
2069
+ {
2070
+ "epoch": 1.09,
2071
+ "grad_norm": 0.474609375,
2072
+ "learning_rate": 2.755864287621992e-05,
2073
+ "loss": 0.7509,
2074
+ "step": 2950
2075
+ },
2076
+ {
2077
+ "epoch": 1.1,
2078
+ "grad_norm": 0.435546875,
2079
+ "learning_rate": 2.738803745125821e-05,
2080
+ "loss": 0.8001,
2081
+ "step": 2960
2082
+ },
2083
+ {
2084
+ "epoch": 1.1,
2085
+ "grad_norm": 0.396484375,
2086
+ "learning_rate": 2.7217319716253574e-05,
2087
+ "loss": 0.7911,
2088
+ "step": 2970
2089
+ },
2090
+ {
2091
+ "epoch": 1.11,
2092
+ "grad_norm": 0.4296875,
2093
+ "learning_rate": 2.704649770010696e-05,
2094
+ "loss": 0.8088,
2095
+ "step": 2980
2096
+ },
2097
+ {
2098
+ "epoch": 1.11,
2099
+ "grad_norm": 0.416015625,
2100
+ "learning_rate": 2.6875579436623678e-05,
2101
+ "loss": 0.8155,
2102
+ "step": 2990
2103
+ },
2104
+ {
2105
+ "epoch": 1.11,
2106
+ "grad_norm": 0.431640625,
2107
+ "learning_rate": 2.6704572964135576e-05,
2108
+ "loss": 0.7625,
2109
+ "step": 3000
2110
+ },
2111
+ {
2112
+ "epoch": 1.12,
2113
+ "grad_norm": 0.416015625,
2114
+ "learning_rate": 2.6533486325123007e-05,
2115
+ "loss": 0.7729,
2116
+ "step": 3010
2117
+ },
2118
+ {
2119
+ "epoch": 1.12,
2120
+ "grad_norm": 0.4140625,
2121
+ "learning_rate": 2.636232756583657e-05,
2122
+ "loss": 0.7772,
2123
+ "step": 3020
2124
+ },
2125
+ {
2126
+ "epoch": 1.12,
2127
+ "grad_norm": 0.431640625,
2128
+ "learning_rate": 2.6191104735918686e-05,
2129
+ "loss": 0.7969,
2130
+ "step": 3030
2131
+ },
2132
+ {
2133
+ "epoch": 1.13,
2134
+ "grad_norm": 0.451171875,
2135
+ "learning_rate": 2.601982588802507e-05,
2136
+ "loss": 0.8003,
2137
+ "step": 3040
2138
+ },
2139
+ {
2140
+ "epoch": 1.13,
2141
+ "grad_norm": 0.44921875,
2142
+ "learning_rate": 2.5848499077445932e-05,
2143
+ "loss": 0.8036,
2144
+ "step": 3050
2145
+ },
2146
+ {
2147
+ "epoch": 1.14,
2148
+ "grad_norm": 0.44921875,
2149
+ "learning_rate": 2.5677132361727225e-05,
2150
+ "loss": 0.7889,
2151
+ "step": 3060
2152
+ },
2153
+ {
2154
+ "epoch": 1.14,
2155
+ "grad_norm": 0.40234375,
2156
+ "learning_rate": 2.5505733800291622e-05,
2157
+ "loss": 0.7891,
2158
+ "step": 3070
2159
+ },
2160
+ {
2161
+ "epoch": 1.14,
2162
+ "grad_norm": 0.42578125,
2163
+ "learning_rate": 2.5334311454059505e-05,
2164
+ "loss": 0.7805,
2165
+ "step": 3080
2166
+ },
2167
+ {
2168
+ "epoch": 1.15,
2169
+ "grad_norm": 0.416015625,
2170
+ "learning_rate": 2.516287338506989e-05,
2171
+ "loss": 0.8171,
2172
+ "step": 3090
2173
+ },
2174
+ {
2175
+ "epoch": 1.15,
2176
+ "grad_norm": 0.41015625,
2177
+ "learning_rate": 2.499142765610122e-05,
2178
+ "loss": 0.7768,
2179
+ "step": 3100
2180
+ },
2181
+ {
2182
+ "epoch": 1.15,
2183
+ "grad_norm": 0.40234375,
2184
+ "learning_rate": 2.4819982330292184e-05,
2185
+ "loss": 0.822,
2186
+ "step": 3110
2187
+ },
2188
+ {
2189
+ "epoch": 1.16,
2190
+ "grad_norm": 0.4375,
2191
+ "learning_rate": 2.4648545470762517e-05,
2192
+ "loss": 0.7701,
2193
+ "step": 3120
2194
+ },
2195
+ {
2196
+ "epoch": 1.16,
2197
+ "grad_norm": 0.443359375,
2198
+ "learning_rate": 2.4477125140233787e-05,
2199
+ "loss": 0.7995,
2200
+ "step": 3130
2201
+ },
2202
+ {
2203
+ "epoch": 1.16,
2204
+ "grad_norm": 0.4609375,
2205
+ "learning_rate": 2.4305729400650192e-05,
2206
+ "loss": 0.7826,
2207
+ "step": 3140
2208
+ },
2209
+ {
2210
+ "epoch": 1.17,
2211
+ "grad_norm": 0.4296875,
2212
+ "learning_rate": 2.4134366312799412e-05,
2213
+ "loss": 0.7764,
2214
+ "step": 3150
2215
+ },
2216
+ {
2217
+ "epoch": 1.17,
2218
+ "grad_norm": 0.396484375,
2219
+ "learning_rate": 2.396304393593351e-05,
2220
+ "loss": 0.793,
2221
+ "step": 3160
2222
+ },
2223
+ {
2224
+ "epoch": 1.18,
2225
+ "grad_norm": 0.423828125,
2226
+ "learning_rate": 2.37917703273899e-05,
2227
+ "loss": 0.7768,
2228
+ "step": 3170
2229
+ },
2230
+ {
2231
+ "epoch": 1.18,
2232
+ "grad_norm": 0.431640625,
2233
+ "learning_rate": 2.362055354221241e-05,
2234
+ "loss": 0.778,
2235
+ "step": 3180
2236
+ },
2237
+ {
2238
+ "epoch": 1.18,
2239
+ "grad_norm": 0.4140625,
2240
+ "learning_rate": 2.3449401632772445e-05,
2241
+ "loss": 0.8069,
2242
+ "step": 3190
2243
+ },
2244
+ {
2245
+ "epoch": 1.19,
2246
+ "grad_norm": 0.423828125,
2247
+ "learning_rate": 2.3278322648390298e-05,
2248
+ "loss": 0.7816,
2249
+ "step": 3200
2250
+ },
2251
+ {
2252
+ "epoch": 1.19,
2253
+ "grad_norm": 0.4453125,
2254
+ "learning_rate": 2.3107324634956552e-05,
2255
+ "loss": 0.7878,
2256
+ "step": 3210
2257
+ },
2258
+ {
2259
+ "epoch": 1.19,
2260
+ "grad_norm": 0.42578125,
2261
+ "learning_rate": 2.2936415634553727e-05,
2262
+ "loss": 0.8075,
2263
+ "step": 3220
2264
+ },
2265
+ {
2266
+ "epoch": 1.2,
2267
+ "grad_norm": 0.4296875,
2268
+ "learning_rate": 2.276560368507803e-05,
2269
+ "loss": 0.7748,
2270
+ "step": 3230
2271
+ },
2272
+ {
2273
+ "epoch": 1.2,
2274
+ "grad_norm": 0.435546875,
2275
+ "learning_rate": 2.2594896819861345e-05,
2276
+ "loss": 0.7655,
2277
+ "step": 3240
2278
+ },
2279
+ {
2280
+ "epoch": 1.21,
2281
+ "grad_norm": 0.41796875,
2282
+ "learning_rate": 2.2424303067293396e-05,
2283
+ "loss": 0.7799,
2284
+ "step": 3250
2285
+ },
2286
+ {
2287
+ "epoch": 1.21,
2288
+ "grad_norm": 0.439453125,
2289
+ "learning_rate": 2.2253830450444202e-05,
2290
+ "loss": 0.7805,
2291
+ "step": 3260
2292
+ },
2293
+ {
2294
+ "epoch": 1.21,
2295
+ "grad_norm": 0.4453125,
2296
+ "learning_rate": 2.208348698668674e-05,
2297
+ "loss": 0.7737,
2298
+ "step": 3270
2299
+ },
2300
+ {
2301
+ "epoch": 1.22,
2302
+ "grad_norm": 0.431640625,
2303
+ "learning_rate": 2.191328068731987e-05,
2304
+ "loss": 0.816,
2305
+ "step": 3280
2306
+ },
2307
+ {
2308
+ "epoch": 1.22,
2309
+ "grad_norm": 0.408203125,
2310
+ "learning_rate": 2.1743219557191585e-05,
2311
+ "loss": 0.7772,
2312
+ "step": 3290
2313
+ },
2314
+ {
2315
+ "epoch": 1.22,
2316
+ "grad_norm": 0.400390625,
2317
+ "learning_rate": 2.157331159432253e-05,
2318
+ "loss": 0.7636,
2319
+ "step": 3300
2320
+ },
2321
+ {
2322
+ "epoch": 1.23,
2323
+ "grad_norm": 0.408203125,
2324
+ "learning_rate": 2.1403564789529833e-05,
2325
+ "loss": 0.7981,
2326
+ "step": 3310
2327
+ },
2328
+ {
2329
+ "epoch": 1.23,
2330
+ "grad_norm": 0.3671875,
2331
+ "learning_rate": 2.123398712605134e-05,
2332
+ "loss": 0.7901,
2333
+ "step": 3320
2334
+ },
2335
+ {
2336
+ "epoch": 1.24,
2337
+ "grad_norm": 0.40234375,
2338
+ "learning_rate": 2.1064586579170124e-05,
2339
+ "loss": 0.7919,
2340
+ "step": 3330
2341
+ },
2342
+ {
2343
+ "epoch": 1.24,
2344
+ "grad_norm": 0.41796875,
2345
+ "learning_rate": 2.0895371115839413e-05,
2346
+ "loss": 0.7885,
2347
+ "step": 3340
2348
+ },
2349
+ {
2350
+ "epoch": 1.24,
2351
+ "grad_norm": 0.45703125,
2352
+ "learning_rate": 2.0726348694307916e-05,
2353
+ "loss": 0.7947,
2354
+ "step": 3350
2355
+ },
2356
+ {
2357
+ "epoch": 1.25,
2358
+ "grad_norm": 0.412109375,
2359
+ "learning_rate": 2.0557527263745522e-05,
2360
+ "loss": 0.8202,
2361
+ "step": 3360
2362
+ },
2363
+ {
2364
+ "epoch": 1.25,
2365
+ "grad_norm": 0.419921875,
2366
+ "learning_rate": 2.038891476386948e-05,
2367
+ "loss": 0.8103,
2368
+ "step": 3370
2369
+ },
2370
+ {
2371
+ "epoch": 1.25,
2372
+ "grad_norm": 0.423828125,
2373
+ "learning_rate": 2.0220519124570946e-05,
2374
+ "loss": 0.7949,
2375
+ "step": 3380
2376
+ },
2377
+ {
2378
+ "epoch": 1.26,
2379
+ "grad_norm": 0.42578125,
2380
+ "learning_rate": 2.0052348265542087e-05,
2381
+ "loss": 0.7849,
2382
+ "step": 3390
2383
+ },
2384
+ {
2385
+ "epoch": 1.26,
2386
+ "grad_norm": 0.3828125,
2387
+ "learning_rate": 1.9884410095903587e-05,
2388
+ "loss": 0.7817,
2389
+ "step": 3400
2390
+ },
2391
+ {
2392
+ "epoch": 1.27,
2393
+ "grad_norm": 0.39453125,
2394
+ "learning_rate": 1.971671251383268e-05,
2395
+ "loss": 0.8121,
2396
+ "step": 3410
2397
+ },
2398
+ {
2399
+ "epoch": 1.27,
2400
+ "grad_norm": 0.4140625,
2401
+ "learning_rate": 1.9549263406191707e-05,
2402
+ "loss": 0.787,
2403
+ "step": 3420
2404
+ },
2405
+ {
2406
+ "epoch": 1.27,
2407
+ "grad_norm": 0.42578125,
2408
+ "learning_rate": 1.9382070648157187e-05,
2409
+ "loss": 0.7708,
2410
+ "step": 3430
2411
+ },
2412
+ {
2413
+ "epoch": 1.28,
2414
+ "grad_norm": 0.44140625,
2415
+ "learning_rate": 1.921514210284945e-05,
2416
+ "loss": 0.779,
2417
+ "step": 3440
2418
+ },
2419
+ {
2420
+ "epoch": 1.28,
2421
+ "grad_norm": 0.423828125,
2422
+ "learning_rate": 1.9048485620962833e-05,
2423
+ "loss": 0.7638,
2424
+ "step": 3450
2425
+ },
2426
+ {
2427
+ "epoch": 1.28,
2428
+ "grad_norm": 0.431640625,
2429
+ "learning_rate": 1.8882109040396456e-05,
2430
+ "loss": 0.7859,
2431
+ "step": 3460
2432
+ },
2433
+ {
2434
+ "epoch": 1.29,
2435
+ "grad_norm": 0.41015625,
2436
+ "learning_rate": 1.8716020185885598e-05,
2437
+ "loss": 0.7698,
2438
+ "step": 3470
2439
+ },
2440
+ {
2441
+ "epoch": 1.29,
2442
+ "grad_norm": 0.37890625,
2443
+ "learning_rate": 1.855022686863372e-05,
2444
+ "loss": 0.7937,
2445
+ "step": 3480
2446
+ },
2447
+ {
2448
+ "epoch": 1.29,
2449
+ "grad_norm": 0.39453125,
2450
+ "learning_rate": 1.838473688594506e-05,
2451
+ "loss": 0.7875,
2452
+ "step": 3490
2453
+ },
2454
+ {
2455
+ "epoch": 1.3,
2456
+ "grad_norm": 0.416015625,
2457
+ "learning_rate": 1.821955802085798e-05,
2458
+ "loss": 0.8009,
2459
+ "step": 3500
2460
+ },
2461
+ {
2462
+ "epoch": 1.3,
2463
+ "grad_norm": 0.404296875,
2464
+ "learning_rate": 1.8054698041778877e-05,
2465
+ "loss": 0.7664,
2466
+ "step": 3510
2467
+ },
2468
+ {
2469
+ "epoch": 1.31,
2470
+ "grad_norm": 0.3828125,
2471
+ "learning_rate": 1.7890164702116867e-05,
2472
+ "loss": 0.7846,
2473
+ "step": 3520
2474
+ },
2475
+ {
2476
+ "epoch": 1.31,
2477
+ "grad_norm": 0.435546875,
2478
+ "learning_rate": 1.7725965739919113e-05,
2479
+ "loss": 0.7939,
2480
+ "step": 3530
2481
+ },
2482
+ {
2483
+ "epoch": 1.31,
2484
+ "grad_norm": 0.39453125,
2485
+ "learning_rate": 1.756210887750692e-05,
2486
+ "loss": 0.7927,
2487
+ "step": 3540
2488
+ },
2489
+ {
2490
+ "epoch": 1.32,
2491
+ "grad_norm": 0.4140625,
2492
+ "learning_rate": 1.7398601821112552e-05,
2493
+ "loss": 0.8056,
2494
+ "step": 3550
2495
+ },
2496
+ {
2497
+ "epoch": 1.32,
2498
+ "grad_norm": 0.447265625,
2499
+ "learning_rate": 1.7235452260516804e-05,
2500
+ "loss": 0.8037,
2501
+ "step": 3560
2502
+ },
2503
+ {
2504
+ "epoch": 1.32,
2505
+ "grad_norm": 0.41796875,
2506
+ "learning_rate": 1.7072667868687348e-05,
2507
+ "loss": 0.7432,
2508
+ "step": 3570
2509
+ },
2510
+ {
2511
+ "epoch": 1.33,
2512
+ "grad_norm": 0.421875,
2513
+ "learning_rate": 1.6910256301417856e-05,
2514
+ "loss": 0.7778,
2515
+ "step": 3580
2516
+ },
2517
+ {
2518
+ "epoch": 1.33,
2519
+ "grad_norm": 0.369140625,
2520
+ "learning_rate": 1.6748225196967983e-05,
2521
+ "loss": 0.7727,
2522
+ "step": 3590
2523
+ },
2524
+ {
2525
+ "epoch": 1.34,
2526
+ "grad_norm": 0.41015625,
2527
+ "learning_rate": 1.6586582175704092e-05,
2528
+ "loss": 0.7997,
2529
+ "step": 3600
2530
+ },
2531
+ {
2532
+ "epoch": 1.34,
2533
+ "grad_norm": 0.4375,
2534
+ "learning_rate": 1.6425334839740915e-05,
2535
+ "loss": 0.7967,
2536
+ "step": 3610
2537
+ },
2538
+ {
2539
+ "epoch": 1.34,
2540
+ "grad_norm": 0.3984375,
2541
+ "learning_rate": 1.6264490772583985e-05,
2542
+ "loss": 0.8328,
2543
+ "step": 3620
2544
+ },
2545
+ {
2546
+ "epoch": 1.35,
2547
+ "grad_norm": 0.42578125,
2548
+ "learning_rate": 1.6104057538772975e-05,
2549
+ "loss": 0.8032,
2550
+ "step": 3630
2551
+ },
2552
+ {
2553
+ "epoch": 1.35,
2554
+ "grad_norm": 0.416015625,
2555
+ "learning_rate": 1.594404268352599e-05,
2556
+ "loss": 0.7699,
2557
+ "step": 3640
2558
+ },
2559
+ {
2560
+ "epoch": 1.35,
2561
+ "grad_norm": 0.369140625,
2562
+ "learning_rate": 1.5784453732384652e-05,
2563
+ "loss": 0.8065,
2564
+ "step": 3650
2565
+ },
2566
+ {
2567
+ "epoch": 1.36,
2568
+ "grad_norm": 0.42578125,
2569
+ "learning_rate": 1.562529819086023e-05,
2570
+ "loss": 0.7946,
2571
+ "step": 3660
2572
+ },
2573
+ {
2574
+ "epoch": 1.36,
2575
+ "grad_norm": 0.423828125,
2576
+ "learning_rate": 1.5466583544080587e-05,
2577
+ "loss": 0.7898,
2578
+ "step": 3670
2579
+ },
2580
+ {
2581
+ "epoch": 1.37,
2582
+ "grad_norm": 0.49609375,
2583
+ "learning_rate": 1.5308317256438205e-05,
2584
+ "loss": 0.7733,
2585
+ "step": 3680
2586
+ },
2587
+ {
2588
+ "epoch": 1.37,
2589
+ "grad_norm": 0.48046875,
2590
+ "learning_rate": 1.5150506771239114e-05,
2591
+ "loss": 0.7995,
2592
+ "step": 3690
2593
+ },
2594
+ {
2595
+ "epoch": 1.37,
2596
+ "grad_norm": 0.423828125,
2597
+ "learning_rate": 1.4993159510352836e-05,
2598
+ "loss": 0.7843,
2599
+ "step": 3700
2600
+ },
2601
+ {
2602
+ "epoch": 1.38,
2603
+ "grad_norm": 0.41796875,
2604
+ "learning_rate": 1.4836282873863319e-05,
2605
+ "loss": 0.7567,
2606
+ "step": 3710
2607
+ },
2608
+ {
2609
+ "epoch": 1.38,
2610
+ "grad_norm": 0.427734375,
2611
+ "learning_rate": 1.4679884239720928e-05,
2612
+ "loss": 0.7699,
2613
+ "step": 3720
2614
+ },
2615
+ {
2616
+ "epoch": 1.38,
2617
+ "grad_norm": 0.421875,
2618
+ "learning_rate": 1.452397096339545e-05,
2619
+ "loss": 0.7625,
2620
+ "step": 3730
2621
+ },
2622
+ {
2623
+ "epoch": 1.39,
2624
+ "grad_norm": 0.447265625,
2625
+ "learning_rate": 1.436855037753016e-05,
2626
+ "loss": 0.764,
2627
+ "step": 3740
2628
+ },
2629
+ {
2630
+ "epoch": 1.39,
2631
+ "grad_norm": 0.46875,
2632
+ "learning_rate": 1.421362979159695e-05,
2633
+ "loss": 0.7931,
2634
+ "step": 3750
2635
+ },
2636
+ {
2637
+ "epoch": 1.39,
2638
+ "grad_norm": 0.44921875,
2639
+ "learning_rate": 1.4059216491552621e-05,
2640
+ "loss": 0.7986,
2641
+ "step": 3760
2642
+ },
2643
+ {
2644
+ "epoch": 1.4,
2645
+ "grad_norm": 0.423828125,
2646
+ "learning_rate": 1.3905317739496143e-05,
2647
+ "loss": 0.791,
2648
+ "step": 3770
2649
+ },
2650
+ {
2651
+ "epoch": 1.4,
2652
+ "grad_norm": 0.4375,
2653
+ "learning_rate": 1.3751940773327194e-05,
2654
+ "loss": 0.7896,
2655
+ "step": 3780
2656
+ },
2657
+ {
2658
+ "epoch": 1.41,
2659
+ "grad_norm": 0.439453125,
2660
+ "learning_rate": 1.3599092806405677e-05,
2661
+ "loss": 0.77,
2662
+ "step": 3790
2663
+ },
2664
+ {
2665
+ "epoch": 1.41,
2666
+ "grad_norm": 0.404296875,
2667
+ "learning_rate": 1.3446781027212563e-05,
2668
+ "loss": 0.8162,
2669
+ "step": 3800
2670
+ },
2671
+ {
2672
+ "epoch": 1.41,
2673
+ "grad_norm": 0.431640625,
2674
+ "learning_rate": 1.329501259901173e-05,
2675
+ "loss": 0.7702,
2676
+ "step": 3810
2677
+ },
2678
+ {
2679
+ "epoch": 1.42,
2680
+ "grad_norm": 0.435546875,
2681
+ "learning_rate": 1.3143794659513153e-05,
2682
+ "loss": 0.7743,
2683
+ "step": 3820
2684
+ },
2685
+ {
2686
+ "epoch": 1.42,
2687
+ "grad_norm": 0.43359375,
2688
+ "learning_rate": 1.299313432053713e-05,
2689
+ "loss": 0.7876,
2690
+ "step": 3830
2691
+ },
2692
+ {
2693
+ "epoch": 1.42,
2694
+ "grad_norm": 0.44140625,
2695
+ "learning_rate": 1.2843038667679905e-05,
2696
+ "loss": 0.7682,
2697
+ "step": 3840
2698
+ },
2699
+ {
2700
+ "epoch": 1.43,
2701
+ "grad_norm": 0.431640625,
2702
+ "learning_rate": 1.2693514759980345e-05,
2703
+ "loss": 0.7882,
2704
+ "step": 3850
2705
+ },
2706
+ {
2707
+ "epoch": 1.43,
2708
+ "grad_norm": 0.435546875,
2709
+ "learning_rate": 1.2544569629587996e-05,
2710
+ "loss": 0.7782,
2711
+ "step": 3860
2712
+ },
2713
+ {
2714
+ "epoch": 1.44,
2715
+ "grad_norm": 0.4296875,
2716
+ "learning_rate": 1.2396210281432374e-05,
2717
+ "loss": 0.8012,
2718
+ "step": 3870
2719
+ },
2720
+ {
2721
+ "epoch": 1.44,
2722
+ "grad_norm": 0.447265625,
2723
+ "learning_rate": 1.2248443692893463e-05,
2724
+ "loss": 0.8027,
2725
+ "step": 3880
2726
+ },
2727
+ {
2728
+ "epoch": 1.44,
2729
+ "grad_norm": 0.42578125,
2730
+ "learning_rate": 1.2101276813473642e-05,
2731
+ "loss": 0.7991,
2732
+ "step": 3890
2733
+ },
2734
+ {
2735
+ "epoch": 1.45,
2736
+ "grad_norm": 0.458984375,
2737
+ "learning_rate": 1.1954716564470772e-05,
2738
+ "loss": 0.784,
2739
+ "step": 3900
2740
+ },
2741
+ {
2742
+ "epoch": 1.45,
2743
+ "grad_norm": 0.388671875,
2744
+ "learning_rate": 1.1808769838652755e-05,
2745
+ "loss": 0.7678,
2746
+ "step": 3910
2747
+ },
2748
+ {
2749
+ "epoch": 1.45,
2750
+ "grad_norm": 0.4140625,
2751
+ "learning_rate": 1.1663443499933303e-05,
2752
+ "loss": 0.8044,
2753
+ "step": 3920
2754
+ },
2755
+ {
2756
+ "epoch": 1.46,
2757
+ "grad_norm": 0.43359375,
2758
+ "learning_rate": 1.1518744383049187e-05,
2759
+ "loss": 0.7707,
2760
+ "step": 3930
2761
+ },
2762
+ {
2763
+ "epoch": 1.46,
2764
+ "grad_norm": 0.421875,
2765
+ "learning_rate": 1.1374679293238733e-05,
2766
+ "loss": 0.7842,
2767
+ "step": 3940
2768
+ },
2769
+ {
2770
+ "epoch": 1.47,
2771
+ "grad_norm": 0.4453125,
2772
+ "learning_rate": 1.1231255005921845e-05,
2773
+ "loss": 0.7971,
2774
+ "step": 3950
2775
+ },
2776
+ {
2777
+ "epoch": 1.47,
2778
+ "grad_norm": 0.388671875,
2779
+ "learning_rate": 1.1088478266381258e-05,
2780
+ "loss": 0.7996,
2781
+ "step": 3960
2782
+ },
2783
+ {
2784
+ "epoch": 1.47,
2785
+ "grad_norm": 0.423828125,
2786
+ "learning_rate": 1.094635578944541e-05,
2787
+ "loss": 0.7945,
2788
+ "step": 3970
2789
+ },
2790
+ {
2791
+ "epoch": 1.48,
2792
+ "grad_norm": 0.421875,
2793
+ "learning_rate": 1.0804894259172579e-05,
2794
+ "loss": 0.8138,
2795
+ "step": 3980
2796
+ },
2797
+ {
2798
+ "epoch": 1.48,
2799
+ "grad_norm": 0.427734375,
2800
+ "learning_rate": 1.0664100328536525e-05,
2801
+ "loss": 0.8029,
2802
+ "step": 3990
2803
+ },
2804
+ {
2805
+ "epoch": 1.48,
2806
+ "grad_norm": 0.412109375,
2807
+ "learning_rate": 1.0523980619113655e-05,
2808
+ "loss": 0.8133,
2809
+ "step": 4000
2810
+ }
2811
+ ],
2812
+ "logging_steps": 10,
2813
+ "max_steps": 5390,
2814
+ "num_input_tokens_seen": 0,
2815
+ "num_train_epochs": 2,
2816
+ "save_steps": 200,
2817
+ "total_flos": 4.738673495402086e+19,
2818
+ "train_batch_size": 2,
2819
+ "trial_name": null,
2820
+ "trial_params": null
2821
+ }
training_args.bin ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:a7a679998340bfc147dea361d69c35dae027c71bfd6ee3a5e8a4f777e6456595
3
+ size 4920
vision_tower_builder.py ADDED
@@ -0,0 +1,632 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from typing import Optional, Tuple, Union, Dict
2
+ from dataclasses import dataclass
3
+ from functools import partial, reduce
4
+ from PIL import Image
5
+ import os
6
+ from transformers.image_processing_utils import BatchFeature, get_size_dict
7
+ from transformers.image_transforms import (
8
+ convert_to_rgb,
9
+ normalize,
10
+ rescale,
11
+ resize,
12
+ to_channel_dimension_format,
13
+ )
14
+ from transformers.image_utils import (
15
+ ChannelDimension,
16
+ PILImageResampling,
17
+ to_numpy_array,
18
+ )
19
+ import numpy as np
20
+ import torch
21
+ import torch.nn as nn
22
+ import torch.nn.functional as F
23
+ import torch.utils.checkpoint as checkpoint
24
+ from functools import partial
25
+ try:
26
+ from flash_attn import flash_attn_qkvpacked_func
27
+ use_flash_attn = True
28
+ except:
29
+ use_flash_attn = False
30
+ print("You need to install flash_attn to be faster!")
31
+
32
+ try:
33
+ from timm.layers import drop_path, to_2tuple, trunc_normal_
34
+ except:
35
+ from timm.models.layers import drop_path, trunc_normal_, to_2tuple
36
+
37
+
38
+
39
+ class DropPath(nn.Module):
40
+ """Drop paths (Stochastic Depth) per sample (when applied in main path of residual blocks).
41
+ """
42
+ def __init__(self, drop_prob=None):
43
+ super(DropPath, self).__init__()
44
+ self.drop_prob = drop_prob
45
+
46
+ def forward(self, x):
47
+ return drop_path(x, self.drop_prob, self.training)
48
+
49
+ def extra_repr(self) -> str:
50
+ return 'p={}'.format(self.drop_prob)
51
+
52
+
53
+ class Mlp(nn.Module):
54
+ def __init__(self, in_features, hidden_features=None, out_features=None, act_layer=nn.GELU, drop=0.):
55
+ super().__init__()
56
+ out_features = out_features or in_features
57
+ hidden_features = hidden_features or in_features
58
+ self.fc1 = nn.Linear(in_features, hidden_features)
59
+ self.act = act_layer()
60
+ self.fc2 = nn.Linear(hidden_features, out_features)
61
+ self.drop = nn.Dropout(drop)
62
+
63
+ def forward(self, x):
64
+ x = self.fc1(x)
65
+ x = self.act(x)
66
+ x = self.drop(x)
67
+ x = self.fc2(x)
68
+ x = self.drop(x)
69
+ return x
70
+
71
+ class Attention(nn.Module):
72
+ def __init__(
73
+ self, dim, num_heads=8, qkv_bias=False, qk_scale=None, attn_drop=0.,
74
+ proj_drop=0., attn_head_dim=None,
75
+ attn_type='flash_v2'):
76
+
77
+ if use_flash_attn:
78
+ attn_type = attn_type
79
+ else:
80
+ attn_type = 'origin'
81
+
82
+ print(attn_type)
83
+
84
+ super().__init__()
85
+ self.num_heads = num_heads
86
+ head_dim = dim // num_heads
87
+ if attn_head_dim is not None:
88
+ head_dim = attn_head_dim
89
+ all_head_dim = head_dim * self.num_heads
90
+ self.scale = qk_scale or head_dim ** -0.5
91
+
92
+ self.qkv = nn.Linear(dim, all_head_dim * 3, bias=False)
93
+ if qkv_bias:
94
+ self.q_bias = nn.Parameter(torch.zeros(all_head_dim))
95
+ self.v_bias = nn.Parameter(torch.zeros(all_head_dim))
96
+ else:
97
+ self.q_bias = None
98
+ self.v_bias = None
99
+
100
+ if attn_type not in ['origin', 'flash_v2']:
101
+ raise NotImplementedError(f"Not support attn_type: {attn_type}")
102
+
103
+ # print('umt:', f'attn_type: {attn_type}')
104
+
105
+ self.attn_type = attn_type
106
+ if attn_type == 'flash_v2':
107
+ self.attn_drop = attn_drop
108
+ else:
109
+ self.attn_drop = nn.Dropout(attn_drop)
110
+ self.proj = nn.Linear(all_head_dim, dim)
111
+ self.proj_drop = nn.Dropout(proj_drop)
112
+
113
+ def forward(self, x):
114
+ B, N, C = x.shape
115
+ qkv_bias = None
116
+ if self.q_bias is not None:
117
+ qkv_bias = torch.cat((self.q_bias, torch.zeros_like(self.v_bias, requires_grad=False), self.v_bias))
118
+ # qkv = self.qkv(x).reshape(B, N, 3, self.num_heads, C // self.num_heads).permute(2, 0, 3, 1, 4)
119
+ qkv = F.linear(input=x, weight=self.qkv.weight, bias=qkv_bias)
120
+
121
+ if self.attn_type == 'flash_v2':
122
+ qkv = qkv.reshape(B, N, 3, self.num_heads, -1)
123
+ x = flash_attn_qkvpacked_func(qkv, dropout_p=self.attn_drop, softmax_scale=self.scale, causal=False).reshape(B, N, -1)
124
+ else:
125
+ qkv = qkv.reshape(B, N, 3, self.num_heads, -1).permute(2, 0, 3, 1, 4)
126
+ q, k, v = qkv[0], qkv[1], qkv[
127
+ 2] # make torchscript happy (cannot use tensor as tuple)
128
+ # B num_heads N head_dim
129
+
130
+ q = q * self.scale
131
+ attn = (q @ k.transpose(-2, -1))
132
+
133
+ attn = attn.softmax(dim=-1)
134
+ attn = self.attn_drop(attn)
135
+
136
+ x = (attn @ v).transpose(1, 2).reshape(B, N, -1)
137
+
138
+ x = self.proj(x)
139
+ x = self.proj_drop(x)
140
+ return x
141
+
142
+
143
+
144
+
145
+ class Block(nn.Module):
146
+ def __init__(self, dim, num_heads, mlp_ratio=4., qkv_bias=False, qk_scale=None, drop=0., attn_drop=0.,
147
+ drop_path=0., init_values=None, act_layer=nn.GELU, norm_layer=nn.LayerNorm,
148
+ attn_head_dim=None):
149
+ super().__init__()
150
+ self.norm1 = norm_layer(dim)
151
+ self.attn = Attention(
152
+ dim, num_heads=num_heads, qkv_bias=qkv_bias, qk_scale=qk_scale,
153
+ attn_drop=attn_drop, proj_drop=drop, attn_head_dim=attn_head_dim)
154
+ # NOTE: drop path for stochastic depth, we shall see if this is better than dropout here
155
+ self.drop_path = DropPath(drop_path) if drop_path > 0. else nn.Identity()
156
+ self.norm2 = norm_layer(dim)
157
+ mlp_hidden_dim = int(dim * mlp_ratio)
158
+ self.mlp = Mlp(in_features=dim, hidden_features=mlp_hidden_dim, act_layer=act_layer, drop=drop)
159
+
160
+ if init_values > 0:
161
+ self.gamma_1 = nn.Parameter(init_values * torch.ones((dim)),requires_grad=True)
162
+ self.gamma_2 = nn.Parameter(init_values * torch.ones((dim)),requires_grad=True)
163
+ else:
164
+ self.gamma_1, self.gamma_2 = None, None
165
+
166
+ def forward(self, x):
167
+ if self.gamma_1 is None:
168
+ x = x + self.drop_path(self.attn(self.norm1(x)))
169
+ x = x + self.drop_path(self.mlp(self.norm2(x)))
170
+ else:
171
+ x = x + self.drop_path(self.gamma_1 * self.attn(self.norm1(x)))
172
+ x = x + self.drop_path(self.gamma_2 * self.mlp(self.norm2(x)))
173
+ return x
174
+
175
+
176
+ class PatchEmbed(nn.Module):
177
+ """ Image to Patch Embedding
178
+ """
179
+ def __init__(self, img_size=224, patch_size=16, in_chans=3, embed_dim=768, num_frames=16, tubelet_size=2):
180
+ super().__init__()
181
+ img_size = to_2tuple(img_size)
182
+ patch_size = to_2tuple(patch_size)
183
+ self.tubelet_size = int(tubelet_size)
184
+ num_patches = (img_size[1] // patch_size[1]) * (img_size[0] // patch_size[0]) * (num_frames // self.tubelet_size)
185
+ self.img_size = img_size
186
+ self.patch_size = patch_size
187
+ self.num_patches = num_patches
188
+ self.proj = nn.Conv3d(
189
+ in_channels=in_chans, out_channels=embed_dim,
190
+ kernel_size=(self.tubelet_size, patch_size[0], patch_size[1]),
191
+ stride=(self.tubelet_size, patch_size[0], patch_size[1])
192
+ )
193
+ # print('umt:', f'Num of patches: {num_patches}')
194
+
195
+ def forward(self, x, **kwargs):
196
+ B, C, T, H, W = x.shape
197
+ # FIXME look at relaxing size constraints
198
+ # assert H == self.img_size[0] and W == self.img_size[1], \
199
+ # f"Input image size ({H}*{W}) doesn't match model ({self.img_size[0]}*{self.img_size[1]})."
200
+ x = self.proj(x).flatten(2).transpose(1, 2)
201
+ return x
202
+
203
+ # sin-cos position encoding
204
+ # https://github.com/jadore801120/attention-is-all-you-need-pytorch/blob/master/transformer/Models.py#L31
205
+ def get_sinusoid_encoding_table(n_position, d_hid, ckpt_num_frame=-1, cur_frame=12):
206
+ ''' Sinusoid position encoding table '''
207
+ # TODO: make it with torch instead of numpy
208
+ def get_position_angle_vec(position):
209
+ return [position / np.power(10000, 2 * (hid_j // 2) / d_hid) for hid_j in range(d_hid)]
210
+
211
+ if ckpt_num_frame != -1 and ckpt_num_frame != cur_frame:
212
+ # print('umt:', f"Interpolate position embedding")
213
+ # print('umt:', f"Testing frame: {cur_frame}")
214
+ # print('umt:', f"Checkpoint frame: {ckpt_num_frame}")
215
+
216
+ T = ckpt_num_frame # checkpoint frame
217
+ new_T = cur_frame # testing frame
218
+ n_position = n_position // new_T * T # generate checkpoint position embedding
219
+ sinusoid_table = np.array([get_position_angle_vec(pos_i) for pos_i in range(n_position)])
220
+ sinusoid_table[:, 0::2] = np.sin(sinusoid_table[:, 0::2]) # dim 2i
221
+ sinusoid_table[:, 1::2] = np.cos(sinusoid_table[:, 1::2]) # dim 2i+1
222
+ sinusoid_table = torch.tensor(sinusoid_table, dtype=torch.float, requires_grad=False).unsqueeze(0)
223
+ # interpolate
224
+ P = int((n_position // T) ** 0.5)
225
+ C = d_hid
226
+ sinusoid_table = sinusoid_table.reshape(-1, T, P, P, C)
227
+ sinusoid_table = sinusoid_table.permute(0, 2, 3, 4, 1).reshape(-1, C, T) # BHW, C, T
228
+ sinusoid_table = torch.nn.functional.interpolate(sinusoid_table, size=new_T, mode='linear')
229
+ sinusoid_table = sinusoid_table.reshape(1, P, P, C, new_T).permute(0, 4, 1, 2, 3) # B, T, H, W, C
230
+ sinusoid_table = sinusoid_table.flatten(1, 3)
231
+ return sinusoid_table
232
+ else:
233
+ sinusoid_table = np.array([get_position_angle_vec(pos_i) for pos_i in range(n_position)])
234
+ sinusoid_table[:, 0::2] = np.sin(sinusoid_table[:, 0::2]) # dim 2i
235
+ sinusoid_table[:, 1::2] = np.cos(sinusoid_table[:, 1::2]) # dim 2i+1
236
+ return torch.tensor(sinusoid_table, dtype=torch.float, requires_grad=False).unsqueeze(0)
237
+
238
+
239
+ def get_sinusoid_encoding_table2(n_position=784, d_hid=1024, cur_frame=8, ckpt_num_frame=4, pre_n_position=784):
240
+ ''' Sinusoid position encoding table '''
241
+ # TODO: make it with torch instead of numpy
242
+ def get_position_angle_vec(position):
243
+ return [position / np.power(10000, 2 * (hid_j // 2) / d_hid) for hid_j in range(d_hid)]
244
+
245
+ # generate checkpoint position embedding
246
+ sinusoid_table = np.array([get_position_angle_vec(pos_i) for pos_i in range(pre_n_position)])
247
+ sinusoid_table[:, 0::2] = np.sin(sinusoid_table[:, 0::2]) # dim 2i
248
+ sinusoid_table[:, 1::2] = np.cos(sinusoid_table[:, 1::2]) # dim 2i+1
249
+ sinusoid_table = torch.tensor(sinusoid_table, dtype=torch.float, requires_grad=False).unsqueeze(0)
250
+
251
+ # print(f"n_position: {n_position}")
252
+ # print(f"pre_n_position: {pre_n_position}")
253
+
254
+ if n_position != pre_n_position:
255
+ T = ckpt_num_frame # checkpoint frame
256
+ P = 14 # checkpoint size
257
+ C = d_hid
258
+ new_P = int((n_position // cur_frame) ** 0.5) # testing size
259
+ # print(f'Pretraining uses 14x14, but current version is {new_P}x{new_P}')
260
+ # print(f'Interpolate the position embedding')
261
+ sinusoid_table = sinusoid_table.reshape(-1, T, P, P, C)
262
+ sinusoid_table = sinusoid_table.reshape(-1, P, P, C).permute(0, 3, 1, 2)
263
+ sinusoid_table = torch.nn.functional.interpolate(
264
+ sinusoid_table, size=(new_P, new_P), mode='bicubic', align_corners=False)
265
+ # BT, C, H, W -> BT, H, W, C -> B, T, H, W, C
266
+ sinusoid_table = sinusoid_table.permute(0, 2, 3, 1).reshape(-1, T, new_P, new_P, C)
267
+ sinusoid_table = sinusoid_table.flatten(1, 3) # B, THW, C
268
+
269
+ if cur_frame != ckpt_num_frame:
270
+ # print(f'Pretraining uses 4 frames, but current frame is {cur_frame}')
271
+ # print(f'Interpolate the position embedding')
272
+ T = ckpt_num_frame # checkpoint frame
273
+ new_T = cur_frame # testing frame
274
+ # interpolate
275
+ P = int((n_position // cur_frame) ** 0.5) # testing size
276
+ C = d_hid
277
+ sinusoid_table = sinusoid_table.reshape(-1, T, P, P, C)
278
+ sinusoid_table = sinusoid_table.permute(0, 2, 3, 4, 1).reshape(-1, C, T) # BHW, C, T
279
+ sinusoid_table = torch.nn.functional.interpolate(sinusoid_table, size=new_T, mode='linear')
280
+ sinusoid_table = sinusoid_table.reshape(1, P, P, C, new_T).permute(0, 4, 1, 2, 3) # B, T, H, W, C
281
+ sinusoid_table = sinusoid_table.flatten(1, 3) # B, THW, C
282
+
283
+ return sinusoid_table
284
+
285
+
286
+ class PretrainVisionTransformerEncoder(nn.Module):
287
+ """ Vision Transformer with support for patch or hybrid CNN input stage
288
+ """
289
+ def __init__(self, img_size=224, patch_size=16, in_chans=3, embed_dim=768, depth=12,
290
+ num_heads=12, mlp_ratio=4., qkv_bias=False, qk_scale=None, drop_rate=0., attn_drop_rate=0.,
291
+ drop_path_rate=0., norm_layer=nn.LayerNorm, init_values=None, num_frames=8, tubelet_size=1,
292
+ use_learnable_pos_emb=False,
293
+ use_checkpoint=False, checkpoint_num=0,
294
+ ckpt_num_frame=-1, with_ln=True, return_index=-1
295
+ ):
296
+ super().__init__()
297
+ self.num_features = self.embed_dim = embed_dim # num_features for consistency with other models
298
+ self.patch_embed = PatchEmbed(
299
+ img_size=img_size, patch_size=patch_size, in_chans=in_chans, embed_dim=embed_dim,
300
+ num_frames=num_frames, tubelet_size=tubelet_size
301
+ )
302
+ num_patches = self.patch_embed.num_patches
303
+ self.depth = depth + return_index + 1
304
+ self.use_checkpoint = use_checkpoint
305
+ self.checkpoint_num = checkpoint_num
306
+ # print('umt:', f"Use checkpoint: {use_checkpoint}")
307
+ # print('umt:', f"Checkpoint number: {checkpoint_num}")
308
+ # print('UMT:', f"Real runing depth: {self.depth}")
309
+
310
+ # TODO: Add the cls token
311
+ if use_learnable_pos_emb:
312
+ self.pos_embed = nn.Parameter(torch.zeros(1, num_patches + 1, embed_dim))
313
+ self.img_pos_embed = nn.Parameter(torch.zeros(1, num_patches//(num_frames//tubelet_size) + 1, embed_dim))
314
+ else:
315
+ # sine-cosine positional embeddings
316
+ if img_size != 224:
317
+ self.pos_embed = get_sinusoid_encoding_table2(num_patches, embed_dim, ckpt_num_frame=ckpt_num_frame, cur_frame=num_frames//tubelet_size)
318
+ self.img_pos_embed = get_sinusoid_encoding_table2(num_patches//(num_frames//tubelet_size), embed_dim, cur_frame=1, ckpt_num_frame=1, pre_n_position=14*14)
319
+ else:
320
+ self.pos_embed = get_sinusoid_encoding_table(num_patches, embed_dim, ckpt_num_frame=ckpt_num_frame, cur_frame=num_frames//tubelet_size)
321
+ self.img_pos_embed = get_sinusoid_encoding_table(num_patches//(num_frames//tubelet_size), embed_dim)
322
+
323
+ dpr = [x.item() for x in torch.linspace(0, drop_path_rate, depth)] # stochastic depth decay rule
324
+ self.blocks = nn.ModuleList([
325
+ Block(
326
+ dim=embed_dim, num_heads=num_heads, mlp_ratio=mlp_ratio, qkv_bias=qkv_bias, qk_scale=qk_scale,
327
+ drop=drop_rate, attn_drop=attn_drop_rate, drop_path=dpr[i], norm_layer=norm_layer,
328
+ init_values=init_values)
329
+ for i in range(self.depth)])
330
+
331
+ if with_ln:
332
+ self.vision_layernorm = nn.LayerNorm(embed_dim, eps=1e-12)
333
+ else:
334
+ self.vision_layernorm = nn.Identity()
335
+
336
+ if use_learnable_pos_emb:
337
+ trunc_normal_(self.pos_embed, std=.02)
338
+
339
+ @torch.jit.ignore
340
+ def no_weight_decay(self):
341
+ return {'pos_embed', 'cls_token'}
342
+
343
+ def forward_features(self, x, use_image=False):
344
+ x = self.patch_embed(x)
345
+
346
+ if use_image:
347
+ x = x + self.img_pos_embed.type_as(x).to(x.device).clone().detach()
348
+ else:
349
+ x = x + self.pos_embed.type_as(x).to(x.device).clone().detach()
350
+
351
+ B, _, C = x.shape
352
+ x_vis = x
353
+
354
+ for idx, blk in enumerate(self.blocks):
355
+ if self.use_checkpoint and idx < self.checkpoint_num:
356
+ x_vis = checkpoint.checkpoint(blk, x_vis)
357
+ else:
358
+ x_vis = blk(x_vis)
359
+
360
+ # with ln ot not
361
+ x_vis = self.vision_layernorm(x_vis)
362
+ return x_vis
363
+
364
+ def forward(self, x, use_image=False):
365
+ x_vis = self.forward_features(x, use_image)
366
+ return x_vis
367
+
368
+
369
+ class PretrainVisionTransformer(nn.Module):
370
+ """ Vision Transformer with support for patch or hybrid CNN input stage
371
+ """
372
+ def __init__(self,
373
+ img_size=224,
374
+ patch_size=16,
375
+ encoder_in_chans=3,
376
+ encoder_embed_dim=768,
377
+ encoder_depth=12,
378
+ encoder_num_heads=12,
379
+ mlp_ratio=4.,
380
+ qkv_bias=True,
381
+ qk_scale=None,
382
+ drop_rate=0.,
383
+ attn_drop_rate=0.,
384
+ drop_path_rate=0.,
385
+ norm_layer=partial(nn.LayerNorm, eps=1e-6),
386
+ init_values=0.,
387
+ use_learnable_pos_emb=False,
388
+ num_frames=8,
389
+ tubelet_size=1,
390
+ use_checkpoint=False,
391
+ checkpoint_num=0,
392
+ ckpt_num_frame=4, # the pretrained model uses 4 frames
393
+ return_index=-1,
394
+ with_ln=False
395
+ ):
396
+ super().__init__()
397
+
398
+ self.encoder = PretrainVisionTransformerEncoder(
399
+ img_size=img_size,
400
+ patch_size=patch_size,
401
+ in_chans=encoder_in_chans,
402
+ embed_dim=encoder_embed_dim,
403
+ depth=encoder_depth,
404
+ num_heads=encoder_num_heads,
405
+ mlp_ratio=mlp_ratio,
406
+ qkv_bias=qkv_bias,
407
+ qk_scale=qk_scale,
408
+ drop_rate=drop_rate,
409
+ attn_drop_rate=attn_drop_rate,
410
+ drop_path_rate=drop_path_rate,
411
+ norm_layer=norm_layer,
412
+ init_values=init_values,
413
+ num_frames=num_frames,
414
+ tubelet_size=tubelet_size,
415
+ use_learnable_pos_emb=use_learnable_pos_emb,
416
+ use_checkpoint=use_checkpoint,
417
+ checkpoint_num=checkpoint_num,
418
+ ckpt_num_frame=ckpt_num_frame,
419
+ with_ln=with_ln,
420
+ return_index=return_index
421
+ )
422
+ # print('umt:', f'With LN: {with_ln}')
423
+ # print('UMT:', f'Total {encoder_depth} layer')
424
+ # print('UMT:', f'Return {encoder_depth+return_index+1}-th layer')
425
+
426
+ self.apply(self._init_weights)
427
+
428
+ def _init_weights(self, m):
429
+ if isinstance(m, nn.Linear):
430
+ nn.init.xavier_uniform_(m.weight)
431
+ if isinstance(m, nn.Linear) and m.bias is not None:
432
+ nn.init.constant_(m.bias, 0)
433
+ elif isinstance(m, nn.LayerNorm):
434
+ nn.init.constant_(m.bias, 0)
435
+ nn.init.constant_(m.weight, 1.0)
436
+
437
+ @torch.jit.ignore
438
+ def no_weight_decay(self):
439
+ return {'pos_embed', 'cls_token', 'clip_pos_embed'}
440
+
441
+ def forward(self, x, use_image=False):
442
+ T = x.shape[2]
443
+ x_vis = self.encoder(x, use_image) # [B, N_vis, C_e]
444
+ B, TL, C = x_vis.shape
445
+ x_vis = x_vis.view(B, T, TL // T, C)
446
+
447
+ return x_vis
448
+
449
+
450
+
451
+
452
+
453
+
454
+
455
+ class UMTImageProcessor:
456
+ def __init__(self, image_mean=(0.485, 0.456, 0.406), image_std=(0.229, 0.224, 0.225), size=(224, 224), crop_size: Dict[str, int] = None, resample=PILImageResampling.BICUBIC, rescale_factor=1 / 255, data_format=ChannelDimension.FIRST):
457
+ crop_size = crop_size if crop_size is not None else {"height": 224, "width": 224}
458
+ crop_size = get_size_dict(crop_size, default_to_square=True, param_name="crop_size")
459
+
460
+ self.image_mean = image_mean
461
+ self.image_std = image_std
462
+ self.size = size
463
+ self.resample = resample
464
+ self.rescale_factor = rescale_factor
465
+ self.data_format = data_format
466
+ self.crop_size = crop_size
467
+
468
+ def preprocess(self, images, return_tensors, target_size=None):
469
+ if isinstance(images, Image.Image):
470
+ images = [images]
471
+ else:
472
+ # to adapt video data
473
+ images = [to_numpy_array(image) for image in images]
474
+ assert isinstance(images, list)
475
+
476
+ if target_size is None:
477
+ target_size = self.size
478
+
479
+ transforms = [
480
+ convert_to_rgb,
481
+ to_numpy_array,
482
+ partial(resize, size=target_size, resample=self.resample, data_format=self.data_format),
483
+ partial(rescale, scale=self.rescale_factor, data_format=self.data_format),
484
+ partial(normalize, mean=self.image_mean, std=self.image_std, data_format=self.data_format),
485
+ partial(to_channel_dimension_format, channel_dim=self.data_format, input_channel_dim=self.data_format),
486
+ ]
487
+
488
+ images = reduce(lambda x, f: [*map(f, x)], transforms, images)
489
+ data = {"pixel_values": images}
490
+
491
+ return BatchFeature(data=data, tensor_type=return_tensors)
492
+
493
+
494
+ class UMTVisionConfig:
495
+ model_type = "umt_vision_model"
496
+
497
+ def __init__(
498
+ self,
499
+ num_frames=4,
500
+ hidden_size=1024,
501
+ num_hidden_layers=24,
502
+ num_attention_heads=16,
503
+ num_channels=3,
504
+ image_size=224,
505
+ patch_size=16,
506
+ return_idx=-2
507
+ # **kwargs,
508
+ ):
509
+ # super().__init__(**kwargs)
510
+ self.num_frames = num_frames
511
+ self.hidden_size = hidden_size
512
+ self.num_hidden_layers = num_hidden_layers
513
+ self.num_attention_heads = num_attention_heads
514
+ self.num_channels = num_channels
515
+ self.patch_size = patch_size
516
+ self.image_size = image_size
517
+ self.return_idx = return_idx
518
+
519
+
520
+ def build_vit(config, pt_type='origin'):
521
+ model = PretrainVisionTransformer(
522
+ img_size=config.image_size,
523
+ patch_size=16,
524
+ encoder_embed_dim=1024,
525
+ encoder_depth=24,
526
+ encoder_num_heads=16,
527
+ drop_path_rate=0.,
528
+ num_frames=config.num_frames,
529
+ tubelet_size=1,
530
+ use_checkpoint=False,
531
+ checkpoint_num=24,
532
+ return_index=config.return_idx,
533
+ with_ln=True, # merge vision_layernorm in it
534
+ )
535
+
536
+ # no need to load pt
537
+
538
+ return model
539
+
540
+
541
+
542
+ class UMTVisionTower(nn.Module):
543
+ def __init__(self, vision_tower, vision_tower_cfg, delay_load=False, pt_type='origin', image_size=224):
544
+ super().__init__()
545
+
546
+ self.is_loaded = False
547
+ self.pt_type = pt_type
548
+
549
+ self.config = UMTVisionConfig(num_frames=vision_tower_cfg.mm_local_num_frames, return_idx=vision_tower_cfg.mm_vision_select_layer, image_size=image_size)
550
+
551
+ self.vision_tower_name = vision_tower
552
+
553
+ self.image_processor = UMTImageProcessor(size=(image_size, image_size))
554
+
555
+ if not delay_load:
556
+ print(f"Loading vision tower: {vision_tower}")
557
+ self.load_model()
558
+ elif getattr(vision_tower_cfg, "unfreeze_mm_vision_tower", False):
559
+ # TODO: better detector is needed.
560
+ print(f"The checkpoint seems to contain `vision_tower` weights: `unfreeze_mm_vision_tower`: True.")
561
+ self.load_model()
562
+ elif hasattr(vision_tower_cfg, "mm_tunable_parts") and "mm_vision_tower" in vision_tower_cfg.mm_tunable_parts:
563
+ print(f"The checkpoint seems to contain `vision_tower` weights: `mm_tunable_parts` contains `mm_vision_tower`.")
564
+ self.load_model()
565
+ else:
566
+ self.cfg_only = self.config
567
+
568
+ def load_model(self, device_map=None):
569
+ if self.is_loaded:
570
+ print("{} is already loaded, `load_model` called again, skipping.".format(self.vision_tower_name))
571
+ return
572
+
573
+ self.vision_tower = build_vit(self.config, pt_type=self.pt_type)
574
+ self.vision_tower.requires_grad_(False)
575
+
576
+ self.is_loaded = True
577
+
578
+ def forward(self, images):
579
+ if type(images) is list:
580
+ raise NotImplementedError
581
+ else:
582
+ # input: B T C H W
583
+ # output: B T*L C
584
+ T = images.shape[1]
585
+ images = images.permute(0, 2, 1, 3, 4)
586
+ image_embeds = self.vision_tower(images, use_image=(T == 1))
587
+ B, T, L, C = image_embeds.shape
588
+ image_embeds = image_embeds.reshape(B, -1, C)
589
+
590
+ return image_embeds
591
+
592
+ @property
593
+ def dummy_feature(self):
594
+ return torch.zeros(1, self.hidden_size, device=self.device, dtype=self.dtype)
595
+
596
+ @property
597
+ def dtype(self):
598
+ for p in self.vision_tower.parameters():
599
+ return p.dtype
600
+
601
+ @property
602
+ def device(self):
603
+ for p in self.vision_tower.parameters():
604
+ return p.device
605
+
606
+ @property
607
+ def hidden_size(self):
608
+ return self.config.hidden_size
609
+
610
+ @property
611
+ def num_patches(self):
612
+ return (self.config.image_size // self.config.patch_size) ** 2
613
+
614
+ @property
615
+ def num_patches_per_side(self):
616
+ return self.config.image_size // self.config.patch_size
617
+
618
+ @property
619
+ def image_size(self):
620
+ return self.config.image_size
621
+
622
+
623
+ def build_vision_tower(vision_tower_cfg, **kwargs):
624
+ vision_tower = getattr(vision_tower_cfg, "mm_vision_tower", getattr(vision_tower_cfg, "vision_tower", None))
625
+
626
+
627
+ if "umt-hd" in vision_tower:
628
+ return UMTVisionTower(vision_tower, vision_tower_cfg=vision_tower_cfg, image_size=448, **kwargs)
629
+ elif "umt" in vision_tower:
630
+ return UMTVisionTower(vision_tower, vision_tower_cfg=vision_tower_cfg, **kwargs)
631
+
632
+ raise ValueError(f"Unknown vision tower: {vision_tower}")
vocab.json ADDED
The diff for this file is too large to render. See raw diff