Upload folder using huggingface_hub
Browse files- .gitattributes +1 -0
- added_tokens.json +24 -0
- attention_mask.py +81 -0
- aux_vision.py +102 -0
- chat_template.json +3 -0
- config.json +54 -0
- configuration_vora.py +38 -0
- generation_config.json +14 -0
- global_step30000/bf16_zero_pp_rank_0_mp_rank_00_optim_states.pt +3 -0
- global_step30000/mp_rank_00_model_states.pt +3 -0
- latest +1 -0
- lora.py +104 -0
- merges.txt +0 -0
- model-00001-of-00004.safetensors +3 -0
- model-00002-of-00004.safetensors +3 -0
- model-00003-of-00004.safetensors +3 -0
- model-00004-of-00004.safetensors +3 -0
- model.safetensors.index.json +626 -0
- modeling_vora.py +289 -0
- preprocessor_config.json +19 -0
- processing_vora.py +150 -0
- processor_config.json +6 -0
- rng_state.pth +3 -0
- scheduler.pt +3 -0
- special_tokens_map.json +31 -0
- tokenizer.json +3 -0
- tokenizer_config.json +209 -0
- trainer_state.json +0 -0
- training_args.bin +3 -0
- vision_embedding.py +70 -0
- vocab.json +0 -0
- vora_generation_utils.py +101 -0
- zero_to_fp32.py +760 -0
.gitattributes
CHANGED
|
@@ -33,3 +33,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
| 33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
| 33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
| 36 |
+
tokenizer.json filter=lfs diff=lfs merge=lfs -text
|
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 |
+
}
|
attention_mask.py
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from typing import Optional
|
| 2 |
+
|
| 3 |
+
import torch
|
| 4 |
+
|
| 5 |
+
|
| 6 |
+
def _make_causal_mask(
|
| 7 |
+
attention_mask: torch.Tensor, dtype: torch.dtype, device: torch.device
|
| 8 |
+
):
|
| 9 |
+
"""
|
| 10 |
+
Make causal mask used for bi-directional self-attention.
|
| 11 |
+
"""
|
| 12 |
+
bsz, tgt_len = attention_mask.shape
|
| 13 |
+
mask = torch.full((tgt_len, tgt_len), torch.tensor(torch.finfo(dtype).min, device=device), device=device)
|
| 14 |
+
mask_cond = torch.arange(mask.size(-1), device=device)
|
| 15 |
+
mask.masked_fill_(mask_cond < (mask_cond + 1).view(mask.size(-1), 1), 0)
|
| 16 |
+
mask = mask.to(dtype)
|
| 17 |
+
|
| 18 |
+
return mask[None, None, :, :].expand(bsz, 1, tgt_len, tgt_len)
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
def _make_2dvison_mask(column_mask, dtype: torch.dtype, device: torch.device):
|
| 22 |
+
"""
|
| 23 |
+
"""
|
| 24 |
+
bsz, seq_length = column_mask.shape
|
| 25 |
+
cross_mask = torch.zeros((bsz, 1, seq_length, seq_length), dtype=dtype, device=device)
|
| 26 |
+
|
| 27 |
+
# 找到连续的 1 的区间
|
| 28 |
+
start = None
|
| 29 |
+
for bsz_idx in range(bsz):
|
| 30 |
+
for i in range(seq_length):
|
| 31 |
+
if column_mask[bsz_idx, i] == 1:
|
| 32 |
+
if start is None:
|
| 33 |
+
start = i
|
| 34 |
+
else:
|
| 35 |
+
if start is not None:
|
| 36 |
+
# 填充区间
|
| 37 |
+
cross_mask[bsz_idx, 0, start:i, start:i] = 1
|
| 38 |
+
start = None
|
| 39 |
+
|
| 40 |
+
# 处理最后一个区间
|
| 41 |
+
if start is not None:
|
| 42 |
+
cross_mask[bsz_idx, 0, start:seq_length, start:seq_length] = 1
|
| 43 |
+
|
| 44 |
+
return cross_mask
|
| 45 |
+
|
| 46 |
+
|
| 47 |
+
def _expand_mask(mask: torch.Tensor, dtype: torch.dtype, tgt_len: Optional[int] = None):
|
| 48 |
+
"""
|
| 49 |
+
Expands attention_mask from `[bsz, seq_len]` to `[bsz, 1, tgt_seq_len, src_seq_len]`.
|
| 50 |
+
"""
|
| 51 |
+
bsz, src_len = mask.size()
|
| 52 |
+
tgt_len = tgt_len if tgt_len is not None else src_len
|
| 53 |
+
|
| 54 |
+
expanded_mask = mask[:, None, None, :].expand(bsz, 1, tgt_len, src_len).to(dtype)
|
| 55 |
+
|
| 56 |
+
inverted_mask = 1.0 - expanded_mask
|
| 57 |
+
|
| 58 |
+
return inverted_mask.masked_fill_(inverted_mask.to(torch.bool), torch.finfo(dtype).min)
|
| 59 |
+
|
| 60 |
+
|
| 61 |
+
def make_mask(attention_mask: torch.Tensor, dtype: torch.dtype=None, device: torch.device=None, mode: str="default", vision_mask: torch.Tensor=None, ):
|
| 62 |
+
if dtype is None:
|
| 63 |
+
dtype = attention_mask.dtype
|
| 64 |
+
if device is None:
|
| 65 |
+
device = attention_mask.device
|
| 66 |
+
expanded_attn_mask = _expand_mask(attention_mask, dtype).to(device)
|
| 67 |
+
causal_mask = _make_causal_mask(attention_mask, dtype, device).to(device)
|
| 68 |
+
if mode == "default":
|
| 69 |
+
return attention_mask
|
| 70 |
+
else:
|
| 71 |
+
assert vision_mask is not None, "vision_mask is None"
|
| 72 |
+
vision_mask = vision_mask.to(device)
|
| 73 |
+
bsz, seq_length = attention_mask.shape
|
| 74 |
+
vision_mask_bg = vision_mask[:, None, :, None]
|
| 75 |
+
vision_mask_2d = _make_2dvison_mask(vision_mask, dtype, device)
|
| 76 |
+
if mode == "bidirectional":
|
| 77 |
+
mask = expanded_attn_mask + causal_mask
|
| 78 |
+
mask = mask.clone().masked_fill_(vision_mask_2d.to(torch.bool), 0)
|
| 79 |
+
return mask
|
| 80 |
+
else:
|
| 81 |
+
raise NotImplementedError(f"mode {mode} is not implemented")
|
aux_vision.py
ADDED
|
@@ -0,0 +1,102 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import torch
|
| 2 |
+
import torch.nn as nn
|
| 3 |
+
from transformers import CLIPVisionModel, AutoModel
|
| 4 |
+
|
| 5 |
+
from .configuration_vora import VoRAConfig
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
class RMSNorm(nn.Module):
|
| 9 |
+
def __init__(self, dim: int, eps: float = 1e-5):
|
| 10 |
+
super().__init__()
|
| 11 |
+
self.weight = nn.Parameter(torch.ones(dim))
|
| 12 |
+
self.eps = eps
|
| 13 |
+
|
| 14 |
+
def forward(self, x: torch.Tensor) -> torch.Tensor:
|
| 15 |
+
output = self._norm(x.float()).type_as(x)
|
| 16 |
+
return output * self.weight
|
| 17 |
+
|
| 18 |
+
def extra_repr(self) -> str:
|
| 19 |
+
return f"{tuple(self.weight.shape)}, eps={self.eps}"
|
| 20 |
+
|
| 21 |
+
def _norm(self, x: torch.Tensor) -> torch.Tensor:
|
| 22 |
+
return x * torch.rsqrt(x.pow(2).mean(-1, keepdim=True) + self.eps)
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
class CosineLoss(nn.Module):
|
| 26 |
+
def __init__(self, reduction='mean'):
|
| 27 |
+
super(CosineLoss, self).__init__()
|
| 28 |
+
self.reduction = reduction
|
| 29 |
+
|
| 30 |
+
@staticmethod
|
| 31 |
+
def interpolate_tokens_2d(self, teacher_tokens, target_size):
|
| 32 |
+
"""
|
| 33 |
+
Interpolate teacher tokens to the target size using bilinear interpolation.
|
| 34 |
+
"""
|
| 35 |
+
# teacher_tokens shape is (batch_size, height, width, feature_dim)
|
| 36 |
+
teacher_tokens = teacher_tokens.permute(0, 3, 1, 2) # Convert to (batch_size, feature_dim, height, width)
|
| 37 |
+
interpolated = torch.nn.functional.interpolate(teacher_tokens, size=target_size, mode='bilinear', align_corners=True).flatten(2) # Flatten height and width dimensions
|
| 38 |
+
return interpolated.permute(0, 2, 1) # Convert back to (batch_size, new_height * new_width, feature_dim)
|
| 39 |
+
|
| 40 |
+
def forward(self, input: torch.Tensor, target: torch.Tensor, input_shape=None, target_shape=None) -> torch.Tensor:
|
| 41 |
+
if input_shape is not None and target_shape is not None:
|
| 42 |
+
input = input.reshape((input.shape[0], ) + input_shape + (-1, ))
|
| 43 |
+
input = self.interpolate_tokens_2d(input, target_shape)
|
| 44 |
+
|
| 45 |
+
cos_sim = nn.functional.cosine_similarity(input, target, dim=1)
|
| 46 |
+
loss = 1 - cos_sim
|
| 47 |
+
|
| 48 |
+
if self.reduction == 'mean':
|
| 49 |
+
return loss.mean()
|
| 50 |
+
elif self.reduction == 'sum':
|
| 51 |
+
return loss.sum()
|
| 52 |
+
else:
|
| 53 |
+
return loss
|
| 54 |
+
|
| 55 |
+
|
| 56 |
+
class AuxVision(nn.Module):
|
| 57 |
+
def __init__(self,
|
| 58 |
+
config: VoRAConfig = None,
|
| 59 |
+
):
|
| 60 |
+
super().__init__()
|
| 61 |
+
self.skip_aux_cls = config.skip_aux_cls # whether to skip the cls token in ViT
|
| 62 |
+
# ---------------- Setup Aux Model ----------------
|
| 63 |
+
if 'clip' in config.aux_vision.lower():
|
| 64 |
+
self.aux_model = CLIPVisionModel.from_pretrained(config.aux_vision)
|
| 65 |
+
vision_hidden_size = self.aux_model.vision_model.config.hidden_size
|
| 66 |
+
num_hidden_layers = self.aux_model.vision_model.config.num_hidden_layers
|
| 67 |
+
else:
|
| 68 |
+
self.aux_model = AutoModel.from_pretrained(config.aux_vision, trust_remote_code=True)
|
| 69 |
+
vision_hidden_size = self.aux_model.config.hidden_size
|
| 70 |
+
num_hidden_layers = self.aux_model.config.num_hidden_layers
|
| 71 |
+
for name, param in self.aux_model.named_parameters():
|
| 72 |
+
param.requires_grad = False
|
| 73 |
+
# -------------------------------------------------
|
| 74 |
+
|
| 75 |
+
# ---------------- Setup Aux Heads ----------------
|
| 76 |
+
self.aux_layers = list(range(num_hidden_layers))
|
| 77 |
+
for layer_id in self.aux_layers:
|
| 78 |
+
self.add_module(f"aux_layer_{layer_id}", self.build_aux_layer(config.hidden_size, vision_hidden_size))
|
| 79 |
+
# -------------------------------------------------
|
| 80 |
+
|
| 81 |
+
self.loss_function = CosineLoss()
|
| 82 |
+
self.loss_keys = [f"loss_aux_layer_{layer_id}" for layer_id in self.aux_layers]
|
| 83 |
+
|
| 84 |
+
def build_aux_layer(self, llm_hidden_size, vit_hidden_size):
|
| 85 |
+
return nn.Sequential(
|
| 86 |
+
RMSNorm(llm_hidden_size),
|
| 87 |
+
nn.Linear(
|
| 88 |
+
llm_hidden_size,
|
| 89 |
+
vit_hidden_size,
|
| 90 |
+
bias=False,
|
| 91 |
+
)
|
| 92 |
+
)
|
| 93 |
+
|
| 94 |
+
def forward(self, frames, llm_hidden_states, vision_mask):
|
| 95 |
+
vision_hidden_states = self.aux_model(frames, output_hidden_states=True).hidden_states
|
| 96 |
+
losses = {}
|
| 97 |
+
for layer_idx in self.aux_layers:
|
| 98 |
+
aux_hidden_states = getattr(self, f"aux_layer_{layer_idx}")(llm_hidden_states[layer_idx][vision_mask == 1])
|
| 99 |
+
start_id = 1 if self.skip_aux_cls else 0
|
| 100 |
+
aux_loss = self.loss_function(vision_hidden_states[layer_idx][:, start_id:].reshape(aux_hidden_states.shape), aux_hidden_states)
|
| 101 |
+
losses[f"loss_aux_layer_{layer_idx}"] = aux_loss
|
| 102 |
+
return losses
|
chat_template.json
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"chat_template": "{% set image_count = namespace(value=0) %}{% set video_count = namespace(value=0) %}{% for message in messages %}{% if loop.first and message['role'] != 'system' %}<|im_start|>system\nYou are a helpful assistant.<|im_end|>\n{% endif %}<|im_start|>{{ message['role'] }}\n{% if message['content'] is string %}{{ message['content'] }}<|im_end|>\n{% else %}{% set text_string = namespace(value='') %}{% for content in message['content'] %}{% if 'text' in content %}{% set text_string.value = content['text'] %}{% endif %}{% endfor %}{% for content in message['content'] %}{% if content['type'] == 'image' or 'image' in content or 'image_url' in content %}{% set image_count.value = image_count.value + 1 %}{% if add_vision_id %}Picture {{ image_count.value }}: {% endif %}{% if '<image>' not in text_string.value %}<image>{% endif %}{% elif content['type'] == 'video' or 'video' in content %}{% set video_count.value = video_count.value + 1 %}{% if add_vision_id %}Video {{ video_count.value }}: {% endif %}<|vision_start|><|video_pad|><|vision_end|>{% elif 'text' in content %}{{ content['text'] }}{% endif %}{% endfor %}<|im_end|>\n{% endif %}{% endfor %}{% if add_generation_prompt %}<|im_start|>assistant\n{% endif %}"
|
| 3 |
+
}
|
config.json
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"architectures": [
|
| 3 |
+
"VoRAForCausalLM"
|
| 4 |
+
],
|
| 5 |
+
"attention_dropout": 0.0,
|
| 6 |
+
"auto_map": {
|
| 7 |
+
"AutoConfig": "configuration_vora.VoRAConfig",
|
| 8 |
+
"AutoModelForCausalLM": "modeling_vora.VoRAForCausalLM"
|
| 9 |
+
},
|
| 10 |
+
"aux_vision": "apple/aimv2-huge-patch14-448",
|
| 11 |
+
"bos_token_id": 151643,
|
| 12 |
+
"eos_token_id": 151645,
|
| 13 |
+
"hidden_act": "silu",
|
| 14 |
+
"hidden_size": 3584,
|
| 15 |
+
"image_size": 448,
|
| 16 |
+
"initializer_range": 0.02,
|
| 17 |
+
"intermediate_size": 18944,
|
| 18 |
+
"llm": "Qwen/Qwen2.5-7B-Instruct",
|
| 19 |
+
"lora": {
|
| 20 |
+
"layers": 3,
|
| 21 |
+
"r": 128,
|
| 22 |
+
"target_modules": [
|
| 23 |
+
"self_attn.q_proj",
|
| 24 |
+
"self_attn.k_proj",
|
| 25 |
+
"self_attn.v_proj",
|
| 26 |
+
"self_attn.o_proj",
|
| 27 |
+
"mlp.up_proj",
|
| 28 |
+
"mlp.gate_proj",
|
| 29 |
+
"mlp.down_proj"
|
| 30 |
+
]
|
| 31 |
+
},
|
| 32 |
+
"max_position_embeddings": 32768,
|
| 33 |
+
"max_window_layers": 28,
|
| 34 |
+
"model_type": "vora",
|
| 35 |
+
"num_attention_heads": 28,
|
| 36 |
+
"num_hidden_layers": 28,
|
| 37 |
+
"num_key_value_heads": 4,
|
| 38 |
+
"patch_size": 14,
|
| 39 |
+
"reuse_aux_vision_embedding_layers": "preprocessor",
|
| 40 |
+
"rms_norm_eps": 1e-06,
|
| 41 |
+
"rope_scaling": null,
|
| 42 |
+
"rope_theta": 1000000.0,
|
| 43 |
+
"skip_aux_cls": false,
|
| 44 |
+
"sliding_window": 131072,
|
| 45 |
+
"tie_word_embeddings": false,
|
| 46 |
+
"torch_dtype": "bfloat16",
|
| 47 |
+
"transformers_version": "4.50.3",
|
| 48 |
+
"use_cache": true,
|
| 49 |
+
"use_sliding_window": false,
|
| 50 |
+
"vision_attention_mask": "bidirectional",
|
| 51 |
+
"vision_embedding": "AIMv2Embedding",
|
| 52 |
+
"vision_embedding_intermediate_size": 1536,
|
| 53 |
+
"vocab_size": 152064
|
| 54 |
+
}
|
configuration_vora.py
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from typing import Any
|
| 2 |
+
|
| 3 |
+
from transformers.configuration_utils import PretrainedConfig
|
| 4 |
+
|
| 5 |
+
__all__ = ["VoRAConfig"]
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
class VoRAConfig(PretrainedConfig):
|
| 9 |
+
model_type = "vora"
|
| 10 |
+
_auto_class = "AutoConfig"
|
| 11 |
+
|
| 12 |
+
def __init__(
|
| 13 |
+
self,
|
| 14 |
+
llm: str = "",
|
| 15 |
+
aux_vision: str = "",
|
| 16 |
+
skip_aux_cls: bool = False,
|
| 17 |
+
reuse_aux_vision_embedding_layers: str = "",
|
| 18 |
+
lora: dict = {},
|
| 19 |
+
image_size: int = 448,
|
| 20 |
+
vision_embedding: str = "AIMv2",
|
| 21 |
+
vision_embedding_intermediate_size: int = 1536,
|
| 22 |
+
patch_size: int = 14,
|
| 23 |
+
vision_attention_mask: str = "bidirectional",
|
| 24 |
+
rms_norm_eps: float = 1e-5,
|
| 25 |
+
**kwargs: Any,
|
| 26 |
+
):
|
| 27 |
+
super().__init__(**kwargs)
|
| 28 |
+
self.llm = llm
|
| 29 |
+
self.aux_vision = aux_vision
|
| 30 |
+
self.skip_aux_cls = skip_aux_cls
|
| 31 |
+
self.reuse_aux_vision_embedding_layers = reuse_aux_vision_embedding_layers
|
| 32 |
+
self.lora = lora
|
| 33 |
+
self.image_size = image_size
|
| 34 |
+
self.vision_embedding = vision_embedding
|
| 35 |
+
self.vision_embedding_intermediate_size = vision_embedding_intermediate_size
|
| 36 |
+
self.patch_size = patch_size
|
| 37 |
+
self.vision_attention_mask = vision_attention_mask
|
| 38 |
+
self.rms_norm_eps = rms_norm_eps
|
generation_config.json
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"bos_token_id": 151643,
|
| 3 |
+
"pad_token_id": 151643,
|
| 4 |
+
"do_sample": true,
|
| 5 |
+
"eos_token_id": [
|
| 6 |
+
151645,
|
| 7 |
+
151643
|
| 8 |
+
],
|
| 9 |
+
"repetition_penalty": 1.05,
|
| 10 |
+
"temperature": 0.7,
|
| 11 |
+
"top_p": 0.8,
|
| 12 |
+
"top_k": 20,
|
| 13 |
+
"transformers_version": "4.37.0"
|
| 14 |
+
}
|
global_step30000/bf16_zero_pp_rank_0_mp_rank_00_optim_states.pt
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:0b50d041c2ad4752e3d637685f5c1e4b7206bb2edb5996fe5b04f5902dbec3e0
|
| 3 |
+
size 2099159920
|
global_step30000/mp_rank_00_model_states.pt
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:ea146ae9efb83fcb6d95940e607356da519eed072e3278604bfe176e65775e34
|
| 3 |
+
size 33540906252
|
latest
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
global_step30000
|
lora.py
ADDED
|
@@ -0,0 +1,104 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import torch
|
| 2 |
+
import types
|
| 3 |
+
import math
|
| 4 |
+
from torch import nn
|
| 5 |
+
import torch.nn.functional as F
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
QWEN2_TARGET_MODULES = [
|
| 9 |
+
"self_attn.q_proj",
|
| 10 |
+
"self_attn.k_proj",
|
| 11 |
+
"self_attn.v_proj",
|
| 12 |
+
"self_attn.o_proj",
|
| 13 |
+
"mlp.up_proj",
|
| 14 |
+
"mlp.gate_proj",
|
| 15 |
+
"mlp.down_proj",
|
| 16 |
+
]
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
class LoRALayer(nn.Linear):
|
| 20 |
+
def __init__(
|
| 21 |
+
self,
|
| 22 |
+
in_features: int,
|
| 23 |
+
out_features: int,
|
| 24 |
+
r: int = 1024,
|
| 25 |
+
**kwargs
|
| 26 |
+
):
|
| 27 |
+
nn.Linear.__init__(self, in_features, out_features)
|
| 28 |
+
# we elimate lora_alpha here bc we find it unnecessary in VoRA
|
| 29 |
+
if r < 0:
|
| 30 |
+
self.forward = self.naive_forward
|
| 31 |
+
else:
|
| 32 |
+
self.lora_A = nn.Linear(in_features, r, bias=False)
|
| 33 |
+
self.lora_B = nn.Linear(r, out_features, bias=False)
|
| 34 |
+
nn.init.kaiming_uniform_(self.lora_A.weight, a=math.sqrt(5))
|
| 35 |
+
nn.init.zeros_(self.lora_B.weight)
|
| 36 |
+
|
| 37 |
+
def forward(self, x: torch.Tensor):
|
| 38 |
+
intermediate = F.linear(x, self.weight, bias=self.bias)
|
| 39 |
+
result = intermediate + self.lora_B(self.lora_A(x))
|
| 40 |
+
return result
|
| 41 |
+
|
| 42 |
+
def naive_forward(self, x: torch.Tensor):
|
| 43 |
+
return F.linear(x, self.weight, bias=self.bias)
|
| 44 |
+
|
| 45 |
+
|
| 46 |
+
def _get_submodules(self, key):
|
| 47 |
+
parent = self.get_submodule(".".join(key.split(".")[:-1]))
|
| 48 |
+
target_name = key.split(".")[-1]
|
| 49 |
+
target = self.get_submodule(key)
|
| 50 |
+
return parent, target, target_name
|
| 51 |
+
|
| 52 |
+
|
| 53 |
+
def _find_and_replace(self, lora_params):
|
| 54 |
+
target_modules = lora_params["target_modules"]
|
| 55 |
+
|
| 56 |
+
for llm_module_name in target_modules:
|
| 57 |
+
parent, target, target_name = self._get_submodules(llm_module_name)
|
| 58 |
+
bias = target.bias is not None
|
| 59 |
+
vora_layer = LoRALayer(
|
| 60 |
+
target.in_features,
|
| 61 |
+
target.out_features,
|
| 62 |
+
bias=bias,
|
| 63 |
+
**lora_params
|
| 64 |
+
)
|
| 65 |
+
self._replace_module(parent, target_name, vora_layer, target)
|
| 66 |
+
|
| 67 |
+
|
| 68 |
+
def _replace_module(self, parent_module, child_name, new_module, old_module):
|
| 69 |
+
setattr(parent_module, child_name, new_module)
|
| 70 |
+
new_module.weight = old_module.weight
|
| 71 |
+
if old_module.bias is not None:
|
| 72 |
+
new_module.bias = old_module.bias
|
| 73 |
+
if getattr(old_module, "state", None) is not None:
|
| 74 |
+
new_module.state = old_module.state
|
| 75 |
+
new_module.to(old_module.weight.device)
|
| 76 |
+
|
| 77 |
+
|
| 78 |
+
def apply_lora(llm, lora_params={"layers": "all", "r": 1024, "target_modules": QWEN2_TARGET_MODULES}):
|
| 79 |
+
llm_num_layers = llm.config.num_hidden_layers
|
| 80 |
+
total_layers = lora_params.get("layers", "all")
|
| 81 |
+
|
| 82 |
+
# -------------------- validation check ---------------------
|
| 83 |
+
if isinstance(total_layers, str):
|
| 84 |
+
if total_layers.lower() == "all":
|
| 85 |
+
total_layers = list(range(llm_num_layers))
|
| 86 |
+
else:
|
| 87 |
+
assert isinstance(total_layers, int), "total_layers must be an integer or 'all'"
|
| 88 |
+
total_layers = list(range(total_layers))
|
| 89 |
+
# -------------------- validation check ---------------------
|
| 90 |
+
|
| 91 |
+
# -------------------- replace llm layers ---------------------
|
| 92 |
+
for i in total_layers:
|
| 93 |
+
llm_layer = llm.model.layers[i]
|
| 94 |
+
llm_layer._get_submodules = types.MethodType(_get_submodules, llm_layer)
|
| 95 |
+
llm_layer._find_and_replace = types.MethodType(_find_and_replace, llm_layer)
|
| 96 |
+
llm_layer._replace_module = types.MethodType(_replace_module, llm_layer)
|
| 97 |
+
llm_layer._find_and_replace(lora_params)
|
| 98 |
+
|
| 99 |
+
|
| 100 |
+
if __name__ == "__main__":
|
| 101 |
+
from transformers import LlamaForCausalLM, CLIPVisionModel, AutoModel
|
| 102 |
+
llama = LlamaForCausalLM.from_pretrained("/mnt/bn/wh-data/data/models/llama2_7b_hf_chat")
|
| 103 |
+
apply_lora(llama)
|
| 104 |
+
print(llama)
|
merges.txt
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
model-00001-of-00004.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:6f4eed1c23cef08a6dfcceaea64c8e7368a8a16fe41fd738fb300b4e01af948c
|
| 3 |
+
size 4947144152
|
model-00002-of-00004.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:0d1f561f54d1540e99425dbbf3743697de31839e8f1ed474b58cb88571ac7aa4
|
| 3 |
+
size 4932751496
|
model-00003-of-00004.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:b00b0b5a2fad76fed51ce15c130eed90cd8f110bd4edfd110131880e7e32a539
|
| 3 |
+
size 4330865648
|
model-00004-of-00004.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:726a5e44beb2a17ee85a87ee0ea466b63197c399bc9171f08e67b921ffa36530
|
| 3 |
+
size 2734467176
|
model.safetensors.index.json
ADDED
|
@@ -0,0 +1,626 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"metadata": {
|
| 3 |
+
"total_size": 16945154048
|
| 4 |
+
},
|
| 5 |
+
"weight_map": {
|
| 6 |
+
"aux_vision.aux_layer_0.0.weight": "model-00004-of-00004.safetensors",
|
| 7 |
+
"aux_vision.aux_layer_0.1.weight": "model-00004-of-00004.safetensors",
|
| 8 |
+
"aux_vision.aux_layer_1.0.weight": "model-00004-of-00004.safetensors",
|
| 9 |
+
"aux_vision.aux_layer_1.1.weight": "model-00004-of-00004.safetensors",
|
| 10 |
+
"aux_vision.aux_layer_10.0.weight": "model-00004-of-00004.safetensors",
|
| 11 |
+
"aux_vision.aux_layer_10.1.weight": "model-00004-of-00004.safetensors",
|
| 12 |
+
"aux_vision.aux_layer_11.0.weight": "model-00004-of-00004.safetensors",
|
| 13 |
+
"aux_vision.aux_layer_11.1.weight": "model-00004-of-00004.safetensors",
|
| 14 |
+
"aux_vision.aux_layer_12.0.weight": "model-00004-of-00004.safetensors",
|
| 15 |
+
"aux_vision.aux_layer_12.1.weight": "model-00004-of-00004.safetensors",
|
| 16 |
+
"aux_vision.aux_layer_13.0.weight": "model-00004-of-00004.safetensors",
|
| 17 |
+
"aux_vision.aux_layer_13.1.weight": "model-00004-of-00004.safetensors",
|
| 18 |
+
"aux_vision.aux_layer_14.0.weight": "model-00004-of-00004.safetensors",
|
| 19 |
+
"aux_vision.aux_layer_14.1.weight": "model-00004-of-00004.safetensors",
|
| 20 |
+
"aux_vision.aux_layer_15.0.weight": "model-00004-of-00004.safetensors",
|
| 21 |
+
"aux_vision.aux_layer_15.1.weight": "model-00004-of-00004.safetensors",
|
| 22 |
+
"aux_vision.aux_layer_16.0.weight": "model-00004-of-00004.safetensors",
|
| 23 |
+
"aux_vision.aux_layer_16.1.weight": "model-00004-of-00004.safetensors",
|
| 24 |
+
"aux_vision.aux_layer_17.0.weight": "model-00004-of-00004.safetensors",
|
| 25 |
+
"aux_vision.aux_layer_17.1.weight": "model-00004-of-00004.safetensors",
|
| 26 |
+
"aux_vision.aux_layer_18.0.weight": "model-00004-of-00004.safetensors",
|
| 27 |
+
"aux_vision.aux_layer_18.1.weight": "model-00004-of-00004.safetensors",
|
| 28 |
+
"aux_vision.aux_layer_19.0.weight": "model-00004-of-00004.safetensors",
|
| 29 |
+
"aux_vision.aux_layer_19.1.weight": "model-00004-of-00004.safetensors",
|
| 30 |
+
"aux_vision.aux_layer_2.0.weight": "model-00004-of-00004.safetensors",
|
| 31 |
+
"aux_vision.aux_layer_2.1.weight": "model-00004-of-00004.safetensors",
|
| 32 |
+
"aux_vision.aux_layer_20.0.weight": "model-00004-of-00004.safetensors",
|
| 33 |
+
"aux_vision.aux_layer_20.1.weight": "model-00004-of-00004.safetensors",
|
| 34 |
+
"aux_vision.aux_layer_21.0.weight": "model-00004-of-00004.safetensors",
|
| 35 |
+
"aux_vision.aux_layer_21.1.weight": "model-00004-of-00004.safetensors",
|
| 36 |
+
"aux_vision.aux_layer_22.0.weight": "model-00004-of-00004.safetensors",
|
| 37 |
+
"aux_vision.aux_layer_22.1.weight": "model-00004-of-00004.safetensors",
|
| 38 |
+
"aux_vision.aux_layer_23.0.weight": "model-00004-of-00004.safetensors",
|
| 39 |
+
"aux_vision.aux_layer_23.1.weight": "model-00004-of-00004.safetensors",
|
| 40 |
+
"aux_vision.aux_layer_3.0.weight": "model-00004-of-00004.safetensors",
|
| 41 |
+
"aux_vision.aux_layer_3.1.weight": "model-00004-of-00004.safetensors",
|
| 42 |
+
"aux_vision.aux_layer_4.0.weight": "model-00004-of-00004.safetensors",
|
| 43 |
+
"aux_vision.aux_layer_4.1.weight": "model-00004-of-00004.safetensors",
|
| 44 |
+
"aux_vision.aux_layer_5.0.weight": "model-00004-of-00004.safetensors",
|
| 45 |
+
"aux_vision.aux_layer_5.1.weight": "model-00004-of-00004.safetensors",
|
| 46 |
+
"aux_vision.aux_layer_6.0.weight": "model-00004-of-00004.safetensors",
|
| 47 |
+
"aux_vision.aux_layer_6.1.weight": "model-00004-of-00004.safetensors",
|
| 48 |
+
"aux_vision.aux_layer_7.0.weight": "model-00004-of-00004.safetensors",
|
| 49 |
+
"aux_vision.aux_layer_7.1.weight": "model-00004-of-00004.safetensors",
|
| 50 |
+
"aux_vision.aux_layer_8.0.weight": "model-00004-of-00004.safetensors",
|
| 51 |
+
"aux_vision.aux_layer_8.1.weight": "model-00004-of-00004.safetensors",
|
| 52 |
+
"aux_vision.aux_layer_9.0.weight": "model-00004-of-00004.safetensors",
|
| 53 |
+
"aux_vision.aux_layer_9.1.weight": "model-00004-of-00004.safetensors",
|
| 54 |
+
"aux_vision.aux_model.preprocessor.patchifier.norm.weight": "model-00004-of-00004.safetensors",
|
| 55 |
+
"aux_vision.aux_model.preprocessor.patchifier.proj.bias": "model-00004-of-00004.safetensors",
|
| 56 |
+
"aux_vision.aux_model.preprocessor.patchifier.proj.weight": "model-00004-of-00004.safetensors",
|
| 57 |
+
"aux_vision.aux_model.preprocessor.pos_embed": "model-00004-of-00004.safetensors",
|
| 58 |
+
"aux_vision.aux_model.trunk.blocks.0.attn.proj.weight": "model-00004-of-00004.safetensors",
|
| 59 |
+
"aux_vision.aux_model.trunk.blocks.0.attn.qkv.weight": "model-00004-of-00004.safetensors",
|
| 60 |
+
"aux_vision.aux_model.trunk.blocks.0.mlp.fc1.weight": "model-00004-of-00004.safetensors",
|
| 61 |
+
"aux_vision.aux_model.trunk.blocks.0.mlp.fc2.weight": "model-00004-of-00004.safetensors",
|
| 62 |
+
"aux_vision.aux_model.trunk.blocks.0.mlp.fc3.weight": "model-00004-of-00004.safetensors",
|
| 63 |
+
"aux_vision.aux_model.trunk.blocks.0.norm_1.weight": "model-00004-of-00004.safetensors",
|
| 64 |
+
"aux_vision.aux_model.trunk.blocks.0.norm_2.weight": "model-00004-of-00004.safetensors",
|
| 65 |
+
"aux_vision.aux_model.trunk.blocks.1.attn.proj.weight": "model-00004-of-00004.safetensors",
|
| 66 |
+
"aux_vision.aux_model.trunk.blocks.1.attn.qkv.weight": "model-00004-of-00004.safetensors",
|
| 67 |
+
"aux_vision.aux_model.trunk.blocks.1.mlp.fc1.weight": "model-00004-of-00004.safetensors",
|
| 68 |
+
"aux_vision.aux_model.trunk.blocks.1.mlp.fc2.weight": "model-00004-of-00004.safetensors",
|
| 69 |
+
"aux_vision.aux_model.trunk.blocks.1.mlp.fc3.weight": "model-00004-of-00004.safetensors",
|
| 70 |
+
"aux_vision.aux_model.trunk.blocks.1.norm_1.weight": "model-00004-of-00004.safetensors",
|
| 71 |
+
"aux_vision.aux_model.trunk.blocks.1.norm_2.weight": "model-00004-of-00004.safetensors",
|
| 72 |
+
"aux_vision.aux_model.trunk.blocks.10.attn.proj.weight": "model-00004-of-00004.safetensors",
|
| 73 |
+
"aux_vision.aux_model.trunk.blocks.10.attn.qkv.weight": "model-00004-of-00004.safetensors",
|
| 74 |
+
"aux_vision.aux_model.trunk.blocks.10.mlp.fc1.weight": "model-00004-of-00004.safetensors",
|
| 75 |
+
"aux_vision.aux_model.trunk.blocks.10.mlp.fc2.weight": "model-00004-of-00004.safetensors",
|
| 76 |
+
"aux_vision.aux_model.trunk.blocks.10.mlp.fc3.weight": "model-00004-of-00004.safetensors",
|
| 77 |
+
"aux_vision.aux_model.trunk.blocks.10.norm_1.weight": "model-00004-of-00004.safetensors",
|
| 78 |
+
"aux_vision.aux_model.trunk.blocks.10.norm_2.weight": "model-00004-of-00004.safetensors",
|
| 79 |
+
"aux_vision.aux_model.trunk.blocks.11.attn.proj.weight": "model-00004-of-00004.safetensors",
|
| 80 |
+
"aux_vision.aux_model.trunk.blocks.11.attn.qkv.weight": "model-00004-of-00004.safetensors",
|
| 81 |
+
"aux_vision.aux_model.trunk.blocks.11.mlp.fc1.weight": "model-00004-of-00004.safetensors",
|
| 82 |
+
"aux_vision.aux_model.trunk.blocks.11.mlp.fc2.weight": "model-00004-of-00004.safetensors",
|
| 83 |
+
"aux_vision.aux_model.trunk.blocks.11.mlp.fc3.weight": "model-00004-of-00004.safetensors",
|
| 84 |
+
"aux_vision.aux_model.trunk.blocks.11.norm_1.weight": "model-00004-of-00004.safetensors",
|
| 85 |
+
"aux_vision.aux_model.trunk.blocks.11.norm_2.weight": "model-00004-of-00004.safetensors",
|
| 86 |
+
"aux_vision.aux_model.trunk.blocks.12.attn.proj.weight": "model-00004-of-00004.safetensors",
|
| 87 |
+
"aux_vision.aux_model.trunk.blocks.12.attn.qkv.weight": "model-00004-of-00004.safetensors",
|
| 88 |
+
"aux_vision.aux_model.trunk.blocks.12.mlp.fc1.weight": "model-00004-of-00004.safetensors",
|
| 89 |
+
"aux_vision.aux_model.trunk.blocks.12.mlp.fc2.weight": "model-00004-of-00004.safetensors",
|
| 90 |
+
"aux_vision.aux_model.trunk.blocks.12.mlp.fc3.weight": "model-00004-of-00004.safetensors",
|
| 91 |
+
"aux_vision.aux_model.trunk.blocks.12.norm_1.weight": "model-00004-of-00004.safetensors",
|
| 92 |
+
"aux_vision.aux_model.trunk.blocks.12.norm_2.weight": "model-00004-of-00004.safetensors",
|
| 93 |
+
"aux_vision.aux_model.trunk.blocks.13.attn.proj.weight": "model-00004-of-00004.safetensors",
|
| 94 |
+
"aux_vision.aux_model.trunk.blocks.13.attn.qkv.weight": "model-00004-of-00004.safetensors",
|
| 95 |
+
"aux_vision.aux_model.trunk.blocks.13.mlp.fc1.weight": "model-00004-of-00004.safetensors",
|
| 96 |
+
"aux_vision.aux_model.trunk.blocks.13.mlp.fc2.weight": "model-00004-of-00004.safetensors",
|
| 97 |
+
"aux_vision.aux_model.trunk.blocks.13.mlp.fc3.weight": "model-00004-of-00004.safetensors",
|
| 98 |
+
"aux_vision.aux_model.trunk.blocks.13.norm_1.weight": "model-00004-of-00004.safetensors",
|
| 99 |
+
"aux_vision.aux_model.trunk.blocks.13.norm_2.weight": "model-00004-of-00004.safetensors",
|
| 100 |
+
"aux_vision.aux_model.trunk.blocks.14.attn.proj.weight": "model-00004-of-00004.safetensors",
|
| 101 |
+
"aux_vision.aux_model.trunk.blocks.14.attn.qkv.weight": "model-00004-of-00004.safetensors",
|
| 102 |
+
"aux_vision.aux_model.trunk.blocks.14.mlp.fc1.weight": "model-00004-of-00004.safetensors",
|
| 103 |
+
"aux_vision.aux_model.trunk.blocks.14.mlp.fc2.weight": "model-00004-of-00004.safetensors",
|
| 104 |
+
"aux_vision.aux_model.trunk.blocks.14.mlp.fc3.weight": "model-00004-of-00004.safetensors",
|
| 105 |
+
"aux_vision.aux_model.trunk.blocks.14.norm_1.weight": "model-00004-of-00004.safetensors",
|
| 106 |
+
"aux_vision.aux_model.trunk.blocks.14.norm_2.weight": "model-00004-of-00004.safetensors",
|
| 107 |
+
"aux_vision.aux_model.trunk.blocks.15.attn.proj.weight": "model-00004-of-00004.safetensors",
|
| 108 |
+
"aux_vision.aux_model.trunk.blocks.15.attn.qkv.weight": "model-00004-of-00004.safetensors",
|
| 109 |
+
"aux_vision.aux_model.trunk.blocks.15.mlp.fc1.weight": "model-00004-of-00004.safetensors",
|
| 110 |
+
"aux_vision.aux_model.trunk.blocks.15.mlp.fc2.weight": "model-00004-of-00004.safetensors",
|
| 111 |
+
"aux_vision.aux_model.trunk.blocks.15.mlp.fc3.weight": "model-00004-of-00004.safetensors",
|
| 112 |
+
"aux_vision.aux_model.trunk.blocks.15.norm_1.weight": "model-00004-of-00004.safetensors",
|
| 113 |
+
"aux_vision.aux_model.trunk.blocks.15.norm_2.weight": "model-00004-of-00004.safetensors",
|
| 114 |
+
"aux_vision.aux_model.trunk.blocks.16.attn.proj.weight": "model-00004-of-00004.safetensors",
|
| 115 |
+
"aux_vision.aux_model.trunk.blocks.16.attn.qkv.weight": "model-00004-of-00004.safetensors",
|
| 116 |
+
"aux_vision.aux_model.trunk.blocks.16.mlp.fc1.weight": "model-00004-of-00004.safetensors",
|
| 117 |
+
"aux_vision.aux_model.trunk.blocks.16.mlp.fc2.weight": "model-00004-of-00004.safetensors",
|
| 118 |
+
"aux_vision.aux_model.trunk.blocks.16.mlp.fc3.weight": "model-00004-of-00004.safetensors",
|
| 119 |
+
"aux_vision.aux_model.trunk.blocks.16.norm_1.weight": "model-00004-of-00004.safetensors",
|
| 120 |
+
"aux_vision.aux_model.trunk.blocks.16.norm_2.weight": "model-00004-of-00004.safetensors",
|
| 121 |
+
"aux_vision.aux_model.trunk.blocks.17.attn.proj.weight": "model-00004-of-00004.safetensors",
|
| 122 |
+
"aux_vision.aux_model.trunk.blocks.17.attn.qkv.weight": "model-00004-of-00004.safetensors",
|
| 123 |
+
"aux_vision.aux_model.trunk.blocks.17.mlp.fc1.weight": "model-00004-of-00004.safetensors",
|
| 124 |
+
"aux_vision.aux_model.trunk.blocks.17.mlp.fc2.weight": "model-00004-of-00004.safetensors",
|
| 125 |
+
"aux_vision.aux_model.trunk.blocks.17.mlp.fc3.weight": "model-00004-of-00004.safetensors",
|
| 126 |
+
"aux_vision.aux_model.trunk.blocks.17.norm_1.weight": "model-00004-of-00004.safetensors",
|
| 127 |
+
"aux_vision.aux_model.trunk.blocks.17.norm_2.weight": "model-00004-of-00004.safetensors",
|
| 128 |
+
"aux_vision.aux_model.trunk.blocks.18.attn.proj.weight": "model-00004-of-00004.safetensors",
|
| 129 |
+
"aux_vision.aux_model.trunk.blocks.18.attn.qkv.weight": "model-00004-of-00004.safetensors",
|
| 130 |
+
"aux_vision.aux_model.trunk.blocks.18.mlp.fc1.weight": "model-00004-of-00004.safetensors",
|
| 131 |
+
"aux_vision.aux_model.trunk.blocks.18.mlp.fc2.weight": "model-00004-of-00004.safetensors",
|
| 132 |
+
"aux_vision.aux_model.trunk.blocks.18.mlp.fc3.weight": "model-00004-of-00004.safetensors",
|
| 133 |
+
"aux_vision.aux_model.trunk.blocks.18.norm_1.weight": "model-00004-of-00004.safetensors",
|
| 134 |
+
"aux_vision.aux_model.trunk.blocks.18.norm_2.weight": "model-00004-of-00004.safetensors",
|
| 135 |
+
"aux_vision.aux_model.trunk.blocks.19.attn.proj.weight": "model-00004-of-00004.safetensors",
|
| 136 |
+
"aux_vision.aux_model.trunk.blocks.19.attn.qkv.weight": "model-00004-of-00004.safetensors",
|
| 137 |
+
"aux_vision.aux_model.trunk.blocks.19.mlp.fc1.weight": "model-00004-of-00004.safetensors",
|
| 138 |
+
"aux_vision.aux_model.trunk.blocks.19.mlp.fc2.weight": "model-00004-of-00004.safetensors",
|
| 139 |
+
"aux_vision.aux_model.trunk.blocks.19.mlp.fc3.weight": "model-00004-of-00004.safetensors",
|
| 140 |
+
"aux_vision.aux_model.trunk.blocks.19.norm_1.weight": "model-00004-of-00004.safetensors",
|
| 141 |
+
"aux_vision.aux_model.trunk.blocks.19.norm_2.weight": "model-00004-of-00004.safetensors",
|
| 142 |
+
"aux_vision.aux_model.trunk.blocks.2.attn.proj.weight": "model-00004-of-00004.safetensors",
|
| 143 |
+
"aux_vision.aux_model.trunk.blocks.2.attn.qkv.weight": "model-00004-of-00004.safetensors",
|
| 144 |
+
"aux_vision.aux_model.trunk.blocks.2.mlp.fc1.weight": "model-00004-of-00004.safetensors",
|
| 145 |
+
"aux_vision.aux_model.trunk.blocks.2.mlp.fc2.weight": "model-00004-of-00004.safetensors",
|
| 146 |
+
"aux_vision.aux_model.trunk.blocks.2.mlp.fc3.weight": "model-00004-of-00004.safetensors",
|
| 147 |
+
"aux_vision.aux_model.trunk.blocks.2.norm_1.weight": "model-00004-of-00004.safetensors",
|
| 148 |
+
"aux_vision.aux_model.trunk.blocks.2.norm_2.weight": "model-00004-of-00004.safetensors",
|
| 149 |
+
"aux_vision.aux_model.trunk.blocks.20.attn.proj.weight": "model-00004-of-00004.safetensors",
|
| 150 |
+
"aux_vision.aux_model.trunk.blocks.20.attn.qkv.weight": "model-00004-of-00004.safetensors",
|
| 151 |
+
"aux_vision.aux_model.trunk.blocks.20.mlp.fc1.weight": "model-00004-of-00004.safetensors",
|
| 152 |
+
"aux_vision.aux_model.trunk.blocks.20.mlp.fc2.weight": "model-00004-of-00004.safetensors",
|
| 153 |
+
"aux_vision.aux_model.trunk.blocks.20.mlp.fc3.weight": "model-00004-of-00004.safetensors",
|
| 154 |
+
"aux_vision.aux_model.trunk.blocks.20.norm_1.weight": "model-00004-of-00004.safetensors",
|
| 155 |
+
"aux_vision.aux_model.trunk.blocks.20.norm_2.weight": "model-00004-of-00004.safetensors",
|
| 156 |
+
"aux_vision.aux_model.trunk.blocks.21.attn.proj.weight": "model-00004-of-00004.safetensors",
|
| 157 |
+
"aux_vision.aux_model.trunk.blocks.21.attn.qkv.weight": "model-00004-of-00004.safetensors",
|
| 158 |
+
"aux_vision.aux_model.trunk.blocks.21.mlp.fc1.weight": "model-00004-of-00004.safetensors",
|
| 159 |
+
"aux_vision.aux_model.trunk.blocks.21.mlp.fc2.weight": "model-00004-of-00004.safetensors",
|
| 160 |
+
"aux_vision.aux_model.trunk.blocks.21.mlp.fc3.weight": "model-00004-of-00004.safetensors",
|
| 161 |
+
"aux_vision.aux_model.trunk.blocks.21.norm_1.weight": "model-00004-of-00004.safetensors",
|
| 162 |
+
"aux_vision.aux_model.trunk.blocks.21.norm_2.weight": "model-00004-of-00004.safetensors",
|
| 163 |
+
"aux_vision.aux_model.trunk.blocks.22.attn.proj.weight": "model-00004-of-00004.safetensors",
|
| 164 |
+
"aux_vision.aux_model.trunk.blocks.22.attn.qkv.weight": "model-00004-of-00004.safetensors",
|
| 165 |
+
"aux_vision.aux_model.trunk.blocks.22.mlp.fc1.weight": "model-00004-of-00004.safetensors",
|
| 166 |
+
"aux_vision.aux_model.trunk.blocks.22.mlp.fc2.weight": "model-00004-of-00004.safetensors",
|
| 167 |
+
"aux_vision.aux_model.trunk.blocks.22.mlp.fc3.weight": "model-00004-of-00004.safetensors",
|
| 168 |
+
"aux_vision.aux_model.trunk.blocks.22.norm_1.weight": "model-00004-of-00004.safetensors",
|
| 169 |
+
"aux_vision.aux_model.trunk.blocks.22.norm_2.weight": "model-00004-of-00004.safetensors",
|
| 170 |
+
"aux_vision.aux_model.trunk.blocks.23.attn.proj.weight": "model-00004-of-00004.safetensors",
|
| 171 |
+
"aux_vision.aux_model.trunk.blocks.23.attn.qkv.weight": "model-00004-of-00004.safetensors",
|
| 172 |
+
"aux_vision.aux_model.trunk.blocks.23.mlp.fc1.weight": "model-00004-of-00004.safetensors",
|
| 173 |
+
"aux_vision.aux_model.trunk.blocks.23.mlp.fc2.weight": "model-00004-of-00004.safetensors",
|
| 174 |
+
"aux_vision.aux_model.trunk.blocks.23.mlp.fc3.weight": "model-00004-of-00004.safetensors",
|
| 175 |
+
"aux_vision.aux_model.trunk.blocks.23.norm_1.weight": "model-00004-of-00004.safetensors",
|
| 176 |
+
"aux_vision.aux_model.trunk.blocks.23.norm_2.weight": "model-00004-of-00004.safetensors",
|
| 177 |
+
"aux_vision.aux_model.trunk.blocks.3.attn.proj.weight": "model-00004-of-00004.safetensors",
|
| 178 |
+
"aux_vision.aux_model.trunk.blocks.3.attn.qkv.weight": "model-00004-of-00004.safetensors",
|
| 179 |
+
"aux_vision.aux_model.trunk.blocks.3.mlp.fc1.weight": "model-00004-of-00004.safetensors",
|
| 180 |
+
"aux_vision.aux_model.trunk.blocks.3.mlp.fc2.weight": "model-00004-of-00004.safetensors",
|
| 181 |
+
"aux_vision.aux_model.trunk.blocks.3.mlp.fc3.weight": "model-00004-of-00004.safetensors",
|
| 182 |
+
"aux_vision.aux_model.trunk.blocks.3.norm_1.weight": "model-00004-of-00004.safetensors",
|
| 183 |
+
"aux_vision.aux_model.trunk.blocks.3.norm_2.weight": "model-00004-of-00004.safetensors",
|
| 184 |
+
"aux_vision.aux_model.trunk.blocks.4.attn.proj.weight": "model-00004-of-00004.safetensors",
|
| 185 |
+
"aux_vision.aux_model.trunk.blocks.4.attn.qkv.weight": "model-00004-of-00004.safetensors",
|
| 186 |
+
"aux_vision.aux_model.trunk.blocks.4.mlp.fc1.weight": "model-00004-of-00004.safetensors",
|
| 187 |
+
"aux_vision.aux_model.trunk.blocks.4.mlp.fc2.weight": "model-00004-of-00004.safetensors",
|
| 188 |
+
"aux_vision.aux_model.trunk.blocks.4.mlp.fc3.weight": "model-00004-of-00004.safetensors",
|
| 189 |
+
"aux_vision.aux_model.trunk.blocks.4.norm_1.weight": "model-00004-of-00004.safetensors",
|
| 190 |
+
"aux_vision.aux_model.trunk.blocks.4.norm_2.weight": "model-00004-of-00004.safetensors",
|
| 191 |
+
"aux_vision.aux_model.trunk.blocks.5.attn.proj.weight": "model-00004-of-00004.safetensors",
|
| 192 |
+
"aux_vision.aux_model.trunk.blocks.5.attn.qkv.weight": "model-00004-of-00004.safetensors",
|
| 193 |
+
"aux_vision.aux_model.trunk.blocks.5.mlp.fc1.weight": "model-00004-of-00004.safetensors",
|
| 194 |
+
"aux_vision.aux_model.trunk.blocks.5.mlp.fc2.weight": "model-00004-of-00004.safetensors",
|
| 195 |
+
"aux_vision.aux_model.trunk.blocks.5.mlp.fc3.weight": "model-00004-of-00004.safetensors",
|
| 196 |
+
"aux_vision.aux_model.trunk.blocks.5.norm_1.weight": "model-00004-of-00004.safetensors",
|
| 197 |
+
"aux_vision.aux_model.trunk.blocks.5.norm_2.weight": "model-00004-of-00004.safetensors",
|
| 198 |
+
"aux_vision.aux_model.trunk.blocks.6.attn.proj.weight": "model-00004-of-00004.safetensors",
|
| 199 |
+
"aux_vision.aux_model.trunk.blocks.6.attn.qkv.weight": "model-00004-of-00004.safetensors",
|
| 200 |
+
"aux_vision.aux_model.trunk.blocks.6.mlp.fc1.weight": "model-00004-of-00004.safetensors",
|
| 201 |
+
"aux_vision.aux_model.trunk.blocks.6.mlp.fc2.weight": "model-00004-of-00004.safetensors",
|
| 202 |
+
"aux_vision.aux_model.trunk.blocks.6.mlp.fc3.weight": "model-00004-of-00004.safetensors",
|
| 203 |
+
"aux_vision.aux_model.trunk.blocks.6.norm_1.weight": "model-00004-of-00004.safetensors",
|
| 204 |
+
"aux_vision.aux_model.trunk.blocks.6.norm_2.weight": "model-00004-of-00004.safetensors",
|
| 205 |
+
"aux_vision.aux_model.trunk.blocks.7.attn.proj.weight": "model-00004-of-00004.safetensors",
|
| 206 |
+
"aux_vision.aux_model.trunk.blocks.7.attn.qkv.weight": "model-00004-of-00004.safetensors",
|
| 207 |
+
"aux_vision.aux_model.trunk.blocks.7.mlp.fc1.weight": "model-00004-of-00004.safetensors",
|
| 208 |
+
"aux_vision.aux_model.trunk.blocks.7.mlp.fc2.weight": "model-00004-of-00004.safetensors",
|
| 209 |
+
"aux_vision.aux_model.trunk.blocks.7.mlp.fc3.weight": "model-00004-of-00004.safetensors",
|
| 210 |
+
"aux_vision.aux_model.trunk.blocks.7.norm_1.weight": "model-00004-of-00004.safetensors",
|
| 211 |
+
"aux_vision.aux_model.trunk.blocks.7.norm_2.weight": "model-00004-of-00004.safetensors",
|
| 212 |
+
"aux_vision.aux_model.trunk.blocks.8.attn.proj.weight": "model-00004-of-00004.safetensors",
|
| 213 |
+
"aux_vision.aux_model.trunk.blocks.8.attn.qkv.weight": "model-00004-of-00004.safetensors",
|
| 214 |
+
"aux_vision.aux_model.trunk.blocks.8.mlp.fc1.weight": "model-00004-of-00004.safetensors",
|
| 215 |
+
"aux_vision.aux_model.trunk.blocks.8.mlp.fc2.weight": "model-00004-of-00004.safetensors",
|
| 216 |
+
"aux_vision.aux_model.trunk.blocks.8.mlp.fc3.weight": "model-00004-of-00004.safetensors",
|
| 217 |
+
"aux_vision.aux_model.trunk.blocks.8.norm_1.weight": "model-00004-of-00004.safetensors",
|
| 218 |
+
"aux_vision.aux_model.trunk.blocks.8.norm_2.weight": "model-00004-of-00004.safetensors",
|
| 219 |
+
"aux_vision.aux_model.trunk.blocks.9.attn.proj.weight": "model-00004-of-00004.safetensors",
|
| 220 |
+
"aux_vision.aux_model.trunk.blocks.9.attn.qkv.weight": "model-00004-of-00004.safetensors",
|
| 221 |
+
"aux_vision.aux_model.trunk.blocks.9.mlp.fc1.weight": "model-00004-of-00004.safetensors",
|
| 222 |
+
"aux_vision.aux_model.trunk.blocks.9.mlp.fc2.weight": "model-00004-of-00004.safetensors",
|
| 223 |
+
"aux_vision.aux_model.trunk.blocks.9.mlp.fc3.weight": "model-00004-of-00004.safetensors",
|
| 224 |
+
"aux_vision.aux_model.trunk.blocks.9.norm_1.weight": "model-00004-of-00004.safetensors",
|
| 225 |
+
"aux_vision.aux_model.trunk.blocks.9.norm_2.weight": "model-00004-of-00004.safetensors",
|
| 226 |
+
"aux_vision.aux_model.trunk.post_trunk_norm.weight": "model-00004-of-00004.safetensors",
|
| 227 |
+
"llm.lm_head.weight": "model-00004-of-00004.safetensors",
|
| 228 |
+
"llm.model.embed_tokens.weight": "model-00001-of-00004.safetensors",
|
| 229 |
+
"llm.model.layers.0.input_layernorm.weight": "model-00001-of-00004.safetensors",
|
| 230 |
+
"llm.model.layers.0.mlp.down_proj.bias": "model-00001-of-00004.safetensors",
|
| 231 |
+
"llm.model.layers.0.mlp.down_proj.lora_A.weight": "model-00001-of-00004.safetensors",
|
| 232 |
+
"llm.model.layers.0.mlp.down_proj.lora_B.weight": "model-00001-of-00004.safetensors",
|
| 233 |
+
"llm.model.layers.0.mlp.down_proj.weight": "model-00001-of-00004.safetensors",
|
| 234 |
+
"llm.model.layers.0.mlp.gate_proj.bias": "model-00001-of-00004.safetensors",
|
| 235 |
+
"llm.model.layers.0.mlp.gate_proj.lora_A.weight": "model-00001-of-00004.safetensors",
|
| 236 |
+
"llm.model.layers.0.mlp.gate_proj.lora_B.weight": "model-00001-of-00004.safetensors",
|
| 237 |
+
"llm.model.layers.0.mlp.gate_proj.weight": "model-00001-of-00004.safetensors",
|
| 238 |
+
"llm.model.layers.0.mlp.up_proj.bias": "model-00001-of-00004.safetensors",
|
| 239 |
+
"llm.model.layers.0.mlp.up_proj.lora_A.weight": "model-00001-of-00004.safetensors",
|
| 240 |
+
"llm.model.layers.0.mlp.up_proj.lora_B.weight": "model-00001-of-00004.safetensors",
|
| 241 |
+
"llm.model.layers.0.mlp.up_proj.weight": "model-00001-of-00004.safetensors",
|
| 242 |
+
"llm.model.layers.0.post_attention_layernorm.weight": "model-00001-of-00004.safetensors",
|
| 243 |
+
"llm.model.layers.0.self_attn.k_proj.bias": "model-00001-of-00004.safetensors",
|
| 244 |
+
"llm.model.layers.0.self_attn.k_proj.lora_A.weight": "model-00001-of-00004.safetensors",
|
| 245 |
+
"llm.model.layers.0.self_attn.k_proj.lora_B.weight": "model-00001-of-00004.safetensors",
|
| 246 |
+
"llm.model.layers.0.self_attn.k_proj.weight": "model-00001-of-00004.safetensors",
|
| 247 |
+
"llm.model.layers.0.self_attn.o_proj.bias": "model-00001-of-00004.safetensors",
|
| 248 |
+
"llm.model.layers.0.self_attn.o_proj.lora_A.weight": "model-00001-of-00004.safetensors",
|
| 249 |
+
"llm.model.layers.0.self_attn.o_proj.lora_B.weight": "model-00001-of-00004.safetensors",
|
| 250 |
+
"llm.model.layers.0.self_attn.o_proj.weight": "model-00001-of-00004.safetensors",
|
| 251 |
+
"llm.model.layers.0.self_attn.q_proj.bias": "model-00001-of-00004.safetensors",
|
| 252 |
+
"llm.model.layers.0.self_attn.q_proj.lora_A.weight": "model-00001-of-00004.safetensors",
|
| 253 |
+
"llm.model.layers.0.self_attn.q_proj.lora_B.weight": "model-00001-of-00004.safetensors",
|
| 254 |
+
"llm.model.layers.0.self_attn.q_proj.weight": "model-00001-of-00004.safetensors",
|
| 255 |
+
"llm.model.layers.0.self_attn.v_proj.bias": "model-00001-of-00004.safetensors",
|
| 256 |
+
"llm.model.layers.0.self_attn.v_proj.lora_A.weight": "model-00001-of-00004.safetensors",
|
| 257 |
+
"llm.model.layers.0.self_attn.v_proj.lora_B.weight": "model-00001-of-00004.safetensors",
|
| 258 |
+
"llm.model.layers.0.self_attn.v_proj.weight": "model-00001-of-00004.safetensors",
|
| 259 |
+
"llm.model.layers.1.input_layernorm.weight": "model-00001-of-00004.safetensors",
|
| 260 |
+
"llm.model.layers.1.mlp.down_proj.bias": "model-00001-of-00004.safetensors",
|
| 261 |
+
"llm.model.layers.1.mlp.down_proj.lora_A.weight": "model-00001-of-00004.safetensors",
|
| 262 |
+
"llm.model.layers.1.mlp.down_proj.lora_B.weight": "model-00001-of-00004.safetensors",
|
| 263 |
+
"llm.model.layers.1.mlp.down_proj.weight": "model-00001-of-00004.safetensors",
|
| 264 |
+
"llm.model.layers.1.mlp.gate_proj.bias": "model-00001-of-00004.safetensors",
|
| 265 |
+
"llm.model.layers.1.mlp.gate_proj.lora_A.weight": "model-00001-of-00004.safetensors",
|
| 266 |
+
"llm.model.layers.1.mlp.gate_proj.lora_B.weight": "model-00001-of-00004.safetensors",
|
| 267 |
+
"llm.model.layers.1.mlp.gate_proj.weight": "model-00001-of-00004.safetensors",
|
| 268 |
+
"llm.model.layers.1.mlp.up_proj.bias": "model-00001-of-00004.safetensors",
|
| 269 |
+
"llm.model.layers.1.mlp.up_proj.lora_A.weight": "model-00001-of-00004.safetensors",
|
| 270 |
+
"llm.model.layers.1.mlp.up_proj.lora_B.weight": "model-00001-of-00004.safetensors",
|
| 271 |
+
"llm.model.layers.1.mlp.up_proj.weight": "model-00001-of-00004.safetensors",
|
| 272 |
+
"llm.model.layers.1.post_attention_layernorm.weight": "model-00001-of-00004.safetensors",
|
| 273 |
+
"llm.model.layers.1.self_attn.k_proj.bias": "model-00001-of-00004.safetensors",
|
| 274 |
+
"llm.model.layers.1.self_attn.k_proj.lora_A.weight": "model-00001-of-00004.safetensors",
|
| 275 |
+
"llm.model.layers.1.self_attn.k_proj.lora_B.weight": "model-00001-of-00004.safetensors",
|
| 276 |
+
"llm.model.layers.1.self_attn.k_proj.weight": "model-00001-of-00004.safetensors",
|
| 277 |
+
"llm.model.layers.1.self_attn.o_proj.bias": "model-00001-of-00004.safetensors",
|
| 278 |
+
"llm.model.layers.1.self_attn.o_proj.lora_A.weight": "model-00001-of-00004.safetensors",
|
| 279 |
+
"llm.model.layers.1.self_attn.o_proj.lora_B.weight": "model-00001-of-00004.safetensors",
|
| 280 |
+
"llm.model.layers.1.self_attn.o_proj.weight": "model-00001-of-00004.safetensors",
|
| 281 |
+
"llm.model.layers.1.self_attn.q_proj.bias": "model-00001-of-00004.safetensors",
|
| 282 |
+
"llm.model.layers.1.self_attn.q_proj.lora_A.weight": "model-00001-of-00004.safetensors",
|
| 283 |
+
"llm.model.layers.1.self_attn.q_proj.lora_B.weight": "model-00001-of-00004.safetensors",
|
| 284 |
+
"llm.model.layers.1.self_attn.q_proj.weight": "model-00001-of-00004.safetensors",
|
| 285 |
+
"llm.model.layers.1.self_attn.v_proj.bias": "model-00001-of-00004.safetensors",
|
| 286 |
+
"llm.model.layers.1.self_attn.v_proj.lora_A.weight": "model-00001-of-00004.safetensors",
|
| 287 |
+
"llm.model.layers.1.self_attn.v_proj.lora_B.weight": "model-00001-of-00004.safetensors",
|
| 288 |
+
"llm.model.layers.1.self_attn.v_proj.weight": "model-00001-of-00004.safetensors",
|
| 289 |
+
"llm.model.layers.10.input_layernorm.weight": "model-00002-of-00004.safetensors",
|
| 290 |
+
"llm.model.layers.10.mlp.down_proj.weight": "model-00002-of-00004.safetensors",
|
| 291 |
+
"llm.model.layers.10.mlp.gate_proj.weight": "model-00002-of-00004.safetensors",
|
| 292 |
+
"llm.model.layers.10.mlp.up_proj.weight": "model-00002-of-00004.safetensors",
|
| 293 |
+
"llm.model.layers.10.post_attention_layernorm.weight": "model-00002-of-00004.safetensors",
|
| 294 |
+
"llm.model.layers.10.self_attn.k_proj.bias": "model-00002-of-00004.safetensors",
|
| 295 |
+
"llm.model.layers.10.self_attn.k_proj.weight": "model-00002-of-00004.safetensors",
|
| 296 |
+
"llm.model.layers.10.self_attn.o_proj.weight": "model-00002-of-00004.safetensors",
|
| 297 |
+
"llm.model.layers.10.self_attn.q_proj.bias": "model-00002-of-00004.safetensors",
|
| 298 |
+
"llm.model.layers.10.self_attn.q_proj.weight": "model-00002-of-00004.safetensors",
|
| 299 |
+
"llm.model.layers.10.self_attn.v_proj.bias": "model-00002-of-00004.safetensors",
|
| 300 |
+
"llm.model.layers.10.self_attn.v_proj.weight": "model-00002-of-00004.safetensors",
|
| 301 |
+
"llm.model.layers.11.input_layernorm.weight": "model-00002-of-00004.safetensors",
|
| 302 |
+
"llm.model.layers.11.mlp.down_proj.weight": "model-00002-of-00004.safetensors",
|
| 303 |
+
"llm.model.layers.11.mlp.gate_proj.weight": "model-00002-of-00004.safetensors",
|
| 304 |
+
"llm.model.layers.11.mlp.up_proj.weight": "model-00002-of-00004.safetensors",
|
| 305 |
+
"llm.model.layers.11.post_attention_layernorm.weight": "model-00002-of-00004.safetensors",
|
| 306 |
+
"llm.model.layers.11.self_attn.k_proj.bias": "model-00002-of-00004.safetensors",
|
| 307 |
+
"llm.model.layers.11.self_attn.k_proj.weight": "model-00002-of-00004.safetensors",
|
| 308 |
+
"llm.model.layers.11.self_attn.o_proj.weight": "model-00002-of-00004.safetensors",
|
| 309 |
+
"llm.model.layers.11.self_attn.q_proj.bias": "model-00002-of-00004.safetensors",
|
| 310 |
+
"llm.model.layers.11.self_attn.q_proj.weight": "model-00002-of-00004.safetensors",
|
| 311 |
+
"llm.model.layers.11.self_attn.v_proj.bias": "model-00002-of-00004.safetensors",
|
| 312 |
+
"llm.model.layers.11.self_attn.v_proj.weight": "model-00002-of-00004.safetensors",
|
| 313 |
+
"llm.model.layers.12.input_layernorm.weight": "model-00002-of-00004.safetensors",
|
| 314 |
+
"llm.model.layers.12.mlp.down_proj.weight": "model-00002-of-00004.safetensors",
|
| 315 |
+
"llm.model.layers.12.mlp.gate_proj.weight": "model-00002-of-00004.safetensors",
|
| 316 |
+
"llm.model.layers.12.mlp.up_proj.weight": "model-00002-of-00004.safetensors",
|
| 317 |
+
"llm.model.layers.12.post_attention_layernorm.weight": "model-00002-of-00004.safetensors",
|
| 318 |
+
"llm.model.layers.12.self_attn.k_proj.bias": "model-00002-of-00004.safetensors",
|
| 319 |
+
"llm.model.layers.12.self_attn.k_proj.weight": "model-00002-of-00004.safetensors",
|
| 320 |
+
"llm.model.layers.12.self_attn.o_proj.weight": "model-00002-of-00004.safetensors",
|
| 321 |
+
"llm.model.layers.12.self_attn.q_proj.bias": "model-00002-of-00004.safetensors",
|
| 322 |
+
"llm.model.layers.12.self_attn.q_proj.weight": "model-00002-of-00004.safetensors",
|
| 323 |
+
"llm.model.layers.12.self_attn.v_proj.bias": "model-00002-of-00004.safetensors",
|
| 324 |
+
"llm.model.layers.12.self_attn.v_proj.weight": "model-00002-of-00004.safetensors",
|
| 325 |
+
"llm.model.layers.13.input_layernorm.weight": "model-00002-of-00004.safetensors",
|
| 326 |
+
"llm.model.layers.13.mlp.down_proj.weight": "model-00002-of-00004.safetensors",
|
| 327 |
+
"llm.model.layers.13.mlp.gate_proj.weight": "model-00002-of-00004.safetensors",
|
| 328 |
+
"llm.model.layers.13.mlp.up_proj.weight": "model-00002-of-00004.safetensors",
|
| 329 |
+
"llm.model.layers.13.post_attention_layernorm.weight": "model-00002-of-00004.safetensors",
|
| 330 |
+
"llm.model.layers.13.self_attn.k_proj.bias": "model-00002-of-00004.safetensors",
|
| 331 |
+
"llm.model.layers.13.self_attn.k_proj.weight": "model-00002-of-00004.safetensors",
|
| 332 |
+
"llm.model.layers.13.self_attn.o_proj.weight": "model-00002-of-00004.safetensors",
|
| 333 |
+
"llm.model.layers.13.self_attn.q_proj.bias": "model-00002-of-00004.safetensors",
|
| 334 |
+
"llm.model.layers.13.self_attn.q_proj.weight": "model-00002-of-00004.safetensors",
|
| 335 |
+
"llm.model.layers.13.self_attn.v_proj.bias": "model-00002-of-00004.safetensors",
|
| 336 |
+
"llm.model.layers.13.self_attn.v_proj.weight": "model-00002-of-00004.safetensors",
|
| 337 |
+
"llm.model.layers.14.input_layernorm.weight": "model-00002-of-00004.safetensors",
|
| 338 |
+
"llm.model.layers.14.mlp.down_proj.weight": "model-00002-of-00004.safetensors",
|
| 339 |
+
"llm.model.layers.14.mlp.gate_proj.weight": "model-00002-of-00004.safetensors",
|
| 340 |
+
"llm.model.layers.14.mlp.up_proj.weight": "model-00002-of-00004.safetensors",
|
| 341 |
+
"llm.model.layers.14.post_attention_layernorm.weight": "model-00002-of-00004.safetensors",
|
| 342 |
+
"llm.model.layers.14.self_attn.k_proj.bias": "model-00002-of-00004.safetensors",
|
| 343 |
+
"llm.model.layers.14.self_attn.k_proj.weight": "model-00002-of-00004.safetensors",
|
| 344 |
+
"llm.model.layers.14.self_attn.o_proj.weight": "model-00002-of-00004.safetensors",
|
| 345 |
+
"llm.model.layers.14.self_attn.q_proj.bias": "model-00002-of-00004.safetensors",
|
| 346 |
+
"llm.model.layers.14.self_attn.q_proj.weight": "model-00002-of-00004.safetensors",
|
| 347 |
+
"llm.model.layers.14.self_attn.v_proj.bias": "model-00002-of-00004.safetensors",
|
| 348 |
+
"llm.model.layers.14.self_attn.v_proj.weight": "model-00002-of-00004.safetensors",
|
| 349 |
+
"llm.model.layers.15.input_layernorm.weight": "model-00002-of-00004.safetensors",
|
| 350 |
+
"llm.model.layers.15.mlp.down_proj.weight": "model-00002-of-00004.safetensors",
|
| 351 |
+
"llm.model.layers.15.mlp.gate_proj.weight": "model-00002-of-00004.safetensors",
|
| 352 |
+
"llm.model.layers.15.mlp.up_proj.weight": "model-00002-of-00004.safetensors",
|
| 353 |
+
"llm.model.layers.15.post_attention_layernorm.weight": "model-00002-of-00004.safetensors",
|
| 354 |
+
"llm.model.layers.15.self_attn.k_proj.bias": "model-00002-of-00004.safetensors",
|
| 355 |
+
"llm.model.layers.15.self_attn.k_proj.weight": "model-00002-of-00004.safetensors",
|
| 356 |
+
"llm.model.layers.15.self_attn.o_proj.weight": "model-00002-of-00004.safetensors",
|
| 357 |
+
"llm.model.layers.15.self_attn.q_proj.bias": "model-00002-of-00004.safetensors",
|
| 358 |
+
"llm.model.layers.15.self_attn.q_proj.weight": "model-00002-of-00004.safetensors",
|
| 359 |
+
"llm.model.layers.15.self_attn.v_proj.bias": "model-00002-of-00004.safetensors",
|
| 360 |
+
"llm.model.layers.15.self_attn.v_proj.weight": "model-00002-of-00004.safetensors",
|
| 361 |
+
"llm.model.layers.16.input_layernorm.weight": "model-00002-of-00004.safetensors",
|
| 362 |
+
"llm.model.layers.16.mlp.down_proj.weight": "model-00002-of-00004.safetensors",
|
| 363 |
+
"llm.model.layers.16.mlp.gate_proj.weight": "model-00002-of-00004.safetensors",
|
| 364 |
+
"llm.model.layers.16.mlp.up_proj.weight": "model-00002-of-00004.safetensors",
|
| 365 |
+
"llm.model.layers.16.post_attention_layernorm.weight": "model-00002-of-00004.safetensors",
|
| 366 |
+
"llm.model.layers.16.self_attn.k_proj.bias": "model-00002-of-00004.safetensors",
|
| 367 |
+
"llm.model.layers.16.self_attn.k_proj.weight": "model-00002-of-00004.safetensors",
|
| 368 |
+
"llm.model.layers.16.self_attn.o_proj.weight": "model-00002-of-00004.safetensors",
|
| 369 |
+
"llm.model.layers.16.self_attn.q_proj.bias": "model-00002-of-00004.safetensors",
|
| 370 |
+
"llm.model.layers.16.self_attn.q_proj.weight": "model-00002-of-00004.safetensors",
|
| 371 |
+
"llm.model.layers.16.self_attn.v_proj.bias": "model-00002-of-00004.safetensors",
|
| 372 |
+
"llm.model.layers.16.self_attn.v_proj.weight": "model-00002-of-00004.safetensors",
|
| 373 |
+
"llm.model.layers.17.input_layernorm.weight": "model-00002-of-00004.safetensors",
|
| 374 |
+
"llm.model.layers.17.mlp.down_proj.weight": "model-00002-of-00004.safetensors",
|
| 375 |
+
"llm.model.layers.17.mlp.gate_proj.weight": "model-00002-of-00004.safetensors",
|
| 376 |
+
"llm.model.layers.17.mlp.up_proj.weight": "model-00002-of-00004.safetensors",
|
| 377 |
+
"llm.model.layers.17.post_attention_layernorm.weight": "model-00002-of-00004.safetensors",
|
| 378 |
+
"llm.model.layers.17.self_attn.k_proj.bias": "model-00002-of-00004.safetensors",
|
| 379 |
+
"llm.model.layers.17.self_attn.k_proj.weight": "model-00002-of-00004.safetensors",
|
| 380 |
+
"llm.model.layers.17.self_attn.o_proj.weight": "model-00002-of-00004.safetensors",
|
| 381 |
+
"llm.model.layers.17.self_attn.q_proj.bias": "model-00002-of-00004.safetensors",
|
| 382 |
+
"llm.model.layers.17.self_attn.q_proj.weight": "model-00002-of-00004.safetensors",
|
| 383 |
+
"llm.model.layers.17.self_attn.v_proj.bias": "model-00002-of-00004.safetensors",
|
| 384 |
+
"llm.model.layers.17.self_attn.v_proj.weight": "model-00002-of-00004.safetensors",
|
| 385 |
+
"llm.model.layers.18.input_layernorm.weight": "model-00003-of-00004.safetensors",
|
| 386 |
+
"llm.model.layers.18.mlp.down_proj.weight": "model-00003-of-00004.safetensors",
|
| 387 |
+
"llm.model.layers.18.mlp.gate_proj.weight": "model-00002-of-00004.safetensors",
|
| 388 |
+
"llm.model.layers.18.mlp.up_proj.weight": "model-00002-of-00004.safetensors",
|
| 389 |
+
"llm.model.layers.18.post_attention_layernorm.weight": "model-00003-of-00004.safetensors",
|
| 390 |
+
"llm.model.layers.18.self_attn.k_proj.bias": "model-00002-of-00004.safetensors",
|
| 391 |
+
"llm.model.layers.18.self_attn.k_proj.weight": "model-00002-of-00004.safetensors",
|
| 392 |
+
"llm.model.layers.18.self_attn.o_proj.weight": "model-00002-of-00004.safetensors",
|
| 393 |
+
"llm.model.layers.18.self_attn.q_proj.bias": "model-00002-of-00004.safetensors",
|
| 394 |
+
"llm.model.layers.18.self_attn.q_proj.weight": "model-00002-of-00004.safetensors",
|
| 395 |
+
"llm.model.layers.18.self_attn.v_proj.bias": "model-00002-of-00004.safetensors",
|
| 396 |
+
"llm.model.layers.18.self_attn.v_proj.weight": "model-00002-of-00004.safetensors",
|
| 397 |
+
"llm.model.layers.19.input_layernorm.weight": "model-00003-of-00004.safetensors",
|
| 398 |
+
"llm.model.layers.19.mlp.down_proj.weight": "model-00003-of-00004.safetensors",
|
| 399 |
+
"llm.model.layers.19.mlp.gate_proj.weight": "model-00003-of-00004.safetensors",
|
| 400 |
+
"llm.model.layers.19.mlp.up_proj.weight": "model-00003-of-00004.safetensors",
|
| 401 |
+
"llm.model.layers.19.post_attention_layernorm.weight": "model-00003-of-00004.safetensors",
|
| 402 |
+
"llm.model.layers.19.self_attn.k_proj.bias": "model-00003-of-00004.safetensors",
|
| 403 |
+
"llm.model.layers.19.self_attn.k_proj.weight": "model-00003-of-00004.safetensors",
|
| 404 |
+
"llm.model.layers.19.self_attn.o_proj.weight": "model-00003-of-00004.safetensors",
|
| 405 |
+
"llm.model.layers.19.self_attn.q_proj.bias": "model-00003-of-00004.safetensors",
|
| 406 |
+
"llm.model.layers.19.self_attn.q_proj.weight": "model-00003-of-00004.safetensors",
|
| 407 |
+
"llm.model.layers.19.self_attn.v_proj.bias": "model-00003-of-00004.safetensors",
|
| 408 |
+
"llm.model.layers.19.self_attn.v_proj.weight": "model-00003-of-00004.safetensors",
|
| 409 |
+
"llm.model.layers.2.input_layernorm.weight": "model-00001-of-00004.safetensors",
|
| 410 |
+
"llm.model.layers.2.mlp.down_proj.bias": "model-00001-of-00004.safetensors",
|
| 411 |
+
"llm.model.layers.2.mlp.down_proj.lora_A.weight": "model-00001-of-00004.safetensors",
|
| 412 |
+
"llm.model.layers.2.mlp.down_proj.lora_B.weight": "model-00001-of-00004.safetensors",
|
| 413 |
+
"llm.model.layers.2.mlp.down_proj.weight": "model-00001-of-00004.safetensors",
|
| 414 |
+
"llm.model.layers.2.mlp.gate_proj.bias": "model-00001-of-00004.safetensors",
|
| 415 |
+
"llm.model.layers.2.mlp.gate_proj.lora_A.weight": "model-00001-of-00004.safetensors",
|
| 416 |
+
"llm.model.layers.2.mlp.gate_proj.lora_B.weight": "model-00001-of-00004.safetensors",
|
| 417 |
+
"llm.model.layers.2.mlp.gate_proj.weight": "model-00001-of-00004.safetensors",
|
| 418 |
+
"llm.model.layers.2.mlp.up_proj.bias": "model-00001-of-00004.safetensors",
|
| 419 |
+
"llm.model.layers.2.mlp.up_proj.lora_A.weight": "model-00001-of-00004.safetensors",
|
| 420 |
+
"llm.model.layers.2.mlp.up_proj.lora_B.weight": "model-00001-of-00004.safetensors",
|
| 421 |
+
"llm.model.layers.2.mlp.up_proj.weight": "model-00001-of-00004.safetensors",
|
| 422 |
+
"llm.model.layers.2.post_attention_layernorm.weight": "model-00001-of-00004.safetensors",
|
| 423 |
+
"llm.model.layers.2.self_attn.k_proj.bias": "model-00001-of-00004.safetensors",
|
| 424 |
+
"llm.model.layers.2.self_attn.k_proj.lora_A.weight": "model-00001-of-00004.safetensors",
|
| 425 |
+
"llm.model.layers.2.self_attn.k_proj.lora_B.weight": "model-00001-of-00004.safetensors",
|
| 426 |
+
"llm.model.layers.2.self_attn.k_proj.weight": "model-00001-of-00004.safetensors",
|
| 427 |
+
"llm.model.layers.2.self_attn.o_proj.bias": "model-00001-of-00004.safetensors",
|
| 428 |
+
"llm.model.layers.2.self_attn.o_proj.lora_A.weight": "model-00001-of-00004.safetensors",
|
| 429 |
+
"llm.model.layers.2.self_attn.o_proj.lora_B.weight": "model-00001-of-00004.safetensors",
|
| 430 |
+
"llm.model.layers.2.self_attn.o_proj.weight": "model-00001-of-00004.safetensors",
|
| 431 |
+
"llm.model.layers.2.self_attn.q_proj.bias": "model-00001-of-00004.safetensors",
|
| 432 |
+
"llm.model.layers.2.self_attn.q_proj.lora_A.weight": "model-00001-of-00004.safetensors",
|
| 433 |
+
"llm.model.layers.2.self_attn.q_proj.lora_B.weight": "model-00001-of-00004.safetensors",
|
| 434 |
+
"llm.model.layers.2.self_attn.q_proj.weight": "model-00001-of-00004.safetensors",
|
| 435 |
+
"llm.model.layers.2.self_attn.v_proj.bias": "model-00001-of-00004.safetensors",
|
| 436 |
+
"llm.model.layers.2.self_attn.v_proj.lora_A.weight": "model-00001-of-00004.safetensors",
|
| 437 |
+
"llm.model.layers.2.self_attn.v_proj.lora_B.weight": "model-00001-of-00004.safetensors",
|
| 438 |
+
"llm.model.layers.2.self_attn.v_proj.weight": "model-00001-of-00004.safetensors",
|
| 439 |
+
"llm.model.layers.20.input_layernorm.weight": "model-00003-of-00004.safetensors",
|
| 440 |
+
"llm.model.layers.20.mlp.down_proj.weight": "model-00003-of-00004.safetensors",
|
| 441 |
+
"llm.model.layers.20.mlp.gate_proj.weight": "model-00003-of-00004.safetensors",
|
| 442 |
+
"llm.model.layers.20.mlp.up_proj.weight": "model-00003-of-00004.safetensors",
|
| 443 |
+
"llm.model.layers.20.post_attention_layernorm.weight": "model-00003-of-00004.safetensors",
|
| 444 |
+
"llm.model.layers.20.self_attn.k_proj.bias": "model-00003-of-00004.safetensors",
|
| 445 |
+
"llm.model.layers.20.self_attn.k_proj.weight": "model-00003-of-00004.safetensors",
|
| 446 |
+
"llm.model.layers.20.self_attn.o_proj.weight": "model-00003-of-00004.safetensors",
|
| 447 |
+
"llm.model.layers.20.self_attn.q_proj.bias": "model-00003-of-00004.safetensors",
|
| 448 |
+
"llm.model.layers.20.self_attn.q_proj.weight": "model-00003-of-00004.safetensors",
|
| 449 |
+
"llm.model.layers.20.self_attn.v_proj.bias": "model-00003-of-00004.safetensors",
|
| 450 |
+
"llm.model.layers.20.self_attn.v_proj.weight": "model-00003-of-00004.safetensors",
|
| 451 |
+
"llm.model.layers.21.input_layernorm.weight": "model-00003-of-00004.safetensors",
|
| 452 |
+
"llm.model.layers.21.mlp.down_proj.weight": "model-00003-of-00004.safetensors",
|
| 453 |
+
"llm.model.layers.21.mlp.gate_proj.weight": "model-00003-of-00004.safetensors",
|
| 454 |
+
"llm.model.layers.21.mlp.up_proj.weight": "model-00003-of-00004.safetensors",
|
| 455 |
+
"llm.model.layers.21.post_attention_layernorm.weight": "model-00003-of-00004.safetensors",
|
| 456 |
+
"llm.model.layers.21.self_attn.k_proj.bias": "model-00003-of-00004.safetensors",
|
| 457 |
+
"llm.model.layers.21.self_attn.k_proj.weight": "model-00003-of-00004.safetensors",
|
| 458 |
+
"llm.model.layers.21.self_attn.o_proj.weight": "model-00003-of-00004.safetensors",
|
| 459 |
+
"llm.model.layers.21.self_attn.q_proj.bias": "model-00003-of-00004.safetensors",
|
| 460 |
+
"llm.model.layers.21.self_attn.q_proj.weight": "model-00003-of-00004.safetensors",
|
| 461 |
+
"llm.model.layers.21.self_attn.v_proj.bias": "model-00003-of-00004.safetensors",
|
| 462 |
+
"llm.model.layers.21.self_attn.v_proj.weight": "model-00003-of-00004.safetensors",
|
| 463 |
+
"llm.model.layers.22.input_layernorm.weight": "model-00003-of-00004.safetensors",
|
| 464 |
+
"llm.model.layers.22.mlp.down_proj.weight": "model-00003-of-00004.safetensors",
|
| 465 |
+
"llm.model.layers.22.mlp.gate_proj.weight": "model-00003-of-00004.safetensors",
|
| 466 |
+
"llm.model.layers.22.mlp.up_proj.weight": "model-00003-of-00004.safetensors",
|
| 467 |
+
"llm.model.layers.22.post_attention_layernorm.weight": "model-00003-of-00004.safetensors",
|
| 468 |
+
"llm.model.layers.22.self_attn.k_proj.bias": "model-00003-of-00004.safetensors",
|
| 469 |
+
"llm.model.layers.22.self_attn.k_proj.weight": "model-00003-of-00004.safetensors",
|
| 470 |
+
"llm.model.layers.22.self_attn.o_proj.weight": "model-00003-of-00004.safetensors",
|
| 471 |
+
"llm.model.layers.22.self_attn.q_proj.bias": "model-00003-of-00004.safetensors",
|
| 472 |
+
"llm.model.layers.22.self_attn.q_proj.weight": "model-00003-of-00004.safetensors",
|
| 473 |
+
"llm.model.layers.22.self_attn.v_proj.bias": "model-00003-of-00004.safetensors",
|
| 474 |
+
"llm.model.layers.22.self_attn.v_proj.weight": "model-00003-of-00004.safetensors",
|
| 475 |
+
"llm.model.layers.23.input_layernorm.weight": "model-00003-of-00004.safetensors",
|
| 476 |
+
"llm.model.layers.23.mlp.down_proj.weight": "model-00003-of-00004.safetensors",
|
| 477 |
+
"llm.model.layers.23.mlp.gate_proj.weight": "model-00003-of-00004.safetensors",
|
| 478 |
+
"llm.model.layers.23.mlp.up_proj.weight": "model-00003-of-00004.safetensors",
|
| 479 |
+
"llm.model.layers.23.post_attention_layernorm.weight": "model-00003-of-00004.safetensors",
|
| 480 |
+
"llm.model.layers.23.self_attn.k_proj.bias": "model-00003-of-00004.safetensors",
|
| 481 |
+
"llm.model.layers.23.self_attn.k_proj.weight": "model-00003-of-00004.safetensors",
|
| 482 |
+
"llm.model.layers.23.self_attn.o_proj.weight": "model-00003-of-00004.safetensors",
|
| 483 |
+
"llm.model.layers.23.self_attn.q_proj.bias": "model-00003-of-00004.safetensors",
|
| 484 |
+
"llm.model.layers.23.self_attn.q_proj.weight": "model-00003-of-00004.safetensors",
|
| 485 |
+
"llm.model.layers.23.self_attn.v_proj.bias": "model-00003-of-00004.safetensors",
|
| 486 |
+
"llm.model.layers.23.self_attn.v_proj.weight": "model-00003-of-00004.safetensors",
|
| 487 |
+
"llm.model.layers.24.input_layernorm.weight": "model-00003-of-00004.safetensors",
|
| 488 |
+
"llm.model.layers.24.mlp.down_proj.weight": "model-00003-of-00004.safetensors",
|
| 489 |
+
"llm.model.layers.24.mlp.gate_proj.weight": "model-00003-of-00004.safetensors",
|
| 490 |
+
"llm.model.layers.24.mlp.up_proj.weight": "model-00003-of-00004.safetensors",
|
| 491 |
+
"llm.model.layers.24.post_attention_layernorm.weight": "model-00003-of-00004.safetensors",
|
| 492 |
+
"llm.model.layers.24.self_attn.k_proj.bias": "model-00003-of-00004.safetensors",
|
| 493 |
+
"llm.model.layers.24.self_attn.k_proj.weight": "model-00003-of-00004.safetensors",
|
| 494 |
+
"llm.model.layers.24.self_attn.o_proj.weight": "model-00003-of-00004.safetensors",
|
| 495 |
+
"llm.model.layers.24.self_attn.q_proj.bias": "model-00003-of-00004.safetensors",
|
| 496 |
+
"llm.model.layers.24.self_attn.q_proj.weight": "model-00003-of-00004.safetensors",
|
| 497 |
+
"llm.model.layers.24.self_attn.v_proj.bias": "model-00003-of-00004.safetensors",
|
| 498 |
+
"llm.model.layers.24.self_attn.v_proj.weight": "model-00003-of-00004.safetensors",
|
| 499 |
+
"llm.model.layers.25.input_layernorm.weight": "model-00003-of-00004.safetensors",
|
| 500 |
+
"llm.model.layers.25.mlp.down_proj.weight": "model-00003-of-00004.safetensors",
|
| 501 |
+
"llm.model.layers.25.mlp.gate_proj.weight": "model-00003-of-00004.safetensors",
|
| 502 |
+
"llm.model.layers.25.mlp.up_proj.weight": "model-00003-of-00004.safetensors",
|
| 503 |
+
"llm.model.layers.25.post_attention_layernorm.weight": "model-00003-of-00004.safetensors",
|
| 504 |
+
"llm.model.layers.25.self_attn.k_proj.bias": "model-00003-of-00004.safetensors",
|
| 505 |
+
"llm.model.layers.25.self_attn.k_proj.weight": "model-00003-of-00004.safetensors",
|
| 506 |
+
"llm.model.layers.25.self_attn.o_proj.weight": "model-00003-of-00004.safetensors",
|
| 507 |
+
"llm.model.layers.25.self_attn.q_proj.bias": "model-00003-of-00004.safetensors",
|
| 508 |
+
"llm.model.layers.25.self_attn.q_proj.weight": "model-00003-of-00004.safetensors",
|
| 509 |
+
"llm.model.layers.25.self_attn.v_proj.bias": "model-00003-of-00004.safetensors",
|
| 510 |
+
"llm.model.layers.25.self_attn.v_proj.weight": "model-00003-of-00004.safetensors",
|
| 511 |
+
"llm.model.layers.26.input_layernorm.weight": "model-00003-of-00004.safetensors",
|
| 512 |
+
"llm.model.layers.26.mlp.down_proj.weight": "model-00003-of-00004.safetensors",
|
| 513 |
+
"llm.model.layers.26.mlp.gate_proj.weight": "model-00003-of-00004.safetensors",
|
| 514 |
+
"llm.model.layers.26.mlp.up_proj.weight": "model-00003-of-00004.safetensors",
|
| 515 |
+
"llm.model.layers.26.post_attention_layernorm.weight": "model-00003-of-00004.safetensors",
|
| 516 |
+
"llm.model.layers.26.self_attn.k_proj.bias": "model-00003-of-00004.safetensors",
|
| 517 |
+
"llm.model.layers.26.self_attn.k_proj.weight": "model-00003-of-00004.safetensors",
|
| 518 |
+
"llm.model.layers.26.self_attn.o_proj.weight": "model-00003-of-00004.safetensors",
|
| 519 |
+
"llm.model.layers.26.self_attn.q_proj.bias": "model-00003-of-00004.safetensors",
|
| 520 |
+
"llm.model.layers.26.self_attn.q_proj.weight": "model-00003-of-00004.safetensors",
|
| 521 |
+
"llm.model.layers.26.self_attn.v_proj.bias": "model-00003-of-00004.safetensors",
|
| 522 |
+
"llm.model.layers.26.self_attn.v_proj.weight": "model-00003-of-00004.safetensors",
|
| 523 |
+
"llm.model.layers.27.input_layernorm.weight": "model-00003-of-00004.safetensors",
|
| 524 |
+
"llm.model.layers.27.mlp.down_proj.weight": "model-00003-of-00004.safetensors",
|
| 525 |
+
"llm.model.layers.27.mlp.gate_proj.weight": "model-00003-of-00004.safetensors",
|
| 526 |
+
"llm.model.layers.27.mlp.up_proj.weight": "model-00003-of-00004.safetensors",
|
| 527 |
+
"llm.model.layers.27.post_attention_layernorm.weight": "model-00003-of-00004.safetensors",
|
| 528 |
+
"llm.model.layers.27.self_attn.k_proj.bias": "model-00003-of-00004.safetensors",
|
| 529 |
+
"llm.model.layers.27.self_attn.k_proj.weight": "model-00003-of-00004.safetensors",
|
| 530 |
+
"llm.model.layers.27.self_attn.o_proj.weight": "model-00003-of-00004.safetensors",
|
| 531 |
+
"llm.model.layers.27.self_attn.q_proj.bias": "model-00003-of-00004.safetensors",
|
| 532 |
+
"llm.model.layers.27.self_attn.q_proj.weight": "model-00003-of-00004.safetensors",
|
| 533 |
+
"llm.model.layers.27.self_attn.v_proj.bias": "model-00003-of-00004.safetensors",
|
| 534 |
+
"llm.model.layers.27.self_attn.v_proj.weight": "model-00003-of-00004.safetensors",
|
| 535 |
+
"llm.model.layers.3.input_layernorm.weight": "model-00001-of-00004.safetensors",
|
| 536 |
+
"llm.model.layers.3.mlp.down_proj.weight": "model-00001-of-00004.safetensors",
|
| 537 |
+
"llm.model.layers.3.mlp.gate_proj.weight": "model-00001-of-00004.safetensors",
|
| 538 |
+
"llm.model.layers.3.mlp.up_proj.weight": "model-00001-of-00004.safetensors",
|
| 539 |
+
"llm.model.layers.3.post_attention_layernorm.weight": "model-00001-of-00004.safetensors",
|
| 540 |
+
"llm.model.layers.3.self_attn.k_proj.bias": "model-00001-of-00004.safetensors",
|
| 541 |
+
"llm.model.layers.3.self_attn.k_proj.weight": "model-00001-of-00004.safetensors",
|
| 542 |
+
"llm.model.layers.3.self_attn.o_proj.weight": "model-00001-of-00004.safetensors",
|
| 543 |
+
"llm.model.layers.3.self_attn.q_proj.bias": "model-00001-of-00004.safetensors",
|
| 544 |
+
"llm.model.layers.3.self_attn.q_proj.weight": "model-00001-of-00004.safetensors",
|
| 545 |
+
"llm.model.layers.3.self_attn.v_proj.bias": "model-00001-of-00004.safetensors",
|
| 546 |
+
"llm.model.layers.3.self_attn.v_proj.weight": "model-00001-of-00004.safetensors",
|
| 547 |
+
"llm.model.layers.4.input_layernorm.weight": "model-00001-of-00004.safetensors",
|
| 548 |
+
"llm.model.layers.4.mlp.down_proj.weight": "model-00001-of-00004.safetensors",
|
| 549 |
+
"llm.model.layers.4.mlp.gate_proj.weight": "model-00001-of-00004.safetensors",
|
| 550 |
+
"llm.model.layers.4.mlp.up_proj.weight": "model-00001-of-00004.safetensors",
|
| 551 |
+
"llm.model.layers.4.post_attention_layernorm.weight": "model-00001-of-00004.safetensors",
|
| 552 |
+
"llm.model.layers.4.self_attn.k_proj.bias": "model-00001-of-00004.safetensors",
|
| 553 |
+
"llm.model.layers.4.self_attn.k_proj.weight": "model-00001-of-00004.safetensors",
|
| 554 |
+
"llm.model.layers.4.self_attn.o_proj.weight": "model-00001-of-00004.safetensors",
|
| 555 |
+
"llm.model.layers.4.self_attn.q_proj.bias": "model-00001-of-00004.safetensors",
|
| 556 |
+
"llm.model.layers.4.self_attn.q_proj.weight": "model-00001-of-00004.safetensors",
|
| 557 |
+
"llm.model.layers.4.self_attn.v_proj.bias": "model-00001-of-00004.safetensors",
|
| 558 |
+
"llm.model.layers.4.self_attn.v_proj.weight": "model-00001-of-00004.safetensors",
|
| 559 |
+
"llm.model.layers.5.input_layernorm.weight": "model-00001-of-00004.safetensors",
|
| 560 |
+
"llm.model.layers.5.mlp.down_proj.weight": "model-00001-of-00004.safetensors",
|
| 561 |
+
"llm.model.layers.5.mlp.gate_proj.weight": "model-00001-of-00004.safetensors",
|
| 562 |
+
"llm.model.layers.5.mlp.up_proj.weight": "model-00001-of-00004.safetensors",
|
| 563 |
+
"llm.model.layers.5.post_attention_layernorm.weight": "model-00001-of-00004.safetensors",
|
| 564 |
+
"llm.model.layers.5.self_attn.k_proj.bias": "model-00001-of-00004.safetensors",
|
| 565 |
+
"llm.model.layers.5.self_attn.k_proj.weight": "model-00001-of-00004.safetensors",
|
| 566 |
+
"llm.model.layers.5.self_attn.o_proj.weight": "model-00001-of-00004.safetensors",
|
| 567 |
+
"llm.model.layers.5.self_attn.q_proj.bias": "model-00001-of-00004.safetensors",
|
| 568 |
+
"llm.model.layers.5.self_attn.q_proj.weight": "model-00001-of-00004.safetensors",
|
| 569 |
+
"llm.model.layers.5.self_attn.v_proj.bias": "model-00001-of-00004.safetensors",
|
| 570 |
+
"llm.model.layers.5.self_attn.v_proj.weight": "model-00001-of-00004.safetensors",
|
| 571 |
+
"llm.model.layers.6.input_layernorm.weight": "model-00001-of-00004.safetensors",
|
| 572 |
+
"llm.model.layers.6.mlp.down_proj.weight": "model-00001-of-00004.safetensors",
|
| 573 |
+
"llm.model.layers.6.mlp.gate_proj.weight": "model-00001-of-00004.safetensors",
|
| 574 |
+
"llm.model.layers.6.mlp.up_proj.weight": "model-00001-of-00004.safetensors",
|
| 575 |
+
"llm.model.layers.6.post_attention_layernorm.weight": "model-00001-of-00004.safetensors",
|
| 576 |
+
"llm.model.layers.6.self_attn.k_proj.bias": "model-00001-of-00004.safetensors",
|
| 577 |
+
"llm.model.layers.6.self_attn.k_proj.weight": "model-00001-of-00004.safetensors",
|
| 578 |
+
"llm.model.layers.6.self_attn.o_proj.weight": "model-00001-of-00004.safetensors",
|
| 579 |
+
"llm.model.layers.6.self_attn.q_proj.bias": "model-00001-of-00004.safetensors",
|
| 580 |
+
"llm.model.layers.6.self_attn.q_proj.weight": "model-00001-of-00004.safetensors",
|
| 581 |
+
"llm.model.layers.6.self_attn.v_proj.bias": "model-00001-of-00004.safetensors",
|
| 582 |
+
"llm.model.layers.6.self_attn.v_proj.weight": "model-00001-of-00004.safetensors",
|
| 583 |
+
"llm.model.layers.7.input_layernorm.weight": "model-00001-of-00004.safetensors",
|
| 584 |
+
"llm.model.layers.7.mlp.down_proj.weight": "model-00001-of-00004.safetensors",
|
| 585 |
+
"llm.model.layers.7.mlp.gate_proj.weight": "model-00001-of-00004.safetensors",
|
| 586 |
+
"llm.model.layers.7.mlp.up_proj.weight": "model-00001-of-00004.safetensors",
|
| 587 |
+
"llm.model.layers.7.post_attention_layernorm.weight": "model-00001-of-00004.safetensors",
|
| 588 |
+
"llm.model.layers.7.self_attn.k_proj.bias": "model-00001-of-00004.safetensors",
|
| 589 |
+
"llm.model.layers.7.self_attn.k_proj.weight": "model-00001-of-00004.safetensors",
|
| 590 |
+
"llm.model.layers.7.self_attn.o_proj.weight": "model-00001-of-00004.safetensors",
|
| 591 |
+
"llm.model.layers.7.self_attn.q_proj.bias": "model-00001-of-00004.safetensors",
|
| 592 |
+
"llm.model.layers.7.self_attn.q_proj.weight": "model-00001-of-00004.safetensors",
|
| 593 |
+
"llm.model.layers.7.self_attn.v_proj.bias": "model-00001-of-00004.safetensors",
|
| 594 |
+
"llm.model.layers.7.self_attn.v_proj.weight": "model-00001-of-00004.safetensors",
|
| 595 |
+
"llm.model.layers.8.input_layernorm.weight": "model-00002-of-00004.safetensors",
|
| 596 |
+
"llm.model.layers.8.mlp.down_proj.weight": "model-00002-of-00004.safetensors",
|
| 597 |
+
"llm.model.layers.8.mlp.gate_proj.weight": "model-00002-of-00004.safetensors",
|
| 598 |
+
"llm.model.layers.8.mlp.up_proj.weight": "model-00002-of-00004.safetensors",
|
| 599 |
+
"llm.model.layers.8.post_attention_layernorm.weight": "model-00002-of-00004.safetensors",
|
| 600 |
+
"llm.model.layers.8.self_attn.k_proj.bias": "model-00001-of-00004.safetensors",
|
| 601 |
+
"llm.model.layers.8.self_attn.k_proj.weight": "model-00001-of-00004.safetensors",
|
| 602 |
+
"llm.model.layers.8.self_attn.o_proj.weight": "model-00001-of-00004.safetensors",
|
| 603 |
+
"llm.model.layers.8.self_attn.q_proj.bias": "model-00001-of-00004.safetensors",
|
| 604 |
+
"llm.model.layers.8.self_attn.q_proj.weight": "model-00001-of-00004.safetensors",
|
| 605 |
+
"llm.model.layers.8.self_attn.v_proj.bias": "model-00001-of-00004.safetensors",
|
| 606 |
+
"llm.model.layers.8.self_attn.v_proj.weight": "model-00001-of-00004.safetensors",
|
| 607 |
+
"llm.model.layers.9.input_layernorm.weight": "model-00002-of-00004.safetensors",
|
| 608 |
+
"llm.model.layers.9.mlp.down_proj.weight": "model-00002-of-00004.safetensors",
|
| 609 |
+
"llm.model.layers.9.mlp.gate_proj.weight": "model-00002-of-00004.safetensors",
|
| 610 |
+
"llm.model.layers.9.mlp.up_proj.weight": "model-00002-of-00004.safetensors",
|
| 611 |
+
"llm.model.layers.9.post_attention_layernorm.weight": "model-00002-of-00004.safetensors",
|
| 612 |
+
"llm.model.layers.9.self_attn.k_proj.bias": "model-00002-of-00004.safetensors",
|
| 613 |
+
"llm.model.layers.9.self_attn.k_proj.weight": "model-00002-of-00004.safetensors",
|
| 614 |
+
"llm.model.layers.9.self_attn.o_proj.weight": "model-00002-of-00004.safetensors",
|
| 615 |
+
"llm.model.layers.9.self_attn.q_proj.bias": "model-00002-of-00004.safetensors",
|
| 616 |
+
"llm.model.layers.9.self_attn.q_proj.weight": "model-00002-of-00004.safetensors",
|
| 617 |
+
"llm.model.layers.9.self_attn.v_proj.bias": "model-00002-of-00004.safetensors",
|
| 618 |
+
"llm.model.layers.9.self_attn.v_proj.weight": "model-00002-of-00004.safetensors",
|
| 619 |
+
"llm.model.norm.weight": "model-00003-of-00004.safetensors",
|
| 620 |
+
"vision_embedding.out_proj.weight": "model-00004-of-00004.safetensors",
|
| 621 |
+
"vision_embedding.patchifier.norm.weight": "model-00004-of-00004.safetensors",
|
| 622 |
+
"vision_embedding.patchifier.proj.bias": "model-00004-of-00004.safetensors",
|
| 623 |
+
"vision_embedding.patchifier.proj.weight": "model-00004-of-00004.safetensors",
|
| 624 |
+
"vision_embedding.pos_embed": "model-00004-of-00004.safetensors"
|
| 625 |
+
}
|
| 626 |
+
}
|
modeling_vora.py
ADDED
|
@@ -0,0 +1,289 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import torch
|
| 2 |
+
import torch.distributed as dist
|
| 3 |
+
from transformers import (
|
| 4 |
+
AutoModelForCausalLM,
|
| 5 |
+
AutoTokenizer,
|
| 6 |
+
PreTrainedModel,
|
| 7 |
+
PretrainedConfig,
|
| 8 |
+
)
|
| 9 |
+
|
| 10 |
+
from .attention_mask import make_mask
|
| 11 |
+
from .configuration_vora import VoRAConfig
|
| 12 |
+
from .vision_embedding import * # hacking, let transformers find vision_embedding
|
| 13 |
+
from . import vision_embedding as VB
|
| 14 |
+
from .lora import apply_lora
|
| 15 |
+
from .vora_generation_utils import (
|
| 16 |
+
VoraGenerationMixin,
|
| 17 |
+
custom_prepare_4d_causal_attention_mask_with_cache_position,
|
| 18 |
+
)
|
| 19 |
+
|
| 20 |
+
try:
|
| 21 |
+
from utils import logging
|
| 22 |
+
except:
|
| 23 |
+
from transformers.utils import logging
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
logger = logging.get_logger(__name__)
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
class VoRAForCausalLM(PreTrainedModel):
|
| 30 |
+
config_class = VoRAConfig
|
| 31 |
+
_auto_class = 'AutoModelForCausalLM'
|
| 32 |
+
supports_gradient_checkpointing = True
|
| 33 |
+
supports_report_metrics: bool = True
|
| 34 |
+
|
| 35 |
+
def __init__(self, config: PretrainedConfig = VoRAConfig()):
|
| 36 |
+
super().__init__(config)
|
| 37 |
+
self.config = config
|
| 38 |
+
# -------------- Setup LLM ---------------------
|
| 39 |
+
self.llm = AutoModelForCausalLM.from_pretrained(config.llm)
|
| 40 |
+
self.tokenizer = AutoTokenizer.from_pretrained(config.llm)
|
| 41 |
+
self.llm.__class__ = type(self.llm.__class__.__name__, (self.llm.__class__, VoraGenerationMixin), {})
|
| 42 |
+
self.llm.model._prepare_4d_causal_attention_mask_with_cache_position = staticmethod(custom_prepare_4d_causal_attention_mask_with_cache_position)
|
| 43 |
+
|
| 44 |
+
self.config.update(self.llm.config.to_dict())
|
| 45 |
+
|
| 46 |
+
# -------------- Setup LoRA -------------------
|
| 47 |
+
if config.lora:
|
| 48 |
+
for _, param in self.llm.named_parameters():
|
| 49 |
+
param.requires_grad = False
|
| 50 |
+
apply_lora(self.llm, config.lora)
|
| 51 |
+
# ----------------------------------------------
|
| 52 |
+
|
| 53 |
+
# ------------ Setup Vision Embedding ----------
|
| 54 |
+
self.vision_embedding = getattr(VB, config.vision_embedding)(self.config) # setup after llm so that we know the hiddensize
|
| 55 |
+
# ----------------------------------------------
|
| 56 |
+
|
| 57 |
+
# ------------- Setup Aux Vision ---------------
|
| 58 |
+
self.enable_aux_vision = False
|
| 59 |
+
if config.aux_vision:
|
| 60 |
+
from .aux_vision import AuxVision
|
| 61 |
+
self.enable_aux_vision = True
|
| 62 |
+
self.aux_vision = AuxVision(self.config)
|
| 63 |
+
if config.reuse_aux_vision_embedding_layers:
|
| 64 |
+
weights = getattr(self.aux_vision.aux_model, config.reuse_aux_vision_embedding_layers).state_dict()
|
| 65 |
+
msg = self.vision_embedding.load_state_dict(weights, strict=False)
|
| 66 |
+
logger.info(f"Loaded aux vision weights: {msg}")
|
| 67 |
+
# ----------------------------------------------
|
| 68 |
+
# print trainable prameters and total parameters so that we can check if we are loading the correct model
|
| 69 |
+
logger.info("Trainable parameters:")
|
| 70 |
+
for name, param in self.named_parameters():
|
| 71 |
+
if param.requires_grad:
|
| 72 |
+
logger.info(f"{name}: {param.numel()}")
|
| 73 |
+
logger.info(f"Total parameters: {sum(p.numel() for p in self.parameters())}")
|
| 74 |
+
|
| 75 |
+
def detach_and_gather_loss(self, loss, dtype, device):
|
| 76 |
+
if not dist.is_initialized():
|
| 77 |
+
return loss.item()
|
| 78 |
+
gathered_loss = [torch.tensor(0.0, dtype=loss.dtype).to(device) for _ in range(dist.get_world_size())]
|
| 79 |
+
dist.all_gather(gathered_loss, loss.detach().clone())
|
| 80 |
+
avg_gathered_loss = torch.mean(torch.stack(gathered_loss))
|
| 81 |
+
return avg_gathered_loss.item()
|
| 82 |
+
|
| 83 |
+
def _encode_vision(self, images, n_frames):
|
| 84 |
+
# TODO: we need a more elegant way here to deal with mixed image and pure text training
|
| 85 |
+
if images.size(0) > 0:
|
| 86 |
+
vision_embeds = self.vision_embedding(images)
|
| 87 |
+
else:
|
| 88 |
+
# FIXME: hacking for deepspeed training
|
| 89 |
+
# we feed a dummy image tensor (1, 3, H, W) into vision_encoder when training a pure-text batch
|
| 90 |
+
images = images.new_zeros((1, *images.shape[1:]))
|
| 91 |
+
vision_embeds = self.vision_embedding(images)[0:0]
|
| 92 |
+
vision_embeds = vision_embeds.split(n_frames, dim=0)
|
| 93 |
+
attention_mask = [torch.ones(feature.size()[:-1], dtype=torch.long).to(feature.device) for feature in vision_embeds]
|
| 94 |
+
vision_targets = [torch.ones(feature.size(), dtype=torch.long).to(feature.device).fill_(-100) for feature in attention_mask]
|
| 95 |
+
|
| 96 |
+
image_shapes = images.shape[-2:]
|
| 97 |
+
|
| 98 |
+
return vision_embeds, attention_mask, vision_targets, image_shapes
|
| 99 |
+
|
| 100 |
+
def _concat_embedding(self, vision_encode_out, batch, vision_placeholder_index, left_padding=False):
|
| 101 |
+
""" concat vision and text
|
| 102 |
+
"""
|
| 103 |
+
|
| 104 |
+
vision_embeds, vision_atts, vision_targets, _ = vision_encode_out
|
| 105 |
+
|
| 106 |
+
input_embeds = []
|
| 107 |
+
attention_mask = []
|
| 108 |
+
targets = []
|
| 109 |
+
vision_mask = [] # set vision token as 1, text token as 0
|
| 110 |
+
|
| 111 |
+
for cur_batch_idx, cur_input_ids in enumerate(batch["input_ids"]):
|
| 112 |
+
cur_vision_embeds = vision_embeds[cur_batch_idx]
|
| 113 |
+
cur_vision_attn = vision_atts[cur_batch_idx]
|
| 114 |
+
cur_vision_targets = vision_targets[cur_batch_idx]
|
| 115 |
+
cur_attn_masks = batch["attention_mask"][cur_batch_idx]
|
| 116 |
+
|
| 117 |
+
image_token_indices = torch.where(cur_input_ids == vision_placeholder_index)[0]
|
| 118 |
+
cur_image_num = len(image_token_indices)
|
| 119 |
+
image_token_indices = list(image_token_indices) + [cur_input_ids.shape[0]]
|
| 120 |
+
|
| 121 |
+
cur_input_embeds = []
|
| 122 |
+
cur_attention_mask = []
|
| 123 |
+
cur_target = []
|
| 124 |
+
cur_vision_mask = []
|
| 125 |
+
|
| 126 |
+
# convert text before 1st <image> to embedding
|
| 127 |
+
image_token_index = image_token_indices[0]
|
| 128 |
+
|
| 129 |
+
cur_input_embeds.append(
|
| 130 |
+
self.llm.get_input_embeddings()(cur_input_ids[:image_token_index]),
|
| 131 |
+
)
|
| 132 |
+
cur_attention_mask.append(
|
| 133 |
+
cur_attn_masks[:image_token_index],
|
| 134 |
+
)
|
| 135 |
+
cur_vision_mask.append(
|
| 136 |
+
torch.zeros_like(cur_attn_masks[:image_token_index]).to(cur_attn_masks.device),
|
| 137 |
+
)
|
| 138 |
+
if "labels" in batch:
|
| 139 |
+
cur_target.append(
|
| 140 |
+
batch["labels"][cur_batch_idx, :image_token_index],
|
| 141 |
+
)
|
| 142 |
+
|
| 143 |
+
if batch.get("vison_placeholder_mode", 0) == 1:
|
| 144 |
+
assert cur_image_num <= 1, "multiple video input is not supported"
|
| 145 |
+
cur_vision_embeds = cur_vision_embeds.unsqueeze(0)
|
| 146 |
+
cur_vision_attn = cur_vision_attn.unsqueeze(0)
|
| 147 |
+
cur_vision_targets = cur_vision_targets.unsqueeze(0)
|
| 148 |
+
assert cur_image_num == len(cur_vision_embeds), \
|
| 149 |
+
f"Size mismatch! cur_image_num: {cur_image_num}, len(cur_vision_embeds): {len(cur_vision_embeds)} {len(cur_vision_embeds)} \
|
| 150 |
+
in {batch['prompt'][cur_batch_idx]} & {batch['gt'][cur_batch_idx]} & {batch['input_ids'][cur_batch_idx]}"
|
| 151 |
+
# convert each <image> xxx group into embedding
|
| 152 |
+
text_embedding = self.llm.get_input_embeddings()(cur_input_ids.relu())
|
| 153 |
+
for i in range(0, cur_image_num):
|
| 154 |
+
image_token_index = image_token_indices[i]
|
| 155 |
+
cur_input_embeds.extend([
|
| 156 |
+
cur_vision_embeds[i],
|
| 157 |
+
text_embedding[image_token_index+1:image_token_indices[i+1]]
|
| 158 |
+
])
|
| 159 |
+
cur_attention_mask.extend([
|
| 160 |
+
cur_vision_attn[i],
|
| 161 |
+
cur_attn_masks[image_token_index+1:image_token_indices[i+1]]
|
| 162 |
+
])
|
| 163 |
+
cur_vision_mask.extend([
|
| 164 |
+
torch.ones_like(cur_vision_attn[i]).to(cur_vision_attn[i].device),
|
| 165 |
+
torch.zeros_like(cur_attn_masks[image_token_index+1:image_token_indices[i+1]]).to(cur_vision_attn[i].device),
|
| 166 |
+
])
|
| 167 |
+
if "labels" in batch:
|
| 168 |
+
cur_target.extend([
|
| 169 |
+
cur_vision_targets[i],
|
| 170 |
+
batch["labels"][cur_batch_idx, image_token_index+1:image_token_indices[i+1]],
|
| 171 |
+
])
|
| 172 |
+
|
| 173 |
+
input_embeds.append(torch.cat(cur_input_embeds))
|
| 174 |
+
attention_mask.append(torch.cat(cur_attention_mask))
|
| 175 |
+
vision_mask.append(torch.cat(cur_vision_mask))
|
| 176 |
+
if "labels" in batch:
|
| 177 |
+
targets.append(torch.cat(cur_target))
|
| 178 |
+
|
| 179 |
+
# padding
|
| 180 |
+
n_tokens = [embed.shape[0] for embed in input_embeds]
|
| 181 |
+
|
| 182 |
+
max_token = max(n_tokens)
|
| 183 |
+
|
| 184 |
+
for i in range(len(input_embeds)):
|
| 185 |
+
if max_token > n_tokens[i]:
|
| 186 |
+
self.pad_id = self.tokenizer.pad_token_id or self.tokenizer.eos_token_id
|
| 187 |
+
pad_token = torch.tensor([self.pad_id] * (max_token - n_tokens[i]))
|
| 188 |
+
pad_embedding = self.llm.get_input_embeddings()(pad_token.to(batch["attention_mask"][i].device))
|
| 189 |
+
pad_attention = torch.zeros(pad_embedding.shape[0], dtype=torch.long).to(batch["attention_mask"][i].device)
|
| 190 |
+
pad_targets = torch.ones(pad_attention.size(), dtype=torch.long).to(batch["attention_mask"][i].device).fill_(-100)
|
| 191 |
+
|
| 192 |
+
if left_padding:
|
| 193 |
+
input_embeds[i] = torch.cat([pad_embedding, input_embeds[i]])
|
| 194 |
+
attention_mask[i] = torch.cat([pad_attention, attention_mask[i]])
|
| 195 |
+
vision_mask[i] = torch.cat([pad_attention, vision_mask[i]])
|
| 196 |
+
if "labels" in batch:
|
| 197 |
+
targets[i] = torch.cat([pad_targets, targets[i]])
|
| 198 |
+
else:
|
| 199 |
+
input_embeds[i] = torch.cat([input_embeds[i], pad_embedding])
|
| 200 |
+
attention_mask[i] = torch.cat([attention_mask[i], pad_attention])
|
| 201 |
+
vision_mask[i] = torch.cat([vision_mask[i], pad_attention])
|
| 202 |
+
if "labels" in batch:
|
| 203 |
+
targets[i] = torch.cat([targets[i], pad_targets])
|
| 204 |
+
|
| 205 |
+
inputs_embeds = torch.stack(input_embeds, dim=0).type(self.llm.dtype)
|
| 206 |
+
attention_mask = torch.stack(attention_mask, dim=0)
|
| 207 |
+
vision_mask = torch.stack(vision_mask, dim=0).to(attention_mask.device)
|
| 208 |
+
|
| 209 |
+
if len(targets) > 0:
|
| 210 |
+
targets = torch.stack(targets, dim=0)
|
| 211 |
+
|
| 212 |
+
attention_mask = make_mask(
|
| 213 |
+
attention_mask,
|
| 214 |
+
mode=self.config.vision_attention_mask,
|
| 215 |
+
vision_mask=vision_mask,
|
| 216 |
+
dtype=inputs_embeds.dtype
|
| 217 |
+
)
|
| 218 |
+
|
| 219 |
+
return inputs_embeds, attention_mask, targets, vision_mask
|
| 220 |
+
|
| 221 |
+
def forward(self, **batch):
|
| 222 |
+
# -------------- Vision/Text Embedding ----------
|
| 223 |
+
vision_placeholder_index = batch.pop("vision_placeholder_index")
|
| 224 |
+
images, n_frames = batch["frames"], batch["n_frames"]
|
| 225 |
+
vision_encode_out = self._encode_vision(images, n_frames)
|
| 226 |
+
inputs_embeds, attention_mask, targets, vision_mask = self._concat_embedding(
|
| 227 |
+
vision_encode_out, batch, vision_placeholder_index)
|
| 228 |
+
# -----------------------------------------------
|
| 229 |
+
|
| 230 |
+
outputs = self.llm(
|
| 231 |
+
inputs_embeds=inputs_embeds,
|
| 232 |
+
attention_mask=attention_mask,
|
| 233 |
+
labels=targets,
|
| 234 |
+
return_dict=True,
|
| 235 |
+
output_hidden_states=True,
|
| 236 |
+
)
|
| 237 |
+
|
| 238 |
+
llm_loss = outputs.loss
|
| 239 |
+
device = llm_loss.device
|
| 240 |
+
dtype = llm_loss.dtype
|
| 241 |
+
|
| 242 |
+
metrics = {}
|
| 243 |
+
|
| 244 |
+
metrics["llm_loss"] = self.detach_and_gather_loss(llm_loss, dtype, device)
|
| 245 |
+
if self.enable_aux_vision:
|
| 246 |
+
if images.size(0) > 0:
|
| 247 |
+
aux_losses = self.aux_vision(images, outputs.hidden_states, vision_mask)
|
| 248 |
+
else:
|
| 249 |
+
# FIXME: hacking for deepspeed training
|
| 250 |
+
aux_losses = {key: torch.tensor(0., dtype=dtype).to(device) for key in self.aux_vision.loss_keys}
|
| 251 |
+
|
| 252 |
+
aux_loss = torch.tensor(0., dtype=dtype).to(device)
|
| 253 |
+
n_aux = 0
|
| 254 |
+
for _aux_key, _aux_loss in aux_losses.items():
|
| 255 |
+
aux_loss += _aux_loss
|
| 256 |
+
n_aux += 1
|
| 257 |
+
metrics[_aux_key] = self.detach_and_gather_loss(_aux_loss, dtype, device)
|
| 258 |
+
aux_loss /= n_aux
|
| 259 |
+
|
| 260 |
+
outputs.loss = aux_loss + llm_loss
|
| 261 |
+
metrics["total_loss"] = self.detach_and_gather_loss(outputs.loss, dtype, device)
|
| 262 |
+
self.report_metrics(**metrics)
|
| 263 |
+
|
| 264 |
+
return outputs
|
| 265 |
+
|
| 266 |
+
def generate(self, batch, **generate_params):
|
| 267 |
+
|
| 268 |
+
with torch.amp.autocast(
|
| 269 |
+
enabled=(self.device != torch.device("cpu")),
|
| 270 |
+
device_type=self.device.type,
|
| 271 |
+
):
|
| 272 |
+
# get vision token
|
| 273 |
+
vision_placeholder_index = batch.pop("vision_placeholder_index")
|
| 274 |
+
|
| 275 |
+
# get vision features
|
| 276 |
+
images, n_frames = batch["frames"], batch["n_frames"]
|
| 277 |
+
vision_encode_out = self._encode_vision(images, n_frames)
|
| 278 |
+
|
| 279 |
+
inputs_embeds, attention_mask, _, _ = self._concat_embedding(
|
| 280 |
+
vision_encode_out, batch, vision_placeholder_index, left_padding=False)
|
| 281 |
+
|
| 282 |
+
outputs = self.llm.generate(
|
| 283 |
+
inputs_embeds=inputs_embeds,
|
| 284 |
+
attention_mask=attention_mask,
|
| 285 |
+
output_attentions=True,
|
| 286 |
+
**generate_params
|
| 287 |
+
)
|
| 288 |
+
|
| 289 |
+
return outputs
|
preprocessor_config.json
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"crop_size": 224,
|
| 3 |
+
"do_center_crop": true,
|
| 4 |
+
"do_normalize": true,
|
| 5 |
+
"do_resize": true,
|
| 6 |
+
"feature_extractor_type": "CLIPFeatureExtractor",
|
| 7 |
+
"image_mean": [
|
| 8 |
+
0.48145466,
|
| 9 |
+
0.4578275,
|
| 10 |
+
0.40821073
|
| 11 |
+
],
|
| 12 |
+
"image_std": [
|
| 13 |
+
0.26862954,
|
| 14 |
+
0.26130258,
|
| 15 |
+
0.27577711
|
| 16 |
+
],
|
| 17 |
+
"resample": 3,
|
| 18 |
+
"size": 224
|
| 19 |
+
}
|
processing_vora.py
ADDED
|
@@ -0,0 +1,150 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import torch
|
| 2 |
+
|
| 3 |
+
from typing import List, Union
|
| 4 |
+
from PIL import Image
|
| 5 |
+
|
| 6 |
+
from transformers.feature_extraction_utils import BatchFeature
|
| 7 |
+
from transformers.image_utils import ImageInput
|
| 8 |
+
from transformers.processing_utils import ProcessingKwargs, ProcessorMixin, Unpack, _validate_images_text_input_order
|
| 9 |
+
from transformers.tokenization_utils_base import PreTokenizedInput, TextInput
|
| 10 |
+
|
| 11 |
+
from .modeling_vora import VoRAForCausalLM
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
class VoRAProcessorKwargs(ProcessingKwargs, total=False):
|
| 15 |
+
_defaults = {
|
| 16 |
+
"text_kwargs": {
|
| 17 |
+
"padding": False,
|
| 18 |
+
},
|
| 19 |
+
"images_kwargs": {},
|
| 20 |
+
}
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
class VoRAProcesser(ProcessorMixin):
|
| 24 |
+
attributes = ["image_processor", "tokenizer"]
|
| 25 |
+
valid_kwargs = [
|
| 26 |
+
"chat_template",
|
| 27 |
+
"image_token",
|
| 28 |
+
]
|
| 29 |
+
image_processor_class = "AutoImageProcessor"
|
| 30 |
+
tokenizer_class = "AutoTokenizer"
|
| 31 |
+
|
| 32 |
+
def __init__(
|
| 33 |
+
self,
|
| 34 |
+
image_processor=None,
|
| 35 |
+
tokenizer=None,
|
| 36 |
+
chat_template=None,
|
| 37 |
+
image_token="<image>", # set the default and let users change if they have peculiar special tokens in rare cases
|
| 38 |
+
image_token_index = -200,
|
| 39 |
+
**kwargs,
|
| 40 |
+
):
|
| 41 |
+
self.image_token = image_token
|
| 42 |
+
self.image_token_index = image_token_index
|
| 43 |
+
super().__init__(image_processor, tokenizer, chat_template=chat_template)
|
| 44 |
+
|
| 45 |
+
def __call__(
|
| 46 |
+
self,
|
| 47 |
+
images: ImageInput = None,
|
| 48 |
+
text: Union[TextInput, PreTokenizedInput, List[TextInput], List[PreTokenizedInput]] = None,
|
| 49 |
+
**kwargs: Unpack[VoRAProcessorKwargs],
|
| 50 |
+
):
|
| 51 |
+
if images is None and text is None:
|
| 52 |
+
raise ValueError("You have to specify at least one of `images` or `text`.")
|
| 53 |
+
|
| 54 |
+
images, text = _validate_images_text_input_order(images, text)
|
| 55 |
+
output_kwargs = self._merge_kwargs(
|
| 56 |
+
VoRAProcessorKwargs,
|
| 57 |
+
tokenizer_init_kwargs=self.tokenizer.init_kwargs,
|
| 58 |
+
**kwargs,
|
| 59 |
+
)
|
| 60 |
+
|
| 61 |
+
if images is not None:
|
| 62 |
+
images = [[self.expand2square(image[0])] for image in images]
|
| 63 |
+
image_inputs = self.image_processor(images, **output_kwargs["images_kwargs"])
|
| 64 |
+
else:
|
| 65 |
+
image_inputs = {}
|
| 66 |
+
|
| 67 |
+
if isinstance(text, str):
|
| 68 |
+
text = [text]
|
| 69 |
+
elif not isinstance(text, list) and not isinstance(text[0], str):
|
| 70 |
+
raise ValueError("Invalid input text. Please provide a string, or a list of strings")
|
| 71 |
+
|
| 72 |
+
input_ids = [self.tokenizer_vision_placeholder(t) for t in text]
|
| 73 |
+
attention_mask = [
|
| 74 |
+
[1] * len(input_ids[i]) for i in range(len(input_ids))
|
| 75 |
+
]
|
| 76 |
+
|
| 77 |
+
text_inputs = dict(
|
| 78 |
+
input_ids=torch.as_tensor(input_ids, dtype=torch.int64),
|
| 79 |
+
attention_mask=torch.as_tensor(attention_mask, dtype=torch.int64),
|
| 80 |
+
)
|
| 81 |
+
image_inputs['frames'] = image_inputs.pop('pixel_values')
|
| 82 |
+
image_inputs['n_frames'] = [len(_images) for _images in images]
|
| 83 |
+
image_inputs['vision_placeholder_index'] = self.image_token_index
|
| 84 |
+
return BatchFeature(data={**text_inputs, **image_inputs})
|
| 85 |
+
|
| 86 |
+
def expand2square(self, pil_img: Image.Image):
|
| 87 |
+
background_color = (0, 0, 0)
|
| 88 |
+
width, height = pil_img.size
|
| 89 |
+
if width == height:
|
| 90 |
+
return pil_img
|
| 91 |
+
elif width > height:
|
| 92 |
+
result = Image.new(pil_img.mode, (width, width), background_color)
|
| 93 |
+
result.paste(pil_img, (0, (width - height) // 2))
|
| 94 |
+
return result
|
| 95 |
+
else:
|
| 96 |
+
result = Image.new(pil_img.mode, (height, height), background_color)
|
| 97 |
+
result.paste(pil_img, ((height - width) // 2, 0))
|
| 98 |
+
return result
|
| 99 |
+
|
| 100 |
+
def tokenizer_vision_placeholder(self, prompt, add_bos=False):
|
| 101 |
+
def join_lists(*lists, sep):
|
| 102 |
+
result = []
|
| 103 |
+
for i, lst in enumerate(lists):
|
| 104 |
+
if i > 0 and sep:
|
| 105 |
+
result.extend([sep])
|
| 106 |
+
result.extend(lst)
|
| 107 |
+
return result
|
| 108 |
+
|
| 109 |
+
prompt_chunks = [self.tokenizer.encode(
|
| 110 |
+
chunk) for chunk in prompt.split(self.image_token)]
|
| 111 |
+
input_ids = join_lists(*prompt_chunks, sep=self.image_token_index)
|
| 112 |
+
if add_bos:
|
| 113 |
+
input_ids = [self.tokenizer.bos_token_id] + input_ids
|
| 114 |
+
|
| 115 |
+
return input_ids
|
| 116 |
+
|
| 117 |
+
|
| 118 |
+
if __name__ == '__main__':
|
| 119 |
+
import torch
|
| 120 |
+
from transformers import AutoProcessor, AutoModelForCausalLM
|
| 121 |
+
|
| 122 |
+
model_name = "/mnt/bn/wh-data/open_source/models/VoRA-7B-Instruct"
|
| 123 |
+
processor = AutoProcessor.from_pretrained(model_name, trust_remote_code=True)
|
| 124 |
+
model = AutoModelForCausalLM.from_pretrained(model_name, trust_remote_code=True)
|
| 125 |
+
|
| 126 |
+
conversation = [
|
| 127 |
+
{
|
| 128 |
+
"role":"user",
|
| 129 |
+
"content":[
|
| 130 |
+
{
|
| 131 |
+
"type":"image",
|
| 132 |
+
"url": "/mnt/bn/wh-data/data/datasets/a_demo/frames/35.jpg"
|
| 133 |
+
},
|
| 134 |
+
{
|
| 135 |
+
"type":"text",
|
| 136 |
+
"text":"<image> Describe this image."
|
| 137 |
+
}
|
| 138 |
+
]
|
| 139 |
+
}
|
| 140 |
+
]
|
| 141 |
+
model_inputs = processor.apply_chat_template(conversation, add_generation_prompt=True, tokenize=True, return_tensors='pt', return_dict=True).to(model.device)
|
| 142 |
+
|
| 143 |
+
gen_kwargs = {"max_new_tokens": 1024, "pad_token_id": processor.tokenizer.eos_token_id}
|
| 144 |
+
|
| 145 |
+
with torch.inference_mode():
|
| 146 |
+
outputs = model.generate(model_inputs, **gen_kwargs)
|
| 147 |
+
output_text = processor.tokenizer.batch_decode(
|
| 148 |
+
outputs, skip_special_tokens=True
|
| 149 |
+
)
|
| 150 |
+
print(output_text)
|
processor_config.json
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"image_token": "<image>",
|
| 3 |
+
"image_token_index": -200,
|
| 4 |
+
"processor_class": "VoRAProcessing",
|
| 5 |
+
"auto_map": {"AutoProcessor": "processing_vora.VoRAProcesser"}
|
| 6 |
+
}
|
rng_state.pth
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:105f982ab14254bd10068585b2b517ad27a13743448d1886bf3871a930461347
|
| 3 |
+
size 14244
|
scheduler.pt
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:878ab278cdfa3fcccab62e0bd220524657c165f2dedfbcf20d4757c84c62d35f
|
| 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
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:9c5ae00e602b8860cbd784ba82a8aa14e8feecec692e7076590d014d7b7fdafa
|
| 3 |
+
size 11421896
|
tokenizer_config.json
ADDED
|
@@ -0,0 +1,209 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 Qwen, created by Alibaba Cloud. 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 Qwen, created by Alibaba Cloud. You 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 |
+
"extra_special_tokens": {},
|
| 203 |
+
"model_max_length": 131072,
|
| 204 |
+
"pad_token": "<|endoftext|>",
|
| 205 |
+
"processor_class": "VoRAProcessing",
|
| 206 |
+
"split_special_tokens": false,
|
| 207 |
+
"tokenizer_class": "Qwen2Tokenizer",
|
| 208 |
+
"unk_token": null
|
| 209 |
+
}
|
trainer_state.json
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
training_args.bin
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:7592ba5d7aa00b95a9d2f6cfba109c8e8d0e76fa4fd1f23a9dfb213893c4c1b4
|
| 3 |
+
size 7032
|
vision_embedding.py
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import torch
|
| 2 |
+
import torch.nn as nn
|
| 3 |
+
|
| 4 |
+
from .configuration_vora import VoRAConfig
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
class RMSNorm(nn.Module):
|
| 8 |
+
def __init__(self, dim: int, eps: float = 1e-6):
|
| 9 |
+
super().__init__()
|
| 10 |
+
self.weight = nn.Parameter(torch.ones(dim))
|
| 11 |
+
self.eps = eps
|
| 12 |
+
|
| 13 |
+
def forward(self, x: torch.Tensor) -> torch.Tensor:
|
| 14 |
+
output = self._norm(x.float()).type_as(x)
|
| 15 |
+
return output * self.weight
|
| 16 |
+
|
| 17 |
+
def extra_repr(self) -> str:
|
| 18 |
+
return f"{tuple(self.weight.shape)}, eps={self.eps}"
|
| 19 |
+
|
| 20 |
+
def _norm(self, x: torch.Tensor) -> torch.Tensor:
|
| 21 |
+
return x * torch.rsqrt(x.pow(2).mean(-1, keepdim=True) + self.eps)
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
class AIMv2PatchEmbed(nn.Module):
|
| 25 |
+
def __init__(self, config: VoRAConfig):
|
| 26 |
+
super().__init__()
|
| 27 |
+
self.proj = nn.Conv2d(
|
| 28 |
+
3,
|
| 29 |
+
config.vision_embedding_intermediate_size,
|
| 30 |
+
kernel_size=(config.patch_size, config.patch_size),
|
| 31 |
+
stride=(config.patch_size, config.patch_size),
|
| 32 |
+
)
|
| 33 |
+
self.norm = RMSNorm(config.vision_embedding_intermediate_size, eps=config.rms_norm_eps)
|
| 34 |
+
|
| 35 |
+
def forward(self, x: torch.Tensor) -> torch.Tensor:
|
| 36 |
+
x = self.proj(x).flatten(2).transpose(1, 2)
|
| 37 |
+
x = self.norm(x)
|
| 38 |
+
return x
|
| 39 |
+
|
| 40 |
+
|
| 41 |
+
class AIMv2Embedding(nn.Module):
|
| 42 |
+
def __init__(self,
|
| 43 |
+
config: VoRAConfig = None,
|
| 44 |
+
):
|
| 45 |
+
super().__init__()
|
| 46 |
+
hidden_size = config.hidden_size
|
| 47 |
+
num_patches = (config.image_size // config.patch_size) ** 2
|
| 48 |
+
self.config = config
|
| 49 |
+
|
| 50 |
+
self.patchifier = AIMv2PatchEmbed(config)
|
| 51 |
+
self.pos_embed = nn.Parameter(torch.zeros((1, num_patches, config.vision_embedding_intermediate_size)))
|
| 52 |
+
self.out_proj = nn.Linear(config.vision_embedding_intermediate_size, hidden_size, bias=False)
|
| 53 |
+
|
| 54 |
+
def forward(self, x: torch.Tensor) -> torch.Tensor:
|
| 55 |
+
B, C, H, W = x.shape
|
| 56 |
+
h_token = H // self.config.patch_size
|
| 57 |
+
w_token = W // self.config.patch_size
|
| 58 |
+
tokens = self.patchifier(x)
|
| 59 |
+
_, N, _ = tokens.shape
|
| 60 |
+
pos_embed = self.pos_embed.to(tokens.device)
|
| 61 |
+
|
| 62 |
+
if N <= pos_embed.size(1):
|
| 63 |
+
tokens = tokens + pos_embed[:, :N]
|
| 64 |
+
else:
|
| 65 |
+
pos_embed = pos_embed.view(1, int(pos_embed.size(1)**0.5), int(pos_embed.size(1)**0.5), -1).permute(0, 3, 1, 2)
|
| 66 |
+
pos_embed = nn.functional.interpolate(pos_embed, size=(h_token, w_token), mode='bilinear', align_corners=False).permute(0, 2, 3, 1)
|
| 67 |
+
pos_embed = pos_embed.view(1, N, pos_embed.size(-1))
|
| 68 |
+
tokens = tokens + pos_embed
|
| 69 |
+
|
| 70 |
+
return self.out_proj(tokens)
|
vocab.json
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
vora_generation_utils.py
ADDED
|
@@ -0,0 +1,101 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from typing import Any, Dict, Optional
|
| 2 |
+
|
| 3 |
+
import torch
|
| 4 |
+
from transformers import GenerationMixin
|
| 5 |
+
from transformers.cache_utils import Cache
|
| 6 |
+
from transformers.utils import ModelOutput
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
class VoraGenerationMixin(GenerationMixin):
|
| 10 |
+
|
| 11 |
+
def prepare_inputs_for_generation(
|
| 12 |
+
self,
|
| 13 |
+
input_ids: torch.LongTensor,
|
| 14 |
+
past_key_values: Optional[Cache] = None,
|
| 15 |
+
attention_mask: Optional[torch.LongTensor] = None,
|
| 16 |
+
inputs_embeds: Optional[torch.FloatTensor] = None,
|
| 17 |
+
cache_position: Optional[torch.LongTensor] = None,
|
| 18 |
+
**kwargs,
|
| 19 |
+
):
|
| 20 |
+
if attention_mask is not None and attention_mask.ndim == 4:
|
| 21 |
+
attention_mask_2d = (attention_mask[:, 0, :, :] == 0).any(dim=1).long().to(attention_mask.device)
|
| 22 |
+
model_input = super().prepare_inputs_for_generation(
|
| 23 |
+
input_ids,
|
| 24 |
+
past_key_values=past_key_values,
|
| 25 |
+
attention_mask=attention_mask_2d,
|
| 26 |
+
inputs_embeds=inputs_embeds,
|
| 27 |
+
cache_position=cache_position,
|
| 28 |
+
**kwargs,
|
| 29 |
+
)
|
| 30 |
+
model_input['attention_mask'] = attention_mask
|
| 31 |
+
return model_input
|
| 32 |
+
else:
|
| 33 |
+
return super().prepare_inputs_for_generation(
|
| 34 |
+
input_ids,
|
| 35 |
+
past_key_values=past_key_values,
|
| 36 |
+
attention_mask=attention_mask,
|
| 37 |
+
inputs_embeds=inputs_embeds,
|
| 38 |
+
cache_position=cache_position,
|
| 39 |
+
**kwargs,
|
| 40 |
+
)
|
| 41 |
+
|
| 42 |
+
def _update_model_kwargs_for_generation(
|
| 43 |
+
self,
|
| 44 |
+
outputs: ModelOutput,
|
| 45 |
+
model_kwargs: Dict[str, Any],
|
| 46 |
+
is_encoder_decoder: bool = False,
|
| 47 |
+
num_new_tokens: int = 1,
|
| 48 |
+
) -> Dict[str, Any]:
|
| 49 |
+
if "attention_mask" in model_kwargs and model_kwargs["attention_mask"].ndim == 4:
|
| 50 |
+
attention_mask = model_kwargs.pop("attention_mask")
|
| 51 |
+
model_kwargs = super()._update_model_kwargs_for_generation(
|
| 52 |
+
outputs, model_kwargs, is_encoder_decoder=is_encoder_decoder, num_new_tokens=num_new_tokens
|
| 53 |
+
)
|
| 54 |
+
bs, _, seq_len, tgt_len = attention_mask.shape
|
| 55 |
+
dtype = attention_mask.dtype
|
| 56 |
+
min_dtype = torch.finfo(dtype).min
|
| 57 |
+
new_col = attention_mask.new_zeros((bs, 1, seq_len, 1)).fill_(min_dtype)
|
| 58 |
+
new_row = attention_mask.new_zeros((bs, 1, 1, tgt_len + 1))
|
| 59 |
+
model_kwargs["attention_mask"] = torch.cat([
|
| 60 |
+
torch.cat([attention_mask, new_col], dim=-1),
|
| 61 |
+
new_row
|
| 62 |
+
], dim=2)
|
| 63 |
+
return model_kwargs
|
| 64 |
+
else:
|
| 65 |
+
return super()._update_model_kwargs_for_generation(
|
| 66 |
+
outputs, model_kwargs, is_encoder_decoder=is_encoder_decoder, num_new_tokens=num_new_tokens
|
| 67 |
+
)
|
| 68 |
+
|
| 69 |
+
|
| 70 |
+
def custom_prepare_4d_causal_attention_mask_with_cache_position(
|
| 71 |
+
attention_mask: torch.Tensor,
|
| 72 |
+
sequence_length: int,
|
| 73 |
+
target_length: int,
|
| 74 |
+
dtype: torch.dtype,
|
| 75 |
+
device: torch.device,
|
| 76 |
+
cache_position: torch.Tensor,
|
| 77 |
+
batch_size: int,
|
| 78 |
+
**kwargs,
|
| 79 |
+
):
|
| 80 |
+
if attention_mask is not None and attention_mask.dim() == 4:
|
| 81 |
+
# In this case we assume that the mask comes already in inverted form and requires no inversion or slicing.
|
| 82 |
+
causal_mask = attention_mask[:, :, -sequence_length:, -target_length:]
|
| 83 |
+
else:
|
| 84 |
+
min_dtype = torch.finfo(dtype).min
|
| 85 |
+
causal_mask = torch.full(
|
| 86 |
+
(sequence_length, target_length), fill_value=min_dtype, dtype=dtype, device=device
|
| 87 |
+
)
|
| 88 |
+
if sequence_length != 1:
|
| 89 |
+
causal_mask = torch.triu(causal_mask, diagonal=1)
|
| 90 |
+
causal_mask *= torch.arange(target_length, device=device) > cache_position.reshape(-1, 1)
|
| 91 |
+
causal_mask = causal_mask[None, None, :, :].expand(batch_size, 1, -1, -1)
|
| 92 |
+
if attention_mask is not None:
|
| 93 |
+
causal_mask = causal_mask.clone() # copy to contiguous memory for in-place edit
|
| 94 |
+
mask_length = attention_mask.shape[-1]
|
| 95 |
+
padding_mask = causal_mask[:, :, :, :mask_length] + attention_mask[:, None, None, :]
|
| 96 |
+
padding_mask = padding_mask == 0
|
| 97 |
+
causal_mask[:, :, :, :mask_length] = causal_mask[:, :, :, :mask_length].masked_fill(
|
| 98 |
+
padding_mask, min_dtype
|
| 99 |
+
)
|
| 100 |
+
|
| 101 |
+
return causal_mask
|
zero_to_fp32.py
ADDED
|
@@ -0,0 +1,760 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python
|
| 2 |
+
|
| 3 |
+
# Copyright (c) Microsoft Corporation.
|
| 4 |
+
# SPDX-License-Identifier: Apache-2.0
|
| 5 |
+
|
| 6 |
+
# DeepSpeed Team
|
| 7 |
+
|
| 8 |
+
# This script extracts fp32 consolidated weights from a zero 1, 2 and 3 DeepSpeed checkpoints. It gets
|
| 9 |
+
# copied into the top level checkpoint dir, so the user can easily do the conversion at any point in
|
| 10 |
+
# the future. Once extracted, the weights don't require DeepSpeed and can be used in any
|
| 11 |
+
# application.
|
| 12 |
+
#
|
| 13 |
+
# example:
|
| 14 |
+
# python zero_to_fp32.py . output_dir/
|
| 15 |
+
# or
|
| 16 |
+
# python zero_to_fp32.py . output_dir/ --safe_serialization
|
| 17 |
+
|
| 18 |
+
import argparse
|
| 19 |
+
import torch
|
| 20 |
+
import glob
|
| 21 |
+
import math
|
| 22 |
+
import os
|
| 23 |
+
import re
|
| 24 |
+
import gc
|
| 25 |
+
import json
|
| 26 |
+
import numpy as np
|
| 27 |
+
from tqdm import tqdm
|
| 28 |
+
from collections import OrderedDict
|
| 29 |
+
from dataclasses import dataclass
|
| 30 |
+
|
| 31 |
+
# while this script doesn't use deepspeed to recover data, since the checkpoints are pickled with
|
| 32 |
+
# DeepSpeed data structures it has to be available in the current python environment.
|
| 33 |
+
from deepspeed.utils import logger
|
| 34 |
+
from deepspeed.checkpoint.constants import (DS_VERSION, OPTIMIZER_STATE_DICT, SINGLE_PARTITION_OF_FP32_GROUPS,
|
| 35 |
+
FP32_FLAT_GROUPS, ZERO_STAGE, PARTITION_COUNT, PARAM_SHAPES, BUFFER_NAMES,
|
| 36 |
+
FROZEN_PARAM_SHAPES, FROZEN_PARAM_FRAGMENTS)
|
| 37 |
+
|
| 38 |
+
|
| 39 |
+
@dataclass
|
| 40 |
+
class zero_model_state:
|
| 41 |
+
buffers: dict()
|
| 42 |
+
param_shapes: dict()
|
| 43 |
+
shared_params: list
|
| 44 |
+
ds_version: int
|
| 45 |
+
frozen_param_shapes: dict()
|
| 46 |
+
frozen_param_fragments: dict()
|
| 47 |
+
|
| 48 |
+
|
| 49 |
+
debug = 0
|
| 50 |
+
|
| 51 |
+
# load to cpu
|
| 52 |
+
device = torch.device('cpu')
|
| 53 |
+
|
| 54 |
+
|
| 55 |
+
def atoi(text):
|
| 56 |
+
return int(text) if text.isdigit() else text
|
| 57 |
+
|
| 58 |
+
|
| 59 |
+
def natural_keys(text):
|
| 60 |
+
'''
|
| 61 |
+
alist.sort(key=natural_keys) sorts in human order
|
| 62 |
+
http://nedbatchelder.com/blog/200712/human_sorting.html
|
| 63 |
+
(See Toothy's implementation in the comments)
|
| 64 |
+
'''
|
| 65 |
+
return [atoi(c) for c in re.split(r'(\d+)', text)]
|
| 66 |
+
|
| 67 |
+
|
| 68 |
+
def get_model_state_file(checkpoint_dir, zero_stage):
|
| 69 |
+
if not os.path.isdir(checkpoint_dir):
|
| 70 |
+
raise FileNotFoundError(f"Directory '{checkpoint_dir}' doesn't exist")
|
| 71 |
+
|
| 72 |
+
# there should be only one file
|
| 73 |
+
if zero_stage <= 2:
|
| 74 |
+
file = os.path.join(checkpoint_dir, "mp_rank_00_model_states.pt")
|
| 75 |
+
elif zero_stage == 3:
|
| 76 |
+
file = os.path.join(checkpoint_dir, "zero_pp_rank_0_mp_rank_00_model_states.pt")
|
| 77 |
+
|
| 78 |
+
if not os.path.exists(file):
|
| 79 |
+
raise FileNotFoundError(f"can't find model states file at '{file}'")
|
| 80 |
+
|
| 81 |
+
return file
|
| 82 |
+
|
| 83 |
+
|
| 84 |
+
def get_checkpoint_files(checkpoint_dir, glob_pattern):
|
| 85 |
+
# XXX: need to test that this simple glob rule works for multi-node setup too
|
| 86 |
+
ckpt_files = sorted(glob.glob(os.path.join(checkpoint_dir, glob_pattern)), key=natural_keys)
|
| 87 |
+
|
| 88 |
+
if len(ckpt_files) == 0:
|
| 89 |
+
raise FileNotFoundError(f"can't find {glob_pattern} files in directory '{checkpoint_dir}'")
|
| 90 |
+
|
| 91 |
+
return ckpt_files
|
| 92 |
+
|
| 93 |
+
|
| 94 |
+
def get_optim_files(checkpoint_dir):
|
| 95 |
+
return get_checkpoint_files(checkpoint_dir, "*_optim_states.pt")
|
| 96 |
+
|
| 97 |
+
|
| 98 |
+
def get_model_state_files(checkpoint_dir):
|
| 99 |
+
return get_checkpoint_files(checkpoint_dir, "*_model_states.pt")
|
| 100 |
+
|
| 101 |
+
|
| 102 |
+
def parse_model_states(files):
|
| 103 |
+
zero_model_states = []
|
| 104 |
+
for file in files:
|
| 105 |
+
state_dict = torch.load(file, map_location=device, weights_only=False)
|
| 106 |
+
|
| 107 |
+
if BUFFER_NAMES not in state_dict:
|
| 108 |
+
raise ValueError(f"{file} is not a model state checkpoint")
|
| 109 |
+
buffer_names = state_dict[BUFFER_NAMES]
|
| 110 |
+
if debug:
|
| 111 |
+
print("Found buffers:", buffer_names)
|
| 112 |
+
|
| 113 |
+
# recover just the buffers while restoring them to fp32 if they were saved in fp16
|
| 114 |
+
buffers = {k: v.float() for k, v in state_dict["module"].items() if k in buffer_names}
|
| 115 |
+
param_shapes = state_dict[PARAM_SHAPES]
|
| 116 |
+
|
| 117 |
+
# collect parameters that are included in param_shapes
|
| 118 |
+
param_names = []
|
| 119 |
+
for s in param_shapes:
|
| 120 |
+
for name in s.keys():
|
| 121 |
+
param_names.append(name)
|
| 122 |
+
|
| 123 |
+
# update with frozen parameters
|
| 124 |
+
frozen_param_shapes = state_dict.get(FROZEN_PARAM_SHAPES, None)
|
| 125 |
+
if frozen_param_shapes is not None:
|
| 126 |
+
if debug:
|
| 127 |
+
print(f"Found frozen_param_shapes: {frozen_param_shapes}")
|
| 128 |
+
param_names += list(frozen_param_shapes.keys())
|
| 129 |
+
|
| 130 |
+
# handle shared params
|
| 131 |
+
shared_params = [[k, v] for k, v in state_dict["shared_params"].items()]
|
| 132 |
+
|
| 133 |
+
ds_version = state_dict.get(DS_VERSION, None)
|
| 134 |
+
|
| 135 |
+
frozen_param_fragments = state_dict.get(FROZEN_PARAM_FRAGMENTS, None)
|
| 136 |
+
|
| 137 |
+
z_model_state = zero_model_state(buffers=buffers,
|
| 138 |
+
param_shapes=param_shapes,
|
| 139 |
+
shared_params=shared_params,
|
| 140 |
+
ds_version=ds_version,
|
| 141 |
+
frozen_param_shapes=frozen_param_shapes,
|
| 142 |
+
frozen_param_fragments=frozen_param_fragments)
|
| 143 |
+
zero_model_states.append(z_model_state)
|
| 144 |
+
|
| 145 |
+
return zero_model_states
|
| 146 |
+
|
| 147 |
+
|
| 148 |
+
def parse_optim_states(files, ds_checkpoint_dir):
|
| 149 |
+
total_files = len(files)
|
| 150 |
+
state_dicts = []
|
| 151 |
+
for f in tqdm(files, desc='Loading checkpoint shards'):
|
| 152 |
+
state_dict = torch.load(f, map_location=device, mmap=True, weights_only=False)
|
| 153 |
+
# immediately discard the potentially huge 2 optimizer states as we only care for fp32 master weights
|
| 154 |
+
# and also handle the case where it was already removed by another helper script
|
| 155 |
+
state_dict["optimizer_state_dict"].pop("optimizer_state_dict", None)
|
| 156 |
+
state_dicts.append(state_dict)
|
| 157 |
+
|
| 158 |
+
if not ZERO_STAGE in state_dicts[0][OPTIMIZER_STATE_DICT]:
|
| 159 |
+
raise ValueError(f"{files[0]} is not a zero checkpoint")
|
| 160 |
+
zero_stage = state_dicts[0][OPTIMIZER_STATE_DICT][ZERO_STAGE]
|
| 161 |
+
world_size = state_dicts[0][OPTIMIZER_STATE_DICT][PARTITION_COUNT]
|
| 162 |
+
|
| 163 |
+
# For ZeRO-2 each param group can have different partition_count as data parallelism for expert
|
| 164 |
+
# parameters can be different from data parallelism for non-expert parameters. So we can just
|
| 165 |
+
# use the max of the partition_count to get the dp world_size.
|
| 166 |
+
|
| 167 |
+
if type(world_size) is list:
|
| 168 |
+
world_size = max(world_size)
|
| 169 |
+
|
| 170 |
+
if world_size != total_files:
|
| 171 |
+
raise ValueError(
|
| 172 |
+
f"Expected {world_size} of '*_optim_states.pt' under '{ds_checkpoint_dir}' but found {total_files} files. "
|
| 173 |
+
"Possibly due to an overwrite of an old checkpoint, or a checkpoint didn't get saved by one or more processes."
|
| 174 |
+
)
|
| 175 |
+
|
| 176 |
+
# the groups are named differently in each stage
|
| 177 |
+
if zero_stage <= 2:
|
| 178 |
+
fp32_groups_key = SINGLE_PARTITION_OF_FP32_GROUPS
|
| 179 |
+
elif zero_stage == 3:
|
| 180 |
+
fp32_groups_key = FP32_FLAT_GROUPS
|
| 181 |
+
else:
|
| 182 |
+
raise ValueError(f"unknown zero stage {zero_stage}")
|
| 183 |
+
|
| 184 |
+
fp32_flat_groups = [state_dicts[i][OPTIMIZER_STATE_DICT][fp32_groups_key] for i in range(len(state_dicts))]
|
| 185 |
+
return zero_stage, world_size, fp32_flat_groups
|
| 186 |
+
|
| 187 |
+
|
| 188 |
+
def _get_fp32_state_dict_from_zero_checkpoint(ds_checkpoint_dir, exclude_frozen_parameters):
|
| 189 |
+
"""
|
| 190 |
+
Returns fp32 state_dict reconstructed from ds checkpoint
|
| 191 |
+
|
| 192 |
+
Args:
|
| 193 |
+
- ``ds_checkpoint_dir``: path to the deepspeed checkpoint folder (where the optimizer files are)
|
| 194 |
+
|
| 195 |
+
"""
|
| 196 |
+
print(f"Processing zero checkpoint '{ds_checkpoint_dir}'")
|
| 197 |
+
|
| 198 |
+
optim_files = get_optim_files(ds_checkpoint_dir)
|
| 199 |
+
zero_stage, world_size, fp32_flat_groups = parse_optim_states(optim_files, ds_checkpoint_dir)
|
| 200 |
+
print(f"Detected checkpoint of type zero stage {zero_stage}, world_size: {world_size}")
|
| 201 |
+
|
| 202 |
+
model_files = get_model_state_files(ds_checkpoint_dir)
|
| 203 |
+
|
| 204 |
+
zero_model_states = parse_model_states(model_files)
|
| 205 |
+
print(f'Parsing checkpoint created by deepspeed=={zero_model_states[0].ds_version}')
|
| 206 |
+
|
| 207 |
+
if zero_stage <= 2:
|
| 208 |
+
return _get_fp32_state_dict_from_zero2_checkpoint(world_size, fp32_flat_groups, zero_model_states,
|
| 209 |
+
exclude_frozen_parameters)
|
| 210 |
+
elif zero_stage == 3:
|
| 211 |
+
return _get_fp32_state_dict_from_zero3_checkpoint(world_size, fp32_flat_groups, zero_model_states,
|
| 212 |
+
exclude_frozen_parameters)
|
| 213 |
+
|
| 214 |
+
|
| 215 |
+
def _zero2_merge_frozen_params(state_dict, zero_model_states):
|
| 216 |
+
if zero_model_states[0].frozen_param_shapes is None or len(zero_model_states[0].frozen_param_shapes) == 0:
|
| 217 |
+
return
|
| 218 |
+
|
| 219 |
+
frozen_param_shapes = zero_model_states[0].frozen_param_shapes
|
| 220 |
+
frozen_param_fragments = zero_model_states[0].frozen_param_fragments
|
| 221 |
+
|
| 222 |
+
if debug:
|
| 223 |
+
num_elem = sum(s.numel() for s in frozen_param_shapes.values())
|
| 224 |
+
print(f'rank 0: {FROZEN_PARAM_SHAPES}.numel = {num_elem}')
|
| 225 |
+
|
| 226 |
+
wanted_params = len(frozen_param_shapes)
|
| 227 |
+
wanted_numel = sum(s.numel() for s in frozen_param_shapes.values())
|
| 228 |
+
avail_numel = sum([p.numel() for p in frozen_param_fragments.values()])
|
| 229 |
+
print(f'Frozen params: Have {avail_numel} numels to process.')
|
| 230 |
+
print(f'Frozen params: Need {wanted_numel} numels in {wanted_params} params')
|
| 231 |
+
|
| 232 |
+
total_params = 0
|
| 233 |
+
total_numel = 0
|
| 234 |
+
for name, shape in frozen_param_shapes.items():
|
| 235 |
+
total_params += 1
|
| 236 |
+
unpartitioned_numel = shape.numel()
|
| 237 |
+
total_numel += unpartitioned_numel
|
| 238 |
+
|
| 239 |
+
state_dict[name] = frozen_param_fragments[name]
|
| 240 |
+
|
| 241 |
+
if debug:
|
| 242 |
+
print(f"{name} full shape: {shape} unpartitioned numel {unpartitioned_numel} ")
|
| 243 |
+
|
| 244 |
+
print(f"Reconstructed Frozen fp32 state dict with {total_params} params {total_numel} elements")
|
| 245 |
+
|
| 246 |
+
|
| 247 |
+
def _has_callable(obj, fn):
|
| 248 |
+
attr = getattr(obj, fn, None)
|
| 249 |
+
return callable(attr)
|
| 250 |
+
|
| 251 |
+
|
| 252 |
+
def _zero2_merge_trainable_params(state_dict, world_size, fp32_flat_groups, zero_model_states):
|
| 253 |
+
param_shapes = zero_model_states[0].param_shapes
|
| 254 |
+
|
| 255 |
+
# Reconstruction protocol:
|
| 256 |
+
#
|
| 257 |
+
# XXX: document this
|
| 258 |
+
|
| 259 |
+
if debug:
|
| 260 |
+
for i in range(world_size):
|
| 261 |
+
for j in range(len(fp32_flat_groups[0])):
|
| 262 |
+
print(f"{FP32_FLAT_GROUPS}[{i}][{j}].shape={fp32_flat_groups[i][j].shape}")
|
| 263 |
+
|
| 264 |
+
# XXX: memory usage doubles here (zero2)
|
| 265 |
+
num_param_groups = len(fp32_flat_groups[0])
|
| 266 |
+
merged_single_partition_of_fp32_groups = []
|
| 267 |
+
for i in range(num_param_groups):
|
| 268 |
+
merged_partitions = [sd[i] for sd in fp32_flat_groups]
|
| 269 |
+
full_single_fp32_vector = torch.cat(merged_partitions, 0)
|
| 270 |
+
merged_single_partition_of_fp32_groups.append(full_single_fp32_vector)
|
| 271 |
+
avail_numel = sum(
|
| 272 |
+
[full_single_fp32_vector.numel() for full_single_fp32_vector in merged_single_partition_of_fp32_groups])
|
| 273 |
+
|
| 274 |
+
if debug:
|
| 275 |
+
wanted_params = sum([len(shapes) for shapes in param_shapes])
|
| 276 |
+
wanted_numel = sum([sum(shape.numel() for shape in shapes.values()) for shapes in param_shapes])
|
| 277 |
+
# not asserting if there is a mismatch due to possible padding
|
| 278 |
+
print(f"Have {avail_numel} numels to process.")
|
| 279 |
+
print(f"Need {wanted_numel} numels in {wanted_params} params.")
|
| 280 |
+
|
| 281 |
+
# params
|
| 282 |
+
# XXX: for huge models that can't fit into the host's RAM we will have to recode this to support
|
| 283 |
+
# out-of-core computing solution
|
| 284 |
+
total_numel = 0
|
| 285 |
+
total_params = 0
|
| 286 |
+
for shapes, full_single_fp32_vector in zip(param_shapes, merged_single_partition_of_fp32_groups):
|
| 287 |
+
offset = 0
|
| 288 |
+
avail_numel = full_single_fp32_vector.numel()
|
| 289 |
+
for name, shape in shapes.items():
|
| 290 |
+
|
| 291 |
+
unpartitioned_numel = shape.numel() if _has_callable(shape, 'numel') else math.prod(shape)
|
| 292 |
+
total_numel += unpartitioned_numel
|
| 293 |
+
total_params += 1
|
| 294 |
+
|
| 295 |
+
if debug:
|
| 296 |
+
print(f"{name} full shape: {shape} unpartitioned numel {unpartitioned_numel} ")
|
| 297 |
+
state_dict[name] = full_single_fp32_vector.narrow(0, offset, unpartitioned_numel).view(shape)
|
| 298 |
+
offset += unpartitioned_numel
|
| 299 |
+
|
| 300 |
+
# Z2 started to align to 2*world_size to improve nccl performance. Therefore both offset and
|
| 301 |
+
# avail_numel can differ by anywhere between 0..2*world_size. Due to two unrelated complex
|
| 302 |
+
# paddings performed in the code it's almost impossible to predict the exact numbers w/o the
|
| 303 |
+
# live optimizer object, so we are checking that the numbers are within the right range
|
| 304 |
+
align_to = 2 * world_size
|
| 305 |
+
|
| 306 |
+
def zero2_align(x):
|
| 307 |
+
return align_to * math.ceil(x / align_to)
|
| 308 |
+
|
| 309 |
+
if debug:
|
| 310 |
+
print(f"original offset={offset}, avail_numel={avail_numel}")
|
| 311 |
+
|
| 312 |
+
offset = zero2_align(offset)
|
| 313 |
+
avail_numel = zero2_align(avail_numel)
|
| 314 |
+
|
| 315 |
+
if debug:
|
| 316 |
+
print(f"aligned offset={offset}, avail_numel={avail_numel}")
|
| 317 |
+
|
| 318 |
+
# Sanity check
|
| 319 |
+
if offset != avail_numel:
|
| 320 |
+
raise ValueError(f"consumed {offset} numels out of {avail_numel} - something is wrong")
|
| 321 |
+
|
| 322 |
+
print(f"Reconstructed fp32 state dict with {total_params} params {total_numel} elements")
|
| 323 |
+
|
| 324 |
+
|
| 325 |
+
def _get_fp32_state_dict_from_zero2_checkpoint(world_size, fp32_flat_groups, zero_model_states,
|
| 326 |
+
exclude_frozen_parameters):
|
| 327 |
+
state_dict = OrderedDict()
|
| 328 |
+
|
| 329 |
+
# buffers
|
| 330 |
+
buffers = zero_model_states[0].buffers
|
| 331 |
+
state_dict.update(buffers)
|
| 332 |
+
if debug:
|
| 333 |
+
print(f"added {len(buffers)} buffers")
|
| 334 |
+
|
| 335 |
+
if not exclude_frozen_parameters:
|
| 336 |
+
_zero2_merge_frozen_params(state_dict, zero_model_states)
|
| 337 |
+
|
| 338 |
+
_zero2_merge_trainable_params(state_dict, world_size, fp32_flat_groups, zero_model_states)
|
| 339 |
+
|
| 340 |
+
# recover shared parameters
|
| 341 |
+
for pair in zero_model_states[0].shared_params:
|
| 342 |
+
if pair[1] in state_dict:
|
| 343 |
+
state_dict[pair[0]] = state_dict[pair[1]]
|
| 344 |
+
|
| 345 |
+
return state_dict
|
| 346 |
+
|
| 347 |
+
|
| 348 |
+
def zero3_partitioned_param_info(unpartitioned_numel, world_size):
|
| 349 |
+
remainder = unpartitioned_numel % world_size
|
| 350 |
+
padding_numel = (world_size - remainder) if remainder else 0
|
| 351 |
+
partitioned_numel = math.ceil(unpartitioned_numel / world_size)
|
| 352 |
+
return partitioned_numel, padding_numel
|
| 353 |
+
|
| 354 |
+
|
| 355 |
+
def _zero3_merge_frozen_params(state_dict, world_size, zero_model_states):
|
| 356 |
+
if zero_model_states[0].frozen_param_shapes is None or len(zero_model_states[0].frozen_param_shapes) == 0:
|
| 357 |
+
return
|
| 358 |
+
|
| 359 |
+
if debug:
|
| 360 |
+
for i in range(world_size):
|
| 361 |
+
num_elem = sum(s.numel() for s in zero_model_states[i].frozen_param_fragments.values())
|
| 362 |
+
print(f'rank {i}: {FROZEN_PARAM_SHAPES}.numel = {num_elem}')
|
| 363 |
+
|
| 364 |
+
frozen_param_shapes = zero_model_states[0].frozen_param_shapes
|
| 365 |
+
wanted_params = len(frozen_param_shapes)
|
| 366 |
+
wanted_numel = sum(s.numel() for s in frozen_param_shapes.values())
|
| 367 |
+
avail_numel = sum([p.numel() for p in zero_model_states[0].frozen_param_fragments.values()]) * world_size
|
| 368 |
+
print(f'Frozen params: Have {avail_numel} numels to process.')
|
| 369 |
+
print(f'Frozen params: Need {wanted_numel} numels in {wanted_params} params')
|
| 370 |
+
|
| 371 |
+
total_params = 0
|
| 372 |
+
total_numel = 0
|
| 373 |
+
for name, shape in zero_model_states[0].frozen_param_shapes.items():
|
| 374 |
+
total_params += 1
|
| 375 |
+
unpartitioned_numel = shape.numel()
|
| 376 |
+
total_numel += unpartitioned_numel
|
| 377 |
+
|
| 378 |
+
param_frags = tuple(model_state.frozen_param_fragments[name] for model_state in zero_model_states)
|
| 379 |
+
state_dict[name] = torch.cat(param_frags, 0).narrow(0, 0, unpartitioned_numel).view(shape)
|
| 380 |
+
|
| 381 |
+
partitioned_numel, partitioned_padding_numel = zero3_partitioned_param_info(unpartitioned_numel, world_size)
|
| 382 |
+
|
| 383 |
+
if debug:
|
| 384 |
+
print(
|
| 385 |
+
f"Frozen params: {total_params} {name} full shape: {shape} partition0 numel={partitioned_numel} partitioned_padding_numel={partitioned_padding_numel}"
|
| 386 |
+
)
|
| 387 |
+
|
| 388 |
+
print(f"Reconstructed Frozen fp32 state dict with {total_params} params {total_numel} elements")
|
| 389 |
+
|
| 390 |
+
|
| 391 |
+
class GatheredTensor:
|
| 392 |
+
"""
|
| 393 |
+
A pseudo tensor that collects partitioned weights.
|
| 394 |
+
It is more memory efficient when there are multiple groups.
|
| 395 |
+
"""
|
| 396 |
+
|
| 397 |
+
def __init__(self, flat_groups, flat_groups_offset, offset, partitioned_numel, shape):
|
| 398 |
+
self.flat_groups = flat_groups
|
| 399 |
+
self.flat_groups_offset = flat_groups_offset
|
| 400 |
+
self.offset = offset
|
| 401 |
+
self.partitioned_numel = partitioned_numel
|
| 402 |
+
self.shape = shape
|
| 403 |
+
self.dtype = self.flat_groups[0][0].dtype
|
| 404 |
+
|
| 405 |
+
def contiguous(self):
|
| 406 |
+
"""
|
| 407 |
+
Merge partitioned weights from flat_groups into a single tensor.
|
| 408 |
+
"""
|
| 409 |
+
end_idx = self.offset + self.partitioned_numel
|
| 410 |
+
world_size = len(self.flat_groups)
|
| 411 |
+
pad_flat_param_chunks = []
|
| 412 |
+
|
| 413 |
+
for rank_i in range(world_size):
|
| 414 |
+
# for each rank, we need to collect weights from related group/groups
|
| 415 |
+
flat_groups_at_rank_i = self.flat_groups[rank_i]
|
| 416 |
+
start_group_id = None
|
| 417 |
+
end_group_id = None
|
| 418 |
+
for group_id in range(len(self.flat_groups_offset)):
|
| 419 |
+
if self.flat_groups_offset[group_id] <= self.offset < self.flat_groups_offset[group_id + 1]:
|
| 420 |
+
start_group_id = group_id
|
| 421 |
+
if self.flat_groups_offset[group_id] < end_idx <= self.flat_groups_offset[group_id + 1]:
|
| 422 |
+
end_group_id = group_id
|
| 423 |
+
break
|
| 424 |
+
# collect weights from related group/groups
|
| 425 |
+
for group_id in range(start_group_id, end_group_id + 1):
|
| 426 |
+
flat_tensor = flat_groups_at_rank_i[group_id]
|
| 427 |
+
start_offset = self.offset - self.flat_groups_offset[group_id]
|
| 428 |
+
end_offset = min(end_idx, self.flat_groups_offset[group_id + 1]) - self.flat_groups_offset[group_id]
|
| 429 |
+
pad_flat_param_chunks.append(flat_tensor[start_offset:end_offset])
|
| 430 |
+
|
| 431 |
+
# collect weights from all ranks
|
| 432 |
+
pad_flat_param = torch.cat(pad_flat_param_chunks, dim=0)
|
| 433 |
+
param = pad_flat_param[:self.shape.numel()].view(self.shape).contiguous()
|
| 434 |
+
return param
|
| 435 |
+
|
| 436 |
+
|
| 437 |
+
def _zero3_merge_trainable_params(state_dict, world_size, fp32_flat_groups, zero_model_states):
|
| 438 |
+
param_shapes = zero_model_states[0].param_shapes
|
| 439 |
+
avail_numel = sum([flat_group.numel() for flat_group in fp32_flat_groups[0]]) * world_size
|
| 440 |
+
|
| 441 |
+
# Reconstruction protocol: For zero3 we need to zip the partitions together at boundary of each
|
| 442 |
+
# param, re-consolidating each param, while dealing with padding if any
|
| 443 |
+
|
| 444 |
+
# merge list of dicts, preserving order
|
| 445 |
+
param_shapes = {k: v for d in param_shapes for k, v in d.items()}
|
| 446 |
+
|
| 447 |
+
if debug:
|
| 448 |
+
for i in range(world_size):
|
| 449 |
+
print(f"{FP32_FLAT_GROUPS}[{i}].shape={fp32_flat_groups[i].shape}")
|
| 450 |
+
|
| 451 |
+
wanted_params = len(param_shapes)
|
| 452 |
+
wanted_numel = sum(shape.numel() for shape in param_shapes.values())
|
| 453 |
+
# not asserting if there is a mismatch due to possible padding
|
| 454 |
+
avail_numel = fp32_flat_groups[0].numel() * world_size
|
| 455 |
+
print(f"Trainable params: Have {avail_numel} numels to process.")
|
| 456 |
+
print(f"Trainable params: Need {wanted_numel} numels in {wanted_params} params.")
|
| 457 |
+
|
| 458 |
+
# params
|
| 459 |
+
# XXX: for huge models that can't fit into the host's RAM we will have to recode this to support
|
| 460 |
+
# out-of-core computing solution
|
| 461 |
+
offset = 0
|
| 462 |
+
total_numel = 0
|
| 463 |
+
total_params = 0
|
| 464 |
+
flat_groups_offset = [0] + list(np.cumsum([flat_tensor.numel() for flat_tensor in fp32_flat_groups[0]]))
|
| 465 |
+
for name, shape in tqdm(param_shapes.items(), desc='Gathering sharded weights'):
|
| 466 |
+
unpartitioned_numel = shape.numel()
|
| 467 |
+
total_numel += unpartitioned_numel
|
| 468 |
+
total_params += 1
|
| 469 |
+
partitioned_numel, partitioned_padding_numel = zero3_partitioned_param_info(unpartitioned_numel, world_size)
|
| 470 |
+
|
| 471 |
+
if debug:
|
| 472 |
+
print(
|
| 473 |
+
f"Trainable params: {total_params} {name} full shape: {shape} partition0 numel={partitioned_numel} partitioned_padding_numel={partitioned_padding_numel}"
|
| 474 |
+
)
|
| 475 |
+
|
| 476 |
+
# memory efficient tensor
|
| 477 |
+
tensor = GatheredTensor(fp32_flat_groups, flat_groups_offset, offset, partitioned_numel, shape)
|
| 478 |
+
state_dict[name] = tensor
|
| 479 |
+
offset += partitioned_numel
|
| 480 |
+
|
| 481 |
+
offset *= world_size
|
| 482 |
+
|
| 483 |
+
# Sanity check
|
| 484 |
+
if offset != avail_numel:
|
| 485 |
+
raise ValueError(f"consumed {offset} numels out of {avail_numel} - something is wrong")
|
| 486 |
+
|
| 487 |
+
print(f"Reconstructed Trainable fp32 state dict with {total_params} params {total_numel} elements")
|
| 488 |
+
|
| 489 |
+
|
| 490 |
+
def _get_fp32_state_dict_from_zero3_checkpoint(world_size, fp32_flat_groups, zero_model_states,
|
| 491 |
+
exclude_frozen_parameters):
|
| 492 |
+
state_dict = OrderedDict()
|
| 493 |
+
|
| 494 |
+
# buffers
|
| 495 |
+
buffers = zero_model_states[0].buffers
|
| 496 |
+
state_dict.update(buffers)
|
| 497 |
+
if debug:
|
| 498 |
+
print(f"added {len(buffers)} buffers")
|
| 499 |
+
|
| 500 |
+
if not exclude_frozen_parameters:
|
| 501 |
+
_zero3_merge_frozen_params(state_dict, world_size, zero_model_states)
|
| 502 |
+
|
| 503 |
+
_zero3_merge_trainable_params(state_dict, world_size, fp32_flat_groups, zero_model_states)
|
| 504 |
+
|
| 505 |
+
# recover shared parameters
|
| 506 |
+
for pair in zero_model_states[0].shared_params:
|
| 507 |
+
if pair[1] in state_dict:
|
| 508 |
+
state_dict[pair[0]] = state_dict[pair[1]]
|
| 509 |
+
|
| 510 |
+
return state_dict
|
| 511 |
+
|
| 512 |
+
|
| 513 |
+
def to_torch_tensor(state_dict, return_empty_tensor=False):
|
| 514 |
+
"""
|
| 515 |
+
Convert state_dict of GatheredTensor to torch tensor
|
| 516 |
+
"""
|
| 517 |
+
torch_state_dict = {}
|
| 518 |
+
converted_tensors = {}
|
| 519 |
+
for name, tensor in state_dict.items():
|
| 520 |
+
tensor_id = id(tensor)
|
| 521 |
+
if tensor_id in converted_tensors: # shared tensors
|
| 522 |
+
shared_tensor = torch_state_dict[converted_tensors[tensor_id]]
|
| 523 |
+
torch_state_dict[name] = shared_tensor
|
| 524 |
+
else:
|
| 525 |
+
converted_tensors[tensor_id] = name
|
| 526 |
+
if return_empty_tensor:
|
| 527 |
+
torch_state_dict[name] = torch.empty(tensor.shape, dtype=tensor.dtype)
|
| 528 |
+
else:
|
| 529 |
+
torch_state_dict[name] = tensor.contiguous()
|
| 530 |
+
return torch_state_dict
|
| 531 |
+
|
| 532 |
+
|
| 533 |
+
def get_fp32_state_dict_from_zero_checkpoint(checkpoint_dir,
|
| 534 |
+
tag=None,
|
| 535 |
+
exclude_frozen_parameters=False,
|
| 536 |
+
lazy_mode=False):
|
| 537 |
+
"""
|
| 538 |
+
Convert ZeRO 2 or 3 checkpoint into a single fp32 consolidated state_dict that can be loaded with
|
| 539 |
+
``load_state_dict()`` and used for training without DeepSpeed or shared with others, for example
|
| 540 |
+
via a model hub.
|
| 541 |
+
|
| 542 |
+
Args:
|
| 543 |
+
- ``checkpoint_dir``: path to the desired checkpoint folder
|
| 544 |
+
- ``tag``: checkpoint tag used as a unique identifier for checkpoint. If not provided will attempt to load tag in 'latest' file. e.g., ``global_step14``
|
| 545 |
+
- ``exclude_frozen_parameters``: exclude frozen parameters
|
| 546 |
+
- ``lazy_mode``: get state_dict in lazy mode. It returns a dict of pesduo tensor instead of torch tensor, which is more memory efficient.
|
| 547 |
+
Convert the pesduo tensor to torch tensor by ``.contiguous()``
|
| 548 |
+
|
| 549 |
+
Returns:
|
| 550 |
+
- pytorch ``state_dict``
|
| 551 |
+
|
| 552 |
+
A typical usage might be ::
|
| 553 |
+
|
| 554 |
+
from deepspeed.utils.zero_to_fp32 import get_fp32_state_dict_from_zero_checkpoint
|
| 555 |
+
# do the training and checkpoint saving
|
| 556 |
+
state_dict = get_fp32_state_dict_from_zero_checkpoint(checkpoint_dir) # already on cpu
|
| 557 |
+
model = model.cpu() # move to cpu
|
| 558 |
+
model.load_state_dict(state_dict)
|
| 559 |
+
# submit to model hub or save the model to share with others
|
| 560 |
+
|
| 561 |
+
In this example the ``model`` will no longer be usable in the deepspeed context of the same
|
| 562 |
+
application. i.e. you will need to re-initialize the deepspeed engine, since
|
| 563 |
+
``model.load_state_dict(state_dict)`` will remove all the deepspeed magic from it.
|
| 564 |
+
|
| 565 |
+
If you want it all done for you, use ``load_state_dict_from_zero_checkpoint`` instead.
|
| 566 |
+
|
| 567 |
+
Note: the above usage may not work if your application doesn't have sufficient free CPU memory.
|
| 568 |
+
You may need to use the offline approach using the ``zero_to_fp32.py`` script that is saved with
|
| 569 |
+
the checkpoint. Or you can load state_dict in lazy mode ::
|
| 570 |
+
|
| 571 |
+
from deepspeed.utils.zero_to_fp32 import get_fp32_state_dict_from_zero_checkpoint
|
| 572 |
+
state_dict = get_fp32_state_dict_from_zero_checkpoint(checkpoint_dir, lazy_mode=True) # not on cpu
|
| 573 |
+
for name, lazy_tensor in state_dict.item():
|
| 574 |
+
tensor = lazy_tensor.contiguous() # to cpu
|
| 575 |
+
print(name, tensor)
|
| 576 |
+
# del tensor to release memory if it no longer in use
|
| 577 |
+
"""
|
| 578 |
+
if tag is None:
|
| 579 |
+
latest_path = os.path.join(checkpoint_dir, 'latest')
|
| 580 |
+
if os.path.isfile(latest_path):
|
| 581 |
+
with open(latest_path, 'r') as fd:
|
| 582 |
+
tag = fd.read().strip()
|
| 583 |
+
else:
|
| 584 |
+
raise ValueError(f"Unable to find 'latest' file at {latest_path}")
|
| 585 |
+
|
| 586 |
+
ds_checkpoint_dir = os.path.join(checkpoint_dir, tag)
|
| 587 |
+
|
| 588 |
+
if not os.path.isdir(ds_checkpoint_dir):
|
| 589 |
+
raise FileNotFoundError(f"Directory '{ds_checkpoint_dir}' doesn't exist")
|
| 590 |
+
|
| 591 |
+
state_dict = _get_fp32_state_dict_from_zero_checkpoint(ds_checkpoint_dir, exclude_frozen_parameters)
|
| 592 |
+
if lazy_mode:
|
| 593 |
+
return state_dict
|
| 594 |
+
else:
|
| 595 |
+
return to_torch_tensor(state_dict)
|
| 596 |
+
|
| 597 |
+
|
| 598 |
+
def convert_zero_checkpoint_to_fp32_state_dict(checkpoint_dir,
|
| 599 |
+
output_dir,
|
| 600 |
+
max_shard_size="5GB",
|
| 601 |
+
safe_serialization=False,
|
| 602 |
+
tag=None,
|
| 603 |
+
exclude_frozen_parameters=False):
|
| 604 |
+
"""
|
| 605 |
+
Convert ZeRO 2 or 3 checkpoint into a single fp32 consolidated ``state_dict`` file that can be
|
| 606 |
+
loaded with ``torch.load(file)`` + ``load_state_dict()`` and used for training without DeepSpeed.
|
| 607 |
+
|
| 608 |
+
Args:
|
| 609 |
+
- ``checkpoint_dir``: path to the desired checkpoint folder. (one that contains the tag-folder, like ``global_step14``)
|
| 610 |
+
- ``output_dir``: directory to the pytorch fp32 state_dict output files
|
| 611 |
+
- ``max_shard_size``: the maximum size for a checkpoint before being sharded, default value is 5GB
|
| 612 |
+
- ``safe_serialization``: whether to save the model using `safetensors` or the traditional PyTorch way (that uses `pickle`).
|
| 613 |
+
- ``tag``: checkpoint tag used as a unique identifier for checkpoint. If not provided will attempt to load tag in the file named ``latest`` in the checkpoint folder, e.g., ``global_step14``
|
| 614 |
+
- ``exclude_frozen_parameters``: exclude frozen parameters
|
| 615 |
+
"""
|
| 616 |
+
|
| 617 |
+
# Dependency pre-check
|
| 618 |
+
if safe_serialization:
|
| 619 |
+
try:
|
| 620 |
+
from safetensors.torch import save_file
|
| 621 |
+
except ImportError:
|
| 622 |
+
print('If you want to use `safe_serialization`, please `pip install safetensors`')
|
| 623 |
+
raise
|
| 624 |
+
if max_shard_size is not None:
|
| 625 |
+
try:
|
| 626 |
+
from huggingface_hub import split_torch_state_dict_into_shards
|
| 627 |
+
except ImportError:
|
| 628 |
+
print('If you want to use `max_shard_size`, please `pip install huggingface_hub`')
|
| 629 |
+
raise
|
| 630 |
+
|
| 631 |
+
# Convert zero checkpoint to state_dict
|
| 632 |
+
state_dict = get_fp32_state_dict_from_zero_checkpoint(checkpoint_dir,
|
| 633 |
+
tag,
|
| 634 |
+
exclude_frozen_parameters,
|
| 635 |
+
lazy_mode=True)
|
| 636 |
+
|
| 637 |
+
# Shard the model if it is too big.
|
| 638 |
+
weights_name = "model.safetensors" if safe_serialization else "pytorch_model.bin"
|
| 639 |
+
if max_shard_size is not None:
|
| 640 |
+
filename_pattern = weights_name.replace(".bin", "{suffix}.bin").replace(".safetensors", "{suffix}.safetensors")
|
| 641 |
+
# an memory-efficient approach for sharding
|
| 642 |
+
empty_state_dict = to_torch_tensor(state_dict, return_empty_tensor=True)
|
| 643 |
+
state_dict_split = split_torch_state_dict_into_shards(empty_state_dict,
|
| 644 |
+
filename_pattern=filename_pattern,
|
| 645 |
+
max_shard_size=max_shard_size)
|
| 646 |
+
else:
|
| 647 |
+
from collections import namedtuple
|
| 648 |
+
StateDictSplit = namedtuple("StateDictSplit", ["is_sharded", "filename_to_tensors"])
|
| 649 |
+
state_dict_split = StateDictSplit(is_sharded=False,
|
| 650 |
+
filename_to_tensors={weights_name: list(state_dict.keys())})
|
| 651 |
+
|
| 652 |
+
# Save the model by shard
|
| 653 |
+
os.makedirs(output_dir, exist_ok=True)
|
| 654 |
+
filename_to_tensors = state_dict_split.filename_to_tensors.items()
|
| 655 |
+
for shard_file, tensors in tqdm(filename_to_tensors, desc="Saving checkpoint shards"):
|
| 656 |
+
shard_state_dict = {tensor_name: state_dict[tensor_name] for tensor_name in tensors}
|
| 657 |
+
shard_state_dict = to_torch_tensor(shard_state_dict)
|
| 658 |
+
output_path = os.path.join(output_dir, shard_file)
|
| 659 |
+
if safe_serialization:
|
| 660 |
+
save_file(shard_state_dict, output_path, metadata={"format": "pt"})
|
| 661 |
+
else:
|
| 662 |
+
torch.save(shard_state_dict, output_path)
|
| 663 |
+
# release the memory of current shard
|
| 664 |
+
for tensor_name in list(shard_state_dict.keys()):
|
| 665 |
+
del state_dict[tensor_name]
|
| 666 |
+
del shard_state_dict[tensor_name]
|
| 667 |
+
del shard_state_dict
|
| 668 |
+
gc.collect()
|
| 669 |
+
|
| 670 |
+
# Save index if sharded
|
| 671 |
+
if state_dict_split.is_sharded:
|
| 672 |
+
index = {
|
| 673 |
+
"metadata": state_dict_split.metadata,
|
| 674 |
+
"weight_map": state_dict_split.tensor_to_filename,
|
| 675 |
+
}
|
| 676 |
+
save_index_file = "model.safetensors.index.json" if safe_serialization else "pytorch_model.bin.index.json"
|
| 677 |
+
save_index_file = os.path.join(output_dir, save_index_file)
|
| 678 |
+
with open(save_index_file, "w", encoding="utf-8") as f:
|
| 679 |
+
content = json.dumps(index, indent=2, sort_keys=True) + "\n"
|
| 680 |
+
f.write(content)
|
| 681 |
+
|
| 682 |
+
|
| 683 |
+
def load_state_dict_from_zero_checkpoint(model, checkpoint_dir, tag=None):
|
| 684 |
+
"""
|
| 685 |
+
1. Put the provided model to cpu
|
| 686 |
+
2. Convert ZeRO 2 or 3 checkpoint into a single fp32 consolidated ``state_dict``
|
| 687 |
+
3. Load it into the provided model
|
| 688 |
+
|
| 689 |
+
Args:
|
| 690 |
+
- ``model``: the model object to update
|
| 691 |
+
- ``checkpoint_dir``: path to the desired checkpoint folder. (one that contains the tag-folder, like ``global_step14``)
|
| 692 |
+
- ``tag``: checkpoint tag used as a unique identifier for checkpoint. If not provided will attempt to load tag in the file named ``latest`` in the checkpoint folder, e.g., ``global_step14``
|
| 693 |
+
|
| 694 |
+
Returns:
|
| 695 |
+
- ``model`: modified model
|
| 696 |
+
|
| 697 |
+
Make sure you have plenty of CPU memory available before you call this function. If you don't
|
| 698 |
+
have enough use the ``zero_to_fp32.py`` utility to do the conversion. You will find it
|
| 699 |
+
conveniently placed for you in the checkpoint folder.
|
| 700 |
+
|
| 701 |
+
A typical usage might be ::
|
| 702 |
+
|
| 703 |
+
from deepspeed.utils.zero_to_fp32 import load_state_dict_from_zero_checkpoint
|
| 704 |
+
model = load_state_dict_from_zero_checkpoint(trainer.model, checkpoint_dir)
|
| 705 |
+
# submit to model hub or save the model to share with others
|
| 706 |
+
|
| 707 |
+
Note, that once this was run, the ``model`` will no longer be usable in the deepspeed context
|
| 708 |
+
of the same application. i.e. you will need to re-initialize the deepspeed engine, since
|
| 709 |
+
``model.load_state_dict(state_dict)`` will remove all the deepspeed magic from it.
|
| 710 |
+
|
| 711 |
+
"""
|
| 712 |
+
logger.info(f"Extracting fp32 weights")
|
| 713 |
+
state_dict = get_fp32_state_dict_from_zero_checkpoint(checkpoint_dir, tag)
|
| 714 |
+
|
| 715 |
+
logger.info(f"Overwriting model with fp32 weights")
|
| 716 |
+
model = model.cpu()
|
| 717 |
+
model.load_state_dict(state_dict, strict=False)
|
| 718 |
+
|
| 719 |
+
return model
|
| 720 |
+
|
| 721 |
+
|
| 722 |
+
if __name__ == "__main__":
|
| 723 |
+
parser = argparse.ArgumentParser()
|
| 724 |
+
parser.add_argument("checkpoint_dir",
|
| 725 |
+
type=str,
|
| 726 |
+
help="path to the desired checkpoint folder, e.g., path/checkpoint-12")
|
| 727 |
+
parser.add_argument("output_dir",
|
| 728 |
+
type=str,
|
| 729 |
+
help="directory to the pytorch fp32 state_dict output files"
|
| 730 |
+
"(e.g. path/checkpoint-12-output/)")
|
| 731 |
+
parser.add_argument(
|
| 732 |
+
"--max_shard_size",
|
| 733 |
+
type=str,
|
| 734 |
+
default="5GB",
|
| 735 |
+
help="The maximum size for a checkpoint before being sharded. Checkpoints shard will then be each of size"
|
| 736 |
+
"lower than this size. If expressed as a string, needs to be digits followed by a unit (like `5MB`"
|
| 737 |
+
"We default it to 5GB in order for models to be able to run easily on free-tier google colab instances"
|
| 738 |
+
"without CPU OOM issues.")
|
| 739 |
+
parser.add_argument(
|
| 740 |
+
"--safe_serialization",
|
| 741 |
+
default=False,
|
| 742 |
+
action='store_true',
|
| 743 |
+
help="Whether to save the model using `safetensors` or the traditional PyTorch way (that uses `pickle`).")
|
| 744 |
+
parser.add_argument("-t",
|
| 745 |
+
"--tag",
|
| 746 |
+
type=str,
|
| 747 |
+
default=None,
|
| 748 |
+
help="checkpoint tag used as a unique identifier for checkpoint. e.g., global_step1")
|
| 749 |
+
parser.add_argument("--exclude_frozen_parameters", action='store_true', help="exclude frozen parameters")
|
| 750 |
+
parser.add_argument("-d", "--debug", action='store_true', help="enable debug")
|
| 751 |
+
args = parser.parse_args()
|
| 752 |
+
|
| 753 |
+
debug = args.debug
|
| 754 |
+
|
| 755 |
+
convert_zero_checkpoint_to_fp32_state_dict(args.checkpoint_dir,
|
| 756 |
+
args.output_dir,
|
| 757 |
+
max_shard_size=args.max_shard_size,
|
| 758 |
+
safe_serialization=args.safe_serialization,
|
| 759 |
+
tag=args.tag,
|
| 760 |
+
exclude_frozen_parameters=args.exclude_frozen_parameters)
|