BiliSakura commited on
Commit
fbad450
·
verified ·
1 Parent(s): 57c8209

Upload folder using huggingface_hub

Browse files
Files changed (42) hide show
  1. .gitattributes +4 -0
  2. PixelDiT-T2I-1024/__pycache__/pipeline.cpython-312.pyc +0 -0
  3. PixelDiT-T2I-1024/demo.png +3 -0
  4. PixelDiT-T2I-1024/model_index.json +23 -0
  5. PixelDiT-T2I-1024/pipeline.py +401 -0
  6. PixelDiT-T2I-1024/scheduler/__pycache__/flow_dpm.cpython-312.pyc +0 -0
  7. PixelDiT-T2I-1024/scheduler/__pycache__/scheduling_pixeldit_flow_dpm.cpython-312.pyc +0 -0
  8. PixelDiT-T2I-1024/scheduler/scheduler_config.json +7 -0
  9. PixelDiT-T2I-1024/text_encoder/config.json +36 -0
  10. PixelDiT-T2I-1024/text_encoder/configuration.json +1 -0
  11. PixelDiT-T2I-1024/text_encoder/generation_config.json +11 -0
  12. PixelDiT-T2I-1024/text_encoder/model-00001-of-00002.safetensors +3 -0
  13. PixelDiT-T2I-1024/text_encoder/model-00002-of-00002.safetensors +3 -0
  14. PixelDiT-T2I-1024/text_encoder/model.safetensors.index.json +295 -0
  15. PixelDiT-T2I-1024/tokenizer/special_tokens_map.json +34 -0
  16. PixelDiT-T2I-1024/tokenizer/tokenizer.json +3 -0
  17. PixelDiT-T2I-1024/tokenizer/tokenizer.model +3 -0
  18. PixelDiT-T2I-1024/tokenizer/tokenizer_config.json +2013 -0
  19. PixelDiT-T2I-1024/transformer/__pycache__/transformer_pixeldit.cpython-312.pyc +0 -0
  20. PixelDiT-T2I-1024/transformer/__pycache__/transformer_pixeldit_t2i.cpython-312.pyc +0 -0
  21. PixelDiT-T2I-1024/transformer/config.json +21 -0
  22. PixelDiT-T2I-1024/transformer/diffusion_pytorch_model.safetensors +3 -0
  23. PixelDiT-T2I-1024/transformer/transformer_pixeldit.py +639 -0
  24. PixelDiT-T2I-1024/transformer/transformer_pixeldit_t2i.py +537 -0
  25. PixelDiT-XL-16-256/demo.png +3 -0
  26. PixelDiT-XL-16-256/model_index.json +1017 -0
  27. PixelDiT-XL-16-256/pipeline.py +286 -0
  28. PixelDiT-XL-16-256/scheduler/config.json +7 -0
  29. PixelDiT-XL-16-256/scheduler/scheduler_config.json +7 -0
  30. PixelDiT-XL-16-256/transformer/config.json +14 -0
  31. PixelDiT-XL-16-256/transformer/diffusion_pytorch_model.safetensors +3 -0
  32. PixelDiT-XL-16-256/transformer/transformer_pixeldit.py +639 -0
  33. PixelDiT-XL-16-512/demo.png +3 -0
  34. PixelDiT-XL-16-512/model_index.json +1017 -0
  35. PixelDiT-XL-16-512/pipeline.py +286 -0
  36. PixelDiT-XL-16-512/scheduler/scheduler_config.json +7 -0
  37. PixelDiT-XL-16-512/transformer/config.json +14 -0
  38. PixelDiT-XL-16-512/transformer/diffusion_pytorch_model.safetensors +3 -0
  39. PixelDiT-XL-16-512/transformer/transformer_pixeldit.py +639 -0
  40. README.md +241 -0
  41. demo_inference.py +95 -0
  42. demo_inference_t2i.py +73 -0
.gitattributes CHANGED
@@ -33,3 +33,7 @@ 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
+ PixelDiT-T2I-1024/demo.png filter=lfs diff=lfs merge=lfs -text
37
+ PixelDiT-T2I-1024/tokenizer/tokenizer.json filter=lfs diff=lfs merge=lfs -text
38
+ PixelDiT-XL-16-256/demo.png filter=lfs diff=lfs merge=lfs -text
39
+ PixelDiT-XL-16-512/demo.png filter=lfs diff=lfs merge=lfs -text
PixelDiT-T2I-1024/__pycache__/pipeline.cpython-312.pyc ADDED
Binary file (18.2 kB). View file
 
PixelDiT-T2I-1024/demo.png ADDED

Git LFS Details

  • SHA256: 465a5bec6ddb064e228c04d311bf825da0488c6df13c21b13be31a2159ca9a94
  • Pointer size: 132 Bytes
  • Size of remote file: 1.78 MB
PixelDiT-T2I-1024/model_index.json ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "_class_name": [
3
+ "pipeline",
4
+ "PixelDiTT2IPipeline"
5
+ ],
6
+ "_diffusers_version": "0.35.1",
7
+ "scheduler": [
8
+ "diffusers",
9
+ "FlowMatchEulerDiscreteScheduler"
10
+ ],
11
+ "transformer": [
12
+ "transformer_pixeldit_t2i",
13
+ "PixelDiTT2ITransformer2DModel"
14
+ ],
15
+ "text_encoder": [
16
+ "transformers",
17
+ "Gemma2Model"
18
+ ],
19
+ "tokenizer": [
20
+ "transformers",
21
+ "GemmaTokenizerFast"
22
+ ]
23
+ }
PixelDiT-T2I-1024/pipeline.py ADDED
@@ -0,0 +1,401 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright 2026 The HuggingFace Team. All rights reserved.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ from __future__ import annotations
16
+
17
+ import os
18
+ import sys
19
+ from pathlib import Path
20
+ from typing import List, Optional, Tuple, Union
21
+
22
+ import torch
23
+ from diffusers.pipelines.pipeline_utils import DiffusionPipeline, ImagePipelineOutput
24
+ from diffusers.schedulers import FlowMatchEulerDiscreteScheduler
25
+ from diffusers.utils.torch_utils import randn_tensor
26
+ from transformers import AutoModelForCausalLM, AutoTokenizer
27
+
28
+ import importlib.util
29
+
30
+ def _load_flow_dpm_solver():
31
+ diffusers_src = os.environ.get("PIXELDIT_DIFFUSERS_SRC")
32
+ if diffusers_src:
33
+ diffusers_src = str(Path(diffusers_src).resolve())
34
+ if diffusers_src not in sys.path:
35
+ sys.path.insert(0, diffusers_src)
36
+ else:
37
+ for parent in Path(__file__).resolve().parents:
38
+ candidate_root = parent / "libs/diffusers/src"
39
+ if (candidate_root / "diffusers/schedulers/flow_dpm.py").is_file():
40
+ if str(candidate_root) not in sys.path:
41
+ sys.path.insert(0, str(candidate_root))
42
+ break
43
+
44
+ from diffusers.schedulers.flow_dpm import create_flow_dpm_solver
45
+
46
+ return create_flow_dpm_solver
47
+
48
+
49
+ DEFAULT_TEXT_ENCODER_REPO = "google/gemma-2-2b-it"
50
+ DEFAULT_NEGATIVE_PROMPT = "low quality, worst quality, over-saturated, blurry, deformed, watermark"
51
+ DEFAULT_CHI_PROMPT = "\n".join(
52
+ [
53
+ 'Given a user prompt, generate an "Enhanced prompt" that provides detailed visual descriptions suitable for image generation. Evaluate the level of detail in the user prompt:',
54
+ "- If the prompt is simple, focus on adding specifics about colors, shapes, sizes, textures, and spatial relationships to create vivid and concrete scenes.",
55
+ "- If the prompt is already detailed, refine and enhance the existing details slightly without overcomplicating.",
56
+ "Here are examples of how to transform or refine prompts:",
57
+ "- User Prompt: A cat sleeping -> Enhanced: A small, fluffy white cat curled up in a round shape, sleeping peacefully on a warm sunny windowsill, surrounded by pots of blooming red flowers.",
58
+ "- User Prompt: A busy city street -> Enhanced: A bustling city street scene at dusk, featuring glowing street lamps, a diverse crowd of people in colorful clothing, and a double-decker bus passing by towering glass skyscrapers.",
59
+ "Please generate only the enhanced description for the prompt below and avoid including any additional commentary or evaluations:",
60
+ "User Prompt: ",
61
+ ]
62
+ )
63
+
64
+
65
+ def _default_t2i_scheduler(**kwargs) -> FlowMatchEulerDiscreteScheduler:
66
+ defaults = {
67
+ "num_train_timesteps": 1000,
68
+ "shift": 4.0,
69
+ "stochastic_sampling": False,
70
+ }
71
+ defaults.update(kwargs)
72
+ return FlowMatchEulerDiscreteScheduler(**defaults)
73
+
74
+
75
+ class PixelDiTT2IPipeline(DiffusionPipeline):
76
+ r"""
77
+ Pipeline for text-to-image generation using PixelDiT (Pixel Diffusion Transformer).
78
+
79
+ Parameters:
80
+ transformer ([`PixelDiTT2ITransformer2DModel`]):
81
+ Text-conditioned PixelDiT transformer that predicts flow-matching velocity in pixel space.
82
+ scheduler ([`FlowMatchEulerDiscreteScheduler`]):
83
+ Configures flow shift for PixelDiT T2I flow DPM sampling.
84
+ text_encoder (`transformers.PreTrainedModel`, *optional*):
85
+ Gemma decoder used to embed prompts.
86
+ tokenizer (`transformers.PreTrainedTokenizer`, *optional*):
87
+ Tokenizer paired with the text encoder.
88
+ """
89
+
90
+ model_cpu_offload_seq = "text_encoder->transformer"
91
+ _optional_components = ["text_encoder", "tokenizer"]
92
+
93
+ def __init__(
94
+ self,
95
+ transformer,
96
+ scheduler: FlowMatchEulerDiscreteScheduler,
97
+ text_encoder=None,
98
+ tokenizer=None,
99
+ model_max_length: int = 300,
100
+ default_negative_prompt: str = DEFAULT_NEGATIVE_PROMPT,
101
+ ):
102
+ super().__init__()
103
+ scheduler = scheduler or _default_t2i_scheduler()
104
+ self.register_modules(
105
+ transformer=transformer,
106
+ scheduler=scheduler,
107
+ text_encoder=text_encoder,
108
+ tokenizer=tokenizer,
109
+ )
110
+ self.model_max_length = int(model_max_length)
111
+ self.default_negative_prompt = default_negative_prompt
112
+
113
+ def _load_text_stack(
114
+ self,
115
+ base_path: Path,
116
+ text_encoder_subfolder: Optional[str],
117
+ tokenizer_subfolder: Optional[str],
118
+ text_encoder_repo: str,
119
+ model_kwargs: dict,
120
+ ) -> None:
121
+ if self.text_encoder is not None and self.tokenizer is not None:
122
+ return
123
+
124
+ text_encoder = self.text_encoder
125
+ tokenizer = self.tokenizer
126
+ if text_encoder_subfolder is not None and text_encoder is None:
127
+ text_encoder = AutoModelForCausalLM.from_pretrained(
128
+ str(base_path / text_encoder_subfolder), **model_kwargs
129
+ ).get_decoder()
130
+ if tokenizer_subfolder is not None and tokenizer is None:
131
+ tokenizer = AutoTokenizer.from_pretrained(str(base_path / tokenizer_subfolder))
132
+ tokenizer.padding_side = "right"
133
+
134
+ if text_encoder is None or tokenizer is None:
135
+ tokenizer = tokenizer or AutoTokenizer.from_pretrained(text_encoder_repo)
136
+ tokenizer.padding_side = "right"
137
+ text_encoder = text_encoder or AutoModelForCausalLM.from_pretrained(
138
+ text_encoder_repo, **model_kwargs
139
+ ).get_decoder()
140
+
141
+ self.register_modules(text_encoder=text_encoder, tokenizer=tokenizer)
142
+
143
+ @classmethod
144
+ def from_pretrained(cls, pretrained_model_name_or_path: str, **kwargs):
145
+ model_kwargs = dict(kwargs)
146
+ transformer_subfolder = model_kwargs.pop("transformer_subfolder", None)
147
+ scheduler_subfolder = model_kwargs.pop("scheduler_subfolder", None)
148
+ text_encoder_subfolder = model_kwargs.pop("text_encoder_subfolder", None)
149
+ tokenizer_subfolder = model_kwargs.pop("tokenizer_subfolder", None)
150
+ scheduler_kwargs = model_kwargs.pop("scheduler_kwargs", {})
151
+ text_encoder_repo = model_kwargs.pop("text_encoder_repo", DEFAULT_TEXT_ENCODER_REPO)
152
+ base_path = Path(pretrained_model_name_or_path)
153
+
154
+ if transformer_subfolder is None and (base_path / "transformer").exists():
155
+ transformer_subfolder = "transformer"
156
+ if scheduler_subfolder is None and (base_path / "scheduler").exists():
157
+ scheduler_subfolder = "scheduler"
158
+ if text_encoder_subfolder is None and (base_path / "text_encoder").exists():
159
+ text_encoder_subfolder = "text_encoder"
160
+ if tokenizer_subfolder is None and (base_path / "tokenizer").exists():
161
+ tokenizer_subfolder = "tokenizer"
162
+
163
+ try:
164
+ pipe = super().from_pretrained(pretrained_model_name_or_path, **kwargs)
165
+ except Exception:
166
+ if transformer_subfolder is not None:
167
+ transformer_path = str(base_path / transformer_subfolder)
168
+ else:
169
+ transformer_path = pretrained_model_name_or_path
170
+
171
+ transformer_module_path = Path(transformer_path) / 'transformer_pixeldit_t2i.py'
172
+ spec = importlib.util.spec_from_file_location('transformer_pixeldit_t2i', transformer_module_path)
173
+ module = importlib.util.module_from_spec(spec)
174
+ spec.loader.exec_module(module)
175
+ transformer = module.PixelDiTT2ITransformer2DModel.from_pretrained(transformer_path, **model_kwargs)
176
+ try:
177
+ scheduler = FlowMatchEulerDiscreteScheduler.from_pretrained(
178
+ pretrained_model_name_or_path,
179
+ subfolder=scheduler_subfolder,
180
+ **scheduler_kwargs,
181
+ )
182
+ except Exception:
183
+ scheduler = _default_t2i_scheduler(**scheduler_kwargs)
184
+ pipe = cls(transformer=transformer, scheduler=scheduler)
185
+
186
+ pipe._load_text_stack(
187
+ base_path=base_path,
188
+ text_encoder_subfolder=text_encoder_subfolder,
189
+ tokenizer_subfolder=tokenizer_subfolder,
190
+ text_encoder_repo=text_encoder_repo,
191
+ model_kwargs=model_kwargs,
192
+ )
193
+ return pipe
194
+
195
+ @property
196
+ def _select_index(self) -> List[int]:
197
+ return [0] + list(range(-self.model_max_length + 1, 0))
198
+
199
+ def _ensure_text_stack_loaded(self) -> None:
200
+ if self.text_encoder is not None and self.tokenizer is not None:
201
+ return
202
+ variant_path = getattr(self.config, "_name_or_path", None)
203
+ base_path = Path(variant_path) if variant_path else Path(".")
204
+ text_encoder_subfolder = "text_encoder" if (base_path / "text_encoder").exists() else None
205
+ tokenizer_subfolder = "tokenizer" if (base_path / "tokenizer").exists() else None
206
+ self._load_text_stack(
207
+ base_path=base_path,
208
+ text_encoder_subfolder=text_encoder_subfolder,
209
+ tokenizer_subfolder=tokenizer_subfolder,
210
+ text_encoder_repo=DEFAULT_TEXT_ENCODER_REPO,
211
+ model_kwargs={"torch_dtype": self.transformer.dtype},
212
+ )
213
+
214
+ @torch.inference_mode()
215
+ def encode_prompt(
216
+ self,
217
+ prompt: Union[str, List[str]],
218
+ negative_prompt: Optional[Union[str, List[str]]] = None,
219
+ device: Optional[torch.device] = None,
220
+ dtype: Optional[torch.dtype] = None,
221
+ do_classifier_free_guidance: bool = True,
222
+ use_chi_prompt: bool = True,
223
+ ) -> Tuple[torch.Tensor, Optional[torch.Tensor]]:
224
+ self._ensure_text_stack_loaded()
225
+ if self.text_encoder is None or self.tokenizer is None:
226
+ raise ValueError("Text-to-image generation requires `text_encoder` and `tokenizer`.")
227
+
228
+ device = device or self._execution_device
229
+ dtype = dtype or self.transformer.dtype
230
+
231
+ if isinstance(prompt, str):
232
+ prompt = [prompt]
233
+ batch_size = len(prompt)
234
+
235
+ if use_chi_prompt and DEFAULT_CHI_PROMPT:
236
+ prompts_all = [DEFAULT_CHI_PROMPT + item for item in prompt]
237
+ chi_prompt_tokens = len(self.tokenizer.encode(DEFAULT_CHI_PROMPT))
238
+ max_length_all = chi_prompt_tokens + self.model_max_length - 2
239
+ else:
240
+ prompts_all = prompt
241
+ max_length_all = self.model_max_length
242
+
243
+ tokenized = self.tokenizer(
244
+ prompts_all,
245
+ max_length=max_length_all,
246
+ padding="max_length",
247
+ truncation=True,
248
+ return_tensors="pt",
249
+ )
250
+ input_ids = tokenized.input_ids.to(device)
251
+ attention_mask = tokenized.attention_mask.to(device)
252
+ prompt_embeds = self.text_encoder(input_ids, attention_mask=attention_mask)[0]
253
+ select_index = self._select_index
254
+ prompt_embeds = prompt_embeds[:, select_index]
255
+ prompt_attention_mask = attention_mask[:, select_index]
256
+ prompt_embeds = prompt_embeds.to(dtype=dtype)
257
+
258
+ if not do_classifier_free_guidance:
259
+ return prompt_embeds, prompt_attention_mask
260
+
261
+ if negative_prompt is None:
262
+ negative_prompt = self.default_negative_prompt
263
+ if isinstance(negative_prompt, str):
264
+ negative_prompt = [negative_prompt] * batch_size
265
+
266
+ null_tokenized = self.tokenizer(
267
+ negative_prompt,
268
+ max_length=self.model_max_length,
269
+ padding="max_length",
270
+ truncation=True,
271
+ return_tensors="pt",
272
+ )
273
+ null_input_ids = null_tokenized.input_ids.to(device)
274
+ null_attention_mask = null_tokenized.attention_mask.to(device)
275
+ negative_embeds = self.text_encoder(null_input_ids, attention_mask=null_attention_mask)[0].to(dtype=dtype)
276
+ negative_attention_mask = null_attention_mask
277
+
278
+ prompt_embeds = torch.cat([negative_embeds, prompt_embeds], dim=0)
279
+ prompt_attention_mask = torch.cat([negative_attention_mask, prompt_attention_mask], dim=0)
280
+ return prompt_embeds, prompt_attention_mask
281
+
282
+ @staticmethod
283
+ def _resolve_flow_shift(scheduler, image_size: int) -> float:
284
+ flow_shift = getattr(scheduler.config, "flow_shift", None)
285
+ if flow_shift is not None:
286
+ return float(flow_shift)
287
+ shift = getattr(scheduler.config, "shift", None)
288
+ if shift is not None:
289
+ return float(shift)
290
+ return 4.0 if image_size >= 1024 else 1.0
291
+
292
+ def _make_dpm_transformer_fn(self):
293
+ transformer = self.transformer
294
+
295
+ def forward(x, t_input, y, **model_kwargs):
296
+ if y.dim() == 4:
297
+ y = y.squeeze(1)
298
+ return transformer(
299
+ x,
300
+ timestep=t_input.to(dtype=transformer.dtype),
301
+ encoder_hidden_states=y.to(dtype=transformer.dtype),
302
+ encoder_attention_mask=None,
303
+ ).sample
304
+
305
+ return forward
306
+
307
+ @torch.inference_mode()
308
+ def __call__(
309
+ self,
310
+ prompt: Union[str, List[str]],
311
+ negative_prompt: Optional[Union[str, List[str]]] = None,
312
+ guidance_scale: Optional[float] = None,
313
+ guidance_interval_min: float = 0.0,
314
+ guidance_interval_max: float = 1.0,
315
+ use_chi_prompt: bool = True,
316
+ generator: Optional[Union[torch.Generator, List[torch.Generator]]] = None,
317
+ num_inference_steps: int = 50,
318
+ height: Optional[int] = None,
319
+ width: Optional[int] = None,
320
+ output_type: Optional[str] = "pil",
321
+ return_dict: bool = True,
322
+ ) -> Union[ImagePipelineOutput, Tuple]:
323
+ if num_inference_steps < 1:
324
+ raise ValueError("num_inference_steps must be >= 1.")
325
+ if output_type not in {"pil", "np", "pt"}:
326
+ raise ValueError("output_type must be one of: 'pil', 'np', 'pt'.")
327
+
328
+ if isinstance(prompt, str):
329
+ prompt = [prompt]
330
+ batch_size = len(prompt)
331
+
332
+ image_size = int(getattr(self.transformer.config, "sample_size", 1024))
333
+ patch_size = int(self.transformer.config.patch_size)
334
+ height = int(height or image_size)
335
+ width = int(width or image_size)
336
+ if height <= 0 or width <= 0:
337
+ raise ValueError("height and width must be positive integers.")
338
+ if height % patch_size != 0 or width % patch_size != 0:
339
+ raise ValueError(
340
+ f"height and width must be divisible by patch_size={patch_size}. Got {(height, width)}."
341
+ )
342
+ channels = int(self.transformer.config.in_channels)
343
+
344
+ if guidance_scale is None:
345
+ guidance_scale = 2.75
346
+
347
+ prompt_embeds, _ = self.encode_prompt(
348
+ prompt,
349
+ negative_prompt=negative_prompt,
350
+ do_classifier_free_guidance=True,
351
+ use_chi_prompt=use_chi_prompt,
352
+ )
353
+
354
+ latents = randn_tensor(
355
+ shape=(batch_size, channels, height, width),
356
+ generator=generator,
357
+ device=self._execution_device,
358
+ dtype=self.transformer.dtype,
359
+ )
360
+
361
+ flow_shift = self._resolve_flow_shift(self.scheduler, image_size)
362
+ solver_order = 2
363
+ skip_type = "time_uniform_flow"
364
+ method = "multistep"
365
+ condition = prompt_embeds[batch_size:].unsqueeze(1)
366
+ uncondition = prompt_embeds[:batch_size].unsqueeze(1)
367
+ create_flow_dpm_solver = _load_flow_dpm_solver()
368
+ dpm_solver = create_flow_dpm_solver(
369
+ self._make_dpm_transformer_fn(),
370
+ condition=condition,
371
+ uncondition=uncondition,
372
+ cfg_scale=float(guidance_scale),
373
+ model_kwargs={},
374
+ interval_guidance=[guidance_interval_min, guidance_interval_max],
375
+ )
376
+ os.environ["DPM_TQDM"] = "True"
377
+ latents = dpm_solver.sample(
378
+ latents,
379
+ steps=num_inference_steps,
380
+ order=solver_order,
381
+ skip_type=skip_type,
382
+ method=method,
383
+ flow_shift=flow_shift,
384
+ )
385
+
386
+ images_pt = ((latents.float().clamp(-1, 1) + 1.0) / 2.0).cpu()
387
+ if output_type == "pt":
388
+ images = images_pt
389
+ elif output_type == "np":
390
+ images = images_pt.permute(0, 2, 3, 1).numpy()
391
+ else:
392
+ images = self.numpy_to_pil(images_pt.permute(0, 2, 3, 1).numpy())
393
+
394
+ self.maybe_free_model_hooks()
395
+
396
+ if not return_dict:
397
+ return (images,)
398
+ return ImagePipelineOutput(images=images)
399
+
400
+
401
+ PixelDiTT2IPipelineOutput = ImagePipelineOutput
PixelDiT-T2I-1024/scheduler/__pycache__/flow_dpm.cpython-312.pyc ADDED
Binary file (1.2 kB). View file
 
PixelDiT-T2I-1024/scheduler/__pycache__/scheduling_pixeldit_flow_dpm.cpython-312.pyc ADDED
Binary file (81.1 kB). View file
 
PixelDiT-T2I-1024/scheduler/scheduler_config.json ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ {
2
+ "_class_name": "FlowMatchEulerDiscreteScheduler",
3
+ "_diffusers_version": "0.36.0",
4
+ "num_train_timesteps": 1000,
5
+ "shift": 4.0,
6
+ "stochastic_sampling": false
7
+ }
PixelDiT-T2I-1024/text_encoder/config.json ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "_name_or_path": "google/gemma-2-2b-it",
3
+ "architectures": [
4
+ "Gemma2ForCausalLM"
5
+ ],
6
+ "attention_bias": false,
7
+ "attention_dropout": 0.0,
8
+ "attn_logit_softcapping": 50.0,
9
+ "bos_token_id": 2,
10
+ "cache_implementation": "hybrid",
11
+ "eos_token_id": [
12
+ 1,
13
+ 107
14
+ ],
15
+ "final_logit_softcapping": 30.0,
16
+ "head_dim": 256,
17
+ "hidden_act": "gelu_pytorch_tanh",
18
+ "hidden_activation": "gelu_pytorch_tanh",
19
+ "hidden_size": 2304,
20
+ "initializer_range": 0.02,
21
+ "intermediate_size": 9216,
22
+ "max_position_embeddings": 8192,
23
+ "model_type": "gemma2",
24
+ "num_attention_heads": 8,
25
+ "num_hidden_layers": 26,
26
+ "num_key_value_heads": 4,
27
+ "pad_token_id": 0,
28
+ "query_pre_attn_scalar": 256,
29
+ "rms_norm_eps": 1e-06,
30
+ "rope_theta": 10000.0,
31
+ "sliding_window": 4096,
32
+ "torch_dtype": "bfloat16",
33
+ "transformers_version": "4.46.0",
34
+ "use_cache": true,
35
+ "vocab_size": 256000
36
+ }
PixelDiT-T2I-1024/text_encoder/configuration.json ADDED
@@ -0,0 +1 @@
 
 
1
+ {"framework": "pytorch", "task": "text-generation", "allow_remote": true}
PixelDiT-T2I-1024/text_encoder/generation_config.json ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "_from_model_config": true,
3
+ "bos_token_id": 2,
4
+ "cache_implementation": "hybrid",
5
+ "eos_token_id": [
6
+ 1,
7
+ 107
8
+ ],
9
+ "pad_token_id": 0,
10
+ "transformers_version": "4.46.0"
11
+ }
PixelDiT-T2I-1024/text_encoder/model-00001-of-00002.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:532d792c9178805064170a3ec485b7dedbfccc6fd297b92c31a6091b6c7e41bf
3
+ size 4988025760
PixelDiT-T2I-1024/text_encoder/model-00002-of-00002.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:6d6d9ce84db398fb6e0191f91542e5da0a73da2cb695e172a24edc2146dc8d20
3
+ size 240691728
PixelDiT-T2I-1024/text_encoder/model.safetensors.index.json ADDED
@@ -0,0 +1,295 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "metadata": {
3
+ "total_size": 5228683776
4
+ },
5
+ "weight_map": {
6
+ "model.embed_tokens.weight": "model-00001-of-00002.safetensors",
7
+ "model.layers.0.input_layernorm.weight": "model-00001-of-00002.safetensors",
8
+ "model.layers.0.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
9
+ "model.layers.0.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
10
+ "model.layers.0.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
11
+ "model.layers.0.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
12
+ "model.layers.0.post_feedforward_layernorm.weight": "model-00001-of-00002.safetensors",
13
+ "model.layers.0.pre_feedforward_layernorm.weight": "model-00001-of-00002.safetensors",
14
+ "model.layers.0.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
15
+ "model.layers.0.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
16
+ "model.layers.0.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
17
+ "model.layers.0.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
18
+ "model.layers.1.input_layernorm.weight": "model-00001-of-00002.safetensors",
19
+ "model.layers.1.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
20
+ "model.layers.1.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
21
+ "model.layers.1.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
22
+ "model.layers.1.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
23
+ "model.layers.1.post_feedforward_layernorm.weight": "model-00001-of-00002.safetensors",
24
+ "model.layers.1.pre_feedforward_layernorm.weight": "model-00001-of-00002.safetensors",
25
+ "model.layers.1.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
26
+ "model.layers.1.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
27
+ "model.layers.1.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
28
+ "model.layers.1.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
29
+ "model.layers.10.input_layernorm.weight": "model-00001-of-00002.safetensors",
30
+ "model.layers.10.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
31
+ "model.layers.10.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
32
+ "model.layers.10.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
33
+ "model.layers.10.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
34
+ "model.layers.10.post_feedforward_layernorm.weight": "model-00001-of-00002.safetensors",
35
+ "model.layers.10.pre_feedforward_layernorm.weight": "model-00001-of-00002.safetensors",
36
+ "model.layers.10.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
37
+ "model.layers.10.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
38
+ "model.layers.10.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
39
+ "model.layers.10.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
40
+ "model.layers.11.input_layernorm.weight": "model-00001-of-00002.safetensors",
41
+ "model.layers.11.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
42
+ "model.layers.11.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
43
+ "model.layers.11.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
44
+ "model.layers.11.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
45
+ "model.layers.11.post_feedforward_layernorm.weight": "model-00001-of-00002.safetensors",
46
+ "model.layers.11.pre_feedforward_layernorm.weight": "model-00001-of-00002.safetensors",
47
+ "model.layers.11.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
48
+ "model.layers.11.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
49
+ "model.layers.11.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
50
+ "model.layers.11.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
51
+ "model.layers.12.input_layernorm.weight": "model-00001-of-00002.safetensors",
52
+ "model.layers.12.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
53
+ "model.layers.12.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
54
+ "model.layers.12.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
55
+ "model.layers.12.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
56
+ "model.layers.12.post_feedforward_layernorm.weight": "model-00001-of-00002.safetensors",
57
+ "model.layers.12.pre_feedforward_layernorm.weight": "model-00001-of-00002.safetensors",
58
+ "model.layers.12.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
59
+ "model.layers.12.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
60
+ "model.layers.12.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
61
+ "model.layers.12.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
62
+ "model.layers.13.input_layernorm.weight": "model-00001-of-00002.safetensors",
63
+ "model.layers.13.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
64
+ "model.layers.13.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
65
+ "model.layers.13.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
66
+ "model.layers.13.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
67
+ "model.layers.13.post_feedforward_layernorm.weight": "model-00001-of-00002.safetensors",
68
+ "model.layers.13.pre_feedforward_layernorm.weight": "model-00001-of-00002.safetensors",
69
+ "model.layers.13.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
70
+ "model.layers.13.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
71
+ "model.layers.13.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
72
+ "model.layers.13.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
73
+ "model.layers.14.input_layernorm.weight": "model-00001-of-00002.safetensors",
74
+ "model.layers.14.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
75
+ "model.layers.14.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
76
+ "model.layers.14.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
77
+ "model.layers.14.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
78
+ "model.layers.14.post_feedforward_layernorm.weight": "model-00001-of-00002.safetensors",
79
+ "model.layers.14.pre_feedforward_layernorm.weight": "model-00001-of-00002.safetensors",
80
+ "model.layers.14.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
81
+ "model.layers.14.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
82
+ "model.layers.14.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
83
+ "model.layers.14.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
84
+ "model.layers.15.input_layernorm.weight": "model-00001-of-00002.safetensors",
85
+ "model.layers.15.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
86
+ "model.layers.15.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
87
+ "model.layers.15.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
88
+ "model.layers.15.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
89
+ "model.layers.15.post_feedforward_layernorm.weight": "model-00001-of-00002.safetensors",
90
+ "model.layers.15.pre_feedforward_layernorm.weight": "model-00001-of-00002.safetensors",
91
+ "model.layers.15.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
92
+ "model.layers.15.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
93
+ "model.layers.15.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
94
+ "model.layers.15.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
95
+ "model.layers.16.input_layernorm.weight": "model-00001-of-00002.safetensors",
96
+ "model.layers.16.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
97
+ "model.layers.16.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
98
+ "model.layers.16.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
99
+ "model.layers.16.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
100
+ "model.layers.16.post_feedforward_layernorm.weight": "model-00001-of-00002.safetensors",
101
+ "model.layers.16.pre_feedforward_layernorm.weight": "model-00001-of-00002.safetensors",
102
+ "model.layers.16.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
103
+ "model.layers.16.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
104
+ "model.layers.16.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
105
+ "model.layers.16.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
106
+ "model.layers.17.input_layernorm.weight": "model-00001-of-00002.safetensors",
107
+ "model.layers.17.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
108
+ "model.layers.17.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
109
+ "model.layers.17.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
110
+ "model.layers.17.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
111
+ "model.layers.17.post_feedforward_layernorm.weight": "model-00001-of-00002.safetensors",
112
+ "model.layers.17.pre_feedforward_layernorm.weight": "model-00001-of-00002.safetensors",
113
+ "model.layers.17.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
114
+ "model.layers.17.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
115
+ "model.layers.17.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
116
+ "model.layers.17.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
117
+ "model.layers.18.input_layernorm.weight": "model-00001-of-00002.safetensors",
118
+ "model.layers.18.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
119
+ "model.layers.18.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
120
+ "model.layers.18.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
121
+ "model.layers.18.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
122
+ "model.layers.18.post_feedforward_layernorm.weight": "model-00001-of-00002.safetensors",
123
+ "model.layers.18.pre_feedforward_layernorm.weight": "model-00001-of-00002.safetensors",
124
+ "model.layers.18.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
125
+ "model.layers.18.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
126
+ "model.layers.18.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
127
+ "model.layers.18.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
128
+ "model.layers.19.input_layernorm.weight": "model-00001-of-00002.safetensors",
129
+ "model.layers.19.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
130
+ "model.layers.19.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
131
+ "model.layers.19.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
132
+ "model.layers.19.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
133
+ "model.layers.19.post_feedforward_layernorm.weight": "model-00001-of-00002.safetensors",
134
+ "model.layers.19.pre_feedforward_layernorm.weight": "model-00001-of-00002.safetensors",
135
+ "model.layers.19.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
136
+ "model.layers.19.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
137
+ "model.layers.19.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
138
+ "model.layers.19.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
139
+ "model.layers.2.input_layernorm.weight": "model-00001-of-00002.safetensors",
140
+ "model.layers.2.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
141
+ "model.layers.2.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
142
+ "model.layers.2.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
143
+ "model.layers.2.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
144
+ "model.layers.2.post_feedforward_layernorm.weight": "model-00001-of-00002.safetensors",
145
+ "model.layers.2.pre_feedforward_layernorm.weight": "model-00001-of-00002.safetensors",
146
+ "model.layers.2.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
147
+ "model.layers.2.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
148
+ "model.layers.2.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
149
+ "model.layers.2.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
150
+ "model.layers.20.input_layernorm.weight": "model-00001-of-00002.safetensors",
151
+ "model.layers.20.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
152
+ "model.layers.20.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
153
+ "model.layers.20.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
154
+ "model.layers.20.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
155
+ "model.layers.20.post_feedforward_layernorm.weight": "model-00001-of-00002.safetensors",
156
+ "model.layers.20.pre_feedforward_layernorm.weight": "model-00001-of-00002.safetensors",
157
+ "model.layers.20.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
158
+ "model.layers.20.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
159
+ "model.layers.20.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
160
+ "model.layers.20.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
161
+ "model.layers.21.input_layernorm.weight": "model-00001-of-00002.safetensors",
162
+ "model.layers.21.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
163
+ "model.layers.21.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
164
+ "model.layers.21.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
165
+ "model.layers.21.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
166
+ "model.layers.21.post_feedforward_layernorm.weight": "model-00001-of-00002.safetensors",
167
+ "model.layers.21.pre_feedforward_layernorm.weight": "model-00001-of-00002.safetensors",
168
+ "model.layers.21.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
169
+ "model.layers.21.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
170
+ "model.layers.21.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
171
+ "model.layers.21.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
172
+ "model.layers.22.input_layernorm.weight": "model-00001-of-00002.safetensors",
173
+ "model.layers.22.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
174
+ "model.layers.22.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
175
+ "model.layers.22.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
176
+ "model.layers.22.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
177
+ "model.layers.22.post_feedforward_layernorm.weight": "model-00001-of-00002.safetensors",
178
+ "model.layers.22.pre_feedforward_layernorm.weight": "model-00001-of-00002.safetensors",
179
+ "model.layers.22.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
180
+ "model.layers.22.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
181
+ "model.layers.22.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
182
+ "model.layers.22.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
183
+ "model.layers.23.input_layernorm.weight": "model-00001-of-00002.safetensors",
184
+ "model.layers.23.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
185
+ "model.layers.23.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
186
+ "model.layers.23.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
187
+ "model.layers.23.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
188
+ "model.layers.23.post_feedforward_layernorm.weight": "model-00001-of-00002.safetensors",
189
+ "model.layers.23.pre_feedforward_layernorm.weight": "model-00001-of-00002.safetensors",
190
+ "model.layers.23.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
191
+ "model.layers.23.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
192
+ "model.layers.23.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
193
+ "model.layers.23.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
194
+ "model.layers.24.input_layernorm.weight": "model-00002-of-00002.safetensors",
195
+ "model.layers.24.mlp.down_proj.weight": "model-00002-of-00002.safetensors",
196
+ "model.layers.24.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
197
+ "model.layers.24.mlp.up_proj.weight": "model-00002-of-00002.safetensors",
198
+ "model.layers.24.post_attention_layernorm.weight": "model-00002-of-00002.safetensors",
199
+ "model.layers.24.post_feedforward_layernorm.weight": "model-00002-of-00002.safetensors",
200
+ "model.layers.24.pre_feedforward_layernorm.weight": "model-00002-of-00002.safetensors",
201
+ "model.layers.24.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
202
+ "model.layers.24.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
203
+ "model.layers.24.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
204
+ "model.layers.24.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
205
+ "model.layers.25.input_layernorm.weight": "model-00002-of-00002.safetensors",
206
+ "model.layers.25.mlp.down_proj.weight": "model-00002-of-00002.safetensors",
207
+ "model.layers.25.mlp.gate_proj.weight": "model-00002-of-00002.safetensors",
208
+ "model.layers.25.mlp.up_proj.weight": "model-00002-of-00002.safetensors",
209
+ "model.layers.25.post_attention_layernorm.weight": "model-00002-of-00002.safetensors",
210
+ "model.layers.25.post_feedforward_layernorm.weight": "model-00002-of-00002.safetensors",
211
+ "model.layers.25.pre_feedforward_layernorm.weight": "model-00002-of-00002.safetensors",
212
+ "model.layers.25.self_attn.k_proj.weight": "model-00002-of-00002.safetensors",
213
+ "model.layers.25.self_attn.o_proj.weight": "model-00002-of-00002.safetensors",
214
+ "model.layers.25.self_attn.q_proj.weight": "model-00002-of-00002.safetensors",
215
+ "model.layers.25.self_attn.v_proj.weight": "model-00002-of-00002.safetensors",
216
+ "model.layers.3.input_layernorm.weight": "model-00001-of-00002.safetensors",
217
+ "model.layers.3.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
218
+ "model.layers.3.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
219
+ "model.layers.3.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
220
+ "model.layers.3.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
221
+ "model.layers.3.post_feedforward_layernorm.weight": "model-00001-of-00002.safetensors",
222
+ "model.layers.3.pre_feedforward_layernorm.weight": "model-00001-of-00002.safetensors",
223
+ "model.layers.3.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
224
+ "model.layers.3.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
225
+ "model.layers.3.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
226
+ "model.layers.3.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
227
+ "model.layers.4.input_layernorm.weight": "model-00001-of-00002.safetensors",
228
+ "model.layers.4.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
229
+ "model.layers.4.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
230
+ "model.layers.4.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
231
+ "model.layers.4.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
232
+ "model.layers.4.post_feedforward_layernorm.weight": "model-00001-of-00002.safetensors",
233
+ "model.layers.4.pre_feedforward_layernorm.weight": "model-00001-of-00002.safetensors",
234
+ "model.layers.4.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
235
+ "model.layers.4.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
236
+ "model.layers.4.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
237
+ "model.layers.4.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
238
+ "model.layers.5.input_layernorm.weight": "model-00001-of-00002.safetensors",
239
+ "model.layers.5.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
240
+ "model.layers.5.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
241
+ "model.layers.5.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
242
+ "model.layers.5.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
243
+ "model.layers.5.post_feedforward_layernorm.weight": "model-00001-of-00002.safetensors",
244
+ "model.layers.5.pre_feedforward_layernorm.weight": "model-00001-of-00002.safetensors",
245
+ "model.layers.5.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
246
+ "model.layers.5.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
247
+ "model.layers.5.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
248
+ "model.layers.5.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
249
+ "model.layers.6.input_layernorm.weight": "model-00001-of-00002.safetensors",
250
+ "model.layers.6.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
251
+ "model.layers.6.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
252
+ "model.layers.6.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
253
+ "model.layers.6.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
254
+ "model.layers.6.post_feedforward_layernorm.weight": "model-00001-of-00002.safetensors",
255
+ "model.layers.6.pre_feedforward_layernorm.weight": "model-00001-of-00002.safetensors",
256
+ "model.layers.6.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
257
+ "model.layers.6.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
258
+ "model.layers.6.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
259
+ "model.layers.6.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
260
+ "model.layers.7.input_layernorm.weight": "model-00001-of-00002.safetensors",
261
+ "model.layers.7.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
262
+ "model.layers.7.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
263
+ "model.layers.7.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
264
+ "model.layers.7.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
265
+ "model.layers.7.post_feedforward_layernorm.weight": "model-00001-of-00002.safetensors",
266
+ "model.layers.7.pre_feedforward_layernorm.weight": "model-00001-of-00002.safetensors",
267
+ "model.layers.7.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
268
+ "model.layers.7.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
269
+ "model.layers.7.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
270
+ "model.layers.7.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
271
+ "model.layers.8.input_layernorm.weight": "model-00001-of-00002.safetensors",
272
+ "model.layers.8.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
273
+ "model.layers.8.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
274
+ "model.layers.8.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
275
+ "model.layers.8.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
276
+ "model.layers.8.post_feedforward_layernorm.weight": "model-00001-of-00002.safetensors",
277
+ "model.layers.8.pre_feedforward_layernorm.weight": "model-00001-of-00002.safetensors",
278
+ "model.layers.8.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
279
+ "model.layers.8.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
280
+ "model.layers.8.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
281
+ "model.layers.8.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
282
+ "model.layers.9.input_layernorm.weight": "model-00001-of-00002.safetensors",
283
+ "model.layers.9.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
284
+ "model.layers.9.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
285
+ "model.layers.9.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
286
+ "model.layers.9.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
287
+ "model.layers.9.post_feedforward_layernorm.weight": "model-00001-of-00002.safetensors",
288
+ "model.layers.9.pre_feedforward_layernorm.weight": "model-00001-of-00002.safetensors",
289
+ "model.layers.9.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
290
+ "model.layers.9.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
291
+ "model.layers.9.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
292
+ "model.layers.9.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
293
+ "model.norm.weight": "model-00002-of-00002.safetensors"
294
+ }
295
+ }
PixelDiT-T2I-1024/tokenizer/special_tokens_map.json ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "additional_special_tokens": [
3
+ "<start_of_turn>",
4
+ "<end_of_turn>"
5
+ ],
6
+ "bos_token": {
7
+ "content": "<bos>",
8
+ "lstrip": false,
9
+ "normalized": false,
10
+ "rstrip": false,
11
+ "single_word": false
12
+ },
13
+ "eos_token": {
14
+ "content": "<eos>",
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
+ "unk_token": {
28
+ "content": "<unk>",
29
+ "lstrip": false,
30
+ "normalized": false,
31
+ "rstrip": false,
32
+ "single_word": false
33
+ }
34
+ }
PixelDiT-T2I-1024/tokenizer/tokenizer.json ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:3f289bc05132635a8bc7aca7aa21255efd5e18f3710f43e3cdb96bcd41be4922
3
+ size 17525357
PixelDiT-T2I-1024/tokenizer/tokenizer.model ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:61a7b147390c64585d6c3543dd6fc636906c9af3865a5548f27f31aee1d4c8e2
3
+ size 4241003
PixelDiT-T2I-1024/tokenizer/tokenizer_config.json ADDED
@@ -0,0 +1,2013 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "add_bos_token": true,
3
+ "add_eos_token": false,
4
+ "added_tokens_decoder": {
5
+ "0": {
6
+ "content": "<pad>",
7
+ "lstrip": false,
8
+ "normalized": false,
9
+ "rstrip": false,
10
+ "single_word": false,
11
+ "special": true
12
+ },
13
+ "1": {
14
+ "content": "<eos>",
15
+ "lstrip": false,
16
+ "normalized": false,
17
+ "rstrip": false,
18
+ "single_word": false,
19
+ "special": true
20
+ },
21
+ "2": {
22
+ "content": "<bos>",
23
+ "lstrip": false,
24
+ "normalized": false,
25
+ "rstrip": false,
26
+ "single_word": false,
27
+ "special": true
28
+ },
29
+ "3": {
30
+ "content": "<unk>",
31
+ "lstrip": false,
32
+ "normalized": false,
33
+ "rstrip": false,
34
+ "single_word": false,
35
+ "special": true
36
+ },
37
+ "4": {
38
+ "content": "<mask>",
39
+ "lstrip": false,
40
+ "normalized": false,
41
+ "rstrip": false,
42
+ "single_word": false,
43
+ "special": false
44
+ },
45
+ "5": {
46
+ "content": "<2mass>",
47
+ "lstrip": false,
48
+ "normalized": false,
49
+ "rstrip": false,
50
+ "single_word": false,
51
+ "special": false
52
+ },
53
+ "6": {
54
+ "content": "[@BOS@]",
55
+ "lstrip": false,
56
+ "normalized": false,
57
+ "rstrip": false,
58
+ "single_word": false,
59
+ "special": false
60
+ },
61
+ "7": {
62
+ "content": "<unused0>",
63
+ "lstrip": false,
64
+ "normalized": false,
65
+ "rstrip": false,
66
+ "single_word": false,
67
+ "special": false
68
+ },
69
+ "8": {
70
+ "content": "<unused1>",
71
+ "lstrip": false,
72
+ "normalized": false,
73
+ "rstrip": false,
74
+ "single_word": false,
75
+ "special": false
76
+ },
77
+ "9": {
78
+ "content": "<unused2>",
79
+ "lstrip": false,
80
+ "normalized": false,
81
+ "rstrip": false,
82
+ "single_word": false,
83
+ "special": false
84
+ },
85
+ "10": {
86
+ "content": "<unused3>",
87
+ "lstrip": false,
88
+ "normalized": false,
89
+ "rstrip": false,
90
+ "single_word": false,
91
+ "special": false
92
+ },
93
+ "11": {
94
+ "content": "<unused4>",
95
+ "lstrip": false,
96
+ "normalized": false,
97
+ "rstrip": false,
98
+ "single_word": false,
99
+ "special": false
100
+ },
101
+ "12": {
102
+ "content": "<unused5>",
103
+ "lstrip": false,
104
+ "normalized": false,
105
+ "rstrip": false,
106
+ "single_word": false,
107
+ "special": false
108
+ },
109
+ "13": {
110
+ "content": "<unused6>",
111
+ "lstrip": false,
112
+ "normalized": false,
113
+ "rstrip": false,
114
+ "single_word": false,
115
+ "special": false
116
+ },
117
+ "14": {
118
+ "content": "<unused7>",
119
+ "lstrip": false,
120
+ "normalized": false,
121
+ "rstrip": false,
122
+ "single_word": false,
123
+ "special": false
124
+ },
125
+ "15": {
126
+ "content": "<unused8>",
127
+ "lstrip": false,
128
+ "normalized": false,
129
+ "rstrip": false,
130
+ "single_word": false,
131
+ "special": false
132
+ },
133
+ "16": {
134
+ "content": "<unused9>",
135
+ "lstrip": false,
136
+ "normalized": false,
137
+ "rstrip": false,
138
+ "single_word": false,
139
+ "special": false
140
+ },
141
+ "17": {
142
+ "content": "<unused10>",
143
+ "lstrip": false,
144
+ "normalized": false,
145
+ "rstrip": false,
146
+ "single_word": false,
147
+ "special": false
148
+ },
149
+ "18": {
150
+ "content": "<unused11>",
151
+ "lstrip": false,
152
+ "normalized": false,
153
+ "rstrip": false,
154
+ "single_word": false,
155
+ "special": false
156
+ },
157
+ "19": {
158
+ "content": "<unused12>",
159
+ "lstrip": false,
160
+ "normalized": false,
161
+ "rstrip": false,
162
+ "single_word": false,
163
+ "special": false
164
+ },
165
+ "20": {
166
+ "content": "<unused13>",
167
+ "lstrip": false,
168
+ "normalized": false,
169
+ "rstrip": false,
170
+ "single_word": false,
171
+ "special": false
172
+ },
173
+ "21": {
174
+ "content": "<unused14>",
175
+ "lstrip": false,
176
+ "normalized": false,
177
+ "rstrip": false,
178
+ "single_word": false,
179
+ "special": false
180
+ },
181
+ "22": {
182
+ "content": "<unused15>",
183
+ "lstrip": false,
184
+ "normalized": false,
185
+ "rstrip": false,
186
+ "single_word": false,
187
+ "special": false
188
+ },
189
+ "23": {
190
+ "content": "<unused16>",
191
+ "lstrip": false,
192
+ "normalized": false,
193
+ "rstrip": false,
194
+ "single_word": false,
195
+ "special": false
196
+ },
197
+ "24": {
198
+ "content": "<unused17>",
199
+ "lstrip": false,
200
+ "normalized": false,
201
+ "rstrip": false,
202
+ "single_word": false,
203
+ "special": false
204
+ },
205
+ "25": {
206
+ "content": "<unused18>",
207
+ "lstrip": false,
208
+ "normalized": false,
209
+ "rstrip": false,
210
+ "single_word": false,
211
+ "special": false
212
+ },
213
+ "26": {
214
+ "content": "<unused19>",
215
+ "lstrip": false,
216
+ "normalized": false,
217
+ "rstrip": false,
218
+ "single_word": false,
219
+ "special": false
220
+ },
221
+ "27": {
222
+ "content": "<unused20>",
223
+ "lstrip": false,
224
+ "normalized": false,
225
+ "rstrip": false,
226
+ "single_word": false,
227
+ "special": false
228
+ },
229
+ "28": {
230
+ "content": "<unused21>",
231
+ "lstrip": false,
232
+ "normalized": false,
233
+ "rstrip": false,
234
+ "single_word": false,
235
+ "special": false
236
+ },
237
+ "29": {
238
+ "content": "<unused22>",
239
+ "lstrip": false,
240
+ "normalized": false,
241
+ "rstrip": false,
242
+ "single_word": false,
243
+ "special": false
244
+ },
245
+ "30": {
246
+ "content": "<unused23>",
247
+ "lstrip": false,
248
+ "normalized": false,
249
+ "rstrip": false,
250
+ "single_word": false,
251
+ "special": false
252
+ },
253
+ "31": {
254
+ "content": "<unused24>",
255
+ "lstrip": false,
256
+ "normalized": false,
257
+ "rstrip": false,
258
+ "single_word": false,
259
+ "special": false
260
+ },
261
+ "32": {
262
+ "content": "<unused25>",
263
+ "lstrip": false,
264
+ "normalized": false,
265
+ "rstrip": false,
266
+ "single_word": false,
267
+ "special": false
268
+ },
269
+ "33": {
270
+ "content": "<unused26>",
271
+ "lstrip": false,
272
+ "normalized": false,
273
+ "rstrip": false,
274
+ "single_word": false,
275
+ "special": false
276
+ },
277
+ "34": {
278
+ "content": "<unused27>",
279
+ "lstrip": false,
280
+ "normalized": false,
281
+ "rstrip": false,
282
+ "single_word": false,
283
+ "special": false
284
+ },
285
+ "35": {
286
+ "content": "<unused28>",
287
+ "lstrip": false,
288
+ "normalized": false,
289
+ "rstrip": false,
290
+ "single_word": false,
291
+ "special": false
292
+ },
293
+ "36": {
294
+ "content": "<unused29>",
295
+ "lstrip": false,
296
+ "normalized": false,
297
+ "rstrip": false,
298
+ "single_word": false,
299
+ "special": false
300
+ },
301
+ "37": {
302
+ "content": "<unused30>",
303
+ "lstrip": false,
304
+ "normalized": false,
305
+ "rstrip": false,
306
+ "single_word": false,
307
+ "special": false
308
+ },
309
+ "38": {
310
+ "content": "<unused31>",
311
+ "lstrip": false,
312
+ "normalized": false,
313
+ "rstrip": false,
314
+ "single_word": false,
315
+ "special": false
316
+ },
317
+ "39": {
318
+ "content": "<unused32>",
319
+ "lstrip": false,
320
+ "normalized": false,
321
+ "rstrip": false,
322
+ "single_word": false,
323
+ "special": false
324
+ },
325
+ "40": {
326
+ "content": "<unused33>",
327
+ "lstrip": false,
328
+ "normalized": false,
329
+ "rstrip": false,
330
+ "single_word": false,
331
+ "special": false
332
+ },
333
+ "41": {
334
+ "content": "<unused34>",
335
+ "lstrip": false,
336
+ "normalized": false,
337
+ "rstrip": false,
338
+ "single_word": false,
339
+ "special": false
340
+ },
341
+ "42": {
342
+ "content": "<unused35>",
343
+ "lstrip": false,
344
+ "normalized": false,
345
+ "rstrip": false,
346
+ "single_word": false,
347
+ "special": false
348
+ },
349
+ "43": {
350
+ "content": "<unused36>",
351
+ "lstrip": false,
352
+ "normalized": false,
353
+ "rstrip": false,
354
+ "single_word": false,
355
+ "special": false
356
+ },
357
+ "44": {
358
+ "content": "<unused37>",
359
+ "lstrip": false,
360
+ "normalized": false,
361
+ "rstrip": false,
362
+ "single_word": false,
363
+ "special": false
364
+ },
365
+ "45": {
366
+ "content": "<unused38>",
367
+ "lstrip": false,
368
+ "normalized": false,
369
+ "rstrip": false,
370
+ "single_word": false,
371
+ "special": false
372
+ },
373
+ "46": {
374
+ "content": "<unused39>",
375
+ "lstrip": false,
376
+ "normalized": false,
377
+ "rstrip": false,
378
+ "single_word": false,
379
+ "special": false
380
+ },
381
+ "47": {
382
+ "content": "<unused40>",
383
+ "lstrip": false,
384
+ "normalized": false,
385
+ "rstrip": false,
386
+ "single_word": false,
387
+ "special": false
388
+ },
389
+ "48": {
390
+ "content": "<unused41>",
391
+ "lstrip": false,
392
+ "normalized": false,
393
+ "rstrip": false,
394
+ "single_word": false,
395
+ "special": false
396
+ },
397
+ "49": {
398
+ "content": "<unused42>",
399
+ "lstrip": false,
400
+ "normalized": false,
401
+ "rstrip": false,
402
+ "single_word": false,
403
+ "special": false
404
+ },
405
+ "50": {
406
+ "content": "<unused43>",
407
+ "lstrip": false,
408
+ "normalized": false,
409
+ "rstrip": false,
410
+ "single_word": false,
411
+ "special": false
412
+ },
413
+ "51": {
414
+ "content": "<unused44>",
415
+ "lstrip": false,
416
+ "normalized": false,
417
+ "rstrip": false,
418
+ "single_word": false,
419
+ "special": false
420
+ },
421
+ "52": {
422
+ "content": "<unused45>",
423
+ "lstrip": false,
424
+ "normalized": false,
425
+ "rstrip": false,
426
+ "single_word": false,
427
+ "special": false
428
+ },
429
+ "53": {
430
+ "content": "<unused46>",
431
+ "lstrip": false,
432
+ "normalized": false,
433
+ "rstrip": false,
434
+ "single_word": false,
435
+ "special": false
436
+ },
437
+ "54": {
438
+ "content": "<unused47>",
439
+ "lstrip": false,
440
+ "normalized": false,
441
+ "rstrip": false,
442
+ "single_word": false,
443
+ "special": false
444
+ },
445
+ "55": {
446
+ "content": "<unused48>",
447
+ "lstrip": false,
448
+ "normalized": false,
449
+ "rstrip": false,
450
+ "single_word": false,
451
+ "special": false
452
+ },
453
+ "56": {
454
+ "content": "<unused49>",
455
+ "lstrip": false,
456
+ "normalized": false,
457
+ "rstrip": false,
458
+ "single_word": false,
459
+ "special": false
460
+ },
461
+ "57": {
462
+ "content": "<unused50>",
463
+ "lstrip": false,
464
+ "normalized": false,
465
+ "rstrip": false,
466
+ "single_word": false,
467
+ "special": false
468
+ },
469
+ "58": {
470
+ "content": "<unused51>",
471
+ "lstrip": false,
472
+ "normalized": false,
473
+ "rstrip": false,
474
+ "single_word": false,
475
+ "special": false
476
+ },
477
+ "59": {
478
+ "content": "<unused52>",
479
+ "lstrip": false,
480
+ "normalized": false,
481
+ "rstrip": false,
482
+ "single_word": false,
483
+ "special": false
484
+ },
485
+ "60": {
486
+ "content": "<unused53>",
487
+ "lstrip": false,
488
+ "normalized": false,
489
+ "rstrip": false,
490
+ "single_word": false,
491
+ "special": false
492
+ },
493
+ "61": {
494
+ "content": "<unused54>",
495
+ "lstrip": false,
496
+ "normalized": false,
497
+ "rstrip": false,
498
+ "single_word": false,
499
+ "special": false
500
+ },
501
+ "62": {
502
+ "content": "<unused55>",
503
+ "lstrip": false,
504
+ "normalized": false,
505
+ "rstrip": false,
506
+ "single_word": false,
507
+ "special": false
508
+ },
509
+ "63": {
510
+ "content": "<unused56>",
511
+ "lstrip": false,
512
+ "normalized": false,
513
+ "rstrip": false,
514
+ "single_word": false,
515
+ "special": false
516
+ },
517
+ "64": {
518
+ "content": "<unused57>",
519
+ "lstrip": false,
520
+ "normalized": false,
521
+ "rstrip": false,
522
+ "single_word": false,
523
+ "special": false
524
+ },
525
+ "65": {
526
+ "content": "<unused58>",
527
+ "lstrip": false,
528
+ "normalized": false,
529
+ "rstrip": false,
530
+ "single_word": false,
531
+ "special": false
532
+ },
533
+ "66": {
534
+ "content": "<unused59>",
535
+ "lstrip": false,
536
+ "normalized": false,
537
+ "rstrip": false,
538
+ "single_word": false,
539
+ "special": false
540
+ },
541
+ "67": {
542
+ "content": "<unused60>",
543
+ "lstrip": false,
544
+ "normalized": false,
545
+ "rstrip": false,
546
+ "single_word": false,
547
+ "special": false
548
+ },
549
+ "68": {
550
+ "content": "<unused61>",
551
+ "lstrip": false,
552
+ "normalized": false,
553
+ "rstrip": false,
554
+ "single_word": false,
555
+ "special": false
556
+ },
557
+ "69": {
558
+ "content": "<unused62>",
559
+ "lstrip": false,
560
+ "normalized": false,
561
+ "rstrip": false,
562
+ "single_word": false,
563
+ "special": false
564
+ },
565
+ "70": {
566
+ "content": "<unused63>",
567
+ "lstrip": false,
568
+ "normalized": false,
569
+ "rstrip": false,
570
+ "single_word": false,
571
+ "special": false
572
+ },
573
+ "71": {
574
+ "content": "<unused64>",
575
+ "lstrip": false,
576
+ "normalized": false,
577
+ "rstrip": false,
578
+ "single_word": false,
579
+ "special": false
580
+ },
581
+ "72": {
582
+ "content": "<unused65>",
583
+ "lstrip": false,
584
+ "normalized": false,
585
+ "rstrip": false,
586
+ "single_word": false,
587
+ "special": false
588
+ },
589
+ "73": {
590
+ "content": "<unused66>",
591
+ "lstrip": false,
592
+ "normalized": false,
593
+ "rstrip": false,
594
+ "single_word": false,
595
+ "special": false
596
+ },
597
+ "74": {
598
+ "content": "<unused67>",
599
+ "lstrip": false,
600
+ "normalized": false,
601
+ "rstrip": false,
602
+ "single_word": false,
603
+ "special": false
604
+ },
605
+ "75": {
606
+ "content": "<unused68>",
607
+ "lstrip": false,
608
+ "normalized": false,
609
+ "rstrip": false,
610
+ "single_word": false,
611
+ "special": false
612
+ },
613
+ "76": {
614
+ "content": "<unused69>",
615
+ "lstrip": false,
616
+ "normalized": false,
617
+ "rstrip": false,
618
+ "single_word": false,
619
+ "special": false
620
+ },
621
+ "77": {
622
+ "content": "<unused70>",
623
+ "lstrip": false,
624
+ "normalized": false,
625
+ "rstrip": false,
626
+ "single_word": false,
627
+ "special": false
628
+ },
629
+ "78": {
630
+ "content": "<unused71>",
631
+ "lstrip": false,
632
+ "normalized": false,
633
+ "rstrip": false,
634
+ "single_word": false,
635
+ "special": false
636
+ },
637
+ "79": {
638
+ "content": "<unused72>",
639
+ "lstrip": false,
640
+ "normalized": false,
641
+ "rstrip": false,
642
+ "single_word": false,
643
+ "special": false
644
+ },
645
+ "80": {
646
+ "content": "<unused73>",
647
+ "lstrip": false,
648
+ "normalized": false,
649
+ "rstrip": false,
650
+ "single_word": false,
651
+ "special": false
652
+ },
653
+ "81": {
654
+ "content": "<unused74>",
655
+ "lstrip": false,
656
+ "normalized": false,
657
+ "rstrip": false,
658
+ "single_word": false,
659
+ "special": false
660
+ },
661
+ "82": {
662
+ "content": "<unused75>",
663
+ "lstrip": false,
664
+ "normalized": false,
665
+ "rstrip": false,
666
+ "single_word": false,
667
+ "special": false
668
+ },
669
+ "83": {
670
+ "content": "<unused76>",
671
+ "lstrip": false,
672
+ "normalized": false,
673
+ "rstrip": false,
674
+ "single_word": false,
675
+ "special": false
676
+ },
677
+ "84": {
678
+ "content": "<unused77>",
679
+ "lstrip": false,
680
+ "normalized": false,
681
+ "rstrip": false,
682
+ "single_word": false,
683
+ "special": false
684
+ },
685
+ "85": {
686
+ "content": "<unused78>",
687
+ "lstrip": false,
688
+ "normalized": false,
689
+ "rstrip": false,
690
+ "single_word": false,
691
+ "special": false
692
+ },
693
+ "86": {
694
+ "content": "<unused79>",
695
+ "lstrip": false,
696
+ "normalized": false,
697
+ "rstrip": false,
698
+ "single_word": false,
699
+ "special": false
700
+ },
701
+ "87": {
702
+ "content": "<unused80>",
703
+ "lstrip": false,
704
+ "normalized": false,
705
+ "rstrip": false,
706
+ "single_word": false,
707
+ "special": false
708
+ },
709
+ "88": {
710
+ "content": "<unused81>",
711
+ "lstrip": false,
712
+ "normalized": false,
713
+ "rstrip": false,
714
+ "single_word": false,
715
+ "special": false
716
+ },
717
+ "89": {
718
+ "content": "<unused82>",
719
+ "lstrip": false,
720
+ "normalized": false,
721
+ "rstrip": false,
722
+ "single_word": false,
723
+ "special": false
724
+ },
725
+ "90": {
726
+ "content": "<unused83>",
727
+ "lstrip": false,
728
+ "normalized": false,
729
+ "rstrip": false,
730
+ "single_word": false,
731
+ "special": false
732
+ },
733
+ "91": {
734
+ "content": "<unused84>",
735
+ "lstrip": false,
736
+ "normalized": false,
737
+ "rstrip": false,
738
+ "single_word": false,
739
+ "special": false
740
+ },
741
+ "92": {
742
+ "content": "<unused85>",
743
+ "lstrip": false,
744
+ "normalized": false,
745
+ "rstrip": false,
746
+ "single_word": false,
747
+ "special": false
748
+ },
749
+ "93": {
750
+ "content": "<unused86>",
751
+ "lstrip": false,
752
+ "normalized": false,
753
+ "rstrip": false,
754
+ "single_word": false,
755
+ "special": false
756
+ },
757
+ "94": {
758
+ "content": "<unused87>",
759
+ "lstrip": false,
760
+ "normalized": false,
761
+ "rstrip": false,
762
+ "single_word": false,
763
+ "special": false
764
+ },
765
+ "95": {
766
+ "content": "<unused88>",
767
+ "lstrip": false,
768
+ "normalized": false,
769
+ "rstrip": false,
770
+ "single_word": false,
771
+ "special": false
772
+ },
773
+ "96": {
774
+ "content": "<unused89>",
775
+ "lstrip": false,
776
+ "normalized": false,
777
+ "rstrip": false,
778
+ "single_word": false,
779
+ "special": false
780
+ },
781
+ "97": {
782
+ "content": "<unused90>",
783
+ "lstrip": false,
784
+ "normalized": false,
785
+ "rstrip": false,
786
+ "single_word": false,
787
+ "special": false
788
+ },
789
+ "98": {
790
+ "content": "<unused91>",
791
+ "lstrip": false,
792
+ "normalized": false,
793
+ "rstrip": false,
794
+ "single_word": false,
795
+ "special": false
796
+ },
797
+ "99": {
798
+ "content": "<unused92>",
799
+ "lstrip": false,
800
+ "normalized": false,
801
+ "rstrip": false,
802
+ "single_word": false,
803
+ "special": false
804
+ },
805
+ "100": {
806
+ "content": "<unused93>",
807
+ "lstrip": false,
808
+ "normalized": false,
809
+ "rstrip": false,
810
+ "single_word": false,
811
+ "special": false
812
+ },
813
+ "101": {
814
+ "content": "<unused94>",
815
+ "lstrip": false,
816
+ "normalized": false,
817
+ "rstrip": false,
818
+ "single_word": false,
819
+ "special": false
820
+ },
821
+ "102": {
822
+ "content": "<unused95>",
823
+ "lstrip": false,
824
+ "normalized": false,
825
+ "rstrip": false,
826
+ "single_word": false,
827
+ "special": false
828
+ },
829
+ "103": {
830
+ "content": "<unused96>",
831
+ "lstrip": false,
832
+ "normalized": false,
833
+ "rstrip": false,
834
+ "single_word": false,
835
+ "special": false
836
+ },
837
+ "104": {
838
+ "content": "<unused97>",
839
+ "lstrip": false,
840
+ "normalized": false,
841
+ "rstrip": false,
842
+ "single_word": false,
843
+ "special": false
844
+ },
845
+ "105": {
846
+ "content": "<unused98>",
847
+ "lstrip": false,
848
+ "normalized": false,
849
+ "rstrip": false,
850
+ "single_word": false,
851
+ "special": false
852
+ },
853
+ "106": {
854
+ "content": "<start_of_turn>",
855
+ "lstrip": false,
856
+ "normalized": false,
857
+ "rstrip": false,
858
+ "single_word": false,
859
+ "special": true
860
+ },
861
+ "107": {
862
+ "content": "<end_of_turn>",
863
+ "lstrip": false,
864
+ "normalized": false,
865
+ "rstrip": false,
866
+ "single_word": false,
867
+ "special": true
868
+ },
869
+ "108": {
870
+ "content": "\n",
871
+ "lstrip": false,
872
+ "normalized": false,
873
+ "rstrip": false,
874
+ "single_word": false,
875
+ "special": false
876
+ },
877
+ "109": {
878
+ "content": "\n\n",
879
+ "lstrip": false,
880
+ "normalized": false,
881
+ "rstrip": false,
882
+ "single_word": false,
883
+ "special": false
884
+ },
885
+ "110": {
886
+ "content": "\n\n\n",
887
+ "lstrip": false,
888
+ "normalized": false,
889
+ "rstrip": false,
890
+ "single_word": false,
891
+ "special": false
892
+ },
893
+ "111": {
894
+ "content": "\n\n\n\n",
895
+ "lstrip": false,
896
+ "normalized": false,
897
+ "rstrip": false,
898
+ "single_word": false,
899
+ "special": false
900
+ },
901
+ "112": {
902
+ "content": "\n\n\n\n\n",
903
+ "lstrip": false,
904
+ "normalized": false,
905
+ "rstrip": false,
906
+ "single_word": false,
907
+ "special": false
908
+ },
909
+ "113": {
910
+ "content": "\n\n\n\n\n\n",
911
+ "lstrip": false,
912
+ "normalized": false,
913
+ "rstrip": false,
914
+ "single_word": false,
915
+ "special": false
916
+ },
917
+ "114": {
918
+ "content": "\n\n\n\n\n\n\n",
919
+ "lstrip": false,
920
+ "normalized": false,
921
+ "rstrip": false,
922
+ "single_word": false,
923
+ "special": false
924
+ },
925
+ "115": {
926
+ "content": "\n\n\n\n\n\n\n\n",
927
+ "lstrip": false,
928
+ "normalized": false,
929
+ "rstrip": false,
930
+ "single_word": false,
931
+ "special": false
932
+ },
933
+ "116": {
934
+ "content": "\n\n\n\n\n\n\n\n\n",
935
+ "lstrip": false,
936
+ "normalized": false,
937
+ "rstrip": false,
938
+ "single_word": false,
939
+ "special": false
940
+ },
941
+ "117": {
942
+ "content": "\n\n\n\n\n\n\n\n\n\n",
943
+ "lstrip": false,
944
+ "normalized": false,
945
+ "rstrip": false,
946
+ "single_word": false,
947
+ "special": false
948
+ },
949
+ "118": {
950
+ "content": "\n\n\n\n\n\n\n\n\n\n\n",
951
+ "lstrip": false,
952
+ "normalized": false,
953
+ "rstrip": false,
954
+ "single_word": false,
955
+ "special": false
956
+ },
957
+ "119": {
958
+ "content": "\n\n\n\n\n\n\n\n\n\n\n\n",
959
+ "lstrip": false,
960
+ "normalized": false,
961
+ "rstrip": false,
962
+ "single_word": false,
963
+ "special": false
964
+ },
965
+ "120": {
966
+ "content": "\n\n\n\n\n\n\n\n\n\n\n\n\n",
967
+ "lstrip": false,
968
+ "normalized": false,
969
+ "rstrip": false,
970
+ "single_word": false,
971
+ "special": false
972
+ },
973
+ "121": {
974
+ "content": "\n\n\n\n\n\n\n\n\n\n\n\n\n\n",
975
+ "lstrip": false,
976
+ "normalized": false,
977
+ "rstrip": false,
978
+ "single_word": false,
979
+ "special": false
980
+ },
981
+ "122": {
982
+ "content": "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n",
983
+ "lstrip": false,
984
+ "normalized": false,
985
+ "rstrip": false,
986
+ "single_word": false,
987
+ "special": false
988
+ },
989
+ "123": {
990
+ "content": "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n",
991
+ "lstrip": false,
992
+ "normalized": false,
993
+ "rstrip": false,
994
+ "single_word": false,
995
+ "special": false
996
+ },
997
+ "124": {
998
+ "content": "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n",
999
+ "lstrip": false,
1000
+ "normalized": false,
1001
+ "rstrip": false,
1002
+ "single_word": false,
1003
+ "special": false
1004
+ },
1005
+ "125": {
1006
+ "content": "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n",
1007
+ "lstrip": false,
1008
+ "normalized": false,
1009
+ "rstrip": false,
1010
+ "single_word": false,
1011
+ "special": false
1012
+ },
1013
+ "126": {
1014
+ "content": "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n",
1015
+ "lstrip": false,
1016
+ "normalized": false,
1017
+ "rstrip": false,
1018
+ "single_word": false,
1019
+ "special": false
1020
+ },
1021
+ "127": {
1022
+ "content": "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n",
1023
+ "lstrip": false,
1024
+ "normalized": false,
1025
+ "rstrip": false,
1026
+ "single_word": false,
1027
+ "special": false
1028
+ },
1029
+ "128": {
1030
+ "content": "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n",
1031
+ "lstrip": false,
1032
+ "normalized": false,
1033
+ "rstrip": false,
1034
+ "single_word": false,
1035
+ "special": false
1036
+ },
1037
+ "129": {
1038
+ "content": "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n",
1039
+ "lstrip": false,
1040
+ "normalized": false,
1041
+ "rstrip": false,
1042
+ "single_word": false,
1043
+ "special": false
1044
+ },
1045
+ "130": {
1046
+ "content": "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n",
1047
+ "lstrip": false,
1048
+ "normalized": false,
1049
+ "rstrip": false,
1050
+ "single_word": false,
1051
+ "special": false
1052
+ },
1053
+ "131": {
1054
+ "content": "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n",
1055
+ "lstrip": false,
1056
+ "normalized": false,
1057
+ "rstrip": false,
1058
+ "single_word": false,
1059
+ "special": false
1060
+ },
1061
+ "132": {
1062
+ "content": "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n",
1063
+ "lstrip": false,
1064
+ "normalized": false,
1065
+ "rstrip": false,
1066
+ "single_word": false,
1067
+ "special": false
1068
+ },
1069
+ "133": {
1070
+ "content": "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n",
1071
+ "lstrip": false,
1072
+ "normalized": false,
1073
+ "rstrip": false,
1074
+ "single_word": false,
1075
+ "special": false
1076
+ },
1077
+ "134": {
1078
+ "content": "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n",
1079
+ "lstrip": false,
1080
+ "normalized": false,
1081
+ "rstrip": false,
1082
+ "single_word": false,
1083
+ "special": false
1084
+ },
1085
+ "135": {
1086
+ "content": "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n",
1087
+ "lstrip": false,
1088
+ "normalized": false,
1089
+ "rstrip": false,
1090
+ "single_word": false,
1091
+ "special": false
1092
+ },
1093
+ "136": {
1094
+ "content": "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n",
1095
+ "lstrip": false,
1096
+ "normalized": false,
1097
+ "rstrip": false,
1098
+ "single_word": false,
1099
+ "special": false
1100
+ },
1101
+ "137": {
1102
+ "content": "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n",
1103
+ "lstrip": false,
1104
+ "normalized": false,
1105
+ "rstrip": false,
1106
+ "single_word": false,
1107
+ "special": false
1108
+ },
1109
+ "138": {
1110
+ "content": "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n",
1111
+ "lstrip": false,
1112
+ "normalized": false,
1113
+ "rstrip": false,
1114
+ "single_word": false,
1115
+ "special": false
1116
+ },
1117
+ "139": {
1118
+ "content": "▁▁",
1119
+ "lstrip": false,
1120
+ "normalized": false,
1121
+ "rstrip": false,
1122
+ "single_word": false,
1123
+ "special": false
1124
+ },
1125
+ "140": {
1126
+ "content": "▁▁▁",
1127
+ "lstrip": false,
1128
+ "normalized": false,
1129
+ "rstrip": false,
1130
+ "single_word": false,
1131
+ "special": false
1132
+ },
1133
+ "141": {
1134
+ "content": "▁▁▁▁",
1135
+ "lstrip": false,
1136
+ "normalized": false,
1137
+ "rstrip": false,
1138
+ "single_word": false,
1139
+ "special": false
1140
+ },
1141
+ "142": {
1142
+ "content": "▁▁▁▁▁",
1143
+ "lstrip": false,
1144
+ "normalized": false,
1145
+ "rstrip": false,
1146
+ "single_word": false,
1147
+ "special": false
1148
+ },
1149
+ "143": {
1150
+ "content": "▁▁▁▁▁▁",
1151
+ "lstrip": false,
1152
+ "normalized": false,
1153
+ "rstrip": false,
1154
+ "single_word": false,
1155
+ "special": false
1156
+ },
1157
+ "144": {
1158
+ "content": "▁▁▁▁▁▁▁",
1159
+ "lstrip": false,
1160
+ "normalized": false,
1161
+ "rstrip": false,
1162
+ "single_word": false,
1163
+ "special": false
1164
+ },
1165
+ "145": {
1166
+ "content": "▁▁▁▁▁▁▁▁",
1167
+ "lstrip": false,
1168
+ "normalized": false,
1169
+ "rstrip": false,
1170
+ "single_word": false,
1171
+ "special": false
1172
+ },
1173
+ "146": {
1174
+ "content": "▁▁▁▁▁▁▁▁▁",
1175
+ "lstrip": false,
1176
+ "normalized": false,
1177
+ "rstrip": false,
1178
+ "single_word": false,
1179
+ "special": false
1180
+ },
1181
+ "147": {
1182
+ "content": "▁▁▁▁▁▁▁▁▁▁",
1183
+ "lstrip": false,
1184
+ "normalized": false,
1185
+ "rstrip": false,
1186
+ "single_word": false,
1187
+ "special": false
1188
+ },
1189
+ "148": {
1190
+ "content": "▁▁▁▁▁▁▁▁▁▁▁",
1191
+ "lstrip": false,
1192
+ "normalized": false,
1193
+ "rstrip": false,
1194
+ "single_word": false,
1195
+ "special": false
1196
+ },
1197
+ "149": {
1198
+ "content": "▁▁▁▁▁▁▁▁▁▁▁▁",
1199
+ "lstrip": false,
1200
+ "normalized": false,
1201
+ "rstrip": false,
1202
+ "single_word": false,
1203
+ "special": false
1204
+ },
1205
+ "150": {
1206
+ "content": "▁▁▁▁▁▁▁▁▁▁▁▁▁",
1207
+ "lstrip": false,
1208
+ "normalized": false,
1209
+ "rstrip": false,
1210
+ "single_word": false,
1211
+ "special": false
1212
+ },
1213
+ "151": {
1214
+ "content": "▁▁▁▁▁▁▁▁▁▁▁▁▁▁",
1215
+ "lstrip": false,
1216
+ "normalized": false,
1217
+ "rstrip": false,
1218
+ "single_word": false,
1219
+ "special": false
1220
+ },
1221
+ "152": {
1222
+ "content": "▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁",
1223
+ "lstrip": false,
1224
+ "normalized": false,
1225
+ "rstrip": false,
1226
+ "single_word": false,
1227
+ "special": false
1228
+ },
1229
+ "153": {
1230
+ "content": "▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁",
1231
+ "lstrip": false,
1232
+ "normalized": false,
1233
+ "rstrip": false,
1234
+ "single_word": false,
1235
+ "special": false
1236
+ },
1237
+ "154": {
1238
+ "content": "▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁",
1239
+ "lstrip": false,
1240
+ "normalized": false,
1241
+ "rstrip": false,
1242
+ "single_word": false,
1243
+ "special": false
1244
+ },
1245
+ "155": {
1246
+ "content": "▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁",
1247
+ "lstrip": false,
1248
+ "normalized": false,
1249
+ "rstrip": false,
1250
+ "single_word": false,
1251
+ "special": false
1252
+ },
1253
+ "156": {
1254
+ "content": "▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁",
1255
+ "lstrip": false,
1256
+ "normalized": false,
1257
+ "rstrip": false,
1258
+ "single_word": false,
1259
+ "special": false
1260
+ },
1261
+ "157": {
1262
+ "content": "▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁",
1263
+ "lstrip": false,
1264
+ "normalized": false,
1265
+ "rstrip": false,
1266
+ "single_word": false,
1267
+ "special": false
1268
+ },
1269
+ "158": {
1270
+ "content": "▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁",
1271
+ "lstrip": false,
1272
+ "normalized": false,
1273
+ "rstrip": false,
1274
+ "single_word": false,
1275
+ "special": false
1276
+ },
1277
+ "159": {
1278
+ "content": "▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁",
1279
+ "lstrip": false,
1280
+ "normalized": false,
1281
+ "rstrip": false,
1282
+ "single_word": false,
1283
+ "special": false
1284
+ },
1285
+ "160": {
1286
+ "content": "▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁",
1287
+ "lstrip": false,
1288
+ "normalized": false,
1289
+ "rstrip": false,
1290
+ "single_word": false,
1291
+ "special": false
1292
+ },
1293
+ "161": {
1294
+ "content": "▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁",
1295
+ "lstrip": false,
1296
+ "normalized": false,
1297
+ "rstrip": false,
1298
+ "single_word": false,
1299
+ "special": false
1300
+ },
1301
+ "162": {
1302
+ "content": "▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁",
1303
+ "lstrip": false,
1304
+ "normalized": false,
1305
+ "rstrip": false,
1306
+ "single_word": false,
1307
+ "special": false
1308
+ },
1309
+ "163": {
1310
+ "content": "▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁",
1311
+ "lstrip": false,
1312
+ "normalized": false,
1313
+ "rstrip": false,
1314
+ "single_word": false,
1315
+ "special": false
1316
+ },
1317
+ "164": {
1318
+ "content": "▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁",
1319
+ "lstrip": false,
1320
+ "normalized": false,
1321
+ "rstrip": false,
1322
+ "single_word": false,
1323
+ "special": false
1324
+ },
1325
+ "165": {
1326
+ "content": "▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁",
1327
+ "lstrip": false,
1328
+ "normalized": false,
1329
+ "rstrip": false,
1330
+ "single_word": false,
1331
+ "special": false
1332
+ },
1333
+ "166": {
1334
+ "content": "▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁",
1335
+ "lstrip": false,
1336
+ "normalized": false,
1337
+ "rstrip": false,
1338
+ "single_word": false,
1339
+ "special": false
1340
+ },
1341
+ "167": {
1342
+ "content": "▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁",
1343
+ "lstrip": false,
1344
+ "normalized": false,
1345
+ "rstrip": false,
1346
+ "single_word": false,
1347
+ "special": false
1348
+ },
1349
+ "168": {
1350
+ "content": "▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁",
1351
+ "lstrip": false,
1352
+ "normalized": false,
1353
+ "rstrip": false,
1354
+ "single_word": false,
1355
+ "special": false
1356
+ },
1357
+ "169": {
1358
+ "content": "<table>",
1359
+ "lstrip": false,
1360
+ "normalized": false,
1361
+ "rstrip": false,
1362
+ "single_word": false,
1363
+ "special": false
1364
+ },
1365
+ "170": {
1366
+ "content": "<caption>",
1367
+ "lstrip": false,
1368
+ "normalized": false,
1369
+ "rstrip": false,
1370
+ "single_word": false,
1371
+ "special": false
1372
+ },
1373
+ "171": {
1374
+ "content": "<thead>",
1375
+ "lstrip": false,
1376
+ "normalized": false,
1377
+ "rstrip": false,
1378
+ "single_word": false,
1379
+ "special": false
1380
+ },
1381
+ "172": {
1382
+ "content": "<tbody>",
1383
+ "lstrip": false,
1384
+ "normalized": false,
1385
+ "rstrip": false,
1386
+ "single_word": false,
1387
+ "special": false
1388
+ },
1389
+ "173": {
1390
+ "content": "<tfoot>",
1391
+ "lstrip": false,
1392
+ "normalized": false,
1393
+ "rstrip": false,
1394
+ "single_word": false,
1395
+ "special": false
1396
+ },
1397
+ "174": {
1398
+ "content": "<tr>",
1399
+ "lstrip": false,
1400
+ "normalized": false,
1401
+ "rstrip": false,
1402
+ "single_word": false,
1403
+ "special": false
1404
+ },
1405
+ "175": {
1406
+ "content": "<th>",
1407
+ "lstrip": false,
1408
+ "normalized": false,
1409
+ "rstrip": false,
1410
+ "single_word": false,
1411
+ "special": false
1412
+ },
1413
+ "176": {
1414
+ "content": "<td>",
1415
+ "lstrip": false,
1416
+ "normalized": false,
1417
+ "rstrip": false,
1418
+ "single_word": false,
1419
+ "special": false
1420
+ },
1421
+ "177": {
1422
+ "content": "</table>",
1423
+ "lstrip": false,
1424
+ "normalized": false,
1425
+ "rstrip": false,
1426
+ "single_word": false,
1427
+ "special": false
1428
+ },
1429
+ "178": {
1430
+ "content": "</caption>",
1431
+ "lstrip": false,
1432
+ "normalized": false,
1433
+ "rstrip": false,
1434
+ "single_word": false,
1435
+ "special": false
1436
+ },
1437
+ "179": {
1438
+ "content": "</thead>",
1439
+ "lstrip": false,
1440
+ "normalized": false,
1441
+ "rstrip": false,
1442
+ "single_word": false,
1443
+ "special": false
1444
+ },
1445
+ "180": {
1446
+ "content": "</tbody>",
1447
+ "lstrip": false,
1448
+ "normalized": false,
1449
+ "rstrip": false,
1450
+ "single_word": false,
1451
+ "special": false
1452
+ },
1453
+ "181": {
1454
+ "content": "</tfoot>",
1455
+ "lstrip": false,
1456
+ "normalized": false,
1457
+ "rstrip": false,
1458
+ "single_word": false,
1459
+ "special": false
1460
+ },
1461
+ "182": {
1462
+ "content": "</tr>",
1463
+ "lstrip": false,
1464
+ "normalized": false,
1465
+ "rstrip": false,
1466
+ "single_word": false,
1467
+ "special": false
1468
+ },
1469
+ "183": {
1470
+ "content": "</th>",
1471
+ "lstrip": false,
1472
+ "normalized": false,
1473
+ "rstrip": false,
1474
+ "single_word": false,
1475
+ "special": false
1476
+ },
1477
+ "184": {
1478
+ "content": "</td>",
1479
+ "lstrip": false,
1480
+ "normalized": false,
1481
+ "rstrip": false,
1482
+ "single_word": false,
1483
+ "special": false
1484
+ },
1485
+ "185": {
1486
+ "content": "<h1>",
1487
+ "lstrip": false,
1488
+ "normalized": false,
1489
+ "rstrip": false,
1490
+ "single_word": false,
1491
+ "special": false
1492
+ },
1493
+ "186": {
1494
+ "content": "<h2>",
1495
+ "lstrip": false,
1496
+ "normalized": false,
1497
+ "rstrip": false,
1498
+ "single_word": false,
1499
+ "special": false
1500
+ },
1501
+ "187": {
1502
+ "content": "<h3>",
1503
+ "lstrip": false,
1504
+ "normalized": false,
1505
+ "rstrip": false,
1506
+ "single_word": false,
1507
+ "special": false
1508
+ },
1509
+ "188": {
1510
+ "content": "<h4>",
1511
+ "lstrip": false,
1512
+ "normalized": false,
1513
+ "rstrip": false,
1514
+ "single_word": false,
1515
+ "special": false
1516
+ },
1517
+ "189": {
1518
+ "content": "<h5>",
1519
+ "lstrip": false,
1520
+ "normalized": false,
1521
+ "rstrip": false,
1522
+ "single_word": false,
1523
+ "special": false
1524
+ },
1525
+ "190": {
1526
+ "content": "<h6>",
1527
+ "lstrip": false,
1528
+ "normalized": false,
1529
+ "rstrip": false,
1530
+ "single_word": false,
1531
+ "special": false
1532
+ },
1533
+ "191": {
1534
+ "content": "<blockquote>",
1535
+ "lstrip": false,
1536
+ "normalized": false,
1537
+ "rstrip": false,
1538
+ "single_word": false,
1539
+ "special": false
1540
+ },
1541
+ "192": {
1542
+ "content": "</h1>",
1543
+ "lstrip": false,
1544
+ "normalized": false,
1545
+ "rstrip": false,
1546
+ "single_word": false,
1547
+ "special": false
1548
+ },
1549
+ "193": {
1550
+ "content": "</h2>",
1551
+ "lstrip": false,
1552
+ "normalized": false,
1553
+ "rstrip": false,
1554
+ "single_word": false,
1555
+ "special": false
1556
+ },
1557
+ "194": {
1558
+ "content": "</h3>",
1559
+ "lstrip": false,
1560
+ "normalized": false,
1561
+ "rstrip": false,
1562
+ "single_word": false,
1563
+ "special": false
1564
+ },
1565
+ "195": {
1566
+ "content": "</h4>",
1567
+ "lstrip": false,
1568
+ "normalized": false,
1569
+ "rstrip": false,
1570
+ "single_word": false,
1571
+ "special": false
1572
+ },
1573
+ "196": {
1574
+ "content": "</h5>",
1575
+ "lstrip": false,
1576
+ "normalized": false,
1577
+ "rstrip": false,
1578
+ "single_word": false,
1579
+ "special": false
1580
+ },
1581
+ "197": {
1582
+ "content": "</h6>",
1583
+ "lstrip": false,
1584
+ "normalized": false,
1585
+ "rstrip": false,
1586
+ "single_word": false,
1587
+ "special": false
1588
+ },
1589
+ "198": {
1590
+ "content": "</blockquote>",
1591
+ "lstrip": false,
1592
+ "normalized": false,
1593
+ "rstrip": false,
1594
+ "single_word": false,
1595
+ "special": false
1596
+ },
1597
+ "199": {
1598
+ "content": "<strong>",
1599
+ "lstrip": false,
1600
+ "normalized": false,
1601
+ "rstrip": false,
1602
+ "single_word": false,
1603
+ "special": false
1604
+ },
1605
+ "200": {
1606
+ "content": "<em>",
1607
+ "lstrip": false,
1608
+ "normalized": false,
1609
+ "rstrip": false,
1610
+ "single_word": false,
1611
+ "special": false
1612
+ },
1613
+ "201": {
1614
+ "content": "<b>",
1615
+ "lstrip": false,
1616
+ "normalized": false,
1617
+ "rstrip": false,
1618
+ "single_word": false,
1619
+ "special": false
1620
+ },
1621
+ "202": {
1622
+ "content": "<i>",
1623
+ "lstrip": false,
1624
+ "normalized": false,
1625
+ "rstrip": false,
1626
+ "single_word": false,
1627
+ "special": false
1628
+ },
1629
+ "203": {
1630
+ "content": "<u>",
1631
+ "lstrip": false,
1632
+ "normalized": false,
1633
+ "rstrip": false,
1634
+ "single_word": false,
1635
+ "special": false
1636
+ },
1637
+ "204": {
1638
+ "content": "<s>",
1639
+ "lstrip": false,
1640
+ "normalized": false,
1641
+ "rstrip": false,
1642
+ "single_word": false,
1643
+ "special": false
1644
+ },
1645
+ "205": {
1646
+ "content": "<sub>",
1647
+ "lstrip": false,
1648
+ "normalized": false,
1649
+ "rstrip": false,
1650
+ "single_word": false,
1651
+ "special": false
1652
+ },
1653
+ "206": {
1654
+ "content": "<sup>",
1655
+ "lstrip": false,
1656
+ "normalized": false,
1657
+ "rstrip": false,
1658
+ "single_word": false,
1659
+ "special": false
1660
+ },
1661
+ "207": {
1662
+ "content": "<code>",
1663
+ "lstrip": false,
1664
+ "normalized": false,
1665
+ "rstrip": false,
1666
+ "single_word": false,
1667
+ "special": false
1668
+ },
1669
+ "208": {
1670
+ "content": "</strong>",
1671
+ "lstrip": false,
1672
+ "normalized": false,
1673
+ "rstrip": false,
1674
+ "single_word": false,
1675
+ "special": false
1676
+ },
1677
+ "209": {
1678
+ "content": "</em>",
1679
+ "lstrip": false,
1680
+ "normalized": false,
1681
+ "rstrip": false,
1682
+ "single_word": false,
1683
+ "special": false
1684
+ },
1685
+ "210": {
1686
+ "content": "</b>",
1687
+ "lstrip": false,
1688
+ "normalized": false,
1689
+ "rstrip": false,
1690
+ "single_word": false,
1691
+ "special": false
1692
+ },
1693
+ "211": {
1694
+ "content": "</i>",
1695
+ "lstrip": false,
1696
+ "normalized": false,
1697
+ "rstrip": false,
1698
+ "single_word": false,
1699
+ "special": false
1700
+ },
1701
+ "212": {
1702
+ "content": "</u>",
1703
+ "lstrip": false,
1704
+ "normalized": false,
1705
+ "rstrip": false,
1706
+ "single_word": false,
1707
+ "special": false
1708
+ },
1709
+ "213": {
1710
+ "content": "</s>",
1711
+ "lstrip": false,
1712
+ "normalized": false,
1713
+ "rstrip": false,
1714
+ "single_word": false,
1715
+ "special": false
1716
+ },
1717
+ "214": {
1718
+ "content": "</sub>",
1719
+ "lstrip": false,
1720
+ "normalized": false,
1721
+ "rstrip": false,
1722
+ "single_word": false,
1723
+ "special": false
1724
+ },
1725
+ "215": {
1726
+ "content": "</sup>",
1727
+ "lstrip": false,
1728
+ "normalized": false,
1729
+ "rstrip": false,
1730
+ "single_word": false,
1731
+ "special": false
1732
+ },
1733
+ "216": {
1734
+ "content": "</code>",
1735
+ "lstrip": false,
1736
+ "normalized": false,
1737
+ "rstrip": false,
1738
+ "single_word": false,
1739
+ "special": false
1740
+ },
1741
+ "255968": {
1742
+ "content": "[toxicity=0]",
1743
+ "lstrip": false,
1744
+ "normalized": false,
1745
+ "rstrip": false,
1746
+ "single_word": false,
1747
+ "special": false
1748
+ },
1749
+ "255969": {
1750
+ "content": "\t\t",
1751
+ "lstrip": false,
1752
+ "normalized": false,
1753
+ "rstrip": false,
1754
+ "single_word": false,
1755
+ "special": false
1756
+ },
1757
+ "255970": {
1758
+ "content": "\t\t\t",
1759
+ "lstrip": false,
1760
+ "normalized": false,
1761
+ "rstrip": false,
1762
+ "single_word": false,
1763
+ "special": false
1764
+ },
1765
+ "255971": {
1766
+ "content": "\t\t\t\t",
1767
+ "lstrip": false,
1768
+ "normalized": false,
1769
+ "rstrip": false,
1770
+ "single_word": false,
1771
+ "special": false
1772
+ },
1773
+ "255972": {
1774
+ "content": "\t\t\t\t\t",
1775
+ "lstrip": false,
1776
+ "normalized": false,
1777
+ "rstrip": false,
1778
+ "single_word": false,
1779
+ "special": false
1780
+ },
1781
+ "255973": {
1782
+ "content": "\t\t\t\t\t\t",
1783
+ "lstrip": false,
1784
+ "normalized": false,
1785
+ "rstrip": false,
1786
+ "single_word": false,
1787
+ "special": false
1788
+ },
1789
+ "255974": {
1790
+ "content": "\t\t\t\t\t\t\t",
1791
+ "lstrip": false,
1792
+ "normalized": false,
1793
+ "rstrip": false,
1794
+ "single_word": false,
1795
+ "special": false
1796
+ },
1797
+ "255975": {
1798
+ "content": "\t\t\t\t\t\t\t\t",
1799
+ "lstrip": false,
1800
+ "normalized": false,
1801
+ "rstrip": false,
1802
+ "single_word": false,
1803
+ "special": false
1804
+ },
1805
+ "255976": {
1806
+ "content": "\t\t\t\t\t\t\t\t\t",
1807
+ "lstrip": false,
1808
+ "normalized": false,
1809
+ "rstrip": false,
1810
+ "single_word": false,
1811
+ "special": false
1812
+ },
1813
+ "255977": {
1814
+ "content": "\t\t\t\t\t\t\t\t\t\t",
1815
+ "lstrip": false,
1816
+ "normalized": false,
1817
+ "rstrip": false,
1818
+ "single_word": false,
1819
+ "special": false
1820
+ },
1821
+ "255978": {
1822
+ "content": "\t\t\t\t\t\t\t\t\t\t\t",
1823
+ "lstrip": false,
1824
+ "normalized": false,
1825
+ "rstrip": false,
1826
+ "single_word": false,
1827
+ "special": false
1828
+ },
1829
+ "255979": {
1830
+ "content": "\t\t\t\t\t\t\t\t\t\t\t\t",
1831
+ "lstrip": false,
1832
+ "normalized": false,
1833
+ "rstrip": false,
1834
+ "single_word": false,
1835
+ "special": false
1836
+ },
1837
+ "255980": {
1838
+ "content": "\t\t\t\t\t\t\t\t\t\t\t\t\t",
1839
+ "lstrip": false,
1840
+ "normalized": false,
1841
+ "rstrip": false,
1842
+ "single_word": false,
1843
+ "special": false
1844
+ },
1845
+ "255981": {
1846
+ "content": "\t\t\t\t\t\t\t\t\t\t\t\t\t\t",
1847
+ "lstrip": false,
1848
+ "normalized": false,
1849
+ "rstrip": false,
1850
+ "single_word": false,
1851
+ "special": false
1852
+ },
1853
+ "255982": {
1854
+ "content": "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t",
1855
+ "lstrip": false,
1856
+ "normalized": false,
1857
+ "rstrip": false,
1858
+ "single_word": false,
1859
+ "special": false
1860
+ },
1861
+ "255983": {
1862
+ "content": "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t",
1863
+ "lstrip": false,
1864
+ "normalized": false,
1865
+ "rstrip": false,
1866
+ "single_word": false,
1867
+ "special": false
1868
+ },
1869
+ "255984": {
1870
+ "content": "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t",
1871
+ "lstrip": false,
1872
+ "normalized": false,
1873
+ "rstrip": false,
1874
+ "single_word": false,
1875
+ "special": false
1876
+ },
1877
+ "255985": {
1878
+ "content": "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t",
1879
+ "lstrip": false,
1880
+ "normalized": false,
1881
+ "rstrip": false,
1882
+ "single_word": false,
1883
+ "special": false
1884
+ },
1885
+ "255986": {
1886
+ "content": "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t",
1887
+ "lstrip": false,
1888
+ "normalized": false,
1889
+ "rstrip": false,
1890
+ "single_word": false,
1891
+ "special": false
1892
+ },
1893
+ "255987": {
1894
+ "content": "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t",
1895
+ "lstrip": false,
1896
+ "normalized": false,
1897
+ "rstrip": false,
1898
+ "single_word": false,
1899
+ "special": false
1900
+ },
1901
+ "255988": {
1902
+ "content": "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t",
1903
+ "lstrip": false,
1904
+ "normalized": false,
1905
+ "rstrip": false,
1906
+ "single_word": false,
1907
+ "special": false
1908
+ },
1909
+ "255989": {
1910
+ "content": "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t",
1911
+ "lstrip": false,
1912
+ "normalized": false,
1913
+ "rstrip": false,
1914
+ "single_word": false,
1915
+ "special": false
1916
+ },
1917
+ "255990": {
1918
+ "content": "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t",
1919
+ "lstrip": false,
1920
+ "normalized": false,
1921
+ "rstrip": false,
1922
+ "single_word": false,
1923
+ "special": false
1924
+ },
1925
+ "255991": {
1926
+ "content": "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t",
1927
+ "lstrip": false,
1928
+ "normalized": false,
1929
+ "rstrip": false,
1930
+ "single_word": false,
1931
+ "special": false
1932
+ },
1933
+ "255992": {
1934
+ "content": "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t",
1935
+ "lstrip": false,
1936
+ "normalized": false,
1937
+ "rstrip": false,
1938
+ "single_word": false,
1939
+ "special": false
1940
+ },
1941
+ "255993": {
1942
+ "content": "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t",
1943
+ "lstrip": false,
1944
+ "normalized": false,
1945
+ "rstrip": false,
1946
+ "single_word": false,
1947
+ "special": false
1948
+ },
1949
+ "255994": {
1950
+ "content": "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t",
1951
+ "lstrip": false,
1952
+ "normalized": false,
1953
+ "rstrip": false,
1954
+ "single_word": false,
1955
+ "special": false
1956
+ },
1957
+ "255995": {
1958
+ "content": "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t",
1959
+ "lstrip": false,
1960
+ "normalized": false,
1961
+ "rstrip": false,
1962
+ "single_word": false,
1963
+ "special": false
1964
+ },
1965
+ "255996": {
1966
+ "content": "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t",
1967
+ "lstrip": false,
1968
+ "normalized": false,
1969
+ "rstrip": false,
1970
+ "single_word": false,
1971
+ "special": false
1972
+ },
1973
+ "255997": {
1974
+ "content": "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t",
1975
+ "lstrip": false,
1976
+ "normalized": false,
1977
+ "rstrip": false,
1978
+ "single_word": false,
1979
+ "special": false
1980
+ },
1981
+ "255998": {
1982
+ "content": "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t",
1983
+ "lstrip": false,
1984
+ "normalized": false,
1985
+ "rstrip": false,
1986
+ "single_word": false,
1987
+ "special": false
1988
+ },
1989
+ "255999": {
1990
+ "content": "<unused99>",
1991
+ "lstrip": false,
1992
+ "normalized": false,
1993
+ "rstrip": false,
1994
+ "single_word": false,
1995
+ "special": false
1996
+ }
1997
+ },
1998
+ "additional_special_tokens": [
1999
+ "<start_of_turn>",
2000
+ "<end_of_turn>"
2001
+ ],
2002
+ "bos_token": "<bos>",
2003
+ "chat_template": "{{ bos_token }}{% if messages[0]['role'] == 'system' %}{{ raise_exception('System role not supported') }}{% endif %}{% for message in messages %}{% if (message['role'] == 'user') != (loop.index0 % 2 == 0) %}{{ raise_exception('Conversation roles must alternate user/assistant/user/assistant/...') }}{% endif %}{% if (message['role'] == 'assistant') %}{% set role = 'model' %}{% else %}{% set role = message['role'] %}{% endif %}{{ '<start_of_turn>' + role + '\n' + message['content'] | trim + '<end_of_turn>\n' }}{% endfor %}{% if add_generation_prompt %}{{'<start_of_turn>model\n'}}{% endif %}",
2004
+ "clean_up_tokenization_spaces": false,
2005
+ "eos_token": "<eos>",
2006
+ "model_max_length": 1000000000000000019884624838656,
2007
+ "pad_token": "<pad>",
2008
+ "sp_model_kwargs": {},
2009
+ "spaces_between_special_tokens": false,
2010
+ "tokenizer_class": "GemmaTokenizer",
2011
+ "unk_token": "<unk>",
2012
+ "use_default_system_prompt": false
2013
+ }
PixelDiT-T2I-1024/transformer/__pycache__/transformer_pixeldit.cpython-312.pyc ADDED
Binary file (42.4 kB). View file
 
PixelDiT-T2I-1024/transformer/__pycache__/transformer_pixeldit_t2i.cpython-312.pyc ADDED
Binary file (28.8 kB). View file
 
PixelDiT-T2I-1024/transformer/config.json ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "_class_name": "PixelDiTT2ITransformer2DModel",
3
+ "hidden_size": 1536,
4
+ "in_channels": 3,
5
+ "model_type": "pixeldit",
6
+ "num_groups": 24,
7
+ "num_text_blocks": 4,
8
+ "patch_depth": 14,
9
+ "patch_size": 16,
10
+ "pixel_attn_hidden_size": 1152,
11
+ "pixel_depth": 2,
12
+ "pixel_hidden_size": 16,
13
+ "pixel_num_groups": 16,
14
+ "repa_encoder_index": 6,
15
+ "sample_size": 1024,
16
+ "text_rope_theta": 10000.0,
17
+ "txt_embed_dim": 2304,
18
+ "txt_max_length": 300,
19
+ "use_pixel_abs_pos": true,
20
+ "use_text_rope": true
21
+ }
PixelDiT-T2I-1024/transformer/diffusion_pytorch_model.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:c06618b1540ff926b6bb165d0dfbe14c1b228e66b28e72459dcef1c92eb7768c
3
+ size 5209924596
PixelDiT-T2I-1024/transformer/transformer_pixeldit.py ADDED
@@ -0,0 +1,639 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright 2026 The HuggingFace Team. All rights reserved.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ from __future__ import annotations
16
+
17
+ import math
18
+ from collections.abc import Mapping
19
+ from typing import Dict, Literal, Optional, Tuple, Union
20
+
21
+ import numpy as np
22
+ import torch
23
+ import torch.nn as nn
24
+ import torch.nn.functional as F
25
+ from diffusers.configuration_utils import ConfigMixin, register_to_config
26
+ from diffusers.models.modeling_outputs import Transformer2DModelOutput
27
+ from diffusers.models.modeling_utils import ModelMixin
28
+ from diffusers.models.normalization import RMSNorm
29
+
30
+
31
+ PIXELDIT_PRESET_CONFIGS: Dict[str, Dict[str, object]] = {
32
+ "pixeldit-xl": {
33
+ "sample_size": 256,
34
+ "num_groups": 16,
35
+ "hidden_size": 1152,
36
+ "pixel_hidden_size": 16,
37
+ "patch_depth": 26,
38
+ "pixel_depth": 4,
39
+ "patch_size": 16,
40
+ },
41
+ }
42
+
43
+
44
+ def remap_legacy_state_dict(state_dict: Dict[str, torch.Tensor]) -> Dict[str, torch.Tensor]:
45
+ """Map wrapper/backbone keys from legacy checkpoints to native PixelDiTTransformer2DModel keys."""
46
+ remapped: Dict[str, torch.Tensor] = {}
47
+ prefixes = ("transformer.", "model.", "module.", "denoiser.", "net.")
48
+ for key, value in state_dict.items():
49
+ new_key = key
50
+ for prefix in prefixes:
51
+ if new_key.startswith(prefix):
52
+ new_key = new_key[len(prefix) :]
53
+ break
54
+ remapped[new_key] = value
55
+ return remapped
56
+
57
+
58
+ def config_from_legacy(config: Dict[str, object]) -> Dict[str, object]:
59
+ """Build native config kwargs from a legacy config.json dict."""
60
+ model_type = config.get("model_type") or config.get("model_name") or config.get("model_size")
61
+ if model_type not in PIXELDIT_PRESET_CONFIGS:
62
+ raise ValueError(f"Unknown PixelDiT preset '{model_type}'. Known: {list(PIXELDIT_PRESET_CONFIGS)}")
63
+
64
+ preset = dict(PIXELDIT_PRESET_CONFIGS[model_type])
65
+ preset["num_classes"] = int(config.get("num_classes") or config.get("num_class_embeds") or 1000)
66
+ preset["in_channels"] = int(config.get("in_channels", 3))
67
+ preset["use_pixel_abs_pos"] = bool(config.get("use_pixel_abs_pos", True))
68
+ preset["model_type"] = model_type
69
+
70
+ for key in ("sample_size", "num_groups", "hidden_size", "pixel_hidden_size", "patch_depth", "pixel_depth", "patch_size"):
71
+ if config.get(key) is not None:
72
+ preset[key] = config[key]
73
+
74
+ return preset
75
+
76
+
77
+ def get_2d_sincos_pos_embed(embed_dim: int, grid_size: int) -> np.ndarray:
78
+ grid_h = np.arange(grid_size, dtype=np.float32)
79
+ grid_w = np.arange(grid_size, dtype=np.float32)
80
+ grid = np.meshgrid(grid_w, grid_h)
81
+ grid = np.stack(grid, axis=0)
82
+ grid = grid.reshape([2, 1, grid_size, grid_size])
83
+ return get_2d_sincos_pos_embed_from_grid(embed_dim, grid)
84
+
85
+
86
+ def get_2d_sincos_pos_embed_from_grid(embed_dim: int, grid: np.ndarray) -> np.ndarray:
87
+ if embed_dim % 2 != 0:
88
+ raise ValueError("Embedding dimension must be even for 2D sin/cos positional embeddings.")
89
+ emb_h = get_1d_sincos_pos_embed_from_grid(embed_dim // 2, grid[0])
90
+ emb_w = get_1d_sincos_pos_embed_from_grid(embed_dim // 2, grid[1])
91
+ return np.concatenate([emb_h, emb_w], axis=1)
92
+
93
+
94
+ def get_1d_sincos_pos_embed_from_grid(embed_dim: int, pos: np.ndarray) -> np.ndarray:
95
+ if embed_dim % 2 != 0:
96
+ raise ValueError("Embedding dimension must be even for 1D sin/cos positional embeddings.")
97
+ omega = np.arange(embed_dim // 2, dtype=np.float64)
98
+ omega /= embed_dim / 2.0
99
+ omega = 1.0 / 10000**omega
100
+ pos = pos.reshape(-1)
101
+ out = np.einsum("m,d->md", pos, omega)
102
+ return np.concatenate([np.sin(out), np.cos(out)], axis=1)
103
+
104
+
105
+ def apply_adaln(hidden_states: torch.Tensor, shift: torch.Tensor, scale: torch.Tensor) -> torch.Tensor:
106
+ return hidden_states * (1 + scale) + shift
107
+
108
+
109
+ def precompute_freqs_cis_2d(dim: int, height: int, width: int, theta: float = 10000.0, scale: float = 16.0):
110
+ x_pos = torch.linspace(0, scale, width)
111
+ y_pos = torch.linspace(0, scale, height)
112
+ y_pos, x_pos = torch.meshgrid(y_pos, x_pos, indexing="ij")
113
+ y_pos = y_pos.reshape(-1)
114
+ x_pos = x_pos.reshape(-1)
115
+ freqs = 1.0 / (theta ** (torch.arange(0, dim, 4)[: (dim // 4)].float() / dim))
116
+ x_freqs = torch.outer(x_pos, freqs).float()
117
+ y_freqs = torch.outer(y_pos, freqs).float()
118
+ x_cis = torch.polar(torch.ones_like(x_freqs), x_freqs)
119
+ y_cis = torch.polar(torch.ones_like(y_freqs), y_freqs)
120
+ freqs_cis = torch.cat([x_cis.unsqueeze(dim=-1), y_cis.unsqueeze(dim=-1)], dim=-1)
121
+ return freqs_cis.reshape(height * width, -1)
122
+
123
+
124
+ def apply_rotary_emb(
125
+ xq: torch.Tensor,
126
+ xk: torch.Tensor,
127
+ freqs_cis: torch.Tensor,
128
+ ) -> Tuple[torch.Tensor, torch.Tensor]:
129
+ freqs_cis = freqs_cis[None, :, None, :]
130
+ xq_ = torch.view_as_complex(xq.float().reshape(*xq.shape[:-1], -1, 2))
131
+ xk_ = torch.view_as_complex(xk.float().reshape(*xk.shape[:-1], -1, 2))
132
+ xq_out = torch.view_as_real(xq_ * freqs_cis).flatten(3)
133
+ xk_out = torch.view_as_real(xk_ * freqs_cis).flatten(3)
134
+ return xq_out.type_as(xq), xk_out.type_as(xk)
135
+
136
+
137
+ class TimestepConditioner(nn.Module):
138
+ def __init__(self, hidden_size: int, frequency_embedding_size: int = 256):
139
+ super().__init__()
140
+ self.mlp = nn.Sequential(
141
+ nn.Linear(frequency_embedding_size, hidden_size, bias=True),
142
+ nn.SiLU(),
143
+ nn.Linear(hidden_size, hidden_size, bias=True),
144
+ )
145
+ self.frequency_embedding_size = frequency_embedding_size
146
+
147
+ @staticmethod
148
+ def timestep_embedding(timesteps: torch.Tensor, dim: int, max_period: int = 10):
149
+ half = dim // 2
150
+ freqs = torch.exp(
151
+ -math.log(max_period) * torch.arange(start=0, end=half, dtype=torch.float32, device=timesteps.device) / half
152
+ )
153
+ args = timesteps[..., None].float() * freqs[None, ...]
154
+ embedding = torch.cat([torch.cos(args), torch.sin(args)], dim=-1)
155
+ if dim % 2:
156
+ embedding = torch.cat([embedding, torch.zeros_like(embedding[:, :1])], dim=-1)
157
+ return embedding
158
+
159
+ def forward(self, timesteps: torch.Tensor) -> torch.Tensor:
160
+ timestep_freq = self.timestep_embedding(timesteps, self.frequency_embedding_size)
161
+ mlp_dtype = next(self.mlp.parameters()).dtype
162
+ if timestep_freq.dtype != mlp_dtype:
163
+ timestep_freq = timestep_freq.to(mlp_dtype)
164
+ return self.mlp(timestep_freq)
165
+
166
+
167
+ class ClassEmbedder(nn.Module):
168
+ def __init__(self, num_classes: int, hidden_size: int):
169
+ super().__init__()
170
+ self.embedding_table = nn.Embedding(num_classes, hidden_size)
171
+ self.num_classes = num_classes
172
+
173
+ def forward(self, labels: torch.Tensor) -> torch.Tensor:
174
+ return self.embedding_table(labels)
175
+
176
+
177
+ class FeedForward(nn.Module):
178
+ def __init__(self, dim: int, hidden_dim: int):
179
+ super().__init__()
180
+ hidden_dim = int(2 * hidden_dim / 3)
181
+ self.w1 = nn.Linear(dim, hidden_dim, bias=False)
182
+ self.w3 = nn.Linear(dim, hidden_dim, bias=False)
183
+ self.w2 = nn.Linear(hidden_dim, dim, bias=False)
184
+
185
+ def forward(self, hidden_states: torch.Tensor) -> torch.Tensor:
186
+ return self.w2(F.silu(self.w1(hidden_states)) * self.w3(hidden_states))
187
+
188
+
189
+ class RotaryAttention(nn.Module):
190
+ def __init__(
191
+ self,
192
+ dim: int,
193
+ num_heads: int = 8,
194
+ qkv_bias: bool = False,
195
+ qk_norm: bool = True,
196
+ attn_drop: float = 0.0,
197
+ proj_drop: float = 0.0,
198
+ eps: float = 1e-6,
199
+ ) -> None:
200
+ super().__init__()
201
+ if dim % num_heads != 0:
202
+ raise ValueError("dim should be divisible by num_heads")
203
+
204
+ self.dim = dim
205
+ self.num_heads = num_heads
206
+ self.head_dim = dim // num_heads
207
+
208
+ self.qkv = nn.Linear(dim, dim * 3, bias=qkv_bias)
209
+ self.q_norm = RMSNorm(self.head_dim, eps=eps) if qk_norm else nn.Identity()
210
+ self.k_norm = RMSNorm(self.head_dim, eps=eps) if qk_norm else nn.Identity()
211
+ self.attn_drop = nn.Dropout(attn_drop)
212
+ self.proj = nn.Linear(dim, dim)
213
+ self.proj_drop = nn.Dropout(proj_drop)
214
+
215
+ def forward(self, hidden_states: torch.Tensor, pos: torch.Tensor) -> torch.Tensor:
216
+ batch_size, length, channels = hidden_states.shape
217
+ qkv = (
218
+ self.qkv(hidden_states)
219
+ .reshape(batch_size, length, 3, self.num_heads, channels // self.num_heads)
220
+ .permute(2, 0, 1, 3, 4)
221
+ )
222
+ query, key, value = qkv[0], qkv[1], qkv[2]
223
+ query = self.q_norm(query)
224
+ key = self.k_norm(key)
225
+ query, key = apply_rotary_emb(query, key, freqs_cis=pos)
226
+ query = query.view(batch_size, -1, self.num_heads, channels // self.num_heads).transpose(1, 2)
227
+ key = key.view(batch_size, -1, self.num_heads, channels // self.num_heads).transpose(1, 2).contiguous()
228
+ value = value.view(batch_size, -1, self.num_heads, channels // self.num_heads).transpose(1, 2).contiguous()
229
+ hidden_states = F.scaled_dot_product_attention(query, key, value, dropout_p=0.0)
230
+ hidden_states = hidden_states.transpose(1, 2).reshape(batch_size, length, channels)
231
+ hidden_states = self.proj(hidden_states)
232
+ return self.proj_drop(hidden_states)
233
+
234
+
235
+ class MLP(nn.Module):
236
+ def __init__(self, dim: int, mlp_ratio: float = 4.0, drop: float = 0.0):
237
+ super().__init__()
238
+ hidden_dim = int(dim * mlp_ratio)
239
+ self.fc1 = nn.Linear(dim, hidden_dim)
240
+ self.act = nn.GELU()
241
+ self.fc2 = nn.Linear(hidden_dim, dim)
242
+ self.drop = nn.Dropout(drop)
243
+
244
+ def forward(self, hidden_states: torch.Tensor) -> torch.Tensor:
245
+ hidden_states = self.fc1(hidden_states)
246
+ hidden_states = self.act(hidden_states)
247
+ hidden_states = self.drop(hidden_states)
248
+ hidden_states = self.fc2(hidden_states)
249
+ return self.drop(hidden_states)
250
+
251
+
252
+ class FinalLayer(nn.Module):
253
+ def __init__(self, hidden_size: int, out_channels: int, eps: float = 1e-6):
254
+ super().__init__()
255
+ self.norm = RMSNorm(hidden_size, eps=eps)
256
+ self.linear = nn.Linear(hidden_size, out_channels, bias=True)
257
+
258
+ def forward(self, hidden_states: torch.Tensor) -> torch.Tensor:
259
+ hidden_states = self.norm(hidden_states)
260
+ return self.linear(hidden_states)
261
+
262
+
263
+ class PatchTokenEmbedder(nn.Module):
264
+ def __init__(self, in_chans: int, embed_dim: int, norm_layer=None, bias: bool = True):
265
+ super().__init__()
266
+ self.in_chans = in_chans
267
+ self.embed_dim = embed_dim
268
+ self.proj = nn.Linear(in_chans, embed_dim, bias=bias)
269
+ self.norm = norm_layer(embed_dim) if norm_layer else nn.Identity()
270
+
271
+ def forward(self, hidden_states: torch.Tensor) -> torch.Tensor:
272
+ hidden_states = self.proj(hidden_states)
273
+ return self.norm(hidden_states)
274
+
275
+
276
+ class PixelTokenEmbedder(nn.Module):
277
+ def __init__(self, in_channels: int, hidden_size_output: int, use_pixel_abs_pos: bool = True):
278
+ super().__init__()
279
+ self.in_channels = int(in_channels)
280
+ self.hidden_size_output = int(hidden_size_output)
281
+ self.use_pixel_abs_pos = bool(use_pixel_abs_pos)
282
+ self.proj = nn.Linear(self.in_channels, self.hidden_size_output, bias=True)
283
+ self._pos_cache: Dict[tuple[str, int, int], torch.Tensor] = {}
284
+
285
+ def _fetch_pixel_pos_image(self, height: int, width: int, device: torch.device, dtype: torch.dtype):
286
+ key = ("image", height, width)
287
+ if key in self._pos_cache:
288
+ return self._pos_cache[key].to(device=device, dtype=dtype)
289
+ if height == width:
290
+ pos_np = get_2d_sincos_pos_embed(self.hidden_size_output, height)
291
+ else:
292
+ grid_h = np.arange(height, dtype=np.float32)
293
+ grid_w = np.arange(width, dtype=np.float32)
294
+ grid = np.meshgrid(grid_w, grid_h)
295
+ grid = np.stack(grid, axis=0).reshape(2, 1, height, width)
296
+ pos_np = get_2d_sincos_pos_embed_from_grid(self.hidden_size_output, grid)
297
+ pos = torch.from_numpy(pos_np).to(device=device, dtype=dtype)
298
+ self._pos_cache[key] = pos
299
+ return pos
300
+
301
+ def forward(self, inputs: torch.Tensor, img_height: int, img_width: int, patch_size: int):
302
+ if inputs.dim() != 4:
303
+ raise ValueError("PixelTokenEmbedder expects inputs of shape [B,C,H,W]")
304
+ batch_size, channels, height, width = inputs.shape
305
+ if height != img_height or width != img_width:
306
+ raise ValueError("Input resolution does not match img_height/img_width.")
307
+ if height % patch_size != 0 or width % patch_size != 0:
308
+ raise ValueError("Image height and width must be divisible by patch_size.")
309
+ h_tokens, w_tokens = height // patch_size, width // patch_size
310
+ patch_area = patch_size * patch_size
311
+ hidden_states = inputs.permute(0, 2, 3, 1).contiguous()
312
+ hidden_states = self.proj(hidden_states)
313
+ if self.use_pixel_abs_pos:
314
+ pos_full = self._fetch_pixel_pos_image(height, width, inputs.device, inputs.dtype)
315
+ hidden_states = hidden_states + pos_full.view(height, width, self.hidden_size_output).unsqueeze(0)
316
+ hidden_states = hidden_states.view(batch_size, h_tokens, patch_size, w_tokens, patch_size, self.hidden_size_output)
317
+ hidden_states = hidden_states.permute(0, 1, 3, 2, 4, 5).contiguous()
318
+ return hidden_states.view(batch_size * h_tokens * w_tokens, patch_area, self.hidden_size_output)
319
+
320
+
321
+ class AugmentedDiTBlock(nn.Module):
322
+ def __init__(self, hidden_size: int, groups: int, mlp_ratio: float = 4.0, adaLN_modulation=None, eps: float = 1e-6):
323
+ super().__init__()
324
+ self.norm1 = RMSNorm(hidden_size, eps=eps)
325
+ self.attn = RotaryAttention(hidden_size, num_heads=groups, qkv_bias=False, eps=eps)
326
+ self.norm2 = RMSNorm(hidden_size, eps=eps)
327
+ mlp_hidden_dim = int(hidden_size * mlp_ratio)
328
+ self.mlp = FeedForward(hidden_size, mlp_hidden_dim)
329
+ self.adaLN_modulation = adaLN_modulation if adaLN_modulation is not None else nn.Sequential(
330
+ nn.Linear(hidden_size, 6 * hidden_size, bias=True)
331
+ )
332
+
333
+ def forward(self, hidden_states: torch.Tensor, conditioning: torch.Tensor, pos: torch.Tensor):
334
+ shift_msa, scale_msa, gate_msa, shift_mlp, scale_mlp, gate_mlp = self.adaLN_modulation(conditioning).chunk(
335
+ 6, dim=-1
336
+ )
337
+ hidden_states = hidden_states + gate_msa * self.attn(
338
+ apply_adaln(self.norm1(hidden_states), shift_msa, scale_msa), pos
339
+ )
340
+ hidden_states = hidden_states + gate_mlp * self.mlp(
341
+ apply_adaln(self.norm2(hidden_states), shift_mlp, scale_mlp)
342
+ )
343
+ return hidden_states
344
+
345
+
346
+ class PiTBlock(nn.Module):
347
+ def __init__(
348
+ self,
349
+ pixel_hidden_size: int,
350
+ patch_hidden_size: int,
351
+ patch_size: int,
352
+ num_heads: int,
353
+ mlp_ratio: float = 4.0,
354
+ attn_hidden_size: Optional[int] = None,
355
+ attn_num_heads: Optional[int] = None,
356
+ rope_fn=None,
357
+ eps: float = 1e-6,
358
+ ):
359
+ super().__init__()
360
+ self.pixel_dim = int(pixel_hidden_size)
361
+ self.context_dim = int(patch_hidden_size)
362
+ self.patch_size = int(patch_size)
363
+ self.attn_dim = int(attn_hidden_size) if attn_hidden_size is not None else self.context_dim
364
+ self.num_heads = int(attn_num_heads) if attn_num_heads is not None else int(num_heads)
365
+ if self.attn_dim % self.num_heads != 0:
366
+ raise ValueError("pixel attention hidden size must be divisible by pixel num_heads")
367
+ patch_area = self.patch_size * self.patch_size
368
+ self.compress_to_attn = nn.Linear(patch_area * self.pixel_dim, self.attn_dim, bias=True)
369
+ self.expand_from_attn = nn.Linear(self.attn_dim, patch_area * self.pixel_dim, bias=True)
370
+ self.norm1 = RMSNorm(self.pixel_dim, eps=eps)
371
+ self.attn = RotaryAttention(self.attn_dim, num_heads=self.num_heads, qkv_bias=False, eps=eps)
372
+ self.norm2 = RMSNorm(self.pixel_dim, eps=eps)
373
+ self.mlp = MLP(self.pixel_dim, mlp_ratio=mlp_ratio, drop=0.0)
374
+ self.adaLN_modulation = nn.Sequential(nn.Linear(self.context_dim, 6 * self.pixel_dim * patch_area, bias=True))
375
+ self._pos_cache: Dict[tuple[int, int], torch.Tensor] = {}
376
+ self._rope_fn = rope_fn if rope_fn is not None else precompute_freqs_cis_2d
377
+
378
+ def _fetch_pos(self, height: int, width: int, device: torch.device):
379
+ key = (height, width)
380
+ if key in self._pos_cache:
381
+ return self._pos_cache[key].to(device)
382
+ pos = self._rope_fn(self.attn_dim // self.num_heads, height, width).to(device)
383
+ self._pos_cache[key] = pos
384
+ return pos
385
+
386
+ def forward(
387
+ self,
388
+ hidden_states: torch.Tensor,
389
+ conditioning: torch.Tensor,
390
+ image_height: int,
391
+ image_width: int,
392
+ patch_size: int,
393
+ ) -> torch.Tensor:
394
+ batch_tokens, patch_area, channels = hidden_states.shape
395
+ if channels != self.pixel_dim:
396
+ raise ValueError(f"PiTBlock expected pixel_dim={self.pixel_dim}, got {channels}")
397
+ if image_height % patch_size != 0 or image_width % patch_size != 0:
398
+ raise ValueError("Image height and width must be divisible by patch_size.")
399
+ h_tokens, w_tokens = image_height // patch_size, image_width // patch_size
400
+ length = h_tokens * w_tokens
401
+ batch_size = batch_tokens // length
402
+ cond_params = self.adaLN_modulation(conditioning).view(batch_tokens, patch_area, 6 * self.pixel_dim)
403
+ shift_msa, scale_msa, gate_msa, shift_mlp, scale_mlp, gate_mlp = torch.chunk(cond_params, 6, dim=-1)
404
+ hidden_norm = apply_adaln(self.norm1(hidden_states), shift_msa, scale_msa)
405
+ hidden_flat = hidden_norm.view(batch_tokens, patch_area * self.pixel_dim)
406
+ hidden_comp = self.compress_to_attn(hidden_flat).view(batch_size, length, self.attn_dim)
407
+ pos_comp = self._fetch_pos(h_tokens, w_tokens, hidden_states.device)
408
+ attn_out = self.attn(hidden_comp, pos_comp)
409
+ attn_flat = self.expand_from_attn(attn_out.view(batch_size * length, self.attn_dim))
410
+ attn_exp = attn_flat.view(batch_tokens, patch_area, self.pixel_dim)
411
+ hidden_states = hidden_states + gate_msa * attn_exp
412
+ mlp_out = self.mlp(apply_adaln(self.norm2(hidden_states), shift_mlp, scale_mlp))
413
+ hidden_states = hidden_states + gate_mlp * mlp_out
414
+ return hidden_states
415
+
416
+
417
+ class PixelDiTTransformer2DModel(ModelMixin, ConfigMixin):
418
+ _supports_gradient_checkpointing = True
419
+ _skip_layerwise_casting_patterns = ["pos", "_pos_cache"]
420
+
421
+ @register_to_config
422
+ def __init__(
423
+ self,
424
+ sample_size: int = 256,
425
+ in_channels: int = 3,
426
+ num_groups: int = 16,
427
+ hidden_size: int = 1152,
428
+ pixel_hidden_size: int = 16,
429
+ patch_depth: int = 26,
430
+ pixel_depth: int = 4,
431
+ patch_size: int = 16,
432
+ num_classes: int = 1000,
433
+ use_pixel_abs_pos: bool = True,
434
+ norm_eps: float = 1e-6,
435
+ model_type: str | None = None,
436
+ num_class_embeds: int | None = None,
437
+ ):
438
+ super().__init__()
439
+ if num_class_embeds is not None:
440
+ num_classes = int(num_class_embeds)
441
+ if model_type in PIXELDIT_PRESET_CONFIGS:
442
+ preset = PIXELDIT_PRESET_CONFIGS[model_type]
443
+ sample_size = int(preset["sample_size"])
444
+ num_groups = int(preset["num_groups"])
445
+ hidden_size = int(preset["hidden_size"])
446
+ pixel_hidden_size = int(preset["pixel_hidden_size"])
447
+ patch_depth = int(preset["patch_depth"])
448
+ pixel_depth = int(preset["pixel_depth"])
449
+ patch_size = int(preset["patch_size"])
450
+
451
+ self.sample_size = int(sample_size)
452
+ self.in_channels = int(in_channels)
453
+ self.out_channels = int(in_channels)
454
+ self.hidden_size = int(hidden_size)
455
+ self.num_groups = int(num_groups)
456
+ self.patch_depth = int(patch_depth)
457
+ self.pixel_depth = int(pixel_depth)
458
+ self.patch_size = int(patch_size)
459
+ self.pixel_hidden_size = int(pixel_hidden_size)
460
+ self.num_classes = int(num_classes)
461
+ self.use_pixel_abs_pos = bool(use_pixel_abs_pos)
462
+ self.norm_eps = float(norm_eps)
463
+ self.gradient_checkpointing = False
464
+
465
+ if self.pixel_depth <= 0:
466
+ raise ValueError("PixelDiT expects pixel_depth > 0 to preserve the dual-level pipeline")
467
+
468
+ self.pixel_embedder = PixelTokenEmbedder(
469
+ self.in_channels, self.pixel_hidden_size, use_pixel_abs_pos=self.use_pixel_abs_pos
470
+ )
471
+ self.s_embedder = PatchTokenEmbedder(self.in_channels * self.patch_size**2, self.hidden_size, bias=True)
472
+ self.t_embedder = TimestepConditioner(self.hidden_size)
473
+ self.y_embedder = ClassEmbedder(self.num_classes + 1, self.hidden_size)
474
+
475
+ self.final_layer = FinalLayer(self.pixel_hidden_size, self.out_channels, eps=self.norm_eps)
476
+ self.patch_blocks = nn.ModuleList(
477
+ [AugmentedDiTBlock(self.hidden_size, self.num_groups, eps=self.norm_eps) for _ in range(self.patch_depth)]
478
+ )
479
+ self.pixel_blocks = nn.ModuleList(
480
+ [
481
+ PiTBlock(
482
+ self.pixel_hidden_size,
483
+ self.hidden_size,
484
+ patch_size=self.patch_size,
485
+ num_heads=self.num_groups,
486
+ mlp_ratio=4.0,
487
+ eps=self.norm_eps,
488
+ )
489
+ for _ in range(self.pixel_depth)
490
+ ]
491
+ )
492
+ self._precompute_pos: Dict[tuple[int, int], torch.Tensor] = {}
493
+ self._initialize_weights()
494
+
495
+ def _fetch_pos(self, height: int, width: int, device: torch.device):
496
+ key = (height, width)
497
+ if key in self._precompute_pos:
498
+ return self._precompute_pos[key].to(device)
499
+ pos = precompute_freqs_cis_2d(self.hidden_size // self.num_groups, height, width).to(device)
500
+ self._precompute_pos[key] = pos
501
+ return pos
502
+
503
+ def _initialize_weights(self) -> None:
504
+ weight = self.s_embedder.proj.weight.data
505
+ nn.init.xavier_uniform_(weight.view([weight.shape[0], -1]))
506
+ nn.init.constant_(self.s_embedder.proj.bias, 0)
507
+ nn.init.normal_(self.y_embedder.embedding_table.weight, std=0.02)
508
+ nn.init.normal_(self.t_embedder.mlp[0].weight, std=0.02)
509
+ nn.init.normal_(self.t_embedder.mlp[2].weight, std=0.02)
510
+ nn.init.zeros_(self.final_layer.linear.weight)
511
+ nn.init.zeros_(self.final_layer.linear.bias)
512
+ for block in self.patch_blocks:
513
+ nn.init.zeros_(block.adaLN_modulation[0].weight)
514
+ nn.init.zeros_(block.adaLN_modulation[0].bias)
515
+ for block in self.pixel_blocks:
516
+ nn.init.zeros_(block.adaLN_modulation[0].weight)
517
+ nn.init.zeros_(block.adaLN_modulation[0].bias)
518
+
519
+ def forward(
520
+ self,
521
+ sample: torch.Tensor,
522
+ timestep: Union[torch.Tensor, float],
523
+ class_labels: Union[torch.Tensor, int],
524
+ return_dict: bool = True,
525
+ ) -> Union[Transformer2DModelOutput, Tuple[torch.Tensor]]:
526
+ if sample.dim() != 4:
527
+ raise ValueError("PixelDiTTransformer2DModel expects sample of shape [B,C,H,W]")
528
+ batch_size, _, height, width = sample.shape
529
+ if height % self.patch_size != 0 or width % self.patch_size != 0:
530
+ raise ValueError("Image height and width must be divisible by patch_size.")
531
+
532
+ timestep = torch.as_tensor(timestep, device=sample.device)
533
+ if timestep.ndim == 0:
534
+ timestep = timestep.repeat(batch_size)
535
+ else:
536
+ timestep = timestep.reshape(-1)
537
+ if timestep.shape[0] == 1 and batch_size > 1:
538
+ timestep = timestep.repeat(batch_size)
539
+
540
+ if not torch.is_tensor(class_labels):
541
+ class_labels = torch.tensor(class_labels, device=sample.device, dtype=torch.long)
542
+ class_labels = class_labels.to(device=sample.device, dtype=torch.long).reshape(-1)
543
+ if class_labels.shape[0] == 1 and batch_size > 1:
544
+ class_labels = class_labels.repeat(batch_size)
545
+
546
+ pos = self._fetch_pos(height // self.patch_size, width // self.patch_size, sample.device)
547
+ x_patches = F.unfold(sample, kernel_size=self.patch_size, stride=self.patch_size).transpose(1, 2)
548
+ t_emb = self.t_embedder(timestep.view(-1)).view(batch_size, -1, self.hidden_size)
549
+ y_emb = self.y_embedder(class_labels).view(batch_size, 1, self.hidden_size)
550
+ conditioning = F.silu(t_emb + y_emb)
551
+
552
+ patch_states = self.s_embedder(x_patches)
553
+ for block in self.patch_blocks:
554
+ if self.training and self.gradient_checkpointing:
555
+
556
+ def custom_forward(hidden_states, cond, position):
557
+ return block(hidden_states, cond, position)
558
+
559
+ patch_states = torch.utils.checkpoint.checkpoint(
560
+ custom_forward, patch_states, conditioning, pos, use_reentrant=False
561
+ )
562
+ else:
563
+ patch_states = block(patch_states, conditioning, pos)
564
+ patch_states = F.silu(t_emb + patch_states)
565
+
566
+ length = patch_states.shape[1]
567
+ conditioning_states = patch_states.view(batch_size * length, self.hidden_size)
568
+ pixel_states = self.pixel_embedder(
569
+ sample, img_height=height, img_width=width, patch_size=self.patch_size
570
+ )
571
+ for block in self.pixel_blocks:
572
+ if self.training and self.gradient_checkpointing:
573
+
574
+ def custom_forward(hidden_states, cond):
575
+ return block(hidden_states, cond, height, width, self.patch_size)
576
+
577
+ pixel_states = torch.utils.checkpoint.checkpoint(
578
+ custom_forward, pixel_states, conditioning_states, use_reentrant=False
579
+ )
580
+ else:
581
+ pixel_states = block(pixel_states, conditioning_states, height, width, self.patch_size)
582
+ pixel_states = self.final_layer(pixel_states)
583
+
584
+ patch_area = self.patch_size * self.patch_size
585
+ pixel_states = pixel_states.view(batch_size, length, patch_area, self.out_channels).permute(0, 3, 2, 1)
586
+ pixel_states = pixel_states.contiguous().view(batch_size, self.out_channels * patch_area, length)
587
+ output = F.fold(pixel_states, (height, width), kernel_size=self.patch_size, stride=self.patch_size)
588
+
589
+ if not return_dict:
590
+ return (output,)
591
+ return Transformer2DModelOutput(sample=output)
592
+
593
+ @classmethod
594
+ def from_pixeldit_checkpoint(
595
+ cls,
596
+ checkpoint_path: str,
597
+ model_type: Literal["pixeldit-xl"] = "pixeldit-xl",
598
+ map_location: str = "cpu",
599
+ strict: bool = True,
600
+ ) -> Tuple["PixelDiTTransformer2DModel", Dict[str, object]]:
601
+ if model_type not in PIXELDIT_PRESET_CONFIGS:
602
+ raise ValueError(f"Unknown PixelDiT preset '{model_type}'.")
603
+
604
+ if checkpoint_path.endswith(".safetensors"):
605
+ try:
606
+ from safetensors.torch import load_file
607
+ except ImportError as error:
608
+ raise ImportError("Install safetensors to load .safetensors checkpoints.") from error
609
+ state_dict = load_file(checkpoint_path, device=map_location)
610
+ else:
611
+ loaded = torch.load(checkpoint_path, map_location=map_location, weights_only=False)
612
+ if isinstance(loaded, Mapping):
613
+ state_dict = loaded
614
+ for key in ("state_dict", "model", "module", "denoiser"):
615
+ if key in state_dict and isinstance(state_dict[key], dict):
616
+ state_dict = state_dict[key]
617
+ break
618
+ else:
619
+ raise ValueError("Unsupported checkpoint format.")
620
+
621
+ config = dict(PIXELDIT_PRESET_CONFIGS[model_type])
622
+ config["model_type"] = model_type
623
+ model = cls(**config)
624
+ model.load_state_dict(remap_legacy_state_dict(state_dict), strict=strict)
625
+
626
+ metadata = {
627
+ "checkpoint_path": checkpoint_path,
628
+ "model_type": model_type,
629
+ }
630
+ return model, metadata
631
+
632
+ def to_pixeldit_checkpoint(self, prefix: str = "") -> Dict[str, torch.Tensor]:
633
+ checkpoint: Dict[str, torch.Tensor] = {}
634
+ for key, value in self.state_dict().items():
635
+ checkpoint[f"{prefix}{key}"] = value.detach().cpu()
636
+ return checkpoint
637
+
638
+
639
+ PixelDiTDiffusersModel = PixelDiTTransformer2DModel
PixelDiT-T2I-1024/transformer/transformer_pixeldit_t2i.py ADDED
@@ -0,0 +1,537 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright 2026 The HuggingFace Team. All rights reserved.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ from __future__ import annotations
16
+
17
+ from collections.abc import Mapping
18
+ from typing import Dict, Literal, Optional, Tuple, Union
19
+
20
+ import torch
21
+ import torch.nn as nn
22
+ import torch.nn.functional as F
23
+ from diffusers.configuration_utils import ConfigMixin, register_to_config
24
+ from diffusers.models.modeling_outputs import Transformer2DModelOutput
25
+ from diffusers.models.modeling_utils import ModelMixin
26
+ from diffusers.models.normalization import RMSNorm
27
+
28
+ import sys
29
+ from pathlib import Path as _Path
30
+ _MODULE_DIR = _Path(__file__).resolve().parent
31
+ if str(_MODULE_DIR) not in sys.path:
32
+ sys.path.insert(0, str(_MODULE_DIR))
33
+ from transformer_pixeldit import (
34
+ FinalLayer,
35
+ FeedForward,
36
+ PatchTokenEmbedder,
37
+ PiTBlock,
38
+ PixelTokenEmbedder,
39
+ TimestepConditioner,
40
+ apply_adaln,
41
+ apply_rotary_emb,
42
+ precompute_freqs_cis_2d,
43
+ )
44
+
45
+
46
+ PIXELDIT_T2I_PRESET_CONFIGS: Dict[str, Dict[str, object]] = {
47
+ "pixeldit-t2i-1300m": {
48
+ "sample_size": 1024,
49
+ "num_groups": 24,
50
+ "hidden_size": 1536,
51
+ "pixel_hidden_size": 16,
52
+ "pixel_attn_hidden_size": 1152,
53
+ "pixel_num_groups": 16,
54
+ "patch_depth": 14,
55
+ "pixel_depth": 2,
56
+ "num_text_blocks": 4,
57
+ "patch_size": 16,
58
+ "txt_embed_dim": 2304,
59
+ "txt_max_length": 300,
60
+ "use_text_rope": True,
61
+ "text_rope_theta": 10000.0,
62
+ "repa_encoder_index": 6,
63
+ },
64
+ }
65
+
66
+
67
+ def remap_t2i_legacy_state_dict(state_dict: Dict[str, torch.Tensor]) -> Dict[str, torch.Tensor]:
68
+ """Map legacy T2I checkpoint keys to native PixelDiTT2ITransformer2DModel keys."""
69
+ remapped: Dict[str, torch.Tensor] = {}
70
+ for key, value in state_dict.items():
71
+ if key.startswith("_repa_projector."):
72
+ continue
73
+ new_key = key[5:] if key.startswith("core.") else key
74
+ remapped[new_key] = value
75
+ return remapped
76
+
77
+
78
+ def config_from_legacy_t2i(config: Dict[str, object]) -> Dict[str, object]:
79
+ """Build native T2I config kwargs from a legacy config.json dict."""
80
+ model_type = config.get("model_type")
81
+ if model_type == "pixeldit" and config.get("architectures") == ["PixDiT_T2I"]:
82
+ model_type = "pixeldit-t2i-1300m"
83
+ if model_type not in PIXELDIT_T2I_PRESET_CONFIGS:
84
+ raise ValueError(
85
+ f"Unknown PixelDiT T2I preset '{model_type}'. Known: {list(PIXELDIT_T2I_PRESET_CONFIGS)}"
86
+ )
87
+
88
+ preset = dict(PIXELDIT_T2I_PRESET_CONFIGS[model_type])
89
+ preset["in_channels"] = int(config.get("in_channels", 3))
90
+ preset["use_pixel_abs_pos"] = bool(config.get("use_pixel_abs_pos", True))
91
+ preset["model_type"] = model_type
92
+
93
+ for key in preset:
94
+ if config.get(key) is not None:
95
+ preset[key] = config[key]
96
+ if config.get("image_size") is not None:
97
+ preset["sample_size"] = int(config["image_size"])
98
+ return preset
99
+
100
+
101
+ class MMDiTJointAttention(nn.Module):
102
+ def __init__(
103
+ self,
104
+ dim: int,
105
+ num_heads: int = 8,
106
+ qkv_bias: bool = False,
107
+ attn_drop: float = 0.0,
108
+ proj_drop: float = 0.0,
109
+ eps: float = 1e-6,
110
+ ) -> None:
111
+ super().__init__()
112
+ if dim % num_heads != 0:
113
+ raise ValueError("dim should be divisible by num_heads")
114
+ self.dim = dim
115
+ self.num_heads = num_heads
116
+ self.head_dim = dim // num_heads
117
+
118
+ self.qkv_x = nn.Linear(dim, dim * 3, bias=qkv_bias)
119
+ self.qkv_y = nn.Linear(dim, dim * 3, bias=qkv_bias)
120
+ self.q_norm_x = RMSNorm(self.head_dim, eps=eps)
121
+ self.k_norm_x = RMSNorm(self.head_dim, eps=eps)
122
+ self.q_norm_y = RMSNorm(self.head_dim, eps=eps)
123
+ self.k_norm_y = RMSNorm(self.head_dim, eps=eps)
124
+ self.proj_x = nn.Linear(dim, dim)
125
+ self.proj_y = nn.Linear(dim, dim)
126
+ self.attn_drop = nn.Dropout(attn_drop)
127
+ self.proj_drop_x = nn.Dropout(proj_drop)
128
+ self.proj_drop_y = nn.Dropout(proj_drop)
129
+
130
+ def forward(
131
+ self,
132
+ x: torch.Tensor,
133
+ y: torch.Tensor,
134
+ pos_img: torch.Tensor,
135
+ pos_txt: Optional[torch.Tensor] = None,
136
+ attn_mask: Optional[torch.Tensor] = None,
137
+ ) -> Tuple[torch.Tensor, torch.Tensor]:
138
+ batch_size, num_img_tokens, channels = x.shape
139
+ _, num_txt_tokens, txt_channels = y.shape
140
+ if batch_size != y.shape[0] or channels != txt_channels:
141
+ raise ValueError("x and y must share batch and channel dims")
142
+
143
+ qkv_x = (
144
+ self.qkv_x(x)
145
+ .reshape(batch_size, num_img_tokens, 3, self.num_heads, channels // self.num_heads)
146
+ .permute(2, 0, 1, 3, 4)
147
+ )
148
+ qx, kx, vx = qkv_x[0], qkv_x[1], qkv_x[2]
149
+ qx = self.q_norm_x(qx)
150
+ kx = self.k_norm_x(kx)
151
+
152
+ qkv_y = (
153
+ self.qkv_y(y)
154
+ .reshape(batch_size, num_txt_tokens, 3, self.num_heads, channels // self.num_heads)
155
+ .permute(2, 0, 1, 3, 4)
156
+ )
157
+ qy, ky, vy = qkv_y[0], qkv_y[1], qkv_y[2]
158
+ qy = self.q_norm_y(qy)
159
+ ky = self.k_norm_y(ky)
160
+
161
+ qx, kx = apply_rotary_emb(qx, kx, freqs_cis=pos_img)
162
+ if pos_txt is not None:
163
+ qy, ky = apply_rotary_emb(qy, ky, freqs_cis=pos_txt)
164
+
165
+ qx = qx.transpose(1, 2)
166
+ kx = kx.transpose(1, 2)
167
+ vx = vx.transpose(1, 2)
168
+ qy = qy.transpose(1, 2)
169
+ ky = ky.transpose(1, 2)
170
+ vy = vy.transpose(1, 2)
171
+
172
+ q_joint = torch.cat([qy, qx], dim=2)
173
+ k_joint = torch.cat([ky, kx], dim=2)
174
+ v_joint = torch.cat([vy, vx], dim=2)
175
+
176
+ out_joint = F.scaled_dot_product_attention(
177
+ q_joint, k_joint, v_joint, dropout_p=0.0, attn_mask=attn_mask
178
+ )
179
+ out_y = out_joint[:, :, :num_txt_tokens, :]
180
+ out_x = out_joint[:, :, num_txt_tokens:, :]
181
+
182
+ out_y = out_y.transpose(1, 2).reshape(batch_size, num_txt_tokens, channels)
183
+ out_x = out_x.transpose(1, 2).reshape(batch_size, num_img_tokens, channels)
184
+ out_x = self.proj_drop_x(self.proj_x(out_x))
185
+ out_y = self.proj_drop_y(self.proj_y(out_y))
186
+ return out_x, out_y
187
+
188
+
189
+ class MMDiTBlockT2I(nn.Module):
190
+ def __init__(
191
+ self,
192
+ hidden_size: int,
193
+ groups: int,
194
+ mlp_ratio: float = 4.0,
195
+ adaLN_modulation_img=None,
196
+ adaLN_modulation_txt=None,
197
+ eps: float = 1e-6,
198
+ ):
199
+ super().__init__()
200
+ self.norm_x1 = RMSNorm(hidden_size, eps=eps)
201
+ self.norm_y1 = RMSNorm(hidden_size, eps=eps)
202
+ self.attn = MMDiTJointAttention(hidden_size, num_heads=groups, qkv_bias=False, eps=eps)
203
+ self.norm_x2 = RMSNorm(hidden_size, eps=eps)
204
+ self.norm_y2 = RMSNorm(hidden_size, eps=eps)
205
+ mlp_hidden_dim = int(hidden_size * mlp_ratio)
206
+ self.mlp_x = FeedForward(hidden_size, mlp_hidden_dim)
207
+ self.mlp_y = FeedForward(hidden_size, mlp_hidden_dim)
208
+ self.adaLN_modulation_img = adaLN_modulation_img or nn.Sequential(
209
+ nn.Linear(hidden_size, 6 * hidden_size, bias=True)
210
+ )
211
+ self.adaLN_modulation_txt = adaLN_modulation_txt or nn.Sequential(
212
+ nn.Linear(hidden_size, 6 * hidden_size, bias=True)
213
+ )
214
+
215
+ def forward(
216
+ self,
217
+ x: torch.Tensor,
218
+ y: torch.Tensor,
219
+ conditioning: torch.Tensor,
220
+ pos_img: torch.Tensor,
221
+ pos_txt: Optional[torch.Tensor] = None,
222
+ attn_mask: Optional[torch.Tensor] = None,
223
+ ) -> Tuple[torch.Tensor, torch.Tensor]:
224
+ shift_msa_x, scale_msa_x, gate_msa_x, shift_mlp_x, scale_mlp_x, gate_mlp_x = self.adaLN_modulation_img(
225
+ conditioning
226
+ ).chunk(6, dim=-1)
227
+ shift_msa_y, scale_msa_y, gate_msa_y, shift_mlp_y, scale_mlp_y, gate_mlp_y = self.adaLN_modulation_txt(
228
+ conditioning
229
+ ).chunk(6, dim=-1)
230
+
231
+ x_norm = apply_adaln(self.norm_x1(x), shift_msa_x, scale_msa_x)
232
+ y_norm = apply_adaln(self.norm_y1(y), shift_msa_y, scale_msa_y)
233
+ attn_x, attn_y = self.attn(x_norm, y_norm, pos_img, pos_txt, attn_mask)
234
+ x = x + gate_msa_x * attn_x
235
+ y = y + gate_msa_y * attn_y
236
+ x = x + gate_mlp_x * self.mlp_x(apply_adaln(self.norm_x2(x), shift_mlp_x, scale_mlp_x))
237
+ y = y + gate_mlp_y * self.mlp_y(apply_adaln(self.norm_y2(y), shift_mlp_y, scale_mlp_y))
238
+ return x, y
239
+
240
+
241
+ class PixelDiTT2ITransformer2DModel(ModelMixin, ConfigMixin):
242
+ _supports_gradient_checkpointing = True
243
+ _skip_layerwise_casting_patterns = ["pos", "_pos_cache", "y_pos_embedding"]
244
+
245
+ @register_to_config
246
+ def __init__(
247
+ self,
248
+ sample_size: int = 1024,
249
+ in_channels: int = 3,
250
+ num_groups: int = 24,
251
+ hidden_size: int = 1536,
252
+ pixel_hidden_size: int = 16,
253
+ pixel_attn_hidden_size: int = 1152,
254
+ pixel_num_groups: int = 16,
255
+ patch_depth: int = 14,
256
+ pixel_depth: int = 2,
257
+ num_text_blocks: int = 4,
258
+ patch_size: int = 16,
259
+ txt_embed_dim: int = 2304,
260
+ txt_max_length: int = 300,
261
+ use_text_rope: bool = True,
262
+ text_rope_theta: float = 10000.0,
263
+ repa_encoder_index: int = 6,
264
+ use_pixel_abs_pos: bool = True,
265
+ norm_eps: float = 1e-6,
266
+ model_type: str | None = None,
267
+ ):
268
+ super().__init__()
269
+ if model_type in PIXELDIT_T2I_PRESET_CONFIGS:
270
+ preset = PIXELDIT_T2I_PRESET_CONFIGS[model_type]
271
+ sample_size = int(preset["sample_size"])
272
+ num_groups = int(preset["num_groups"])
273
+ hidden_size = int(preset["hidden_size"])
274
+ pixel_hidden_size = int(preset["pixel_hidden_size"])
275
+ pixel_attn_hidden_size = int(preset["pixel_attn_hidden_size"])
276
+ pixel_num_groups = int(preset["pixel_num_groups"])
277
+ patch_depth = int(preset["patch_depth"])
278
+ pixel_depth = int(preset["pixel_depth"])
279
+ num_text_blocks = int(preset["num_text_blocks"])
280
+ patch_size = int(preset["patch_size"])
281
+ txt_embed_dim = int(preset["txt_embed_dim"])
282
+ txt_max_length = int(preset["txt_max_length"])
283
+ use_text_rope = bool(preset["use_text_rope"])
284
+ text_rope_theta = float(preset["text_rope_theta"])
285
+ repa_encoder_index = int(preset["repa_encoder_index"])
286
+
287
+ self.sample_size = int(sample_size)
288
+ self.in_channels = int(in_channels)
289
+ self.out_channels = int(in_channels)
290
+ self.hidden_size = int(hidden_size)
291
+ self.num_groups = int(num_groups)
292
+ self.patch_depth = int(patch_depth)
293
+ self.pixel_depth = int(pixel_depth)
294
+ self.num_text_blocks = int(num_text_blocks)
295
+ self.patch_size = int(patch_size)
296
+ self.pixel_hidden_size = int(pixel_hidden_size)
297
+ self.pixel_attn_hidden_size = int(pixel_attn_hidden_size)
298
+ self.pixel_num_groups = int(pixel_num_groups)
299
+ self.txt_embed_dim = int(txt_embed_dim)
300
+ self.txt_max_length = int(txt_max_length)
301
+ self.use_text_rope = bool(use_text_rope)
302
+ self.text_rope_theta = float(text_rope_theta)
303
+ self.repa_encoder_index = int(repa_encoder_index)
304
+ self.use_pixel_abs_pos = bool(use_pixel_abs_pos)
305
+ self.norm_eps = float(norm_eps)
306
+ self.gradient_checkpointing = False
307
+
308
+ if self.pixel_depth <= 0:
309
+ raise ValueError("PixelDiT T2I expects pixel_depth > 0 to preserve the pixel pathway")
310
+
311
+ self.pixel_embedder = PixelTokenEmbedder(
312
+ self.in_channels, self.pixel_hidden_size, use_pixel_abs_pos=self.use_pixel_abs_pos
313
+ )
314
+ self.s_embedder = PatchTokenEmbedder(self.in_channels * self.patch_size**2, self.hidden_size, bias=True)
315
+ self.t_embedder = TimestepConditioner(self.hidden_size)
316
+ self.y_embedder = PatchTokenEmbedder(
317
+ self.txt_embed_dim,
318
+ self.hidden_size,
319
+ bias=True,
320
+ norm_layer=lambda dim: RMSNorm(dim, eps=self.norm_eps),
321
+ )
322
+ self.y_pos_embedding = nn.Parameter(torch.randn(1, self.txt_max_length, self.hidden_size))
323
+
324
+ self.patch_blocks = nn.ModuleList(
325
+ [MMDiTBlockT2I(self.hidden_size, self.num_groups, eps=self.norm_eps) for _ in range(self.patch_depth)]
326
+ )
327
+ self.pixel_blocks = nn.ModuleList(
328
+ [
329
+ PiTBlock(
330
+ self.pixel_hidden_size,
331
+ self.hidden_size,
332
+ patch_size=self.patch_size,
333
+ num_heads=self.num_groups,
334
+ mlp_ratio=4.0,
335
+ attn_hidden_size=self.pixel_attn_hidden_size,
336
+ attn_num_heads=self.pixel_num_groups,
337
+ rope_fn=precompute_freqs_cis_2d,
338
+ eps=self.norm_eps,
339
+ )
340
+ for _ in range(self.pixel_depth)
341
+ ]
342
+ )
343
+ self.final_layer = FinalLayer(self.pixel_hidden_size, self.out_channels, eps=self.norm_eps)
344
+ self._precompute_pos: Dict[tuple[int, int], torch.Tensor] = {}
345
+ self._precompute_pos_txt: Dict[int, torch.Tensor] = {}
346
+ self._initialize_weights()
347
+
348
+ def _fetch_pos(self, height: int, width: int, device: torch.device):
349
+ key = (height, width)
350
+ if key in self._precompute_pos:
351
+ return self._precompute_pos[key].to(device)
352
+ pos = precompute_freqs_cis_2d(self.hidden_size // self.num_groups, height, width).to(device)
353
+ self._precompute_pos[key] = pos
354
+ return pos
355
+
356
+ def _fetch_pos_text(self, length: int, device: torch.device):
357
+ if length in self._precompute_pos_txt:
358
+ return self._precompute_pos_txt[length].to(device)
359
+ head_dim = self.hidden_size // self.num_groups
360
+ freqs = 1.0 / (
361
+ self.text_rope_theta ** (torch.arange(0, head_dim, 2, device=device).float() / head_dim)
362
+ )
363
+ positions = torch.arange(0, length, device=device).float().unsqueeze(1)
364
+ angles = positions * freqs.unsqueeze(0)
365
+ freqs_cis = torch.polar(torch.ones_like(angles), angles)
366
+ self._precompute_pos_txt[length] = freqs_cis
367
+ return freqs_cis
368
+
369
+ def _initialize_weights(self) -> None:
370
+ weight = self.s_embedder.proj.weight.data
371
+ nn.init.xavier_uniform_(weight.view([weight.shape[0], -1]))
372
+ nn.init.constant_(self.s_embedder.proj.bias, 0)
373
+ nn.init.normal_(self.t_embedder.mlp[0].weight, std=0.02)
374
+ nn.init.normal_(self.t_embedder.mlp[2].weight, std=0.02)
375
+ nn.init.zeros_(self.final_layer.linear.weight)
376
+ nn.init.zeros_(self.final_layer.linear.bias)
377
+
378
+ def _build_joint_attn_mask(
379
+ self,
380
+ encoder_attention_mask: Optional[torch.Tensor],
381
+ batch_size: int,
382
+ num_img_tokens: int,
383
+ num_txt_tokens: int,
384
+ device: torch.device,
385
+ ) -> Optional[torch.Tensor]:
386
+ if encoder_attention_mask is None:
387
+ return None
388
+ mask = encoder_attention_mask
389
+ while mask.dim() > 2 and mask.size(1) == 1:
390
+ mask = mask.squeeze(1)
391
+ if mask.dim() == 3 and mask.size(1) == 1:
392
+ mask = mask.squeeze(1)
393
+ if mask.dim() != 2:
394
+ return None
395
+ pad = mask == 0
396
+ pad_img = torch.zeros((batch_size, num_img_tokens), dtype=torch.bool, device=device)
397
+ return torch.cat([pad[:, :num_txt_tokens], pad_img], dim=1).view(batch_size, 1, 1, num_txt_tokens + num_img_tokens)
398
+
399
+ def forward(
400
+ self,
401
+ sample: torch.Tensor,
402
+ timestep: Union[torch.Tensor, float],
403
+ encoder_hidden_states: torch.Tensor,
404
+ encoder_attention_mask: Optional[torch.Tensor] = None,
405
+ return_dict: bool = True,
406
+ ) -> Union[Transformer2DModelOutput, Tuple[torch.Tensor]]:
407
+ if sample.dim() != 4:
408
+ raise ValueError("PixelDiTT2ITransformer2DModel expects sample of shape [B,C,H,W]")
409
+ batch_size, _, height, width = sample.shape
410
+ if height % self.patch_size != 0 or width % self.patch_size != 0:
411
+ raise ValueError("Image height and width must be divisible by patch_size.")
412
+
413
+ timestep = torch.as_tensor(timestep, device=sample.device)
414
+ if timestep.ndim == 0:
415
+ timestep = timestep.repeat(batch_size)
416
+ else:
417
+ timestep = timestep.reshape(-1)
418
+ if timestep.shape[0] == 1 and batch_size > 1:
419
+ timestep = timestep.repeat(batch_size)
420
+
421
+ if encoder_hidden_states.dim() == 4:
422
+ encoder_hidden_states = encoder_hidden_states.squeeze(1)
423
+ if encoder_hidden_states.dim() != 3:
424
+ raise ValueError("encoder_hidden_states must be [B, L, D]")
425
+
426
+ height_tokens = height // self.patch_size
427
+ width_tokens = width // self.patch_size
428
+ num_img_tokens = height_tokens * width_tokens
429
+
430
+ pos = self._fetch_pos(height_tokens, width_tokens, sample.device)
431
+ x_patches = F.unfold(sample, kernel_size=self.patch_size, stride=self.patch_size).transpose(1, 2)
432
+ t_emb = self.t_embedder(timestep.view(-1)).view(batch_size, -1, self.hidden_size)
433
+
434
+ txt_length = min(encoder_hidden_states.shape[1], self.txt_max_length)
435
+ text_states = encoder_hidden_states[:, :txt_length, :]
436
+ text_states = self.y_embedder(text_states).view(batch_size, txt_length, self.hidden_size)
437
+ text_states = text_states + self.y_pos_embedding[:, :txt_length, :].to(text_states.dtype)
438
+ conditioning = F.silu(t_emb)
439
+
440
+ pos_txt = self._fetch_pos_text(txt_length, sample.device) if self.use_text_rope else None
441
+ attn_mask = self._build_joint_attn_mask(
442
+ encoder_attention_mask, batch_size, num_img_tokens, txt_length, sample.device
443
+ )
444
+
445
+ patch_states = self.s_embedder(x_patches)
446
+ for block in self.patch_blocks:
447
+ if self.training and self.gradient_checkpointing:
448
+
449
+ def custom_forward(img_states, txt_states, cond, position_img, position_txt, mask):
450
+ return block(img_states, txt_states, cond, position_img, position_txt, mask)
451
+
452
+ patch_states, text_states = torch.utils.checkpoint.checkpoint(
453
+ custom_forward,
454
+ patch_states,
455
+ text_states,
456
+ conditioning,
457
+ pos,
458
+ pos_txt,
459
+ attn_mask,
460
+ use_reentrant=False,
461
+ )
462
+ else:
463
+ patch_states, text_states = block(
464
+ patch_states, text_states, conditioning, pos, pos_txt, attn_mask
465
+ )
466
+
467
+ patch_states = F.silu(t_emb + patch_states)
468
+ if patch_states.shape[1] != num_img_tokens:
469
+ if patch_states.shape[1] > num_img_tokens:
470
+ patch_states = patch_states[:, :num_img_tokens, :]
471
+ else:
472
+ pad_len = num_img_tokens - patch_states.shape[1]
473
+ patch_states = torch.cat(
474
+ [patch_states, patch_states.new_zeros(batch_size, pad_len, patch_states.shape[2])], dim=1
475
+ )
476
+
477
+ conditioning_states = patch_states.reshape(batch_size * num_img_tokens, self.hidden_size)
478
+ pixel_states = self.pixel_embedder(sample, img_height=height, img_width=width, patch_size=self.patch_size)
479
+ for block in self.pixel_blocks:
480
+ if self.training and self.gradient_checkpointing:
481
+
482
+ def custom_forward(hidden_states, cond):
483
+ return block(hidden_states, cond, height, width, self.patch_size)
484
+
485
+ pixel_states = torch.utils.checkpoint.checkpoint(
486
+ custom_forward, pixel_states, conditioning_states, use_reentrant=False
487
+ )
488
+ else:
489
+ pixel_states = block(pixel_states, conditioning_states, height, width, self.patch_size)
490
+
491
+ pixel_states = self.final_layer(pixel_states)
492
+ patch_area = self.patch_size * self.patch_size
493
+ pixel_states = pixel_states.view(batch_size, num_img_tokens, patch_area, self.out_channels).permute(0, 3, 2, 1)
494
+ pixel_states = pixel_states.contiguous().view(batch_size, self.out_channels * patch_area, num_img_tokens)
495
+ output = F.fold(pixel_states, (height, width), kernel_size=self.patch_size, stride=self.patch_size)
496
+
497
+ if not return_dict:
498
+ return (output,)
499
+ return Transformer2DModelOutput(sample=output)
500
+
501
+ @classmethod
502
+ def from_pixeldit_t2i_checkpoint(
503
+ cls,
504
+ checkpoint_path: str,
505
+ model_type: Literal["pixeldit-t2i-1300m"] = "pixeldit-t2i-1300m",
506
+ map_location: str = "cpu",
507
+ strict: bool = True,
508
+ ) -> Tuple["PixelDiTT2ITransformer2DModel", Dict[str, object]]:
509
+ if model_type not in PIXELDIT_T2I_PRESET_CONFIGS:
510
+ raise ValueError(f"Unknown PixelDiT T2I preset '{model_type}'.")
511
+
512
+ if checkpoint_path.endswith(".safetensors"):
513
+ try:
514
+ from safetensors.torch import load_file
515
+ except ImportError as error:
516
+ raise ImportError("Install safetensors to load .safetensors checkpoints.") from error
517
+ state_dict = load_file(checkpoint_path, device=map_location)
518
+ else:
519
+ loaded = torch.load(checkpoint_path, map_location=map_location, weights_only=False)
520
+ if isinstance(loaded, Mapping):
521
+ state_dict = loaded
522
+ for key in ("state_dict", "model", "module", "denoiser"):
523
+ if key in state_dict and isinstance(state_dict[key], dict):
524
+ state_dict = state_dict[key]
525
+ break
526
+ else:
527
+ raise ValueError("Unsupported checkpoint format.")
528
+
529
+ config = dict(PIXELDIT_T2I_PRESET_CONFIGS[model_type])
530
+ config["model_type"] = model_type
531
+ model = cls(**config)
532
+ model.load_state_dict(remap_t2i_legacy_state_dict(state_dict), strict=strict)
533
+ metadata = {"checkpoint_path": checkpoint_path, "model_type": model_type}
534
+ return model, metadata
535
+
536
+
537
+ PixelDiTT2IDiffusersModel = PixelDiTT2ITransformer2DModel
PixelDiT-XL-16-256/demo.png ADDED

Git LFS Details

  • SHA256: dfed0852cbe4af2a2121dbb20fa48a8bfb9900f346c68fa6bc8b92c07c8e1ee8
  • Pointer size: 131 Bytes
  • Size of remote file: 110 kB
PixelDiT-XL-16-256/model_index.json ADDED
@@ -0,0 +1,1017 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "_class_name": [
3
+ "pipeline",
4
+ "PixelDiTPipeline"
5
+ ],
6
+ "_diffusers_version": "0.35.1",
7
+ "id2label": {
8
+ "0": "tench, Tinca tinca",
9
+ "1": "goldfish, Carassius auratus",
10
+ "10": "brambling, Fringilla montifringilla",
11
+ "100": "black swan, Cygnus atratus",
12
+ "101": "tusker",
13
+ "102": "echidna, spiny anteater, anteater",
14
+ "103": "platypus, duckbill, duckbilled platypus, duck-billed platypus, Ornithorhynchus anatinus",
15
+ "104": "wallaby, brush kangaroo",
16
+ "105": "koala, koala bear, kangaroo bear, native bear, Phascolarctos cinereus",
17
+ "106": "wombat",
18
+ "107": "jellyfish",
19
+ "108": "sea anemone, anemone",
20
+ "109": "brain coral",
21
+ "11": "goldfinch, Carduelis carduelis",
22
+ "110": "flatworm, platyhelminth",
23
+ "111": "nematode, nematode worm, roundworm",
24
+ "112": "conch",
25
+ "113": "snail",
26
+ "114": "slug",
27
+ "115": "sea slug, nudibranch",
28
+ "116": "chiton, coat-of-mail shell, sea cradle, polyplacophore",
29
+ "117": "chambered nautilus, pearly nautilus, nautilus",
30
+ "118": "Dungeness crab, Cancer magister",
31
+ "119": "rock crab, Cancer irroratus",
32
+ "12": "house finch, linnet, Carpodacus mexicanus",
33
+ "120": "fiddler crab",
34
+ "121": "king crab, Alaska crab, Alaskan king crab, Alaska king crab, Paralithodes camtschatica",
35
+ "122": "American lobster, Northern lobster, Maine lobster, Homarus americanus",
36
+ "123": "spiny lobster, langouste, rock lobster, crawfish, crayfish, sea crawfish",
37
+ "124": "crayfish, crawfish, crawdad, crawdaddy",
38
+ "125": "hermit crab",
39
+ "126": "isopod",
40
+ "127": "white stork, Ciconia ciconia",
41
+ "128": "black stork, Ciconia nigra",
42
+ "129": "spoonbill",
43
+ "13": "junco, snowbird",
44
+ "130": "flamingo",
45
+ "131": "little blue heron, Egretta caerulea",
46
+ "132": "American egret, great white heron, Egretta albus",
47
+ "133": "bittern",
48
+ "134": "crane",
49
+ "135": "limpkin, Aramus pictus",
50
+ "136": "European gallinule, Porphyrio porphyrio",
51
+ "137": "American coot, marsh hen, mud hen, water hen, Fulica americana",
52
+ "138": "bustard",
53
+ "139": "ruddy turnstone, Arenaria interpres",
54
+ "14": "indigo bunting, indigo finch, indigo bird, Passerina cyanea",
55
+ "140": "red-backed sandpiper, dunlin, Erolia alpina",
56
+ "141": "redshank, Tringa totanus",
57
+ "142": "dowitcher",
58
+ "143": "oystercatcher, oyster catcher",
59
+ "144": "pelican",
60
+ "145": "king penguin, Aptenodytes patagonica",
61
+ "146": "albatross, mollymawk",
62
+ "147": "grey whale, gray whale, devilfish, Eschrichtius gibbosus, Eschrichtius robustus",
63
+ "148": "killer whale, killer, orca, grampus, sea wolf, Orcinus orca",
64
+ "149": "dugong, Dugong dugon",
65
+ "15": "robin, American robin, Turdus migratorius",
66
+ "150": "sea lion",
67
+ "151": "Chihuahua",
68
+ "152": "Japanese spaniel",
69
+ "153": "Maltese dog, Maltese terrier, Maltese",
70
+ "154": "Pekinese, Pekingese, Peke",
71
+ "155": "Shih-Tzu",
72
+ "156": "Blenheim spaniel",
73
+ "157": "papillon",
74
+ "158": "toy terrier",
75
+ "159": "Rhodesian ridgeback",
76
+ "16": "bulbul",
77
+ "160": "Afghan hound, Afghan",
78
+ "161": "basset, basset hound",
79
+ "162": "beagle",
80
+ "163": "bloodhound, sleuthhound",
81
+ "164": "bluetick",
82
+ "165": "black-and-tan coonhound",
83
+ "166": "Walker hound, Walker foxhound",
84
+ "167": "English foxhound",
85
+ "168": "redbone",
86
+ "169": "borzoi, Russian wolfhound",
87
+ "17": "jay",
88
+ "170": "Irish wolfhound",
89
+ "171": "Italian greyhound",
90
+ "172": "whippet",
91
+ "173": "Ibizan hound, Ibizan Podenco",
92
+ "174": "Norwegian elkhound, elkhound",
93
+ "175": "otterhound, otter hound",
94
+ "176": "Saluki, gazelle hound",
95
+ "177": "Scottish deerhound, deerhound",
96
+ "178": "Weimaraner",
97
+ "179": "Staffordshire bullterrier, Staffordshire bull terrier",
98
+ "18": "magpie",
99
+ "180": "American Staffordshire terrier, Staffordshire terrier, American pit bull terrier, pit bull terrier",
100
+ "181": "Bedlington terrier",
101
+ "182": "Border terrier",
102
+ "183": "Kerry blue terrier",
103
+ "184": "Irish terrier",
104
+ "185": "Norfolk terrier",
105
+ "186": "Norwich terrier",
106
+ "187": "Yorkshire terrier",
107
+ "188": "wire-haired fox terrier",
108
+ "189": "Lakeland terrier",
109
+ "19": "chickadee",
110
+ "190": "Sealyham terrier, Sealyham",
111
+ "191": "Airedale, Airedale terrier",
112
+ "192": "cairn, cairn terrier",
113
+ "193": "Australian terrier",
114
+ "194": "Dandie Dinmont, Dandie Dinmont terrier",
115
+ "195": "Boston bull, Boston terrier",
116
+ "196": "miniature schnauzer",
117
+ "197": "giant schnauzer",
118
+ "198": "standard schnauzer",
119
+ "199": "Scotch terrier, Scottish terrier, Scottie",
120
+ "2": "great white shark, white shark, man-eater, man-eating shark, Carcharodon carcharias",
121
+ "20": "water ouzel, dipper",
122
+ "200": "Tibetan terrier, chrysanthemum dog",
123
+ "201": "silky terrier, Sydney silky",
124
+ "202": "soft-coated wheaten terrier",
125
+ "203": "West Highland white terrier",
126
+ "204": "Lhasa, Lhasa apso",
127
+ "205": "flat-coated retriever",
128
+ "206": "curly-coated retriever",
129
+ "207": "golden retriever",
130
+ "208": "Labrador retriever",
131
+ "209": "Chesapeake Bay retriever",
132
+ "21": "kite",
133
+ "210": "German short-haired pointer",
134
+ "211": "vizsla, Hungarian pointer",
135
+ "212": "English setter",
136
+ "213": "Irish setter, red setter",
137
+ "214": "Gordon setter",
138
+ "215": "Brittany spaniel",
139
+ "216": "clumber, clumber spaniel",
140
+ "217": "English springer, English springer spaniel",
141
+ "218": "Welsh springer spaniel",
142
+ "219": "cocker spaniel, English cocker spaniel, cocker",
143
+ "22": "bald eagle, American eagle, Haliaeetus leucocephalus",
144
+ "220": "Sussex spaniel",
145
+ "221": "Irish water spaniel",
146
+ "222": "kuvasz",
147
+ "223": "schipperke",
148
+ "224": "groenendael",
149
+ "225": "malinois",
150
+ "226": "briard",
151
+ "227": "kelpie",
152
+ "228": "komondor",
153
+ "229": "Old English sheepdog, bobtail",
154
+ "23": "vulture",
155
+ "230": "Shetland sheepdog, Shetland sheep dog, Shetland",
156
+ "231": "collie",
157
+ "232": "Border collie",
158
+ "233": "Bouvier des Flandres, Bouviers des Flandres",
159
+ "234": "Rottweiler",
160
+ "235": "German shepherd, German shepherd dog, German police dog, alsatian",
161
+ "236": "Doberman, Doberman pinscher",
162
+ "237": "miniature pinscher",
163
+ "238": "Greater Swiss Mountain dog",
164
+ "239": "Bernese mountain dog",
165
+ "24": "great grey owl, great gray owl, Strix nebulosa",
166
+ "240": "Appenzeller",
167
+ "241": "EntleBucher",
168
+ "242": "boxer",
169
+ "243": "bull mastiff",
170
+ "244": "Tibetan mastiff",
171
+ "245": "French bulldog",
172
+ "246": "Great Dane",
173
+ "247": "Saint Bernard, St Bernard",
174
+ "248": "Eskimo dog, husky",
175
+ "249": "malamute, malemute, Alaskan malamute",
176
+ "25": "European fire salamander, Salamandra salamandra",
177
+ "250": "Siberian husky",
178
+ "251": "dalmatian, coach dog, carriage dog",
179
+ "252": "affenpinscher, monkey pinscher, monkey dog",
180
+ "253": "basenji",
181
+ "254": "pug, pug-dog",
182
+ "255": "Leonberg",
183
+ "256": "Newfoundland, Newfoundland dog",
184
+ "257": "Great Pyrenees",
185
+ "258": "Samoyed, Samoyede",
186
+ "259": "Pomeranian",
187
+ "26": "common newt, Triturus vulgaris",
188
+ "260": "chow, chow chow",
189
+ "261": "keeshond",
190
+ "262": "Brabancon griffon",
191
+ "263": "Pembroke, Pembroke Welsh corgi",
192
+ "264": "Cardigan, Cardigan Welsh corgi",
193
+ "265": "toy poodle",
194
+ "266": "miniature poodle",
195
+ "267": "standard poodle",
196
+ "268": "Mexican hairless",
197
+ "269": "timber wolf, grey wolf, gray wolf, Canis lupus",
198
+ "27": "eft",
199
+ "270": "white wolf, Arctic wolf, Canis lupus tundrarum",
200
+ "271": "red wolf, maned wolf, Canis rufus, Canis niger",
201
+ "272": "coyote, prairie wolf, brush wolf, Canis latrans",
202
+ "273": "dingo, warrigal, warragal, Canis dingo",
203
+ "274": "dhole, Cuon alpinus",
204
+ "275": "African hunting dog, hyena dog, Cape hunting dog, Lycaon pictus",
205
+ "276": "hyena, hyaena",
206
+ "277": "red fox, Vulpes vulpes",
207
+ "278": "kit fox, Vulpes macrotis",
208
+ "279": "Arctic fox, white fox, Alopex lagopus",
209
+ "28": "spotted salamander, Ambystoma maculatum",
210
+ "280": "grey fox, gray fox, Urocyon cinereoargenteus",
211
+ "281": "tabby, tabby cat",
212
+ "282": "tiger cat",
213
+ "283": "Persian cat",
214
+ "284": "Siamese cat, Siamese",
215
+ "285": "Egyptian cat",
216
+ "286": "cougar, puma, catamount, mountain lion, painter, panther, Felis concolor",
217
+ "287": "lynx, catamount",
218
+ "288": "leopard, Panthera pardus",
219
+ "289": "snow leopard, ounce, Panthera uncia",
220
+ "29": "axolotl, mud puppy, Ambystoma mexicanum",
221
+ "290": "jaguar, panther, Panthera onca, Felis onca",
222
+ "291": "lion, king of beasts, Panthera leo",
223
+ "292": "tiger, Panthera tigris",
224
+ "293": "cheetah, chetah, Acinonyx jubatus",
225
+ "294": "brown bear, bruin, Ursus arctos",
226
+ "295": "American black bear, black bear, Ursus americanus, Euarctos americanus",
227
+ "296": "ice bear, polar bear, Ursus Maritimus, Thalarctos maritimus",
228
+ "297": "sloth bear, Melursus ursinus, Ursus ursinus",
229
+ "298": "mongoose",
230
+ "299": "meerkat, mierkat",
231
+ "3": "tiger shark, Galeocerdo cuvieri",
232
+ "30": "bullfrog, Rana catesbeiana",
233
+ "300": "tiger beetle",
234
+ "301": "ladybug, ladybeetle, lady beetle, ladybird, ladybird beetle",
235
+ "302": "ground beetle, carabid beetle",
236
+ "303": "long-horned beetle, longicorn, longicorn beetle",
237
+ "304": "leaf beetle, chrysomelid",
238
+ "305": "dung beetle",
239
+ "306": "rhinoceros beetle",
240
+ "307": "weevil",
241
+ "308": "fly",
242
+ "309": "bee",
243
+ "31": "tree frog, tree-frog",
244
+ "310": "ant, emmet, pismire",
245
+ "311": "grasshopper, hopper",
246
+ "312": "cricket",
247
+ "313": "walking stick, walkingstick, stick insect",
248
+ "314": "cockroach, roach",
249
+ "315": "mantis, mantid",
250
+ "316": "cicada, cicala",
251
+ "317": "leafhopper",
252
+ "318": "lacewing, lacewing fly",
253
+ "319": "dragonfly, darning needle, devils darning needle, sewing needle, snake feeder, snake doctor, mosquito hawk, skeeter hawk",
254
+ "32": "tailed frog, bell toad, ribbed toad, tailed toad, Ascaphus trui",
255
+ "320": "damselfly",
256
+ "321": "admiral",
257
+ "322": "ringlet, ringlet butterfly",
258
+ "323": "monarch, monarch butterfly, milkweed butterfly, Danaus plexippus",
259
+ "324": "cabbage butterfly",
260
+ "325": "sulphur butterfly, sulfur butterfly",
261
+ "326": "lycaenid, lycaenid butterfly",
262
+ "327": "starfish, sea star",
263
+ "328": "sea urchin",
264
+ "329": "sea cucumber, holothurian",
265
+ "33": "loggerhead, loggerhead turtle, Caretta caretta",
266
+ "330": "wood rabbit, cottontail, cottontail rabbit",
267
+ "331": "hare",
268
+ "332": "Angora, Angora rabbit",
269
+ "333": "hamster",
270
+ "334": "porcupine, hedgehog",
271
+ "335": "fox squirrel, eastern fox squirrel, Sciurus niger",
272
+ "336": "marmot",
273
+ "337": "beaver",
274
+ "338": "guinea pig, Cavia cobaya",
275
+ "339": "sorrel",
276
+ "34": "leatherback turtle, leatherback, leathery turtle, Dermochelys coriacea",
277
+ "340": "zebra",
278
+ "341": "hog, pig, grunter, squealer, Sus scrofa",
279
+ "342": "wild boar, boar, Sus scrofa",
280
+ "343": "warthog",
281
+ "344": "hippopotamus, hippo, river horse, Hippopotamus amphibius",
282
+ "345": "ox",
283
+ "346": "water buffalo, water ox, Asiatic buffalo, Bubalus bubalis",
284
+ "347": "bison",
285
+ "348": "ram, tup",
286
+ "349": "bighorn, bighorn sheep, cimarron, Rocky Mountain bighorn, Rocky Mountain sheep, Ovis canadensis",
287
+ "35": "mud turtle",
288
+ "350": "ibex, Capra ibex",
289
+ "351": "hartebeest",
290
+ "352": "impala, Aepyceros melampus",
291
+ "353": "gazelle",
292
+ "354": "Arabian camel, dromedary, Camelus dromedarius",
293
+ "355": "llama",
294
+ "356": "weasel",
295
+ "357": "mink",
296
+ "358": "polecat, fitch, foulmart, foumart, Mustela putorius",
297
+ "359": "black-footed ferret, ferret, Mustela nigripes",
298
+ "36": "terrapin",
299
+ "360": "otter",
300
+ "361": "skunk, polecat, wood pussy",
301
+ "362": "badger",
302
+ "363": "armadillo",
303
+ "364": "three-toed sloth, ai, Bradypus tridactylus",
304
+ "365": "orangutan, orang, orangutang, Pongo pygmaeus",
305
+ "366": "gorilla, Gorilla gorilla",
306
+ "367": "chimpanzee, chimp, Pan troglodytes",
307
+ "368": "gibbon, Hylobates lar",
308
+ "369": "siamang, Hylobates syndactylus, Symphalangus syndactylus",
309
+ "37": "box turtle, box tortoise",
310
+ "370": "guenon, guenon monkey",
311
+ "371": "patas, hussar monkey, Erythrocebus patas",
312
+ "372": "baboon",
313
+ "373": "macaque",
314
+ "374": "langur",
315
+ "375": "colobus, colobus monkey",
316
+ "376": "proboscis monkey, Nasalis larvatus",
317
+ "377": "marmoset",
318
+ "378": "capuchin, ringtail, Cebus capucinus",
319
+ "379": "howler monkey, howler",
320
+ "38": "banded gecko",
321
+ "380": "titi, titi monkey",
322
+ "381": "spider monkey, Ateles geoffroyi",
323
+ "382": "squirrel monkey, Saimiri sciureus",
324
+ "383": "Madagascar cat, ring-tailed lemur, Lemur catta",
325
+ "384": "indri, indris, Indri indri, Indri brevicaudatus",
326
+ "385": "Indian elephant, Elephas maximus",
327
+ "386": "African elephant, Loxodonta africana",
328
+ "387": "lesser panda, red panda, panda, bear cat, cat bear, Ailurus fulgens",
329
+ "388": "giant panda, panda, panda bear, coon bear, Ailuropoda melanoleuca",
330
+ "389": "barracouta, snoek",
331
+ "39": "common iguana, iguana, Iguana iguana",
332
+ "390": "eel",
333
+ "391": "coho, cohoe, coho salmon, blue jack, silver salmon, Oncorhynchus kisutch",
334
+ "392": "rock beauty, Holocanthus tricolor",
335
+ "393": "anemone fish",
336
+ "394": "sturgeon",
337
+ "395": "gar, garfish, garpike, billfish, Lepisosteus osseus",
338
+ "396": "lionfish",
339
+ "397": "puffer, pufferfish, blowfish, globefish",
340
+ "398": "abacus",
341
+ "399": "abaya",
342
+ "4": "hammerhead, hammerhead shark",
343
+ "40": "American chameleon, anole, Anolis carolinensis",
344
+ "400": "academic gown, academic robe, judge robe",
345
+ "401": "accordion, piano accordion, squeeze box",
346
+ "402": "acoustic guitar",
347
+ "403": "aircraft carrier, carrier, flattop, attack aircraft carrier",
348
+ "404": "airliner",
349
+ "405": "airship, dirigible",
350
+ "406": "altar",
351
+ "407": "ambulance",
352
+ "408": "amphibian, amphibious vehicle",
353
+ "409": "analog clock",
354
+ "41": "whiptail, whiptail lizard",
355
+ "410": "apiary, bee house",
356
+ "411": "apron",
357
+ "412": "ashcan, trash can, garbage can, wastebin, ash bin, ash-bin, ashbin, dustbin, trash barrel, trash bin",
358
+ "413": "assault rifle, assault gun",
359
+ "414": "backpack, back pack, knapsack, packsack, rucksack, haversack",
360
+ "415": "bakery, bakeshop, bakehouse",
361
+ "416": "balance beam, beam",
362
+ "417": "balloon",
363
+ "418": "ballpoint, ballpoint pen, ballpen, Biro",
364
+ "419": "Band Aid",
365
+ "42": "agama",
366
+ "420": "banjo",
367
+ "421": "bannister, banister, balustrade, balusters, handrail",
368
+ "422": "barbell",
369
+ "423": "barber chair",
370
+ "424": "barbershop",
371
+ "425": "barn",
372
+ "426": "barometer",
373
+ "427": "barrel, cask",
374
+ "428": "barrow, garden cart, lawn cart, wheelbarrow",
375
+ "429": "baseball",
376
+ "43": "frilled lizard, Chlamydosaurus kingi",
377
+ "430": "basketball",
378
+ "431": "bassinet",
379
+ "432": "bassoon",
380
+ "433": "bathing cap, swimming cap",
381
+ "434": "bath towel",
382
+ "435": "bathtub, bathing tub, bath, tub",
383
+ "436": "beach wagon, station wagon, wagon, estate car, beach waggon, station waggon, waggon",
384
+ "437": "beacon, lighthouse, beacon light, pharos",
385
+ "438": "beaker",
386
+ "439": "bearskin, busby, shako",
387
+ "44": "alligator lizard",
388
+ "440": "beer bottle",
389
+ "441": "beer glass",
390
+ "442": "bell cote, bell cot",
391
+ "443": "bib",
392
+ "444": "bicycle-built-for-two, tandem bicycle, tandem",
393
+ "445": "bikini, two-piece",
394
+ "446": "binder, ring-binder",
395
+ "447": "binoculars, field glasses, opera glasses",
396
+ "448": "birdhouse",
397
+ "449": "boathouse",
398
+ "45": "Gila monster, Heloderma suspectum",
399
+ "450": "bobsled, bobsleigh, bob",
400
+ "451": "bolo tie, bolo, bola tie, bola",
401
+ "452": "bonnet, poke bonnet",
402
+ "453": "bookcase",
403
+ "454": "bookshop, bookstore, bookstall",
404
+ "455": "bottlecap",
405
+ "456": "bow",
406
+ "457": "bow tie, bow-tie, bowtie",
407
+ "458": "brass, memorial tablet, plaque",
408
+ "459": "brassiere, bra, bandeau",
409
+ "46": "green lizard, Lacerta viridis",
410
+ "460": "breakwater, groin, groyne, mole, bulwark, seawall, jetty",
411
+ "461": "breastplate, aegis, egis",
412
+ "462": "broom",
413
+ "463": "bucket, pail",
414
+ "464": "buckle",
415
+ "465": "bulletproof vest",
416
+ "466": "bullet train, bullet",
417
+ "467": "butcher shop, meat market",
418
+ "468": "cab, hack, taxi, taxicab",
419
+ "469": "caldron, cauldron",
420
+ "47": "African chameleon, Chamaeleo chamaeleon",
421
+ "470": "candle, taper, wax light",
422
+ "471": "cannon",
423
+ "472": "canoe",
424
+ "473": "can opener, tin opener",
425
+ "474": "cardigan",
426
+ "475": "car mirror",
427
+ "476": "carousel, carrousel, merry-go-round, roundabout, whirligig",
428
+ "477": "carpenters kit, tool kit",
429
+ "478": "carton",
430
+ "479": "car wheel",
431
+ "48": "Komodo dragon, Komodo lizard, dragon lizard, giant lizard, Varanus komodoensis",
432
+ "480": "cash machine, cash dispenser, automated teller machine, automatic teller machine, automated teller, automatic teller, ATM",
433
+ "481": "cassette",
434
+ "482": "cassette player",
435
+ "483": "castle",
436
+ "484": "catamaran",
437
+ "485": "CD player",
438
+ "486": "cello, violoncello",
439
+ "487": "cellular telephone, cellular phone, cellphone, cell, mobile phone",
440
+ "488": "chain",
441
+ "489": "chainlink fence",
442
+ "49": "African crocodile, Nile crocodile, Crocodylus niloticus",
443
+ "490": "chain mail, ring mail, mail, chain armor, chain armour, ring armor, ring armour",
444
+ "491": "chain saw, chainsaw",
445
+ "492": "chest",
446
+ "493": "chiffonier, commode",
447
+ "494": "chime, bell, gong",
448
+ "495": "china cabinet, china closet",
449
+ "496": "Christmas stocking",
450
+ "497": "church, church building",
451
+ "498": "cinema, movie theater, movie theatre, movie house, picture palace",
452
+ "499": "cleaver, meat cleaver, chopper",
453
+ "5": "electric ray, crampfish, numbfish, torpedo",
454
+ "50": "American alligator, Alligator mississipiensis",
455
+ "500": "cliff dwelling",
456
+ "501": "cloak",
457
+ "502": "clog, geta, patten, sabot",
458
+ "503": "cocktail shaker",
459
+ "504": "coffee mug",
460
+ "505": "coffeepot",
461
+ "506": "coil, spiral, volute, whorl, helix",
462
+ "507": "combination lock",
463
+ "508": "computer keyboard, keypad",
464
+ "509": "confectionery, confectionary, candy store",
465
+ "51": "triceratops",
466
+ "510": "container ship, containership, container vessel",
467
+ "511": "convertible",
468
+ "512": "corkscrew, bottle screw",
469
+ "513": "cornet, horn, trumpet, trump",
470
+ "514": "cowboy boot",
471
+ "515": "cowboy hat, ten-gallon hat",
472
+ "516": "cradle",
473
+ "517": "crane",
474
+ "518": "crash helmet",
475
+ "519": "crate",
476
+ "52": "thunder snake, worm snake, Carphophis amoenus",
477
+ "520": "crib, cot",
478
+ "521": "Crock Pot",
479
+ "522": "croquet ball",
480
+ "523": "crutch",
481
+ "524": "cuirass",
482
+ "525": "dam, dike, dyke",
483
+ "526": "desk",
484
+ "527": "desktop computer",
485
+ "528": "dial telephone, dial phone",
486
+ "529": "diaper, nappy, napkin",
487
+ "53": "ringneck snake, ring-necked snake, ring snake",
488
+ "530": "digital clock",
489
+ "531": "digital watch",
490
+ "532": "dining table, board",
491
+ "533": "dishrag, dishcloth",
492
+ "534": "dishwasher, dish washer, dishwashing machine",
493
+ "535": "disk brake, disc brake",
494
+ "536": "dock, dockage, docking facility",
495
+ "537": "dogsled, dog sled, dog sleigh",
496
+ "538": "dome",
497
+ "539": "doormat, welcome mat",
498
+ "54": "hognose snake, puff adder, sand viper",
499
+ "540": "drilling platform, offshore rig",
500
+ "541": "drum, membranophone, tympan",
501
+ "542": "drumstick",
502
+ "543": "dumbbell",
503
+ "544": "Dutch oven",
504
+ "545": "electric fan, blower",
505
+ "546": "electric guitar",
506
+ "547": "electric locomotive",
507
+ "548": "entertainment center",
508
+ "549": "envelope",
509
+ "55": "green snake, grass snake",
510
+ "550": "espresso maker",
511
+ "551": "face powder",
512
+ "552": "feather boa, boa",
513
+ "553": "file, file cabinet, filing cabinet",
514
+ "554": "fireboat",
515
+ "555": "fire engine, fire truck",
516
+ "556": "fire screen, fireguard",
517
+ "557": "flagpole, flagstaff",
518
+ "558": "flute, transverse flute",
519
+ "559": "folding chair",
520
+ "56": "king snake, kingsnake",
521
+ "560": "football helmet",
522
+ "561": "forklift",
523
+ "562": "fountain",
524
+ "563": "fountain pen",
525
+ "564": "four-poster",
526
+ "565": "freight car",
527
+ "566": "French horn, horn",
528
+ "567": "frying pan, frypan, skillet",
529
+ "568": "fur coat",
530
+ "569": "garbage truck, dustcart",
531
+ "57": "garter snake, grass snake",
532
+ "570": "gasmask, respirator, gas helmet",
533
+ "571": "gas pump, gasoline pump, petrol pump, island dispenser",
534
+ "572": "goblet",
535
+ "573": "go-kart",
536
+ "574": "golf ball",
537
+ "575": "golfcart, golf cart",
538
+ "576": "gondola",
539
+ "577": "gong, tam-tam",
540
+ "578": "gown",
541
+ "579": "grand piano, grand",
542
+ "58": "water snake",
543
+ "580": "greenhouse, nursery, glasshouse",
544
+ "581": "grille, radiator grille",
545
+ "582": "grocery store, grocery, food market, market",
546
+ "583": "guillotine",
547
+ "584": "hair slide",
548
+ "585": "hair spray",
549
+ "586": "half track",
550
+ "587": "hammer",
551
+ "588": "hamper",
552
+ "589": "hand blower, blow dryer, blow drier, hair dryer, hair drier",
553
+ "59": "vine snake",
554
+ "590": "hand-held computer, hand-held microcomputer",
555
+ "591": "handkerchief, hankie, hanky, hankey",
556
+ "592": "hard disc, hard disk, fixed disk",
557
+ "593": "harmonica, mouth organ, harp, mouth harp",
558
+ "594": "harp",
559
+ "595": "harvester, reaper",
560
+ "596": "hatchet",
561
+ "597": "holster",
562
+ "598": "home theater, home theatre",
563
+ "599": "honeycomb",
564
+ "6": "stingray",
565
+ "60": "night snake, Hypsiglena torquata",
566
+ "600": "hook, claw",
567
+ "601": "hoopskirt, crinoline",
568
+ "602": "horizontal bar, high bar",
569
+ "603": "horse cart, horse-cart",
570
+ "604": "hourglass",
571
+ "605": "iPod",
572
+ "606": "iron, smoothing iron",
573
+ "607": "jack-o-lantern",
574
+ "608": "jean, blue jean, denim",
575
+ "609": "jeep, landrover",
576
+ "61": "boa constrictor, Constrictor constrictor",
577
+ "610": "jersey, T-shirt, tee shirt",
578
+ "611": "jigsaw puzzle",
579
+ "612": "jinrikisha, ricksha, rickshaw",
580
+ "613": "joystick",
581
+ "614": "kimono",
582
+ "615": "knee pad",
583
+ "616": "knot",
584
+ "617": "lab coat, laboratory coat",
585
+ "618": "ladle",
586
+ "619": "lampshade, lamp shade",
587
+ "62": "rock python, rock snake, Python sebae",
588
+ "620": "laptop, laptop computer",
589
+ "621": "lawn mower, mower",
590
+ "622": "lens cap, lens cover",
591
+ "623": "letter opener, paper knife, paperknife",
592
+ "624": "library",
593
+ "625": "lifeboat",
594
+ "626": "lighter, light, igniter, ignitor",
595
+ "627": "limousine, limo",
596
+ "628": "liner, ocean liner",
597
+ "629": "lipstick, lip rouge",
598
+ "63": "Indian cobra, Naja naja",
599
+ "630": "Loafer",
600
+ "631": "lotion",
601
+ "632": "loudspeaker, speaker, speaker unit, loudspeaker system, speaker system",
602
+ "633": "loupe, jewelers loupe",
603
+ "634": "lumbermill, sawmill",
604
+ "635": "magnetic compass",
605
+ "636": "mailbag, postbag",
606
+ "637": "mailbox, letter box",
607
+ "638": "maillot",
608
+ "639": "maillot, tank suit",
609
+ "64": "green mamba",
610
+ "640": "manhole cover",
611
+ "641": "maraca",
612
+ "642": "marimba, xylophone",
613
+ "643": "mask",
614
+ "644": "matchstick",
615
+ "645": "maypole",
616
+ "646": "maze, labyrinth",
617
+ "647": "measuring cup",
618
+ "648": "medicine chest, medicine cabinet",
619
+ "649": "megalith, megalithic structure",
620
+ "65": "sea snake",
621
+ "650": "microphone, mike",
622
+ "651": "microwave, microwave oven",
623
+ "652": "military uniform",
624
+ "653": "milk can",
625
+ "654": "minibus",
626
+ "655": "miniskirt, mini",
627
+ "656": "minivan",
628
+ "657": "missile",
629
+ "658": "mitten",
630
+ "659": "mixing bowl",
631
+ "66": "horned viper, cerastes, sand viper, horned asp, Cerastes cornutus",
632
+ "660": "mobile home, manufactured home",
633
+ "661": "Model T",
634
+ "662": "modem",
635
+ "663": "monastery",
636
+ "664": "monitor",
637
+ "665": "moped",
638
+ "666": "mortar",
639
+ "667": "mortarboard",
640
+ "668": "mosque",
641
+ "669": "mosquito net",
642
+ "67": "diamondback, diamondback rattlesnake, Crotalus adamanteus",
643
+ "670": "motor scooter, scooter",
644
+ "671": "mountain bike, all-terrain bike, off-roader",
645
+ "672": "mountain tent",
646
+ "673": "mouse, computer mouse",
647
+ "674": "mousetrap",
648
+ "675": "moving van",
649
+ "676": "muzzle",
650
+ "677": "nail",
651
+ "678": "neck brace",
652
+ "679": "necklace",
653
+ "68": "sidewinder, horned rattlesnake, Crotalus cerastes",
654
+ "680": "nipple",
655
+ "681": "notebook, notebook computer",
656
+ "682": "obelisk",
657
+ "683": "oboe, hautboy, hautbois",
658
+ "684": "ocarina, sweet potato",
659
+ "685": "odometer, hodometer, mileometer, milometer",
660
+ "686": "oil filter",
661
+ "687": "organ, pipe organ",
662
+ "688": "oscilloscope, scope, cathode-ray oscilloscope, CRO",
663
+ "689": "overskirt",
664
+ "69": "trilobite",
665
+ "690": "oxcart",
666
+ "691": "oxygen mask",
667
+ "692": "packet",
668
+ "693": "paddle, boat paddle",
669
+ "694": "paddlewheel, paddle wheel",
670
+ "695": "padlock",
671
+ "696": "paintbrush",
672
+ "697": "pajama, pyjama, pjs, jammies",
673
+ "698": "palace",
674
+ "699": "panpipe, pandean pipe, syrinx",
675
+ "7": "cock",
676
+ "70": "harvestman, daddy longlegs, Phalangium opilio",
677
+ "700": "paper towel",
678
+ "701": "parachute, chute",
679
+ "702": "parallel bars, bars",
680
+ "703": "park bench",
681
+ "704": "parking meter",
682
+ "705": "passenger car, coach, carriage",
683
+ "706": "patio, terrace",
684
+ "707": "pay-phone, pay-station",
685
+ "708": "pedestal, plinth, footstall",
686
+ "709": "pencil box, pencil case",
687
+ "71": "scorpion",
688
+ "710": "pencil sharpener",
689
+ "711": "perfume, essence",
690
+ "712": "Petri dish",
691
+ "713": "photocopier",
692
+ "714": "pick, plectrum, plectron",
693
+ "715": "pickelhaube",
694
+ "716": "picket fence, paling",
695
+ "717": "pickup, pickup truck",
696
+ "718": "pier",
697
+ "719": "piggy bank, penny bank",
698
+ "72": "black and gold garden spider, Argiope aurantia",
699
+ "720": "pill bottle",
700
+ "721": "pillow",
701
+ "722": "ping-pong ball",
702
+ "723": "pinwheel",
703
+ "724": "pirate, pirate ship",
704
+ "725": "pitcher, ewer",
705
+ "726": "plane, carpenters plane, woodworking plane",
706
+ "727": "planetarium",
707
+ "728": "plastic bag",
708
+ "729": "plate rack",
709
+ "73": "barn spider, Araneus cavaticus",
710
+ "730": "plow, plough",
711
+ "731": "plunger, plumbers helper",
712
+ "732": "Polaroid camera, Polaroid Land camera",
713
+ "733": "pole",
714
+ "734": "police van, police wagon, paddy wagon, patrol wagon, wagon, black Maria",
715
+ "735": "poncho",
716
+ "736": "pool table, billiard table, snooker table",
717
+ "737": "pop bottle, soda bottle",
718
+ "738": "pot, flowerpot",
719
+ "739": "potters wheel",
720
+ "74": "garden spider, Aranea diademata",
721
+ "740": "power drill",
722
+ "741": "prayer rug, prayer mat",
723
+ "742": "printer",
724
+ "743": "prison, prison house",
725
+ "744": "projectile, missile",
726
+ "745": "projector",
727
+ "746": "puck, hockey puck",
728
+ "747": "punching bag, punch bag, punching ball, punchball",
729
+ "748": "purse",
730
+ "749": "quill, quill pen",
731
+ "75": "black widow, Latrodectus mactans",
732
+ "750": "quilt, comforter, comfort, puff",
733
+ "751": "racer, race car, racing car",
734
+ "752": "racket, racquet",
735
+ "753": "radiator",
736
+ "754": "radio, wireless",
737
+ "755": "radio telescope, radio reflector",
738
+ "756": "rain barrel",
739
+ "757": "recreational vehicle, RV, R.V.",
740
+ "758": "reel",
741
+ "759": "reflex camera",
742
+ "76": "tarantula",
743
+ "760": "refrigerator, icebox",
744
+ "761": "remote control, remote",
745
+ "762": "restaurant, eating house, eating place, eatery",
746
+ "763": "revolver, six-gun, six-shooter",
747
+ "764": "rifle",
748
+ "765": "rocking chair, rocker",
749
+ "766": "rotisserie",
750
+ "767": "rubber eraser, rubber, pencil eraser",
751
+ "768": "rugby ball",
752
+ "769": "rule, ruler",
753
+ "77": "wolf spider, hunting spider",
754
+ "770": "running shoe",
755
+ "771": "safe",
756
+ "772": "safety pin",
757
+ "773": "saltshaker, salt shaker",
758
+ "774": "sandal",
759
+ "775": "sarong",
760
+ "776": "sax, saxophone",
761
+ "777": "scabbard",
762
+ "778": "scale, weighing machine",
763
+ "779": "school bus",
764
+ "78": "tick",
765
+ "780": "schooner",
766
+ "781": "scoreboard",
767
+ "782": "screen, CRT screen",
768
+ "783": "screw",
769
+ "784": "screwdriver",
770
+ "785": "seat belt, seatbelt",
771
+ "786": "sewing machine",
772
+ "787": "shield, buckler",
773
+ "788": "shoe shop, shoe-shop, shoe store",
774
+ "789": "shoji",
775
+ "79": "centipede",
776
+ "790": "shopping basket",
777
+ "791": "shopping cart",
778
+ "792": "shovel",
779
+ "793": "shower cap",
780
+ "794": "shower curtain",
781
+ "795": "ski",
782
+ "796": "ski mask",
783
+ "797": "sleeping bag",
784
+ "798": "slide rule, slipstick",
785
+ "799": "sliding door",
786
+ "8": "hen",
787
+ "80": "black grouse",
788
+ "800": "slot, one-armed bandit",
789
+ "801": "snorkel",
790
+ "802": "snowmobile",
791
+ "803": "snowplow, snowplough",
792
+ "804": "soap dispenser",
793
+ "805": "soccer ball",
794
+ "806": "sock",
795
+ "807": "solar dish, solar collector, solar furnace",
796
+ "808": "sombrero",
797
+ "809": "soup bowl",
798
+ "81": "ptarmigan",
799
+ "810": "space bar",
800
+ "811": "space heater",
801
+ "812": "space shuttle",
802
+ "813": "spatula",
803
+ "814": "speedboat",
804
+ "815": "spider web, spiders web",
805
+ "816": "spindle",
806
+ "817": "sports car, sport car",
807
+ "818": "spotlight, spot",
808
+ "819": "stage",
809
+ "82": "ruffed grouse, partridge, Bonasa umbellus",
810
+ "820": "steam locomotive",
811
+ "821": "steel arch bridge",
812
+ "822": "steel drum",
813
+ "823": "stethoscope",
814
+ "824": "stole",
815
+ "825": "stone wall",
816
+ "826": "stopwatch, stop watch",
817
+ "827": "stove",
818
+ "828": "strainer",
819
+ "829": "streetcar, tram, tramcar, trolley, trolley car",
820
+ "83": "prairie chicken, prairie grouse, prairie fowl",
821
+ "830": "stretcher",
822
+ "831": "studio couch, day bed",
823
+ "832": "stupa, tope",
824
+ "833": "submarine, pigboat, sub, U-boat",
825
+ "834": "suit, suit of clothes",
826
+ "835": "sundial",
827
+ "836": "sunglass",
828
+ "837": "sunglasses, dark glasses, shades",
829
+ "838": "sunscreen, sunblock, sun blocker",
830
+ "839": "suspension bridge",
831
+ "84": "peacock",
832
+ "840": "swab, swob, mop",
833
+ "841": "sweatshirt",
834
+ "842": "swimming trunks, bathing trunks",
835
+ "843": "swing",
836
+ "844": "switch, electric switch, electrical switch",
837
+ "845": "syringe",
838
+ "846": "table lamp",
839
+ "847": "tank, army tank, armored combat vehicle, armoured combat vehicle",
840
+ "848": "tape player",
841
+ "849": "teapot",
842
+ "85": "quail",
843
+ "850": "teddy, teddy bear",
844
+ "851": "television, television system",
845
+ "852": "tennis ball",
846
+ "853": "thatch, thatched roof",
847
+ "854": "theater curtain, theatre curtain",
848
+ "855": "thimble",
849
+ "856": "thresher, thrasher, threshing machine",
850
+ "857": "throne",
851
+ "858": "tile roof",
852
+ "859": "toaster",
853
+ "86": "partridge",
854
+ "860": "tobacco shop, tobacconist shop, tobacconist",
855
+ "861": "toilet seat",
856
+ "862": "torch",
857
+ "863": "totem pole",
858
+ "864": "tow truck, tow car, wrecker",
859
+ "865": "toyshop",
860
+ "866": "tractor",
861
+ "867": "trailer truck, tractor trailer, trucking rig, rig, articulated lorry, semi",
862
+ "868": "tray",
863
+ "869": "trench coat",
864
+ "87": "African grey, African gray, Psittacus erithacus",
865
+ "870": "tricycle, trike, velocipede",
866
+ "871": "trimaran",
867
+ "872": "tripod",
868
+ "873": "triumphal arch",
869
+ "874": "trolleybus, trolley coach, trackless trolley",
870
+ "875": "trombone",
871
+ "876": "tub, vat",
872
+ "877": "turnstile",
873
+ "878": "typewriter keyboard",
874
+ "879": "umbrella",
875
+ "88": "macaw",
876
+ "880": "unicycle, monocycle",
877
+ "881": "upright, upright piano",
878
+ "882": "vacuum, vacuum cleaner",
879
+ "883": "vase",
880
+ "884": "vault",
881
+ "885": "velvet",
882
+ "886": "vending machine",
883
+ "887": "vestment",
884
+ "888": "viaduct",
885
+ "889": "violin, fiddle",
886
+ "89": "sulphur-crested cockatoo, Kakatoe galerita, Cacatua galerita",
887
+ "890": "volleyball",
888
+ "891": "waffle iron",
889
+ "892": "wall clock",
890
+ "893": "wallet, billfold, notecase, pocketbook",
891
+ "894": "wardrobe, closet, press",
892
+ "895": "warplane, military plane",
893
+ "896": "washbasin, handbasin, washbowl, lavabo, wash-hand basin",
894
+ "897": "washer, automatic washer, washing machine",
895
+ "898": "water bottle",
896
+ "899": "water jug",
897
+ "9": "ostrich, Struthio camelus",
898
+ "90": "lorikeet",
899
+ "900": "water tower",
900
+ "901": "whiskey jug",
901
+ "902": "whistle",
902
+ "903": "wig",
903
+ "904": "window screen",
904
+ "905": "window shade",
905
+ "906": "Windsor tie",
906
+ "907": "wine bottle",
907
+ "908": "wing",
908
+ "909": "wok",
909
+ "91": "coucal",
910
+ "910": "wooden spoon",
911
+ "911": "wool, woolen, woollen",
912
+ "912": "worm fence, snake fence, snake-rail fence, Virginia fence",
913
+ "913": "wreck",
914
+ "914": "yawl",
915
+ "915": "yurt",
916
+ "916": "web site, website, internet site, site",
917
+ "917": "comic book",
918
+ "918": "crossword puzzle, crossword",
919
+ "919": "street sign",
920
+ "92": "bee eater",
921
+ "920": "traffic light, traffic signal, stoplight",
922
+ "921": "book jacket, dust cover, dust jacket, dust wrapper",
923
+ "922": "menu",
924
+ "923": "plate",
925
+ "924": "guacamole",
926
+ "925": "consomme",
927
+ "926": "hot pot, hotpot",
928
+ "927": "trifle",
929
+ "928": "ice cream, icecream",
930
+ "929": "ice lolly, lolly, lollipop, popsicle",
931
+ "93": "hornbill",
932
+ "930": "French loaf",
933
+ "931": "bagel, beigel",
934
+ "932": "pretzel",
935
+ "933": "cheeseburger",
936
+ "934": "hotdog, hot dog, red hot",
937
+ "935": "mashed potato",
938
+ "936": "head cabbage",
939
+ "937": "broccoli",
940
+ "938": "cauliflower",
941
+ "939": "zucchini, courgette",
942
+ "94": "hummingbird",
943
+ "940": "spaghetti squash",
944
+ "941": "acorn squash",
945
+ "942": "butternut squash",
946
+ "943": "cucumber, cuke",
947
+ "944": "artichoke, globe artichoke",
948
+ "945": "bell pepper",
949
+ "946": "cardoon",
950
+ "947": "mushroom",
951
+ "948": "Granny Smith",
952
+ "949": "strawberry",
953
+ "95": "jacamar",
954
+ "950": "orange",
955
+ "951": "lemon",
956
+ "952": "fig",
957
+ "953": "pineapple, ananas",
958
+ "954": "banana",
959
+ "955": "jackfruit, jak, jack",
960
+ "956": "custard apple",
961
+ "957": "pomegranate",
962
+ "958": "hay",
963
+ "959": "carbonara",
964
+ "96": "toucan",
965
+ "960": "chocolate sauce, chocolate syrup",
966
+ "961": "dough",
967
+ "962": "meat loaf, meatloaf",
968
+ "963": "pizza, pizza pie",
969
+ "964": "potpie",
970
+ "965": "burrito",
971
+ "966": "red wine",
972
+ "967": "espresso",
973
+ "968": "cup",
974
+ "969": "eggnog",
975
+ "97": "drake",
976
+ "970": "alp",
977
+ "971": "bubble",
978
+ "972": "cliff, drop, drop-off",
979
+ "973": "coral reef",
980
+ "974": "geyser",
981
+ "975": "lakeside, lakeshore",
982
+ "976": "promontory, headland, head, foreland",
983
+ "977": "sandbar, sand bar",
984
+ "978": "seashore, coast, seacoast, sea-coast",
985
+ "979": "valley, vale",
986
+ "98": "red-breasted merganser, Mergus serrator",
987
+ "980": "volcano",
988
+ "981": "ballplayer, baseball player",
989
+ "982": "groom, bridegroom",
990
+ "983": "scuba diver",
991
+ "984": "rapeseed",
992
+ "985": "daisy",
993
+ "986": "yellow ladys slipper, yellow lady-slipper, Cypripedium calceolus, Cypripedium parviflorum",
994
+ "987": "corn",
995
+ "988": "acorn",
996
+ "989": "hip, rose hip, rosehip",
997
+ "99": "goose",
998
+ "990": "buckeye, horse chestnut, conker",
999
+ "991": "coral fungus",
1000
+ "992": "agaric",
1001
+ "993": "gyromitra",
1002
+ "994": "stinkhorn, carrion fungus",
1003
+ "995": "earthstar",
1004
+ "996": "hen-of-the-woods, hen of the woods, Polyporus frondosus, Grifola frondosa",
1005
+ "997": "bolete",
1006
+ "998": "ear, spike, capitulum",
1007
+ "999": "toilet tissue, toilet paper, bathroom tissue"
1008
+ },
1009
+ "scheduler": [
1010
+ "diffusers",
1011
+ "FlowMatchEulerDiscreteScheduler"
1012
+ ],
1013
+ "transformer": [
1014
+ "transformer_pixeldit",
1015
+ "PixelDiTTransformer2DModel"
1016
+ ]
1017
+ }
PixelDiT-XL-16-256/pipeline.py ADDED
@@ -0,0 +1,286 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Hub custom pipeline: PixelDiTPipeline.
2
+ Load with native Hugging Face diffusers and trust_remote_code=True.
3
+ """
4
+
5
+ from __future__ import annotations
6
+
7
+ import inspect
8
+ import json
9
+ from pathlib import Path
10
+ from typing import Dict, List, Optional, Tuple, Union
11
+
12
+ import torch
13
+ from diffusers.pipelines.pipeline_utils import DiffusionPipeline, ImagePipelineOutput
14
+ from diffusers.schedulers import FlowMatchEulerDiscreteScheduler
15
+ from diffusers.utils.torch_utils import randn_tensor
16
+
17
+ RECOMMENDED_GUIDANCE_BY_SIZE = {
18
+ 256: 3.25,
19
+ 512: 3.75,
20
+ }
21
+
22
+ RECOMMENDED_SCHEDULER_SHIFT_BY_SIZE = {
23
+ 256: 1.0,
24
+ 512: 3.0,
25
+ }
26
+
27
+
28
+ class PixelDiTPipeline(DiffusionPipeline):
29
+ r"""
30
+ Pipeline for image generation using PixelDiT (Pixel Diffusion Transformer).
31
+
32
+ Parameters:
33
+ transformer ([`PixelDiTTransformer2DModel`]):
34
+ A class-conditioned `PixelDiTTransformer2DModel` that predicts flow-matching velocity in pixel space.
35
+ scheduler ([`FlowMatchEulerDiscreteScheduler`]):
36
+ Diffusers scheduler interface for PixelDiT generation (defaults to deterministic flow-matching Euler).
37
+ id2label (`dict[int, str]`, *optional*):
38
+ ImageNet class id to English label mapping. Values may contain comma-separated synonyms.
39
+ """
40
+
41
+ @staticmethod
42
+ def prepare_extra_step_kwargs(
43
+ scheduler,
44
+ generator=None,
45
+ eta: float | None = None,
46
+ ):
47
+ kwargs = {}
48
+ step_params = set(inspect.signature(scheduler.step).parameters.keys())
49
+ if "generator" in step_params:
50
+ kwargs["generator"] = generator
51
+ if eta is not None and "eta" in step_params:
52
+ kwargs["eta"] = eta
53
+ return kwargs
54
+
55
+ model_cpu_offload_seq = "transformer"
56
+
57
+ def __init__(
58
+ self,
59
+ transformer,
60
+ scheduler,
61
+ id2label: Optional[Dict[Union[int, str], str]] = None,
62
+ ):
63
+ super().__init__()
64
+ sample_size = int(getattr(transformer.config, "sample_size", 256))
65
+ default_shift = RECOMMENDED_SCHEDULER_SHIFT_BY_SIZE.get(sample_size, 1.0)
66
+ scheduler = scheduler or FlowMatchEulerDiscreteScheduler(
67
+ num_train_timesteps=1000,
68
+ shift=default_shift,
69
+ stochastic_sampling=False,
70
+ )
71
+ self.register_modules(transformer=transformer, scheduler=scheduler)
72
+ self._id2label = self._normalize_id2label(id2label)
73
+ self.labels = self._build_label2id(self._id2label)
74
+ self._labels_loaded_from_model_index = bool(self._id2label)
75
+
76
+ def _ensure_labels_loaded(self) -> None:
77
+ if self._labels_loaded_from_model_index:
78
+ return
79
+ loaded = self._read_id2label_from_model_index(getattr(self.config, "_name_or_path", None))
80
+ if loaded:
81
+ self._id2label = loaded
82
+ self.labels = self._build_label2id(self._id2label)
83
+ self._labels_loaded_from_model_index = True
84
+
85
+ @staticmethod
86
+ def _normalize_id2label(id2label: Optional[Dict[Union[int, str], str]]) -> Dict[int, str]:
87
+ if not id2label:
88
+ return {}
89
+ return {int(key): value for key, value in id2label.items()}
90
+
91
+ @staticmethod
92
+ def _read_id2label_from_model_index(variant_path: Optional[str]) -> Dict[int, str]:
93
+ if not variant_path:
94
+ return {}
95
+ variant_dir = Path(variant_path).resolve()
96
+ model_index_path = variant_dir / "model_index.json"
97
+ if not model_index_path.exists():
98
+ return {}
99
+ raw = json.loads(model_index_path.read_text(encoding="utf-8"))
100
+ id2label = raw.get("id2label")
101
+ if not isinstance(id2label, dict):
102
+ return {}
103
+ return {int(key): value for key, value in id2label.items()}
104
+
105
+ @staticmethod
106
+ def _build_label2id(id2label: Dict[int, str]) -> Dict[str, int]:
107
+ label2id: Dict[str, int] = {}
108
+ for class_id, value in id2label.items():
109
+ for synonym in value.split(","):
110
+ synonym = synonym.strip()
111
+ if synonym:
112
+ label2id[synonym] = int(class_id)
113
+ return dict(sorted(label2id.items()))
114
+
115
+ @property
116
+ def id2label(self) -> Dict[int, str]:
117
+ self._ensure_labels_loaded()
118
+ return self._id2label
119
+
120
+ def get_label_ids(self, label: Union[str, List[str]]) -> List[int]:
121
+ self._ensure_labels_loaded()
122
+ label2id = self.labels
123
+ if not label2id:
124
+ raise ValueError(
125
+ "No English labels loaded. Ensure `id2label` exists in model_index.json."
126
+ )
127
+
128
+ if isinstance(label, str):
129
+ label = [label]
130
+
131
+ missing = [item for item in label if item not in label2id]
132
+ if missing:
133
+ preview = ", ".join(list(label2id.keys())[:8])
134
+ raise ValueError(f"Unknown English label(s): {missing}. Example valid labels: {preview}, ...")
135
+ return [label2id[item] for item in label]
136
+
137
+ def _normalize_class_labels(
138
+ self,
139
+ class_labels: Union[int, str, List[Union[int, str]]],
140
+ ) -> List[int]:
141
+ if isinstance(class_labels, int):
142
+ return [class_labels]
143
+
144
+ if isinstance(class_labels, str):
145
+ return self.get_label_ids(class_labels)
146
+
147
+ if class_labels and isinstance(class_labels[0], str):
148
+ return self.get_label_ids(class_labels)
149
+
150
+ return list(class_labels)
151
+
152
+ @staticmethod
153
+ def _resolve_timeshift(scheduler, image_size: int) -> float:
154
+ shift = getattr(scheduler.config, "shift", None)
155
+ if shift is not None:
156
+ return float(shift)
157
+ return RECOMMENDED_SCHEDULER_SHIFT_BY_SIZE.get(image_size, 1.0)
158
+
159
+ @staticmethod
160
+ def _build_flow_timesteps(
161
+ num_inference_steps: int,
162
+ timeshift: float,
163
+ device: torch.device,
164
+ dtype: torch.dtype,
165
+ ) -> torch.Tensor:
166
+ last_step = 1.0 / num_inference_steps if num_inference_steps > 1 else 1.0
167
+ timesteps = torch.linspace(0.0, 1.0 - last_step, num_inference_steps, device=device, dtype=dtype)
168
+ timesteps = torch.cat([timesteps, torch.ones(1, device=device, dtype=dtype)], dim=0)
169
+ if timeshift != 1.0:
170
+ timesteps = timesteps / (timesteps + (1.0 - timesteps) * timeshift)
171
+ return timesteps
172
+
173
+ @staticmethod
174
+ def _apply_classifier_free_guidance(model_output: torch.Tensor, guidance_scale: float) -> torch.Tensor:
175
+ model_output_uncond, model_output_cond = model_output.chunk(2, dim=0)
176
+ return model_output_uncond + guidance_scale * (model_output_cond - model_output_uncond)
177
+
178
+ @torch.inference_mode()
179
+ def __call__(
180
+ self,
181
+ class_labels: Union[int, str, List[Union[int, str]]],
182
+ guidance_scale: Optional[float] = None,
183
+ guidance_interval_min: float = 0.1,
184
+ guidance_interval_max: float = 1.0,
185
+ generator: Optional[Union[torch.Generator, List[torch.Generator]]] = None,
186
+ num_inference_steps: int = 100,
187
+ height: Optional[int] = None,
188
+ width: Optional[int] = None,
189
+ output_type: Optional[str] = "pil",
190
+ return_dict: bool = True,
191
+ ) -> Union[ImagePipelineOutput, Tuple]:
192
+ if num_inference_steps < 1:
193
+ raise ValueError("num_inference_steps must be >= 1.")
194
+ if output_type not in {"pil", "np", "pt"}:
195
+ raise ValueError("output_type must be one of: 'pil', 'np', 'pt'.")
196
+
197
+ class_label_ids = self._normalize_class_labels(class_labels)
198
+ do_classifier_free_guidance = guidance_scale is not None and guidance_scale > 1.0
199
+
200
+ batch_size = len(class_label_ids)
201
+ image_size = int(getattr(self.transformer.config, "sample_size", 256))
202
+ patch_size = int(self.transformer.config.patch_size)
203
+ height = int(height or image_size)
204
+ width = int(width or image_size)
205
+ if height <= 0 or width <= 0:
206
+ raise ValueError("height and width must be positive integers.")
207
+ if height % patch_size != 0 or width % patch_size != 0:
208
+ raise ValueError(
209
+ f"height and width must be divisible by patch_size={patch_size}. Got {(height, width)}."
210
+ )
211
+ channels = int(self.transformer.config.in_channels)
212
+ null_class_val = int(
213
+ getattr(self.transformer.config, "num_classes", getattr(self.transformer.config, "num_class_embeds", 1000))
214
+ )
215
+
216
+ if guidance_scale is None:
217
+ guidance_scale = RECOMMENDED_GUIDANCE_BY_SIZE.get(image_size, 3.25)
218
+
219
+ latents = randn_tensor(
220
+ shape=(batch_size, channels, height, width),
221
+ generator=generator,
222
+ device=self._execution_device,
223
+ dtype=self.transformer.dtype,
224
+ )
225
+
226
+ class_labels_t = torch.tensor(class_label_ids, device=self._execution_device, dtype=torch.long).reshape(-1)
227
+ class_labels_t = class_labels_t.clamp(0, null_class_val - 1)
228
+ class_null = torch.full_like(class_labels_t, null_class_val)
229
+
230
+ timeshift = self._resolve_timeshift(self.scheduler, image_size)
231
+ flow_timesteps = self._build_flow_timesteps(
232
+ num_inference_steps,
233
+ timeshift,
234
+ device=self._execution_device,
235
+ dtype=torch.float32,
236
+ )
237
+ velocity_dtype = self.transformer.dtype
238
+ v_prev = None
239
+
240
+ for t_cur, t_next in self.progress_bar(list(zip(flow_timesteps[:-1], flow_timesteps[1:]))):
241
+ dt = t_next - t_cur
242
+ flow_time = float(t_cur)
243
+ effective_guidance = (
244
+ guidance_scale
245
+ if do_classifier_free_guidance
246
+ and guidance_interval_min < flow_time < guidance_interval_max
247
+ else 1.0
248
+ )
249
+
250
+ latent_model_input = torch.cat([latents, latents], dim=0)
251
+ labels = torch.cat([class_null, class_labels_t], dim=0)
252
+ timesteps = torch.full(
253
+ (latent_model_input.shape[0],),
254
+ flow_time,
255
+ device=self._execution_device,
256
+ dtype=velocity_dtype,
257
+ )
258
+ model_output = self.transformer(
259
+ latent_model_input,
260
+ timestep=timesteps,
261
+ class_labels=labels,
262
+ ).sample
263
+ velocity = self._apply_classifier_free_guidance(model_output, effective_guidance)
264
+
265
+ if v_prev is None:
266
+ latents = latents + velocity * dt
267
+ else:
268
+ latents = latents + dt * (1.5 * velocity - 0.5 * v_prev)
269
+ v_prev = velocity
270
+
271
+ images_pt = ((latents.float().clamp(-1, 1) + 1.0) / 2.0).cpu()
272
+ if output_type == "pt":
273
+ images = images_pt
274
+ elif output_type == "np":
275
+ images = images_pt.permute(0, 2, 3, 1).numpy()
276
+ else:
277
+ images = self.numpy_to_pil(images_pt.permute(0, 2, 3, 1).numpy())
278
+
279
+ self.maybe_free_model_hooks()
280
+
281
+ if not return_dict:
282
+ return (images,)
283
+ return ImagePipelineOutput(images=images)
284
+
285
+
286
+ PixelDiTPipelineOutput = ImagePipelineOutput
PixelDiT-XL-16-256/scheduler/config.json ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ {
2
+ "_class_name": "FlowMatchEulerDiscreteScheduler",
3
+ "_diffusers_version": "0.36.0",
4
+ "num_train_timesteps": 1000,
5
+ "shift": 1.0,
6
+ "stochastic_sampling": false
7
+ }
PixelDiT-XL-16-256/scheduler/scheduler_config.json ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ {
2
+ "_class_name": "FlowMatchEulerDiscreteScheduler",
3
+ "_diffusers_version": "0.36.0",
4
+ "num_train_timesteps": 1000,
5
+ "shift": 1.0,
6
+ "stochastic_sampling": false
7
+ }
PixelDiT-XL-16-256/transformer/config.json ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "_class_name": "PixelDiTTransformer2DModel",
3
+ "hidden_size": 1152,
4
+ "in_channels": 3,
5
+ "model_type": "pixeldit-xl",
6
+ "num_classes": 1000,
7
+ "num_groups": 16,
8
+ "patch_depth": 26,
9
+ "patch_size": 16,
10
+ "pixel_depth": 4,
11
+ "pixel_hidden_size": 16,
12
+ "sample_size": 256,
13
+ "use_pixel_abs_pos": true
14
+ }
PixelDiT-XL-16-256/transformer/diffusion_pytorch_model.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:07ea7a0cc50eb0318a2a100fc33d184c40153910e329398220eac4b9a632c3dd
3
+ size 3189574228
PixelDiT-XL-16-256/transformer/transformer_pixeldit.py ADDED
@@ -0,0 +1,639 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright 2026 The HuggingFace Team. All rights reserved.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ from __future__ import annotations
16
+
17
+ import math
18
+ from collections.abc import Mapping
19
+ from typing import Dict, Literal, Optional, Tuple, Union
20
+
21
+ import numpy as np
22
+ import torch
23
+ import torch.nn as nn
24
+ import torch.nn.functional as F
25
+ from diffusers.configuration_utils import ConfigMixin, register_to_config
26
+ from diffusers.models.modeling_outputs import Transformer2DModelOutput
27
+ from diffusers.models.modeling_utils import ModelMixin
28
+ from diffusers.models.normalization import RMSNorm
29
+
30
+
31
+ PIXELDIT_PRESET_CONFIGS: Dict[str, Dict[str, object]] = {
32
+ "pixeldit-xl": {
33
+ "sample_size": 256,
34
+ "num_groups": 16,
35
+ "hidden_size": 1152,
36
+ "pixel_hidden_size": 16,
37
+ "patch_depth": 26,
38
+ "pixel_depth": 4,
39
+ "patch_size": 16,
40
+ },
41
+ }
42
+
43
+
44
+ def remap_legacy_state_dict(state_dict: Dict[str, torch.Tensor]) -> Dict[str, torch.Tensor]:
45
+ """Map wrapper/backbone keys from legacy checkpoints to native PixelDiTTransformer2DModel keys."""
46
+ remapped: Dict[str, torch.Tensor] = {}
47
+ prefixes = ("transformer.", "model.", "module.", "denoiser.", "net.")
48
+ for key, value in state_dict.items():
49
+ new_key = key
50
+ for prefix in prefixes:
51
+ if new_key.startswith(prefix):
52
+ new_key = new_key[len(prefix) :]
53
+ break
54
+ remapped[new_key] = value
55
+ return remapped
56
+
57
+
58
+ def config_from_legacy(config: Dict[str, object]) -> Dict[str, object]:
59
+ """Build native config kwargs from a legacy config.json dict."""
60
+ model_type = config.get("model_type") or config.get("model_name") or config.get("model_size")
61
+ if model_type not in PIXELDIT_PRESET_CONFIGS:
62
+ raise ValueError(f"Unknown PixelDiT preset '{model_type}'. Known: {list(PIXELDIT_PRESET_CONFIGS)}")
63
+
64
+ preset = dict(PIXELDIT_PRESET_CONFIGS[model_type])
65
+ preset["num_classes"] = int(config.get("num_classes") or config.get("num_class_embeds") or 1000)
66
+ preset["in_channels"] = int(config.get("in_channels", 3))
67
+ preset["use_pixel_abs_pos"] = bool(config.get("use_pixel_abs_pos", True))
68
+ preset["model_type"] = model_type
69
+
70
+ for key in ("sample_size", "num_groups", "hidden_size", "pixel_hidden_size", "patch_depth", "pixel_depth", "patch_size"):
71
+ if config.get(key) is not None:
72
+ preset[key] = config[key]
73
+
74
+ return preset
75
+
76
+
77
+ def get_2d_sincos_pos_embed(embed_dim: int, grid_size: int) -> np.ndarray:
78
+ grid_h = np.arange(grid_size, dtype=np.float32)
79
+ grid_w = np.arange(grid_size, dtype=np.float32)
80
+ grid = np.meshgrid(grid_w, grid_h)
81
+ grid = np.stack(grid, axis=0)
82
+ grid = grid.reshape([2, 1, grid_size, grid_size])
83
+ return get_2d_sincos_pos_embed_from_grid(embed_dim, grid)
84
+
85
+
86
+ def get_2d_sincos_pos_embed_from_grid(embed_dim: int, grid: np.ndarray) -> np.ndarray:
87
+ if embed_dim % 2 != 0:
88
+ raise ValueError("Embedding dimension must be even for 2D sin/cos positional embeddings.")
89
+ emb_h = get_1d_sincos_pos_embed_from_grid(embed_dim // 2, grid[0])
90
+ emb_w = get_1d_sincos_pos_embed_from_grid(embed_dim // 2, grid[1])
91
+ return np.concatenate([emb_h, emb_w], axis=1)
92
+
93
+
94
+ def get_1d_sincos_pos_embed_from_grid(embed_dim: int, pos: np.ndarray) -> np.ndarray:
95
+ if embed_dim % 2 != 0:
96
+ raise ValueError("Embedding dimension must be even for 1D sin/cos positional embeddings.")
97
+ omega = np.arange(embed_dim // 2, dtype=np.float64)
98
+ omega /= embed_dim / 2.0
99
+ omega = 1.0 / 10000**omega
100
+ pos = pos.reshape(-1)
101
+ out = np.einsum("m,d->md", pos, omega)
102
+ return np.concatenate([np.sin(out), np.cos(out)], axis=1)
103
+
104
+
105
+ def apply_adaln(hidden_states: torch.Tensor, shift: torch.Tensor, scale: torch.Tensor) -> torch.Tensor:
106
+ return hidden_states * (1 + scale) + shift
107
+
108
+
109
+ def precompute_freqs_cis_2d(dim: int, height: int, width: int, theta: float = 10000.0, scale: float = 16.0):
110
+ x_pos = torch.linspace(0, scale, width)
111
+ y_pos = torch.linspace(0, scale, height)
112
+ y_pos, x_pos = torch.meshgrid(y_pos, x_pos, indexing="ij")
113
+ y_pos = y_pos.reshape(-1)
114
+ x_pos = x_pos.reshape(-1)
115
+ freqs = 1.0 / (theta ** (torch.arange(0, dim, 4)[: (dim // 4)].float() / dim))
116
+ x_freqs = torch.outer(x_pos, freqs).float()
117
+ y_freqs = torch.outer(y_pos, freqs).float()
118
+ x_cis = torch.polar(torch.ones_like(x_freqs), x_freqs)
119
+ y_cis = torch.polar(torch.ones_like(y_freqs), y_freqs)
120
+ freqs_cis = torch.cat([x_cis.unsqueeze(dim=-1), y_cis.unsqueeze(dim=-1)], dim=-1)
121
+ return freqs_cis.reshape(height * width, -1)
122
+
123
+
124
+ def apply_rotary_emb(
125
+ xq: torch.Tensor,
126
+ xk: torch.Tensor,
127
+ freqs_cis: torch.Tensor,
128
+ ) -> Tuple[torch.Tensor, torch.Tensor]:
129
+ freqs_cis = freqs_cis[None, :, None, :]
130
+ xq_ = torch.view_as_complex(xq.float().reshape(*xq.shape[:-1], -1, 2))
131
+ xk_ = torch.view_as_complex(xk.float().reshape(*xk.shape[:-1], -1, 2))
132
+ xq_out = torch.view_as_real(xq_ * freqs_cis).flatten(3)
133
+ xk_out = torch.view_as_real(xk_ * freqs_cis).flatten(3)
134
+ return xq_out.type_as(xq), xk_out.type_as(xk)
135
+
136
+
137
+ class TimestepConditioner(nn.Module):
138
+ def __init__(self, hidden_size: int, frequency_embedding_size: int = 256):
139
+ super().__init__()
140
+ self.mlp = nn.Sequential(
141
+ nn.Linear(frequency_embedding_size, hidden_size, bias=True),
142
+ nn.SiLU(),
143
+ nn.Linear(hidden_size, hidden_size, bias=True),
144
+ )
145
+ self.frequency_embedding_size = frequency_embedding_size
146
+
147
+ @staticmethod
148
+ def timestep_embedding(timesteps: torch.Tensor, dim: int, max_period: int = 10):
149
+ half = dim // 2
150
+ freqs = torch.exp(
151
+ -math.log(max_period) * torch.arange(start=0, end=half, dtype=torch.float32, device=timesteps.device) / half
152
+ )
153
+ args = timesteps[..., None].float() * freqs[None, ...]
154
+ embedding = torch.cat([torch.cos(args), torch.sin(args)], dim=-1)
155
+ if dim % 2:
156
+ embedding = torch.cat([embedding, torch.zeros_like(embedding[:, :1])], dim=-1)
157
+ return embedding
158
+
159
+ def forward(self, timesteps: torch.Tensor) -> torch.Tensor:
160
+ timestep_freq = self.timestep_embedding(timesteps, self.frequency_embedding_size)
161
+ mlp_dtype = next(self.mlp.parameters()).dtype
162
+ if timestep_freq.dtype != mlp_dtype:
163
+ timestep_freq = timestep_freq.to(mlp_dtype)
164
+ return self.mlp(timestep_freq)
165
+
166
+
167
+ class ClassEmbedder(nn.Module):
168
+ def __init__(self, num_classes: int, hidden_size: int):
169
+ super().__init__()
170
+ self.embedding_table = nn.Embedding(num_classes, hidden_size)
171
+ self.num_classes = num_classes
172
+
173
+ def forward(self, labels: torch.Tensor) -> torch.Tensor:
174
+ return self.embedding_table(labels)
175
+
176
+
177
+ class FeedForward(nn.Module):
178
+ def __init__(self, dim: int, hidden_dim: int):
179
+ super().__init__()
180
+ hidden_dim = int(2 * hidden_dim / 3)
181
+ self.w1 = nn.Linear(dim, hidden_dim, bias=False)
182
+ self.w3 = nn.Linear(dim, hidden_dim, bias=False)
183
+ self.w2 = nn.Linear(hidden_dim, dim, bias=False)
184
+
185
+ def forward(self, hidden_states: torch.Tensor) -> torch.Tensor:
186
+ return self.w2(F.silu(self.w1(hidden_states)) * self.w3(hidden_states))
187
+
188
+
189
+ class RotaryAttention(nn.Module):
190
+ def __init__(
191
+ self,
192
+ dim: int,
193
+ num_heads: int = 8,
194
+ qkv_bias: bool = False,
195
+ qk_norm: bool = True,
196
+ attn_drop: float = 0.0,
197
+ proj_drop: float = 0.0,
198
+ eps: float = 1e-6,
199
+ ) -> None:
200
+ super().__init__()
201
+ if dim % num_heads != 0:
202
+ raise ValueError("dim should be divisible by num_heads")
203
+
204
+ self.dim = dim
205
+ self.num_heads = num_heads
206
+ self.head_dim = dim // num_heads
207
+
208
+ self.qkv = nn.Linear(dim, dim * 3, bias=qkv_bias)
209
+ self.q_norm = RMSNorm(self.head_dim, eps=eps) if qk_norm else nn.Identity()
210
+ self.k_norm = RMSNorm(self.head_dim, eps=eps) if qk_norm else nn.Identity()
211
+ self.attn_drop = nn.Dropout(attn_drop)
212
+ self.proj = nn.Linear(dim, dim)
213
+ self.proj_drop = nn.Dropout(proj_drop)
214
+
215
+ def forward(self, hidden_states: torch.Tensor, pos: torch.Tensor) -> torch.Tensor:
216
+ batch_size, length, channels = hidden_states.shape
217
+ qkv = (
218
+ self.qkv(hidden_states)
219
+ .reshape(batch_size, length, 3, self.num_heads, channels // self.num_heads)
220
+ .permute(2, 0, 1, 3, 4)
221
+ )
222
+ query, key, value = qkv[0], qkv[1], qkv[2]
223
+ query = self.q_norm(query)
224
+ key = self.k_norm(key)
225
+ query, key = apply_rotary_emb(query, key, freqs_cis=pos)
226
+ query = query.view(batch_size, -1, self.num_heads, channels // self.num_heads).transpose(1, 2)
227
+ key = key.view(batch_size, -1, self.num_heads, channels // self.num_heads).transpose(1, 2).contiguous()
228
+ value = value.view(batch_size, -1, self.num_heads, channels // self.num_heads).transpose(1, 2).contiguous()
229
+ hidden_states = F.scaled_dot_product_attention(query, key, value, dropout_p=0.0)
230
+ hidden_states = hidden_states.transpose(1, 2).reshape(batch_size, length, channels)
231
+ hidden_states = self.proj(hidden_states)
232
+ return self.proj_drop(hidden_states)
233
+
234
+
235
+ class MLP(nn.Module):
236
+ def __init__(self, dim: int, mlp_ratio: float = 4.0, drop: float = 0.0):
237
+ super().__init__()
238
+ hidden_dim = int(dim * mlp_ratio)
239
+ self.fc1 = nn.Linear(dim, hidden_dim)
240
+ self.act = nn.GELU()
241
+ self.fc2 = nn.Linear(hidden_dim, dim)
242
+ self.drop = nn.Dropout(drop)
243
+
244
+ def forward(self, hidden_states: torch.Tensor) -> torch.Tensor:
245
+ hidden_states = self.fc1(hidden_states)
246
+ hidden_states = self.act(hidden_states)
247
+ hidden_states = self.drop(hidden_states)
248
+ hidden_states = self.fc2(hidden_states)
249
+ return self.drop(hidden_states)
250
+
251
+
252
+ class FinalLayer(nn.Module):
253
+ def __init__(self, hidden_size: int, out_channels: int, eps: float = 1e-6):
254
+ super().__init__()
255
+ self.norm = RMSNorm(hidden_size, eps=eps)
256
+ self.linear = nn.Linear(hidden_size, out_channels, bias=True)
257
+
258
+ def forward(self, hidden_states: torch.Tensor) -> torch.Tensor:
259
+ hidden_states = self.norm(hidden_states)
260
+ return self.linear(hidden_states)
261
+
262
+
263
+ class PatchTokenEmbedder(nn.Module):
264
+ def __init__(self, in_chans: int, embed_dim: int, norm_layer=None, bias: bool = True):
265
+ super().__init__()
266
+ self.in_chans = in_chans
267
+ self.embed_dim = embed_dim
268
+ self.proj = nn.Linear(in_chans, embed_dim, bias=bias)
269
+ self.norm = norm_layer(embed_dim) if norm_layer else nn.Identity()
270
+
271
+ def forward(self, hidden_states: torch.Tensor) -> torch.Tensor:
272
+ hidden_states = self.proj(hidden_states)
273
+ return self.norm(hidden_states)
274
+
275
+
276
+ class PixelTokenEmbedder(nn.Module):
277
+ def __init__(self, in_channels: int, hidden_size_output: int, use_pixel_abs_pos: bool = True):
278
+ super().__init__()
279
+ self.in_channels = int(in_channels)
280
+ self.hidden_size_output = int(hidden_size_output)
281
+ self.use_pixel_abs_pos = bool(use_pixel_abs_pos)
282
+ self.proj = nn.Linear(self.in_channels, self.hidden_size_output, bias=True)
283
+ self._pos_cache: Dict[tuple[str, int, int], torch.Tensor] = {}
284
+
285
+ def _fetch_pixel_pos_image(self, height: int, width: int, device: torch.device, dtype: torch.dtype):
286
+ key = ("image", height, width)
287
+ if key in self._pos_cache:
288
+ return self._pos_cache[key].to(device=device, dtype=dtype)
289
+ if height == width:
290
+ pos_np = get_2d_sincos_pos_embed(self.hidden_size_output, height)
291
+ else:
292
+ grid_h = np.arange(height, dtype=np.float32)
293
+ grid_w = np.arange(width, dtype=np.float32)
294
+ grid = np.meshgrid(grid_w, grid_h)
295
+ grid = np.stack(grid, axis=0).reshape(2, 1, height, width)
296
+ pos_np = get_2d_sincos_pos_embed_from_grid(self.hidden_size_output, grid)
297
+ pos = torch.from_numpy(pos_np).to(device=device, dtype=dtype)
298
+ self._pos_cache[key] = pos
299
+ return pos
300
+
301
+ def forward(self, inputs: torch.Tensor, img_height: int, img_width: int, patch_size: int):
302
+ if inputs.dim() != 4:
303
+ raise ValueError("PixelTokenEmbedder expects inputs of shape [B,C,H,W]")
304
+ batch_size, channels, height, width = inputs.shape
305
+ if height != img_height or width != img_width:
306
+ raise ValueError("Input resolution does not match img_height/img_width.")
307
+ if height % patch_size != 0 or width % patch_size != 0:
308
+ raise ValueError("Image height and width must be divisible by patch_size.")
309
+ h_tokens, w_tokens = height // patch_size, width // patch_size
310
+ patch_area = patch_size * patch_size
311
+ hidden_states = inputs.permute(0, 2, 3, 1).contiguous()
312
+ hidden_states = self.proj(hidden_states)
313
+ if self.use_pixel_abs_pos:
314
+ pos_full = self._fetch_pixel_pos_image(height, width, inputs.device, inputs.dtype)
315
+ hidden_states = hidden_states + pos_full.view(height, width, self.hidden_size_output).unsqueeze(0)
316
+ hidden_states = hidden_states.view(batch_size, h_tokens, patch_size, w_tokens, patch_size, self.hidden_size_output)
317
+ hidden_states = hidden_states.permute(0, 1, 3, 2, 4, 5).contiguous()
318
+ return hidden_states.view(batch_size * h_tokens * w_tokens, patch_area, self.hidden_size_output)
319
+
320
+
321
+ class AugmentedDiTBlock(nn.Module):
322
+ def __init__(self, hidden_size: int, groups: int, mlp_ratio: float = 4.0, adaLN_modulation=None, eps: float = 1e-6):
323
+ super().__init__()
324
+ self.norm1 = RMSNorm(hidden_size, eps=eps)
325
+ self.attn = RotaryAttention(hidden_size, num_heads=groups, qkv_bias=False, eps=eps)
326
+ self.norm2 = RMSNorm(hidden_size, eps=eps)
327
+ mlp_hidden_dim = int(hidden_size * mlp_ratio)
328
+ self.mlp = FeedForward(hidden_size, mlp_hidden_dim)
329
+ self.adaLN_modulation = adaLN_modulation if adaLN_modulation is not None else nn.Sequential(
330
+ nn.Linear(hidden_size, 6 * hidden_size, bias=True)
331
+ )
332
+
333
+ def forward(self, hidden_states: torch.Tensor, conditioning: torch.Tensor, pos: torch.Tensor):
334
+ shift_msa, scale_msa, gate_msa, shift_mlp, scale_mlp, gate_mlp = self.adaLN_modulation(conditioning).chunk(
335
+ 6, dim=-1
336
+ )
337
+ hidden_states = hidden_states + gate_msa * self.attn(
338
+ apply_adaln(self.norm1(hidden_states), shift_msa, scale_msa), pos
339
+ )
340
+ hidden_states = hidden_states + gate_mlp * self.mlp(
341
+ apply_adaln(self.norm2(hidden_states), shift_mlp, scale_mlp)
342
+ )
343
+ return hidden_states
344
+
345
+
346
+ class PiTBlock(nn.Module):
347
+ def __init__(
348
+ self,
349
+ pixel_hidden_size: int,
350
+ patch_hidden_size: int,
351
+ patch_size: int,
352
+ num_heads: int,
353
+ mlp_ratio: float = 4.0,
354
+ attn_hidden_size: Optional[int] = None,
355
+ attn_num_heads: Optional[int] = None,
356
+ rope_fn=None,
357
+ eps: float = 1e-6,
358
+ ):
359
+ super().__init__()
360
+ self.pixel_dim = int(pixel_hidden_size)
361
+ self.context_dim = int(patch_hidden_size)
362
+ self.patch_size = int(patch_size)
363
+ self.attn_dim = int(attn_hidden_size) if attn_hidden_size is not None else self.context_dim
364
+ self.num_heads = int(attn_num_heads) if attn_num_heads is not None else int(num_heads)
365
+ if self.attn_dim % self.num_heads != 0:
366
+ raise ValueError("pixel attention hidden size must be divisible by pixel num_heads")
367
+ patch_area = self.patch_size * self.patch_size
368
+ self.compress_to_attn = nn.Linear(patch_area * self.pixel_dim, self.attn_dim, bias=True)
369
+ self.expand_from_attn = nn.Linear(self.attn_dim, patch_area * self.pixel_dim, bias=True)
370
+ self.norm1 = RMSNorm(self.pixel_dim, eps=eps)
371
+ self.attn = RotaryAttention(self.attn_dim, num_heads=self.num_heads, qkv_bias=False, eps=eps)
372
+ self.norm2 = RMSNorm(self.pixel_dim, eps=eps)
373
+ self.mlp = MLP(self.pixel_dim, mlp_ratio=mlp_ratio, drop=0.0)
374
+ self.adaLN_modulation = nn.Sequential(nn.Linear(self.context_dim, 6 * self.pixel_dim * patch_area, bias=True))
375
+ self._pos_cache: Dict[tuple[int, int], torch.Tensor] = {}
376
+ self._rope_fn = rope_fn if rope_fn is not None else precompute_freqs_cis_2d
377
+
378
+ def _fetch_pos(self, height: int, width: int, device: torch.device):
379
+ key = (height, width)
380
+ if key in self._pos_cache:
381
+ return self._pos_cache[key].to(device)
382
+ pos = self._rope_fn(self.attn_dim // self.num_heads, height, width).to(device)
383
+ self._pos_cache[key] = pos
384
+ return pos
385
+
386
+ def forward(
387
+ self,
388
+ hidden_states: torch.Tensor,
389
+ conditioning: torch.Tensor,
390
+ image_height: int,
391
+ image_width: int,
392
+ patch_size: int,
393
+ ) -> torch.Tensor:
394
+ batch_tokens, patch_area, channels = hidden_states.shape
395
+ if channels != self.pixel_dim:
396
+ raise ValueError(f"PiTBlock expected pixel_dim={self.pixel_dim}, got {channels}")
397
+ if image_height % patch_size != 0 or image_width % patch_size != 0:
398
+ raise ValueError("Image height and width must be divisible by patch_size.")
399
+ h_tokens, w_tokens = image_height // patch_size, image_width // patch_size
400
+ length = h_tokens * w_tokens
401
+ batch_size = batch_tokens // length
402
+ cond_params = self.adaLN_modulation(conditioning).view(batch_tokens, patch_area, 6 * self.pixel_dim)
403
+ shift_msa, scale_msa, gate_msa, shift_mlp, scale_mlp, gate_mlp = torch.chunk(cond_params, 6, dim=-1)
404
+ hidden_norm = apply_adaln(self.norm1(hidden_states), shift_msa, scale_msa)
405
+ hidden_flat = hidden_norm.view(batch_tokens, patch_area * self.pixel_dim)
406
+ hidden_comp = self.compress_to_attn(hidden_flat).view(batch_size, length, self.attn_dim)
407
+ pos_comp = self._fetch_pos(h_tokens, w_tokens, hidden_states.device)
408
+ attn_out = self.attn(hidden_comp, pos_comp)
409
+ attn_flat = self.expand_from_attn(attn_out.view(batch_size * length, self.attn_dim))
410
+ attn_exp = attn_flat.view(batch_tokens, patch_area, self.pixel_dim)
411
+ hidden_states = hidden_states + gate_msa * attn_exp
412
+ mlp_out = self.mlp(apply_adaln(self.norm2(hidden_states), shift_mlp, scale_mlp))
413
+ hidden_states = hidden_states + gate_mlp * mlp_out
414
+ return hidden_states
415
+
416
+
417
+ class PixelDiTTransformer2DModel(ModelMixin, ConfigMixin):
418
+ _supports_gradient_checkpointing = True
419
+ _skip_layerwise_casting_patterns = ["pos", "_pos_cache"]
420
+
421
+ @register_to_config
422
+ def __init__(
423
+ self,
424
+ sample_size: int = 256,
425
+ in_channels: int = 3,
426
+ num_groups: int = 16,
427
+ hidden_size: int = 1152,
428
+ pixel_hidden_size: int = 16,
429
+ patch_depth: int = 26,
430
+ pixel_depth: int = 4,
431
+ patch_size: int = 16,
432
+ num_classes: int = 1000,
433
+ use_pixel_abs_pos: bool = True,
434
+ norm_eps: float = 1e-6,
435
+ model_type: str | None = None,
436
+ num_class_embeds: int | None = None,
437
+ ):
438
+ super().__init__()
439
+ if num_class_embeds is not None:
440
+ num_classes = int(num_class_embeds)
441
+ if model_type in PIXELDIT_PRESET_CONFIGS:
442
+ preset = PIXELDIT_PRESET_CONFIGS[model_type]
443
+ sample_size = int(preset["sample_size"])
444
+ num_groups = int(preset["num_groups"])
445
+ hidden_size = int(preset["hidden_size"])
446
+ pixel_hidden_size = int(preset["pixel_hidden_size"])
447
+ patch_depth = int(preset["patch_depth"])
448
+ pixel_depth = int(preset["pixel_depth"])
449
+ patch_size = int(preset["patch_size"])
450
+
451
+ self.sample_size = int(sample_size)
452
+ self.in_channels = int(in_channels)
453
+ self.out_channels = int(in_channels)
454
+ self.hidden_size = int(hidden_size)
455
+ self.num_groups = int(num_groups)
456
+ self.patch_depth = int(patch_depth)
457
+ self.pixel_depth = int(pixel_depth)
458
+ self.patch_size = int(patch_size)
459
+ self.pixel_hidden_size = int(pixel_hidden_size)
460
+ self.num_classes = int(num_classes)
461
+ self.use_pixel_abs_pos = bool(use_pixel_abs_pos)
462
+ self.norm_eps = float(norm_eps)
463
+ self.gradient_checkpointing = False
464
+
465
+ if self.pixel_depth <= 0:
466
+ raise ValueError("PixelDiT expects pixel_depth > 0 to preserve the dual-level pipeline")
467
+
468
+ self.pixel_embedder = PixelTokenEmbedder(
469
+ self.in_channels, self.pixel_hidden_size, use_pixel_abs_pos=self.use_pixel_abs_pos
470
+ )
471
+ self.s_embedder = PatchTokenEmbedder(self.in_channels * self.patch_size**2, self.hidden_size, bias=True)
472
+ self.t_embedder = TimestepConditioner(self.hidden_size)
473
+ self.y_embedder = ClassEmbedder(self.num_classes + 1, self.hidden_size)
474
+
475
+ self.final_layer = FinalLayer(self.pixel_hidden_size, self.out_channels, eps=self.norm_eps)
476
+ self.patch_blocks = nn.ModuleList(
477
+ [AugmentedDiTBlock(self.hidden_size, self.num_groups, eps=self.norm_eps) for _ in range(self.patch_depth)]
478
+ )
479
+ self.pixel_blocks = nn.ModuleList(
480
+ [
481
+ PiTBlock(
482
+ self.pixel_hidden_size,
483
+ self.hidden_size,
484
+ patch_size=self.patch_size,
485
+ num_heads=self.num_groups,
486
+ mlp_ratio=4.0,
487
+ eps=self.norm_eps,
488
+ )
489
+ for _ in range(self.pixel_depth)
490
+ ]
491
+ )
492
+ self._precompute_pos: Dict[tuple[int, int], torch.Tensor] = {}
493
+ self._initialize_weights()
494
+
495
+ def _fetch_pos(self, height: int, width: int, device: torch.device):
496
+ key = (height, width)
497
+ if key in self._precompute_pos:
498
+ return self._precompute_pos[key].to(device)
499
+ pos = precompute_freqs_cis_2d(self.hidden_size // self.num_groups, height, width).to(device)
500
+ self._precompute_pos[key] = pos
501
+ return pos
502
+
503
+ def _initialize_weights(self) -> None:
504
+ weight = self.s_embedder.proj.weight.data
505
+ nn.init.xavier_uniform_(weight.view([weight.shape[0], -1]))
506
+ nn.init.constant_(self.s_embedder.proj.bias, 0)
507
+ nn.init.normal_(self.y_embedder.embedding_table.weight, std=0.02)
508
+ nn.init.normal_(self.t_embedder.mlp[0].weight, std=0.02)
509
+ nn.init.normal_(self.t_embedder.mlp[2].weight, std=0.02)
510
+ nn.init.zeros_(self.final_layer.linear.weight)
511
+ nn.init.zeros_(self.final_layer.linear.bias)
512
+ for block in self.patch_blocks:
513
+ nn.init.zeros_(block.adaLN_modulation[0].weight)
514
+ nn.init.zeros_(block.adaLN_modulation[0].bias)
515
+ for block in self.pixel_blocks:
516
+ nn.init.zeros_(block.adaLN_modulation[0].weight)
517
+ nn.init.zeros_(block.adaLN_modulation[0].bias)
518
+
519
+ def forward(
520
+ self,
521
+ sample: torch.Tensor,
522
+ timestep: Union[torch.Tensor, float],
523
+ class_labels: Union[torch.Tensor, int],
524
+ return_dict: bool = True,
525
+ ) -> Union[Transformer2DModelOutput, Tuple[torch.Tensor]]:
526
+ if sample.dim() != 4:
527
+ raise ValueError("PixelDiTTransformer2DModel expects sample of shape [B,C,H,W]")
528
+ batch_size, _, height, width = sample.shape
529
+ if height % self.patch_size != 0 or width % self.patch_size != 0:
530
+ raise ValueError("Image height and width must be divisible by patch_size.")
531
+
532
+ timestep = torch.as_tensor(timestep, device=sample.device)
533
+ if timestep.ndim == 0:
534
+ timestep = timestep.repeat(batch_size)
535
+ else:
536
+ timestep = timestep.reshape(-1)
537
+ if timestep.shape[0] == 1 and batch_size > 1:
538
+ timestep = timestep.repeat(batch_size)
539
+
540
+ if not torch.is_tensor(class_labels):
541
+ class_labels = torch.tensor(class_labels, device=sample.device, dtype=torch.long)
542
+ class_labels = class_labels.to(device=sample.device, dtype=torch.long).reshape(-1)
543
+ if class_labels.shape[0] == 1 and batch_size > 1:
544
+ class_labels = class_labels.repeat(batch_size)
545
+
546
+ pos = self._fetch_pos(height // self.patch_size, width // self.patch_size, sample.device)
547
+ x_patches = F.unfold(sample, kernel_size=self.patch_size, stride=self.patch_size).transpose(1, 2)
548
+ t_emb = self.t_embedder(timestep.view(-1)).view(batch_size, -1, self.hidden_size)
549
+ y_emb = self.y_embedder(class_labels).view(batch_size, 1, self.hidden_size)
550
+ conditioning = F.silu(t_emb + y_emb)
551
+
552
+ patch_states = self.s_embedder(x_patches)
553
+ for block in self.patch_blocks:
554
+ if self.training and self.gradient_checkpointing:
555
+
556
+ def custom_forward(hidden_states, cond, position):
557
+ return block(hidden_states, cond, position)
558
+
559
+ patch_states = torch.utils.checkpoint.checkpoint(
560
+ custom_forward, patch_states, conditioning, pos, use_reentrant=False
561
+ )
562
+ else:
563
+ patch_states = block(patch_states, conditioning, pos)
564
+ patch_states = F.silu(t_emb + patch_states)
565
+
566
+ length = patch_states.shape[1]
567
+ conditioning_states = patch_states.view(batch_size * length, self.hidden_size)
568
+ pixel_states = self.pixel_embedder(
569
+ sample, img_height=height, img_width=width, patch_size=self.patch_size
570
+ )
571
+ for block in self.pixel_blocks:
572
+ if self.training and self.gradient_checkpointing:
573
+
574
+ def custom_forward(hidden_states, cond):
575
+ return block(hidden_states, cond, height, width, self.patch_size)
576
+
577
+ pixel_states = torch.utils.checkpoint.checkpoint(
578
+ custom_forward, pixel_states, conditioning_states, use_reentrant=False
579
+ )
580
+ else:
581
+ pixel_states = block(pixel_states, conditioning_states, height, width, self.patch_size)
582
+ pixel_states = self.final_layer(pixel_states)
583
+
584
+ patch_area = self.patch_size * self.patch_size
585
+ pixel_states = pixel_states.view(batch_size, length, patch_area, self.out_channels).permute(0, 3, 2, 1)
586
+ pixel_states = pixel_states.contiguous().view(batch_size, self.out_channels * patch_area, length)
587
+ output = F.fold(pixel_states, (height, width), kernel_size=self.patch_size, stride=self.patch_size)
588
+
589
+ if not return_dict:
590
+ return (output,)
591
+ return Transformer2DModelOutput(sample=output)
592
+
593
+ @classmethod
594
+ def from_pixeldit_checkpoint(
595
+ cls,
596
+ checkpoint_path: str,
597
+ model_type: Literal["pixeldit-xl"] = "pixeldit-xl",
598
+ map_location: str = "cpu",
599
+ strict: bool = True,
600
+ ) -> Tuple["PixelDiTTransformer2DModel", Dict[str, object]]:
601
+ if model_type not in PIXELDIT_PRESET_CONFIGS:
602
+ raise ValueError(f"Unknown PixelDiT preset '{model_type}'.")
603
+
604
+ if checkpoint_path.endswith(".safetensors"):
605
+ try:
606
+ from safetensors.torch import load_file
607
+ except ImportError as error:
608
+ raise ImportError("Install safetensors to load .safetensors checkpoints.") from error
609
+ state_dict = load_file(checkpoint_path, device=map_location)
610
+ else:
611
+ loaded = torch.load(checkpoint_path, map_location=map_location, weights_only=False)
612
+ if isinstance(loaded, Mapping):
613
+ state_dict = loaded
614
+ for key in ("state_dict", "model", "module", "denoiser"):
615
+ if key in state_dict and isinstance(state_dict[key], dict):
616
+ state_dict = state_dict[key]
617
+ break
618
+ else:
619
+ raise ValueError("Unsupported checkpoint format.")
620
+
621
+ config = dict(PIXELDIT_PRESET_CONFIGS[model_type])
622
+ config["model_type"] = model_type
623
+ model = cls(**config)
624
+ model.load_state_dict(remap_legacy_state_dict(state_dict), strict=strict)
625
+
626
+ metadata = {
627
+ "checkpoint_path": checkpoint_path,
628
+ "model_type": model_type,
629
+ }
630
+ return model, metadata
631
+
632
+ def to_pixeldit_checkpoint(self, prefix: str = "") -> Dict[str, torch.Tensor]:
633
+ checkpoint: Dict[str, torch.Tensor] = {}
634
+ for key, value in self.state_dict().items():
635
+ checkpoint[f"{prefix}{key}"] = value.detach().cpu()
636
+ return checkpoint
637
+
638
+
639
+ PixelDiTDiffusersModel = PixelDiTTransformer2DModel
PixelDiT-XL-16-512/demo.png ADDED

Git LFS Details

  • SHA256: de5f3bc36ec71aa9ed6f71972a6411cf1bde326087ea76b76c1d80609922e8d7
  • Pointer size: 131 Bytes
  • Size of remote file: 423 kB
PixelDiT-XL-16-512/model_index.json ADDED
@@ -0,0 +1,1017 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "_class_name": [
3
+ "pipeline",
4
+ "PixelDiTPipeline"
5
+ ],
6
+ "_diffusers_version": "0.35.1",
7
+ "id2label": {
8
+ "0": "tench, Tinca tinca",
9
+ "1": "goldfish, Carassius auratus",
10
+ "10": "brambling, Fringilla montifringilla",
11
+ "100": "black swan, Cygnus atratus",
12
+ "101": "tusker",
13
+ "102": "echidna, spiny anteater, anteater",
14
+ "103": "platypus, duckbill, duckbilled platypus, duck-billed platypus, Ornithorhynchus anatinus",
15
+ "104": "wallaby, brush kangaroo",
16
+ "105": "koala, koala bear, kangaroo bear, native bear, Phascolarctos cinereus",
17
+ "106": "wombat",
18
+ "107": "jellyfish",
19
+ "108": "sea anemone, anemone",
20
+ "109": "brain coral",
21
+ "11": "goldfinch, Carduelis carduelis",
22
+ "110": "flatworm, platyhelminth",
23
+ "111": "nematode, nematode worm, roundworm",
24
+ "112": "conch",
25
+ "113": "snail",
26
+ "114": "slug",
27
+ "115": "sea slug, nudibranch",
28
+ "116": "chiton, coat-of-mail shell, sea cradle, polyplacophore",
29
+ "117": "chambered nautilus, pearly nautilus, nautilus",
30
+ "118": "Dungeness crab, Cancer magister",
31
+ "119": "rock crab, Cancer irroratus",
32
+ "12": "house finch, linnet, Carpodacus mexicanus",
33
+ "120": "fiddler crab",
34
+ "121": "king crab, Alaska crab, Alaskan king crab, Alaska king crab, Paralithodes camtschatica",
35
+ "122": "American lobster, Northern lobster, Maine lobster, Homarus americanus",
36
+ "123": "spiny lobster, langouste, rock lobster, crawfish, crayfish, sea crawfish",
37
+ "124": "crayfish, crawfish, crawdad, crawdaddy",
38
+ "125": "hermit crab",
39
+ "126": "isopod",
40
+ "127": "white stork, Ciconia ciconia",
41
+ "128": "black stork, Ciconia nigra",
42
+ "129": "spoonbill",
43
+ "13": "junco, snowbird",
44
+ "130": "flamingo",
45
+ "131": "little blue heron, Egretta caerulea",
46
+ "132": "American egret, great white heron, Egretta albus",
47
+ "133": "bittern",
48
+ "134": "crane",
49
+ "135": "limpkin, Aramus pictus",
50
+ "136": "European gallinule, Porphyrio porphyrio",
51
+ "137": "American coot, marsh hen, mud hen, water hen, Fulica americana",
52
+ "138": "bustard",
53
+ "139": "ruddy turnstone, Arenaria interpres",
54
+ "14": "indigo bunting, indigo finch, indigo bird, Passerina cyanea",
55
+ "140": "red-backed sandpiper, dunlin, Erolia alpina",
56
+ "141": "redshank, Tringa totanus",
57
+ "142": "dowitcher",
58
+ "143": "oystercatcher, oyster catcher",
59
+ "144": "pelican",
60
+ "145": "king penguin, Aptenodytes patagonica",
61
+ "146": "albatross, mollymawk",
62
+ "147": "grey whale, gray whale, devilfish, Eschrichtius gibbosus, Eschrichtius robustus",
63
+ "148": "killer whale, killer, orca, grampus, sea wolf, Orcinus orca",
64
+ "149": "dugong, Dugong dugon",
65
+ "15": "robin, American robin, Turdus migratorius",
66
+ "150": "sea lion",
67
+ "151": "Chihuahua",
68
+ "152": "Japanese spaniel",
69
+ "153": "Maltese dog, Maltese terrier, Maltese",
70
+ "154": "Pekinese, Pekingese, Peke",
71
+ "155": "Shih-Tzu",
72
+ "156": "Blenheim spaniel",
73
+ "157": "papillon",
74
+ "158": "toy terrier",
75
+ "159": "Rhodesian ridgeback",
76
+ "16": "bulbul",
77
+ "160": "Afghan hound, Afghan",
78
+ "161": "basset, basset hound",
79
+ "162": "beagle",
80
+ "163": "bloodhound, sleuthhound",
81
+ "164": "bluetick",
82
+ "165": "black-and-tan coonhound",
83
+ "166": "Walker hound, Walker foxhound",
84
+ "167": "English foxhound",
85
+ "168": "redbone",
86
+ "169": "borzoi, Russian wolfhound",
87
+ "17": "jay",
88
+ "170": "Irish wolfhound",
89
+ "171": "Italian greyhound",
90
+ "172": "whippet",
91
+ "173": "Ibizan hound, Ibizan Podenco",
92
+ "174": "Norwegian elkhound, elkhound",
93
+ "175": "otterhound, otter hound",
94
+ "176": "Saluki, gazelle hound",
95
+ "177": "Scottish deerhound, deerhound",
96
+ "178": "Weimaraner",
97
+ "179": "Staffordshire bullterrier, Staffordshire bull terrier",
98
+ "18": "magpie",
99
+ "180": "American Staffordshire terrier, Staffordshire terrier, American pit bull terrier, pit bull terrier",
100
+ "181": "Bedlington terrier",
101
+ "182": "Border terrier",
102
+ "183": "Kerry blue terrier",
103
+ "184": "Irish terrier",
104
+ "185": "Norfolk terrier",
105
+ "186": "Norwich terrier",
106
+ "187": "Yorkshire terrier",
107
+ "188": "wire-haired fox terrier",
108
+ "189": "Lakeland terrier",
109
+ "19": "chickadee",
110
+ "190": "Sealyham terrier, Sealyham",
111
+ "191": "Airedale, Airedale terrier",
112
+ "192": "cairn, cairn terrier",
113
+ "193": "Australian terrier",
114
+ "194": "Dandie Dinmont, Dandie Dinmont terrier",
115
+ "195": "Boston bull, Boston terrier",
116
+ "196": "miniature schnauzer",
117
+ "197": "giant schnauzer",
118
+ "198": "standard schnauzer",
119
+ "199": "Scotch terrier, Scottish terrier, Scottie",
120
+ "2": "great white shark, white shark, man-eater, man-eating shark, Carcharodon carcharias",
121
+ "20": "water ouzel, dipper",
122
+ "200": "Tibetan terrier, chrysanthemum dog",
123
+ "201": "silky terrier, Sydney silky",
124
+ "202": "soft-coated wheaten terrier",
125
+ "203": "West Highland white terrier",
126
+ "204": "Lhasa, Lhasa apso",
127
+ "205": "flat-coated retriever",
128
+ "206": "curly-coated retriever",
129
+ "207": "golden retriever",
130
+ "208": "Labrador retriever",
131
+ "209": "Chesapeake Bay retriever",
132
+ "21": "kite",
133
+ "210": "German short-haired pointer",
134
+ "211": "vizsla, Hungarian pointer",
135
+ "212": "English setter",
136
+ "213": "Irish setter, red setter",
137
+ "214": "Gordon setter",
138
+ "215": "Brittany spaniel",
139
+ "216": "clumber, clumber spaniel",
140
+ "217": "English springer, English springer spaniel",
141
+ "218": "Welsh springer spaniel",
142
+ "219": "cocker spaniel, English cocker spaniel, cocker",
143
+ "22": "bald eagle, American eagle, Haliaeetus leucocephalus",
144
+ "220": "Sussex spaniel",
145
+ "221": "Irish water spaniel",
146
+ "222": "kuvasz",
147
+ "223": "schipperke",
148
+ "224": "groenendael",
149
+ "225": "malinois",
150
+ "226": "briard",
151
+ "227": "kelpie",
152
+ "228": "komondor",
153
+ "229": "Old English sheepdog, bobtail",
154
+ "23": "vulture",
155
+ "230": "Shetland sheepdog, Shetland sheep dog, Shetland",
156
+ "231": "collie",
157
+ "232": "Border collie",
158
+ "233": "Bouvier des Flandres, Bouviers des Flandres",
159
+ "234": "Rottweiler",
160
+ "235": "German shepherd, German shepherd dog, German police dog, alsatian",
161
+ "236": "Doberman, Doberman pinscher",
162
+ "237": "miniature pinscher",
163
+ "238": "Greater Swiss Mountain dog",
164
+ "239": "Bernese mountain dog",
165
+ "24": "great grey owl, great gray owl, Strix nebulosa",
166
+ "240": "Appenzeller",
167
+ "241": "EntleBucher",
168
+ "242": "boxer",
169
+ "243": "bull mastiff",
170
+ "244": "Tibetan mastiff",
171
+ "245": "French bulldog",
172
+ "246": "Great Dane",
173
+ "247": "Saint Bernard, St Bernard",
174
+ "248": "Eskimo dog, husky",
175
+ "249": "malamute, malemute, Alaskan malamute",
176
+ "25": "European fire salamander, Salamandra salamandra",
177
+ "250": "Siberian husky",
178
+ "251": "dalmatian, coach dog, carriage dog",
179
+ "252": "affenpinscher, monkey pinscher, monkey dog",
180
+ "253": "basenji",
181
+ "254": "pug, pug-dog",
182
+ "255": "Leonberg",
183
+ "256": "Newfoundland, Newfoundland dog",
184
+ "257": "Great Pyrenees",
185
+ "258": "Samoyed, Samoyede",
186
+ "259": "Pomeranian",
187
+ "26": "common newt, Triturus vulgaris",
188
+ "260": "chow, chow chow",
189
+ "261": "keeshond",
190
+ "262": "Brabancon griffon",
191
+ "263": "Pembroke, Pembroke Welsh corgi",
192
+ "264": "Cardigan, Cardigan Welsh corgi",
193
+ "265": "toy poodle",
194
+ "266": "miniature poodle",
195
+ "267": "standard poodle",
196
+ "268": "Mexican hairless",
197
+ "269": "timber wolf, grey wolf, gray wolf, Canis lupus",
198
+ "27": "eft",
199
+ "270": "white wolf, Arctic wolf, Canis lupus tundrarum",
200
+ "271": "red wolf, maned wolf, Canis rufus, Canis niger",
201
+ "272": "coyote, prairie wolf, brush wolf, Canis latrans",
202
+ "273": "dingo, warrigal, warragal, Canis dingo",
203
+ "274": "dhole, Cuon alpinus",
204
+ "275": "African hunting dog, hyena dog, Cape hunting dog, Lycaon pictus",
205
+ "276": "hyena, hyaena",
206
+ "277": "red fox, Vulpes vulpes",
207
+ "278": "kit fox, Vulpes macrotis",
208
+ "279": "Arctic fox, white fox, Alopex lagopus",
209
+ "28": "spotted salamander, Ambystoma maculatum",
210
+ "280": "grey fox, gray fox, Urocyon cinereoargenteus",
211
+ "281": "tabby, tabby cat",
212
+ "282": "tiger cat",
213
+ "283": "Persian cat",
214
+ "284": "Siamese cat, Siamese",
215
+ "285": "Egyptian cat",
216
+ "286": "cougar, puma, catamount, mountain lion, painter, panther, Felis concolor",
217
+ "287": "lynx, catamount",
218
+ "288": "leopard, Panthera pardus",
219
+ "289": "snow leopard, ounce, Panthera uncia",
220
+ "29": "axolotl, mud puppy, Ambystoma mexicanum",
221
+ "290": "jaguar, panther, Panthera onca, Felis onca",
222
+ "291": "lion, king of beasts, Panthera leo",
223
+ "292": "tiger, Panthera tigris",
224
+ "293": "cheetah, chetah, Acinonyx jubatus",
225
+ "294": "brown bear, bruin, Ursus arctos",
226
+ "295": "American black bear, black bear, Ursus americanus, Euarctos americanus",
227
+ "296": "ice bear, polar bear, Ursus Maritimus, Thalarctos maritimus",
228
+ "297": "sloth bear, Melursus ursinus, Ursus ursinus",
229
+ "298": "mongoose",
230
+ "299": "meerkat, mierkat",
231
+ "3": "tiger shark, Galeocerdo cuvieri",
232
+ "30": "bullfrog, Rana catesbeiana",
233
+ "300": "tiger beetle",
234
+ "301": "ladybug, ladybeetle, lady beetle, ladybird, ladybird beetle",
235
+ "302": "ground beetle, carabid beetle",
236
+ "303": "long-horned beetle, longicorn, longicorn beetle",
237
+ "304": "leaf beetle, chrysomelid",
238
+ "305": "dung beetle",
239
+ "306": "rhinoceros beetle",
240
+ "307": "weevil",
241
+ "308": "fly",
242
+ "309": "bee",
243
+ "31": "tree frog, tree-frog",
244
+ "310": "ant, emmet, pismire",
245
+ "311": "grasshopper, hopper",
246
+ "312": "cricket",
247
+ "313": "walking stick, walkingstick, stick insect",
248
+ "314": "cockroach, roach",
249
+ "315": "mantis, mantid",
250
+ "316": "cicada, cicala",
251
+ "317": "leafhopper",
252
+ "318": "lacewing, lacewing fly",
253
+ "319": "dragonfly, darning needle, devils darning needle, sewing needle, snake feeder, snake doctor, mosquito hawk, skeeter hawk",
254
+ "32": "tailed frog, bell toad, ribbed toad, tailed toad, Ascaphus trui",
255
+ "320": "damselfly",
256
+ "321": "admiral",
257
+ "322": "ringlet, ringlet butterfly",
258
+ "323": "monarch, monarch butterfly, milkweed butterfly, Danaus plexippus",
259
+ "324": "cabbage butterfly",
260
+ "325": "sulphur butterfly, sulfur butterfly",
261
+ "326": "lycaenid, lycaenid butterfly",
262
+ "327": "starfish, sea star",
263
+ "328": "sea urchin",
264
+ "329": "sea cucumber, holothurian",
265
+ "33": "loggerhead, loggerhead turtle, Caretta caretta",
266
+ "330": "wood rabbit, cottontail, cottontail rabbit",
267
+ "331": "hare",
268
+ "332": "Angora, Angora rabbit",
269
+ "333": "hamster",
270
+ "334": "porcupine, hedgehog",
271
+ "335": "fox squirrel, eastern fox squirrel, Sciurus niger",
272
+ "336": "marmot",
273
+ "337": "beaver",
274
+ "338": "guinea pig, Cavia cobaya",
275
+ "339": "sorrel",
276
+ "34": "leatherback turtle, leatherback, leathery turtle, Dermochelys coriacea",
277
+ "340": "zebra",
278
+ "341": "hog, pig, grunter, squealer, Sus scrofa",
279
+ "342": "wild boar, boar, Sus scrofa",
280
+ "343": "warthog",
281
+ "344": "hippopotamus, hippo, river horse, Hippopotamus amphibius",
282
+ "345": "ox",
283
+ "346": "water buffalo, water ox, Asiatic buffalo, Bubalus bubalis",
284
+ "347": "bison",
285
+ "348": "ram, tup",
286
+ "349": "bighorn, bighorn sheep, cimarron, Rocky Mountain bighorn, Rocky Mountain sheep, Ovis canadensis",
287
+ "35": "mud turtle",
288
+ "350": "ibex, Capra ibex",
289
+ "351": "hartebeest",
290
+ "352": "impala, Aepyceros melampus",
291
+ "353": "gazelle",
292
+ "354": "Arabian camel, dromedary, Camelus dromedarius",
293
+ "355": "llama",
294
+ "356": "weasel",
295
+ "357": "mink",
296
+ "358": "polecat, fitch, foulmart, foumart, Mustela putorius",
297
+ "359": "black-footed ferret, ferret, Mustela nigripes",
298
+ "36": "terrapin",
299
+ "360": "otter",
300
+ "361": "skunk, polecat, wood pussy",
301
+ "362": "badger",
302
+ "363": "armadillo",
303
+ "364": "three-toed sloth, ai, Bradypus tridactylus",
304
+ "365": "orangutan, orang, orangutang, Pongo pygmaeus",
305
+ "366": "gorilla, Gorilla gorilla",
306
+ "367": "chimpanzee, chimp, Pan troglodytes",
307
+ "368": "gibbon, Hylobates lar",
308
+ "369": "siamang, Hylobates syndactylus, Symphalangus syndactylus",
309
+ "37": "box turtle, box tortoise",
310
+ "370": "guenon, guenon monkey",
311
+ "371": "patas, hussar monkey, Erythrocebus patas",
312
+ "372": "baboon",
313
+ "373": "macaque",
314
+ "374": "langur",
315
+ "375": "colobus, colobus monkey",
316
+ "376": "proboscis monkey, Nasalis larvatus",
317
+ "377": "marmoset",
318
+ "378": "capuchin, ringtail, Cebus capucinus",
319
+ "379": "howler monkey, howler",
320
+ "38": "banded gecko",
321
+ "380": "titi, titi monkey",
322
+ "381": "spider monkey, Ateles geoffroyi",
323
+ "382": "squirrel monkey, Saimiri sciureus",
324
+ "383": "Madagascar cat, ring-tailed lemur, Lemur catta",
325
+ "384": "indri, indris, Indri indri, Indri brevicaudatus",
326
+ "385": "Indian elephant, Elephas maximus",
327
+ "386": "African elephant, Loxodonta africana",
328
+ "387": "lesser panda, red panda, panda, bear cat, cat bear, Ailurus fulgens",
329
+ "388": "giant panda, panda, panda bear, coon bear, Ailuropoda melanoleuca",
330
+ "389": "barracouta, snoek",
331
+ "39": "common iguana, iguana, Iguana iguana",
332
+ "390": "eel",
333
+ "391": "coho, cohoe, coho salmon, blue jack, silver salmon, Oncorhynchus kisutch",
334
+ "392": "rock beauty, Holocanthus tricolor",
335
+ "393": "anemone fish",
336
+ "394": "sturgeon",
337
+ "395": "gar, garfish, garpike, billfish, Lepisosteus osseus",
338
+ "396": "lionfish",
339
+ "397": "puffer, pufferfish, blowfish, globefish",
340
+ "398": "abacus",
341
+ "399": "abaya",
342
+ "4": "hammerhead, hammerhead shark",
343
+ "40": "American chameleon, anole, Anolis carolinensis",
344
+ "400": "academic gown, academic robe, judge robe",
345
+ "401": "accordion, piano accordion, squeeze box",
346
+ "402": "acoustic guitar",
347
+ "403": "aircraft carrier, carrier, flattop, attack aircraft carrier",
348
+ "404": "airliner",
349
+ "405": "airship, dirigible",
350
+ "406": "altar",
351
+ "407": "ambulance",
352
+ "408": "amphibian, amphibious vehicle",
353
+ "409": "analog clock",
354
+ "41": "whiptail, whiptail lizard",
355
+ "410": "apiary, bee house",
356
+ "411": "apron",
357
+ "412": "ashcan, trash can, garbage can, wastebin, ash bin, ash-bin, ashbin, dustbin, trash barrel, trash bin",
358
+ "413": "assault rifle, assault gun",
359
+ "414": "backpack, back pack, knapsack, packsack, rucksack, haversack",
360
+ "415": "bakery, bakeshop, bakehouse",
361
+ "416": "balance beam, beam",
362
+ "417": "balloon",
363
+ "418": "ballpoint, ballpoint pen, ballpen, Biro",
364
+ "419": "Band Aid",
365
+ "42": "agama",
366
+ "420": "banjo",
367
+ "421": "bannister, banister, balustrade, balusters, handrail",
368
+ "422": "barbell",
369
+ "423": "barber chair",
370
+ "424": "barbershop",
371
+ "425": "barn",
372
+ "426": "barometer",
373
+ "427": "barrel, cask",
374
+ "428": "barrow, garden cart, lawn cart, wheelbarrow",
375
+ "429": "baseball",
376
+ "43": "frilled lizard, Chlamydosaurus kingi",
377
+ "430": "basketball",
378
+ "431": "bassinet",
379
+ "432": "bassoon",
380
+ "433": "bathing cap, swimming cap",
381
+ "434": "bath towel",
382
+ "435": "bathtub, bathing tub, bath, tub",
383
+ "436": "beach wagon, station wagon, wagon, estate car, beach waggon, station waggon, waggon",
384
+ "437": "beacon, lighthouse, beacon light, pharos",
385
+ "438": "beaker",
386
+ "439": "bearskin, busby, shako",
387
+ "44": "alligator lizard",
388
+ "440": "beer bottle",
389
+ "441": "beer glass",
390
+ "442": "bell cote, bell cot",
391
+ "443": "bib",
392
+ "444": "bicycle-built-for-two, tandem bicycle, tandem",
393
+ "445": "bikini, two-piece",
394
+ "446": "binder, ring-binder",
395
+ "447": "binoculars, field glasses, opera glasses",
396
+ "448": "birdhouse",
397
+ "449": "boathouse",
398
+ "45": "Gila monster, Heloderma suspectum",
399
+ "450": "bobsled, bobsleigh, bob",
400
+ "451": "bolo tie, bolo, bola tie, bola",
401
+ "452": "bonnet, poke bonnet",
402
+ "453": "bookcase",
403
+ "454": "bookshop, bookstore, bookstall",
404
+ "455": "bottlecap",
405
+ "456": "bow",
406
+ "457": "bow tie, bow-tie, bowtie",
407
+ "458": "brass, memorial tablet, plaque",
408
+ "459": "brassiere, bra, bandeau",
409
+ "46": "green lizard, Lacerta viridis",
410
+ "460": "breakwater, groin, groyne, mole, bulwark, seawall, jetty",
411
+ "461": "breastplate, aegis, egis",
412
+ "462": "broom",
413
+ "463": "bucket, pail",
414
+ "464": "buckle",
415
+ "465": "bulletproof vest",
416
+ "466": "bullet train, bullet",
417
+ "467": "butcher shop, meat market",
418
+ "468": "cab, hack, taxi, taxicab",
419
+ "469": "caldron, cauldron",
420
+ "47": "African chameleon, Chamaeleo chamaeleon",
421
+ "470": "candle, taper, wax light",
422
+ "471": "cannon",
423
+ "472": "canoe",
424
+ "473": "can opener, tin opener",
425
+ "474": "cardigan",
426
+ "475": "car mirror",
427
+ "476": "carousel, carrousel, merry-go-round, roundabout, whirligig",
428
+ "477": "carpenters kit, tool kit",
429
+ "478": "carton",
430
+ "479": "car wheel",
431
+ "48": "Komodo dragon, Komodo lizard, dragon lizard, giant lizard, Varanus komodoensis",
432
+ "480": "cash machine, cash dispenser, automated teller machine, automatic teller machine, automated teller, automatic teller, ATM",
433
+ "481": "cassette",
434
+ "482": "cassette player",
435
+ "483": "castle",
436
+ "484": "catamaran",
437
+ "485": "CD player",
438
+ "486": "cello, violoncello",
439
+ "487": "cellular telephone, cellular phone, cellphone, cell, mobile phone",
440
+ "488": "chain",
441
+ "489": "chainlink fence",
442
+ "49": "African crocodile, Nile crocodile, Crocodylus niloticus",
443
+ "490": "chain mail, ring mail, mail, chain armor, chain armour, ring armor, ring armour",
444
+ "491": "chain saw, chainsaw",
445
+ "492": "chest",
446
+ "493": "chiffonier, commode",
447
+ "494": "chime, bell, gong",
448
+ "495": "china cabinet, china closet",
449
+ "496": "Christmas stocking",
450
+ "497": "church, church building",
451
+ "498": "cinema, movie theater, movie theatre, movie house, picture palace",
452
+ "499": "cleaver, meat cleaver, chopper",
453
+ "5": "electric ray, crampfish, numbfish, torpedo",
454
+ "50": "American alligator, Alligator mississipiensis",
455
+ "500": "cliff dwelling",
456
+ "501": "cloak",
457
+ "502": "clog, geta, patten, sabot",
458
+ "503": "cocktail shaker",
459
+ "504": "coffee mug",
460
+ "505": "coffeepot",
461
+ "506": "coil, spiral, volute, whorl, helix",
462
+ "507": "combination lock",
463
+ "508": "computer keyboard, keypad",
464
+ "509": "confectionery, confectionary, candy store",
465
+ "51": "triceratops",
466
+ "510": "container ship, containership, container vessel",
467
+ "511": "convertible",
468
+ "512": "corkscrew, bottle screw",
469
+ "513": "cornet, horn, trumpet, trump",
470
+ "514": "cowboy boot",
471
+ "515": "cowboy hat, ten-gallon hat",
472
+ "516": "cradle",
473
+ "517": "crane",
474
+ "518": "crash helmet",
475
+ "519": "crate",
476
+ "52": "thunder snake, worm snake, Carphophis amoenus",
477
+ "520": "crib, cot",
478
+ "521": "Crock Pot",
479
+ "522": "croquet ball",
480
+ "523": "crutch",
481
+ "524": "cuirass",
482
+ "525": "dam, dike, dyke",
483
+ "526": "desk",
484
+ "527": "desktop computer",
485
+ "528": "dial telephone, dial phone",
486
+ "529": "diaper, nappy, napkin",
487
+ "53": "ringneck snake, ring-necked snake, ring snake",
488
+ "530": "digital clock",
489
+ "531": "digital watch",
490
+ "532": "dining table, board",
491
+ "533": "dishrag, dishcloth",
492
+ "534": "dishwasher, dish washer, dishwashing machine",
493
+ "535": "disk brake, disc brake",
494
+ "536": "dock, dockage, docking facility",
495
+ "537": "dogsled, dog sled, dog sleigh",
496
+ "538": "dome",
497
+ "539": "doormat, welcome mat",
498
+ "54": "hognose snake, puff adder, sand viper",
499
+ "540": "drilling platform, offshore rig",
500
+ "541": "drum, membranophone, tympan",
501
+ "542": "drumstick",
502
+ "543": "dumbbell",
503
+ "544": "Dutch oven",
504
+ "545": "electric fan, blower",
505
+ "546": "electric guitar",
506
+ "547": "electric locomotive",
507
+ "548": "entertainment center",
508
+ "549": "envelope",
509
+ "55": "green snake, grass snake",
510
+ "550": "espresso maker",
511
+ "551": "face powder",
512
+ "552": "feather boa, boa",
513
+ "553": "file, file cabinet, filing cabinet",
514
+ "554": "fireboat",
515
+ "555": "fire engine, fire truck",
516
+ "556": "fire screen, fireguard",
517
+ "557": "flagpole, flagstaff",
518
+ "558": "flute, transverse flute",
519
+ "559": "folding chair",
520
+ "56": "king snake, kingsnake",
521
+ "560": "football helmet",
522
+ "561": "forklift",
523
+ "562": "fountain",
524
+ "563": "fountain pen",
525
+ "564": "four-poster",
526
+ "565": "freight car",
527
+ "566": "French horn, horn",
528
+ "567": "frying pan, frypan, skillet",
529
+ "568": "fur coat",
530
+ "569": "garbage truck, dustcart",
531
+ "57": "garter snake, grass snake",
532
+ "570": "gasmask, respirator, gas helmet",
533
+ "571": "gas pump, gasoline pump, petrol pump, island dispenser",
534
+ "572": "goblet",
535
+ "573": "go-kart",
536
+ "574": "golf ball",
537
+ "575": "golfcart, golf cart",
538
+ "576": "gondola",
539
+ "577": "gong, tam-tam",
540
+ "578": "gown",
541
+ "579": "grand piano, grand",
542
+ "58": "water snake",
543
+ "580": "greenhouse, nursery, glasshouse",
544
+ "581": "grille, radiator grille",
545
+ "582": "grocery store, grocery, food market, market",
546
+ "583": "guillotine",
547
+ "584": "hair slide",
548
+ "585": "hair spray",
549
+ "586": "half track",
550
+ "587": "hammer",
551
+ "588": "hamper",
552
+ "589": "hand blower, blow dryer, blow drier, hair dryer, hair drier",
553
+ "59": "vine snake",
554
+ "590": "hand-held computer, hand-held microcomputer",
555
+ "591": "handkerchief, hankie, hanky, hankey",
556
+ "592": "hard disc, hard disk, fixed disk",
557
+ "593": "harmonica, mouth organ, harp, mouth harp",
558
+ "594": "harp",
559
+ "595": "harvester, reaper",
560
+ "596": "hatchet",
561
+ "597": "holster",
562
+ "598": "home theater, home theatre",
563
+ "599": "honeycomb",
564
+ "6": "stingray",
565
+ "60": "night snake, Hypsiglena torquata",
566
+ "600": "hook, claw",
567
+ "601": "hoopskirt, crinoline",
568
+ "602": "horizontal bar, high bar",
569
+ "603": "horse cart, horse-cart",
570
+ "604": "hourglass",
571
+ "605": "iPod",
572
+ "606": "iron, smoothing iron",
573
+ "607": "jack-o-lantern",
574
+ "608": "jean, blue jean, denim",
575
+ "609": "jeep, landrover",
576
+ "61": "boa constrictor, Constrictor constrictor",
577
+ "610": "jersey, T-shirt, tee shirt",
578
+ "611": "jigsaw puzzle",
579
+ "612": "jinrikisha, ricksha, rickshaw",
580
+ "613": "joystick",
581
+ "614": "kimono",
582
+ "615": "knee pad",
583
+ "616": "knot",
584
+ "617": "lab coat, laboratory coat",
585
+ "618": "ladle",
586
+ "619": "lampshade, lamp shade",
587
+ "62": "rock python, rock snake, Python sebae",
588
+ "620": "laptop, laptop computer",
589
+ "621": "lawn mower, mower",
590
+ "622": "lens cap, lens cover",
591
+ "623": "letter opener, paper knife, paperknife",
592
+ "624": "library",
593
+ "625": "lifeboat",
594
+ "626": "lighter, light, igniter, ignitor",
595
+ "627": "limousine, limo",
596
+ "628": "liner, ocean liner",
597
+ "629": "lipstick, lip rouge",
598
+ "63": "Indian cobra, Naja naja",
599
+ "630": "Loafer",
600
+ "631": "lotion",
601
+ "632": "loudspeaker, speaker, speaker unit, loudspeaker system, speaker system",
602
+ "633": "loupe, jewelers loupe",
603
+ "634": "lumbermill, sawmill",
604
+ "635": "magnetic compass",
605
+ "636": "mailbag, postbag",
606
+ "637": "mailbox, letter box",
607
+ "638": "maillot",
608
+ "639": "maillot, tank suit",
609
+ "64": "green mamba",
610
+ "640": "manhole cover",
611
+ "641": "maraca",
612
+ "642": "marimba, xylophone",
613
+ "643": "mask",
614
+ "644": "matchstick",
615
+ "645": "maypole",
616
+ "646": "maze, labyrinth",
617
+ "647": "measuring cup",
618
+ "648": "medicine chest, medicine cabinet",
619
+ "649": "megalith, megalithic structure",
620
+ "65": "sea snake",
621
+ "650": "microphone, mike",
622
+ "651": "microwave, microwave oven",
623
+ "652": "military uniform",
624
+ "653": "milk can",
625
+ "654": "minibus",
626
+ "655": "miniskirt, mini",
627
+ "656": "minivan",
628
+ "657": "missile",
629
+ "658": "mitten",
630
+ "659": "mixing bowl",
631
+ "66": "horned viper, cerastes, sand viper, horned asp, Cerastes cornutus",
632
+ "660": "mobile home, manufactured home",
633
+ "661": "Model T",
634
+ "662": "modem",
635
+ "663": "monastery",
636
+ "664": "monitor",
637
+ "665": "moped",
638
+ "666": "mortar",
639
+ "667": "mortarboard",
640
+ "668": "mosque",
641
+ "669": "mosquito net",
642
+ "67": "diamondback, diamondback rattlesnake, Crotalus adamanteus",
643
+ "670": "motor scooter, scooter",
644
+ "671": "mountain bike, all-terrain bike, off-roader",
645
+ "672": "mountain tent",
646
+ "673": "mouse, computer mouse",
647
+ "674": "mousetrap",
648
+ "675": "moving van",
649
+ "676": "muzzle",
650
+ "677": "nail",
651
+ "678": "neck brace",
652
+ "679": "necklace",
653
+ "68": "sidewinder, horned rattlesnake, Crotalus cerastes",
654
+ "680": "nipple",
655
+ "681": "notebook, notebook computer",
656
+ "682": "obelisk",
657
+ "683": "oboe, hautboy, hautbois",
658
+ "684": "ocarina, sweet potato",
659
+ "685": "odometer, hodometer, mileometer, milometer",
660
+ "686": "oil filter",
661
+ "687": "organ, pipe organ",
662
+ "688": "oscilloscope, scope, cathode-ray oscilloscope, CRO",
663
+ "689": "overskirt",
664
+ "69": "trilobite",
665
+ "690": "oxcart",
666
+ "691": "oxygen mask",
667
+ "692": "packet",
668
+ "693": "paddle, boat paddle",
669
+ "694": "paddlewheel, paddle wheel",
670
+ "695": "padlock",
671
+ "696": "paintbrush",
672
+ "697": "pajama, pyjama, pjs, jammies",
673
+ "698": "palace",
674
+ "699": "panpipe, pandean pipe, syrinx",
675
+ "7": "cock",
676
+ "70": "harvestman, daddy longlegs, Phalangium opilio",
677
+ "700": "paper towel",
678
+ "701": "parachute, chute",
679
+ "702": "parallel bars, bars",
680
+ "703": "park bench",
681
+ "704": "parking meter",
682
+ "705": "passenger car, coach, carriage",
683
+ "706": "patio, terrace",
684
+ "707": "pay-phone, pay-station",
685
+ "708": "pedestal, plinth, footstall",
686
+ "709": "pencil box, pencil case",
687
+ "71": "scorpion",
688
+ "710": "pencil sharpener",
689
+ "711": "perfume, essence",
690
+ "712": "Petri dish",
691
+ "713": "photocopier",
692
+ "714": "pick, plectrum, plectron",
693
+ "715": "pickelhaube",
694
+ "716": "picket fence, paling",
695
+ "717": "pickup, pickup truck",
696
+ "718": "pier",
697
+ "719": "piggy bank, penny bank",
698
+ "72": "black and gold garden spider, Argiope aurantia",
699
+ "720": "pill bottle",
700
+ "721": "pillow",
701
+ "722": "ping-pong ball",
702
+ "723": "pinwheel",
703
+ "724": "pirate, pirate ship",
704
+ "725": "pitcher, ewer",
705
+ "726": "plane, carpenters plane, woodworking plane",
706
+ "727": "planetarium",
707
+ "728": "plastic bag",
708
+ "729": "plate rack",
709
+ "73": "barn spider, Araneus cavaticus",
710
+ "730": "plow, plough",
711
+ "731": "plunger, plumbers helper",
712
+ "732": "Polaroid camera, Polaroid Land camera",
713
+ "733": "pole",
714
+ "734": "police van, police wagon, paddy wagon, patrol wagon, wagon, black Maria",
715
+ "735": "poncho",
716
+ "736": "pool table, billiard table, snooker table",
717
+ "737": "pop bottle, soda bottle",
718
+ "738": "pot, flowerpot",
719
+ "739": "potters wheel",
720
+ "74": "garden spider, Aranea diademata",
721
+ "740": "power drill",
722
+ "741": "prayer rug, prayer mat",
723
+ "742": "printer",
724
+ "743": "prison, prison house",
725
+ "744": "projectile, missile",
726
+ "745": "projector",
727
+ "746": "puck, hockey puck",
728
+ "747": "punching bag, punch bag, punching ball, punchball",
729
+ "748": "purse",
730
+ "749": "quill, quill pen",
731
+ "75": "black widow, Latrodectus mactans",
732
+ "750": "quilt, comforter, comfort, puff",
733
+ "751": "racer, race car, racing car",
734
+ "752": "racket, racquet",
735
+ "753": "radiator",
736
+ "754": "radio, wireless",
737
+ "755": "radio telescope, radio reflector",
738
+ "756": "rain barrel",
739
+ "757": "recreational vehicle, RV, R.V.",
740
+ "758": "reel",
741
+ "759": "reflex camera",
742
+ "76": "tarantula",
743
+ "760": "refrigerator, icebox",
744
+ "761": "remote control, remote",
745
+ "762": "restaurant, eating house, eating place, eatery",
746
+ "763": "revolver, six-gun, six-shooter",
747
+ "764": "rifle",
748
+ "765": "rocking chair, rocker",
749
+ "766": "rotisserie",
750
+ "767": "rubber eraser, rubber, pencil eraser",
751
+ "768": "rugby ball",
752
+ "769": "rule, ruler",
753
+ "77": "wolf spider, hunting spider",
754
+ "770": "running shoe",
755
+ "771": "safe",
756
+ "772": "safety pin",
757
+ "773": "saltshaker, salt shaker",
758
+ "774": "sandal",
759
+ "775": "sarong",
760
+ "776": "sax, saxophone",
761
+ "777": "scabbard",
762
+ "778": "scale, weighing machine",
763
+ "779": "school bus",
764
+ "78": "tick",
765
+ "780": "schooner",
766
+ "781": "scoreboard",
767
+ "782": "screen, CRT screen",
768
+ "783": "screw",
769
+ "784": "screwdriver",
770
+ "785": "seat belt, seatbelt",
771
+ "786": "sewing machine",
772
+ "787": "shield, buckler",
773
+ "788": "shoe shop, shoe-shop, shoe store",
774
+ "789": "shoji",
775
+ "79": "centipede",
776
+ "790": "shopping basket",
777
+ "791": "shopping cart",
778
+ "792": "shovel",
779
+ "793": "shower cap",
780
+ "794": "shower curtain",
781
+ "795": "ski",
782
+ "796": "ski mask",
783
+ "797": "sleeping bag",
784
+ "798": "slide rule, slipstick",
785
+ "799": "sliding door",
786
+ "8": "hen",
787
+ "80": "black grouse",
788
+ "800": "slot, one-armed bandit",
789
+ "801": "snorkel",
790
+ "802": "snowmobile",
791
+ "803": "snowplow, snowplough",
792
+ "804": "soap dispenser",
793
+ "805": "soccer ball",
794
+ "806": "sock",
795
+ "807": "solar dish, solar collector, solar furnace",
796
+ "808": "sombrero",
797
+ "809": "soup bowl",
798
+ "81": "ptarmigan",
799
+ "810": "space bar",
800
+ "811": "space heater",
801
+ "812": "space shuttle",
802
+ "813": "spatula",
803
+ "814": "speedboat",
804
+ "815": "spider web, spiders web",
805
+ "816": "spindle",
806
+ "817": "sports car, sport car",
807
+ "818": "spotlight, spot",
808
+ "819": "stage",
809
+ "82": "ruffed grouse, partridge, Bonasa umbellus",
810
+ "820": "steam locomotive",
811
+ "821": "steel arch bridge",
812
+ "822": "steel drum",
813
+ "823": "stethoscope",
814
+ "824": "stole",
815
+ "825": "stone wall",
816
+ "826": "stopwatch, stop watch",
817
+ "827": "stove",
818
+ "828": "strainer",
819
+ "829": "streetcar, tram, tramcar, trolley, trolley car",
820
+ "83": "prairie chicken, prairie grouse, prairie fowl",
821
+ "830": "stretcher",
822
+ "831": "studio couch, day bed",
823
+ "832": "stupa, tope",
824
+ "833": "submarine, pigboat, sub, U-boat",
825
+ "834": "suit, suit of clothes",
826
+ "835": "sundial",
827
+ "836": "sunglass",
828
+ "837": "sunglasses, dark glasses, shades",
829
+ "838": "sunscreen, sunblock, sun blocker",
830
+ "839": "suspension bridge",
831
+ "84": "peacock",
832
+ "840": "swab, swob, mop",
833
+ "841": "sweatshirt",
834
+ "842": "swimming trunks, bathing trunks",
835
+ "843": "swing",
836
+ "844": "switch, electric switch, electrical switch",
837
+ "845": "syringe",
838
+ "846": "table lamp",
839
+ "847": "tank, army tank, armored combat vehicle, armoured combat vehicle",
840
+ "848": "tape player",
841
+ "849": "teapot",
842
+ "85": "quail",
843
+ "850": "teddy, teddy bear",
844
+ "851": "television, television system",
845
+ "852": "tennis ball",
846
+ "853": "thatch, thatched roof",
847
+ "854": "theater curtain, theatre curtain",
848
+ "855": "thimble",
849
+ "856": "thresher, thrasher, threshing machine",
850
+ "857": "throne",
851
+ "858": "tile roof",
852
+ "859": "toaster",
853
+ "86": "partridge",
854
+ "860": "tobacco shop, tobacconist shop, tobacconist",
855
+ "861": "toilet seat",
856
+ "862": "torch",
857
+ "863": "totem pole",
858
+ "864": "tow truck, tow car, wrecker",
859
+ "865": "toyshop",
860
+ "866": "tractor",
861
+ "867": "trailer truck, tractor trailer, trucking rig, rig, articulated lorry, semi",
862
+ "868": "tray",
863
+ "869": "trench coat",
864
+ "87": "African grey, African gray, Psittacus erithacus",
865
+ "870": "tricycle, trike, velocipede",
866
+ "871": "trimaran",
867
+ "872": "tripod",
868
+ "873": "triumphal arch",
869
+ "874": "trolleybus, trolley coach, trackless trolley",
870
+ "875": "trombone",
871
+ "876": "tub, vat",
872
+ "877": "turnstile",
873
+ "878": "typewriter keyboard",
874
+ "879": "umbrella",
875
+ "88": "macaw",
876
+ "880": "unicycle, monocycle",
877
+ "881": "upright, upright piano",
878
+ "882": "vacuum, vacuum cleaner",
879
+ "883": "vase",
880
+ "884": "vault",
881
+ "885": "velvet",
882
+ "886": "vending machine",
883
+ "887": "vestment",
884
+ "888": "viaduct",
885
+ "889": "violin, fiddle",
886
+ "89": "sulphur-crested cockatoo, Kakatoe galerita, Cacatua galerita",
887
+ "890": "volleyball",
888
+ "891": "waffle iron",
889
+ "892": "wall clock",
890
+ "893": "wallet, billfold, notecase, pocketbook",
891
+ "894": "wardrobe, closet, press",
892
+ "895": "warplane, military plane",
893
+ "896": "washbasin, handbasin, washbowl, lavabo, wash-hand basin",
894
+ "897": "washer, automatic washer, washing machine",
895
+ "898": "water bottle",
896
+ "899": "water jug",
897
+ "9": "ostrich, Struthio camelus",
898
+ "90": "lorikeet",
899
+ "900": "water tower",
900
+ "901": "whiskey jug",
901
+ "902": "whistle",
902
+ "903": "wig",
903
+ "904": "window screen",
904
+ "905": "window shade",
905
+ "906": "Windsor tie",
906
+ "907": "wine bottle",
907
+ "908": "wing",
908
+ "909": "wok",
909
+ "91": "coucal",
910
+ "910": "wooden spoon",
911
+ "911": "wool, woolen, woollen",
912
+ "912": "worm fence, snake fence, snake-rail fence, Virginia fence",
913
+ "913": "wreck",
914
+ "914": "yawl",
915
+ "915": "yurt",
916
+ "916": "web site, website, internet site, site",
917
+ "917": "comic book",
918
+ "918": "crossword puzzle, crossword",
919
+ "919": "street sign",
920
+ "92": "bee eater",
921
+ "920": "traffic light, traffic signal, stoplight",
922
+ "921": "book jacket, dust cover, dust jacket, dust wrapper",
923
+ "922": "menu",
924
+ "923": "plate",
925
+ "924": "guacamole",
926
+ "925": "consomme",
927
+ "926": "hot pot, hotpot",
928
+ "927": "trifle",
929
+ "928": "ice cream, icecream",
930
+ "929": "ice lolly, lolly, lollipop, popsicle",
931
+ "93": "hornbill",
932
+ "930": "French loaf",
933
+ "931": "bagel, beigel",
934
+ "932": "pretzel",
935
+ "933": "cheeseburger",
936
+ "934": "hotdog, hot dog, red hot",
937
+ "935": "mashed potato",
938
+ "936": "head cabbage",
939
+ "937": "broccoli",
940
+ "938": "cauliflower",
941
+ "939": "zucchini, courgette",
942
+ "94": "hummingbird",
943
+ "940": "spaghetti squash",
944
+ "941": "acorn squash",
945
+ "942": "butternut squash",
946
+ "943": "cucumber, cuke",
947
+ "944": "artichoke, globe artichoke",
948
+ "945": "bell pepper",
949
+ "946": "cardoon",
950
+ "947": "mushroom",
951
+ "948": "Granny Smith",
952
+ "949": "strawberry",
953
+ "95": "jacamar",
954
+ "950": "orange",
955
+ "951": "lemon",
956
+ "952": "fig",
957
+ "953": "pineapple, ananas",
958
+ "954": "banana",
959
+ "955": "jackfruit, jak, jack",
960
+ "956": "custard apple",
961
+ "957": "pomegranate",
962
+ "958": "hay",
963
+ "959": "carbonara",
964
+ "96": "toucan",
965
+ "960": "chocolate sauce, chocolate syrup",
966
+ "961": "dough",
967
+ "962": "meat loaf, meatloaf",
968
+ "963": "pizza, pizza pie",
969
+ "964": "potpie",
970
+ "965": "burrito",
971
+ "966": "red wine",
972
+ "967": "espresso",
973
+ "968": "cup",
974
+ "969": "eggnog",
975
+ "97": "drake",
976
+ "970": "alp",
977
+ "971": "bubble",
978
+ "972": "cliff, drop, drop-off",
979
+ "973": "coral reef",
980
+ "974": "geyser",
981
+ "975": "lakeside, lakeshore",
982
+ "976": "promontory, headland, head, foreland",
983
+ "977": "sandbar, sand bar",
984
+ "978": "seashore, coast, seacoast, sea-coast",
985
+ "979": "valley, vale",
986
+ "98": "red-breasted merganser, Mergus serrator",
987
+ "980": "volcano",
988
+ "981": "ballplayer, baseball player",
989
+ "982": "groom, bridegroom",
990
+ "983": "scuba diver",
991
+ "984": "rapeseed",
992
+ "985": "daisy",
993
+ "986": "yellow ladys slipper, yellow lady-slipper, Cypripedium calceolus, Cypripedium parviflorum",
994
+ "987": "corn",
995
+ "988": "acorn",
996
+ "989": "hip, rose hip, rosehip",
997
+ "99": "goose",
998
+ "990": "buckeye, horse chestnut, conker",
999
+ "991": "coral fungus",
1000
+ "992": "agaric",
1001
+ "993": "gyromitra",
1002
+ "994": "stinkhorn, carrion fungus",
1003
+ "995": "earthstar",
1004
+ "996": "hen-of-the-woods, hen of the woods, Polyporus frondosus, Grifola frondosa",
1005
+ "997": "bolete",
1006
+ "998": "ear, spike, capitulum",
1007
+ "999": "toilet tissue, toilet paper, bathroom tissue"
1008
+ },
1009
+ "scheduler": [
1010
+ "diffusers",
1011
+ "FlowMatchEulerDiscreteScheduler"
1012
+ ],
1013
+ "transformer": [
1014
+ "transformer_pixeldit",
1015
+ "PixelDiTTransformer2DModel"
1016
+ ]
1017
+ }
PixelDiT-XL-16-512/pipeline.py ADDED
@@ -0,0 +1,286 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Hub custom pipeline: PixelDiTPipeline.
2
+ Load with native Hugging Face diffusers and trust_remote_code=True.
3
+ """
4
+
5
+ from __future__ import annotations
6
+
7
+ import inspect
8
+ import json
9
+ from pathlib import Path
10
+ from typing import Dict, List, Optional, Tuple, Union
11
+
12
+ import torch
13
+ from diffusers.pipelines.pipeline_utils import DiffusionPipeline, ImagePipelineOutput
14
+ from diffusers.schedulers import FlowMatchEulerDiscreteScheduler
15
+ from diffusers.utils.torch_utils import randn_tensor
16
+
17
+ RECOMMENDED_GUIDANCE_BY_SIZE = {
18
+ 256: 3.25,
19
+ 512: 3.75,
20
+ }
21
+
22
+ RECOMMENDED_SCHEDULER_SHIFT_BY_SIZE = {
23
+ 256: 1.0,
24
+ 512: 3.0,
25
+ }
26
+
27
+
28
+ class PixelDiTPipeline(DiffusionPipeline):
29
+ r"""
30
+ Pipeline for image generation using PixelDiT (Pixel Diffusion Transformer).
31
+
32
+ Parameters:
33
+ transformer ([`PixelDiTTransformer2DModel`]):
34
+ A class-conditioned `PixelDiTTransformer2DModel` that predicts flow-matching velocity in pixel space.
35
+ scheduler ([`FlowMatchEulerDiscreteScheduler`]):
36
+ Diffusers scheduler interface for PixelDiT generation (defaults to deterministic flow-matching Euler).
37
+ id2label (`dict[int, str]`, *optional*):
38
+ ImageNet class id to English label mapping. Values may contain comma-separated synonyms.
39
+ """
40
+
41
+ @staticmethod
42
+ def prepare_extra_step_kwargs(
43
+ scheduler,
44
+ generator=None,
45
+ eta: float | None = None,
46
+ ):
47
+ kwargs = {}
48
+ step_params = set(inspect.signature(scheduler.step).parameters.keys())
49
+ if "generator" in step_params:
50
+ kwargs["generator"] = generator
51
+ if eta is not None and "eta" in step_params:
52
+ kwargs["eta"] = eta
53
+ return kwargs
54
+
55
+ model_cpu_offload_seq = "transformer"
56
+
57
+ def __init__(
58
+ self,
59
+ transformer,
60
+ scheduler,
61
+ id2label: Optional[Dict[Union[int, str], str]] = None,
62
+ ):
63
+ super().__init__()
64
+ sample_size = int(getattr(transformer.config, "sample_size", 256))
65
+ default_shift = RECOMMENDED_SCHEDULER_SHIFT_BY_SIZE.get(sample_size, 1.0)
66
+ scheduler = scheduler or FlowMatchEulerDiscreteScheduler(
67
+ num_train_timesteps=1000,
68
+ shift=default_shift,
69
+ stochastic_sampling=False,
70
+ )
71
+ self.register_modules(transformer=transformer, scheduler=scheduler)
72
+ self._id2label = self._normalize_id2label(id2label)
73
+ self.labels = self._build_label2id(self._id2label)
74
+ self._labels_loaded_from_model_index = bool(self._id2label)
75
+
76
+ def _ensure_labels_loaded(self) -> None:
77
+ if self._labels_loaded_from_model_index:
78
+ return
79
+ loaded = self._read_id2label_from_model_index(getattr(self.config, "_name_or_path", None))
80
+ if loaded:
81
+ self._id2label = loaded
82
+ self.labels = self._build_label2id(self._id2label)
83
+ self._labels_loaded_from_model_index = True
84
+
85
+ @staticmethod
86
+ def _normalize_id2label(id2label: Optional[Dict[Union[int, str], str]]) -> Dict[int, str]:
87
+ if not id2label:
88
+ return {}
89
+ return {int(key): value for key, value in id2label.items()}
90
+
91
+ @staticmethod
92
+ def _read_id2label_from_model_index(variant_path: Optional[str]) -> Dict[int, str]:
93
+ if not variant_path:
94
+ return {}
95
+ variant_dir = Path(variant_path).resolve()
96
+ model_index_path = variant_dir / "model_index.json"
97
+ if not model_index_path.exists():
98
+ return {}
99
+ raw = json.loads(model_index_path.read_text(encoding="utf-8"))
100
+ id2label = raw.get("id2label")
101
+ if not isinstance(id2label, dict):
102
+ return {}
103
+ return {int(key): value for key, value in id2label.items()}
104
+
105
+ @staticmethod
106
+ def _build_label2id(id2label: Dict[int, str]) -> Dict[str, int]:
107
+ label2id: Dict[str, int] = {}
108
+ for class_id, value in id2label.items():
109
+ for synonym in value.split(","):
110
+ synonym = synonym.strip()
111
+ if synonym:
112
+ label2id[synonym] = int(class_id)
113
+ return dict(sorted(label2id.items()))
114
+
115
+ @property
116
+ def id2label(self) -> Dict[int, str]:
117
+ self._ensure_labels_loaded()
118
+ return self._id2label
119
+
120
+ def get_label_ids(self, label: Union[str, List[str]]) -> List[int]:
121
+ self._ensure_labels_loaded()
122
+ label2id = self.labels
123
+ if not label2id:
124
+ raise ValueError(
125
+ "No English labels loaded. Ensure `id2label` exists in model_index.json."
126
+ )
127
+
128
+ if isinstance(label, str):
129
+ label = [label]
130
+
131
+ missing = [item for item in label if item not in label2id]
132
+ if missing:
133
+ preview = ", ".join(list(label2id.keys())[:8])
134
+ raise ValueError(f"Unknown English label(s): {missing}. Example valid labels: {preview}, ...")
135
+ return [label2id[item] for item in label]
136
+
137
+ def _normalize_class_labels(
138
+ self,
139
+ class_labels: Union[int, str, List[Union[int, str]]],
140
+ ) -> List[int]:
141
+ if isinstance(class_labels, int):
142
+ return [class_labels]
143
+
144
+ if isinstance(class_labels, str):
145
+ return self.get_label_ids(class_labels)
146
+
147
+ if class_labels and isinstance(class_labels[0], str):
148
+ return self.get_label_ids(class_labels)
149
+
150
+ return list(class_labels)
151
+
152
+ @staticmethod
153
+ def _resolve_timeshift(scheduler, image_size: int) -> float:
154
+ shift = getattr(scheduler.config, "shift", None)
155
+ if shift is not None:
156
+ return float(shift)
157
+ return RECOMMENDED_SCHEDULER_SHIFT_BY_SIZE.get(image_size, 1.0)
158
+
159
+ @staticmethod
160
+ def _build_flow_timesteps(
161
+ num_inference_steps: int,
162
+ timeshift: float,
163
+ device: torch.device,
164
+ dtype: torch.dtype,
165
+ ) -> torch.Tensor:
166
+ last_step = 1.0 / num_inference_steps if num_inference_steps > 1 else 1.0
167
+ timesteps = torch.linspace(0.0, 1.0 - last_step, num_inference_steps, device=device, dtype=dtype)
168
+ timesteps = torch.cat([timesteps, torch.ones(1, device=device, dtype=dtype)], dim=0)
169
+ if timeshift != 1.0:
170
+ timesteps = timesteps / (timesteps + (1.0 - timesteps) * timeshift)
171
+ return timesteps
172
+
173
+ @staticmethod
174
+ def _apply_classifier_free_guidance(model_output: torch.Tensor, guidance_scale: float) -> torch.Tensor:
175
+ model_output_uncond, model_output_cond = model_output.chunk(2, dim=0)
176
+ return model_output_uncond + guidance_scale * (model_output_cond - model_output_uncond)
177
+
178
+ @torch.inference_mode()
179
+ def __call__(
180
+ self,
181
+ class_labels: Union[int, str, List[Union[int, str]]],
182
+ guidance_scale: Optional[float] = None,
183
+ guidance_interval_min: float = 0.1,
184
+ guidance_interval_max: float = 1.0,
185
+ generator: Optional[Union[torch.Generator, List[torch.Generator]]] = None,
186
+ num_inference_steps: int = 100,
187
+ height: Optional[int] = None,
188
+ width: Optional[int] = None,
189
+ output_type: Optional[str] = "pil",
190
+ return_dict: bool = True,
191
+ ) -> Union[ImagePipelineOutput, Tuple]:
192
+ if num_inference_steps < 1:
193
+ raise ValueError("num_inference_steps must be >= 1.")
194
+ if output_type not in {"pil", "np", "pt"}:
195
+ raise ValueError("output_type must be one of: 'pil', 'np', 'pt'.")
196
+
197
+ class_label_ids = self._normalize_class_labels(class_labels)
198
+ do_classifier_free_guidance = guidance_scale is not None and guidance_scale > 1.0
199
+
200
+ batch_size = len(class_label_ids)
201
+ image_size = int(getattr(self.transformer.config, "sample_size", 256))
202
+ patch_size = int(self.transformer.config.patch_size)
203
+ height = int(height or image_size)
204
+ width = int(width or image_size)
205
+ if height <= 0 or width <= 0:
206
+ raise ValueError("height and width must be positive integers.")
207
+ if height % patch_size != 0 or width % patch_size != 0:
208
+ raise ValueError(
209
+ f"height and width must be divisible by patch_size={patch_size}. Got {(height, width)}."
210
+ )
211
+ channels = int(self.transformer.config.in_channels)
212
+ null_class_val = int(
213
+ getattr(self.transformer.config, "num_classes", getattr(self.transformer.config, "num_class_embeds", 1000))
214
+ )
215
+
216
+ if guidance_scale is None:
217
+ guidance_scale = RECOMMENDED_GUIDANCE_BY_SIZE.get(image_size, 3.25)
218
+
219
+ latents = randn_tensor(
220
+ shape=(batch_size, channels, height, width),
221
+ generator=generator,
222
+ device=self._execution_device,
223
+ dtype=self.transformer.dtype,
224
+ )
225
+
226
+ class_labels_t = torch.tensor(class_label_ids, device=self._execution_device, dtype=torch.long).reshape(-1)
227
+ class_labels_t = class_labels_t.clamp(0, null_class_val - 1)
228
+ class_null = torch.full_like(class_labels_t, null_class_val)
229
+
230
+ timeshift = self._resolve_timeshift(self.scheduler, image_size)
231
+ flow_timesteps = self._build_flow_timesteps(
232
+ num_inference_steps,
233
+ timeshift,
234
+ device=self._execution_device,
235
+ dtype=torch.float32,
236
+ )
237
+ velocity_dtype = self.transformer.dtype
238
+ v_prev = None
239
+
240
+ for t_cur, t_next in self.progress_bar(list(zip(flow_timesteps[:-1], flow_timesteps[1:]))):
241
+ dt = t_next - t_cur
242
+ flow_time = float(t_cur)
243
+ effective_guidance = (
244
+ guidance_scale
245
+ if do_classifier_free_guidance
246
+ and guidance_interval_min < flow_time < guidance_interval_max
247
+ else 1.0
248
+ )
249
+
250
+ latent_model_input = torch.cat([latents, latents], dim=0)
251
+ labels = torch.cat([class_null, class_labels_t], dim=0)
252
+ timesteps = torch.full(
253
+ (latent_model_input.shape[0],),
254
+ flow_time,
255
+ device=self._execution_device,
256
+ dtype=velocity_dtype,
257
+ )
258
+ model_output = self.transformer(
259
+ latent_model_input,
260
+ timestep=timesteps,
261
+ class_labels=labels,
262
+ ).sample
263
+ velocity = self._apply_classifier_free_guidance(model_output, effective_guidance)
264
+
265
+ if v_prev is None:
266
+ latents = latents + velocity * dt
267
+ else:
268
+ latents = latents + dt * (1.5 * velocity - 0.5 * v_prev)
269
+ v_prev = velocity
270
+
271
+ images_pt = ((latents.float().clamp(-1, 1) + 1.0) / 2.0).cpu()
272
+ if output_type == "pt":
273
+ images = images_pt
274
+ elif output_type == "np":
275
+ images = images_pt.permute(0, 2, 3, 1).numpy()
276
+ else:
277
+ images = self.numpy_to_pil(images_pt.permute(0, 2, 3, 1).numpy())
278
+
279
+ self.maybe_free_model_hooks()
280
+
281
+ if not return_dict:
282
+ return (images,)
283
+ return ImagePipelineOutput(images=images)
284
+
285
+
286
+ PixelDiTPipelineOutput = ImagePipelineOutput
PixelDiT-XL-16-512/scheduler/scheduler_config.json ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ {
2
+ "_class_name": "FlowMatchEulerDiscreteScheduler",
3
+ "_diffusers_version": "0.36.0",
4
+ "num_train_timesteps": 1000,
5
+ "shift": 3.0,
6
+ "stochastic_sampling": false
7
+ }
PixelDiT-XL-16-512/transformer/config.json ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "_class_name": "PixelDiTTransformer2DModel",
3
+ "hidden_size": 1152,
4
+ "in_channels": 3,
5
+ "model_type": "pixeldit-xl",
6
+ "num_classes": 1000,
7
+ "num_groups": 16,
8
+ "patch_depth": 26,
9
+ "patch_size": 16,
10
+ "pixel_depth": 4,
11
+ "pixel_hidden_size": 16,
12
+ "sample_size": 512,
13
+ "use_pixel_abs_pos": true
14
+ }
PixelDiT-XL-16-512/transformer/diffusion_pytorch_model.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:8fc9fe08e4de9709a94818cd5519604715641280e47f3f41e48993f05e22fa99
3
+ size 3189574228
PixelDiT-XL-16-512/transformer/transformer_pixeldit.py ADDED
@@ -0,0 +1,639 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright 2026 The HuggingFace Team. All rights reserved.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ from __future__ import annotations
16
+
17
+ import math
18
+ from collections.abc import Mapping
19
+ from typing import Dict, Literal, Optional, Tuple, Union
20
+
21
+ import numpy as np
22
+ import torch
23
+ import torch.nn as nn
24
+ import torch.nn.functional as F
25
+ from diffusers.configuration_utils import ConfigMixin, register_to_config
26
+ from diffusers.models.modeling_outputs import Transformer2DModelOutput
27
+ from diffusers.models.modeling_utils import ModelMixin
28
+ from diffusers.models.normalization import RMSNorm
29
+
30
+
31
+ PIXELDIT_PRESET_CONFIGS: Dict[str, Dict[str, object]] = {
32
+ "pixeldit-xl": {
33
+ "sample_size": 256,
34
+ "num_groups": 16,
35
+ "hidden_size": 1152,
36
+ "pixel_hidden_size": 16,
37
+ "patch_depth": 26,
38
+ "pixel_depth": 4,
39
+ "patch_size": 16,
40
+ },
41
+ }
42
+
43
+
44
+ def remap_legacy_state_dict(state_dict: Dict[str, torch.Tensor]) -> Dict[str, torch.Tensor]:
45
+ """Map wrapper/backbone keys from legacy checkpoints to native PixelDiTTransformer2DModel keys."""
46
+ remapped: Dict[str, torch.Tensor] = {}
47
+ prefixes = ("transformer.", "model.", "module.", "denoiser.", "net.")
48
+ for key, value in state_dict.items():
49
+ new_key = key
50
+ for prefix in prefixes:
51
+ if new_key.startswith(prefix):
52
+ new_key = new_key[len(prefix) :]
53
+ break
54
+ remapped[new_key] = value
55
+ return remapped
56
+
57
+
58
+ def config_from_legacy(config: Dict[str, object]) -> Dict[str, object]:
59
+ """Build native config kwargs from a legacy config.json dict."""
60
+ model_type = config.get("model_type") or config.get("model_name") or config.get("model_size")
61
+ if model_type not in PIXELDIT_PRESET_CONFIGS:
62
+ raise ValueError(f"Unknown PixelDiT preset '{model_type}'. Known: {list(PIXELDIT_PRESET_CONFIGS)}")
63
+
64
+ preset = dict(PIXELDIT_PRESET_CONFIGS[model_type])
65
+ preset["num_classes"] = int(config.get("num_classes") or config.get("num_class_embeds") or 1000)
66
+ preset["in_channels"] = int(config.get("in_channels", 3))
67
+ preset["use_pixel_abs_pos"] = bool(config.get("use_pixel_abs_pos", True))
68
+ preset["model_type"] = model_type
69
+
70
+ for key in ("sample_size", "num_groups", "hidden_size", "pixel_hidden_size", "patch_depth", "pixel_depth", "patch_size"):
71
+ if config.get(key) is not None:
72
+ preset[key] = config[key]
73
+
74
+ return preset
75
+
76
+
77
+ def get_2d_sincos_pos_embed(embed_dim: int, grid_size: int) -> np.ndarray:
78
+ grid_h = np.arange(grid_size, dtype=np.float32)
79
+ grid_w = np.arange(grid_size, dtype=np.float32)
80
+ grid = np.meshgrid(grid_w, grid_h)
81
+ grid = np.stack(grid, axis=0)
82
+ grid = grid.reshape([2, 1, grid_size, grid_size])
83
+ return get_2d_sincos_pos_embed_from_grid(embed_dim, grid)
84
+
85
+
86
+ def get_2d_sincos_pos_embed_from_grid(embed_dim: int, grid: np.ndarray) -> np.ndarray:
87
+ if embed_dim % 2 != 0:
88
+ raise ValueError("Embedding dimension must be even for 2D sin/cos positional embeddings.")
89
+ emb_h = get_1d_sincos_pos_embed_from_grid(embed_dim // 2, grid[0])
90
+ emb_w = get_1d_sincos_pos_embed_from_grid(embed_dim // 2, grid[1])
91
+ return np.concatenate([emb_h, emb_w], axis=1)
92
+
93
+
94
+ def get_1d_sincos_pos_embed_from_grid(embed_dim: int, pos: np.ndarray) -> np.ndarray:
95
+ if embed_dim % 2 != 0:
96
+ raise ValueError("Embedding dimension must be even for 1D sin/cos positional embeddings.")
97
+ omega = np.arange(embed_dim // 2, dtype=np.float64)
98
+ omega /= embed_dim / 2.0
99
+ omega = 1.0 / 10000**omega
100
+ pos = pos.reshape(-1)
101
+ out = np.einsum("m,d->md", pos, omega)
102
+ return np.concatenate([np.sin(out), np.cos(out)], axis=1)
103
+
104
+
105
+ def apply_adaln(hidden_states: torch.Tensor, shift: torch.Tensor, scale: torch.Tensor) -> torch.Tensor:
106
+ return hidden_states * (1 + scale) + shift
107
+
108
+
109
+ def precompute_freqs_cis_2d(dim: int, height: int, width: int, theta: float = 10000.0, scale: float = 16.0):
110
+ x_pos = torch.linspace(0, scale, width)
111
+ y_pos = torch.linspace(0, scale, height)
112
+ y_pos, x_pos = torch.meshgrid(y_pos, x_pos, indexing="ij")
113
+ y_pos = y_pos.reshape(-1)
114
+ x_pos = x_pos.reshape(-1)
115
+ freqs = 1.0 / (theta ** (torch.arange(0, dim, 4)[: (dim // 4)].float() / dim))
116
+ x_freqs = torch.outer(x_pos, freqs).float()
117
+ y_freqs = torch.outer(y_pos, freqs).float()
118
+ x_cis = torch.polar(torch.ones_like(x_freqs), x_freqs)
119
+ y_cis = torch.polar(torch.ones_like(y_freqs), y_freqs)
120
+ freqs_cis = torch.cat([x_cis.unsqueeze(dim=-1), y_cis.unsqueeze(dim=-1)], dim=-1)
121
+ return freqs_cis.reshape(height * width, -1)
122
+
123
+
124
+ def apply_rotary_emb(
125
+ xq: torch.Tensor,
126
+ xk: torch.Tensor,
127
+ freqs_cis: torch.Tensor,
128
+ ) -> Tuple[torch.Tensor, torch.Tensor]:
129
+ freqs_cis = freqs_cis[None, :, None, :]
130
+ xq_ = torch.view_as_complex(xq.float().reshape(*xq.shape[:-1], -1, 2))
131
+ xk_ = torch.view_as_complex(xk.float().reshape(*xk.shape[:-1], -1, 2))
132
+ xq_out = torch.view_as_real(xq_ * freqs_cis).flatten(3)
133
+ xk_out = torch.view_as_real(xk_ * freqs_cis).flatten(3)
134
+ return xq_out.type_as(xq), xk_out.type_as(xk)
135
+
136
+
137
+ class TimestepConditioner(nn.Module):
138
+ def __init__(self, hidden_size: int, frequency_embedding_size: int = 256):
139
+ super().__init__()
140
+ self.mlp = nn.Sequential(
141
+ nn.Linear(frequency_embedding_size, hidden_size, bias=True),
142
+ nn.SiLU(),
143
+ nn.Linear(hidden_size, hidden_size, bias=True),
144
+ )
145
+ self.frequency_embedding_size = frequency_embedding_size
146
+
147
+ @staticmethod
148
+ def timestep_embedding(timesteps: torch.Tensor, dim: int, max_period: int = 10):
149
+ half = dim // 2
150
+ freqs = torch.exp(
151
+ -math.log(max_period) * torch.arange(start=0, end=half, dtype=torch.float32, device=timesteps.device) / half
152
+ )
153
+ args = timesteps[..., None].float() * freqs[None, ...]
154
+ embedding = torch.cat([torch.cos(args), torch.sin(args)], dim=-1)
155
+ if dim % 2:
156
+ embedding = torch.cat([embedding, torch.zeros_like(embedding[:, :1])], dim=-1)
157
+ return embedding
158
+
159
+ def forward(self, timesteps: torch.Tensor) -> torch.Tensor:
160
+ timestep_freq = self.timestep_embedding(timesteps, self.frequency_embedding_size)
161
+ mlp_dtype = next(self.mlp.parameters()).dtype
162
+ if timestep_freq.dtype != mlp_dtype:
163
+ timestep_freq = timestep_freq.to(mlp_dtype)
164
+ return self.mlp(timestep_freq)
165
+
166
+
167
+ class ClassEmbedder(nn.Module):
168
+ def __init__(self, num_classes: int, hidden_size: int):
169
+ super().__init__()
170
+ self.embedding_table = nn.Embedding(num_classes, hidden_size)
171
+ self.num_classes = num_classes
172
+
173
+ def forward(self, labels: torch.Tensor) -> torch.Tensor:
174
+ return self.embedding_table(labels)
175
+
176
+
177
+ class FeedForward(nn.Module):
178
+ def __init__(self, dim: int, hidden_dim: int):
179
+ super().__init__()
180
+ hidden_dim = int(2 * hidden_dim / 3)
181
+ self.w1 = nn.Linear(dim, hidden_dim, bias=False)
182
+ self.w3 = nn.Linear(dim, hidden_dim, bias=False)
183
+ self.w2 = nn.Linear(hidden_dim, dim, bias=False)
184
+
185
+ def forward(self, hidden_states: torch.Tensor) -> torch.Tensor:
186
+ return self.w2(F.silu(self.w1(hidden_states)) * self.w3(hidden_states))
187
+
188
+
189
+ class RotaryAttention(nn.Module):
190
+ def __init__(
191
+ self,
192
+ dim: int,
193
+ num_heads: int = 8,
194
+ qkv_bias: bool = False,
195
+ qk_norm: bool = True,
196
+ attn_drop: float = 0.0,
197
+ proj_drop: float = 0.0,
198
+ eps: float = 1e-6,
199
+ ) -> None:
200
+ super().__init__()
201
+ if dim % num_heads != 0:
202
+ raise ValueError("dim should be divisible by num_heads")
203
+
204
+ self.dim = dim
205
+ self.num_heads = num_heads
206
+ self.head_dim = dim // num_heads
207
+
208
+ self.qkv = nn.Linear(dim, dim * 3, bias=qkv_bias)
209
+ self.q_norm = RMSNorm(self.head_dim, eps=eps) if qk_norm else nn.Identity()
210
+ self.k_norm = RMSNorm(self.head_dim, eps=eps) if qk_norm else nn.Identity()
211
+ self.attn_drop = nn.Dropout(attn_drop)
212
+ self.proj = nn.Linear(dim, dim)
213
+ self.proj_drop = nn.Dropout(proj_drop)
214
+
215
+ def forward(self, hidden_states: torch.Tensor, pos: torch.Tensor) -> torch.Tensor:
216
+ batch_size, length, channels = hidden_states.shape
217
+ qkv = (
218
+ self.qkv(hidden_states)
219
+ .reshape(batch_size, length, 3, self.num_heads, channels // self.num_heads)
220
+ .permute(2, 0, 1, 3, 4)
221
+ )
222
+ query, key, value = qkv[0], qkv[1], qkv[2]
223
+ query = self.q_norm(query)
224
+ key = self.k_norm(key)
225
+ query, key = apply_rotary_emb(query, key, freqs_cis=pos)
226
+ query = query.view(batch_size, -1, self.num_heads, channels // self.num_heads).transpose(1, 2)
227
+ key = key.view(batch_size, -1, self.num_heads, channels // self.num_heads).transpose(1, 2).contiguous()
228
+ value = value.view(batch_size, -1, self.num_heads, channels // self.num_heads).transpose(1, 2).contiguous()
229
+ hidden_states = F.scaled_dot_product_attention(query, key, value, dropout_p=0.0)
230
+ hidden_states = hidden_states.transpose(1, 2).reshape(batch_size, length, channels)
231
+ hidden_states = self.proj(hidden_states)
232
+ return self.proj_drop(hidden_states)
233
+
234
+
235
+ class MLP(nn.Module):
236
+ def __init__(self, dim: int, mlp_ratio: float = 4.0, drop: float = 0.0):
237
+ super().__init__()
238
+ hidden_dim = int(dim * mlp_ratio)
239
+ self.fc1 = nn.Linear(dim, hidden_dim)
240
+ self.act = nn.GELU()
241
+ self.fc2 = nn.Linear(hidden_dim, dim)
242
+ self.drop = nn.Dropout(drop)
243
+
244
+ def forward(self, hidden_states: torch.Tensor) -> torch.Tensor:
245
+ hidden_states = self.fc1(hidden_states)
246
+ hidden_states = self.act(hidden_states)
247
+ hidden_states = self.drop(hidden_states)
248
+ hidden_states = self.fc2(hidden_states)
249
+ return self.drop(hidden_states)
250
+
251
+
252
+ class FinalLayer(nn.Module):
253
+ def __init__(self, hidden_size: int, out_channels: int, eps: float = 1e-6):
254
+ super().__init__()
255
+ self.norm = RMSNorm(hidden_size, eps=eps)
256
+ self.linear = nn.Linear(hidden_size, out_channels, bias=True)
257
+
258
+ def forward(self, hidden_states: torch.Tensor) -> torch.Tensor:
259
+ hidden_states = self.norm(hidden_states)
260
+ return self.linear(hidden_states)
261
+
262
+
263
+ class PatchTokenEmbedder(nn.Module):
264
+ def __init__(self, in_chans: int, embed_dim: int, norm_layer=None, bias: bool = True):
265
+ super().__init__()
266
+ self.in_chans = in_chans
267
+ self.embed_dim = embed_dim
268
+ self.proj = nn.Linear(in_chans, embed_dim, bias=bias)
269
+ self.norm = norm_layer(embed_dim) if norm_layer else nn.Identity()
270
+
271
+ def forward(self, hidden_states: torch.Tensor) -> torch.Tensor:
272
+ hidden_states = self.proj(hidden_states)
273
+ return self.norm(hidden_states)
274
+
275
+
276
+ class PixelTokenEmbedder(nn.Module):
277
+ def __init__(self, in_channels: int, hidden_size_output: int, use_pixel_abs_pos: bool = True):
278
+ super().__init__()
279
+ self.in_channels = int(in_channels)
280
+ self.hidden_size_output = int(hidden_size_output)
281
+ self.use_pixel_abs_pos = bool(use_pixel_abs_pos)
282
+ self.proj = nn.Linear(self.in_channels, self.hidden_size_output, bias=True)
283
+ self._pos_cache: Dict[tuple[str, int, int], torch.Tensor] = {}
284
+
285
+ def _fetch_pixel_pos_image(self, height: int, width: int, device: torch.device, dtype: torch.dtype):
286
+ key = ("image", height, width)
287
+ if key in self._pos_cache:
288
+ return self._pos_cache[key].to(device=device, dtype=dtype)
289
+ if height == width:
290
+ pos_np = get_2d_sincos_pos_embed(self.hidden_size_output, height)
291
+ else:
292
+ grid_h = np.arange(height, dtype=np.float32)
293
+ grid_w = np.arange(width, dtype=np.float32)
294
+ grid = np.meshgrid(grid_w, grid_h)
295
+ grid = np.stack(grid, axis=0).reshape(2, 1, height, width)
296
+ pos_np = get_2d_sincos_pos_embed_from_grid(self.hidden_size_output, grid)
297
+ pos = torch.from_numpy(pos_np).to(device=device, dtype=dtype)
298
+ self._pos_cache[key] = pos
299
+ return pos
300
+
301
+ def forward(self, inputs: torch.Tensor, img_height: int, img_width: int, patch_size: int):
302
+ if inputs.dim() != 4:
303
+ raise ValueError("PixelTokenEmbedder expects inputs of shape [B,C,H,W]")
304
+ batch_size, channels, height, width = inputs.shape
305
+ if height != img_height or width != img_width:
306
+ raise ValueError("Input resolution does not match img_height/img_width.")
307
+ if height % patch_size != 0 or width % patch_size != 0:
308
+ raise ValueError("Image height and width must be divisible by patch_size.")
309
+ h_tokens, w_tokens = height // patch_size, width // patch_size
310
+ patch_area = patch_size * patch_size
311
+ hidden_states = inputs.permute(0, 2, 3, 1).contiguous()
312
+ hidden_states = self.proj(hidden_states)
313
+ if self.use_pixel_abs_pos:
314
+ pos_full = self._fetch_pixel_pos_image(height, width, inputs.device, inputs.dtype)
315
+ hidden_states = hidden_states + pos_full.view(height, width, self.hidden_size_output).unsqueeze(0)
316
+ hidden_states = hidden_states.view(batch_size, h_tokens, patch_size, w_tokens, patch_size, self.hidden_size_output)
317
+ hidden_states = hidden_states.permute(0, 1, 3, 2, 4, 5).contiguous()
318
+ return hidden_states.view(batch_size * h_tokens * w_tokens, patch_area, self.hidden_size_output)
319
+
320
+
321
+ class AugmentedDiTBlock(nn.Module):
322
+ def __init__(self, hidden_size: int, groups: int, mlp_ratio: float = 4.0, adaLN_modulation=None, eps: float = 1e-6):
323
+ super().__init__()
324
+ self.norm1 = RMSNorm(hidden_size, eps=eps)
325
+ self.attn = RotaryAttention(hidden_size, num_heads=groups, qkv_bias=False, eps=eps)
326
+ self.norm2 = RMSNorm(hidden_size, eps=eps)
327
+ mlp_hidden_dim = int(hidden_size * mlp_ratio)
328
+ self.mlp = FeedForward(hidden_size, mlp_hidden_dim)
329
+ self.adaLN_modulation = adaLN_modulation if adaLN_modulation is not None else nn.Sequential(
330
+ nn.Linear(hidden_size, 6 * hidden_size, bias=True)
331
+ )
332
+
333
+ def forward(self, hidden_states: torch.Tensor, conditioning: torch.Tensor, pos: torch.Tensor):
334
+ shift_msa, scale_msa, gate_msa, shift_mlp, scale_mlp, gate_mlp = self.adaLN_modulation(conditioning).chunk(
335
+ 6, dim=-1
336
+ )
337
+ hidden_states = hidden_states + gate_msa * self.attn(
338
+ apply_adaln(self.norm1(hidden_states), shift_msa, scale_msa), pos
339
+ )
340
+ hidden_states = hidden_states + gate_mlp * self.mlp(
341
+ apply_adaln(self.norm2(hidden_states), shift_mlp, scale_mlp)
342
+ )
343
+ return hidden_states
344
+
345
+
346
+ class PiTBlock(nn.Module):
347
+ def __init__(
348
+ self,
349
+ pixel_hidden_size: int,
350
+ patch_hidden_size: int,
351
+ patch_size: int,
352
+ num_heads: int,
353
+ mlp_ratio: float = 4.0,
354
+ attn_hidden_size: Optional[int] = None,
355
+ attn_num_heads: Optional[int] = None,
356
+ rope_fn=None,
357
+ eps: float = 1e-6,
358
+ ):
359
+ super().__init__()
360
+ self.pixel_dim = int(pixel_hidden_size)
361
+ self.context_dim = int(patch_hidden_size)
362
+ self.patch_size = int(patch_size)
363
+ self.attn_dim = int(attn_hidden_size) if attn_hidden_size is not None else self.context_dim
364
+ self.num_heads = int(attn_num_heads) if attn_num_heads is not None else int(num_heads)
365
+ if self.attn_dim % self.num_heads != 0:
366
+ raise ValueError("pixel attention hidden size must be divisible by pixel num_heads")
367
+ patch_area = self.patch_size * self.patch_size
368
+ self.compress_to_attn = nn.Linear(patch_area * self.pixel_dim, self.attn_dim, bias=True)
369
+ self.expand_from_attn = nn.Linear(self.attn_dim, patch_area * self.pixel_dim, bias=True)
370
+ self.norm1 = RMSNorm(self.pixel_dim, eps=eps)
371
+ self.attn = RotaryAttention(self.attn_dim, num_heads=self.num_heads, qkv_bias=False, eps=eps)
372
+ self.norm2 = RMSNorm(self.pixel_dim, eps=eps)
373
+ self.mlp = MLP(self.pixel_dim, mlp_ratio=mlp_ratio, drop=0.0)
374
+ self.adaLN_modulation = nn.Sequential(nn.Linear(self.context_dim, 6 * self.pixel_dim * patch_area, bias=True))
375
+ self._pos_cache: Dict[tuple[int, int], torch.Tensor] = {}
376
+ self._rope_fn = rope_fn if rope_fn is not None else precompute_freqs_cis_2d
377
+
378
+ def _fetch_pos(self, height: int, width: int, device: torch.device):
379
+ key = (height, width)
380
+ if key in self._pos_cache:
381
+ return self._pos_cache[key].to(device)
382
+ pos = self._rope_fn(self.attn_dim // self.num_heads, height, width).to(device)
383
+ self._pos_cache[key] = pos
384
+ return pos
385
+
386
+ def forward(
387
+ self,
388
+ hidden_states: torch.Tensor,
389
+ conditioning: torch.Tensor,
390
+ image_height: int,
391
+ image_width: int,
392
+ patch_size: int,
393
+ ) -> torch.Tensor:
394
+ batch_tokens, patch_area, channels = hidden_states.shape
395
+ if channels != self.pixel_dim:
396
+ raise ValueError(f"PiTBlock expected pixel_dim={self.pixel_dim}, got {channels}")
397
+ if image_height % patch_size != 0 or image_width % patch_size != 0:
398
+ raise ValueError("Image height and width must be divisible by patch_size.")
399
+ h_tokens, w_tokens = image_height // patch_size, image_width // patch_size
400
+ length = h_tokens * w_tokens
401
+ batch_size = batch_tokens // length
402
+ cond_params = self.adaLN_modulation(conditioning).view(batch_tokens, patch_area, 6 * self.pixel_dim)
403
+ shift_msa, scale_msa, gate_msa, shift_mlp, scale_mlp, gate_mlp = torch.chunk(cond_params, 6, dim=-1)
404
+ hidden_norm = apply_adaln(self.norm1(hidden_states), shift_msa, scale_msa)
405
+ hidden_flat = hidden_norm.view(batch_tokens, patch_area * self.pixel_dim)
406
+ hidden_comp = self.compress_to_attn(hidden_flat).view(batch_size, length, self.attn_dim)
407
+ pos_comp = self._fetch_pos(h_tokens, w_tokens, hidden_states.device)
408
+ attn_out = self.attn(hidden_comp, pos_comp)
409
+ attn_flat = self.expand_from_attn(attn_out.view(batch_size * length, self.attn_dim))
410
+ attn_exp = attn_flat.view(batch_tokens, patch_area, self.pixel_dim)
411
+ hidden_states = hidden_states + gate_msa * attn_exp
412
+ mlp_out = self.mlp(apply_adaln(self.norm2(hidden_states), shift_mlp, scale_mlp))
413
+ hidden_states = hidden_states + gate_mlp * mlp_out
414
+ return hidden_states
415
+
416
+
417
+ class PixelDiTTransformer2DModel(ModelMixin, ConfigMixin):
418
+ _supports_gradient_checkpointing = True
419
+ _skip_layerwise_casting_patterns = ["pos", "_pos_cache"]
420
+
421
+ @register_to_config
422
+ def __init__(
423
+ self,
424
+ sample_size: int = 256,
425
+ in_channels: int = 3,
426
+ num_groups: int = 16,
427
+ hidden_size: int = 1152,
428
+ pixel_hidden_size: int = 16,
429
+ patch_depth: int = 26,
430
+ pixel_depth: int = 4,
431
+ patch_size: int = 16,
432
+ num_classes: int = 1000,
433
+ use_pixel_abs_pos: bool = True,
434
+ norm_eps: float = 1e-6,
435
+ model_type: str | None = None,
436
+ num_class_embeds: int | None = None,
437
+ ):
438
+ super().__init__()
439
+ if num_class_embeds is not None:
440
+ num_classes = int(num_class_embeds)
441
+ if model_type in PIXELDIT_PRESET_CONFIGS:
442
+ preset = PIXELDIT_PRESET_CONFIGS[model_type]
443
+ sample_size = int(preset["sample_size"])
444
+ num_groups = int(preset["num_groups"])
445
+ hidden_size = int(preset["hidden_size"])
446
+ pixel_hidden_size = int(preset["pixel_hidden_size"])
447
+ patch_depth = int(preset["patch_depth"])
448
+ pixel_depth = int(preset["pixel_depth"])
449
+ patch_size = int(preset["patch_size"])
450
+
451
+ self.sample_size = int(sample_size)
452
+ self.in_channels = int(in_channels)
453
+ self.out_channels = int(in_channels)
454
+ self.hidden_size = int(hidden_size)
455
+ self.num_groups = int(num_groups)
456
+ self.patch_depth = int(patch_depth)
457
+ self.pixel_depth = int(pixel_depth)
458
+ self.patch_size = int(patch_size)
459
+ self.pixel_hidden_size = int(pixel_hidden_size)
460
+ self.num_classes = int(num_classes)
461
+ self.use_pixel_abs_pos = bool(use_pixel_abs_pos)
462
+ self.norm_eps = float(norm_eps)
463
+ self.gradient_checkpointing = False
464
+
465
+ if self.pixel_depth <= 0:
466
+ raise ValueError("PixelDiT expects pixel_depth > 0 to preserve the dual-level pipeline")
467
+
468
+ self.pixel_embedder = PixelTokenEmbedder(
469
+ self.in_channels, self.pixel_hidden_size, use_pixel_abs_pos=self.use_pixel_abs_pos
470
+ )
471
+ self.s_embedder = PatchTokenEmbedder(self.in_channels * self.patch_size**2, self.hidden_size, bias=True)
472
+ self.t_embedder = TimestepConditioner(self.hidden_size)
473
+ self.y_embedder = ClassEmbedder(self.num_classes + 1, self.hidden_size)
474
+
475
+ self.final_layer = FinalLayer(self.pixel_hidden_size, self.out_channels, eps=self.norm_eps)
476
+ self.patch_blocks = nn.ModuleList(
477
+ [AugmentedDiTBlock(self.hidden_size, self.num_groups, eps=self.norm_eps) for _ in range(self.patch_depth)]
478
+ )
479
+ self.pixel_blocks = nn.ModuleList(
480
+ [
481
+ PiTBlock(
482
+ self.pixel_hidden_size,
483
+ self.hidden_size,
484
+ patch_size=self.patch_size,
485
+ num_heads=self.num_groups,
486
+ mlp_ratio=4.0,
487
+ eps=self.norm_eps,
488
+ )
489
+ for _ in range(self.pixel_depth)
490
+ ]
491
+ )
492
+ self._precompute_pos: Dict[tuple[int, int], torch.Tensor] = {}
493
+ self._initialize_weights()
494
+
495
+ def _fetch_pos(self, height: int, width: int, device: torch.device):
496
+ key = (height, width)
497
+ if key in self._precompute_pos:
498
+ return self._precompute_pos[key].to(device)
499
+ pos = precompute_freqs_cis_2d(self.hidden_size // self.num_groups, height, width).to(device)
500
+ self._precompute_pos[key] = pos
501
+ return pos
502
+
503
+ def _initialize_weights(self) -> None:
504
+ weight = self.s_embedder.proj.weight.data
505
+ nn.init.xavier_uniform_(weight.view([weight.shape[0], -1]))
506
+ nn.init.constant_(self.s_embedder.proj.bias, 0)
507
+ nn.init.normal_(self.y_embedder.embedding_table.weight, std=0.02)
508
+ nn.init.normal_(self.t_embedder.mlp[0].weight, std=0.02)
509
+ nn.init.normal_(self.t_embedder.mlp[2].weight, std=0.02)
510
+ nn.init.zeros_(self.final_layer.linear.weight)
511
+ nn.init.zeros_(self.final_layer.linear.bias)
512
+ for block in self.patch_blocks:
513
+ nn.init.zeros_(block.adaLN_modulation[0].weight)
514
+ nn.init.zeros_(block.adaLN_modulation[0].bias)
515
+ for block in self.pixel_blocks:
516
+ nn.init.zeros_(block.adaLN_modulation[0].weight)
517
+ nn.init.zeros_(block.adaLN_modulation[0].bias)
518
+
519
+ def forward(
520
+ self,
521
+ sample: torch.Tensor,
522
+ timestep: Union[torch.Tensor, float],
523
+ class_labels: Union[torch.Tensor, int],
524
+ return_dict: bool = True,
525
+ ) -> Union[Transformer2DModelOutput, Tuple[torch.Tensor]]:
526
+ if sample.dim() != 4:
527
+ raise ValueError("PixelDiTTransformer2DModel expects sample of shape [B,C,H,W]")
528
+ batch_size, _, height, width = sample.shape
529
+ if height % self.patch_size != 0 or width % self.patch_size != 0:
530
+ raise ValueError("Image height and width must be divisible by patch_size.")
531
+
532
+ timestep = torch.as_tensor(timestep, device=sample.device)
533
+ if timestep.ndim == 0:
534
+ timestep = timestep.repeat(batch_size)
535
+ else:
536
+ timestep = timestep.reshape(-1)
537
+ if timestep.shape[0] == 1 and batch_size > 1:
538
+ timestep = timestep.repeat(batch_size)
539
+
540
+ if not torch.is_tensor(class_labels):
541
+ class_labels = torch.tensor(class_labels, device=sample.device, dtype=torch.long)
542
+ class_labels = class_labels.to(device=sample.device, dtype=torch.long).reshape(-1)
543
+ if class_labels.shape[0] == 1 and batch_size > 1:
544
+ class_labels = class_labels.repeat(batch_size)
545
+
546
+ pos = self._fetch_pos(height // self.patch_size, width // self.patch_size, sample.device)
547
+ x_patches = F.unfold(sample, kernel_size=self.patch_size, stride=self.patch_size).transpose(1, 2)
548
+ t_emb = self.t_embedder(timestep.view(-1)).view(batch_size, -1, self.hidden_size)
549
+ y_emb = self.y_embedder(class_labels).view(batch_size, 1, self.hidden_size)
550
+ conditioning = F.silu(t_emb + y_emb)
551
+
552
+ patch_states = self.s_embedder(x_patches)
553
+ for block in self.patch_blocks:
554
+ if self.training and self.gradient_checkpointing:
555
+
556
+ def custom_forward(hidden_states, cond, position):
557
+ return block(hidden_states, cond, position)
558
+
559
+ patch_states = torch.utils.checkpoint.checkpoint(
560
+ custom_forward, patch_states, conditioning, pos, use_reentrant=False
561
+ )
562
+ else:
563
+ patch_states = block(patch_states, conditioning, pos)
564
+ patch_states = F.silu(t_emb + patch_states)
565
+
566
+ length = patch_states.shape[1]
567
+ conditioning_states = patch_states.view(batch_size * length, self.hidden_size)
568
+ pixel_states = self.pixel_embedder(
569
+ sample, img_height=height, img_width=width, patch_size=self.patch_size
570
+ )
571
+ for block in self.pixel_blocks:
572
+ if self.training and self.gradient_checkpointing:
573
+
574
+ def custom_forward(hidden_states, cond):
575
+ return block(hidden_states, cond, height, width, self.patch_size)
576
+
577
+ pixel_states = torch.utils.checkpoint.checkpoint(
578
+ custom_forward, pixel_states, conditioning_states, use_reentrant=False
579
+ )
580
+ else:
581
+ pixel_states = block(pixel_states, conditioning_states, height, width, self.patch_size)
582
+ pixel_states = self.final_layer(pixel_states)
583
+
584
+ patch_area = self.patch_size * self.patch_size
585
+ pixel_states = pixel_states.view(batch_size, length, patch_area, self.out_channels).permute(0, 3, 2, 1)
586
+ pixel_states = pixel_states.contiguous().view(batch_size, self.out_channels * patch_area, length)
587
+ output = F.fold(pixel_states, (height, width), kernel_size=self.patch_size, stride=self.patch_size)
588
+
589
+ if not return_dict:
590
+ return (output,)
591
+ return Transformer2DModelOutput(sample=output)
592
+
593
+ @classmethod
594
+ def from_pixeldit_checkpoint(
595
+ cls,
596
+ checkpoint_path: str,
597
+ model_type: Literal["pixeldit-xl"] = "pixeldit-xl",
598
+ map_location: str = "cpu",
599
+ strict: bool = True,
600
+ ) -> Tuple["PixelDiTTransformer2DModel", Dict[str, object]]:
601
+ if model_type not in PIXELDIT_PRESET_CONFIGS:
602
+ raise ValueError(f"Unknown PixelDiT preset '{model_type}'.")
603
+
604
+ if checkpoint_path.endswith(".safetensors"):
605
+ try:
606
+ from safetensors.torch import load_file
607
+ except ImportError as error:
608
+ raise ImportError("Install safetensors to load .safetensors checkpoints.") from error
609
+ state_dict = load_file(checkpoint_path, device=map_location)
610
+ else:
611
+ loaded = torch.load(checkpoint_path, map_location=map_location, weights_only=False)
612
+ if isinstance(loaded, Mapping):
613
+ state_dict = loaded
614
+ for key in ("state_dict", "model", "module", "denoiser"):
615
+ if key in state_dict and isinstance(state_dict[key], dict):
616
+ state_dict = state_dict[key]
617
+ break
618
+ else:
619
+ raise ValueError("Unsupported checkpoint format.")
620
+
621
+ config = dict(PIXELDIT_PRESET_CONFIGS[model_type])
622
+ config["model_type"] = model_type
623
+ model = cls(**config)
624
+ model.load_state_dict(remap_legacy_state_dict(state_dict), strict=strict)
625
+
626
+ metadata = {
627
+ "checkpoint_path": checkpoint_path,
628
+ "model_type": model_type,
629
+ }
630
+ return model, metadata
631
+
632
+ def to_pixeldit_checkpoint(self, prefix: str = "") -> Dict[str, torch.Tensor]:
633
+ checkpoint: Dict[str, torch.Tensor] = {}
634
+ for key, value in self.state_dict().items():
635
+ checkpoint[f"{prefix}{key}"] = value.detach().cpu()
636
+ return checkpoint
637
+
638
+
639
+ PixelDiTDiffusersModel = PixelDiTTransformer2DModel
README.md ADDED
@@ -0,0 +1,241 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: other
3
+ license_name: nsclv1
4
+ license_link: https://huggingface.co/nvidia/PixelDiT-ImageNet/blob/main/LICENSE
5
+ library_name: diffusers
6
+ pipeline_tag: text-to-image
7
+ tags:
8
+ - diffusers
9
+ - image-generation
10
+ - class-conditional
11
+ - text-to-image
12
+ - imagenet
13
+ - pixeldit
14
+ - flow-matching
15
+ - pixel-space
16
+ - dit
17
+ widget:
18
+ - text: A golden retriever playing in a sunny garden
19
+ output:
20
+ url: PixelDiT-T2I-1024/demo.png
21
+ - text: golden retriever
22
+ output:
23
+ url: PixelDiT-XL-16-256/demo.png
24
+ language:
25
+ - en
26
+ ---
27
+
28
+ # BiliSakura/PixelDiT-diffusers
29
+
30
+ Self-contained PixelDiT checkpoints for Hugging Face diffusers. Each variant folder ships its own `pipeline.py`, component modules, and weights.
31
+
32
+ Converted from [nvidia/PixelDiT-ImageNet](https://huggingface.co/nvidia/PixelDiT-ImageNet) and [nvidia/PixelDiT-1300M-1024px](https://huggingface.co/nvidia/PixelDiT-1300M-1024px) using [PixelDiT-diffusers](https://github.com/BiliSakura/Visual-Generative-Foundation-Model-Collection/tree/main/libs/PixelDiT-diffusers).
33
+
34
+ ## Available checkpoints
35
+
36
+ | Subfolder | Pipeline | Task | Resolution | Source checkpoint | gFID | Params |
37
+ | --- | --- | --- | ---: | --- | ---: | ---: |
38
+ | [`PixelDiT-T2I-1024/`](PixelDiT-T2I-1024/) | `PixelDiTT2IPipeline` | text-to-image | 1024×1024 | `pixeldit_t2i_v1.pth` | — | ~1.3B |
39
+ | [`PixelDiT-XL-16-256/`](PixelDiT-XL-16-256/) | `PixelDiTPipeline` | class-to-image | 256×256 | `imagenet256_pixeldit_xl_epoch320.ckpt` | 1.61 | ~700M |
40
+ | [`PixelDiT-XL-16-512/`](PixelDiT-XL-16-512/) | `PixelDiTPipeline` | class-to-image | 512×512 | `imagenet512_pixeldit_xl.ckpt` | 1.81 | ~700M |
41
+
42
+ ## Repo layout
43
+
44
+ ```text
45
+ BiliSakura/PixelDiT-diffusers/
46
+ ├── README.md
47
+ ├── demo_inference.py
48
+ ├── PixelDiT-T2I-1024/
49
+ │ ├── pipeline.py
50
+ │ ├── model_index.json
51
+ │ ├── demo.png
52
+ │ ├── scheduler/scheduler_config.json
53
+ │ └── transformer/
54
+ ├── PixelDiT-XL-16-256/
55
+ │ ├── pipeline.py
56
+ │ ├── model_index.json
57
+ │ ├── demo.png
58
+ │ ├── scheduler/scheduler_config.json
59
+ │ └── transformer/
60
+ └── PixelDiT-XL-16-512/
61
+ ├── pipeline.py
62
+ ├── model_index.json
63
+ ├── scheduler/scheduler_config.json
64
+ └── transformer/
65
+ ```
66
+
67
+ Each variant is self-contained. The `scheduler/` folder uses built-in `FlowMatchEulerDiscreteScheduler` from PyPI diffusers. No shared helper modules at inference time beyond the local variant directory.
68
+
69
+ ## ImageNet class labels
70
+
71
+ `id2label` is embedded in each variant's `model_index.json` (DiT-style).
72
+
73
+ - `pipe.id2label` — inspect id → English label correspondence
74
+ - `pipe.labels` — reverse map (English synonym → id)
75
+ - `pipe.get_label_ids("golden retriever")`
76
+ - `pipe(class_labels="golden retriever", ...)` — string labels resolved automatically
77
+
78
+ ## Demo
79
+
80
+ ![PixelDiT-T2I-1024 demo](PixelDiT-T2I-1024/demo.png)
81
+
82
+ Text-to-image — "A golden retriever playing in a sunny garden", 1024×1024, 50 steps, `guidance_scale=2.75`.
83
+
84
+ ```bash
85
+ python demo_inference_t2i.py
86
+ ```
87
+
88
+ ![PixelDiT-XL-16-256 demo](PixelDiT-XL-16-256/demo.png)
89
+
90
+ Class 207 — golden retriever, 256×256, 100 steps, `guidance_scale=2.75`, CFG interval `[0.1, 0.9]`.
91
+
92
+ ```bash
93
+ python demo_inference.py
94
+ ```
95
+
96
+ ## Load from a local clone
97
+
98
+ ### Text-to-image 1024×1024 (`PixelDiT-T2I-1024`)
99
+
100
+ ```python
101
+ from pathlib import Path
102
+ import torch
103
+ from diffusers import DiffusionPipeline
104
+
105
+ model_dir = Path("./PixelDiT-T2I-1024").resolve()
106
+ pipe = DiffusionPipeline.from_pretrained(
107
+ str(model_dir),
108
+ local_files_only=True,
109
+ custom_pipeline=str(model_dir / "pipeline.py"),
110
+ trust_remote_code=True,
111
+ torch_dtype=torch.bfloat16,
112
+ )
113
+ pipe.to("cuda")
114
+
115
+ generator = torch.Generator(device="cuda").manual_seed(42)
116
+ image = pipe(
117
+ prompt="A golden retriever playing in a sunny garden",
118
+ negative_prompt="low quality, worst quality, over-saturated, blurry, deformed, watermark",
119
+ height=1024,
120
+ width=1024,
121
+ num_inference_steps=50,
122
+ guidance_scale=2.75,
123
+ generator=generator,
124
+ ).images[0]
125
+ image.save("demo.png")
126
+ ```
127
+
128
+ Gemma text encoder (`google/gemma-2-2b-it`) is downloaded on first run unless bundled under `text_encoder/`.
129
+
130
+ ### ImageNet 256×256 (`PixelDiT-XL-16-256`)
131
+
132
+ ```python
133
+ from pathlib import Path
134
+ import torch
135
+ from diffusers import DiffusionPipeline
136
+
137
+ model_dir = Path("./PixelDiT-XL-16-256").resolve()
138
+ pipe = DiffusionPipeline.from_pretrained(
139
+ str(model_dir),
140
+ local_files_only=True,
141
+ custom_pipeline=str(model_dir / "pipeline.py"),
142
+ trust_remote_code=True,
143
+ torch_dtype=torch.bfloat16,
144
+ )
145
+ pipe.to("cuda")
146
+
147
+ print(pipe.id2label[207])
148
+ print(pipe.get_label_ids("golden retriever"))
149
+
150
+ generator = torch.Generator(device="cuda").manual_seed(42)
151
+ image = pipe(
152
+ class_labels="golden retriever",
153
+ height=256,
154
+ width=256,
155
+ num_inference_steps=100,
156
+ guidance_scale=2.75,
157
+ guidance_interval_min=0.1,
158
+ guidance_interval_max=0.9,
159
+ generator=generator,
160
+ ).images[0]
161
+ image.save("demo.png")
162
+ ```
163
+
164
+ ### ImageNet 512×512 (`PixelDiT-XL-16-512`)
165
+
166
+ ```python
167
+ from pathlib import Path
168
+ import torch
169
+ from diffusers import DiffusionPipeline
170
+
171
+ model_dir = Path("./PixelDiT-XL-16-512").resolve()
172
+ pipe = DiffusionPipeline.from_pretrained(
173
+ str(model_dir),
174
+ local_files_only=True,
175
+ custom_pipeline=str(model_dir / "pipeline.py"),
176
+ trust_remote_code=True,
177
+ torch_dtype=torch.bfloat16,
178
+ )
179
+ pipe.to("cuda")
180
+
181
+ generator = torch.Generator(device="cuda").manual_seed(42)
182
+ image = pipe(
183
+ class_labels=207,
184
+ height=512,
185
+ width=512,
186
+ num_inference_steps=100,
187
+ guidance_scale=3.5,
188
+ guidance_interval_min=0.1,
189
+ guidance_interval_max=1.0,
190
+ generator=generator,
191
+ ).images[0]
192
+ image.save("demo.png")
193
+ ```
194
+
195
+ ## Recommended inference settings
196
+
197
+ | Variant | Steps | CFG scale | Scheduler shift | CFG interval |
198
+ | --- | ---: | ---: | ---: | --- |
199
+ | `PixelDiT-T2I-1024` | 50 | 2.75 | 4.0 | [0.0, 1.0] |
200
+ | `PixelDiT-XL-16-256` | 100 | 2.75 | 1.0 | [0.1, 0.9] |
201
+ | `PixelDiT-XL-16-512` | 100 | 3.5 | 2.0 | [0.1, 1.0] |
202
+
203
+ PixelDiT denoises directly in pixel space (no VAE). `height` and `width` must be divisible by the patch size (16).
204
+
205
+ ## Conversion
206
+
207
+ ```bash
208
+ cd libs/PixelDiT-diffusers
209
+
210
+ python scripts/convert_pixeldit_t2i_to_diffusers.py \
211
+ --checkpoint /path/to/pixeldit_t2i_v1.pth \
212
+ --config /path/to/config.json \
213
+ --output /path/to/PixelDiT-T2I-1024 \
214
+ --sample-size 1024 \
215
+ --scheduler-shift 4.0 \
216
+ --check-load
217
+
218
+ python scripts/convert_pixeldit_to_diffusers.py \
219
+ --checkpoint /path/to/imagenet256_pixeldit_xl_epoch320.ckpt \
220
+ --output /path/to/PixelDiT-XL-16-256 \
221
+ --model-size pixeldit-xl \
222
+ --sample-size 256 \
223
+ --scheduler-shift 1.0 \
224
+ --check-load \
225
+ --id2label /path/to/id2label_en.json
226
+ ```
227
+
228
+ ## Citation
229
+
230
+ ```bibtex
231
+ @inproceedings{yu2025pixeldit,
232
+ title={PixelDiT: Pixel Diffusion Transformers for Image Generation},
233
+ author={Yongsheng Yu and Wei Xiong and Weili Nie and Yichen Sheng and Shiqiu Liu and Jiebo Luo},
234
+ booktitle={Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition (CVPR)},
235
+ year={2026},
236
+ }
237
+ ```
238
+
239
+ ## License
240
+
241
+ Weights are converted from NVIDIA checkpoints released under the [NSCLv1 License](https://huggingface.co/nvidia/PixelDiT-ImageNet/blob/main/LICENSE). Use for non-commercial research and evaluation only.
demo_inference.py ADDED
@@ -0,0 +1,95 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python3
2
+ """Generate demo images for PixelDiT class-conditional checkpoints."""
3
+
4
+ from __future__ import annotations
5
+
6
+ import argparse
7
+ from pathlib import Path
8
+
9
+ import torch
10
+ from diffusers import DiffusionPipeline
11
+
12
+ REPO_ROOT = Path(__file__).resolve().parent
13
+
14
+ VARIANTS = {
15
+ "256": {
16
+ "dir": REPO_ROOT / "PixelDiT-XL-16-256",
17
+ "height": 256,
18
+ "width": 256,
19
+ "num_inference_steps": 100,
20
+ "guidance_scale": 3.25,
21
+ "class_label": "golden retriever",
22
+ "seed": 7,
23
+ },
24
+ "512": {
25
+ "dir": REPO_ROOT / "PixelDiT-XL-16-512",
26
+ "height": 512,
27
+ "width": 512,
28
+ "num_inference_steps": 100,
29
+ "guidance_scale": 3.75,
30
+ "class_label": "golden retriever",
31
+ "seed": 7,
32
+ },
33
+ }
34
+
35
+
36
+ def parse_args() -> argparse.Namespace:
37
+ parser = argparse.ArgumentParser(description="Run PixelDiT demo inference.")
38
+ parser.add_argument(
39
+ "--variant",
40
+ choices=sorted(VARIANTS),
41
+ default="256",
42
+ help="Checkpoint resolution variant to sample.",
43
+ )
44
+ parser.add_argument(
45
+ "--all",
46
+ action="store_true",
47
+ help="Generate demo.png for every supported variant.",
48
+ )
49
+ return parser.parse_args()
50
+
51
+
52
+ def run_variant(name: str) -> Path:
53
+ settings = VARIANTS[name]
54
+ model_dir = settings["dir"]
55
+ output_path = model_dir / "demo.png"
56
+
57
+ pipe = DiffusionPipeline.from_pretrained(
58
+ str(model_dir),
59
+ local_files_only=True,
60
+ custom_pipeline=str(model_dir / "pipeline.py"),
61
+ trust_remote_code=True,
62
+ torch_dtype=torch.bfloat16,
63
+ )
64
+ pipe.to("cuda")
65
+
66
+ print(f"[{name}] {settings['class_label']} -> {pipe.get_label_ids(settings['class_label'])}")
67
+ print(f"[{name}] scheduler shift={pipe.scheduler.config.shift}")
68
+
69
+ generator = torch.Generator(device="cuda").manual_seed(settings["seed"])
70
+ image = pipe(
71
+ class_labels=settings["class_label"],
72
+ height=settings["height"],
73
+ width=settings["width"],
74
+ num_inference_steps=settings["num_inference_steps"],
75
+ guidance_scale=settings["guidance_scale"],
76
+ guidance_interval_min=0.1,
77
+ guidance_interval_max=1.0,
78
+ generator=generator,
79
+ ).images[0]
80
+ image.save(output_path)
81
+ print(f"[{name}] Saved demo image to {output_path}")
82
+ return output_path
83
+
84
+
85
+ def main() -> None:
86
+ args = parse_args()
87
+ if args.all:
88
+ for name in VARIANTS:
89
+ run_variant(name)
90
+ return
91
+ run_variant(args.variant)
92
+
93
+
94
+ if __name__ == "__main__":
95
+ main()
demo_inference_t2i.py ADDED
@@ -0,0 +1,73 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python3
2
+ """Generate a demo image with PixelDiT-T2I-1024."""
3
+
4
+ from __future__ import annotations
5
+
6
+ import importlib.util
7
+ import sys
8
+ from pathlib import Path
9
+
10
+ REPO_ROOT = Path(__file__).resolve().parent
11
+ MODEL_DIR = REPO_ROOT / "PixelDiT-T2I-1024"
12
+ OUTPUT_PATH = MODEL_DIR / "demo.png"
13
+
14
+ DIFFUSERS_SRC = None
15
+ for parent in Path(__file__).resolve().parents:
16
+ candidate = parent / "libs/diffusers/src"
17
+ if (candidate / "diffusers/schedulers/flow_dpm.py").is_file():
18
+ DIFFUSERS_SRC = candidate
19
+ break
20
+ if DIFFUSERS_SRC is None:
21
+ fallback = Path("/data/projects/Visual-Generative-Foundation-Model-Collection/libs/diffusers/src")
22
+ if (fallback / "diffusers/schedulers/flow_dpm.py").is_file():
23
+ DIFFUSERS_SRC = fallback
24
+ if DIFFUSERS_SRC is None:
25
+ raise ImportError("Could not locate libs/diffusers/src for PixelDiT flow DPM sampling.")
26
+ if str(DIFFUSERS_SRC) not in sys.path:
27
+ sys.path.insert(0, str(DIFFUSERS_SRC))
28
+ import os
29
+
30
+ os.environ.setdefault("PIXELDIT_DIFFUSERS_SRC", str(DIFFUSERS_SRC))
31
+
32
+ import torch
33
+
34
+
35
+ def _load_pipeline_class():
36
+ spec = importlib.util.spec_from_file_location("pixeldit_t2i_pipeline", MODEL_DIR / "pipeline.py")
37
+ if spec is None or spec.loader is None:
38
+ raise ImportError(f"Unable to load pipeline from {MODEL_DIR / 'pipeline.py'}")
39
+ module = importlib.util.module_from_spec(spec)
40
+ spec.loader.exec_module(module)
41
+ return module.PixelDiTT2IPipeline
42
+
43
+
44
+ def main() -> None:
45
+ pipe_cls = _load_pipeline_class()
46
+ pipe = pipe_cls.from_pretrained(
47
+ str(MODEL_DIR),
48
+ local_files_only=True,
49
+ torch_dtype=torch.bfloat16,
50
+ )
51
+ pipe.to("cuda")
52
+
53
+ prompt = "A golden retriever playing in a sunny garden"
54
+ print("text_encoder:", type(pipe.text_encoder).__name__)
55
+ print("prompt:", prompt)
56
+
57
+ generator = torch.Generator(device="cuda").manual_seed(42)
58
+ image = pipe(
59
+ prompt=prompt,
60
+ negative_prompt="low quality, worst quality, over-saturated, blurry, deformed, watermark",
61
+ height=1024,
62
+ width=1024,
63
+ num_inference_steps=50,
64
+ guidance_scale=2.75,
65
+ use_chi_prompt=True,
66
+ generator=generator,
67
+ ).images[0]
68
+ image.save(OUTPUT_PATH)
69
+ print(f"Saved demo image to {OUTPUT_PATH}")
70
+
71
+
72
+ if __name__ == "__main__":
73
+ main()