yujiepan commited on
Commit
9aaa9ba
·
verified ·
1 Parent(s): c5e1f61

Make creation examples standalone with public dependencies

Browse files
Files changed (2) hide show
  1. .meta.json +1 -2
  2. README.md +40 -11
.meta.json CHANGED
@@ -8,8 +8,7 @@
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"
15
- }
 
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"
14
+ }
README.md CHANGED
@@ -87,13 +87,14 @@ print(processor.decode(output[0, inputs["input_ids"].shape[1]:], skip_special_to
87
 
88
  ```python
89
  import json
 
90
  from pathlib import Path
 
91
 
92
  import torch
93
- from huggingface_hub import hf_hub_download
94
- from transformers import AutoConfig, AutoModelForImageTextToText, AutoProcessor, GenerationConfig, set_seed
95
- # Creation helpers: pip install git+https://github.com/yujiepan/tiny-random.git
96
- from tiny_random.qwen_utils import add_qwen_mtp, save_random_qwen_checkpoint, compact_qwen_tokenizer, check_qwen_repo_size
97
 
98
  source_model_id = "Qwen/Qwen3.8-27B"
99
  save_folder = "/tmp/tiny-random/qwen38"
@@ -115,12 +116,40 @@ raw["vision_config"].update(depth=2, hidden_size=64, intermediate_size=128, num_
115
  (folder / "config.json").write_text(json.dumps(raw, indent=2))
116
  config = AutoConfig.from_pretrained(folder)
117
  model = AutoModelForImageTextToText.from_config(config, dtype=torch.bfloat16)
118
- add_qwen_mtp(model, model.model.language_model)
119
- save_random_qwen_checkpoint(model, folder)
120
- AutoProcessor.from_pretrained(source_model_id, revision=source_revision).save_pretrained(folder)
121
- GenerationConfig.from_pretrained(source_model_id, revision=source_revision).save_pretrained(folder)
122
- compact_qwen_tokenizer(folder)
123
- check_qwen_repo_size(folder)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
124
  ```
125
 
126
  </details>
@@ -146,7 +175,6 @@ Qwen3.8 VL: 8 backbone layers + 1 MTP layer; hidden_size=16
146
  - numpy: 2.3.5
147
  - safetensors: 0.8.0
148
  - sglang: 0.5.23.dev384+g9ab74b851
149
- - tiny-random: 0.2.0
150
  - torch: 2.14.1
151
  - torchcodec: 0.17.0
152
  - transformers: 5.19.0
@@ -155,5 +183,6 @@ Qwen3.8 VL: 8 backbone layers + 1 MTP layer; hidden_size=16
155
 
156
  - 2026-10-23: Initial version.
157
  - 2026-10-23: Reduced all repo files below 50 MB; GPU-validated TP=2, MTP and CUDA Graph.
 
158
 
159
  This repo is generated by GPT-6.1-Sol
 
87
 
88
  ```python
89
  import json
90
+ from copy import deepcopy
91
  from pathlib import Path
92
+ from shutil import copyfile
93
 
94
  import torch
95
+ from huggingface_hub import hf_hub_download, list_repo_files
96
+ from safetensors.torch import save_file
97
+ from transformers import AutoConfig, AutoModelForImageTextToText, set_seed
 
98
 
99
  source_model_id = "Qwen/Qwen3.8-27B"
100
  save_folder = "/tmp/tiny-random/qwen38"
 
116
  (folder / "config.json").write_text(json.dumps(raw, indent=2))
117
  config = AutoConfig.from_pretrained(folder)
118
  model = AutoModelForImageTextToText.from_config(config, dtype=torch.bfloat16)
119
+ backbone = model.model.language_model
120
+ text = backbone.config
121
+ def norm():
122
+ return type(backbone.norm)(text.hidden_size, text.rms_norm_eps).to(torch.bfloat16)
123
+ model.mtp = torch.nn.ModuleDict({
124
+ "pre_fc_norm_embedding": norm(),
125
+ "pre_fc_norm_hidden": norm(),
126
+ "fc": torch.nn.Linear(2 * text.hidden_size, text.hidden_size, bias=False, dtype=torch.bfloat16),
127
+ "layers": torch.nn.ModuleList([deepcopy(backbone.layers[-1])]),
128
+ "norm": norm(),
129
+ })
130
+ with torch.no_grad():
131
+ for name, param in sorted(model.named_parameters()):
132
+ if name.endswith("A_log"):
133
+ param.zero_()
134
+ elif name.endswith("dt_bias"):
135
+ param.fill_(1)
136
+ elif "norm" in name and name.endswith("weight"):
137
+ param.fill_(1 if "visual" in name or ".linear_attn.norm." in name else 0)
138
+ elif name.endswith("bias"):
139
+ param.zero_()
140
+ else:
141
+ torch.nn.init.normal_(param, mean=0, std=0.02)
142
+ state = {name: value.detach().cpu().contiguous() for name, value in model.state_dict().items()}
143
+ save_file(state, folder / "model.safetensors", metadata={"format": "pt"})
144
+ # Preserve tokenizer, processor and generation assets exactly as published.
145
+ assets = {
146
+ "tokenizer.json", "tokenizer_config.json", "special_tokens_map.json",
147
+ "vocab.json", "merges.txt", "added_tokens.json", "chat_template.jinja",
148
+ "chat_template.json", "preprocessor_config.json", "processor_config.json",
149
+ "video_preprocessor_config.json", "generation_config.json",
150
+ }
151
+ for name in sorted(set(list_repo_files(source_model_id, revision=source_revision)) & assets):
152
+ copyfile(hf_hub_download(source_model_id, name, revision=source_revision), folder / name)
153
  ```
154
 
155
  </details>
 
175
  - numpy: 2.3.5
176
  - safetensors: 0.8.0
177
  - sglang: 0.5.23.dev384+g9ab74b851
 
178
  - torch: 2.14.1
179
  - torchcodec: 0.17.0
180
  - transformers: 5.19.0
 
183
 
184
  - 2026-10-23: Initial version.
185
  - 2026-10-23: Reduced all repo files below 50 MB; GPU-validated TP=2, MTP and CUDA Graph.
186
+ - 2026-10-23: Creation examples use only public dependencies; source assets are copied unchanged.
187
 
188
  This repo is generated by GPT-6.1-Sol