yujiepan commited on
Commit
346bb76
·
verified ·
1 Parent(s): d7ec583

Show verified image/video examples and actual model structures

Browse files
Files changed (1) hide show
  1. README.md +151 -3
README.md CHANGED
@@ -60,22 +60,31 @@ sglang serve \
60
  - Transformers (✅ verified)
61
 
62
  ```python
 
63
  import torch
64
  from PIL import Image
65
  from transformers import AutoProcessor, Qwen3_5ForConditionalGeneration
 
66
 
67
  model_id = "tiny-random/qwen3.8"
68
  model = Qwen3_5ForConditionalGeneration.from_pretrained(
69
  model_id, dtype=torch.bfloat16, device_map="cuda", attn_implementation="sdpa",
70
  )
71
  processor = AutoProcessor.from_pretrained(model_id)
 
 
 
 
72
  messages = [{"role": "user", "content": [
73
- {"type": "image", "image": Image.new("RGB", (64, 64), (220, 30, 30))},
74
- {"type": "text", "text": "Describe this image."},
 
75
  ]}]
76
  inputs = processor.apply_chat_template(
77
  messages, tokenize=True, add_generation_prompt=True,
78
  return_dict=True, return_tensors="pt",
 
 
79
  ).to(model.device)
80
  output = model.generate(**inputs, do_sample=False, max_new_tokens=10)
81
  print(processor.decode(output[0, inputs["input_ids"].shape[1]:], skip_special_tokens=True))
@@ -159,7 +168,146 @@ for name in sorted(set(list_repo_files(source_model_id, revision=source_revision
159
  <details><summary>Click to expand</summary>
160
 
161
  ```text
162
- Qwen3.8 VL: 8 backbone layers + 1 MTP layer; hidden_size=16
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
163
  ```
164
 
165
  </details>
 
60
  - Transformers (✅ verified)
61
 
62
  ```python
63
+ import numpy as np
64
  import torch
65
  from PIL import Image
66
  from transformers import AutoProcessor, Qwen3_5ForConditionalGeneration
67
+ from transformers.video_utils import VideoMetadata
68
 
69
  model_id = "tiny-random/qwen3.8"
70
  model = Qwen3_5ForConditionalGeneration.from_pretrained(
71
  model_id, dtype=torch.bfloat16, device_map="cuda", attn_implementation="sdpa",
72
  )
73
  processor = AutoProcessor.from_pretrained(model_id)
74
+ image = Image.new("RGB", (64, 64), (220, 30, 30))
75
+ # Four predecoded RGB frames, with timestamps supplied through video_metadata.
76
+ video = np.stack([np.asarray(Image.new("RGB", (64, 64), color)) for color in
77
+ [(220, 30, 30), (30, 220, 30), (30, 30, 220), (220, 220, 30)]])
78
  messages = [{"role": "user", "content": [
79
+ {"type": "image", "image": image},
80
+ {"type": "video", "video": video},
81
+ {"type": "text", "text": "Describe the image and the video."},
82
  ]}]
83
  inputs = processor.apply_chat_template(
84
  messages, tokenize=True, add_generation_prompt=True,
85
  return_dict=True, return_tensors="pt",
86
+ do_sample_frames=False,
87
+ video_metadata=[VideoMetadata(total_num_frames=4, fps=2, frames_indices=[0, 1, 2, 3])],
88
  ).to(model.device)
89
  output = model.generate(**inputs, do_sample=False, max_new_tokens=10)
90
  print(processor.decode(output[0, inputs["input_ids"].shape[1]:], skip_special_tokens=True))
 
168
  <details><summary>Click to expand</summary>
169
 
170
  ```text
171
+ Qwen3_5ForConditionalGeneration(
172
+ (model): Qwen3_5Model(
173
+ (visual): Qwen3_5VisionModel(
174
+ (patch_embed): Qwen3_5VisionPatchEmbed(
175
+ (proj): Conv3d(3, 64, kernel_size=(2, 16, 16), stride=(2, 16, 16))
176
+ )
177
+ (pos_embed): Embedding(2304, 64)
178
+ (rotary_pos_emb): Qwen3_5VisionRotaryEmbedding()
179
+ (blocks): ModuleList(
180
+ (0-1): 2 x Qwen3_5VisionBlock(
181
+ (norm1): LayerNorm((64,), eps=1e-06, elementwise_affine=True, bias=True)
182
+ (norm2): LayerNorm((64,), eps=1e-06, elementwise_affine=True, bias=True)
183
+ (attn): Qwen3_5VisionAttention(
184
+ (qkv): Linear(in_features=64, out_features=192, bias=True)
185
+ (proj): Linear(in_features=64, out_features=64, bias=True)
186
+ )
187
+ (mlp): Qwen3_5VisionMLP(
188
+ (linear_fc1): Linear(in_features=64, out_features=128, bias=True)
189
+ (linear_fc2): Linear(in_features=128, out_features=64, bias=True)
190
+ (act_fn): GELUTanh()
191
+ )
192
+ )
193
+ )
194
+ (merger): Qwen3_5VisionPatchMerger(
195
+ (norm): LayerNorm((64,), eps=1e-06, elementwise_affine=True, bias=True)
196
+ (linear_fc1): Linear(in_features=256, out_features=256, bias=True)
197
+ (act_fn): GELU(approximate='none')
198
+ (linear_fc2): Linear(in_features=256, out_features=16, bias=True)
199
+ )
200
+ )
201
+ (language_model): Qwen3_5TextModel(
202
+ (embed_tokens): Embedding(248320, 16)
203
+ (layers): ModuleList(
204
+ (0-2): 3 x Qwen3_5DecoderLayer(
205
+ (linear_attn): Qwen3_5GatedDeltaNet(
206
+ (conv1d): Conv1d(1280, 1280, kernel_size=(4,), stride=(1,), padding=(3,), groups=1280, bias=False)
207
+ (norm): Qwen3_5RMSNormGated()
208
+ (out_proj): Linear(in_features=768, out_features=16, bias=False)
209
+ (in_proj_qkv): Linear(in_features=16, out_features=1280, bias=False)
210
+ (in_proj_z): Linear(in_features=16, out_features=768, bias=False)
211
+ (in_proj_b): Linear(in_features=16, out_features=6, bias=False)
212
+ (in_proj_a): Linear(in_features=16, out_features=6, bias=False)
213
+ )
214
+ (mlp): Qwen3_5MLP(
215
+ (gate_proj): Linear(in_features=16, out_features=512, bias=False)
216
+ (up_proj): Linear(in_features=16, out_features=512, bias=False)
217
+ (down_proj): Linear(in_features=512, out_features=16, bias=False)
218
+ (act_fn): SiLUActivation()
219
+ )
220
+ (input_layernorm): Qwen3_5RMSNorm((16,), eps=1e-06)
221
+ (post_attention_layernorm): Qwen3_5RMSNorm((16,), eps=1e-06)
222
+ )
223
+ (3): Qwen3_5DecoderLayer(
224
+ (self_attn): Qwen3_5Attention(
225
+ (q_proj): Linear(in_features=16, out_features=3072, bias=False)
226
+ (k_proj): Linear(in_features=16, out_features=256, bias=False)
227
+ (v_proj): Linear(in_features=16, out_features=256, bias=False)
228
+ (o_proj): Linear(in_features=1536, out_features=16, bias=False)
229
+ (q_norm): Qwen3_5RMSNorm((128,), eps=1e-06)
230
+ (k_norm): Qwen3_5RMSNorm((128,), eps=1e-06)
231
+ )
232
+ (mlp): Qwen3_5MLP(
233
+ (gate_proj): Linear(in_features=16, out_features=512, bias=False)
234
+ (up_proj): Linear(in_features=16, out_features=512, bias=False)
235
+ (down_proj): Linear(in_features=512, out_features=16, bias=False)
236
+ (act_fn): SiLUActivation()
237
+ )
238
+ (input_layernorm): Qwen3_5RMSNorm((16,), eps=1e-06)
239
+ (post_attention_layernorm): Qwen3_5RMSNorm((16,), eps=1e-06)
240
+ )
241
+ (4-6): 3 x Qwen3_5DecoderLayer(
242
+ (linear_attn): Qwen3_5GatedDeltaNet(
243
+ (conv1d): Conv1d(1280, 1280, kernel_size=(4,), stride=(1,), padding=(3,), groups=1280, bias=False)
244
+ (norm): Qwen3_5RMSNormGated()
245
+ (out_proj): Linear(in_features=768, out_features=16, bias=False)
246
+ (in_proj_qkv): Linear(in_features=16, out_features=1280, bias=False)
247
+ (in_proj_z): Linear(in_features=16, out_features=768, bias=False)
248
+ (in_proj_b): Linear(in_features=16, out_features=6, bias=False)
249
+ (in_proj_a): Linear(in_features=16, out_features=6, bias=False)
250
+ )
251
+ (mlp): Qwen3_5MLP(
252
+ (gate_proj): Linear(in_features=16, out_features=512, bias=False)
253
+ (up_proj): Linear(in_features=16, out_features=512, bias=False)
254
+ (down_proj): Linear(in_features=512, out_features=16, bias=False)
255
+ (act_fn): SiLUActivation()
256
+ )
257
+ (input_layernorm): Qwen3_5RMSNorm((16,), eps=1e-06)
258
+ (post_attention_layernorm): Qwen3_5RMSNorm((16,), eps=1e-06)
259
+ )
260
+ (7): Qwen3_5DecoderLayer(
261
+ (self_attn): Qwen3_5Attention(
262
+ (q_proj): Linear(in_features=16, out_features=3072, bias=False)
263
+ (k_proj): Linear(in_features=16, out_features=256, bias=False)
264
+ (v_proj): Linear(in_features=16, out_features=256, bias=False)
265
+ (o_proj): Linear(in_features=1536, out_features=16, bias=False)
266
+ (q_norm): Qwen3_5RMSNorm((128,), eps=1e-06)
267
+ (k_norm): Qwen3_5RMSNorm((128,), eps=1e-06)
268
+ )
269
+ (mlp): Qwen3_5MLP(
270
+ (gate_proj): Linear(in_features=16, out_features=512, bias=False)
271
+ (up_proj): Linear(in_features=16, out_features=512, bias=False)
272
+ (down_proj): Linear(in_features=512, out_features=16, bias=False)
273
+ (act_fn): SiLUActivation()
274
+ )
275
+ (input_layernorm): Qwen3_5RMSNorm((16,), eps=1e-06)
276
+ (post_attention_layernorm): Qwen3_5RMSNorm((16,), eps=1e-06)
277
+ )
278
+ )
279
+ (norm): Qwen3_5RMSNorm((16,), eps=1e-06)
280
+ (rotary_emb): Qwen3_5TextRotaryEmbedding()
281
+ )
282
+ )
283
+ (lm_head): Linear(in_features=16, out_features=248320, bias=False)
284
+ (mtp): ModuleDict(
285
+ (pre_fc_norm_embedding): Qwen3_5RMSNorm((16,), eps=1e-06)
286
+ (pre_fc_norm_hidden): Qwen3_5RMSNorm((16,), eps=1e-06)
287
+ (fc): Linear(in_features=32, out_features=16, bias=False)
288
+ (layers): ModuleList(
289
+ (0): Qwen3_5DecoderLayer(
290
+ (self_attn): Qwen3_5Attention(
291
+ (q_proj): Linear(in_features=16, out_features=3072, bias=False)
292
+ (k_proj): Linear(in_features=16, out_features=256, bias=False)
293
+ (v_proj): Linear(in_features=16, out_features=256, bias=False)
294
+ (o_proj): Linear(in_features=1536, out_features=16, bias=False)
295
+ (q_norm): Qwen3_5RMSNorm((128,), eps=1e-06)
296
+ (k_norm): Qwen3_5RMSNorm((128,), eps=1e-06)
297
+ )
298
+ (mlp): Qwen3_5MLP(
299
+ (gate_proj): Linear(in_features=16, out_features=512, bias=False)
300
+ (up_proj): Linear(in_features=16, out_features=512, bias=False)
301
+ (down_proj): Linear(in_features=512, out_features=16, bias=False)
302
+ (act_fn): SiLUActivation()
303
+ )
304
+ (input_layernorm): Qwen3_5RMSNorm((16,), eps=1e-06)
305
+ (post_attention_layernorm): Qwen3_5RMSNorm((16,), eps=1e-06)
306
+ )
307
+ )
308
+ (norm): Qwen3_5RMSNorm((16,), eps=1e-06)
309
+ )
310
+ )
311
  ```
312
 
313
  </details>