yujiepan commited on
Commit
63196aa
·
verified ·
1 Parent(s): af2c89d

Upload folder using huggingface_hub

Browse files
Files changed (2) hide show
  1. README.md +14 -3
  2. model.safetensors +2 -2
README.md CHANGED
@@ -24,7 +24,7 @@ processor = AutoProcessor.from_pretrained(model_id)
24
  model = AutoModelForMultimodalLM.from_pretrained(
25
  model_id,
26
  dtype=torch.bfloat16,
27
- device_map="cuda",
28
  )
29
 
30
  # Synthetic multimodal inputs — no network fetch.
@@ -54,7 +54,7 @@ inputs = processor.apply_chat_template(
54
  ).to(model.device, dtype=model.dtype)
55
  input_len = inputs["input_ids"].shape[-1]
56
  outputs = model.generate(**inputs, max_new_tokens=16)
57
- print(processor.decode(outputs[0][input_len:], skip_special_tokens=False))
58
  ```
59
 
60
  ### Codes to create this repo:
@@ -103,7 +103,6 @@ config_json['text_config'].update({
103
  'dense_intermediate_size': 32,
104
  'intermediate_size': 32,
105
  'moe_intermediate_size': 32,
106
- # 'n_routed_experts': 8,
107
  })
108
  config_json['vision_config'].update({
109
  'decoder_dmodel': hidden_size,
@@ -136,6 +135,14 @@ with torch.no_grad():
136
  for name, p in sorted(model.named_parameters()):
137
  torch.nn.init.normal_(p, 0, 0.2)
138
  print(name, p.shape, f'{p.numel() / num_params:.2%}', f'{p.numel() * p.element_size() / 1024**2:.2f}MB')
 
 
 
 
 
 
 
 
139
  model.save_pretrained(save_folder)
140
 
141
  # HF ignores `model.mtp.*` on main load; write them with original checkpoint naming.
@@ -159,6 +166,10 @@ for i in range(num_mtp_layers):
159
  state[name] = torch.empty(shape, dtype=torch.bfloat16)
160
  torch.nn.init.normal_(state[name], 0, 0.2)
161
  print(name, shape)
 
 
 
 
162
  save_file(state, str(path))
163
  ```
164
 
 
24
  model = AutoModelForMultimodalLM.from_pretrained(
25
  model_id,
26
  dtype=torch.bfloat16,
27
+ device_map="cuda" if torch.cuda.is_available() else "cpu",
28
  )
29
 
30
  # Synthetic multimodal inputs — no network fetch.
 
54
  ).to(model.device, dtype=model.dtype)
55
  input_len = inputs["input_ids"].shape[-1]
56
  outputs = model.generate(**inputs, max_new_tokens=16)
57
+ print(processor.decode(outputs[0], skip_special_tokens=False))
58
  ```
59
 
60
  ### Codes to create this repo:
 
103
  'dense_intermediate_size': 32,
104
  'intermediate_size': 32,
105
  'moe_intermediate_size': 32,
 
106
  })
107
  config_json['vision_config'].update({
108
  'decoder_dmodel': hidden_size,
 
135
  for name, p in sorted(model.named_parameters()):
136
  torch.nn.init.normal_(p, 0, 0.2)
137
  print(name, p.shape, f'{p.numel() / num_params:.2%}', f'{p.numel() * p.element_size() / 1024**2:.2f}MB')
138
+ # Upstream MoE gate bias / global_scale are F32; sconv stays BF16 in the checkpoint.
139
+ for name, module in model.named_modules():
140
+ if hasattr(module, "e_score_correction_bias"):
141
+ module.e_score_correction_bias = torch.nn.Parameter(
142
+ module.e_score_correction_bias.detach().float()
143
+ )
144
+ if name.endswith(".mlp.gate") and hasattr(module, "global_scale"):
145
+ module.global_scale = torch.nn.Parameter(module.global_scale.detach().float())
146
  model.save_pretrained(save_folder)
147
 
148
  # HF ignores `model.mtp.*` on main load; write them with original checkpoint naming.
 
166
  state[name] = torch.empty(shape, dtype=torch.bfloat16)
167
  torch.nn.init.normal_(state[name], 0, 0.2)
168
  print(name, shape)
169
+ # Keep checkpoint key dtypes aligned even if save_pretrained downcasts.
170
+ for key, tensor in list(state.items()):
171
+ if key.endswith(".mlp.gate.bias") or key.endswith(".mlp.gate.global_scale"):
172
+ state[key] = tensor.float()
173
  save_file(state, str(path))
174
  ```
175
 
model.safetensors CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:6ca1255f3740250d220436140a50fd6603c01a31b202ccba3a773e854b5b3445
3
- size 7337022
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:1b67f75e7f07e189a6dde338347e81a3616b7fed4f3236b0d34c957b69d25887
3
+ size 7337520