yujiepan commited on
Commit
d2e6517
·
verified ·
1 Parent(s): a1f5bea

Make creation examples standalone with public dependencies

Browse files
Files changed (2) hide show
  1. .meta.json +0 -1
  2. README.md +50 -7
.meta.json CHANGED
@@ -8,7 +8,6 @@
8
  "numpy": "2.3.5",
9
  "safetensors": "0.8.0",
10
  "sglang": "0.5.23.dev384+g9ab74b851",
11
- "tiny-random": "0.2.0",
12
  "torch": "2.14.1",
13
  "torchcodec": "0.17.0",
14
  "transformers": "5.19.0",
 
8
  "numpy": "2.3.5",
9
  "safetensors": "0.8.0",
10
  "sglang": "0.5.23.dev384+g9ab74b851",
 
11
  "torch": "2.14.1",
12
  "torchcodec": "0.17.0",
13
  "transformers": "5.19.0",
README.md CHANGED
@@ -104,13 +104,15 @@ print(processor.decode(output[0, inputs['input_ids'].shape[1]:], skip_special_to
104
 
105
  ```python
106
  import json
 
107
  from pathlib import Path
 
108
 
109
  import torch
110
- from huggingface_hub import hf_hub_download
 
111
  from transformers import AutoConfig, AutoModelForImageTextToText, set_seed
112
- # Creation helpers: pip install git+https://github.com/yujiepan/tiny-random.git
113
- from tiny_random.qwen_utils import add_qwen4_mtp, copy_qwen_source_assets, save_random_qwen_checkpoint
114
 
115
  source_model_id = "Qwen/Qwen3.8-Flash-Next"
116
  save_folder = "/tmp/tiny-random/qwen38-flash-next"
@@ -132,9 +134,50 @@ raw['vision_config'].update(depth=2, hidden_size=64, intermediate_size=128, num_
132
  (folder / 'config.json').write_text(json.dumps(raw, indent=2))
133
  config = AutoConfig.from_pretrained(folder)
134
  model = AutoModelForImageTextToText.from_config(config, dtype=torch.bfloat16)
135
- add_qwen4_mtp(model, model.model.language_model)
136
- save_random_qwen_checkpoint(model, folder)
137
- copy_qwen_source_assets(source_model_id, source_revision, folder)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
138
  ```
139
 
140
  </details>
@@ -160,7 +203,6 @@ Qwen3.8 Flash-Next: 8 backbone layers + 1 HC-aware MTP layer; hidden_size=4
160
  - numpy: 2.3.5
161
  - safetensors: 0.8.0
162
  - sglang: 0.5.23.dev384+g9ab74b851
163
- - tiny-random: 0.2.0
164
  - torch: 2.14.1
165
  - torchcodec: 0.17.0
166
  - transformers: 5.19.0
@@ -171,5 +213,6 @@ Qwen3.8 Flash-Next: 8 backbone layers + 1 HC-aware MTP layer; hidden_size=4
171
  ### Change log:
172
 
173
  - 2026-10-23: Initial version.
 
174
 
175
  This repo is generated by GPT-6.1-Sol
 
104
 
105
  ```python
106
  import json
107
+ from copy import deepcopy
108
  from pathlib import Path
109
+ from shutil import copyfile
110
 
111
  import torch
112
+ from huggingface_hub import hf_hub_download, list_repo_files
113
+ from safetensors.torch import save_file
114
  from transformers import AutoConfig, AutoModelForImageTextToText, set_seed
115
+ from transformers.models.qwen4_exp.modeling_qwen4_exp import Qwen4ExpTextRMSNorm
 
116
 
117
  source_model_id = "Qwen/Qwen3.8-Flash-Next"
118
  save_folder = "/tmp/tiny-random/qwen38-flash-next"
 
134
  (folder / 'config.json').write_text(json.dumps(raw, indent=2))
135
  config = AutoConfig.from_pretrained(folder)
136
  model = AutoModelForImageTextToText.from_config(config, dtype=torch.bfloat16)
137
+ backbone = model.model.language_model
138
+ text = backbone.config
139
+ width = text.hidden_size
140
+ model.mtp = torch.nn.ModuleDict({
141
+ "fc_embedding": torch.nn.Linear(width, width, bias=False, dtype=torch.bfloat16),
142
+ "fc_hidden": torch.nn.Linear(width, width, bias=False, dtype=torch.bfloat16),
143
+ "pre_fc_norm_embedding": Qwen4ExpTextRMSNorm(width, eps=text.rms_norm_eps).to(torch.bfloat16),
144
+ "pre_fc_norm_hidden": Qwen4ExpTextRMSNorm(width * text.hc_count, eps=text.rms_norm_eps).to(torch.bfloat16),
145
+ "layers": torch.nn.ModuleList([deepcopy(backbone.layers[-1])]),
146
+ "hyper_connection_mixer": deepcopy(backbone.hyper_connection_mixer),
147
+ })
148
+ with torch.no_grad():
149
+ for name, param in sorted(model.named_parameters()):
150
+ if name.endswith("A_log"):
151
+ param.zero_()
152
+ elif name.endswith("dt_bias"):
153
+ param.fill_(1)
154
+ elif "norm" in name and name.endswith("weight"):
155
+ param.fill_(1 if "visual" in name or ".linear_attn.norm." in name else 0)
156
+ elif name.endswith("bias"):
157
+ param.zero_()
158
+ else:
159
+ torch.nn.init.normal_(param, mean=0, std=0.02)
160
+ state = {name: value.detach().cpu().contiguous() for name, value in model.state_dict().items()}
161
+ # The public checkpoint stores PLE embeddings in shard_N tensors.
162
+ for name in list(state):
163
+ if not name.endswith(".ple.ple_embedding.ngram_embedding.weight"):
164
+ continue
165
+ table = state.pop(name)
166
+ parts = text.split_ngram_parts
167
+ rows = (table.shape[0] + parts - 1) // parts
168
+ prefix = name.removesuffix(".weight")
169
+ for part in range(parts):
170
+ state[f"{prefix}.shard_{part}.weight"] = table[part * rows:(part + 1) * rows].contiguous()
171
+ save_file(state, folder / "model.safetensors", metadata={"format": "pt"})
172
+ # Preserve tokenizer, processor and generation assets exactly as published.
173
+ assets = {
174
+ "tokenizer.json", "tokenizer_config.json", "special_tokens_map.json",
175
+ "vocab.json", "merges.txt", "added_tokens.json", "chat_template.jinja",
176
+ "chat_template.json", "preprocessor_config.json", "processor_config.json",
177
+ "video_preprocessor_config.json", "generation_config.json",
178
+ }
179
+ for name in sorted(set(list_repo_files(source_model_id, revision=source_revision)) & assets):
180
+ copyfile(hf_hub_download(source_model_id, name, revision=source_revision), folder / name)
181
  ```
182
 
183
  </details>
 
203
  - numpy: 2.3.5
204
  - safetensors: 0.8.0
205
  - sglang: 0.5.23.dev384+g9ab74b851
 
206
  - torch: 2.14.1
207
  - torchcodec: 0.17.0
208
  - transformers: 5.19.0
 
213
  ### Change log:
214
 
215
  - 2026-10-23: Initial version.
216
+ - 2026-10-23: Creation examples use only public dependencies; source assets are copied unchanged.
217
 
218
  This repo is generated by GPT-6.1-Sol