jingwwu commited on
Commit
a4cc244
·
verified ·
1 Parent(s): 25ae38a

Upload folder using huggingface_hub

Browse files
.gitattributes CHANGED
@@ -33,3 +33,5 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
 
 
 
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
36
+ assets/comparision.png filter=lfs diff=lfs merge=lfs -text
37
+ tokenizer.json filter=lfs diff=lfs merge=lfs -text
README.md CHANGED
@@ -1,3 +1,92 @@
1
- ---
2
- license: apache-2.0
3
- ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: apache-2.0
3
+ pipeline_tag: text-to-image
4
+ library_name: transformers
5
+ ---
6
+
7
+ ## NextStep-1.1
8
+
9
+ [Homepage](https://stepfun.ai/research/en/nextstep-1) 
10
+ | [GitHub](https://github.com/stepfun-ai/NextStep-1) 
11
+ | [Paper](https://arxiv.org/abs/2508.10711) 
12
+
13
+ We introduce **NextStep-1.1**, a new model represents a significant leap forward in the NextStep series. This version effectively resolves the visualization failures seen in **NextStep-1** and substantially elevates image quality through extended training and a Flow-based Reinforcement Learning (RL) post-training paradigm.
14
+
15
+ <div align='center'>
16
+ <img src="assets/comparision.png" class="interpolation-image" alt="arch." width="100%" />
17
+ </div>
18
+
19
+ ## What's New in 1.1?
20
+
21
+ NextStep-1.1 is not just a fine-tune; it is a re-engineered version focused on stability and high-fidelity output. Key improvements include:
22
+
23
+ - RL Enhanced Visual Fidelity: Significant improvement in image texture and a substantial reduction in visual artifacts via RL, ensuring much cleaner and more professional outputs.
24
+
25
+ - Technical Stability: Solves numerical instability inherent in autoregressive flow-based models.
26
+
27
+ ## Environment Setup
28
+
29
+ To avoid potential errors when loading and running your models, we recommend using the following settings:
30
+
31
+ ```shell
32
+ conda create -n nextstep python=3.11 -y
33
+ conda activate nextstep
34
+
35
+ pip install uv # optional
36
+
37
+ GIT_LFS_SKIP_SMUDGE=1 git clone https://huggingface.co/stepfun-ai/NextStep-1.1-Pretrain-256px && cd NextStep-1.1-Pretrain-256px
38
+ uv pip install -r requirements.txt
39
+
40
+ hf download stepfun-ai/NextStep-1.1-Pretrain-256px "vae/checkpoint.pt" --local-dir ./
41
+ ```
42
+
43
+ ## Usage
44
+
45
+ ```python
46
+ import torch
47
+ from transformers import AutoTokenizer, AutoModel
48
+ from models.gen_pipeline import NextStepPipeline
49
+
50
+ HF_HUB = "stepfun-ai/NextStep-1.1-Pretrain-256px"
51
+
52
+ # load model and tokenizer
53
+ tokenizer = AutoTokenizer.from_pretrained(HF_HUB, local_files_only=True, trust_remote_code=True)
54
+ model = AutoModel.from_pretrained(HF_HUB, local_files_only=True, trust_remote_code=True)
55
+ pipeline = NextStepPipeline(tokenizer=tokenizer, model=model).to(device="cuda", dtype=torch.bfloat16)
56
+
57
+ # set prompts
58
+ positive_prompt = ""
59
+ negative_prompt = "lowres, bad anatomy, bad hands, text, error, missing fingers, extra digit, fewer digits, cropped, worst quality, low quality, normal quality, jpeg artifacts, signature, watermark, username, blurry."
60
+ example_prompt = "A REALISTIC PHOTOGRAPH OF A WALL WITH \"TOWARD AUTOREGRESSIVE IMAGE GENERATION WITH CONTINUOUS TOKENS AT SCALE\" PROMINENTLY DISPLAYED"
61
+
62
+ # generate image from text
63
+ IMG_SIZE = 256
64
+ image = pipeline.generate_image(
65
+ example_prompt,
66
+ hw=(IMG_SIZE, IMG_SIZE),
67
+ num_images_per_caption=1,
68
+ positive_prompt=positive_prompt,
69
+ negative_prompt=negative_prompt,
70
+ cfg=7.5,
71
+ cfg_img=1.0,
72
+ cfg_schedule="constant",
73
+ use_norm=False,
74
+ num_sampling_steps=28,
75
+ timesteps_shift=1.0,
76
+ seed=3407,
77
+ )[0]
78
+ image.save("./assets/output.jpg")
79
+ ```
80
+
81
+ ## Citation
82
+
83
+ If you find NextStep useful for your research and applications, please consider starring this repository and citing:
84
+
85
+ ```bibtex
86
+ @article{nextstepteam2025nextstep1,
87
+ title={NextStep-1: Toward Autoregressive Image Generation with Continuous Tokens at Scale},
88
+ author={NextStep Team and Chunrui Han and Guopeng Li and Jingwei Wu and Quan Sun and Yan Cai and Yuang Peng and Zheng Ge and Deyu Zhou and Haomiao Tang and Hongyu Zhou and Kenkun Liu and Ailin Huang and Bin Wang and Changxin Miao and Deshan Sun and En Yu and Fukun Yin and Gang Yu and Hao Nie and Haoran Lv and Hanpeng Hu and Jia Wang and Jian Zhou and Jianjian Sun and Kaijun Tan and Kang An and Kangheng Lin and Liang Zhao and Mei Chen and Peng Xing and Rui Wang and Shiyu Liu and Shutao Xia and Tianhao You and Wei Ji and Xianfang Zeng and Xin Han and Xuelin Zhang and Yana Wei and Yanming Xu and Yimin Jiang and Yingming Wang and Yu Zhou and Yucheng Han and Ziyang Meng and Binxing Jiao and Daxin Jiang and Xiangyu Zhang and Yibo Zhu},
89
+ journal={arXiv preprint arXiv:2508.10711},
90
+ year={2025}
91
+ }
92
+ ```
added_tokens.json ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "</tool_call>": 151658,
3
+ "<tool_call>": 151657,
4
+ "<|begin_of_image|>": 151667,
5
+ "<|begin_of_prompt_refinement|>": 151670,
6
+ "<|begin_of_thinking|>": 151672,
7
+ "<|box_end|>": 151649,
8
+ "<|box_start|>": 151648,
9
+ "<|end_of_image|>": 151668,
10
+ "<|end_of_prompt_refinement|>": 151671,
11
+ "<|end_of_thinking|>": 151673,
12
+ "<|beginoftext|>": 151674,
13
+ "<|endoftext|>": 151643,
14
+ "<|file_sep|>": 151664,
15
+ "<|fim_middle|>": 151660,
16
+ "<|fim_pad|>": 151662,
17
+ "<|fim_prefix|>": 151659,
18
+ "<|fim_suffix|>": 151661,
19
+ "<|im_end|>": 151645,
20
+ "<|im_start|>": 151644,
21
+ "<|image_area|>": 151666,
22
+ "<|image_pad|>": 151655,
23
+ "<|image_placeholder|>": 151669,
24
+ "<|object_ref_end|>": 151647,
25
+ "<|object_ref_start|>": 151646,
26
+ "<|quad_end|>": 151651,
27
+ "<|quad_start|>": 151650,
28
+ "<|repo_name|>": 151663,
29
+ "<|video_pad|>": 151656,
30
+ "<|vision_end|>": 151653,
31
+ "<|vision_pad|>": 151654,
32
+ "<|vision_start|>": 151652,
33
+ "[PAD]": 151665
34
+ }
assets/comparision.png ADDED

Git LFS Details

  • SHA256: c03496181fccd0cb84da7554c305cdeaf7f7f4e4af41b73fe97f36b7626504dd
  • Pointer size: 133 Bytes
  • Size of remote file: 16.5 MB
config.json ADDED
@@ -0,0 +1,66 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "_attn_implementation_autoset": true,
3
+ "architectures": [
4
+ "LlamaForCausalLM"
5
+ ],
6
+ "auto_map":{
7
+ "AutoConfig": "models/config.NextStepConfig",
8
+ "AutoModel": "models/nextstep_model.NextStep"
9
+ },
10
+ "attention_bias": true,
11
+ "attention_dropout": 0.0,
12
+ "base_image_grid_size": 64,
13
+ "boi": 151667,
14
+ "bos_token_id": 151643,
15
+ "create_kwargs": {
16
+ "snr_type": "lognorm"
17
+ },
18
+ "eoi": 151668,
19
+ "eos_token_id": 151643,
20
+ "genloss_batch_mul": 4,
21
+ "genloss_depth": 12,
22
+ "genloss_net_arch": "mlp",
23
+ "genloss_num_sampling_steps": "100",
24
+ "genloss_type": "transport",
25
+ "genloss_width": 1536,
26
+ "head_dim": 128,
27
+ "hidden_act": "silu",
28
+ "hidden_size": 5120,
29
+ "image_decoder_arch": "Trans_E",
30
+ "image_encoder_name": null,
31
+ "image_feature_layer": -2,
32
+ "image_loss_weight": 1.0,
33
+ "image_placeholder_id": 151669,
34
+ "image_size": 64,
35
+ "initializer_range": 0.02,
36
+ "intermediate_size": 13824,
37
+ "lm_loss_weight": 0.01,
38
+ "max_position_embeddings": 131072,
39
+ "max_window_layers": 48,
40
+ "mlp_bias": false,
41
+ "model_type": "nextstep",
42
+ "noise_strength": 0.0,
43
+ "num_attention_heads": 40,
44
+ "num_channels": 16,
45
+ "num_hidden_layers": 48,
46
+ "num_key_value_heads": 8,
47
+ "o_attention_bias": false,
48
+ "pad_token_id_added": 151665,
49
+ "patch_size": 2,
50
+ "pretraining_tp": 1,
51
+ "rms_norm_eps": 1e-05,
52
+ "rope_scaling": null,
53
+ "rope_theta": 1000000.0,
54
+ "sliding_window": 131072,
55
+ "tie_word_embeddings": false,
56
+ "torch_dtype": "bfloat16",
57
+ "transformers_version": "4.55.0",
58
+ "use_2d_rope": false,
59
+ "use_cache": true,
60
+ "use_gen_pos_embed": false,
61
+ "use_mlp_before_lm_head": false,
62
+ "use_sliding_window": false,
63
+ "use_token_length_weight": false,
64
+ "vae_name_or_path": "vae/",
65
+ "vocab_size": 152064
66
+ }
model.safetensors.index.json ADDED
@@ -0,0 +1,698 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "metadata": {
3
+ "total_size": 29907628160
4
+ },
5
+ "weight_map": {
6
+ "embed_tokens.weight": "pytorch-model-00004-of-00004.safetensors",
7
+ "image_head.net.cond_embed.bias": "pytorch-model-00003-of-00004.safetensors",
8
+ "image_head.net.cond_embed.weight": "pytorch-model-00003-of-00004.safetensors",
9
+ "image_head.net.final_layer.adaLN_modulation.1.bias": "pytorch-model-00003-of-00004.safetensors",
10
+ "image_head.net.final_layer.adaLN_modulation.1.weight": "pytorch-model-00003-of-00004.safetensors",
11
+ "image_head.net.final_layer.linear.bias": "pytorch-model-00003-of-00004.safetensors",
12
+ "image_head.net.final_layer.linear.weight": "pytorch-model-00003-of-00004.safetensors",
13
+ "image_head.net.input_proj.bias": "pytorch-model-00003-of-00004.safetensors",
14
+ "image_head.net.input_proj.weight": "pytorch-model-00003-of-00004.safetensors",
15
+ "image_head.net.res_blocks.0.adaLN_modulation.1.bias": "pytorch-model-00003-of-00004.safetensors",
16
+ "image_head.net.res_blocks.0.adaLN_modulation.1.weight": "pytorch-model-00003-of-00004.safetensors",
17
+ "image_head.net.res_blocks.0.in_ln.bias": "pytorch-model-00003-of-00004.safetensors",
18
+ "image_head.net.res_blocks.0.in_ln.weight": "pytorch-model-00003-of-00004.safetensors",
19
+ "image_head.net.res_blocks.0.mlp.0.bias": "pytorch-model-00003-of-00004.safetensors",
20
+ "image_head.net.res_blocks.0.mlp.0.weight": "pytorch-model-00003-of-00004.safetensors",
21
+ "image_head.net.res_blocks.0.mlp.2.bias": "pytorch-model-00003-of-00004.safetensors",
22
+ "image_head.net.res_blocks.0.mlp.2.weight": "pytorch-model-00003-of-00004.safetensors",
23
+ "image_head.net.res_blocks.1.adaLN_modulation.1.bias": "pytorch-model-00003-of-00004.safetensors",
24
+ "image_head.net.res_blocks.1.adaLN_modulation.1.weight": "pytorch-model-00003-of-00004.safetensors",
25
+ "image_head.net.res_blocks.1.in_ln.bias": "pytorch-model-00003-of-00004.safetensors",
26
+ "image_head.net.res_blocks.1.in_ln.weight": "pytorch-model-00003-of-00004.safetensors",
27
+ "image_head.net.res_blocks.1.mlp.0.bias": "pytorch-model-00003-of-00004.safetensors",
28
+ "image_head.net.res_blocks.1.mlp.0.weight": "pytorch-model-00003-of-00004.safetensors",
29
+ "image_head.net.res_blocks.1.mlp.2.bias": "pytorch-model-00003-of-00004.safetensors",
30
+ "image_head.net.res_blocks.1.mlp.2.weight": "pytorch-model-00003-of-00004.safetensors",
31
+ "image_head.net.res_blocks.10.adaLN_modulation.1.bias": "pytorch-model-00003-of-00004.safetensors",
32
+ "image_head.net.res_blocks.10.adaLN_modulation.1.weight": "pytorch-model-00003-of-00004.safetensors",
33
+ "image_head.net.res_blocks.10.in_ln.bias": "pytorch-model-00003-of-00004.safetensors",
34
+ "image_head.net.res_blocks.10.in_ln.weight": "pytorch-model-00003-of-00004.safetensors",
35
+ "image_head.net.res_blocks.10.mlp.0.bias": "pytorch-model-00003-of-00004.safetensors",
36
+ "image_head.net.res_blocks.10.mlp.0.weight": "pytorch-model-00003-of-00004.safetensors",
37
+ "image_head.net.res_blocks.10.mlp.2.bias": "pytorch-model-00003-of-00004.safetensors",
38
+ "image_head.net.res_blocks.10.mlp.2.weight": "pytorch-model-00003-of-00004.safetensors",
39
+ "image_head.net.res_blocks.11.adaLN_modulation.1.bias": "pytorch-model-00003-of-00004.safetensors",
40
+ "image_head.net.res_blocks.11.adaLN_modulation.1.weight": "pytorch-model-00003-of-00004.safetensors",
41
+ "image_head.net.res_blocks.11.in_ln.bias": "pytorch-model-00003-of-00004.safetensors",
42
+ "image_head.net.res_blocks.11.in_ln.weight": "pytorch-model-00003-of-00004.safetensors",
43
+ "image_head.net.res_blocks.11.mlp.0.bias": "pytorch-model-00003-of-00004.safetensors",
44
+ "image_head.net.res_blocks.11.mlp.0.weight": "pytorch-model-00003-of-00004.safetensors",
45
+ "image_head.net.res_blocks.11.mlp.2.bias": "pytorch-model-00003-of-00004.safetensors",
46
+ "image_head.net.res_blocks.11.mlp.2.weight": "pytorch-model-00003-of-00004.safetensors",
47
+ "image_head.net.res_blocks.2.adaLN_modulation.1.bias": "pytorch-model-00003-of-00004.safetensors",
48
+ "image_head.net.res_blocks.2.adaLN_modulation.1.weight": "pytorch-model-00003-of-00004.safetensors",
49
+ "image_head.net.res_blocks.2.in_ln.bias": "pytorch-model-00003-of-00004.safetensors",
50
+ "image_head.net.res_blocks.2.in_ln.weight": "pytorch-model-00003-of-00004.safetensors",
51
+ "image_head.net.res_blocks.2.mlp.0.bias": "pytorch-model-00003-of-00004.safetensors",
52
+ "image_head.net.res_blocks.2.mlp.0.weight": "pytorch-model-00003-of-00004.safetensors",
53
+ "image_head.net.res_blocks.2.mlp.2.bias": "pytorch-model-00003-of-00004.safetensors",
54
+ "image_head.net.res_blocks.2.mlp.2.weight": "pytorch-model-00003-of-00004.safetensors",
55
+ "image_head.net.res_blocks.3.adaLN_modulation.1.bias": "pytorch-model-00003-of-00004.safetensors",
56
+ "image_head.net.res_blocks.3.adaLN_modulation.1.weight": "pytorch-model-00003-of-00004.safetensors",
57
+ "image_head.net.res_blocks.3.in_ln.bias": "pytorch-model-00003-of-00004.safetensors",
58
+ "image_head.net.res_blocks.3.in_ln.weight": "pytorch-model-00003-of-00004.safetensors",
59
+ "image_head.net.res_blocks.3.mlp.0.bias": "pytorch-model-00003-of-00004.safetensors",
60
+ "image_head.net.res_blocks.3.mlp.0.weight": "pytorch-model-00003-of-00004.safetensors",
61
+ "image_head.net.res_blocks.3.mlp.2.bias": "pytorch-model-00003-of-00004.safetensors",
62
+ "image_head.net.res_blocks.3.mlp.2.weight": "pytorch-model-00003-of-00004.safetensors",
63
+ "image_head.net.res_blocks.4.adaLN_modulation.1.bias": "pytorch-model-00003-of-00004.safetensors",
64
+ "image_head.net.res_blocks.4.adaLN_modulation.1.weight": "pytorch-model-00003-of-00004.safetensors",
65
+ "image_head.net.res_blocks.4.in_ln.bias": "pytorch-model-00003-of-00004.safetensors",
66
+ "image_head.net.res_blocks.4.in_ln.weight": "pytorch-model-00003-of-00004.safetensors",
67
+ "image_head.net.res_blocks.4.mlp.0.bias": "pytorch-model-00003-of-00004.safetensors",
68
+ "image_head.net.res_blocks.4.mlp.0.weight": "pytorch-model-00003-of-00004.safetensors",
69
+ "image_head.net.res_blocks.4.mlp.2.bias": "pytorch-model-00003-of-00004.safetensors",
70
+ "image_head.net.res_blocks.4.mlp.2.weight": "pytorch-model-00003-of-00004.safetensors",
71
+ "image_head.net.res_blocks.5.adaLN_modulation.1.bias": "pytorch-model-00003-of-00004.safetensors",
72
+ "image_head.net.res_blocks.5.adaLN_modulation.1.weight": "pytorch-model-00003-of-00004.safetensors",
73
+ "image_head.net.res_blocks.5.in_ln.bias": "pytorch-model-00003-of-00004.safetensors",
74
+ "image_head.net.res_blocks.5.in_ln.weight": "pytorch-model-00003-of-00004.safetensors",
75
+ "image_head.net.res_blocks.5.mlp.0.bias": "pytorch-model-00003-of-00004.safetensors",
76
+ "image_head.net.res_blocks.5.mlp.0.weight": "pytorch-model-00003-of-00004.safetensors",
77
+ "image_head.net.res_blocks.5.mlp.2.bias": "pytorch-model-00003-of-00004.safetensors",
78
+ "image_head.net.res_blocks.5.mlp.2.weight": "pytorch-model-00003-of-00004.safetensors",
79
+ "image_head.net.res_blocks.6.adaLN_modulation.1.bias": "pytorch-model-00003-of-00004.safetensors",
80
+ "image_head.net.res_blocks.6.adaLN_modulation.1.weight": "pytorch-model-00003-of-00004.safetensors",
81
+ "image_head.net.res_blocks.6.in_ln.bias": "pytorch-model-00003-of-00004.safetensors",
82
+ "image_head.net.res_blocks.6.in_ln.weight": "pytorch-model-00003-of-00004.safetensors",
83
+ "image_head.net.res_blocks.6.mlp.0.bias": "pytorch-model-00003-of-00004.safetensors",
84
+ "image_head.net.res_blocks.6.mlp.0.weight": "pytorch-model-00003-of-00004.safetensors",
85
+ "image_head.net.res_blocks.6.mlp.2.bias": "pytorch-model-00003-of-00004.safetensors",
86
+ "image_head.net.res_blocks.6.mlp.2.weight": "pytorch-model-00003-of-00004.safetensors",
87
+ "image_head.net.res_blocks.7.adaLN_modulation.1.bias": "pytorch-model-00003-of-00004.safetensors",
88
+ "image_head.net.res_blocks.7.adaLN_modulation.1.weight": "pytorch-model-00003-of-00004.safetensors",
89
+ "image_head.net.res_blocks.7.in_ln.bias": "pytorch-model-00003-of-00004.safetensors",
90
+ "image_head.net.res_blocks.7.in_ln.weight": "pytorch-model-00003-of-00004.safetensors",
91
+ "image_head.net.res_blocks.7.mlp.0.bias": "pytorch-model-00003-of-00004.safetensors",
92
+ "image_head.net.res_blocks.7.mlp.0.weight": "pytorch-model-00003-of-00004.safetensors",
93
+ "image_head.net.res_blocks.7.mlp.2.bias": "pytorch-model-00003-of-00004.safetensors",
94
+ "image_head.net.res_blocks.7.mlp.2.weight": "pytorch-model-00003-of-00004.safetensors",
95
+ "image_head.net.res_blocks.8.adaLN_modulation.1.bias": "pytorch-model-00003-of-00004.safetensors",
96
+ "image_head.net.res_blocks.8.adaLN_modulation.1.weight": "pytorch-model-00003-of-00004.safetensors",
97
+ "image_head.net.res_blocks.8.in_ln.bias": "pytorch-model-00003-of-00004.safetensors",
98
+ "image_head.net.res_blocks.8.in_ln.weight": "pytorch-model-00003-of-00004.safetensors",
99
+ "image_head.net.res_blocks.8.mlp.0.bias": "pytorch-model-00003-of-00004.safetensors",
100
+ "image_head.net.res_blocks.8.mlp.0.weight": "pytorch-model-00003-of-00004.safetensors",
101
+ "image_head.net.res_blocks.8.mlp.2.bias": "pytorch-model-00003-of-00004.safetensors",
102
+ "image_head.net.res_blocks.8.mlp.2.weight": "pytorch-model-00003-of-00004.safetensors",
103
+ "image_head.net.res_blocks.9.adaLN_modulation.1.bias": "pytorch-model-00003-of-00004.safetensors",
104
+ "image_head.net.res_blocks.9.adaLN_modulation.1.weight": "pytorch-model-00003-of-00004.safetensors",
105
+ "image_head.net.res_blocks.9.in_ln.bias": "pytorch-model-00003-of-00004.safetensors",
106
+ "image_head.net.res_blocks.9.in_ln.weight": "pytorch-model-00003-of-00004.safetensors",
107
+ "image_head.net.res_blocks.9.mlp.0.bias": "pytorch-model-00003-of-00004.safetensors",
108
+ "image_head.net.res_blocks.9.mlp.0.weight": "pytorch-model-00003-of-00004.safetensors",
109
+ "image_head.net.res_blocks.9.mlp.2.bias": "pytorch-model-00003-of-00004.safetensors",
110
+ "image_head.net.res_blocks.9.mlp.2.weight": "pytorch-model-00003-of-00004.safetensors",
111
+ "image_head.net.time_embed.mlp.0.bias": "pytorch-model-00003-of-00004.safetensors",
112
+ "image_head.net.time_embed.mlp.0.weight": "pytorch-model-00003-of-00004.safetensors",
113
+ "image_head.net.time_embed.mlp.2.bias": "pytorch-model-00003-of-00004.safetensors",
114
+ "image_head.net.time_embed.mlp.2.weight": "pytorch-model-00003-of-00004.safetensors",
115
+ "image_in_projector.bias": "pytorch-model-00003-of-00004.safetensors",
116
+ "image_in_projector.weight": "pytorch-model-00003-of-00004.safetensors",
117
+ "image_out_projector.bias": "pytorch-model-00003-of-00004.safetensors",
118
+ "image_out_projector.weight": "pytorch-model-00003-of-00004.safetensors",
119
+ "layers.0.input_layernorm.weight": "pytorch-model-00001-of-00004.safetensors",
120
+ "layers.0.mlp.down_proj.weight": "pytorch-model-00001-of-00004.safetensors",
121
+ "layers.0.mlp.gate_proj.weight": "pytorch-model-00001-of-00004.safetensors",
122
+ "layers.0.mlp.up_proj.weight": "pytorch-model-00001-of-00004.safetensors",
123
+ "layers.0.post_attention_layernorm.weight": "pytorch-model-00001-of-00004.safetensors",
124
+ "layers.0.self_attn.k_proj.bias": "pytorch-model-00001-of-00004.safetensors",
125
+ "layers.0.self_attn.k_proj.weight": "pytorch-model-00001-of-00004.safetensors",
126
+ "layers.0.self_attn.o_proj.weight": "pytorch-model-00001-of-00004.safetensors",
127
+ "layers.0.self_attn.q_proj.bias": "pytorch-model-00001-of-00004.safetensors",
128
+ "layers.0.self_attn.q_proj.weight": "pytorch-model-00001-of-00004.safetensors",
129
+ "layers.0.self_attn.v_proj.bias": "pytorch-model-00001-of-00004.safetensors",
130
+ "layers.0.self_attn.v_proj.weight": "pytorch-model-00001-of-00004.safetensors",
131
+ "layers.1.input_layernorm.weight": "pytorch-model-00001-of-00004.safetensors",
132
+ "layers.1.mlp.down_proj.weight": "pytorch-model-00001-of-00004.safetensors",
133
+ "layers.1.mlp.gate_proj.weight": "pytorch-model-00001-of-00004.safetensors",
134
+ "layers.1.mlp.up_proj.weight": "pytorch-model-00001-of-00004.safetensors",
135
+ "layers.1.post_attention_layernorm.weight": "pytorch-model-00001-of-00004.safetensors",
136
+ "layers.1.self_attn.k_proj.bias": "pytorch-model-00001-of-00004.safetensors",
137
+ "layers.1.self_attn.k_proj.weight": "pytorch-model-00001-of-00004.safetensors",
138
+ "layers.1.self_attn.o_proj.weight": "pytorch-model-00001-of-00004.safetensors",
139
+ "layers.1.self_attn.q_proj.bias": "pytorch-model-00001-of-00004.safetensors",
140
+ "layers.1.self_attn.q_proj.weight": "pytorch-model-00001-of-00004.safetensors",
141
+ "layers.1.self_attn.v_proj.bias": "pytorch-model-00001-of-00004.safetensors",
142
+ "layers.1.self_attn.v_proj.weight": "pytorch-model-00001-of-00004.safetensors",
143
+ "layers.10.input_layernorm.weight": "pytorch-model-00001-of-00004.safetensors",
144
+ "layers.10.mlp.down_proj.weight": "pytorch-model-00001-of-00004.safetensors",
145
+ "layers.10.mlp.gate_proj.weight": "pytorch-model-00001-of-00004.safetensors",
146
+ "layers.10.mlp.up_proj.weight": "pytorch-model-00001-of-00004.safetensors",
147
+ "layers.10.post_attention_layernorm.weight": "pytorch-model-00001-of-00004.safetensors",
148
+ "layers.10.self_attn.k_proj.bias": "pytorch-model-00001-of-00004.safetensors",
149
+ "layers.10.self_attn.k_proj.weight": "pytorch-model-00001-of-00004.safetensors",
150
+ "layers.10.self_attn.o_proj.weight": "pytorch-model-00001-of-00004.safetensors",
151
+ "layers.10.self_attn.q_proj.bias": "pytorch-model-00001-of-00004.safetensors",
152
+ "layers.10.self_attn.q_proj.weight": "pytorch-model-00001-of-00004.safetensors",
153
+ "layers.10.self_attn.v_proj.bias": "pytorch-model-00001-of-00004.safetensors",
154
+ "layers.10.self_attn.v_proj.weight": "pytorch-model-00001-of-00004.safetensors",
155
+ "layers.11.input_layernorm.weight": "pytorch-model-00001-of-00004.safetensors",
156
+ "layers.11.mlp.down_proj.weight": "pytorch-model-00001-of-00004.safetensors",
157
+ "layers.11.mlp.gate_proj.weight": "pytorch-model-00001-of-00004.safetensors",
158
+ "layers.11.mlp.up_proj.weight": "pytorch-model-00001-of-00004.safetensors",
159
+ "layers.11.post_attention_layernorm.weight": "pytorch-model-00001-of-00004.safetensors",
160
+ "layers.11.self_attn.k_proj.bias": "pytorch-model-00001-of-00004.safetensors",
161
+ "layers.11.self_attn.k_proj.weight": "pytorch-model-00001-of-00004.safetensors",
162
+ "layers.11.self_attn.o_proj.weight": "pytorch-model-00001-of-00004.safetensors",
163
+ "layers.11.self_attn.q_proj.bias": "pytorch-model-00001-of-00004.safetensors",
164
+ "layers.11.self_attn.q_proj.weight": "pytorch-model-00001-of-00004.safetensors",
165
+ "layers.11.self_attn.v_proj.bias": "pytorch-model-00001-of-00004.safetensors",
166
+ "layers.11.self_attn.v_proj.weight": "pytorch-model-00001-of-00004.safetensors",
167
+ "layers.12.input_layernorm.weight": "pytorch-model-00001-of-00004.safetensors",
168
+ "layers.12.mlp.down_proj.weight": "pytorch-model-00001-of-00004.safetensors",
169
+ "layers.12.mlp.gate_proj.weight": "pytorch-model-00001-of-00004.safetensors",
170
+ "layers.12.mlp.up_proj.weight": "pytorch-model-00001-of-00004.safetensors",
171
+ "layers.12.post_attention_layernorm.weight": "pytorch-model-00001-of-00004.safetensors",
172
+ "layers.12.self_attn.k_proj.bias": "pytorch-model-00001-of-00004.safetensors",
173
+ "layers.12.self_attn.k_proj.weight": "pytorch-model-00001-of-00004.safetensors",
174
+ "layers.12.self_attn.o_proj.weight": "pytorch-model-00001-of-00004.safetensors",
175
+ "layers.12.self_attn.q_proj.bias": "pytorch-model-00001-of-00004.safetensors",
176
+ "layers.12.self_attn.q_proj.weight": "pytorch-model-00001-of-00004.safetensors",
177
+ "layers.12.self_attn.v_proj.bias": "pytorch-model-00001-of-00004.safetensors",
178
+ "layers.12.self_attn.v_proj.weight": "pytorch-model-00001-of-00004.safetensors",
179
+ "layers.13.input_layernorm.weight": "pytorch-model-00001-of-00004.safetensors",
180
+ "layers.13.mlp.down_proj.weight": "pytorch-model-00001-of-00004.safetensors",
181
+ "layers.13.mlp.gate_proj.weight": "pytorch-model-00001-of-00004.safetensors",
182
+ "layers.13.mlp.up_proj.weight": "pytorch-model-00001-of-00004.safetensors",
183
+ "layers.13.post_attention_layernorm.weight": "pytorch-model-00001-of-00004.safetensors",
184
+ "layers.13.self_attn.k_proj.bias": "pytorch-model-00001-of-00004.safetensors",
185
+ "layers.13.self_attn.k_proj.weight": "pytorch-model-00001-of-00004.safetensors",
186
+ "layers.13.self_attn.o_proj.weight": "pytorch-model-00001-of-00004.safetensors",
187
+ "layers.13.self_attn.q_proj.bias": "pytorch-model-00001-of-00004.safetensors",
188
+ "layers.13.self_attn.q_proj.weight": "pytorch-model-00001-of-00004.safetensors",
189
+ "layers.13.self_attn.v_proj.bias": "pytorch-model-00001-of-00004.safetensors",
190
+ "layers.13.self_attn.v_proj.weight": "pytorch-model-00001-of-00004.safetensors",
191
+ "layers.14.input_layernorm.weight": "pytorch-model-00001-of-00004.safetensors",
192
+ "layers.14.mlp.down_proj.weight": "pytorch-model-00001-of-00004.safetensors",
193
+ "layers.14.mlp.gate_proj.weight": "pytorch-model-00001-of-00004.safetensors",
194
+ "layers.14.mlp.up_proj.weight": "pytorch-model-00001-of-00004.safetensors",
195
+ "layers.14.post_attention_layernorm.weight": "pytorch-model-00001-of-00004.safetensors",
196
+ "layers.14.self_attn.k_proj.bias": "pytorch-model-00001-of-00004.safetensors",
197
+ "layers.14.self_attn.k_proj.weight": "pytorch-model-00001-of-00004.safetensors",
198
+ "layers.14.self_attn.o_proj.weight": "pytorch-model-00001-of-00004.safetensors",
199
+ "layers.14.self_attn.q_proj.bias": "pytorch-model-00001-of-00004.safetensors",
200
+ "layers.14.self_attn.q_proj.weight": "pytorch-model-00001-of-00004.safetensors",
201
+ "layers.14.self_attn.v_proj.bias": "pytorch-model-00001-of-00004.safetensors",
202
+ "layers.14.self_attn.v_proj.weight": "pytorch-model-00001-of-00004.safetensors",
203
+ "layers.15.input_layernorm.weight": "pytorch-model-00001-of-00004.safetensors",
204
+ "layers.15.mlp.down_proj.weight": "pytorch-model-00001-of-00004.safetensors",
205
+ "layers.15.mlp.gate_proj.weight": "pytorch-model-00001-of-00004.safetensors",
206
+ "layers.15.mlp.up_proj.weight": "pytorch-model-00001-of-00004.safetensors",
207
+ "layers.15.post_attention_layernorm.weight": "pytorch-model-00001-of-00004.safetensors",
208
+ "layers.15.self_attn.k_proj.bias": "pytorch-model-00001-of-00004.safetensors",
209
+ "layers.15.self_attn.k_proj.weight": "pytorch-model-00001-of-00004.safetensors",
210
+ "layers.15.self_attn.o_proj.weight": "pytorch-model-00001-of-00004.safetensors",
211
+ "layers.15.self_attn.q_proj.bias": "pytorch-model-00001-of-00004.safetensors",
212
+ "layers.15.self_attn.q_proj.weight": "pytorch-model-00001-of-00004.safetensors",
213
+ "layers.15.self_attn.v_proj.bias": "pytorch-model-00001-of-00004.safetensors",
214
+ "layers.15.self_attn.v_proj.weight": "pytorch-model-00001-of-00004.safetensors",
215
+ "layers.16.input_layernorm.weight": "pytorch-model-00001-of-00004.safetensors",
216
+ "layers.16.mlp.down_proj.weight": "pytorch-model-00001-of-00004.safetensors",
217
+ "layers.16.mlp.gate_proj.weight": "pytorch-model-00001-of-00004.safetensors",
218
+ "layers.16.mlp.up_proj.weight": "pytorch-model-00001-of-00004.safetensors",
219
+ "layers.16.post_attention_layernorm.weight": "pytorch-model-00001-of-00004.safetensors",
220
+ "layers.16.self_attn.k_proj.bias": "pytorch-model-00001-of-00004.safetensors",
221
+ "layers.16.self_attn.k_proj.weight": "pytorch-model-00001-of-00004.safetensors",
222
+ "layers.16.self_attn.o_proj.weight": "pytorch-model-00001-of-00004.safetensors",
223
+ "layers.16.self_attn.q_proj.bias": "pytorch-model-00001-of-00004.safetensors",
224
+ "layers.16.self_attn.q_proj.weight": "pytorch-model-00001-of-00004.safetensors",
225
+ "layers.16.self_attn.v_proj.bias": "pytorch-model-00001-of-00004.safetensors",
226
+ "layers.16.self_attn.v_proj.weight": "pytorch-model-00001-of-00004.safetensors",
227
+ "layers.17.input_layernorm.weight": "pytorch-model-00001-of-00004.safetensors",
228
+ "layers.17.mlp.down_proj.weight": "pytorch-model-00001-of-00004.safetensors",
229
+ "layers.17.mlp.gate_proj.weight": "pytorch-model-00001-of-00004.safetensors",
230
+ "layers.17.mlp.up_proj.weight": "pytorch-model-00001-of-00004.safetensors",
231
+ "layers.17.post_attention_layernorm.weight": "pytorch-model-00001-of-00004.safetensors",
232
+ "layers.17.self_attn.k_proj.bias": "pytorch-model-00001-of-00004.safetensors",
233
+ "layers.17.self_attn.k_proj.weight": "pytorch-model-00001-of-00004.safetensors",
234
+ "layers.17.self_attn.o_proj.weight": "pytorch-model-00001-of-00004.safetensors",
235
+ "layers.17.self_attn.q_proj.bias": "pytorch-model-00001-of-00004.safetensors",
236
+ "layers.17.self_attn.q_proj.weight": "pytorch-model-00001-of-00004.safetensors",
237
+ "layers.17.self_attn.v_proj.bias": "pytorch-model-00001-of-00004.safetensors",
238
+ "layers.17.self_attn.v_proj.weight": "pytorch-model-00001-of-00004.safetensors",
239
+ "layers.18.input_layernorm.weight": "pytorch-model-00001-of-00004.safetensors",
240
+ "layers.18.mlp.down_proj.weight": "pytorch-model-00001-of-00004.safetensors",
241
+ "layers.18.mlp.gate_proj.weight": "pytorch-model-00001-of-00004.safetensors",
242
+ "layers.18.mlp.up_proj.weight": "pytorch-model-00001-of-00004.safetensors",
243
+ "layers.18.post_attention_layernorm.weight": "pytorch-model-00001-of-00004.safetensors",
244
+ "layers.18.self_attn.k_proj.bias": "pytorch-model-00001-of-00004.safetensors",
245
+ "layers.18.self_attn.k_proj.weight": "pytorch-model-00001-of-00004.safetensors",
246
+ "layers.18.self_attn.o_proj.weight": "pytorch-model-00001-of-00004.safetensors",
247
+ "layers.18.self_attn.q_proj.bias": "pytorch-model-00001-of-00004.safetensors",
248
+ "layers.18.self_attn.q_proj.weight": "pytorch-model-00001-of-00004.safetensors",
249
+ "layers.18.self_attn.v_proj.bias": "pytorch-model-00001-of-00004.safetensors",
250
+ "layers.18.self_attn.v_proj.weight": "pytorch-model-00001-of-00004.safetensors",
251
+ "layers.19.input_layernorm.weight": "pytorch-model-00001-of-00004.safetensors",
252
+ "layers.19.mlp.down_proj.weight": "pytorch-model-00001-of-00004.safetensors",
253
+ "layers.19.mlp.gate_proj.weight": "pytorch-model-00001-of-00004.safetensors",
254
+ "layers.19.mlp.up_proj.weight": "pytorch-model-00001-of-00004.safetensors",
255
+ "layers.19.post_attention_layernorm.weight": "pytorch-model-00001-of-00004.safetensors",
256
+ "layers.19.self_attn.k_proj.bias": "pytorch-model-00001-of-00004.safetensors",
257
+ "layers.19.self_attn.k_proj.weight": "pytorch-model-00001-of-00004.safetensors",
258
+ "layers.19.self_attn.o_proj.weight": "pytorch-model-00001-of-00004.safetensors",
259
+ "layers.19.self_attn.q_proj.bias": "pytorch-model-00001-of-00004.safetensors",
260
+ "layers.19.self_attn.q_proj.weight": "pytorch-model-00001-of-00004.safetensors",
261
+ "layers.19.self_attn.v_proj.bias": "pytorch-model-00001-of-00004.safetensors",
262
+ "layers.19.self_attn.v_proj.weight": "pytorch-model-00001-of-00004.safetensors",
263
+ "layers.2.input_layernorm.weight": "pytorch-model-00001-of-00004.safetensors",
264
+ "layers.2.mlp.down_proj.weight": "pytorch-model-00001-of-00004.safetensors",
265
+ "layers.2.mlp.gate_proj.weight": "pytorch-model-00001-of-00004.safetensors",
266
+ "layers.2.mlp.up_proj.weight": "pytorch-model-00001-of-00004.safetensors",
267
+ "layers.2.post_attention_layernorm.weight": "pytorch-model-00001-of-00004.safetensors",
268
+ "layers.2.self_attn.k_proj.bias": "pytorch-model-00001-of-00004.safetensors",
269
+ "layers.2.self_attn.k_proj.weight": "pytorch-model-00001-of-00004.safetensors",
270
+ "layers.2.self_attn.o_proj.weight": "pytorch-model-00001-of-00004.safetensors",
271
+ "layers.2.self_attn.q_proj.bias": "pytorch-model-00001-of-00004.safetensors",
272
+ "layers.2.self_attn.q_proj.weight": "pytorch-model-00001-of-00004.safetensors",
273
+ "layers.2.self_attn.v_proj.bias": "pytorch-model-00001-of-00004.safetensors",
274
+ "layers.2.self_attn.v_proj.weight": "pytorch-model-00001-of-00004.safetensors",
275
+ "layers.20.input_layernorm.weight": "pytorch-model-00001-of-00004.safetensors",
276
+ "layers.20.mlp.down_proj.weight": "pytorch-model-00001-of-00004.safetensors",
277
+ "layers.20.mlp.gate_proj.weight": "pytorch-model-00001-of-00004.safetensors",
278
+ "layers.20.mlp.up_proj.weight": "pytorch-model-00001-of-00004.safetensors",
279
+ "layers.20.post_attention_layernorm.weight": "pytorch-model-00001-of-00004.safetensors",
280
+ "layers.20.self_attn.k_proj.bias": "pytorch-model-00001-of-00004.safetensors",
281
+ "layers.20.self_attn.k_proj.weight": "pytorch-model-00001-of-00004.safetensors",
282
+ "layers.20.self_attn.o_proj.weight": "pytorch-model-00001-of-00004.safetensors",
283
+ "layers.20.self_attn.q_proj.bias": "pytorch-model-00001-of-00004.safetensors",
284
+ "layers.20.self_attn.q_proj.weight": "pytorch-model-00001-of-00004.safetensors",
285
+ "layers.20.self_attn.v_proj.bias": "pytorch-model-00001-of-00004.safetensors",
286
+ "layers.20.self_attn.v_proj.weight": "pytorch-model-00001-of-00004.safetensors",
287
+ "layers.21.input_layernorm.weight": "pytorch-model-00001-of-00004.safetensors",
288
+ "layers.21.mlp.down_proj.weight": "pytorch-model-00001-of-00004.safetensors",
289
+ "layers.21.mlp.gate_proj.weight": "pytorch-model-00001-of-00004.safetensors",
290
+ "layers.21.mlp.up_proj.weight": "pytorch-model-00001-of-00004.safetensors",
291
+ "layers.21.post_attention_layernorm.weight": "pytorch-model-00001-of-00004.safetensors",
292
+ "layers.21.self_attn.k_proj.bias": "pytorch-model-00001-of-00004.safetensors",
293
+ "layers.21.self_attn.k_proj.weight": "pytorch-model-00001-of-00004.safetensors",
294
+ "layers.21.self_attn.o_proj.weight": "pytorch-model-00001-of-00004.safetensors",
295
+ "layers.21.self_attn.q_proj.bias": "pytorch-model-00001-of-00004.safetensors",
296
+ "layers.21.self_attn.q_proj.weight": "pytorch-model-00001-of-00004.safetensors",
297
+ "layers.21.self_attn.v_proj.bias": "pytorch-model-00001-of-00004.safetensors",
298
+ "layers.21.self_attn.v_proj.weight": "pytorch-model-00001-of-00004.safetensors",
299
+ "layers.22.input_layernorm.weight": "pytorch-model-00001-of-00004.safetensors",
300
+ "layers.22.mlp.down_proj.weight": "pytorch-model-00001-of-00004.safetensors",
301
+ "layers.22.mlp.gate_proj.weight": "pytorch-model-00001-of-00004.safetensors",
302
+ "layers.22.mlp.up_proj.weight": "pytorch-model-00001-of-00004.safetensors",
303
+ "layers.22.post_attention_layernorm.weight": "pytorch-model-00001-of-00004.safetensors",
304
+ "layers.22.self_attn.k_proj.bias": "pytorch-model-00001-of-00004.safetensors",
305
+ "layers.22.self_attn.k_proj.weight": "pytorch-model-00001-of-00004.safetensors",
306
+ "layers.22.self_attn.o_proj.weight": "pytorch-model-00001-of-00004.safetensors",
307
+ "layers.22.self_attn.q_proj.bias": "pytorch-model-00001-of-00004.safetensors",
308
+ "layers.22.self_attn.q_proj.weight": "pytorch-model-00001-of-00004.safetensors",
309
+ "layers.22.self_attn.v_proj.bias": "pytorch-model-00001-of-00004.safetensors",
310
+ "layers.22.self_attn.v_proj.weight": "pytorch-model-00001-of-00004.safetensors",
311
+ "layers.23.input_layernorm.weight": "pytorch-model-00001-of-00004.safetensors",
312
+ "layers.23.mlp.down_proj.weight": "pytorch-model-00001-of-00004.safetensors",
313
+ "layers.23.mlp.gate_proj.weight": "pytorch-model-00001-of-00004.safetensors",
314
+ "layers.23.mlp.up_proj.weight": "pytorch-model-00001-of-00004.safetensors",
315
+ "layers.23.post_attention_layernorm.weight": "pytorch-model-00001-of-00004.safetensors",
316
+ "layers.23.self_attn.k_proj.bias": "pytorch-model-00001-of-00004.safetensors",
317
+ "layers.23.self_attn.k_proj.weight": "pytorch-model-00001-of-00004.safetensors",
318
+ "layers.23.self_attn.o_proj.weight": "pytorch-model-00001-of-00004.safetensors",
319
+ "layers.23.self_attn.q_proj.bias": "pytorch-model-00001-of-00004.safetensors",
320
+ "layers.23.self_attn.q_proj.weight": "pytorch-model-00001-of-00004.safetensors",
321
+ "layers.23.self_attn.v_proj.bias": "pytorch-model-00001-of-00004.safetensors",
322
+ "layers.23.self_attn.v_proj.weight": "pytorch-model-00001-of-00004.safetensors",
323
+ "layers.24.input_layernorm.weight": "pytorch-model-00001-of-00004.safetensors",
324
+ "layers.24.mlp.down_proj.weight": "pytorch-model-00001-of-00004.safetensors",
325
+ "layers.24.mlp.gate_proj.weight": "pytorch-model-00001-of-00004.safetensors",
326
+ "layers.24.mlp.up_proj.weight": "pytorch-model-00001-of-00004.safetensors",
327
+ "layers.24.post_attention_layernorm.weight": "pytorch-model-00001-of-00004.safetensors",
328
+ "layers.24.self_attn.k_proj.bias": "pytorch-model-00001-of-00004.safetensors",
329
+ "layers.24.self_attn.k_proj.weight": "pytorch-model-00001-of-00004.safetensors",
330
+ "layers.24.self_attn.o_proj.weight": "pytorch-model-00001-of-00004.safetensors",
331
+ "layers.24.self_attn.q_proj.bias": "pytorch-model-00001-of-00004.safetensors",
332
+ "layers.24.self_attn.q_proj.weight": "pytorch-model-00001-of-00004.safetensors",
333
+ "layers.24.self_attn.v_proj.bias": "pytorch-model-00001-of-00004.safetensors",
334
+ "layers.24.self_attn.v_proj.weight": "pytorch-model-00001-of-00004.safetensors",
335
+ "layers.25.input_layernorm.weight": "pytorch-model-00001-of-00004.safetensors",
336
+ "layers.25.mlp.down_proj.weight": "pytorch-model-00002-of-00004.safetensors",
337
+ "layers.25.mlp.gate_proj.weight": "pytorch-model-00002-of-00004.safetensors",
338
+ "layers.25.mlp.up_proj.weight": "pytorch-model-00002-of-00004.safetensors",
339
+ "layers.25.post_attention_layernorm.weight": "pytorch-model-00002-of-00004.safetensors",
340
+ "layers.25.self_attn.k_proj.bias": "pytorch-model-00002-of-00004.safetensors",
341
+ "layers.25.self_attn.k_proj.weight": "pytorch-model-00002-of-00004.safetensors",
342
+ "layers.25.self_attn.o_proj.weight": "pytorch-model-00001-of-00004.safetensors",
343
+ "layers.25.self_attn.q_proj.bias": "pytorch-model-00002-of-00004.safetensors",
344
+ "layers.25.self_attn.q_proj.weight": "pytorch-model-00002-of-00004.safetensors",
345
+ "layers.25.self_attn.v_proj.bias": "pytorch-model-00002-of-00004.safetensors",
346
+ "layers.25.self_attn.v_proj.weight": "pytorch-model-00002-of-00004.safetensors",
347
+ "layers.26.input_layernorm.weight": "pytorch-model-00002-of-00004.safetensors",
348
+ "layers.26.mlp.down_proj.weight": "pytorch-model-00002-of-00004.safetensors",
349
+ "layers.26.mlp.gate_proj.weight": "pytorch-model-00002-of-00004.safetensors",
350
+ "layers.26.mlp.up_proj.weight": "pytorch-model-00002-of-00004.safetensors",
351
+ "layers.26.post_attention_layernorm.weight": "pytorch-model-00002-of-00004.safetensors",
352
+ "layers.26.self_attn.k_proj.bias": "pytorch-model-00002-of-00004.safetensors",
353
+ "layers.26.self_attn.k_proj.weight": "pytorch-model-00002-of-00004.safetensors",
354
+ "layers.26.self_attn.o_proj.weight": "pytorch-model-00002-of-00004.safetensors",
355
+ "layers.26.self_attn.q_proj.bias": "pytorch-model-00002-of-00004.safetensors",
356
+ "layers.26.self_attn.q_proj.weight": "pytorch-model-00002-of-00004.safetensors",
357
+ "layers.26.self_attn.v_proj.bias": "pytorch-model-00002-of-00004.safetensors",
358
+ "layers.26.self_attn.v_proj.weight": "pytorch-model-00002-of-00004.safetensors",
359
+ "layers.27.input_layernorm.weight": "pytorch-model-00002-of-00004.safetensors",
360
+ "layers.27.mlp.down_proj.weight": "pytorch-model-00002-of-00004.safetensors",
361
+ "layers.27.mlp.gate_proj.weight": "pytorch-model-00002-of-00004.safetensors",
362
+ "layers.27.mlp.up_proj.weight": "pytorch-model-00002-of-00004.safetensors",
363
+ "layers.27.post_attention_layernorm.weight": "pytorch-model-00002-of-00004.safetensors",
364
+ "layers.27.self_attn.k_proj.bias": "pytorch-model-00002-of-00004.safetensors",
365
+ "layers.27.self_attn.k_proj.weight": "pytorch-model-00002-of-00004.safetensors",
366
+ "layers.27.self_attn.o_proj.weight": "pytorch-model-00002-of-00004.safetensors",
367
+ "layers.27.self_attn.q_proj.bias": "pytorch-model-00002-of-00004.safetensors",
368
+ "layers.27.self_attn.q_proj.weight": "pytorch-model-00002-of-00004.safetensors",
369
+ "layers.27.self_attn.v_proj.bias": "pytorch-model-00002-of-00004.safetensors",
370
+ "layers.27.self_attn.v_proj.weight": "pytorch-model-00002-of-00004.safetensors",
371
+ "layers.28.input_layernorm.weight": "pytorch-model-00002-of-00004.safetensors",
372
+ "layers.28.mlp.down_proj.weight": "pytorch-model-00002-of-00004.safetensors",
373
+ "layers.28.mlp.gate_proj.weight": "pytorch-model-00002-of-00004.safetensors",
374
+ "layers.28.mlp.up_proj.weight": "pytorch-model-00002-of-00004.safetensors",
375
+ "layers.28.post_attention_layernorm.weight": "pytorch-model-00002-of-00004.safetensors",
376
+ "layers.28.self_attn.k_proj.bias": "pytorch-model-00002-of-00004.safetensors",
377
+ "layers.28.self_attn.k_proj.weight": "pytorch-model-00002-of-00004.safetensors",
378
+ "layers.28.self_attn.o_proj.weight": "pytorch-model-00002-of-00004.safetensors",
379
+ "layers.28.self_attn.q_proj.bias": "pytorch-model-00002-of-00004.safetensors",
380
+ "layers.28.self_attn.q_proj.weight": "pytorch-model-00002-of-00004.safetensors",
381
+ "layers.28.self_attn.v_proj.bias": "pytorch-model-00002-of-00004.safetensors",
382
+ "layers.28.self_attn.v_proj.weight": "pytorch-model-00002-of-00004.safetensors",
383
+ "layers.29.input_layernorm.weight": "pytorch-model-00002-of-00004.safetensors",
384
+ "layers.29.mlp.down_proj.weight": "pytorch-model-00002-of-00004.safetensors",
385
+ "layers.29.mlp.gate_proj.weight": "pytorch-model-00002-of-00004.safetensors",
386
+ "layers.29.mlp.up_proj.weight": "pytorch-model-00002-of-00004.safetensors",
387
+ "layers.29.post_attention_layernorm.weight": "pytorch-model-00002-of-00004.safetensors",
388
+ "layers.29.self_attn.k_proj.bias": "pytorch-model-00002-of-00004.safetensors",
389
+ "layers.29.self_attn.k_proj.weight": "pytorch-model-00002-of-00004.safetensors",
390
+ "layers.29.self_attn.o_proj.weight": "pytorch-model-00002-of-00004.safetensors",
391
+ "layers.29.self_attn.q_proj.bias": "pytorch-model-00002-of-00004.safetensors",
392
+ "layers.29.self_attn.q_proj.weight": "pytorch-model-00002-of-00004.safetensors",
393
+ "layers.29.self_attn.v_proj.bias": "pytorch-model-00002-of-00004.safetensors",
394
+ "layers.29.self_attn.v_proj.weight": "pytorch-model-00002-of-00004.safetensors",
395
+ "layers.3.input_layernorm.weight": "pytorch-model-00002-of-00004.safetensors",
396
+ "layers.3.mlp.down_proj.weight": "pytorch-model-00002-of-00004.safetensors",
397
+ "layers.3.mlp.gate_proj.weight": "pytorch-model-00002-of-00004.safetensors",
398
+ "layers.3.mlp.up_proj.weight": "pytorch-model-00002-of-00004.safetensors",
399
+ "layers.3.post_attention_layernorm.weight": "pytorch-model-00002-of-00004.safetensors",
400
+ "layers.3.self_attn.k_proj.bias": "pytorch-model-00002-of-00004.safetensors",
401
+ "layers.3.self_attn.k_proj.weight": "pytorch-model-00002-of-00004.safetensors",
402
+ "layers.3.self_attn.o_proj.weight": "pytorch-model-00002-of-00004.safetensors",
403
+ "layers.3.self_attn.q_proj.bias": "pytorch-model-00002-of-00004.safetensors",
404
+ "layers.3.self_attn.q_proj.weight": "pytorch-model-00002-of-00004.safetensors",
405
+ "layers.3.self_attn.v_proj.bias": "pytorch-model-00002-of-00004.safetensors",
406
+ "layers.3.self_attn.v_proj.weight": "pytorch-model-00002-of-00004.safetensors",
407
+ "layers.30.input_layernorm.weight": "pytorch-model-00002-of-00004.safetensors",
408
+ "layers.30.mlp.down_proj.weight": "pytorch-model-00002-of-00004.safetensors",
409
+ "layers.30.mlp.gate_proj.weight": "pytorch-model-00002-of-00004.safetensors",
410
+ "layers.30.mlp.up_proj.weight": "pytorch-model-00002-of-00004.safetensors",
411
+ "layers.30.post_attention_layernorm.weight": "pytorch-model-00002-of-00004.safetensors",
412
+ "layers.30.self_attn.k_proj.bias": "pytorch-model-00002-of-00004.safetensors",
413
+ "layers.30.self_attn.k_proj.weight": "pytorch-model-00002-of-00004.safetensors",
414
+ "layers.30.self_attn.o_proj.weight": "pytorch-model-00002-of-00004.safetensors",
415
+ "layers.30.self_attn.q_proj.bias": "pytorch-model-00002-of-00004.safetensors",
416
+ "layers.30.self_attn.q_proj.weight": "pytorch-model-00002-of-00004.safetensors",
417
+ "layers.30.self_attn.v_proj.bias": "pytorch-model-00002-of-00004.safetensors",
418
+ "layers.30.self_attn.v_proj.weight": "pytorch-model-00002-of-00004.safetensors",
419
+ "layers.31.input_layernorm.weight": "pytorch-model-00002-of-00004.safetensors",
420
+ "layers.31.mlp.down_proj.weight": "pytorch-model-00002-of-00004.safetensors",
421
+ "layers.31.mlp.gate_proj.weight": "pytorch-model-00002-of-00004.safetensors",
422
+ "layers.31.mlp.up_proj.weight": "pytorch-model-00002-of-00004.safetensors",
423
+ "layers.31.post_attention_layernorm.weight": "pytorch-model-00002-of-00004.safetensors",
424
+ "layers.31.self_attn.k_proj.bias": "pytorch-model-00002-of-00004.safetensors",
425
+ "layers.31.self_attn.k_proj.weight": "pytorch-model-00002-of-00004.safetensors",
426
+ "layers.31.self_attn.o_proj.weight": "pytorch-model-00002-of-00004.safetensors",
427
+ "layers.31.self_attn.q_proj.bias": "pytorch-model-00002-of-00004.safetensors",
428
+ "layers.31.self_attn.q_proj.weight": "pytorch-model-00002-of-00004.safetensors",
429
+ "layers.31.self_attn.v_proj.bias": "pytorch-model-00002-of-00004.safetensors",
430
+ "layers.31.self_attn.v_proj.weight": "pytorch-model-00002-of-00004.safetensors",
431
+ "layers.32.input_layernorm.weight": "pytorch-model-00002-of-00004.safetensors",
432
+ "layers.32.mlp.down_proj.weight": "pytorch-model-00002-of-00004.safetensors",
433
+ "layers.32.mlp.gate_proj.weight": "pytorch-model-00002-of-00004.safetensors",
434
+ "layers.32.mlp.up_proj.weight": "pytorch-model-00002-of-00004.safetensors",
435
+ "layers.32.post_attention_layernorm.weight": "pytorch-model-00002-of-00004.safetensors",
436
+ "layers.32.self_attn.k_proj.bias": "pytorch-model-00002-of-00004.safetensors",
437
+ "layers.32.self_attn.k_proj.weight": "pytorch-model-00002-of-00004.safetensors",
438
+ "layers.32.self_attn.o_proj.weight": "pytorch-model-00002-of-00004.safetensors",
439
+ "layers.32.self_attn.q_proj.bias": "pytorch-model-00002-of-00004.safetensors",
440
+ "layers.32.self_attn.q_proj.weight": "pytorch-model-00002-of-00004.safetensors",
441
+ "layers.32.self_attn.v_proj.bias": "pytorch-model-00002-of-00004.safetensors",
442
+ "layers.32.self_attn.v_proj.weight": "pytorch-model-00002-of-00004.safetensors",
443
+ "layers.33.input_layernorm.weight": "pytorch-model-00002-of-00004.safetensors",
444
+ "layers.33.mlp.down_proj.weight": "pytorch-model-00002-of-00004.safetensors",
445
+ "layers.33.mlp.gate_proj.weight": "pytorch-model-00002-of-00004.safetensors",
446
+ "layers.33.mlp.up_proj.weight": "pytorch-model-00002-of-00004.safetensors",
447
+ "layers.33.post_attention_layernorm.weight": "pytorch-model-00002-of-00004.safetensors",
448
+ "layers.33.self_attn.k_proj.bias": "pytorch-model-00002-of-00004.safetensors",
449
+ "layers.33.self_attn.k_proj.weight": "pytorch-model-00002-of-00004.safetensors",
450
+ "layers.33.self_attn.o_proj.weight": "pytorch-model-00002-of-00004.safetensors",
451
+ "layers.33.self_attn.q_proj.bias": "pytorch-model-00002-of-00004.safetensors",
452
+ "layers.33.self_attn.q_proj.weight": "pytorch-model-00002-of-00004.safetensors",
453
+ "layers.33.self_attn.v_proj.bias": "pytorch-model-00002-of-00004.safetensors",
454
+ "layers.33.self_attn.v_proj.weight": "pytorch-model-00002-of-00004.safetensors",
455
+ "layers.34.input_layernorm.weight": "pytorch-model-00002-of-00004.safetensors",
456
+ "layers.34.mlp.down_proj.weight": "pytorch-model-00002-of-00004.safetensors",
457
+ "layers.34.mlp.gate_proj.weight": "pytorch-model-00002-of-00004.safetensors",
458
+ "layers.34.mlp.up_proj.weight": "pytorch-model-00002-of-00004.safetensors",
459
+ "layers.34.post_attention_layernorm.weight": "pytorch-model-00002-of-00004.safetensors",
460
+ "layers.34.self_attn.k_proj.bias": "pytorch-model-00002-of-00004.safetensors",
461
+ "layers.34.self_attn.k_proj.weight": "pytorch-model-00002-of-00004.safetensors",
462
+ "layers.34.self_attn.o_proj.weight": "pytorch-model-00002-of-00004.safetensors",
463
+ "layers.34.self_attn.q_proj.bias": "pytorch-model-00002-of-00004.safetensors",
464
+ "layers.34.self_attn.q_proj.weight": "pytorch-model-00002-of-00004.safetensors",
465
+ "layers.34.self_attn.v_proj.bias": "pytorch-model-00002-of-00004.safetensors",
466
+ "layers.34.self_attn.v_proj.weight": "pytorch-model-00002-of-00004.safetensors",
467
+ "layers.35.input_layernorm.weight": "pytorch-model-00002-of-00004.safetensors",
468
+ "layers.35.mlp.down_proj.weight": "pytorch-model-00002-of-00004.safetensors",
469
+ "layers.35.mlp.gate_proj.weight": "pytorch-model-00002-of-00004.safetensors",
470
+ "layers.35.mlp.up_proj.weight": "pytorch-model-00002-of-00004.safetensors",
471
+ "layers.35.post_attention_layernorm.weight": "pytorch-model-00002-of-00004.safetensors",
472
+ "layers.35.self_attn.k_proj.bias": "pytorch-model-00002-of-00004.safetensors",
473
+ "layers.35.self_attn.k_proj.weight": "pytorch-model-00002-of-00004.safetensors",
474
+ "layers.35.self_attn.o_proj.weight": "pytorch-model-00002-of-00004.safetensors",
475
+ "layers.35.self_attn.q_proj.bias": "pytorch-model-00002-of-00004.safetensors",
476
+ "layers.35.self_attn.q_proj.weight": "pytorch-model-00002-of-00004.safetensors",
477
+ "layers.35.self_attn.v_proj.bias": "pytorch-model-00002-of-00004.safetensors",
478
+ "layers.35.self_attn.v_proj.weight": "pytorch-model-00002-of-00004.safetensors",
479
+ "layers.36.input_layernorm.weight": "pytorch-model-00002-of-00004.safetensors",
480
+ "layers.36.mlp.down_proj.weight": "pytorch-model-00002-of-00004.safetensors",
481
+ "layers.36.mlp.gate_proj.weight": "pytorch-model-00002-of-00004.safetensors",
482
+ "layers.36.mlp.up_proj.weight": "pytorch-model-00002-of-00004.safetensors",
483
+ "layers.36.post_attention_layernorm.weight": "pytorch-model-00002-of-00004.safetensors",
484
+ "layers.36.self_attn.k_proj.bias": "pytorch-model-00002-of-00004.safetensors",
485
+ "layers.36.self_attn.k_proj.weight": "pytorch-model-00002-of-00004.safetensors",
486
+ "layers.36.self_attn.o_proj.weight": "pytorch-model-00002-of-00004.safetensors",
487
+ "layers.36.self_attn.q_proj.bias": "pytorch-model-00002-of-00004.safetensors",
488
+ "layers.36.self_attn.q_proj.weight": "pytorch-model-00002-of-00004.safetensors",
489
+ "layers.36.self_attn.v_proj.bias": "pytorch-model-00002-of-00004.safetensors",
490
+ "layers.36.self_attn.v_proj.weight": "pytorch-model-00002-of-00004.safetensors",
491
+ "layers.37.input_layernorm.weight": "pytorch-model-00002-of-00004.safetensors",
492
+ "layers.37.mlp.down_proj.weight": "pytorch-model-00002-of-00004.safetensors",
493
+ "layers.37.mlp.gate_proj.weight": "pytorch-model-00002-of-00004.safetensors",
494
+ "layers.37.mlp.up_proj.weight": "pytorch-model-00002-of-00004.safetensors",
495
+ "layers.37.post_attention_layernorm.weight": "pytorch-model-00002-of-00004.safetensors",
496
+ "layers.37.self_attn.k_proj.bias": "pytorch-model-00002-of-00004.safetensors",
497
+ "layers.37.self_attn.k_proj.weight": "pytorch-model-00002-of-00004.safetensors",
498
+ "layers.37.self_attn.o_proj.weight": "pytorch-model-00002-of-00004.safetensors",
499
+ "layers.37.self_attn.q_proj.bias": "pytorch-model-00002-of-00004.safetensors",
500
+ "layers.37.self_attn.q_proj.weight": "pytorch-model-00002-of-00004.safetensors",
501
+ "layers.37.self_attn.v_proj.bias": "pytorch-model-00002-of-00004.safetensors",
502
+ "layers.37.self_attn.v_proj.weight": "pytorch-model-00002-of-00004.safetensors",
503
+ "layers.38.input_layernorm.weight": "pytorch-model-00002-of-00004.safetensors",
504
+ "layers.38.mlp.down_proj.weight": "pytorch-model-00002-of-00004.safetensors",
505
+ "layers.38.mlp.gate_proj.weight": "pytorch-model-00002-of-00004.safetensors",
506
+ "layers.38.mlp.up_proj.weight": "pytorch-model-00002-of-00004.safetensors",
507
+ "layers.38.post_attention_layernorm.weight": "pytorch-model-00002-of-00004.safetensors",
508
+ "layers.38.self_attn.k_proj.bias": "pytorch-model-00002-of-00004.safetensors",
509
+ "layers.38.self_attn.k_proj.weight": "pytorch-model-00002-of-00004.safetensors",
510
+ "layers.38.self_attn.o_proj.weight": "pytorch-model-00002-of-00004.safetensors",
511
+ "layers.38.self_attn.q_proj.bias": "pytorch-model-00002-of-00004.safetensors",
512
+ "layers.38.self_attn.q_proj.weight": "pytorch-model-00002-of-00004.safetensors",
513
+ "layers.38.self_attn.v_proj.bias": "pytorch-model-00002-of-00004.safetensors",
514
+ "layers.38.self_attn.v_proj.weight": "pytorch-model-00002-of-00004.safetensors",
515
+ "layers.39.input_layernorm.weight": "pytorch-model-00002-of-00004.safetensors",
516
+ "layers.39.mlp.down_proj.weight": "pytorch-model-00002-of-00004.safetensors",
517
+ "layers.39.mlp.gate_proj.weight": "pytorch-model-00002-of-00004.safetensors",
518
+ "layers.39.mlp.up_proj.weight": "pytorch-model-00002-of-00004.safetensors",
519
+ "layers.39.post_attention_layernorm.weight": "pytorch-model-00002-of-00004.safetensors",
520
+ "layers.39.self_attn.k_proj.bias": "pytorch-model-00002-of-00004.safetensors",
521
+ "layers.39.self_attn.k_proj.weight": "pytorch-model-00002-of-00004.safetensors",
522
+ "layers.39.self_attn.o_proj.weight": "pytorch-model-00002-of-00004.safetensors",
523
+ "layers.39.self_attn.q_proj.bias": "pytorch-model-00002-of-00004.safetensors",
524
+ "layers.39.self_attn.q_proj.weight": "pytorch-model-00002-of-00004.safetensors",
525
+ "layers.39.self_attn.v_proj.bias": "pytorch-model-00002-of-00004.safetensors",
526
+ "layers.39.self_attn.v_proj.weight": "pytorch-model-00002-of-00004.safetensors",
527
+ "layers.4.input_layernorm.weight": "pytorch-model-00002-of-00004.safetensors",
528
+ "layers.4.mlp.down_proj.weight": "pytorch-model-00002-of-00004.safetensors",
529
+ "layers.4.mlp.gate_proj.weight": "pytorch-model-00002-of-00004.safetensors",
530
+ "layers.4.mlp.up_proj.weight": "pytorch-model-00002-of-00004.safetensors",
531
+ "layers.4.post_attention_layernorm.weight": "pytorch-model-00002-of-00004.safetensors",
532
+ "layers.4.self_attn.k_proj.bias": "pytorch-model-00002-of-00004.safetensors",
533
+ "layers.4.self_attn.k_proj.weight": "pytorch-model-00002-of-00004.safetensors",
534
+ "layers.4.self_attn.o_proj.weight": "pytorch-model-00002-of-00004.safetensors",
535
+ "layers.4.self_attn.q_proj.bias": "pytorch-model-00002-of-00004.safetensors",
536
+ "layers.4.self_attn.q_proj.weight": "pytorch-model-00002-of-00004.safetensors",
537
+ "layers.4.self_attn.v_proj.bias": "pytorch-model-00002-of-00004.safetensors",
538
+ "layers.4.self_attn.v_proj.weight": "pytorch-model-00002-of-00004.safetensors",
539
+ "layers.40.input_layernorm.weight": "pytorch-model-00002-of-00004.safetensors",
540
+ "layers.40.mlp.down_proj.weight": "pytorch-model-00002-of-00004.safetensors",
541
+ "layers.40.mlp.gate_proj.weight": "pytorch-model-00002-of-00004.safetensors",
542
+ "layers.40.mlp.up_proj.weight": "pytorch-model-00002-of-00004.safetensors",
543
+ "layers.40.post_attention_layernorm.weight": "pytorch-model-00002-of-00004.safetensors",
544
+ "layers.40.self_attn.k_proj.bias": "pytorch-model-00002-of-00004.safetensors",
545
+ "layers.40.self_attn.k_proj.weight": "pytorch-model-00002-of-00004.safetensors",
546
+ "layers.40.self_attn.o_proj.weight": "pytorch-model-00002-of-00004.safetensors",
547
+ "layers.40.self_attn.q_proj.bias": "pytorch-model-00002-of-00004.safetensors",
548
+ "layers.40.self_attn.q_proj.weight": "pytorch-model-00002-of-00004.safetensors",
549
+ "layers.40.self_attn.v_proj.bias": "pytorch-model-00002-of-00004.safetensors",
550
+ "layers.40.self_attn.v_proj.weight": "pytorch-model-00002-of-00004.safetensors",
551
+ "layers.41.input_layernorm.weight": "pytorch-model-00002-of-00004.safetensors",
552
+ "layers.41.mlp.down_proj.weight": "pytorch-model-00003-of-00004.safetensors",
553
+ "layers.41.mlp.gate_proj.weight": "pytorch-model-00003-of-00004.safetensors",
554
+ "layers.41.mlp.up_proj.weight": "pytorch-model-00003-of-00004.safetensors",
555
+ "layers.41.post_attention_layernorm.weight": "pytorch-model-00003-of-00004.safetensors",
556
+ "layers.41.self_attn.k_proj.bias": "pytorch-model-00003-of-00004.safetensors",
557
+ "layers.41.self_attn.k_proj.weight": "pytorch-model-00003-of-00004.safetensors",
558
+ "layers.41.self_attn.o_proj.weight": "pytorch-model-00002-of-00004.safetensors",
559
+ "layers.41.self_attn.q_proj.bias": "pytorch-model-00003-of-00004.safetensors",
560
+ "layers.41.self_attn.q_proj.weight": "pytorch-model-00003-of-00004.safetensors",
561
+ "layers.41.self_attn.v_proj.bias": "pytorch-model-00003-of-00004.safetensors",
562
+ "layers.41.self_attn.v_proj.weight": "pytorch-model-00003-of-00004.safetensors",
563
+ "layers.42.input_layernorm.weight": "pytorch-model-00003-of-00004.safetensors",
564
+ "layers.42.mlp.down_proj.weight": "pytorch-model-00003-of-00004.safetensors",
565
+ "layers.42.mlp.gate_proj.weight": "pytorch-model-00003-of-00004.safetensors",
566
+ "layers.42.mlp.up_proj.weight": "pytorch-model-00003-of-00004.safetensors",
567
+ "layers.42.post_attention_layernorm.weight": "pytorch-model-00003-of-00004.safetensors",
568
+ "layers.42.self_attn.k_proj.bias": "pytorch-model-00003-of-00004.safetensors",
569
+ "layers.42.self_attn.k_proj.weight": "pytorch-model-00003-of-00004.safetensors",
570
+ "layers.42.self_attn.o_proj.weight": "pytorch-model-00003-of-00004.safetensors",
571
+ "layers.42.self_attn.q_proj.bias": "pytorch-model-00003-of-00004.safetensors",
572
+ "layers.42.self_attn.q_proj.weight": "pytorch-model-00003-of-00004.safetensors",
573
+ "layers.42.self_attn.v_proj.bias": "pytorch-model-00003-of-00004.safetensors",
574
+ "layers.42.self_attn.v_proj.weight": "pytorch-model-00003-of-00004.safetensors",
575
+ "layers.43.input_layernorm.weight": "pytorch-model-00003-of-00004.safetensors",
576
+ "layers.43.mlp.down_proj.weight": "pytorch-model-00003-of-00004.safetensors",
577
+ "layers.43.mlp.gate_proj.weight": "pytorch-model-00003-of-00004.safetensors",
578
+ "layers.43.mlp.up_proj.weight": "pytorch-model-00003-of-00004.safetensors",
579
+ "layers.43.post_attention_layernorm.weight": "pytorch-model-00003-of-00004.safetensors",
580
+ "layers.43.self_attn.k_proj.bias": "pytorch-model-00003-of-00004.safetensors",
581
+ "layers.43.self_attn.k_proj.weight": "pytorch-model-00003-of-00004.safetensors",
582
+ "layers.43.self_attn.o_proj.weight": "pytorch-model-00003-of-00004.safetensors",
583
+ "layers.43.self_attn.q_proj.bias": "pytorch-model-00003-of-00004.safetensors",
584
+ "layers.43.self_attn.q_proj.weight": "pytorch-model-00003-of-00004.safetensors",
585
+ "layers.43.self_attn.v_proj.bias": "pytorch-model-00003-of-00004.safetensors",
586
+ "layers.43.self_attn.v_proj.weight": "pytorch-model-00003-of-00004.safetensors",
587
+ "layers.44.input_layernorm.weight": "pytorch-model-00003-of-00004.safetensors",
588
+ "layers.44.mlp.down_proj.weight": "pytorch-model-00003-of-00004.safetensors",
589
+ "layers.44.mlp.gate_proj.weight": "pytorch-model-00003-of-00004.safetensors",
590
+ "layers.44.mlp.up_proj.weight": "pytorch-model-00003-of-00004.safetensors",
591
+ "layers.44.post_attention_layernorm.weight": "pytorch-model-00003-of-00004.safetensors",
592
+ "layers.44.self_attn.k_proj.bias": "pytorch-model-00003-of-00004.safetensors",
593
+ "layers.44.self_attn.k_proj.weight": "pytorch-model-00003-of-00004.safetensors",
594
+ "layers.44.self_attn.o_proj.weight": "pytorch-model-00003-of-00004.safetensors",
595
+ "layers.44.self_attn.q_proj.bias": "pytorch-model-00003-of-00004.safetensors",
596
+ "layers.44.self_attn.q_proj.weight": "pytorch-model-00003-of-00004.safetensors",
597
+ "layers.44.self_attn.v_proj.bias": "pytorch-model-00003-of-00004.safetensors",
598
+ "layers.44.self_attn.v_proj.weight": "pytorch-model-00003-of-00004.safetensors",
599
+ "layers.45.input_layernorm.weight": "pytorch-model-00003-of-00004.safetensors",
600
+ "layers.45.mlp.down_proj.weight": "pytorch-model-00003-of-00004.safetensors",
601
+ "layers.45.mlp.gate_proj.weight": "pytorch-model-00003-of-00004.safetensors",
602
+ "layers.45.mlp.up_proj.weight": "pytorch-model-00003-of-00004.safetensors",
603
+ "layers.45.post_attention_layernorm.weight": "pytorch-model-00003-of-00004.safetensors",
604
+ "layers.45.self_attn.k_proj.bias": "pytorch-model-00003-of-00004.safetensors",
605
+ "layers.45.self_attn.k_proj.weight": "pytorch-model-00003-of-00004.safetensors",
606
+ "layers.45.self_attn.o_proj.weight": "pytorch-model-00003-of-00004.safetensors",
607
+ "layers.45.self_attn.q_proj.bias": "pytorch-model-00003-of-00004.safetensors",
608
+ "layers.45.self_attn.q_proj.weight": "pytorch-model-00003-of-00004.safetensors",
609
+ "layers.45.self_attn.v_proj.bias": "pytorch-model-00003-of-00004.safetensors",
610
+ "layers.45.self_attn.v_proj.weight": "pytorch-model-00003-of-00004.safetensors",
611
+ "layers.46.input_layernorm.weight": "pytorch-model-00003-of-00004.safetensors",
612
+ "layers.46.mlp.down_proj.weight": "pytorch-model-00003-of-00004.safetensors",
613
+ "layers.46.mlp.gate_proj.weight": "pytorch-model-00003-of-00004.safetensors",
614
+ "layers.46.mlp.up_proj.weight": "pytorch-model-00003-of-00004.safetensors",
615
+ "layers.46.post_attention_layernorm.weight": "pytorch-model-00003-of-00004.safetensors",
616
+ "layers.46.self_attn.k_proj.bias": "pytorch-model-00003-of-00004.safetensors",
617
+ "layers.46.self_attn.k_proj.weight": "pytorch-model-00003-of-00004.safetensors",
618
+ "layers.46.self_attn.o_proj.weight": "pytorch-model-00003-of-00004.safetensors",
619
+ "layers.46.self_attn.q_proj.bias": "pytorch-model-00003-of-00004.safetensors",
620
+ "layers.46.self_attn.q_proj.weight": "pytorch-model-00003-of-00004.safetensors",
621
+ "layers.46.self_attn.v_proj.bias": "pytorch-model-00003-of-00004.safetensors",
622
+ "layers.46.self_attn.v_proj.weight": "pytorch-model-00003-of-00004.safetensors",
623
+ "layers.47.input_layernorm.weight": "pytorch-model-00003-of-00004.safetensors",
624
+ "layers.47.mlp.down_proj.weight": "pytorch-model-00003-of-00004.safetensors",
625
+ "layers.47.mlp.gate_proj.weight": "pytorch-model-00003-of-00004.safetensors",
626
+ "layers.47.mlp.up_proj.weight": "pytorch-model-00003-of-00004.safetensors",
627
+ "layers.47.post_attention_layernorm.weight": "pytorch-model-00003-of-00004.safetensors",
628
+ "layers.47.self_attn.k_proj.bias": "pytorch-model-00003-of-00004.safetensors",
629
+ "layers.47.self_attn.k_proj.weight": "pytorch-model-00003-of-00004.safetensors",
630
+ "layers.47.self_attn.o_proj.weight": "pytorch-model-00003-of-00004.safetensors",
631
+ "layers.47.self_attn.q_proj.bias": "pytorch-model-00003-of-00004.safetensors",
632
+ "layers.47.self_attn.q_proj.weight": "pytorch-model-00003-of-00004.safetensors",
633
+ "layers.47.self_attn.v_proj.bias": "pytorch-model-00003-of-00004.safetensors",
634
+ "layers.47.self_attn.v_proj.weight": "pytorch-model-00003-of-00004.safetensors",
635
+ "layers.5.input_layernorm.weight": "pytorch-model-00003-of-00004.safetensors",
636
+ "layers.5.mlp.down_proj.weight": "pytorch-model-00003-of-00004.safetensors",
637
+ "layers.5.mlp.gate_proj.weight": "pytorch-model-00003-of-00004.safetensors",
638
+ "layers.5.mlp.up_proj.weight": "pytorch-model-00003-of-00004.safetensors",
639
+ "layers.5.post_attention_layernorm.weight": "pytorch-model-00003-of-00004.safetensors",
640
+ "layers.5.self_attn.k_proj.bias": "pytorch-model-00003-of-00004.safetensors",
641
+ "layers.5.self_attn.k_proj.weight": "pytorch-model-00003-of-00004.safetensors",
642
+ "layers.5.self_attn.o_proj.weight": "pytorch-model-00003-of-00004.safetensors",
643
+ "layers.5.self_attn.q_proj.bias": "pytorch-model-00003-of-00004.safetensors",
644
+ "layers.5.self_attn.q_proj.weight": "pytorch-model-00003-of-00004.safetensors",
645
+ "layers.5.self_attn.v_proj.bias": "pytorch-model-00003-of-00004.safetensors",
646
+ "layers.5.self_attn.v_proj.weight": "pytorch-model-00003-of-00004.safetensors",
647
+ "layers.6.input_layernorm.weight": "pytorch-model-00003-of-00004.safetensors",
648
+ "layers.6.mlp.down_proj.weight": "pytorch-model-00003-of-00004.safetensors",
649
+ "layers.6.mlp.gate_proj.weight": "pytorch-model-00003-of-00004.safetensors",
650
+ "layers.6.mlp.up_proj.weight": "pytorch-model-00003-of-00004.safetensors",
651
+ "layers.6.post_attention_layernorm.weight": "pytorch-model-00003-of-00004.safetensors",
652
+ "layers.6.self_attn.k_proj.bias": "pytorch-model-00003-of-00004.safetensors",
653
+ "layers.6.self_attn.k_proj.weight": "pytorch-model-00003-of-00004.safetensors",
654
+ "layers.6.self_attn.o_proj.weight": "pytorch-model-00003-of-00004.safetensors",
655
+ "layers.6.self_attn.q_proj.bias": "pytorch-model-00003-of-00004.safetensors",
656
+ "layers.6.self_attn.q_proj.weight": "pytorch-model-00003-of-00004.safetensors",
657
+ "layers.6.self_attn.v_proj.bias": "pytorch-model-00003-of-00004.safetensors",
658
+ "layers.6.self_attn.v_proj.weight": "pytorch-model-00003-of-00004.safetensors",
659
+ "layers.7.input_layernorm.weight": "pytorch-model-00003-of-00004.safetensors",
660
+ "layers.7.mlp.down_proj.weight": "pytorch-model-00003-of-00004.safetensors",
661
+ "layers.7.mlp.gate_proj.weight": "pytorch-model-00003-of-00004.safetensors",
662
+ "layers.7.mlp.up_proj.weight": "pytorch-model-00003-of-00004.safetensors",
663
+ "layers.7.post_attention_layernorm.weight": "pytorch-model-00003-of-00004.safetensors",
664
+ "layers.7.self_attn.k_proj.bias": "pytorch-model-00003-of-00004.safetensors",
665
+ "layers.7.self_attn.k_proj.weight": "pytorch-model-00003-of-00004.safetensors",
666
+ "layers.7.self_attn.o_proj.weight": "pytorch-model-00003-of-00004.safetensors",
667
+ "layers.7.self_attn.q_proj.bias": "pytorch-model-00003-of-00004.safetensors",
668
+ "layers.7.self_attn.q_proj.weight": "pytorch-model-00003-of-00004.safetensors",
669
+ "layers.7.self_attn.v_proj.bias": "pytorch-model-00003-of-00004.safetensors",
670
+ "layers.7.self_attn.v_proj.weight": "pytorch-model-00003-of-00004.safetensors",
671
+ "layers.8.input_layernorm.weight": "pytorch-model-00003-of-00004.safetensors",
672
+ "layers.8.mlp.down_proj.weight": "pytorch-model-00003-of-00004.safetensors",
673
+ "layers.8.mlp.gate_proj.weight": "pytorch-model-00003-of-00004.safetensors",
674
+ "layers.8.mlp.up_proj.weight": "pytorch-model-00003-of-00004.safetensors",
675
+ "layers.8.post_attention_layernorm.weight": "pytorch-model-00003-of-00004.safetensors",
676
+ "layers.8.self_attn.k_proj.bias": "pytorch-model-00003-of-00004.safetensors",
677
+ "layers.8.self_attn.k_proj.weight": "pytorch-model-00003-of-00004.safetensors",
678
+ "layers.8.self_attn.o_proj.weight": "pytorch-model-00003-of-00004.safetensors",
679
+ "layers.8.self_attn.q_proj.bias": "pytorch-model-00003-of-00004.safetensors",
680
+ "layers.8.self_attn.q_proj.weight": "pytorch-model-00003-of-00004.safetensors",
681
+ "layers.8.self_attn.v_proj.bias": "pytorch-model-00003-of-00004.safetensors",
682
+ "layers.8.self_attn.v_proj.weight": "pytorch-model-00003-of-00004.safetensors",
683
+ "layers.9.input_layernorm.weight": "pytorch-model-00003-of-00004.safetensors",
684
+ "layers.9.mlp.down_proj.weight": "pytorch-model-00003-of-00004.safetensors",
685
+ "layers.9.mlp.gate_proj.weight": "pytorch-model-00003-of-00004.safetensors",
686
+ "layers.9.mlp.up_proj.weight": "pytorch-model-00003-of-00004.safetensors",
687
+ "layers.9.post_attention_layernorm.weight": "pytorch-model-00003-of-00004.safetensors",
688
+ "layers.9.self_attn.k_proj.bias": "pytorch-model-00003-of-00004.safetensors",
689
+ "layers.9.self_attn.k_proj.weight": "pytorch-model-00003-of-00004.safetensors",
690
+ "layers.9.self_attn.o_proj.weight": "pytorch-model-00003-of-00004.safetensors",
691
+ "layers.9.self_attn.q_proj.bias": "pytorch-model-00003-of-00004.safetensors",
692
+ "layers.9.self_attn.q_proj.weight": "pytorch-model-00003-of-00004.safetensors",
693
+ "layers.9.self_attn.v_proj.bias": "pytorch-model-00003-of-00004.safetensors",
694
+ "layers.9.self_attn.v_proj.weight": "pytorch-model-00003-of-00004.safetensors",
695
+ "lm_head.weight": "pytorch-model-00003-of-00004.safetensors",
696
+ "norm.weight": "pytorch-model-00003-of-00004.safetensors"
697
+ }
698
+ }
models/__init__.py ADDED
File without changes
models/gen_pipeline.py ADDED
@@ -0,0 +1,631 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import re
2
+ import os
3
+ import json
4
+ import inspect
5
+ import random
6
+ from typing import Literal
7
+ from dataclasses import dataclass, field
8
+
9
+ import torch
10
+ import torch.nn as nn
11
+ import torch.nn.functional as F
12
+ import torchvision.transforms as transforms
13
+ import numpy as np
14
+ from PIL import Image
15
+ from tqdm.auto import tqdm
16
+ from loguru import logger
17
+
18
+ from transformers import AutoTokenizer
19
+ from transformers.cache_utils import Cache
20
+ from diffusers.models.autoencoders.autoencoder_kl import AutoencoderKL as DiffusersAutoencoderKL
21
+ from diffusers.models.autoencoders.vae import DiagonalGaussianDistribution
22
+ from diffusers.models.modeling_outputs import AutoencoderKLOutput
23
+
24
+ try:
25
+ from .nextstep_model import NextStep
26
+ except ImportError:
27
+ from nextstep_model import NextStep
28
+
29
+ DEFAULT_IMAGE_AREA_TOKEN = "<|image_area|>"
30
+ @dataclass
31
+ class AutoEncoderParams:
32
+ resolution: int = 256
33
+ in_channels: int = 3
34
+ ch: int = 128
35
+ out_ch: int = 3
36
+ ch_mult: list[int] = field(default_factory=lambda: [1, 2, 4, 4])
37
+ num_res_blocks: int = 2
38
+ z_channels: int = 16
39
+ scaling_factor: float = 1
40
+ shift_factor: float = 0
41
+ deterministic: bool = True
42
+ encoder_norm: bool = True
43
+ psz: int | None = 1
44
+
45
+
46
+ class AutoencoderKL(DiffusersAutoencoderKL):
47
+ """
48
+ 继承自 diffusers 的 AutoencoderKL,添加了 patchify 和 encoder_norm 功能。
49
+ 这样可以复用 diffusers 的完整实现,只扩展必要的功能。
50
+ """
51
+
52
+ def __init__(self, params: AutoEncoderParams):
53
+ """
54
+ 从 AutoEncoderParams 初始化模型,转换为 diffusers 格式
55
+ """
56
+ # 转换参数格式为 diffusers 的 AutoencoderKL 格式
57
+ down_block_types = ["DownEncoderBlock2D"] * len(params.ch_mult)
58
+ up_block_types = ["UpDecoderBlock2D"] * len(params.ch_mult)
59
+ block_out_channels = [params.ch * m for m in params.ch_mult]
60
+
61
+ # 调用父类初始化,创建 diffusers 的 encoder 和 decoder
62
+ super().__init__(
63
+ in_channels=params.in_channels,
64
+ out_channels=params.out_ch,
65
+ down_block_types=tuple(down_block_types),
66
+ up_block_types=tuple(up_block_types),
67
+ block_out_channels=tuple(block_out_channels),
68
+ layers_per_block=params.num_res_blocks,
69
+ latent_channels=params.z_channels,
70
+ norm_num_groups=32,
71
+ sample_size=params.resolution,
72
+ scaling_factor=params.scaling_factor,
73
+ shift_factor=params.shift_factor,
74
+ act_fn="silu",
75
+ mid_block_add_attention=True,
76
+ use_quant_conv=False, # 旧的 VAE 没有使用 quant_conv
77
+ use_post_quant_conv=False,
78
+ )
79
+
80
+ # 保存自定义参数
81
+ self.params = params
82
+ self.encoder_norm = params.encoder_norm
83
+ self.psz = params.psz
84
+ self.deterministic = params.deterministic
85
+
86
+ def layer_norm_2d(self, input: torch.Tensor, normalized_shape: torch.Size, eps: float = 1e-6) -> torch.Tensor:
87
+ """Layer normalization for 2D spatial features."""
88
+ # input.shape = (bsz, c, h, w)
89
+ return F.layer_norm(
90
+ input.permute(0, 2, 3, 1), normalized_shape, None, None, eps
91
+ ).permute(0, 3, 1, 2)
92
+
93
+ def patchify(self, img: torch.Tensor):
94
+ """
95
+ img: (bsz, C, H, W)
96
+ x: (bsz, patch_size**2 * C, H / patch_size, W / patch_size)
97
+ """
98
+ bsz, c, h, w = img.shape
99
+ p = self.psz
100
+ h_, w_ = h // p, w // p
101
+
102
+ img = img.reshape(bsz, c, h_, p, w_, p)
103
+ img = torch.einsum("nchpwq->ncpqhw", img)
104
+ x = img.reshape(bsz, c * p**2, h_, w_)
105
+ return x
106
+
107
+ def unpatchify(self, x: torch.Tensor):
108
+ """
109
+ x: (bsz, patch_size**2 * C, H / patch_size, W / patch_size)
110
+ img: (bsz, C, H, W)
111
+ """
112
+ bsz = x.shape[0]
113
+ p = self.psz
114
+ c = self.config.latent_channels
115
+ h_, w_ = x.shape[2], x.shape[3]
116
+
117
+ x = x.reshape(bsz, c, p, p, h_, w_)
118
+ x = torch.einsum("ncpqhw->nchpwq", x)
119
+ img = x.reshape(bsz, c, h_ * p, w_ * p)
120
+ return img
121
+
122
+ def encode(self, x: torch.Tensor, return_dict: bool = True):
123
+ """
124
+ 重写 encode 方法以支持 patchify 和 encoder_norm
125
+ """
126
+ # 使用父类的 encoder
127
+ h = self.encoder(x)
128
+
129
+ # 使用父类的 quant_conv(如果存在)
130
+ moments = self.quant_conv(h) if self.config.use_quant_conv else h
131
+
132
+ # 应用 patchify 和 normalization(如果启用)
133
+ mean, logvar = torch.chunk(moments, 2, dim=1)
134
+
135
+ if self.psz is not None:
136
+ mean = self.patchify(mean)
137
+ if self.encoder_norm:
138
+ mean = self.layer_norm_2d(mean, (mean.size(1),))
139
+ mean = self.unpatchify(mean)
140
+
141
+ moments = torch.cat([mean, logvar], dim=1).contiguous()
142
+ posterior = DiagonalGaussianDistribution(moments, deterministic=self.deterministic)
143
+
144
+ return (posterior,) if not return_dict else AutoencoderKLOutput(latent_dist=posterior)
145
+
146
+ @staticmethod
147
+ def _convert_old_keys_to_diffusers(state_dict, num_resolutions=4):
148
+ """
149
+ 将旧的自定义 VAE 键名转换为 diffusers AutoencoderKL 的键名
150
+ 旧格式: encoder.down.X.block.Y -> 新格式: encoder.down_blocks.X.resnets.Y
151
+
152
+ 注意:decoder 的 up_blocks 顺序需要反转,因为旧实现使用 insert(0, ...)
153
+ """
154
+ import re
155
+ new_state_dict = {}
156
+
157
+ # 定义替换规则
158
+ replacements = [
159
+ # 通用替换
160
+ (".nin_shortcut.", ".conv_shortcut."),
161
+ (".norm_out.", ".conv_norm_out."),
162
+ # Encoder down blocks
163
+ (".down.", ".down_blocks."),
164
+ (".block.", ".resnets."),
165
+ (".downsample.", ".downsamplers.0."),
166
+ # Encoder mid blocks
167
+ (".mid.block_1.", ".mid_block.resnets.0."),
168
+ (".mid.block_2.", ".mid_block.resnets.1."),
169
+ (".mid.attn_1.norm.", ".mid_block.attentions.0.group_norm."),
170
+ (".mid.attn_1.q.", ".mid_block.attentions.0.to_q."),
171
+ (".mid.attn_1.k.", ".mid_block.attentions.0.to_k."),
172
+ (".mid.attn_1.v.", ".mid_block.attentions.0.to_v."),
173
+ (".mid.attn_1.proj_out.", ".mid_block.attentions.0.to_out.0."),
174
+ # Decoder up blocks
175
+ (".upsample.", ".upsamplers.0."),
176
+ ]
177
+
178
+ for key, value in state_dict.items():
179
+ new_key = key
180
+
181
+ # 跳过不需要转换的键
182
+ if any(skip in key for skip in ["conv_in", "conv_out"]) and ("encoder." in key or "decoder." in key):
183
+ new_state_dict[new_key] = value
184
+ continue
185
+
186
+ # Encoder 转换
187
+ if key.startswith("encoder."):
188
+ for old_pattern, new_pattern in replacements:
189
+ new_key = new_key.replace(old_pattern, new_pattern)
190
+
191
+ # Decoder 转换
192
+ elif key.startswith("decoder."):
193
+ # 处理 up blocks 的索引反转
194
+ if ".up." in key:
195
+ match = re.search(r'\.up\.(\d+)\.', key)
196
+ if match:
197
+ old_idx = int(match.group(1))
198
+ new_idx = num_resolutions - 1 - old_idx
199
+ new_key = re.sub(r'\.up\.\d+\.', f'.up_blocks.{new_idx}.', key)
200
+ else:
201
+ new_key = new_key.replace(".up.", ".up_blocks.")
202
+
203
+ # 应用其他替换规则
204
+ for old_pattern, new_pattern in replacements:
205
+ new_key = new_key.replace(old_pattern, new_pattern)
206
+
207
+ # 处理 Conv2d (1x1) -> Linear 的权重形状转换
208
+ if "attentions" in new_key and "weight" in new_key and len(value.shape) == 4:
209
+ if value.shape[2] == 1 and value.shape[3] == 1:
210
+ value = value.squeeze(-1).squeeze(-1)
211
+
212
+ new_state_dict[new_key] = value
213
+
214
+ return new_state_dict
215
+
216
+ @classmethod
217
+ def from_pretrained(cls, model_path, **kwargs):
218
+ """
219
+ 从本地路径加载模型(兼容旧格式)
220
+ """
221
+ config_path = os.path.join(model_path, "config.json")
222
+ ckpt_path = os.path.join(model_path, "checkpoint.pt")
223
+
224
+ if not os.path.isdir(model_path) or not os.path.isfile(ckpt_path):
225
+ raise ValueError(f"Invalid model path: {model_path}. Missing config.json or checkpoint.pt files.")
226
+
227
+ state_dict = torch.load(ckpt_path, map_location="cpu", weights_only=True)
228
+
229
+ # 加载配置
230
+ config = {}
231
+ if os.path.isfile(config_path):
232
+ with open(config_path, "r") as f:
233
+ config = json.load(f)
234
+ config.update(kwargs)
235
+
236
+ # 过滤出 AutoEncoderParams 中的参数
237
+ param_signature = inspect.signature(AutoEncoderParams.__init__).parameters
238
+ valid_kwargs = {k: v for k, v in config.items() if k in param_signature}
239
+
240
+ # 记录被忽略的参数
241
+ ignored_params = [k for k in config.keys() if k not in param_signature]
242
+ if ignored_params:
243
+ logger.debug(f"Ignoring parameters: {ignored_params}")
244
+
245
+ params = AutoEncoderParams(**valid_kwargs)
246
+ model = cls(params)
247
+
248
+ # 转换旧格式的键名到 diffusers 格式
249
+ logger.info("Converting old VAE keys to diffusers format...")
250
+ state_dict = cls._convert_old_keys_to_diffusers(state_dict, num_resolutions=len(params.ch_mult))
251
+
252
+ try:
253
+ msg = model.load_state_dict(state_dict, strict=False)
254
+ logger.info(f"Loaded state_dict from {ckpt_path}")
255
+ if msg.missing_keys:
256
+ logger.warning(f"Missing keys: {msg.missing_keys}")
257
+ # if msg.unexpected_keys:
258
+ # logger.warning(f"Unexpected keys: {msg.unexpected_keys}")
259
+ except Exception as e:
260
+ logger.error(f"Failed to load state_dict: {e}, using random initialization")
261
+
262
+ return model
263
+
264
+
265
+ class NextStepPipeline:
266
+ def __init__(
267
+ self,
268
+ model_name_or_path: str | None = None,
269
+ vae_name_or_path: str | None = None,
270
+ tokenizer: AutoTokenizer | None = None,
271
+ model: nn.Module | None = None,
272
+ vae: AutoencoderKL | None = None,
273
+ enable_gradient_checkpointing: bool = False,
274
+ attn_implementation: str | None = None, # "sdpa", "flash_attention_2", "eager"
275
+ device: str | None = "cuda",
276
+ dtype: torch.dtype | None = torch.bfloat16,
277
+ ):
278
+ self.tokenizer = AutoTokenizer.from_pretrained(
279
+ model_name_or_path,
280
+ local_files_only=True,
281
+ padding_side="left",
282
+ use_fast=True,
283
+ )
284
+ self.model: NextStep = NextStep.from_pretrained(model_name_or_path, local_files_only=True, enable_gradient_checkpointing=enable_gradient_checkpointing)
285
+ self.model.to(device=device,dtype=dtype)
286
+
287
+ self.tokenizer.add_eos_token = False
288
+ if vae_name_or_path is None:
289
+ vae_name_or_path = getattr(self.model.config, "vae_name_or_path", None)
290
+ vae_name_or_path = os.path.join(model_name_or_path, vae_name_or_path)
291
+ self.vae = AutoencoderKL.from_pretrained(vae_name_or_path).to(device=device,dtype=dtype)
292
+
293
+ vae_factor = 2 ** (len(self.vae.config.block_out_channels) - 1)
294
+ self.down_factor = vae_factor * self.model.config.latent_patch_size
295
+ self.shift_factor = getattr(self.vae.config, "shift_factor", 0.0)
296
+ self.scaling_factor = getattr(self.vae.config, "scaling_factor", 1.0)
297
+
298
+ self.boi = self.model.config.boi
299
+ self.eoi = self.model.config.eoi
300
+
301
+ self.image_placeholder_id = self.model.config.image_placeholder_id
302
+ self.pil2tensor = transforms.Compose(
303
+ [
304
+ transforms.ToTensor(),
305
+ transforms.Normalize([0.5, 0.5, 0.5], [0.5, 0.5, 0.5]),
306
+ ]
307
+ )
308
+ self.device = self.model.device
309
+ self.dtype = self.model.dtype
310
+
311
+ def set_seed(self, seed: int, rank: int = 0):
312
+ random.seed(seed + rank)
313
+ np.random.seed(seed + rank)
314
+ torch.manual_seed(seed + rank)
315
+ torch.cuda.manual_seed_all(seed + rank)
316
+ torch.backends.cudnn.deterministic = True
317
+ os.environ["PYTHONHASHSEED"] = str(seed + rank)
318
+
319
+ def to_pil(self, image: torch.Tensor) -> Image.Image:
320
+ """Convert PyTorch tensor to PIL image"""
321
+ if not isinstance(image, torch.Tensor):
322
+ raise TypeError(f"Expected torch.Tensor, got {type(image)}")
323
+
324
+ # 标准化到[0,1]并转换为uint8
325
+ image = (image / 2 + 0.5).clamp(0, 1).mul(255).round().to(torch.uint8)
326
+ image = image.cpu().permute(1, 2, 0).numpy()
327
+
328
+ # 处理单通道图像
329
+ if image.shape[-1] == 1:
330
+ image = image[:, :, 0]
331
+ mode = "L"
332
+ else:
333
+ mode = "RGB"
334
+
335
+ return Image.fromarray(image, mode=mode)
336
+
337
+ def to(self, device: str | None = None, dtype: torch.dtype | None = None):
338
+ if device is not None:
339
+ self.device = device
340
+ if dtype is not None:
341
+ self.dtype = dtype
342
+ self.model.to(self.device, dtype=self.dtype)
343
+ self.vae.to(self.device, dtype=self.dtype)
344
+ return self
345
+
346
+ def hw2str(self, h: int, w: int) -> str:
347
+ return f"{h}*{w}"
348
+
349
+ def _image_str(self, hw: tuple[int, int] = (256, 256)):
350
+ latent_hw = (hw[0] // self.down_factor, hw[1] // self.down_factor)
351
+ image_ids = [self.boi] + [self.image_placeholder_id] * (latent_hw[0] * latent_hw[1]) + [self.eoi]
352
+ image_str = DEFAULT_IMAGE_AREA_TOKEN + self.hw2str(*latent_hw) + self.tokenizer.decode(image_ids)
353
+ return image_str
354
+
355
+ def _check_input(
356
+ self, captions: str | list[str], images: Image.Image | list[Image.Image] | None
357
+ ) -> tuple[list[str], list[Image.Image] | None]:
358
+ if not isinstance(captions, list):
359
+ captions = [captions]
360
+ if images is not None:
361
+ if not isinstance(images, list):
362
+ images = [images]
363
+ # 验证图像数量与<image>标记匹配
364
+ image_token_count = sum(len(re.findall(r"<image>", caption)) for caption in captions)
365
+ if image_token_count != len(images):
366
+ raise ValueError(f"图像数量({len(images)})与图像标记数量({image_token_count})不匹配")
367
+ # 替换<image>标记为图像字符串
368
+ hws = [(img.size[1], img.size[0]) for img in images]
369
+ processed_captions = []
370
+ image_idx = 0
371
+
372
+ for caption in captions:
373
+ processed_caption = caption
374
+ while "<image>" in processed_caption:
375
+ processed_caption = processed_caption.replace("<image>", self._image_str(hws[image_idx]), 1)
376
+ image_idx += 1
377
+ processed_captions.append(processed_caption)
378
+ captions = processed_captions
379
+ return captions, images
380
+
381
+ def _build_captions(
382
+ self,
383
+ captions: str | list[str],
384
+ images: list[Image.Image] | None = None,
385
+ num_images_per_caption: int = 1,
386
+ positive_prompt: str | None = None,
387
+ negative_prompt: str | None = None,
388
+ cfg: float = 1.0,
389
+ cfg_img: float = 1.0,
390
+ ):
391
+ # 标准化输入
392
+ if not isinstance(captions, list):
393
+ captions = [captions]
394
+
395
+ # 重复captions和images
396
+ captions = [caption for caption in captions for _ in range(num_images_per_caption)]
397
+ if images is not None:
398
+ images = [img for img in images for _ in range(num_images_per_caption)]
399
+
400
+ # 添加positive prompt
401
+ if positive_prompt:
402
+ captions = [f"{caption} {positive_prompt}" for caption in captions]
403
+
404
+ # 设置negative prompt默认值
405
+ negative_prompt = negative_prompt or ""
406
+
407
+ num_samples = len(captions)
408
+
409
+ # 简化CFG逻辑
410
+ if cfg != 1.0:
411
+ if cfg_img != 1.0: # 使用图像和文本CFG
412
+ w, h = images[0].size
413
+ captions = captions + [self._image_str((h, w)) + negative_prompt] * num_samples
414
+ images = images + images
415
+ captions = captions + [negative_prompt] * num_samples
416
+
417
+ return captions, images
418
+
419
+ def _add_prefix_ids(self, hw: tuple[int, int], input_ids: torch.Tensor, attention_mask: torch.Tensor):
420
+ """添加图像区域前缀ID"""
421
+ prefix_str = DEFAULT_IMAGE_AREA_TOKEN + self.hw2str(hw[0] // self.down_factor, hw[1] // self.down_factor)
422
+ prefix_output = self.tokenizer(prefix_str, truncation=False, add_special_tokens=True, return_tensors="pt")
423
+
424
+ prefix_input_ids = prefix_output.input_ids.to(input_ids.device, dtype=input_ids.dtype)
425
+ prefix_attention_mask = prefix_output.attention_mask.to(attention_mask.device, dtype=attention_mask.dtype)
426
+
427
+ # 移除BOS token并添加BOI token
428
+ if self.tokenizer.bos_token is not None:
429
+ prefix_input_ids = prefix_input_ids[:, 1:]
430
+ prefix_attention_mask = prefix_attention_mask[:, 1:]
431
+
432
+ boi_token = prefix_input_ids.new_tensor([self.model.config.boi]).unsqueeze(0)
433
+ prefix_input_ids = torch.cat([prefix_input_ids, boi_token], dim=1)
434
+ prefix_attention_mask = torch.cat([prefix_attention_mask, prefix_attention_mask.new_ones((1, 1))], dim=1)
435
+
436
+ # 扩展到batch维度并拼接
437
+ bsz = input_ids.shape[0]
438
+ input_ids = torch.cat([input_ids, prefix_input_ids.expand(bsz, -1)], dim=1)
439
+ attention_mask = torch.cat([attention_mask, prefix_attention_mask.expand(bsz, -1)], dim=1)
440
+
441
+ return input_ids, attention_mask
442
+
443
+
444
+ def layer_norm(self, input: torch.Tensor, normalized_shape: torch.Size, eps: float = 1e-6) -> torch.Tensor:
445
+ """简化的layer norm实现,使用PyTorch内置函数"""
446
+ return F.layer_norm(input, normalized_shape, eps=eps)
447
+
448
+ @torch.no_grad()
449
+ def decoding(
450
+ self,
451
+ c: torch.Tensor,
452
+ attention_mask: torch.Tensor,
453
+ past_key_values: Cache,
454
+ max_new_len: int,
455
+ num_images_per_caption: int,
456
+ noise: torch.Tensor = None,
457
+ use_norm: bool = False,
458
+ cfg: float = 1.0,
459
+ cfg_img: float = 1.0,
460
+ cfg_schedule: Literal["linear", "constant"] = "constant",
461
+ timesteps_shift: float = 1.0,
462
+ num_sampling_steps: int = 20,
463
+ progress: bool = True,
464
+ hw: tuple[int, int] = (256, 256),
465
+ step: int = 0,
466
+ sde_solver: bool = False,
467
+ sde_type: str = "sde",
468
+ ):
469
+ indices = list(range(max_new_len))
470
+ indices = tqdm(indices, unit="tokens") if progress else indices
471
+ tokens = None
472
+ for step in indices:
473
+ cur_noise = None
474
+ if noise is not None:
475
+ cur_noise = noise[:,step:step+1,:][0]
476
+
477
+ # 简化CFG调度逻辑
478
+ if cfg_schedule == "linear":
479
+ tokens_len = 0 if tokens is None else tokens.shape[1]
480
+ cfg_iter = max(cfg / 2, 1 + (cfg - 1) * tokens_len / max_new_len)
481
+ cfg_img_iter = max(cfg_img / 2, 1 + (cfg_img - 1) * tokens_len / max_new_len)
482
+ else: # constant or other
483
+ cfg_iter = cfg
484
+ cfg_img_iter = cfg_img
485
+
486
+ c = self.model.image_out_projector(c)
487
+ token_sampled = self.model.image_head.sample(
488
+ c=c.squeeze(1),
489
+ noise=cur_noise,
490
+ cfg=cfg_iter,
491
+ cfg_img=cfg_img_iter,
492
+ timesteps_shift=timesteps_shift,
493
+ num_sampling_steps=num_sampling_steps,
494
+ noise_repeat=num_images_per_caption,
495
+ sde_solver=sde_solver,
496
+ sde_type=sde_type,
497
+ )
498
+
499
+ if use_norm:
500
+ token_sampled = self.layer_norm(token_sampled, normalized_shape=token_sampled.size()[1:])
501
+ if tokens is not None:
502
+ tokens = torch.cat([tokens, token_sampled.unsqueeze(1)], dim=1)
503
+ else:
504
+ tokens = token_sampled.unsqueeze(1)
505
+
506
+ cur_inputs_embeds = self.model.image_in_projector(tokens[:, -1:])
507
+ # 简化CFG处理逻辑
508
+ if cfg != 1.0:
509
+ repeat_count = 3 if cfg_img != 1.0 else 2
510
+ cur_inputs_embeds = torch.cat([cur_inputs_embeds] * repeat_count, dim=0)
511
+
512
+ attention_mask = torch.cat([attention_mask, attention_mask.new_ones((attention_mask.shape[0], 1))], dim=-1)
513
+ outputs = self.model.forward(
514
+ inputs_embeds=cur_inputs_embeds,
515
+ attention_mask=attention_mask,
516
+ past_key_values=past_key_values,
517
+ use_cache=True,
518
+ )
519
+ past_key_values = outputs.past_key_values
520
+ c = outputs.last_hidden_state[:, -1:]
521
+
522
+
523
+ return tokens
524
+
525
+ @torch.no_grad()
526
+ def generate_image(
527
+ self,
528
+ captions: str | list[str],
529
+ images: list[Image.Image] | None = None,
530
+ num_images_per_caption: int = 1,
531
+ positive_prompt: str | None = None,
532
+ negative_prompt: str | None = None,
533
+ hw: tuple[int, int] = (256, 256),
534
+ use_norm: bool = False,
535
+ cfg: float = 1.0,
536
+ cfg_img: float = 1.0,
537
+ cfg_schedule: Literal["linear", "constant"] = "constant",
538
+ num_sampling_steps: int = 20,
539
+ timesteps_shift: float = 1.0,
540
+ seed: int = 42,
541
+ progress: bool = True,
542
+ sde_type: str = "sde",
543
+ ) -> list[Image.Image]:
544
+ # 0. set seed
545
+
546
+ # 1. check input
547
+ captions, images = self._check_input(captions, images)
548
+
549
+ # 2. build captions
550
+ captions, images = self._build_captions(
551
+ captions, images, num_images_per_caption, positive_prompt, negative_prompt, cfg, cfg_img
552
+ )
553
+
554
+ # 3. encode images
555
+ latents = None
556
+ if images is not None:
557
+ pixel_values = torch.stack([self.pil2tensor(img) for img in images]).to(self.device)
558
+ posterior = self.vae.encode(pixel_values.to(self.vae.dtype)).latent_dist
559
+ latents = (posterior.sample() - self.shift_factor) * self.scaling_factor
560
+
561
+ # 添加BOS token
562
+ if self.tokenizer.bos_token is not None:
563
+ captions = [self.tokenizer.bos_token + caption for caption in captions]
564
+
565
+ if seed is not None:
566
+ self.set_seed(seed)
567
+
568
+ # 4. tokenize caption & add prefix ids
569
+ output = self.tokenizer(
570
+ captions,
571
+ padding="longest",
572
+ truncation=False,
573
+ add_special_tokens=True,
574
+ return_tensors="pt",
575
+ padding_side="left"
576
+ )
577
+ input_ids = output.input_ids.to(self.device)
578
+ attention_mask = output.attention_mask.to(self.device)
579
+ input_ids, attention_mask = self._add_prefix_ids(hw, input_ids, attention_mask)
580
+
581
+ # 5. LLM prefill
582
+ max_new_len = (hw[0] // self.down_factor) * (hw[1] // self.down_factor)
583
+ max_cache_len = input_ids.shape[1] + max_new_len
584
+ # past_key_values = StaticCache(
585
+ # config=self.model.config,
586
+ # max_batch_size=input_ids.shape[0],
587
+ # max_cache_len=max_cache_len,
588
+ # device=self.device,
589
+ # dtype=self.dtype,
590
+ # )
591
+ inputs_embeds = self.model.prepare_inputs_embeds(input_ids, latents)
592
+
593
+ outputs = self.model.forward(
594
+ inputs_embeds=inputs_embeds,
595
+ attention_mask=attention_mask,
596
+ past_key_values=None,
597
+ use_cache=True,
598
+ )
599
+ past_key_values = outputs.past_key_values
600
+ c = outputs.last_hidden_state[:, -1:]
601
+
602
+
603
+ # 6. decoding
604
+ tokens = self.decoding(
605
+ c=c,
606
+ attention_mask=attention_mask,
607
+ past_key_values=past_key_values,
608
+ max_new_len=max_new_len,
609
+ num_images_per_caption=num_images_per_caption,
610
+ use_norm=use_norm,
611
+ cfg=cfg,
612
+ cfg_img=cfg_img,
613
+ cfg_schedule=cfg_schedule,
614
+ timesteps_shift=timesteps_shift,
615
+ num_sampling_steps=num_sampling_steps,
616
+ progress=progress,
617
+ hw=hw,
618
+ sde_type=sde_type,
619
+ )
620
+
621
+ # 7. unpatchify
622
+ latents = self.model.unpatchify(tokens, h=hw[0] // self.down_factor, w=hw[1] // self.down_factor)
623
+ latents = (latents / self.scaling_factor) + self.shift_factor
624
+
625
+ # 8. decode latents
626
+ sampled_images = self.vae.decode(latents.to(self.vae.dtype)).sample
627
+ sampled_images = sampled_images.detach().cpu().to(torch.float32)
628
+ pil_images = [self.to_pil(img) for img in sampled_images]
629
+
630
+ return pil_images
631
+
models/nextstep_model.py ADDED
@@ -0,0 +1,538 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import math
2
+ import torch
3
+ import torch.nn as nn
4
+
5
+ from torch.utils.checkpoint import checkpoint
6
+
7
+ from transformers import Qwen2Model, Qwen2Config
8
+
9
+ def modulate(x, shift, scale=None):
10
+ """Adaptive layer normalization modulation"""
11
+ if shift is None:
12
+ return x * (1 + scale)
13
+ return x * (1 + scale) + shift
14
+
15
+
16
+ def expand_t(t, x):
17
+ """Function to reshape time t to broadcastable dimension of x
18
+ Args:
19
+ t: [bsz,], time vector
20
+ x: [bsz,...], data point
21
+ """
22
+ return t.view(-1, *([1] * (x.ndim - 1)))
23
+
24
+ class ResBlock(nn.Module):
25
+ def __init__(self, channels, mlp_ratio=1.0):
26
+ super().__init__()
27
+ self.channels = channels
28
+ self.intermediate_size = int(channels * mlp_ratio)
29
+
30
+ self.in_ln = nn.LayerNorm(self.channels, eps=1e-6)
31
+ self.mlp = nn.Sequential(
32
+ nn.Linear(self.channels, self.intermediate_size),
33
+ nn.SiLU(),
34
+ nn.Linear(self.intermediate_size, self.channels),
35
+ )
36
+
37
+ self.adaLN_modulation = nn.Sequential(nn.SiLU(), nn.Linear(channels, 3 * channels, bias=True))
38
+
39
+ def forward(self, x, y):
40
+ shift_mlp, scale_mlp, gate_mlp = self.adaLN_modulation(y).chunk(3, dim=-1)
41
+ h = modulate(self.in_ln(x), shift_mlp, scale_mlp)
42
+ h = self.mlp(h)
43
+ return x + gate_mlp * h
44
+
45
+
46
+ class FinalLayer(nn.Module):
47
+ def __init__(self, model_channels, out_channels):
48
+ super().__init__()
49
+ self.norm_final = nn.LayerNorm(model_channels, elementwise_affine=False, eps=1e-6)
50
+ self.linear = nn.Linear(model_channels, out_channels, bias=True)
51
+ self.adaLN_modulation = nn.Sequential(nn.SiLU(), nn.Linear(model_channels, 2 * model_channels, bias=True))
52
+
53
+ def forward(self, x, c):
54
+ shift, scale = self.adaLN_modulation(c).chunk(2, dim=-1)
55
+ x = modulate(self.norm_final(x), shift, scale)
56
+ x = self.linear(x)
57
+ return x
58
+
59
+
60
+ class TimestepEmbedder(nn.Module):
61
+ """
62
+ Embeds scalar timesteps into vector representations.
63
+
64
+ Note: diffusers.models.embeddings.TimestepEmbedding provides similar functionality
65
+ but with a different interface (requires in_channels, time_embed_dim).
66
+ This implementation follows the Glide-style timestep embedding.
67
+ """
68
+
69
+ def __init__(self, hidden_size, frequency_embedding_size=256):
70
+ super().__init__()
71
+ self.mlp = nn.Sequential(
72
+ nn.Linear(frequency_embedding_size, hidden_size, bias=True),
73
+ nn.SiLU(),
74
+ nn.Linear(hidden_size, hidden_size, bias=True),
75
+ )
76
+ self.frequency_embedding_size = frequency_embedding_size
77
+
78
+ @staticmethod
79
+ def timestep_embedding(t: torch.Tensor, dim: int, max_period: float = 10000.0):
80
+ """
81
+ Create sinusoidal timestep embeddings.
82
+ :param t: a 1-D Tensor of N indices, one per batch element. These may be fractional.
83
+ :param dim: the dimension of the output.
84
+ :param max_period: controls the minimum frequency of the embeddings.
85
+ :return: an (N, D) Tensor of positional embeddings.
86
+ """
87
+ # https://github.com/openai/glide-text2im/blob/main/glide_text2im/nn.py
88
+ half = dim // 2
89
+ freqs = torch.exp(-math.log(max_period) * torch.arange(start=0, end=half, dtype=torch.float32) / half).to(
90
+ device=t.device
91
+ )
92
+ args = t[:, None].float() * freqs[None]
93
+ embedding = torch.cat([torch.cos(args), torch.sin(args)], dim=-1)
94
+ if dim % 2:
95
+ embedding = torch.cat([embedding, torch.zeros_like(embedding[:, :1])], dim=-1)
96
+ return embedding
97
+
98
+ def forward(self, t):
99
+ t_freq = self.timestep_embedding(t, self.frequency_embedding_size)
100
+ t_emb = self.mlp(t_freq.to(self.mlp[0].weight.dtype))
101
+ return t_emb
102
+
103
+
104
+ class SimpleMLPAdaLN(nn.Module):
105
+ def __init__(self, input_dim, cond_dim, dim=1536, layers=12, mlp_ratio=1.0):
106
+ super().__init__()
107
+ self.input_dim = input_dim
108
+ self.cond_dim = cond_dim
109
+ self.dim = dim
110
+ self.layers = layers
111
+ self.mlp_ratio = mlp_ratio
112
+
113
+ self.time_embed = TimestepEmbedder(dim)
114
+ self.cond_embed = nn.Linear(cond_dim, dim)
115
+ self.input_proj = nn.Linear(input_dim, dim)
116
+
117
+ res_blocks = []
118
+ for _ in range(layers):
119
+ res_blocks.append(ResBlock(dim, mlp_ratio))
120
+ self.res_blocks = nn.ModuleList(res_blocks)
121
+
122
+ self.final_layer = FinalLayer(dim, input_dim)
123
+
124
+ self.grad_checkpointing = False
125
+
126
+ self.initialize_weights()
127
+
128
+ def initialize_weights(self):
129
+ def _basic_init(module):
130
+ if isinstance(module, nn.Linear):
131
+ torch.nn.init.xavier_uniform_(module.weight)
132
+ if module.bias is not None:
133
+ nn.init.constant_(module.bias, 0)
134
+
135
+ self.apply(_basic_init)
136
+
137
+ # Initialize timestep embedding MLP
138
+ nn.init.normal_(self.time_embed.mlp[0].weight, std=0.02)
139
+ nn.init.normal_(self.time_embed.mlp[2].weight, std=0.02)
140
+
141
+ # Zero-out adaLN modulation layers
142
+ for block in self.res_blocks:
143
+ nn.init.constant_(block.adaLN_modulation[-1].weight, 0)
144
+ nn.init.constant_(block.adaLN_modulation[-1].bias, 0)
145
+
146
+ # Zero-out output layers
147
+ nn.init.constant_(self.final_layer.adaLN_modulation[-1].weight, 0)
148
+ nn.init.constant_(self.final_layer.adaLN_modulation[-1].bias, 0)
149
+ nn.init.constant_(self.final_layer.linear.weight, 0)
150
+ nn.init.constant_(self.final_layer.linear.bias, 0)
151
+
152
+ def forward(self, x, t, c):
153
+ """
154
+ x.shape = (bsz, input_dim)
155
+ t.shape = (bsz,)
156
+ c.shape = (bsz, cond_dim)
157
+ """
158
+
159
+ x = self.input_proj(x)
160
+ t = self.time_embed(t)
161
+ c = self.cond_embed(c)
162
+
163
+ y = t + c
164
+
165
+ for block in self.res_blocks:
166
+ if self.grad_checkpointing and self.training:
167
+ x = checkpoint(block, x, y, use_reentrant=False)
168
+ else:
169
+ x = block(x, y)
170
+
171
+ return self.final_layer(x, y)
172
+
173
+
174
+ class FlowMatchingHead(nn.Module):
175
+
176
+ def __init__(self, input_dim, cond_dim, dim=1536, layers=12, mlp_ratio=1.0):
177
+ super(FlowMatchingHead, self).__init__()
178
+ self.input_dim = input_dim
179
+ self.net = SimpleMLPAdaLN(input_dim=input_dim, cond_dim=cond_dim, dim=dim, layers=layers, mlp_ratio=mlp_ratio)
180
+
181
+ @property
182
+ def dtype(self):
183
+ return self.net.input_proj.weight.dtype
184
+
185
+ @property
186
+ def device(self):
187
+ return self.net.input_proj.weight.device
188
+
189
+ def get_score_from_velocity(self, velocity, x, t):
190
+ """Wrapper function: transfrom velocity prediction model to score
191
+ Args:
192
+ velocity: [bsz, ...] shaped tensor; velocity model output
193
+ x: [bsz, ...] shaped tensor; x_t data point
194
+ t: [bsz,] time tensor
195
+ """
196
+ t = expand_t(t, x)
197
+ alpha_t, d_alpha_t = t, 1
198
+ sigma_t, d_sigma_t = 1 - t, -1
199
+ mean = x
200
+ reverse_alpha_ratio = alpha_t / d_alpha_t
201
+ var = sigma_t**2 - reverse_alpha_ratio * d_sigma_t * sigma_t
202
+ score = (reverse_alpha_ratio * velocity - mean) / var
203
+ return score
204
+
205
+ def get_velocity_from_cfg(self, velocity, cfg, cfg_img, cfg_mul, normalize=False):
206
+ if cfg_mul == 2:
207
+ cond_v, uncond_v = torch.chunk(velocity, 2, dim=0)
208
+ velocity = uncond_v + cfg * (cond_v - uncond_v)
209
+ if normalize and cfg > 1.0:
210
+ norm_cond = torch.norm(cond_v, dim=-1, keepdim=True)
211
+ norm_velocity = torch.norm(velocity, dim=-1, keepdim=True)
212
+ scale_factor = norm_cond / (norm_velocity + 1e-6)
213
+ scale_factor = torch.clamp(scale_factor, min=0, max=1)
214
+ velocity = velocity * scale_factor
215
+ elif cfg_mul == 3:
216
+ cond_v, uncond_v1, uncond_v2 = torch.chunk(velocity, 3, dim=0)
217
+ velocity = uncond_v2 + cfg_img * (uncond_v1 - uncond_v2) + cfg * (cond_v - uncond_v1)
218
+ if normalize and cfg > 1.0 and cfg_img > 1.0:
219
+ norm_cond = torch.norm(cond_v, dim=-1, keepdim=True)
220
+ norm_velocity = torch.norm(velocity, dim=-1, keepdim=True)
221
+ scale_factor = norm_cond / (norm_velocity + 1e-6)
222
+ scale_factor = torch.clamp(scale_factor, min=0, max=1)
223
+ velocity = velocity * scale_factor
224
+ return velocity
225
+
226
+ def _compute_cfg_mult(self, cfg: float, cfg_img: float) -> int:
227
+ """计算 CFG 的倍数"""
228
+ cfg_mul = 1
229
+ if cfg > 1.0:
230
+ cfg_mul += 1
231
+ if cfg_img > 1.0:
232
+ cfg_mul += 1
233
+ return cfg_mul
234
+
235
+ def _compute_velocity_and_basics(self, x, c, ti, cfg, cfg_img, cfg_mul):
236
+ """计算 velocity 和基础值(cur_t, next_t, x0, x1)"""
237
+ combined = torch.cat([x] * cfg_mul, dim=0)
238
+ velocity = self.net(combined.to(c.dtype), ti.expand(c.shape[0]).to(c), c)
239
+ velocity = velocity.to(torch.float32)
240
+ velocity = self.get_velocity_from_cfg(velocity, cfg, cfg_img, cfg_mul)
241
+
242
+ cur_t = ti.view(-1, *([1] * (len(x.shape) - 1))).to(x.device)
243
+ x0 = x - velocity * cur_t # noise
244
+ x1 = x + velocity * (1 - cur_t) # ode image
245
+
246
+ return velocity, cur_t, x0, x1
247
+
248
+
249
+ @torch.no_grad()
250
+ def sample(
251
+ self,
252
+ c: torch.Tensor,
253
+ noise: torch.Tensor = None,
254
+ cfg: float = 1.0,
255
+ cfg_img: float = 1.0,
256
+ timesteps_shift: float = 1.0,
257
+ num_sampling_steps: int = 20,
258
+ last_step_size: float = 0.0,
259
+ noise_repeat: int = 1,
260
+ sde_solver: bool = False,
261
+ sde_type: str = "sde",
262
+ noise_level: float = 0.8,
263
+ ):
264
+ # """c.shape = (bsz, cond_dim)"""
265
+ cfg_mul = self._compute_cfg_mult(cfg, cfg_img)
266
+
267
+ if noise is None:
268
+ noise = torch.randn((c.shape[0] // cfg_mul, self.input_dim), device=c.device, dtype=c.dtype)
269
+
270
+ x = noise
271
+ xs = []
272
+
273
+ t0, t1 = 0, 1
274
+ timesteps = torch.linspace(t0, t1, num_sampling_steps + 1, device=c.device)[:-1]
275
+ timesteps = timesteps / (timesteps_shift - (timesteps_shift - 1) * timesteps)
276
+ timesteps = torch.cat([timesteps, torch.ones(1, device=c.device)])
277
+ # timesteps = torch.tensor([1.0000, 0.9601, 0.9133, 0.8577, 0.7904, 0.7073, 0.6022, 0.4649, 0.2780, 0.0089, 0.0000], device=c.device)
278
+ # timesteps = 1 - timesteps
279
+ sigma_max = timesteps[-2]
280
+ for ti, tj in zip(timesteps[:-1], timesteps[1:]):
281
+ velocity, cur_t, x0, x1 = self._compute_velocity_and_basics(x, c, ti, cfg, cfg_img, cfg_mul)
282
+ next_t = tj.view(-1, *([1] * (len(x.shape) - 1))).to(x.device)
283
+
284
+ if sde_type == "cps":
285
+ # Flow-CPS
286
+ std_dev_t = (1 - next_t) * math.sin(noise_level * math.pi / 2) # sigma_t in paper
287
+ sde_noise = torch.randn((c.shape[0] // cfg_mul, self.input_dim), device=c.device, dtype=c.dtype)
288
+
289
+ x = x0 * torch.sqrt((1 - next_t)**2 - std_dev_t**2) + x1 * next_t + std_dev_t * sde_noise
290
+ elif sde_type == "sde":
291
+ sigma = 1 - cur_t
292
+ dt = tj - ti
293
+ std_dev_t = torch.sqrt(sigma / (1 - torch.where(sigma == 1, sigma_max, sigma)))*noise_level
294
+
295
+ variance_noise = torch.randn((c.shape[0] // cfg_mul, self.input_dim), device=c.device, dtype=c.dtype)
296
+
297
+ x = x0 * (1 - next_t) + x1 * next_t - std_dev_t ** 2 * dt / (2 * sigma) * x0
298
+ x = x + std_dev_t * torch.sqrt(dt) * variance_noise
299
+ else:
300
+ # ODE
301
+ x = x0 * (1 - next_t) + x1 * next_t
302
+
303
+ xs.append(x)
304
+
305
+
306
+ if len(xs) != num_sampling_steps:
307
+ raise ValueError(f"Samples ({len(xs)}) does not match the number of steps ({num_sampling_steps})")
308
+
309
+ return xs[-1].to(c.dtype)
310
+
311
+ class NextStepConfig(Qwen2Config):
312
+ model_type = "nextstep"
313
+
314
+ def __init__(
315
+ self,
316
+ vae_name_or_path: str | None = None,
317
+ latent_size: int = 32,
318
+ latent_patch_size: int = 2,
319
+ latent_channels: int = 16,
320
+ boi: int | None = None,
321
+ eoi: int | None = None,
322
+ image_placeholder_id: int | None = None,
323
+ pad_token_id_added: int | None = None,
324
+ lm_loss_weight: float = 0.01,
325
+ im_loss_weight: float = 1.0,
326
+ fm_head_dim: int = 1536,
327
+ fm_head_layers: int = 12,
328
+ fm_head_batch_mul: int = 4,
329
+ o_attention_bias: bool | None = None,
330
+ attn_implementation: str | None = None, # Add flash attention support
331
+ **kwargs,
332
+ ):
333
+ super().__init__(**kwargs)
334
+
335
+ # 图像相关参数
336
+ self.vae_name_or_path = vae_name_or_path
337
+ self.latent_size = latent_size
338
+ self.latent_patch_size = latent_patch_size
339
+ self.latent_channels = latent_channels
340
+
341
+ # 特殊token ID
342
+ self.boi = boi
343
+ self.eoi = eoi
344
+ self.image_placeholder_id = image_placeholder_id
345
+ self.pad_token_id_added = pad_token_id_added
346
+
347
+ # 损失权重
348
+ self.lm_loss_weight = lm_loss_weight
349
+ self.im_loss_weight = im_loss_weight
350
+
351
+ # Flow Matching Head参数
352
+ self.fm_head_dim = fm_head_dim
353
+ self.fm_head_layers = fm_head_layers
354
+ self.fm_head_batch_mul = fm_head_batch_mul
355
+
356
+ # Attention bias
357
+ self.o_attention_bias = o_attention_bias
358
+
359
+ # Flash attention support
360
+ self._attn_implementation = attn_implementation
361
+
362
+ class NextStep(Qwen2Model):
363
+ config_class = NextStepConfig
364
+
365
+ def __init__(self, config: NextStepConfig, enable_gradient_checkpointing: bool = False):
366
+ super().__init__(config)
367
+
368
+ # 初始化投影器和头部
369
+ self.lm_head = nn.Linear(config.hidden_size, config.vocab_size, bias=False)
370
+ token_dim = config.latent_channels * config.latent_patch_size**2
371
+
372
+ # 图像投影器
373
+ self.image_in_projector = self._create_linear(token_dim, config.hidden_size, config.initializer_range)
374
+ self.image_out_projector = self._create_linear(config.hidden_size, config.hidden_size, config.initializer_range)
375
+
376
+ # Flow Matching Head
377
+ self.image_head = FlowMatchingHead(
378
+ input_dim=token_dim,
379
+ cond_dim=config.hidden_size,
380
+ dim=config.fm_head_dim,
381
+ layers=config.fm_head_layers,
382
+ )
383
+
384
+ self.gradient_checkpointing = False
385
+ # 缓存第一个可训练参数,用于建立梯度连接(避免每次遍历)
386
+ self._first_trainable_param = None
387
+
388
+ if enable_gradient_checkpointing:
389
+ try:
390
+ self.gradient_checkpointing_enable(gradient_checkpointing_kwargs={"use_reentrant": False})
391
+ print("Enabled gradient checkpointing (use_reentrant=False) at init for NextStep model")
392
+ except Exception as e:
393
+ print(f"Enable gradient checkpointing failed at init: {e}")
394
+
395
+ def gradient_checkpointing_enable(self, **kwargs):
396
+ super().gradient_checkpointing_enable(**kwargs)
397
+ self.image_head.net.grad_checkpointing = True
398
+ self.gradient_checkpointing = True
399
+
400
+ def _get_first_trainable_param(self):
401
+ """获取第一个可训练参数的引用(延迟初始化,避免在 __init__ 时 LoRA 还未添加)"""
402
+ if self._first_trainable_param is None:
403
+ for param in self.parameters():
404
+ if param.requires_grad:
405
+ self._first_trainable_param = param
406
+ break
407
+ return self._first_trainable_param
408
+
409
+ def _ensure_gradient_connection(self, hidden_states):
410
+ """确保 hidden_states 有梯度连接(对于 LoRA + gradient checkpointing 很重要)"""
411
+ if self.training and not hidden_states.requires_grad:
412
+ # 通过一个可训练参数的恒等操作来建立梯度连接
413
+ # 这样即使基础层被冻结,梯度也能通过 LoRA 层传播
414
+ # 使用缓存的可训练参数,避免每次遍历
415
+ param = self._get_first_trainable_param()
416
+ if param is not None:
417
+ # 创建一个恒等操作,但通过可训练参数建立连接
418
+ # 这样 hidden_states 就能连接到计算图
419
+ # 使用 flatten()[0] 而不是 sum() 以减少计算开销
420
+ hidden_states = hidden_states + 0.0 * param.flatten()[0]
421
+ else:
422
+ # 如果没有可训练参数,直接设置 requires_grad
423
+ hidden_states = hidden_states.detach().requires_grad_(True)
424
+ return hidden_states
425
+
426
+ def _create_linear(self, in_features: int, out_features: int, std: float) -> nn.Linear:
427
+ """创建并初始化线性层"""
428
+ linear = nn.Linear(in_features, out_features)
429
+ linear.weight.data.normal_(mean=0.0, std=std)
430
+ linear.bias.data.zero_()
431
+ return linear
432
+
433
+ def patchify(self, img: torch.Tensor):
434
+ """
435
+ img: (bsz, C, H, W)
436
+ x: (bsz, H * W / patch_size**2, patch_size**2 * C)
437
+ """
438
+ bsz, c, h, w = img.shape
439
+ p = self.config.latent_patch_size
440
+ h_, w_ = h // p, w // p
441
+
442
+ img = img.reshape(bsz, c, h_, p, w_, p)
443
+ img = torch.einsum("nchpwq->nhwcpq", img)
444
+ x = img.reshape(bsz, h_ * w_, c * p**2)
445
+ return x
446
+
447
+ def unpatchify(self, x: torch.Tensor, h: int = None, w: int = None):
448
+ """
449
+ x: (bsz, H * W / patch_size**2, patch_size**2 * C)
450
+ img: (bsz, C, H, W)
451
+ """
452
+ bsz = x.shape[0]
453
+ p = self.config.latent_patch_size
454
+ c = self.config.latent_channels
455
+ if h is None and w is None:
456
+ h_ = w_ = int(x.shape[1] ** 0.5)
457
+ else:
458
+ h_, w_ = h, w
459
+ assert h_ * w_ == x.shape[1], f"Invalid sequence length {x.shape[1]}."
460
+
461
+ x = x.reshape(bsz, h_, w_, c, p, p)
462
+ x = torch.einsum("nhwcpq->nchpwq", x)
463
+ img = x.reshape(bsz, c, h_ * p, w_ * p)
464
+ return img
465
+
466
+ def prepare_inputs_embeds(self, input_ids: torch.LongTensor | None = None, latents: torch.FloatTensor | None = None):
467
+ """准备输入嵌入,支持文本和图像token混合"""
468
+ if latents is None:
469
+ return self.embed_tokens(input_ids)
470
+
471
+ bs, seq_length = input_ids.shape
472
+ inputs_embeds = torch.zeros(
473
+ (bs, seq_length, self.config.hidden_size),
474
+ device=self.embed_tokens.weight.device,
475
+ dtype=self.embed_tokens.weight.dtype,
476
+ )
477
+
478
+ im_indices = input_ids == self.config.image_placeholder_id
479
+ lm_indices = ~im_indices
480
+
481
+ # 处理图像latents
482
+ try:
483
+ if isinstance(latents, list):
484
+ tokens = torch.cat([self.patchify(latent) for latent in latents], dim=1)
485
+ else:
486
+ tokens = self.patchify(latents)
487
+ except Exception as e:
488
+ tokens = latents
489
+
490
+ image_embeds = self.image_in_projector(tokens).view(-1, self.config.hidden_size)
491
+ token_embeds = self.embed_tokens(input_ids[lm_indices])
492
+
493
+ inputs_embeds[im_indices] = image_embeds.to(inputs_embeds.dtype)
494
+ inputs_embeds[lm_indices] = token_embeds
495
+
496
+ return inputs_embeds
497
+
498
+ def forward(self, input_ids=None, attention_mask=None, position_ids=None,
499
+ inputs_embeds=None, past_key_values=None, use_cache=None,
500
+ output_attentions=None, output_hidden_states=None,
501
+ return_dict=None, forward_head=False,normalize=False, **kwargs):
502
+ """重写 forward 方法,添加梯度连接逻辑"""
503
+ # 如果提供了 inputs_embeds,确保它有梯度连接
504
+ if forward_head:
505
+ x, t, c, cfg, cfg_img, cfg_mul = kwargs["x"], kwargs["t"], kwargs["c"],kwargs["cfg"], kwargs["cfg_img"], kwargs["cfg_mul"]
506
+ return self.forward_head(x, t, c, cfg, cfg_img, cfg_mul, normalize=normalize)
507
+
508
+ if inputs_embeds is not None:
509
+ inputs_embeds = self._ensure_gradient_connection(inputs_embeds)
510
+
511
+ # 调用父类的 forward 方法
512
+ return super().forward(
513
+ input_ids=input_ids,
514
+ attention_mask=attention_mask,
515
+ position_ids=position_ids,
516
+ inputs_embeds=inputs_embeds,
517
+ past_key_values=past_key_values,
518
+ use_cache=use_cache,
519
+ output_attentions=output_attentions,
520
+ output_hidden_states=output_hidden_states,
521
+ return_dict=return_dict,
522
+ **kwargs
523
+ )
524
+
525
+ def forward_head(self, x, t, c, cfg, cfg_img, cfg_mul, normalize=False, **kwargs):
526
+ # Align tensors with the actual module dtypes so Deepspeed casting does not cause matmul mismatches.
527
+ projector_dtype = next(self.image_out_projector.parameters()).dtype
528
+ c = c.to(projector_dtype)
529
+ x = x.to(projector_dtype)
530
+ t = t.to(projector_dtype)
531
+
532
+ c = self.image_out_projector(c)
533
+ c = c.squeeze(1)
534
+
535
+ velocity = self.image_head.net(x, t, c)
536
+ velocity = velocity.to(torch.float32)
537
+ velocity = self.image_head.get_velocity_from_cfg(velocity, cfg, cfg_img, cfg_mul, normalize)
538
+ return velocity
pytorch-model-00001-of-00004.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:a90dfc0a1ff8eb1228c285deb309c2b3dbd764c297ac2eb5f0aefff52c69949f
3
+ size 9962132680
pytorch-model-00002-of-00004.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:7757fd43fa03c2567b43730fa8edfb74c304ceabce1bd3ae6b6a6542dddc4704
3
+ size 9909693448
pytorch-model-00003-of-00004.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:d8a6e6396efe3af55320c3223cd341abc94f0e4862ff54729533b69e404ef099
3
+ size 8478742432
pytorch-model-00004-of-00004.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:03bfc2ef4d9d760fb3ae9edf48d60d66c2e498286825dbc09658d9aa8cce1ceb
3
+ size 1557135464
requirements.txt ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ diffusers==0.34.0
2
+ einops==0.8.1
3
+ gradio==5.42.0
4
+ loguru==0.7.3
5
+ numpy==1.26.4
6
+ omegaconf==2.3.0
7
+ Pillow==11.0.0
8
+ Requests==2.32.4
9
+ safetensors==0.5.3
10
+ tabulate==0.9.0
11
+ torch==2.5.1
12
+ torchvision==0.20.1
13
+ tqdm==4.67.1
14
+ transformers==4.55.0
special_tokens_map.json ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "additional_special_tokens": [
3
+ "<|image_area|>",
4
+ "<|begin_of_image|>",
5
+ "<|end_of_image|>",
6
+ "<|image_placeholder|>",
7
+ "<|begin_of_prompt_refinement|>",
8
+ "<|end_of_prompt_refinement|>",
9
+ "<|begin_of_thinking|>",
10
+ "<|end_of_thinking|>",
11
+ "<|beginoftext|>"
12
+ ],
13
+ "eos_token": {
14
+ "content": "<|endoftext|>",
15
+ "lstrip": false,
16
+ "normalized": false,
17
+ "rstrip": false,
18
+ "single_word": false
19
+ },
20
+ "pad_token": {
21
+ "content": "[PAD]",
22
+ "lstrip": false,
23
+ "normalized": false,
24
+ "rstrip": false,
25
+ "single_word": false
26
+ }
27
+ }
tokenizer.json ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:310b48c809fba04c32e7f7cdac4d0fb1c00140d8914e0b0163307f64e5330a92
3
+ size 11423853
tokenizer_config.json ADDED
@@ -0,0 +1,285 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "add_bos_token": false,
3
+ "add_prefix_space": false,
4
+ "added_tokens_decoder": {
5
+ "151643": {
6
+ "content": "<|endoftext|>",
7
+ "lstrip": false,
8
+ "normalized": false,
9
+ "rstrip": false,
10
+ "single_word": false,
11
+ "special": true
12
+ },
13
+ "151644": {
14
+ "content": "<|im_start|>",
15
+ "lstrip": false,
16
+ "normalized": false,
17
+ "rstrip": false,
18
+ "single_word": false,
19
+ "special": true
20
+ },
21
+ "151645": {
22
+ "content": "<|im_end|>",
23
+ "lstrip": false,
24
+ "normalized": false,
25
+ "rstrip": false,
26
+ "single_word": false,
27
+ "special": true
28
+ },
29
+ "151646": {
30
+ "content": "<|object_ref_start|>",
31
+ "lstrip": false,
32
+ "normalized": false,
33
+ "rstrip": false,
34
+ "single_word": false,
35
+ "special": true
36
+ },
37
+ "151647": {
38
+ "content": "<|object_ref_end|>",
39
+ "lstrip": false,
40
+ "normalized": false,
41
+ "rstrip": false,
42
+ "single_word": false,
43
+ "special": true
44
+ },
45
+ "151648": {
46
+ "content": "<|box_start|>",
47
+ "lstrip": false,
48
+ "normalized": false,
49
+ "rstrip": false,
50
+ "single_word": false,
51
+ "special": true
52
+ },
53
+ "151649": {
54
+ "content": "<|box_end|>",
55
+ "lstrip": false,
56
+ "normalized": false,
57
+ "rstrip": false,
58
+ "single_word": false,
59
+ "special": true
60
+ },
61
+ "151650": {
62
+ "content": "<|quad_start|>",
63
+ "lstrip": false,
64
+ "normalized": false,
65
+ "rstrip": false,
66
+ "single_word": false,
67
+ "special": true
68
+ },
69
+ "151651": {
70
+ "content": "<|quad_end|>",
71
+ "lstrip": false,
72
+ "normalized": false,
73
+ "rstrip": false,
74
+ "single_word": false,
75
+ "special": true
76
+ },
77
+ "151652": {
78
+ "content": "<|vision_start|>",
79
+ "lstrip": false,
80
+ "normalized": false,
81
+ "rstrip": false,
82
+ "single_word": false,
83
+ "special": true
84
+ },
85
+ "151653": {
86
+ "content": "<|vision_end|>",
87
+ "lstrip": false,
88
+ "normalized": false,
89
+ "rstrip": false,
90
+ "single_word": false,
91
+ "special": true
92
+ },
93
+ "151654": {
94
+ "content": "<|vision_pad|>",
95
+ "lstrip": false,
96
+ "normalized": false,
97
+ "rstrip": false,
98
+ "single_word": false,
99
+ "special": true
100
+ },
101
+ "151655": {
102
+ "content": "<|image_pad|>",
103
+ "lstrip": false,
104
+ "normalized": false,
105
+ "rstrip": false,
106
+ "single_word": false,
107
+ "special": true
108
+ },
109
+ "151656": {
110
+ "content": "<|video_pad|>",
111
+ "lstrip": false,
112
+ "normalized": false,
113
+ "rstrip": false,
114
+ "single_word": false,
115
+ "special": true
116
+ },
117
+ "151657": {
118
+ "content": "<tool_call>",
119
+ "lstrip": false,
120
+ "normalized": false,
121
+ "rstrip": false,
122
+ "single_word": false,
123
+ "special": false
124
+ },
125
+ "151658": {
126
+ "content": "</tool_call>",
127
+ "lstrip": false,
128
+ "normalized": false,
129
+ "rstrip": false,
130
+ "single_word": false,
131
+ "special": false
132
+ },
133
+ "151659": {
134
+ "content": "<|fim_prefix|>",
135
+ "lstrip": false,
136
+ "normalized": false,
137
+ "rstrip": false,
138
+ "single_word": false,
139
+ "special": false
140
+ },
141
+ "151660": {
142
+ "content": "<|fim_middle|>",
143
+ "lstrip": false,
144
+ "normalized": false,
145
+ "rstrip": false,
146
+ "single_word": false,
147
+ "special": false
148
+ },
149
+ "151661": {
150
+ "content": "<|fim_suffix|>",
151
+ "lstrip": false,
152
+ "normalized": false,
153
+ "rstrip": false,
154
+ "single_word": false,
155
+ "special": false
156
+ },
157
+ "151662": {
158
+ "content": "<|fim_pad|>",
159
+ "lstrip": false,
160
+ "normalized": false,
161
+ "rstrip": false,
162
+ "single_word": false,
163
+ "special": false
164
+ },
165
+ "151663": {
166
+ "content": "<|repo_name|>",
167
+ "lstrip": false,
168
+ "normalized": false,
169
+ "rstrip": false,
170
+ "single_word": false,
171
+ "special": false
172
+ },
173
+ "151664": {
174
+ "content": "<|file_sep|>",
175
+ "lstrip": false,
176
+ "normalized": false,
177
+ "rstrip": false,
178
+ "single_word": false,
179
+ "special": false
180
+ },
181
+ "151665": {
182
+ "content": "[PAD]",
183
+ "lstrip": false,
184
+ "normalized": false,
185
+ "rstrip": false,
186
+ "single_word": false,
187
+ "special": true
188
+ },
189
+ "151666": {
190
+ "content": "<|image_area|>",
191
+ "lstrip": false,
192
+ "normalized": false,
193
+ "rstrip": false,
194
+ "single_word": false,
195
+ "special": true
196
+ },
197
+ "151667": {
198
+ "content": "<|begin_of_image|>",
199
+ "lstrip": false,
200
+ "normalized": false,
201
+ "rstrip": false,
202
+ "single_word": false,
203
+ "special": true
204
+ },
205
+ "151668": {
206
+ "content": "<|end_of_image|>",
207
+ "lstrip": false,
208
+ "normalized": false,
209
+ "rstrip": false,
210
+ "single_word": false,
211
+ "special": true
212
+ },
213
+ "151669": {
214
+ "content": "<|image_placeholder|>",
215
+ "lstrip": false,
216
+ "normalized": false,
217
+ "rstrip": false,
218
+ "single_word": false,
219
+ "special": true
220
+ },
221
+ "151670": {
222
+ "content": "<|begin_of_prompt_refinement|>",
223
+ "lstrip": false,
224
+ "normalized": false,
225
+ "rstrip": false,
226
+ "single_word": false,
227
+ "special": true
228
+ },
229
+ "151671": {
230
+ "content": "<|end_of_prompt_refinement|>",
231
+ "lstrip": false,
232
+ "normalized": false,
233
+ "rstrip": false,
234
+ "single_word": false,
235
+ "special": true
236
+ },
237
+ "151672": {
238
+ "content": "<|begin_of_thinking|>",
239
+ "lstrip": false,
240
+ "normalized": false,
241
+ "rstrip": false,
242
+ "single_word": false,
243
+ "special": true
244
+ },
245
+ "151673": {
246
+ "content": "<|end_of_thinking|>",
247
+ "lstrip": false,
248
+ "normalized": false,
249
+ "rstrip": false,
250
+ "single_word": false,
251
+ "special": true
252
+ },
253
+ "151674": {
254
+ "content": "<|beginoftext|>",
255
+ "lstrip": false,
256
+ "normalized": false,
257
+ "rstrip": false,
258
+ "single_word": false,
259
+ "special": true
260
+ }
261
+ },
262
+ "additional_special_tokens": [
263
+ "<|image_area|>",
264
+ "<|begin_of_image|>",
265
+ "<|end_of_image|>",
266
+ "<|image_placeholder|>",
267
+ "<|begin_of_prompt_refinement|>",
268
+ "<|end_of_prompt_refinement|>",
269
+ "<|begin_of_thinking|>",
270
+ "<|end_of_thinking|>",
271
+ "<|beginoftext|>"
272
+ ],
273
+ "bos_token": null,
274
+ "chat_template": "{%- if tools %}\n {{- '<|im_start|>system\\n' }}\n {%- if messages[0]['role'] == 'system' %}\n {{- messages[0]['content'] }}\n {%- else %}\n {{- 'You are a helpful assistant.' }}\n {%- endif %}\n {{- \"\\n\\n# Tools\\n\\nYou may call one or more functions to assist with the user query.\\n\\nYou are provided with function signatures within <tools></tools> XML tags:\\n<tools>\" }}\n {%- for tool in tools %}\n {{- \"\\n\" }}\n {{- tool | tojson }}\n {%- endfor %}\n {{- \"\\n</tools>\\n\\nFor each function call, return a json object with function name and arguments within <tool_call></tool_call> XML tags:\\n<tool_call>\\n{\\\"name\\\": <function-name>, \\\"arguments\\\": <args-json-object>}\\n</tool_call><|im_end|>\\n\" }}\n{%- else %}\n {%- if messages[0]['role'] == 'system' %}\n {{- '<|im_start|>system\\n' + messages[0]['content'] + '<|im_end|>\\n' }}\n {%- else %}\n {{- '<|im_start|>system\\nYou are a helpful assistant.<|im_end|>\\n' }}\n {%- endif %}\n{%- endif %}\n{%- for message in messages %}\n {%- if (message.role == \"user\") or (message.role == \"system\" and not loop.first) or (message.role == \"assistant\" and not message.tool_calls) %}\n {{- '<|im_start|>' + message.role + '\\n' + message.content + '<|im_end|>' + '\\n' }}\n {%- elif message.role == \"assistant\" %}\n {{- '<|im_start|>' + message.role }}\n {%- if message.content %}\n {{- '\\n' + message.content }}\n {%- endif %}\n {%- for tool_call in message.tool_calls %}\n {%- if tool_call.function is defined %}\n {%- set tool_call = tool_call.function %}\n {%- endif %}\n {{- '\\n<tool_call>\\n{\"name\": \"' }}\n {{- tool_call.name }}\n {{- '\", \"arguments\": ' }}\n {{- tool_call.arguments | tojson }}\n {{- '}\\n</tool_call>' }}\n {%- endfor %}\n {{- '<|im_end|>\\n' }}\n {%- elif message.role == \"tool\" %}\n {%- if (loop.index0 == 0) or (messages[loop.index0 - 1].role != \"tool\") %}\n {{- '<|im_start|>user' }}\n {%- endif %}\n {{- '\\n<tool_response>\\n' }}\n {{- message.content }}\n {{- '\\n</tool_response>' }}\n {%- if loop.last or (messages[loop.index0 + 1].role != \"tool\") %}\n {{- '<|im_end|>\\n' }}\n {%- endif %}\n {%- endif %}\n{%- endfor %}\n{%- if add_generation_prompt %}\n {{- '<|im_start|>assistant\\n' }}\n{%- endif %}\n",
275
+ "clean_up_tokenization_spaces": false,
276
+ "eos_token": "<|endoftext|>",
277
+ "errors": "replace",
278
+ "extra_special_tokens": {},
279
+ "model_max_length": 8192,
280
+ "pad_token": "[PAD]",
281
+ "padding_side": "right",
282
+ "split_special_tokens": false,
283
+ "tokenizer_class": "Qwen2Tokenizer",
284
+ "unk_token": null
285
+ }
vae/checkpoint.pt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:99293255229a29297e2851858db3794497d1b0b09b20c308c1062636ea4bcdd9
3
+ size 335365010
vocab.json ADDED
The diff for this file is too large to render. See raw diff