Views
No views yet
| File path | Size |
|---|---|
| model.safetensors | 6.0MB |
1vllm serve tiny-random/step3-vl \
2 --trust-remote-code \
3 --reasoning-parser deepseek_r1 \
4 --enable-auto-tool-choice \
5 --tool-call-parser hermes1import torch
2from transformers import AutoModelForCausalLM, AutoProcessor
3
4model_id = "tiny-random/step3-vl"
5messages = [
6 {
7 "role": "user",
8 "content": [
9 {
10 "type": "image",
11 "url": "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/p-blog/candy.JPG"
12 },
13 {
14 "type": "text",
15 "text": "describe this image"
16 }
17 ],
18 }
19]
20processor = AutoProcessor.from_pretrained(
21 model_id,
22 trust_remote_code=True,
23)
24
25model = AutoModelForCausalLM.from_pretrained(
26 model_id,
27 torch_dtype=torch.bfloat16,
28 device_map="cuda",
29 trust_remote_code=True,
30 key_mapping={
31 "^vision_model": "model.vision_model",
32 r"^model(?!\.(language_model|vision_model))": "model.language_model",
33 "vit_large_projector": "model.vit_large_projector",
34 }
35)
36inputs = processor.apply_chat_template(
37 messages,
38 tokenize=True,
39 add_generation_prompt=True,
40 return_dict=True,
41 return_tensors="pt"
42).to(model.device)
43inputs.pop("token_type_ids", None)
44generated_ids = model.generate(**inputs, max_new_tokens=16)
45output_text = processor.decode(
46 generated_ids[0][inputs["input_ids"].shape[1]:], skip_special_tokens=False)
47print(output_text)1import json
2from pathlib import Path
3
4import accelerate
5import torch
6from huggingface_hub import file_exists, hf_hub_download, list_repo_files
7from safetensors.torch import save_file
8from transformers import (
9 AutoConfig,
10 AutoModel,
11 AutoModelForCausalLM,
12 AutoProcessor,
13 AutoTokenizer,
14 GenerationConfig,
15 set_seed,
16)
17
18source_model_id = "stepfun-ai/Step3-VL-10B"
19save_folder = "/tmp/tiny-random/step3-vl"
20
21Path(save_folder).mkdir(parents=True, exist_ok=True)
22for f in list_repo_files(source_model_id, repo_type="model"):
23 if (f.endswith('.json') or f.endswith('.py') or f.endswith('.model') or f.endswith('.jinja')) and (
24 not f.endswith('.index.json')
25 ):
26 hf_hub_download(repo_id=source_model_id, filename=f,
27 repo_type="model", local_dir=save_folder)
28
29def replace_file(filepath, old_string, new_string):
30 with open(filepath, 'r', encoding='utf-8') as f:
31 code = f.read()
32 code = code.replace(old_string, new_string)
33 with open(filepath, 'w', encoding='utf-8') as f:
34 f.write(code)
35
36with open(f'{save_folder}/config.json') as f:
37 config_json = json.load(f)
38
39config_json['text_config'].update({
40 'num_hidden_layers': 2,
41 'hidden_size': 8,
42 'head_dim': 32,
43 'intermediate_size': 64,
44 'num_attention_heads': 8,
45 "num_key_value_heads": 4,
46 'tie_word_embeddings': False,
47})
48config_json['vision_config'].update({
49 'width': 64,
50 'layers': 2,
51 'heads': 2,
52})
53with open(f"{save_folder}/config.json", "w", encoding='utf-8') as f:
54 json.dump(config_json, f, indent=2)
55
56config = AutoConfig.from_pretrained(
57 save_folder,
58 trust_remote_code=True,
59)
60print(config)
61torch.set_default_dtype(torch.bfloat16)
62model = AutoModelForCausalLM.from_config(config, trust_remote_code=True)
63torch.set_default_dtype(torch.float32)
64# if file_exists(filename="generation_config.json", repo_id=source_model_id, repo_type='model'):
65# model.generation_config = GenerationConfig.from_pretrained(
66# source_model_id, trust_remote_code=True,
67# )
68set_seed(42)
69model = model.cpu()
70with torch.no_grad():
71 for name, p in sorted(model.named_parameters()):
72 torch.nn.init.normal_(p, 0, 0.1)
73 print(name, p.shape)
74model_new = torch.nn.Identity()
75model_new.model = model.model.language_model
76model_new.vision_model = model.model.vision_model
77model_new.lm_head = model.lm_head
78model_new.vit_large_projector = model.model.vit_large_projector
79state_dict = model_new.state_dict()
80save_file(state_dict, f"{save_folder}/model.safetensors")1Step3VL10BForCausalLM(
2 (model): StepRoboticsModel(
3 (vision_model): StepRoboticsVisionEncoder(
4 (conv1): Conv2d(3, 64, kernel_size=(14, 14), stride=(14, 14), bias=False)
5 (ln_pre): LayerNorm((64,), eps=1e-05, elementwise_affine=True)
6 (ln_post): Identity()
7 (transformer): EncoderVisionTransformer(
8 (resblocks): ModuleList(
9 (0-1): 2 x EncoderVisionBlock(
10 (attn): EncoderVisionAttention(
11 (out_proj): Linear(in_features=64, out_features=64, bias=True)
12 (rope): EncoderRope2D()
13 )
14 (ln_1): LayerNorm((64,), eps=1e-05, elementwise_affine=True)
15 (ln_2): LayerNorm((64,), eps=1e-05, elementwise_affine=True)
16 (mlp): EncoderMLP(
17 (c_fc): Linear(in_features=64, out_features=373, bias=True)
18 (act_fn): QuickGELUActivation()
19 (c_proj): Linear(in_features=373, out_features=64, bias=True)
20 )
21 (ls_1): EncoderLayerScale()
22 (ls_2): EncoderLayerScale()
23 )
24 )
25 )
26 (vit_downsampler1): Conv2d(64, 128, kernel_size=(3, 3), stride=(2, 2), padding=(1, 1))
27 (vit_downsampler2): Conv2d(128, 256, kernel_size=(3, 3), stride=(2, 2), padding=(1, 1))
28 )
29 (language_model): Qwen3Model(
30 (embed_tokens): Embedding(151936, 8)
31 (layers): ModuleList(
32 (0-1): 2 x Qwen3DecoderLayer(
33 (self_attn): Qwen3Attention(
34 (q_proj): Linear(in_features=8, out_features=256, bias=False)
35 (k_proj): Linear(in_features=8, out_features=128, bias=False)
36 (v_proj): Linear(in_features=8, out_features=128, bias=False)
37 (o_proj): Linear(in_features=256, out_features=8, bias=False)
38 (q_norm): Qwen3RMSNorm((32,), eps=1e-06)
39 (k_norm): Qwen3RMSNorm((32,), eps=1e-06)
40 )
41 (mlp): Qwen3MLP(
42 (gate_proj): Linear(in_features=8, out_features=64, bias=False)
43 (up_proj): Linear(in_features=8, out_features=64, bias=False)
44 (down_proj): Linear(in_features=64, out_features=8, bias=False)
45 (act_fn): SiLUActivation()
46 )
47 (input_layernorm): Qwen3RMSNorm((8,), eps=1e-06)
48 (post_attention_layernorm): Qwen3RMSNorm((8,), eps=1e-06)
49 )
50 )
51 (norm): Qwen3RMSNorm((8,), eps=1e-06)
52 (rotary_emb): Qwen3RotaryEmbedding()
53 )
54 (vit_large_projector): Linear(in_features=256, out_features=8, bias=False)
55 )
56 (lm_head): Linear(in_features=8, out_features=151936, bias=False)
57)