BiliSakura commited on
Commit
6786303
·
verified ·
1 Parent(s): cec62b3

Upload folder using huggingface_hub

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

Git LFS Details

  • SHA256: 03188030ad81ad8a3d5b9ace40731a4c3f8bd540e355e465cf80fe2f13bdc17a
  • Pointer size: 131 Bytes
  • Size of remote file: 155 kB
JiT-H-16-SIM/model_index.json ADDED
@@ -0,0 +1,1017 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "_class_name": [
3
+ "pipeline",
4
+ "JiTPipeline"
5
+ ],
6
+ "_diffusers_version": "0.36.0",
7
+ "scheduler": [
8
+ "scheduling_flow_match_fd",
9
+ "FDLossFlowMatchScheduler"
10
+ ],
11
+ "transformer": [
12
+ "jit_transformer_2d",
13
+ "JiTTransformer2DModel"
14
+ ],
15
+ "id2label": {
16
+ "0": "tench, Tinca tinca",
17
+ "1": "goldfish, Carassius auratus",
18
+ "2": "great white shark, white shark, man-eater, man-eating shark, Carcharodon carcharias",
19
+ "3": "tiger shark, Galeocerdo cuvieri",
20
+ "4": "hammerhead, hammerhead shark",
21
+ "5": "electric ray, crampfish, numbfish, torpedo",
22
+ "6": "stingray",
23
+ "7": "cock",
24
+ "8": "hen",
25
+ "9": "ostrich, Struthio camelus",
26
+ "10": "brambling, Fringilla montifringilla",
27
+ "11": "goldfinch, Carduelis carduelis",
28
+ "12": "house finch, linnet, Carpodacus mexicanus",
29
+ "13": "junco, snowbird",
30
+ "14": "indigo bunting, indigo finch, indigo bird, Passerina cyanea",
31
+ "15": "robin, American robin, Turdus migratorius",
32
+ "16": "bulbul",
33
+ "17": "jay",
34
+ "18": "magpie",
35
+ "19": "chickadee",
36
+ "20": "water ouzel, dipper",
37
+ "21": "kite",
38
+ "22": "bald eagle, American eagle, Haliaeetus leucocephalus",
39
+ "23": "vulture",
40
+ "24": "great grey owl, great gray owl, Strix nebulosa",
41
+ "25": "European fire salamander, Salamandra salamandra",
42
+ "26": "common newt, Triturus vulgaris",
43
+ "27": "eft",
44
+ "28": "spotted salamander, Ambystoma maculatum",
45
+ "29": "axolotl, mud puppy, Ambystoma mexicanum",
46
+ "30": "bullfrog, Rana catesbeiana",
47
+ "31": "tree frog, tree-frog",
48
+ "32": "tailed frog, bell toad, ribbed toad, tailed toad, Ascaphus trui",
49
+ "33": "loggerhead, loggerhead turtle, Caretta caretta",
50
+ "34": "leatherback turtle, leatherback, leathery turtle, Dermochelys coriacea",
51
+ "35": "mud turtle",
52
+ "36": "terrapin",
53
+ "37": "box turtle, box tortoise",
54
+ "38": "banded gecko",
55
+ "39": "common iguana, iguana, Iguana iguana",
56
+ "40": "American chameleon, anole, Anolis carolinensis",
57
+ "41": "whiptail, whiptail lizard",
58
+ "42": "agama",
59
+ "43": "frilled lizard, Chlamydosaurus kingi",
60
+ "44": "alligator lizard",
61
+ "45": "Gila monster, Heloderma suspectum",
62
+ "46": "green lizard, Lacerta viridis",
63
+ "47": "African chameleon, Chamaeleo chamaeleon",
64
+ "48": "Komodo dragon, Komodo lizard, dragon lizard, giant lizard, Varanus komodoensis",
65
+ "49": "African crocodile, Nile crocodile, Crocodylus niloticus",
66
+ "50": "American alligator, Alligator mississipiensis",
67
+ "51": "triceratops",
68
+ "52": "thunder snake, worm snake, Carphophis amoenus",
69
+ "53": "ringneck snake, ring-necked snake, ring snake",
70
+ "54": "hognose snake, puff adder, sand viper",
71
+ "55": "green snake, grass snake",
72
+ "56": "king snake, kingsnake",
73
+ "57": "garter snake, grass snake",
74
+ "58": "water snake",
75
+ "59": "vine snake",
76
+ "60": "night snake, Hypsiglena torquata",
77
+ "61": "boa constrictor, Constrictor constrictor",
78
+ "62": "rock python, rock snake, Python sebae",
79
+ "63": "Indian cobra, Naja naja",
80
+ "64": "green mamba",
81
+ "65": "sea snake",
82
+ "66": "horned viper, cerastes, sand viper, horned asp, Cerastes cornutus",
83
+ "67": "diamondback, diamondback rattlesnake, Crotalus adamanteus",
84
+ "68": "sidewinder, horned rattlesnake, Crotalus cerastes",
85
+ "69": "trilobite",
86
+ "70": "harvestman, daddy longlegs, Phalangium opilio",
87
+ "71": "scorpion",
88
+ "72": "black and gold garden spider, Argiope aurantia",
89
+ "73": "barn spider, Araneus cavaticus",
90
+ "74": "garden spider, Aranea diademata",
91
+ "75": "black widow, Latrodectus mactans",
92
+ "76": "tarantula",
93
+ "77": "wolf spider, hunting spider",
94
+ "78": "tick",
95
+ "79": "centipede",
96
+ "80": "black grouse",
97
+ "81": "ptarmigan",
98
+ "82": "ruffed grouse, partridge, Bonasa umbellus",
99
+ "83": "prairie chicken, prairie grouse, prairie fowl",
100
+ "84": "peacock",
101
+ "85": "quail",
102
+ "86": "partridge",
103
+ "87": "African grey, African gray, Psittacus erithacus",
104
+ "88": "macaw",
105
+ "89": "sulphur-crested cockatoo, Kakatoe galerita, Cacatua galerita",
106
+ "90": "lorikeet",
107
+ "91": "coucal",
108
+ "92": "bee eater",
109
+ "93": "hornbill",
110
+ "94": "hummingbird",
111
+ "95": "jacamar",
112
+ "96": "toucan",
113
+ "97": "drake",
114
+ "98": "red-breasted merganser, Mergus serrator",
115
+ "99": "goose",
116
+ "100": "black swan, Cygnus atratus",
117
+ "101": "tusker",
118
+ "102": "echidna, spiny anteater, anteater",
119
+ "103": "platypus, duckbill, duckbilled platypus, duck-billed platypus, Ornithorhynchus anatinus",
120
+ "104": "wallaby, brush kangaroo",
121
+ "105": "koala, koala bear, kangaroo bear, native bear, Phascolarctos cinereus",
122
+ "106": "wombat",
123
+ "107": "jellyfish",
124
+ "108": "sea anemone, anemone",
125
+ "109": "brain coral",
126
+ "110": "flatworm, platyhelminth",
127
+ "111": "nematode, nematode worm, roundworm",
128
+ "112": "conch",
129
+ "113": "snail",
130
+ "114": "slug",
131
+ "115": "sea slug, nudibranch",
132
+ "116": "chiton, coat-of-mail shell, sea cradle, polyplacophore",
133
+ "117": "chambered nautilus, pearly nautilus, nautilus",
134
+ "118": "Dungeness crab, Cancer magister",
135
+ "119": "rock crab, Cancer irroratus",
136
+ "120": "fiddler crab",
137
+ "121": "king crab, Alaska crab, Alaskan king crab, Alaska king crab, Paralithodes camtschatica",
138
+ "122": "American lobster, Northern lobster, Maine lobster, Homarus americanus",
139
+ "123": "spiny lobster, langouste, rock lobster, crawfish, crayfish, sea crawfish",
140
+ "124": "crayfish, crawfish, crawdad, crawdaddy",
141
+ "125": "hermit crab",
142
+ "126": "isopod",
143
+ "127": "white stork, Ciconia ciconia",
144
+ "128": "black stork, Ciconia nigra",
145
+ "129": "spoonbill",
146
+ "130": "flamingo",
147
+ "131": "little blue heron, Egretta caerulea",
148
+ "132": "American egret, great white heron, Egretta albus",
149
+ "133": "bittern",
150
+ "134": "crane",
151
+ "135": "limpkin, Aramus pictus",
152
+ "136": "European gallinule, Porphyrio porphyrio",
153
+ "137": "American coot, marsh hen, mud hen, water hen, Fulica americana",
154
+ "138": "bustard",
155
+ "139": "ruddy turnstone, Arenaria interpres",
156
+ "140": "red-backed sandpiper, dunlin, Erolia alpina",
157
+ "141": "redshank, Tringa totanus",
158
+ "142": "dowitcher",
159
+ "143": "oystercatcher, oyster catcher",
160
+ "144": "pelican",
161
+ "145": "king penguin, Aptenodytes patagonica",
162
+ "146": "albatross, mollymawk",
163
+ "147": "grey whale, gray whale, devilfish, Eschrichtius gibbosus, Eschrichtius robustus",
164
+ "148": "killer whale, killer, orca, grampus, sea wolf, Orcinus orca",
165
+ "149": "dugong, Dugong dugon",
166
+ "150": "sea lion",
167
+ "151": "Chihuahua",
168
+ "152": "Japanese spaniel",
169
+ "153": "Maltese dog, Maltese terrier, Maltese",
170
+ "154": "Pekinese, Pekingese, Peke",
171
+ "155": "Shih-Tzu",
172
+ "156": "Blenheim spaniel",
173
+ "157": "papillon",
174
+ "158": "toy terrier",
175
+ "159": "Rhodesian ridgeback",
176
+ "160": "Afghan hound, Afghan",
177
+ "161": "basset, basset hound",
178
+ "162": "beagle",
179
+ "163": "bloodhound, sleuthhound",
180
+ "164": "bluetick",
181
+ "165": "black-and-tan coonhound",
182
+ "166": "Walker hound, Walker foxhound",
183
+ "167": "English foxhound",
184
+ "168": "redbone",
185
+ "169": "borzoi, Russian wolfhound",
186
+ "170": "Irish wolfhound",
187
+ "171": "Italian greyhound",
188
+ "172": "whippet",
189
+ "173": "Ibizan hound, Ibizan Podenco",
190
+ "174": "Norwegian elkhound, elkhound",
191
+ "175": "otterhound, otter hound",
192
+ "176": "Saluki, gazelle hound",
193
+ "177": "Scottish deerhound, deerhound",
194
+ "178": "Weimaraner",
195
+ "179": "Staffordshire bullterrier, Staffordshire bull terrier",
196
+ "180": "American Staffordshire terrier, Staffordshire terrier, American pit bull terrier, pit bull terrier",
197
+ "181": "Bedlington terrier",
198
+ "182": "Border terrier",
199
+ "183": "Kerry blue terrier",
200
+ "184": "Irish terrier",
201
+ "185": "Norfolk terrier",
202
+ "186": "Norwich terrier",
203
+ "187": "Yorkshire terrier",
204
+ "188": "wire-haired fox terrier",
205
+ "189": "Lakeland terrier",
206
+ "190": "Sealyham terrier, Sealyham",
207
+ "191": "Airedale, Airedale terrier",
208
+ "192": "cairn, cairn terrier",
209
+ "193": "Australian terrier",
210
+ "194": "Dandie Dinmont, Dandie Dinmont terrier",
211
+ "195": "Boston bull, Boston terrier",
212
+ "196": "miniature schnauzer",
213
+ "197": "giant schnauzer",
214
+ "198": "standard schnauzer",
215
+ "199": "Scotch terrier, Scottish terrier, Scottie",
216
+ "200": "Tibetan terrier, chrysanthemum dog",
217
+ "201": "silky terrier, Sydney silky",
218
+ "202": "soft-coated wheaten terrier",
219
+ "203": "West Highland white terrier",
220
+ "204": "Lhasa, Lhasa apso",
221
+ "205": "flat-coated retriever",
222
+ "206": "curly-coated retriever",
223
+ "207": "golden retriever",
224
+ "208": "Labrador retriever",
225
+ "209": "Chesapeake Bay retriever",
226
+ "210": "German short-haired pointer",
227
+ "211": "vizsla, Hungarian pointer",
228
+ "212": "English setter",
229
+ "213": "Irish setter, red setter",
230
+ "214": "Gordon setter",
231
+ "215": "Brittany spaniel",
232
+ "216": "clumber, clumber spaniel",
233
+ "217": "English springer, English springer spaniel",
234
+ "218": "Welsh springer spaniel",
235
+ "219": "cocker spaniel, English cocker spaniel, cocker",
236
+ "220": "Sussex spaniel",
237
+ "221": "Irish water spaniel",
238
+ "222": "kuvasz",
239
+ "223": "schipperke",
240
+ "224": "groenendael",
241
+ "225": "malinois",
242
+ "226": "briard",
243
+ "227": "kelpie",
244
+ "228": "komondor",
245
+ "229": "Old English sheepdog, bobtail",
246
+ "230": "Shetland sheepdog, Shetland sheep dog, Shetland",
247
+ "231": "collie",
248
+ "232": "Border collie",
249
+ "233": "Bouvier des Flandres, Bouviers des Flandres",
250
+ "234": "Rottweiler",
251
+ "235": "German shepherd, German shepherd dog, German police dog, alsatian",
252
+ "236": "Doberman, Doberman pinscher",
253
+ "237": "miniature pinscher",
254
+ "238": "Greater Swiss Mountain dog",
255
+ "239": "Bernese mountain dog",
256
+ "240": "Appenzeller",
257
+ "241": "EntleBucher",
258
+ "242": "boxer",
259
+ "243": "bull mastiff",
260
+ "244": "Tibetan mastiff",
261
+ "245": "French bulldog",
262
+ "246": "Great Dane",
263
+ "247": "Saint Bernard, St Bernard",
264
+ "248": "Eskimo dog, husky",
265
+ "249": "malamute, malemute, Alaskan malamute",
266
+ "250": "Siberian husky",
267
+ "251": "dalmatian, coach dog, carriage dog",
268
+ "252": "affenpinscher, monkey pinscher, monkey dog",
269
+ "253": "basenji",
270
+ "254": "pug, pug-dog",
271
+ "255": "Leonberg",
272
+ "256": "Newfoundland, Newfoundland dog",
273
+ "257": "Great Pyrenees",
274
+ "258": "Samoyed, Samoyede",
275
+ "259": "Pomeranian",
276
+ "260": "chow, chow chow",
277
+ "261": "keeshond",
278
+ "262": "Brabancon griffon",
279
+ "263": "Pembroke, Pembroke Welsh corgi",
280
+ "264": "Cardigan, Cardigan Welsh corgi",
281
+ "265": "toy poodle",
282
+ "266": "miniature poodle",
283
+ "267": "standard poodle",
284
+ "268": "Mexican hairless",
285
+ "269": "timber wolf, grey wolf, gray wolf, Canis lupus",
286
+ "270": "white wolf, Arctic wolf, Canis lupus tundrarum",
287
+ "271": "red wolf, maned wolf, Canis rufus, Canis niger",
288
+ "272": "coyote, prairie wolf, brush wolf, Canis latrans",
289
+ "273": "dingo, warrigal, warragal, Canis dingo",
290
+ "274": "dhole, Cuon alpinus",
291
+ "275": "African hunting dog, hyena dog, Cape hunting dog, Lycaon pictus",
292
+ "276": "hyena, hyaena",
293
+ "277": "red fox, Vulpes vulpes",
294
+ "278": "kit fox, Vulpes macrotis",
295
+ "279": "Arctic fox, white fox, Alopex lagopus",
296
+ "280": "grey fox, gray fox, Urocyon cinereoargenteus",
297
+ "281": "tabby, tabby cat",
298
+ "282": "tiger cat",
299
+ "283": "Persian cat",
300
+ "284": "Siamese cat, Siamese",
301
+ "285": "Egyptian cat",
302
+ "286": "cougar, puma, catamount, mountain lion, painter, panther, Felis concolor",
303
+ "287": "lynx, catamount",
304
+ "288": "leopard, Panthera pardus",
305
+ "289": "snow leopard, ounce, Panthera uncia",
306
+ "290": "jaguar, panther, Panthera onca, Felis onca",
307
+ "291": "lion, king of beasts, Panthera leo",
308
+ "292": "tiger, Panthera tigris",
309
+ "293": "cheetah, chetah, Acinonyx jubatus",
310
+ "294": "brown bear, bruin, Ursus arctos",
311
+ "295": "American black bear, black bear, Ursus americanus, Euarctos americanus",
312
+ "296": "ice bear, polar bear, Ursus Maritimus, Thalarctos maritimus",
313
+ "297": "sloth bear, Melursus ursinus, Ursus ursinus",
314
+ "298": "mongoose",
315
+ "299": "meerkat, mierkat",
316
+ "300": "tiger beetle",
317
+ "301": "ladybug, ladybeetle, lady beetle, ladybird, ladybird beetle",
318
+ "302": "ground beetle, carabid beetle",
319
+ "303": "long-horned beetle, longicorn, longicorn beetle",
320
+ "304": "leaf beetle, chrysomelid",
321
+ "305": "dung beetle",
322
+ "306": "rhinoceros beetle",
323
+ "307": "weevil",
324
+ "308": "fly",
325
+ "309": "bee",
326
+ "310": "ant, emmet, pismire",
327
+ "311": "grasshopper, hopper",
328
+ "312": "cricket",
329
+ "313": "walking stick, walkingstick, stick insect",
330
+ "314": "cockroach, roach",
331
+ "315": "mantis, mantid",
332
+ "316": "cicada, cicala",
333
+ "317": "leafhopper",
334
+ "318": "lacewing, lacewing fly",
335
+ "319": "dragonfly, darning needle, devils darning needle, sewing needle, snake feeder, snake doctor, mosquito hawk, skeeter hawk",
336
+ "320": "damselfly",
337
+ "321": "admiral",
338
+ "322": "ringlet, ringlet butterfly",
339
+ "323": "monarch, monarch butterfly, milkweed butterfly, Danaus plexippus",
340
+ "324": "cabbage butterfly",
341
+ "325": "sulphur butterfly, sulfur butterfly",
342
+ "326": "lycaenid, lycaenid butterfly",
343
+ "327": "starfish, sea star",
344
+ "328": "sea urchin",
345
+ "329": "sea cucumber, holothurian",
346
+ "330": "wood rabbit, cottontail, cottontail rabbit",
347
+ "331": "hare",
348
+ "332": "Angora, Angora rabbit",
349
+ "333": "hamster",
350
+ "334": "porcupine, hedgehog",
351
+ "335": "fox squirrel, eastern fox squirrel, Sciurus niger",
352
+ "336": "marmot",
353
+ "337": "beaver",
354
+ "338": "guinea pig, Cavia cobaya",
355
+ "339": "sorrel",
356
+ "340": "zebra",
357
+ "341": "hog, pig, grunter, squealer, Sus scrofa",
358
+ "342": "wild boar, boar, Sus scrofa",
359
+ "343": "warthog",
360
+ "344": "hippopotamus, hippo, river horse, Hippopotamus amphibius",
361
+ "345": "ox",
362
+ "346": "water buffalo, water ox, Asiatic buffalo, Bubalus bubalis",
363
+ "347": "bison",
364
+ "348": "ram, tup",
365
+ "349": "bighorn, bighorn sheep, cimarron, Rocky Mountain bighorn, Rocky Mountain sheep, Ovis canadensis",
366
+ "350": "ibex, Capra ibex",
367
+ "351": "hartebeest",
368
+ "352": "impala, Aepyceros melampus",
369
+ "353": "gazelle",
370
+ "354": "Arabian camel, dromedary, Camelus dromedarius",
371
+ "355": "llama",
372
+ "356": "weasel",
373
+ "357": "mink",
374
+ "358": "polecat, fitch, foulmart, foumart, Mustela putorius",
375
+ "359": "black-footed ferret, ferret, Mustela nigripes",
376
+ "360": "otter",
377
+ "361": "skunk, polecat, wood pussy",
378
+ "362": "badger",
379
+ "363": "armadillo",
380
+ "364": "three-toed sloth, ai, Bradypus tridactylus",
381
+ "365": "orangutan, orang, orangutang, Pongo pygmaeus",
382
+ "366": "gorilla, Gorilla gorilla",
383
+ "367": "chimpanzee, chimp, Pan troglodytes",
384
+ "368": "gibbon, Hylobates lar",
385
+ "369": "siamang, Hylobates syndactylus, Symphalangus syndactylus",
386
+ "370": "guenon, guenon monkey",
387
+ "371": "patas, hussar monkey, Erythrocebus patas",
388
+ "372": "baboon",
389
+ "373": "macaque",
390
+ "374": "langur",
391
+ "375": "colobus, colobus monkey",
392
+ "376": "proboscis monkey, Nasalis larvatus",
393
+ "377": "marmoset",
394
+ "378": "capuchin, ringtail, Cebus capucinus",
395
+ "379": "howler monkey, howler",
396
+ "380": "titi, titi monkey",
397
+ "381": "spider monkey, Ateles geoffroyi",
398
+ "382": "squirrel monkey, Saimiri sciureus",
399
+ "383": "Madagascar cat, ring-tailed lemur, Lemur catta",
400
+ "384": "indri, indris, Indri indri, Indri brevicaudatus",
401
+ "385": "Indian elephant, Elephas maximus",
402
+ "386": "African elephant, Loxodonta africana",
403
+ "387": "lesser panda, red panda, panda, bear cat, cat bear, Ailurus fulgens",
404
+ "388": "giant panda, panda, panda bear, coon bear, Ailuropoda melanoleuca",
405
+ "389": "barracouta, snoek",
406
+ "390": "eel",
407
+ "391": "coho, cohoe, coho salmon, blue jack, silver salmon, Oncorhynchus kisutch",
408
+ "392": "rock beauty, Holocanthus tricolor",
409
+ "393": "anemone fish",
410
+ "394": "sturgeon",
411
+ "395": "gar, garfish, garpike, billfish, Lepisosteus osseus",
412
+ "396": "lionfish",
413
+ "397": "puffer, pufferfish, blowfish, globefish",
414
+ "398": "abacus",
415
+ "399": "abaya",
416
+ "400": "academic gown, academic robe, judge robe",
417
+ "401": "accordion, piano accordion, squeeze box",
418
+ "402": "acoustic guitar",
419
+ "403": "aircraft carrier, carrier, flattop, attack aircraft carrier",
420
+ "404": "airliner",
421
+ "405": "airship, dirigible",
422
+ "406": "altar",
423
+ "407": "ambulance",
424
+ "408": "amphibian, amphibious vehicle",
425
+ "409": "analog clock",
426
+ "410": "apiary, bee house",
427
+ "411": "apron",
428
+ "412": "ashcan, trash can, garbage can, wastebin, ash bin, ash-bin, ashbin, dustbin, trash barrel, trash bin",
429
+ "413": "assault rifle, assault gun",
430
+ "414": "backpack, back pack, knapsack, packsack, rucksack, haversack",
431
+ "415": "bakery, bakeshop, bakehouse",
432
+ "416": "balance beam, beam",
433
+ "417": "balloon",
434
+ "418": "ballpoint, ballpoint pen, ballpen, Biro",
435
+ "419": "Band Aid",
436
+ "420": "banjo",
437
+ "421": "bannister, banister, balustrade, balusters, handrail",
438
+ "422": "barbell",
439
+ "423": "barber chair",
440
+ "424": "barbershop",
441
+ "425": "barn",
442
+ "426": "barometer",
443
+ "427": "barrel, cask",
444
+ "428": "barrow, garden cart, lawn cart, wheelbarrow",
445
+ "429": "baseball",
446
+ "430": "basketball",
447
+ "431": "bassinet",
448
+ "432": "bassoon",
449
+ "433": "bathing cap, swimming cap",
450
+ "434": "bath towel",
451
+ "435": "bathtub, bathing tub, bath, tub",
452
+ "436": "beach wagon, station wagon, wagon, estate car, beach waggon, station waggon, waggon",
453
+ "437": "beacon, lighthouse, beacon light, pharos",
454
+ "438": "beaker",
455
+ "439": "bearskin, busby, shako",
456
+ "440": "beer bottle",
457
+ "441": "beer glass",
458
+ "442": "bell cote, bell cot",
459
+ "443": "bib",
460
+ "444": "bicycle-built-for-two, tandem bicycle, tandem",
461
+ "445": "bikini, two-piece",
462
+ "446": "binder, ring-binder",
463
+ "447": "binoculars, field glasses, opera glasses",
464
+ "448": "birdhouse",
465
+ "449": "boathouse",
466
+ "450": "bobsled, bobsleigh, bob",
467
+ "451": "bolo tie, bolo, bola tie, bola",
468
+ "452": "bonnet, poke bonnet",
469
+ "453": "bookcase",
470
+ "454": "bookshop, bookstore, bookstall",
471
+ "455": "bottlecap",
472
+ "456": "bow",
473
+ "457": "bow tie, bow-tie, bowtie",
474
+ "458": "brass, memorial tablet, plaque",
475
+ "459": "brassiere, bra, bandeau",
476
+ "460": "breakwater, groin, groyne, mole, bulwark, seawall, jetty",
477
+ "461": "breastplate, aegis, egis",
478
+ "462": "broom",
479
+ "463": "bucket, pail",
480
+ "464": "buckle",
481
+ "465": "bulletproof vest",
482
+ "466": "bullet train, bullet",
483
+ "467": "butcher shop, meat market",
484
+ "468": "cab, hack, taxi, taxicab",
485
+ "469": "caldron, cauldron",
486
+ "470": "candle, taper, wax light",
487
+ "471": "cannon",
488
+ "472": "canoe",
489
+ "473": "can opener, tin opener",
490
+ "474": "cardigan",
491
+ "475": "car mirror",
492
+ "476": "carousel, carrousel, merry-go-round, roundabout, whirligig",
493
+ "477": "carpenters kit, tool kit",
494
+ "478": "carton",
495
+ "479": "car wheel",
496
+ "480": "cash machine, cash dispenser, automated teller machine, automatic teller machine, automated teller, automatic teller, ATM",
497
+ "481": "cassette",
498
+ "482": "cassette player",
499
+ "483": "castle",
500
+ "484": "catamaran",
501
+ "485": "CD player",
502
+ "486": "cello, violoncello",
503
+ "487": "cellular telephone, cellular phone, cellphone, cell, mobile phone",
504
+ "488": "chain",
505
+ "489": "chainlink fence",
506
+ "490": "chain mail, ring mail, mail, chain armor, chain armour, ring armor, ring armour",
507
+ "491": "chain saw, chainsaw",
508
+ "492": "chest",
509
+ "493": "chiffonier, commode",
510
+ "494": "chime, bell, gong",
511
+ "495": "china cabinet, china closet",
512
+ "496": "Christmas stocking",
513
+ "497": "church, church building",
514
+ "498": "cinema, movie theater, movie theatre, movie house, picture palace",
515
+ "499": "cleaver, meat cleaver, chopper",
516
+ "500": "cliff dwelling",
517
+ "501": "cloak",
518
+ "502": "clog, geta, patten, sabot",
519
+ "503": "cocktail shaker",
520
+ "504": "coffee mug",
521
+ "505": "coffeepot",
522
+ "506": "coil, spiral, volute, whorl, helix",
523
+ "507": "combination lock",
524
+ "508": "computer keyboard, keypad",
525
+ "509": "confectionery, confectionary, candy store",
526
+ "510": "container ship, containership, container vessel",
527
+ "511": "convertible",
528
+ "512": "corkscrew, bottle screw",
529
+ "513": "cornet, horn, trumpet, trump",
530
+ "514": "cowboy boot",
531
+ "515": "cowboy hat, ten-gallon hat",
532
+ "516": "cradle",
533
+ "517": "crane",
534
+ "518": "crash helmet",
535
+ "519": "crate",
536
+ "520": "crib, cot",
537
+ "521": "Crock Pot",
538
+ "522": "croquet ball",
539
+ "523": "crutch",
540
+ "524": "cuirass",
541
+ "525": "dam, dike, dyke",
542
+ "526": "desk",
543
+ "527": "desktop computer",
544
+ "528": "dial telephone, dial phone",
545
+ "529": "diaper, nappy, napkin",
546
+ "530": "digital clock",
547
+ "531": "digital watch",
548
+ "532": "dining table, board",
549
+ "533": "dishrag, dishcloth",
550
+ "534": "dishwasher, dish washer, dishwashing machine",
551
+ "535": "disk brake, disc brake",
552
+ "536": "dock, dockage, docking facility",
553
+ "537": "dogsled, dog sled, dog sleigh",
554
+ "538": "dome",
555
+ "539": "doormat, welcome mat",
556
+ "540": "drilling platform, offshore rig",
557
+ "541": "drum, membranophone, tympan",
558
+ "542": "drumstick",
559
+ "543": "dumbbell",
560
+ "544": "Dutch oven",
561
+ "545": "electric fan, blower",
562
+ "546": "electric guitar",
563
+ "547": "electric locomotive",
564
+ "548": "entertainment center",
565
+ "549": "envelope",
566
+ "550": "espresso maker",
567
+ "551": "face powder",
568
+ "552": "feather boa, boa",
569
+ "553": "file, file cabinet, filing cabinet",
570
+ "554": "fireboat",
571
+ "555": "fire engine, fire truck",
572
+ "556": "fire screen, fireguard",
573
+ "557": "flagpole, flagstaff",
574
+ "558": "flute, transverse flute",
575
+ "559": "folding chair",
576
+ "560": "football helmet",
577
+ "561": "forklift",
578
+ "562": "fountain",
579
+ "563": "fountain pen",
580
+ "564": "four-poster",
581
+ "565": "freight car",
582
+ "566": "French horn, horn",
583
+ "567": "frying pan, frypan, skillet",
584
+ "568": "fur coat",
585
+ "569": "garbage truck, dustcart",
586
+ "570": "gasmask, respirator, gas helmet",
587
+ "571": "gas pump, gasoline pump, petrol pump, island dispenser",
588
+ "572": "goblet",
589
+ "573": "go-kart",
590
+ "574": "golf ball",
591
+ "575": "golfcart, golf cart",
592
+ "576": "gondola",
593
+ "577": "gong, tam-tam",
594
+ "578": "gown",
595
+ "579": "grand piano, grand",
596
+ "580": "greenhouse, nursery, glasshouse",
597
+ "581": "grille, radiator grille",
598
+ "582": "grocery store, grocery, food market, market",
599
+ "583": "guillotine",
600
+ "584": "hair slide",
601
+ "585": "hair spray",
602
+ "586": "half track",
603
+ "587": "hammer",
604
+ "588": "hamper",
605
+ "589": "hand blower, blow dryer, blow drier, hair dryer, hair drier",
606
+ "590": "hand-held computer, hand-held microcomputer",
607
+ "591": "handkerchief, hankie, hanky, hankey",
608
+ "592": "hard disc, hard disk, fixed disk",
609
+ "593": "harmonica, mouth organ, harp, mouth harp",
610
+ "594": "harp",
611
+ "595": "harvester, reaper",
612
+ "596": "hatchet",
613
+ "597": "holster",
614
+ "598": "home theater, home theatre",
615
+ "599": "honeycomb",
616
+ "600": "hook, claw",
617
+ "601": "hoopskirt, crinoline",
618
+ "602": "horizontal bar, high bar",
619
+ "603": "horse cart, horse-cart",
620
+ "604": "hourglass",
621
+ "605": "iPod",
622
+ "606": "iron, smoothing iron",
623
+ "607": "jack-o-lantern",
624
+ "608": "jean, blue jean, denim",
625
+ "609": "jeep, landrover",
626
+ "610": "jersey, T-shirt, tee shirt",
627
+ "611": "jigsaw puzzle",
628
+ "612": "jinrikisha, ricksha, rickshaw",
629
+ "613": "joystick",
630
+ "614": "kimono",
631
+ "615": "knee pad",
632
+ "616": "knot",
633
+ "617": "lab coat, laboratory coat",
634
+ "618": "ladle",
635
+ "619": "lampshade, lamp shade",
636
+ "620": "laptop, laptop computer",
637
+ "621": "lawn mower, mower",
638
+ "622": "lens cap, lens cover",
639
+ "623": "letter opener, paper knife, paperknife",
640
+ "624": "library",
641
+ "625": "lifeboat",
642
+ "626": "lighter, light, igniter, ignitor",
643
+ "627": "limousine, limo",
644
+ "628": "liner, ocean liner",
645
+ "629": "lipstick, lip rouge",
646
+ "630": "Loafer",
647
+ "631": "lotion",
648
+ "632": "loudspeaker, speaker, speaker unit, loudspeaker system, speaker system",
649
+ "633": "loupe, jewelers loupe",
650
+ "634": "lumbermill, sawmill",
651
+ "635": "magnetic compass",
652
+ "636": "mailbag, postbag",
653
+ "637": "mailbox, letter box",
654
+ "638": "maillot",
655
+ "639": "maillot, tank suit",
656
+ "640": "manhole cover",
657
+ "641": "maraca",
658
+ "642": "marimba, xylophone",
659
+ "643": "mask",
660
+ "644": "matchstick",
661
+ "645": "maypole",
662
+ "646": "maze, labyrinth",
663
+ "647": "measuring cup",
664
+ "648": "medicine chest, medicine cabinet",
665
+ "649": "megalith, megalithic structure",
666
+ "650": "microphone, mike",
667
+ "651": "microwave, microwave oven",
668
+ "652": "military uniform",
669
+ "653": "milk can",
670
+ "654": "minibus",
671
+ "655": "miniskirt, mini",
672
+ "656": "minivan",
673
+ "657": "missile",
674
+ "658": "mitten",
675
+ "659": "mixing bowl",
676
+ "660": "mobile home, manufactured home",
677
+ "661": "Model T",
678
+ "662": "modem",
679
+ "663": "monastery",
680
+ "664": "monitor",
681
+ "665": "moped",
682
+ "666": "mortar",
683
+ "667": "mortarboard",
684
+ "668": "mosque",
685
+ "669": "mosquito net",
686
+ "670": "motor scooter, scooter",
687
+ "671": "mountain bike, all-terrain bike, off-roader",
688
+ "672": "mountain tent",
689
+ "673": "mouse, computer mouse",
690
+ "674": "mousetrap",
691
+ "675": "moving van",
692
+ "676": "muzzle",
693
+ "677": "nail",
694
+ "678": "neck brace",
695
+ "679": "necklace",
696
+ "680": "nipple",
697
+ "681": "notebook, notebook computer",
698
+ "682": "obelisk",
699
+ "683": "oboe, hautboy, hautbois",
700
+ "684": "ocarina, sweet potato",
701
+ "685": "odometer, hodometer, mileometer, milometer",
702
+ "686": "oil filter",
703
+ "687": "organ, pipe organ",
704
+ "688": "oscilloscope, scope, cathode-ray oscilloscope, CRO",
705
+ "689": "overskirt",
706
+ "690": "oxcart",
707
+ "691": "oxygen mask",
708
+ "692": "packet",
709
+ "693": "paddle, boat paddle",
710
+ "694": "paddlewheel, paddle wheel",
711
+ "695": "padlock",
712
+ "696": "paintbrush",
713
+ "697": "pajama, pyjama, pjs, jammies",
714
+ "698": "palace",
715
+ "699": "panpipe, pandean pipe, syrinx",
716
+ "700": "paper towel",
717
+ "701": "parachute, chute",
718
+ "702": "parallel bars, bars",
719
+ "703": "park bench",
720
+ "704": "parking meter",
721
+ "705": "passenger car, coach, carriage",
722
+ "706": "patio, terrace",
723
+ "707": "pay-phone, pay-station",
724
+ "708": "pedestal, plinth, footstall",
725
+ "709": "pencil box, pencil case",
726
+ "710": "pencil sharpener",
727
+ "711": "perfume, essence",
728
+ "712": "Petri dish",
729
+ "713": "photocopier",
730
+ "714": "pick, plectrum, plectron",
731
+ "715": "pickelhaube",
732
+ "716": "picket fence, paling",
733
+ "717": "pickup, pickup truck",
734
+ "718": "pier",
735
+ "719": "piggy bank, penny bank",
736
+ "720": "pill bottle",
737
+ "721": "pillow",
738
+ "722": "ping-pong ball",
739
+ "723": "pinwheel",
740
+ "724": "pirate, pirate ship",
741
+ "725": "pitcher, ewer",
742
+ "726": "plane, carpenters plane, woodworking plane",
743
+ "727": "planetarium",
744
+ "728": "plastic bag",
745
+ "729": "plate rack",
746
+ "730": "plow, plough",
747
+ "731": "plunger, plumbers helper",
748
+ "732": "Polaroid camera, Polaroid Land camera",
749
+ "733": "pole",
750
+ "734": "police van, police wagon, paddy wagon, patrol wagon, wagon, black Maria",
751
+ "735": "poncho",
752
+ "736": "pool table, billiard table, snooker table",
753
+ "737": "pop bottle, soda bottle",
754
+ "738": "pot, flowerpot",
755
+ "739": "potters wheel",
756
+ "740": "power drill",
757
+ "741": "prayer rug, prayer mat",
758
+ "742": "printer",
759
+ "743": "prison, prison house",
760
+ "744": "projectile, missile",
761
+ "745": "projector",
762
+ "746": "puck, hockey puck",
763
+ "747": "punching bag, punch bag, punching ball, punchball",
764
+ "748": "purse",
765
+ "749": "quill, quill pen",
766
+ "750": "quilt, comforter, comfort, puff",
767
+ "751": "racer, race car, racing car",
768
+ "752": "racket, racquet",
769
+ "753": "radiator",
770
+ "754": "radio, wireless",
771
+ "755": "radio telescope, radio reflector",
772
+ "756": "rain barrel",
773
+ "757": "recreational vehicle, RV, R.V.",
774
+ "758": "reel",
775
+ "759": "reflex camera",
776
+ "760": "refrigerator, icebox",
777
+ "761": "remote control, remote",
778
+ "762": "restaurant, eating house, eating place, eatery",
779
+ "763": "revolver, six-gun, six-shooter",
780
+ "764": "rifle",
781
+ "765": "rocking chair, rocker",
782
+ "766": "rotisserie",
783
+ "767": "rubber eraser, rubber, pencil eraser",
784
+ "768": "rugby ball",
785
+ "769": "rule, ruler",
786
+ "770": "running shoe",
787
+ "771": "safe",
788
+ "772": "safety pin",
789
+ "773": "saltshaker, salt shaker",
790
+ "774": "sandal",
791
+ "775": "sarong",
792
+ "776": "sax, saxophone",
793
+ "777": "scabbard",
794
+ "778": "scale, weighing machine",
795
+ "779": "school bus",
796
+ "780": "schooner",
797
+ "781": "scoreboard",
798
+ "782": "screen, CRT screen",
799
+ "783": "screw",
800
+ "784": "screwdriver",
801
+ "785": "seat belt, seatbelt",
802
+ "786": "sewing machine",
803
+ "787": "shield, buckler",
804
+ "788": "shoe shop, shoe-shop, shoe store",
805
+ "789": "shoji",
806
+ "790": "shopping basket",
807
+ "791": "shopping cart",
808
+ "792": "shovel",
809
+ "793": "shower cap",
810
+ "794": "shower curtain",
811
+ "795": "ski",
812
+ "796": "ski mask",
813
+ "797": "sleeping bag",
814
+ "798": "slide rule, slipstick",
815
+ "799": "sliding door",
816
+ "800": "slot, one-armed bandit",
817
+ "801": "snorkel",
818
+ "802": "snowmobile",
819
+ "803": "snowplow, snowplough",
820
+ "804": "soap dispenser",
821
+ "805": "soccer ball",
822
+ "806": "sock",
823
+ "807": "solar dish, solar collector, solar furnace",
824
+ "808": "sombrero",
825
+ "809": "soup bowl",
826
+ "810": "space bar",
827
+ "811": "space heater",
828
+ "812": "space shuttle",
829
+ "813": "spatula",
830
+ "814": "speedboat",
831
+ "815": "spider web, spiders web",
832
+ "816": "spindle",
833
+ "817": "sports car, sport car",
834
+ "818": "spotlight, spot",
835
+ "819": "stage",
836
+ "820": "steam locomotive",
837
+ "821": "steel arch bridge",
838
+ "822": "steel drum",
839
+ "823": "stethoscope",
840
+ "824": "stole",
841
+ "825": "stone wall",
842
+ "826": "stopwatch, stop watch",
843
+ "827": "stove",
844
+ "828": "strainer",
845
+ "829": "streetcar, tram, tramcar, trolley, trolley car",
846
+ "830": "stretcher",
847
+ "831": "studio couch, day bed",
848
+ "832": "stupa, tope",
849
+ "833": "submarine, pigboat, sub, U-boat",
850
+ "834": "suit, suit of clothes",
851
+ "835": "sundial",
852
+ "836": "sunglass",
853
+ "837": "sunglasses, dark glasses, shades",
854
+ "838": "sunscreen, sunblock, sun blocker",
855
+ "839": "suspension bridge",
856
+ "840": "swab, swob, mop",
857
+ "841": "sweatshirt",
858
+ "842": "swimming trunks, bathing trunks",
859
+ "843": "swing",
860
+ "844": "switch, electric switch, electrical switch",
861
+ "845": "syringe",
862
+ "846": "table lamp",
863
+ "847": "tank, army tank, armored combat vehicle, armoured combat vehicle",
864
+ "848": "tape player",
865
+ "849": "teapot",
866
+ "850": "teddy, teddy bear",
867
+ "851": "television, television system",
868
+ "852": "tennis ball",
869
+ "853": "thatch, thatched roof",
870
+ "854": "theater curtain, theatre curtain",
871
+ "855": "thimble",
872
+ "856": "thresher, thrasher, threshing machine",
873
+ "857": "throne",
874
+ "858": "tile roof",
875
+ "859": "toaster",
876
+ "860": "tobacco shop, tobacconist shop, tobacconist",
877
+ "861": "toilet seat",
878
+ "862": "torch",
879
+ "863": "totem pole",
880
+ "864": "tow truck, tow car, wrecker",
881
+ "865": "toyshop",
882
+ "866": "tractor",
883
+ "867": "trailer truck, tractor trailer, trucking rig, rig, articulated lorry, semi",
884
+ "868": "tray",
885
+ "869": "trench coat",
886
+ "870": "tricycle, trike, velocipede",
887
+ "871": "trimaran",
888
+ "872": "tripod",
889
+ "873": "triumphal arch",
890
+ "874": "trolleybus, trolley coach, trackless trolley",
891
+ "875": "trombone",
892
+ "876": "tub, vat",
893
+ "877": "turnstile",
894
+ "878": "typewriter keyboard",
895
+ "879": "umbrella",
896
+ "880": "unicycle, monocycle",
897
+ "881": "upright, upright piano",
898
+ "882": "vacuum, vacuum cleaner",
899
+ "883": "vase",
900
+ "884": "vault",
901
+ "885": "velvet",
902
+ "886": "vending machine",
903
+ "887": "vestment",
904
+ "888": "viaduct",
905
+ "889": "violin, fiddle",
906
+ "890": "volleyball",
907
+ "891": "waffle iron",
908
+ "892": "wall clock",
909
+ "893": "wallet, billfold, notecase, pocketbook",
910
+ "894": "wardrobe, closet, press",
911
+ "895": "warplane, military plane",
912
+ "896": "washbasin, handbasin, washbowl, lavabo, wash-hand basin",
913
+ "897": "washer, automatic washer, washing machine",
914
+ "898": "water bottle",
915
+ "899": "water jug",
916
+ "900": "water tower",
917
+ "901": "whiskey jug",
918
+ "902": "whistle",
919
+ "903": "wig",
920
+ "904": "window screen",
921
+ "905": "window shade",
922
+ "906": "Windsor tie",
923
+ "907": "wine bottle",
924
+ "908": "wing",
925
+ "909": "wok",
926
+ "910": "wooden spoon",
927
+ "911": "wool, woolen, woollen",
928
+ "912": "worm fence, snake fence, snake-rail fence, Virginia fence",
929
+ "913": "wreck",
930
+ "914": "yawl",
931
+ "915": "yurt",
932
+ "916": "web site, website, internet site, site",
933
+ "917": "comic book",
934
+ "918": "crossword puzzle, crossword",
935
+ "919": "street sign",
936
+ "920": "traffic light, traffic signal, stoplight",
937
+ "921": "book jacket, dust cover, dust jacket, dust wrapper",
938
+ "922": "menu",
939
+ "923": "plate",
940
+ "924": "guacamole",
941
+ "925": "consomme",
942
+ "926": "hot pot, hotpot",
943
+ "927": "trifle",
944
+ "928": "ice cream, icecream",
945
+ "929": "ice lolly, lolly, lollipop, popsicle",
946
+ "930": "French loaf",
947
+ "931": "bagel, beigel",
948
+ "932": "pretzel",
949
+ "933": "cheeseburger",
950
+ "934": "hotdog, hot dog, red hot",
951
+ "935": "mashed potato",
952
+ "936": "head cabbage",
953
+ "937": "broccoli",
954
+ "938": "cauliflower",
955
+ "939": "zucchini, courgette",
956
+ "940": "spaghetti squash",
957
+ "941": "acorn squash",
958
+ "942": "butternut squash",
959
+ "943": "cucumber, cuke",
960
+ "944": "artichoke, globe artichoke",
961
+ "945": "bell pepper",
962
+ "946": "cardoon",
963
+ "947": "mushroom",
964
+ "948": "Granny Smith",
965
+ "949": "strawberry",
966
+ "950": "orange",
967
+ "951": "lemon",
968
+ "952": "fig",
969
+ "953": "pineapple, ananas",
970
+ "954": "banana",
971
+ "955": "jackfruit, jak, jack",
972
+ "956": "custard apple",
973
+ "957": "pomegranate",
974
+ "958": "hay",
975
+ "959": "carbonara",
976
+ "960": "chocolate sauce, chocolate syrup",
977
+ "961": "dough",
978
+ "962": "meat loaf, meatloaf",
979
+ "963": "pizza, pizza pie",
980
+ "964": "potpie",
981
+ "965": "burrito",
982
+ "966": "red wine",
983
+ "967": "espresso",
984
+ "968": "cup",
985
+ "969": "eggnog",
986
+ "970": "alp",
987
+ "971": "bubble",
988
+ "972": "cliff, drop, drop-off",
989
+ "973": "coral reef",
990
+ "974": "geyser",
991
+ "975": "lakeside, lakeshore",
992
+ "976": "promontory, headland, head, foreland",
993
+ "977": "sandbar, sand bar",
994
+ "978": "seashore, coast, seacoast, sea-coast",
995
+ "979": "valley, vale",
996
+ "980": "volcano",
997
+ "981": "ballplayer, baseball player",
998
+ "982": "groom, bridegroom",
999
+ "983": "scuba diver",
1000
+ "984": "rapeseed",
1001
+ "985": "daisy",
1002
+ "986": "yellow ladys slipper, yellow lady-slipper, Cypripedium calceolus, Cypripedium parviflorum",
1003
+ "987": "corn",
1004
+ "988": "acorn",
1005
+ "989": "hip, rose hip, rosehip",
1006
+ "990": "buckeye, horse chestnut, conker",
1007
+ "991": "coral fungus",
1008
+ "992": "agaric",
1009
+ "993": "gyromitra",
1010
+ "994": "stinkhorn, carrion fungus",
1011
+ "995": "earthstar",
1012
+ "996": "hen-of-the-woods, hen of the woods, Polyporus frondosus, Grifola frondosa",
1013
+ "997": "bolete",
1014
+ "998": "ear, spike, capitulum",
1015
+ "999": "toilet tissue, toilet paper, bathroom tissue"
1016
+ }
1017
+ }
JiT-H-16-SIM/pipeline.py ADDED
@@ -0,0 +1,350 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ """Hub custom pipeline: JiTPipeline for FD-Loss post-trained JiT (legacy time, velocity Euler)."""
16
+
17
+ from __future__ import annotations
18
+
19
+ import importlib.util
20
+ import inspect
21
+ import json
22
+ from pathlib import Path
23
+ from typing import Dict, List, Optional, Tuple, Union
24
+
25
+ import torch
26
+ from diffusers.pipelines.pipeline_utils import DiffusionPipeline, ImagePipelineOutput
27
+ from diffusers.utils.torch_utils import randn_tensor
28
+
29
+ EXAMPLE_DOC_STRING = """
30
+ Examples:
31
+ ```py
32
+ >>> from pathlib import Path
33
+ >>> import torch
34
+ >>> from diffusers import DiffusionPipeline
35
+
36
+ >>> model_dir = Path("BiliSakura/FD-Loss-diffusers/JiT-B-16-SIM")
37
+ >>> pipe = DiffusionPipeline.from_pretrained(
38
+ ... str(model_dir),
39
+ ... custom_pipeline=str(model_dir / "pipeline.py"),
40
+ ... trust_remote_code=True,
41
+ ... )
42
+ >>> pipe.to("cuda")
43
+ >>> image = pipe(class_labels="golden retriever", num_inference_steps=1, guidance_scale=3.0).images[0]
44
+ ```
45
+ """
46
+
47
+ RECOMMENDED_NOISE_BY_SIZE = {256: 1.0, 512: 2.0}
48
+
49
+
50
+ class JiTPipeline(DiffusionPipeline):
51
+ r"""
52
+ Class-conditional JiT pipeline for FD-Loss checkpoints (1-NFE velocity Euler, legacy time convention).
53
+
54
+ Args:
55
+ transformer ([`JiTTransformer2DModel`]): JiT backbone.
56
+ scheduler ([`FDLossFlowMatchScheduler`], *optional*): Bundled flow-matching scheduler (`t=1→0`).
57
+ Accepts `generator` in `step()` for reproducible stochastic sampling.
58
+ id2label (`dict[int, str]`, *optional*): ImageNet id → label strings from `model_index.json`.
59
+ """
60
+
61
+ model_cpu_offload_seq = "transformer"
62
+ _optional_components = ["scheduler"]
63
+
64
+ @staticmethod
65
+ def prepare_extra_step_kwargs(
66
+ scheduler,
67
+ generator=None,
68
+ eta: float | None = None,
69
+ ):
70
+ kwargs = {}
71
+ step_params = set(inspect.signature(scheduler.step).parameters.keys())
72
+ if "generator" in step_params:
73
+ kwargs["generator"] = generator
74
+ if eta is not None and "eta" in step_params:
75
+ kwargs["eta"] = eta
76
+ return kwargs
77
+
78
+ @staticmethod
79
+ def _resolve_inference_generator(
80
+ device: Union[str, torch.device],
81
+ generator: Optional[Union[torch.Generator, List[torch.Generator]]] = None,
82
+ ) -> Optional[Union[torch.Generator, List[torch.Generator]]]:
83
+ if generator is None:
84
+ return None
85
+ if isinstance(device, str):
86
+ device = torch.device(device)
87
+ device_type = device.type
88
+
89
+ def _relocate(gen: torch.Generator) -> torch.Generator:
90
+ if gen.device.type == device_type:
91
+ return gen
92
+ return torch.Generator(device=device_type).manual_seed(gen.initial_seed())
93
+
94
+ if isinstance(generator, list):
95
+ return [_relocate(g) for g in generator]
96
+ return _relocate(generator)
97
+
98
+ @staticmethod
99
+ def _coerce_scheduler(scheduler, transformer):
100
+ """Always load the bundled FD-Loss flow scheduler (ignore model_index diffusers schedulers)."""
101
+ variant_path = getattr(transformer.config, "_name_or_path", None)
102
+ if variant_path:
103
+ scheduler_dir = Path(variant_path).resolve().parent / "scheduler"
104
+ module_path = scheduler_dir / "scheduling_flow_match_fd.py"
105
+ config_path = scheduler_dir / "scheduler_config.json"
106
+ if module_path.is_file() and config_path.is_file():
107
+ spec = importlib.util.spec_from_file_location("scheduling_flow_match_fd", module_path)
108
+ if spec is not None and spec.loader is not None:
109
+ module = importlib.util.module_from_spec(spec)
110
+ spec.loader.exec_module(module)
111
+ scheduler_cls = getattr(module, "FDLossFlowMatchScheduler")
112
+ return scheduler_cls.from_pretrained(str(scheduler_dir))
113
+ scheduler_dir = Path(__file__).resolve().parent / "scheduler"
114
+ module_path = scheduler_dir / "scheduling_flow_match_fd.py"
115
+ config_path = scheduler_dir / "scheduler_config.json"
116
+ if module_path.is_file() and config_path.is_file():
117
+ spec = importlib.util.spec_from_file_location("scheduling_flow_match_fd", module_path)
118
+ if spec is not None and spec.loader is not None:
119
+ module = importlib.util.module_from_spec(spec)
120
+ spec.loader.exec_module(module)
121
+ scheduler_cls = getattr(module, "FDLossFlowMatchScheduler")
122
+ return scheduler_cls.from_pretrained(str(scheduler_dir))
123
+ raise ValueError("FD-Loss JiT requires a bundled FDLossFlowMatchScheduler under `scheduler/`.")
124
+
125
+ def __init__(
126
+ self,
127
+ transformer,
128
+ scheduler=None,
129
+ id2label: Optional[Dict[Union[int, str], str]] = None,
130
+ ):
131
+ super().__init__()
132
+ self.legacy_time_convention = True
133
+ scheduler = self._coerce_scheduler(scheduler, transformer)
134
+ self.register_modules(transformer=transformer, scheduler=scheduler)
135
+ self._id2label = self._normalize_id2label(id2label)
136
+ self.labels = self._build_label2id(self._id2label)
137
+ self._labels_loaded_from_model_index = bool(self._id2label)
138
+
139
+
140
+ @property
141
+ def id2label(self) -> Dict[int, str]:
142
+ self._ensure_labels_loaded()
143
+ return self._id2label
144
+
145
+ def get_label_ids(self, label: Union[str, List[str]]) -> List[int]:
146
+ r"""Map ImageNet English label strings to class ids."""
147
+ self._ensure_labels_loaded()
148
+ if isinstance(label, str):
149
+ label = [label]
150
+ missing = [item for item in label if item not in self.labels]
151
+ if missing:
152
+ preview = ", ".join(list(self.labels.keys())[:8])
153
+ raise ValueError(f"Unknown label(s): {missing}. Examples: {preview}, ...")
154
+ return [self.labels[item] for item in label]
155
+
156
+ def _backbone_timestep(self, t: torch.Tensor) -> torch.Tensor:
157
+ if self.legacy_time_convention:
158
+ return 1.0 - t
159
+ return t
160
+
161
+ def _cfg_interval(self, interval_min: float, interval_max: float, device: torch.device) -> Tuple[float, float]:
162
+ low = float(self._backbone_timestep(torch.tensor(interval_min, device=device)))
163
+ high = float(self._backbone_timestep(torch.tensor(interval_max, device=device)))
164
+ return min(low, high), max(low, high)
165
+
166
+ def _flow_time_tensors(self, t: torch.Tensor, sample: torch.Tensor) -> Tuple[torch.Tensor, torch.Tensor]:
167
+ """Broadcast scalar flow time and per-sample backbone timesteps for `sample` (B, C, H, W)."""
168
+ flow_t = t.reshape(()).to(device=sample.device, dtype=sample.dtype)
169
+ t_view = flow_t.reshape(*([1] * sample.ndim))
170
+ t_bb = self._backbone_timestep(flow_t).expand(sample.shape[0])
171
+ return t_view, t_bb
172
+
173
+ def _predict_velocity(
174
+ self,
175
+ sample: torch.Tensor,
176
+ t: torch.Tensor,
177
+ class_labels: torch.Tensor,
178
+ guidance_scale: float,
179
+ cfg_interval: Tuple[float, float],
180
+ t_eps: float,
181
+ interpolate_pos_encoding: bool,
182
+ ) -> torch.Tensor:
183
+ t_view, t_bb = self._flow_time_tensors(t, sample)
184
+ num_classes = int(getattr(self.transformer.config, "num_classes", 1000))
185
+
186
+ x_cond = self.transformer(
187
+ sample,
188
+ timestep=t_bb,
189
+ class_labels=class_labels,
190
+ interpolate_pos_encoding=interpolate_pos_encoding,
191
+ ).sample
192
+ v_cond = (sample - x_cond) / t_view.clamp_min(t_eps)
193
+
194
+ if guidance_scale <= 1.0:
195
+ return v_cond
196
+
197
+ class_null = torch.full_like(class_labels, num_classes)
198
+ x_uncond = self.transformer(
199
+ sample,
200
+ timestep=t_bb,
201
+ class_labels=class_null,
202
+ interpolate_pos_encoding=interpolate_pos_encoding,
203
+ ).sample
204
+ v_uncond = (sample - x_uncond) / t_view.clamp_min(t_eps)
205
+
206
+ low, high = cfg_interval
207
+ flow_t = t.reshape(()).to(device=sample.device, dtype=sample.dtype)
208
+ mask = (flow_t < high) & ((low == 0) | (flow_t > low))
209
+ scale = torch.where(
210
+ mask,
211
+ torch.tensor(guidance_scale, device=sample.device, dtype=sample.dtype),
212
+ torch.tensor(1.0, device=sample.device, dtype=sample.dtype),
213
+ )
214
+ while scale.ndim < v_cond.ndim:
215
+ scale = scale.unsqueeze(-1)
216
+ return v_uncond + scale * (v_cond - v_uncond)
217
+
218
+ @staticmethod
219
+ def _normalize_id2label(id2label: Optional[Dict[Union[int, str], str]]) -> Dict[int, str]:
220
+ if not id2label:
221
+ return {}
222
+ return {int(key): value for key, value in id2label.items()}
223
+
224
+ @staticmethod
225
+ def _build_label2id(id2label: Dict[int, str]) -> Dict[str, int]:
226
+ label2id: Dict[str, int] = {}
227
+ for class_id, value in id2label.items():
228
+ for synonym in value.split(","):
229
+ synonym = synonym.strip()
230
+ if synonym:
231
+ label2id[synonym] = int(class_id)
232
+ return dict(sorted(label2id.items()))
233
+
234
+ def _ensure_labels_loaded(self) -> None:
235
+ if self._labels_loaded_from_model_index:
236
+ return
237
+ path = getattr(self.config, "_name_or_path", None)
238
+ if path:
239
+ model_index_path = Path(path).resolve() / "model_index.json"
240
+ if model_index_path.exists():
241
+ raw = json.loads(model_index_path.read_text(encoding="utf-8"))
242
+ id2label = raw.get("id2label")
243
+ if isinstance(id2label, dict):
244
+ self._id2label = {int(k): v for k, v in id2label.items()}
245
+ self.labels = self._build_label2id(self._id2label)
246
+ self._labels_loaded_from_model_index = True
247
+
248
+ def _normalize_class_labels(self, class_labels: Union[int, str, List[Union[int, str]]]) -> List[int]:
249
+ if isinstance(class_labels, int):
250
+ return [class_labels]
251
+ if isinstance(class_labels, str):
252
+ return self.get_label_ids(class_labels)
253
+ if class_labels and isinstance(class_labels[0], str):
254
+ return self.get_label_ids(class_labels)
255
+ return list(class_labels)
256
+
257
+ @torch.inference_mode()
258
+ def __call__(
259
+ self,
260
+ class_labels: Union[int, str, List[Union[int, str]]],
261
+ guidance_scale: float = 3.0,
262
+ guidance_interval_min: float = 0.1,
263
+ guidance_interval_max: float = 1.0,
264
+ noise_scale: Optional[float] = None,
265
+ t_eps: float = 5e-2,
266
+ generator: Optional[Union[torch.Generator, List[torch.Generator]]] = None,
267
+ num_inference_steps: int = 1,
268
+ height: Optional[int] = None,
269
+ width: Optional[int] = None,
270
+ interpolate_pos_encoding: bool = True,
271
+ output_type: Optional[str] = "pil",
272
+ return_dict: bool = True,
273
+ ) -> Union[ImagePipelineOutput, Tuple]:
274
+ r"""
275
+ Generate images conditioned on ImageNet class ids or English labels.
276
+
277
+ Args:
278
+ class_labels: Class id(s), label string(s), or mixed list.
279
+ guidance_scale: CFG scale (FD-Loss JiT-B default: 3.0).
280
+ guidance_interval_min: Lower flow-time bound for CFG (default 0.1).
281
+ guidance_interval_max: Upper flow-time bound for CFG (default 1.0).
282
+ noise_scale: Initial Gaussian scale (default 1.0 at 256px).
283
+ t_eps: Clamp for flow time in velocity denominator.
284
+ generator: RNG for latent init.
285
+ num_inference_steps: FD-Loss sampling steps (1 = single NFE).
286
+ height: Output height (defaults to native `sample_size`).
287
+ width: Output width (defaults to native `sample_size`).
288
+ interpolate_pos_encoding: Interpolate positional embeddings for non-native sizes.
289
+ output_type: `pil`, `np`, or `pt`.
290
+ return_dict: Return [`ImagePipelineOutput`] if True.
291
+ """
292
+ # 1. Check inputs
293
+ if num_inference_steps < 1:
294
+ raise ValueError("num_inference_steps must be >= 1.")
295
+ if output_type not in {"pil", "np", "pt"}:
296
+ raise ValueError("output_type must be one of: 'pil', 'np', 'pt'.")
297
+
298
+ # 2. Call parameters
299
+ class_label_ids = self._normalize_class_labels(class_labels)
300
+ batch_size = len(class_label_ids)
301
+ generator = self._resolve_inference_generator(self._execution_device, generator)
302
+ image_size = int(self.transformer.config.sample_size)
303
+ patch_size = int(self.transformer.config.patch_size)
304
+ height = int(height or image_size)
305
+ width = int(width or image_size)
306
+ if height % patch_size != 0 or width % patch_size != 0:
307
+ raise ValueError(f"height/width must be divisible by patch_size={patch_size}.")
308
+ channels = int(self.transformer.config.in_channels)
309
+ null_class_val = int(getattr(self.transformer.config, "num_classes", 1000))
310
+ if noise_scale is None:
311
+ noise_scale = RECOMMENDED_NOISE_BY_SIZE.get(max(height, width), 1.0)
312
+
313
+ # 3. Class labels
314
+ labels = torch.tensor(class_label_ids, device=self._execution_device, dtype=torch.long).reshape(-1)
315
+ labels = labels.clamp(0, null_class_val - 1)
316
+ cfg_interval = self._cfg_interval(guidance_interval_min, guidance_interval_max, labels.device)
317
+
318
+ # 4. Latents
319
+ latents = randn_tensor(
320
+ (batch_size, channels, height, width),
321
+ generator=generator,
322
+ device=self._execution_device,
323
+ dtype=self.transformer.dtype,
324
+ ) * noise_scale
325
+
326
+ # 5–6. Denoising loop (FD-Loss flow t=1 → 0; generator forwarded to scheduler.step)
327
+ self.scheduler.set_timesteps(num_inference_steps, device=self._execution_device)
328
+ extra_step_kwargs = self.prepare_extra_step_kwargs(self.scheduler, generator=generator)
329
+ timesteps = self.scheduler.timesteps
330
+
331
+ for i in self.progress_bar(range(num_inference_steps)):
332
+ t_cur = timesteps[i]
333
+ velocity = self._predict_velocity(
334
+ latents, t_cur, labels, guidance_scale, cfg_interval, t_eps, interpolate_pos_encoding
335
+ )
336
+ latents = self.scheduler.step(velocity, t_cur, latents, **extra_step_kwargs).prev_sample
337
+
338
+ # 8. Output
339
+ images_pt = ((latents.float().clamp(-1, 1) + 1.0) / 2.0).cpu()
340
+ if output_type == "pt":
341
+ images = images_pt
342
+ elif output_type == "np":
343
+ images = images_pt.permute(0, 2, 3, 1).numpy()
344
+ else:
345
+ images = self.numpy_to_pil(images_pt.permute(0, 2, 3, 1).numpy())
346
+
347
+ self.maybe_free_model_hooks()
348
+ if not return_dict:
349
+ return (images,)
350
+ return ImagePipelineOutput(images=images)
JiT-H-16-SIM/scheduler/__pycache__/scheduling_flow_match_fd.cpython-312.pyc ADDED
Binary file (5.97 kB). View file
 
JiT-H-16-SIM/scheduler/scheduler_config.json ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ {
2
+ "_class_name": "FDLossFlowMatchScheduler",
3
+ "_diffusers_version": "0.36.0",
4
+ "num_train_timesteps": 1000,
5
+ "stochastic_sampling": false
6
+ }
JiT-H-16-SIM/scheduler/scheduling_flow_match_fd.py ADDED
@@ -0,0 +1,110 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright 2026 The FD-Loss Authors. SPDX-License-Identifier: MIT
2
+ """Flow-matching scheduler for FD-Loss JiT sampling (t: 1 -> 0)."""
3
+
4
+ from __future__ import annotations
5
+
6
+ from dataclasses import dataclass
7
+ from typing import List, Optional, Tuple, Union
8
+
9
+ import torch
10
+ from diffusers.configuration_utils import ConfigMixin, register_to_config
11
+ from diffusers.schedulers.scheduling_utils import SchedulerMixin
12
+ from diffusers.utils import BaseOutput
13
+ from diffusers.utils.torch_utils import randn_tensor
14
+
15
+
16
+ @dataclass
17
+ class FDLossFlowMatchSchedulerOutput(BaseOutput):
18
+ prev_sample: torch.Tensor
19
+
20
+
21
+ class FDLossFlowMatchScheduler(SchedulerMixin, ConfigMixin):
22
+ """Euler flow-matching scheduler with optional stochastic steps and generator-aware noise."""
23
+
24
+ order = 1
25
+ config_name = "scheduler_config.json"
26
+
27
+ @register_to_config
28
+ def __init__(
29
+ self,
30
+ num_train_timesteps: int = 1000,
31
+ stochastic_sampling: bool = False,
32
+ ):
33
+ self.timesteps: Optional[torch.Tensor] = None
34
+ self.num_inference_steps: Optional[int] = None
35
+ self._step_index: Optional[int] = None
36
+
37
+ @property
38
+ def init_noise_sigma(self) -> float:
39
+ return 1.0
40
+
41
+ def set_timesteps(self, num_inference_steps: int, device: Union[str, torch.device, None] = None) -> torch.Tensor:
42
+ if num_inference_steps < 1:
43
+ raise ValueError("num_inference_steps must be >= 1.")
44
+ self.num_inference_steps = num_inference_steps
45
+ self.timesteps = torch.linspace(1.0, 0.0, num_inference_steps + 1, device=device, dtype=torch.float32)
46
+ self._step_index = 0
47
+ return self.timesteps
48
+
49
+ def scale_model_input(self, sample: torch.Tensor, timestep: Union[float, torch.Tensor]) -> torch.Tensor:
50
+ del timestep
51
+ return sample
52
+
53
+ def _resolve_step_index(self, timestep: Union[float, torch.Tensor, None]) -> int:
54
+ if self._step_index is not None:
55
+ return self._step_index
56
+ if self.timesteps is None:
57
+ raise ValueError("Call `set_timesteps` before `step`.")
58
+ if timestep is None:
59
+ return 0
60
+ t_value = float(timestep) if not isinstance(timestep, torch.Tensor) else float(timestep.reshape(-1)[0])
61
+ matches = (self.timesteps - t_value).abs() < 1e-6
62
+ if matches.any():
63
+ return int(matches.nonzero(as_tuple=False)[0].item())
64
+ return 0
65
+
66
+ @staticmethod
67
+ def _expand_time(value: torch.Tensor, sample: torch.Tensor) -> torch.Tensor:
68
+ value = value.to(dtype=sample.dtype, device=sample.device)
69
+ while value.ndim < sample.ndim:
70
+ value = value.unsqueeze(-1)
71
+ return value
72
+
73
+ def step(
74
+ self,
75
+ model_output: torch.Tensor,
76
+ timestep: Union[float, torch.Tensor, None],
77
+ sample: torch.Tensor,
78
+ return_dict: bool = True,
79
+ generator: Optional[Union[torch.Generator, List[torch.Generator]]] = None,
80
+ ) -> Union[FDLossFlowMatchSchedulerOutput, Tuple[torch.Tensor]]:
81
+ if self.timesteps is None:
82
+ raise ValueError("Call `set_timesteps` before `step`.")
83
+
84
+ step_index = self._resolve_step_index(timestep)
85
+ if step_index >= len(self.timesteps) - 1:
86
+ raise ValueError("Scheduler has already reached the final timestep.")
87
+
88
+ t = self.timesteps[step_index]
89
+ t_next = self.timesteps[step_index + 1]
90
+ dt = self._expand_time(t - t_next, sample)
91
+
92
+ if self.config.stochastic_sampling:
93
+ t_expanded = self._expand_time(t, sample)
94
+ t_next_expanded = self._expand_time(t_next, sample)
95
+ x0 = sample - t_expanded * model_output
96
+ noise = randn_tensor(
97
+ sample.shape,
98
+ generator=generator,
99
+ device=sample.device,
100
+ dtype=sample.dtype,
101
+ )
102
+ prev_sample = (1.0 - t_next_expanded) * x0 + t_next_expanded * noise
103
+ else:
104
+ prev_sample = sample - dt * model_output
105
+
106
+ self._step_index = step_index + 1
107
+
108
+ if not return_dict:
109
+ return (prev_sample,)
110
+ return FDLossFlowMatchSchedulerOutput(prev_sample=prev_sample)
JiT-H-16-SIM/transformer/config.json ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "_class_name": "JiTTransformer2DModel",
3
+ "_diffusers_version": "0.36.0",
4
+ "attention_dropout": 0.0,
5
+ "bottleneck_dim": 256,
6
+ "dropout": 0.2,
7
+ "hidden_size": 1280,
8
+ "in_channels": 3,
9
+ "in_context_len": 32,
10
+ "in_context_start": 10,
11
+ "mlp_ratio": 4.0,
12
+ "norm_eps": 1e-06,
13
+ "num_attention_heads": 16,
14
+ "num_classes": 1000,
15
+ "num_layers": 32,
16
+ "patch_size": 16,
17
+ "sample_size": 256
18
+ }
JiT-H-16-SIM/transformer/diffusion_pytorch_model.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:901c710d3f7bc2243288f0e995f924c9d5b7425d2611391c66b75f6c52e94350
3
+ size 3811413928
JiT-H-16-SIM/transformer/jit_transformer_2d.py ADDED
@@ -0,0 +1,559 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ import math
16
+
17
+ import numpy as np
18
+ import torch
19
+ import torch.nn as nn
20
+ import torch.nn.functional as F
21
+
22
+ from diffusers.configuration_utils import ConfigMixin, register_to_config
23
+ from diffusers.models.modeling_outputs import Transformer2DModelOutput
24
+ from diffusers.models.modeling_utils import ModelMixin
25
+ from diffusers.models.normalization import RMSNorm
26
+ from diffusers.utils import logging
27
+
28
+ logger = logging.get_logger(__name__)
29
+
30
+
31
+
32
+ def broadcat(tensors, dim=-1):
33
+ num_tensors = len(tensors)
34
+ shape_lens = {len(t.shape) for t in tensors}
35
+ if len(shape_lens) != 1:
36
+ raise ValueError("tensors must all have the same number of dimensions")
37
+ shape_len = list(shape_lens)[0]
38
+ dim = (dim + shape_len) if dim < 0 else dim
39
+ dims = list(zip(*(list(t.shape) for t in tensors)))
40
+ expandable_dims = [(i, val) for i, val in enumerate(dims) if i != dim]
41
+
42
+ if not all(len(set(t[1])) <= 2 for t in expandable_dims):
43
+ raise ValueError("invalid dimensions for broadcastable concatenation")
44
+
45
+ max_dims = [(t[0], max(t[1])) for t in expandable_dims]
46
+ expanded_dims = [(t[0], (t[1],) * num_tensors) for t in max_dims]
47
+ expanded_dims.insert(dim, (dim, dims[dim]))
48
+ expandable_shapes = list(zip(*(t[1] for t in expanded_dims)))
49
+ tensors = [t[0].expand(*t[1]) for t in zip(tensors, expandable_shapes)]
50
+ return torch.cat(tensors, dim=dim)
51
+
52
+
53
+ def rotate_half(x):
54
+ x = x.view(*x.shape[:-1], x.shape[-1] // 2, 2)
55
+ x1, x2 = x.unbind(dim=-1)
56
+ x = torch.stack((-x2, x1), dim=-1)
57
+ return x.view(*x.shape[:-2], -1)
58
+
59
+
60
+ class JiTRotaryEmbedding(nn.Module):
61
+ def __init__(
62
+ self,
63
+ dim,
64
+ pt_seq_len=16,
65
+ ft_seq_len=None,
66
+ custom_freqs=None,
67
+ theta=10000,
68
+ num_cls_token=0,
69
+ ):
70
+ super().__init__()
71
+ self.dim = dim
72
+ self.pt_seq_len = pt_seq_len
73
+ self.theta = theta
74
+ self.num_cls_token = num_cls_token
75
+ self.custom_freqs = custom_freqs
76
+ if ft_seq_len is None:
77
+ ft_seq_len = pt_seq_len
78
+ self._cached_hw = None
79
+ cos, sin = self._build_freqs(ft_seq_len, ft_seq_len, device=torch.device("cpu"))
80
+ self.register_buffer("freqs_cos", cos, persistent=False)
81
+ self.register_buffer("freqs_sin", sin, persistent=False)
82
+ self._cached_hw = (ft_seq_len, ft_seq_len)
83
+
84
+ def _build_freqs(self, height, width, device):
85
+ if self.custom_freqs is not None:
86
+ freqs = self.custom_freqs.to(device=device, dtype=torch.float32)
87
+ else:
88
+ freqs = 1.0 / (
89
+ self.theta ** (torch.arange(0, self.dim, 2, device=device, dtype=torch.float32)[: (self.dim // 2)] / self.dim)
90
+ )
91
+
92
+ t_h = torch.arange(height, device=device, dtype=torch.float32) / height * self.pt_seq_len
93
+ t_w = torch.arange(width, device=device, dtype=torch.float32) / width * self.pt_seq_len
94
+ freqs_h = torch.einsum("..., f -> ... f", t_h, freqs).repeat_interleave(2, dim=-1)
95
+ freqs_w = torch.einsum("..., f -> ... f", t_w, freqs).repeat_interleave(2, dim=-1)
96
+ freqs_2d = broadcat((freqs_h[:, None, :], freqs_w[None, :, :]), dim=-1)
97
+ freqs_flat = freqs_2d.view(-1, freqs_2d.shape[-1])
98
+ cos_img = freqs_flat.cos()
99
+ sin_img = freqs_flat.sin()
100
+ if self.num_cls_token > 0:
101
+ _, dim_freq = cos_img.shape
102
+ cos_pad = torch.ones(self.num_cls_token, dim_freq, dtype=cos_img.dtype, device=device)
103
+ sin_pad = torch.zeros(self.num_cls_token, dim_freq, dtype=sin_img.dtype, device=device)
104
+ cos_img = torch.cat([cos_pad, cos_img], dim=0)
105
+ sin_img = torch.cat([sin_pad, sin_img], dim=0)
106
+ return cos_img, sin_img
107
+
108
+ def forward(self, t, height=None, width=None):
109
+ # Applied on (batch, seq_len, heads, head_dim) tensors from attention.
110
+ seq_len = t.shape[1]
111
+ if height is None or width is None:
112
+ image_tokens = seq_len - self.num_cls_token
113
+ size = int(image_tokens**0.5)
114
+ if size * size != image_tokens:
115
+ raise ValueError(
116
+ f"Cannot infer square token grid from sequence length {seq_len} with {self.num_cls_token} class tokens."
117
+ )
118
+ height = size
119
+ width = size
120
+ if self._cached_hw != (height, width) or self.freqs_cos.device != t.device:
121
+ self.freqs_cos, self.freqs_sin = self._build_freqs(height, width, device=t.device)
122
+ self._cached_hw = (height, width)
123
+ freqs_cos = self.freqs_cos[:seq_len].to(t.dtype)
124
+ freqs_sin = self.freqs_sin[:seq_len].to(t.dtype)
125
+
126
+ return t * freqs_cos[:, None, :] + rotate_half(t) * freqs_sin[:, None, :]
127
+
128
+
129
+ def modulate(x, shift, scale):
130
+ return x * (1 + scale.unsqueeze(1)) + shift.unsqueeze(1)
131
+
132
+
133
+ class JiTPatchEmbed(nn.Module):
134
+ """Image to Patch Embedding with Bottleneck"""
135
+
136
+ def __init__(self, img_size=224, patch_size=16, in_chans=3, pca_dim=768, embed_dim=768, bias=True):
137
+ super().__init__()
138
+ img_size = (img_size, img_size)
139
+ patch_size = (patch_size, patch_size)
140
+ self.img_size = img_size
141
+ self.patch_size = patch_size
142
+ self.num_patches = (img_size[1] // patch_size[1]) * (img_size[0] // patch_size[0])
143
+
144
+ self.proj1 = nn.Conv2d(in_chans, pca_dim, kernel_size=patch_size, stride=patch_size, bias=False)
145
+ self.proj2 = nn.Conv2d(pca_dim, embed_dim, kernel_size=1, stride=1, bias=bias)
146
+
147
+ def forward(self, x):
148
+ x = self.proj2(self.proj1(x)).flatten(2).transpose(1, 2)
149
+ return x
150
+
151
+
152
+ class JiTTimestepEmbedder(nn.Module):
153
+ """
154
+ Embeds scalar timesteps into vector representations.
155
+ """
156
+
157
+ def __init__(self, hidden_size, frequency_embedding_size=256):
158
+ super().__init__()
159
+ self.mlp = nn.Sequential(
160
+ nn.Linear(frequency_embedding_size, hidden_size, bias=True),
161
+ nn.SiLU(),
162
+ nn.Linear(hidden_size, hidden_size, bias=True),
163
+ )
164
+ self.frequency_embedding_size = frequency_embedding_size
165
+
166
+ @staticmethod
167
+ def timestep_embedding(t, dim, max_period=10000):
168
+ """
169
+ Create sinusoidal timestep embeddings.
170
+ """
171
+ half = dim // 2
172
+ freqs = torch.exp(
173
+ -math.log(max_period) * torch.arange(start=0, end=half, dtype=torch.float32) / half
174
+ ).to(device=t.device)
175
+ args = t[:, None].float() * freqs[None]
176
+ embedding = torch.cat([torch.cos(args), torch.sin(args)], dim=-1)
177
+ if dim % 2:
178
+ embedding = torch.cat([embedding, torch.zeros_like(embedding[:, :1])], dim=-1)
179
+ return embedding
180
+
181
+ def forward(self, t, dtype=None):
182
+ t_freq = self.timestep_embedding(t, self.frequency_embedding_size)
183
+ if dtype is not None:
184
+ t_freq = t_freq.to(dtype=dtype)
185
+ t_emb = self.mlp(t_freq)
186
+ return t_emb
187
+
188
+
189
+ class JiTLabelEmbedder(nn.Module):
190
+ """
191
+ Embeds class labels into vector representations.
192
+ """
193
+
194
+ def __init__(self, num_classes, hidden_size):
195
+ super().__init__()
196
+ self.embedding_table = nn.Embedding(num_classes + 1, hidden_size)
197
+ self.num_classes = num_classes
198
+
199
+ def forward(self, labels):
200
+ embeddings = self.embedding_table(labels)
201
+ return embeddings
202
+
203
+
204
+ class JiTAttention(nn.Module):
205
+ def __init__(self, dim, num_heads=8, qkv_bias=True, qk_norm=True, attn_drop=0.0, proj_drop=0.0, eps=1e-6):
206
+ super().__init__()
207
+ self.num_heads = num_heads
208
+ head_dim = dim // num_heads
209
+
210
+ self.q_norm = RMSNorm(head_dim, eps=eps) if qk_norm else nn.Identity()
211
+ self.k_norm = RMSNorm(head_dim, eps=eps) if qk_norm else nn.Identity()
212
+
213
+ self.qkv = nn.Linear(dim, dim * 3, bias=qkv_bias)
214
+ self.attn_drop = attn_drop
215
+ self.proj = nn.Linear(dim, dim)
216
+ self.proj_drop = nn.Dropout(proj_drop)
217
+
218
+ def forward(self, x, rope=None, grid_height=None, grid_width=None):
219
+ B, N, C = x.shape
220
+ qkv = self.qkv(x).reshape(B, N, 3, self.num_heads, C // self.num_heads).permute(2, 0, 3, 1, 4)
221
+ q, k, v = qkv[0], qkv[1], qkv[2]
222
+
223
+ q = self.q_norm(q)
224
+ k = self.k_norm(k)
225
+
226
+ if rope is not None:
227
+ q = q.transpose(1, 2)
228
+ k = k.transpose(1, 2)
229
+ q = rope(q, height=grid_height, width=grid_width)
230
+ k = rope(k, height=grid_height, width=grid_width)
231
+ q = q.transpose(1, 2)
232
+ k = k.transpose(1, 2)
233
+
234
+ dropout_p = self.attn_drop if self.training else 0.0
235
+ x = F.scaled_dot_product_attention(q, k, v, dropout_p=dropout_p)
236
+ x = x.transpose(1, 2).reshape(B, N, C)
237
+ x = self.proj(x)
238
+ x = self.proj_drop(x)
239
+ return x
240
+
241
+
242
+ class JiTSwiGLUFFN(nn.Module):
243
+ def __init__(self, dim: int, hidden_dim: int, drop=0.0, bias=True) -> None:
244
+ super().__init__()
245
+ hidden_dim = int(hidden_dim * 2 / 3)
246
+ self.w12 = nn.Linear(dim, 2 * hidden_dim, bias=bias)
247
+ self.w3 = nn.Linear(hidden_dim, dim, bias=bias)
248
+ self.ffn_dropout = nn.Dropout(drop)
249
+
250
+ def forward(self, x):
251
+ x12 = self.w12(x)
252
+ x1, x2 = x12.chunk(2, dim=-1)
253
+ hidden = F.silu(x1) * x2
254
+ return self.w3(self.ffn_dropout(hidden))
255
+
256
+
257
+ class JiTBlock(nn.Module):
258
+ def __init__(self, hidden_size, num_heads, mlp_ratio=4.0, attn_drop=0.0, proj_drop=0.0, eps=1e-6):
259
+ super().__init__()
260
+ self.norm1 = RMSNorm(hidden_size, eps=eps)
261
+ self.attn = JiTAttention(
262
+ hidden_size,
263
+ num_heads=num_heads,
264
+ qkv_bias=True,
265
+ qk_norm=True,
266
+ attn_drop=attn_drop,
267
+ proj_drop=proj_drop,
268
+ eps=eps,
269
+ )
270
+ self.norm2 = RMSNorm(hidden_size, eps=eps)
271
+ mlp_hidden_dim = int(hidden_size * mlp_ratio)
272
+ self.mlp = JiTSwiGLUFFN(hidden_size, mlp_hidden_dim, drop=proj_drop)
273
+
274
+ self.act = nn.SiLU()
275
+ self.adaLN_modulation = nn.Linear(hidden_size, 6 * hidden_size, bias=True)
276
+
277
+ def forward(self, x, c, feat_rope=None, grid_height=None, grid_width=None):
278
+ # Apply activation
279
+ c = self.act(c)
280
+
281
+ shift_msa, scale_msa, gate_msa, shift_mlp, scale_mlp, gate_mlp = self.adaLN_modulation(c).chunk(6, dim=-1)
282
+
283
+ # Attention block
284
+ norm_x = self.norm1(x)
285
+ modulated_x = modulate(norm_x, shift_msa, scale_msa)
286
+ attn_out = self.attn(modulated_x, rope=feat_rope, grid_height=grid_height, grid_width=grid_width)
287
+ x = x + gate_msa.unsqueeze(1) * attn_out
288
+
289
+ # MLP block
290
+ norm_x = self.norm2(x)
291
+ modulated_x = modulate(norm_x, shift_mlp, scale_mlp)
292
+ mlp_out = self.mlp(modulated_x)
293
+ x = x + gate_mlp.unsqueeze(1) * mlp_out
294
+
295
+ return x
296
+
297
+
298
+ def get_2d_sincos_pos_embed(embed_dim, grid_size, cls_token=False, extra_tokens=0):
299
+ grid_h = np.arange(grid_size, dtype=np.float32)
300
+ grid_w = np.arange(grid_size, dtype=np.float32)
301
+ grid = np.meshgrid(grid_w, grid_h)
302
+ grid = np.stack(grid, axis=0)
303
+ grid = grid.reshape([2, 1, grid_size, grid_size])
304
+ pos_embed = get_2d_sincos_pos_embed_from_grid(embed_dim, grid)
305
+ if cls_token and extra_tokens > 0:
306
+ pos_embed = np.concatenate([np.zeros([extra_tokens, embed_dim]), pos_embed], axis=0)
307
+ return pos_embed
308
+
309
+
310
+ def get_2d_sincos_pos_embed_from_grid(embed_dim, grid):
311
+ if embed_dim % 2 != 0:
312
+ raise ValueError(f"embed_dim must be divisible by 2, but got {embed_dim}")
313
+
314
+ emb_h = get_1d_sincos_pos_embed_from_grid(embed_dim // 2, grid[0])
315
+ emb_w = get_1d_sincos_pos_embed_from_grid(embed_dim // 2, grid[1])
316
+ emb = np.concatenate([emb_h, emb_w], axis=1)
317
+ return emb
318
+
319
+
320
+ def get_1d_sincos_pos_embed_from_grid(embed_dim, pos):
321
+ if embed_dim % 2 != 0:
322
+ raise ValueError(f"embed_dim must be divisible by 2, but got {embed_dim}")
323
+
324
+ omega = np.arange(embed_dim // 2, dtype=np.float64)
325
+ omega /= embed_dim / 2.0
326
+ omega = 1.0 / 10000**omega
327
+
328
+ pos = pos.reshape(-1)
329
+ out = np.einsum("m,d->md", pos, omega)
330
+
331
+ emb_sin = np.sin(out)
332
+ emb_cos = np.cos(out)
333
+
334
+ emb = np.concatenate([emb_sin, emb_cos], axis=1)
335
+ return emb
336
+
337
+
338
+ class JiTTransformer2DModel(ModelMixin, ConfigMixin):
339
+ r"""
340
+ A 2D Transformer for pixel-space class-conditional generation with JiT
341
+ ([Back to Basics: Let Denoising Generative Models Denoise](https://arxiv.org/abs/2511.13720)).
342
+
343
+ Parameters:
344
+ sample_size (`int`, defaults to `256`):
345
+ Input image resolution (height and width).
346
+ patch_size (`int`, defaults to `16`):
347
+ Patch size for the bottleneck patch embedder.
348
+ in_channels (`int`, defaults to `3`):
349
+ Number of input image channels.
350
+ hidden_size (`int`, defaults to `768`):
351
+ Transformer hidden dimension.
352
+ num_layers (`int`, defaults to `12`):
353
+ Number of JiT transformer blocks.
354
+ num_attention_heads (`int`, defaults to `12`):
355
+ Number of attention heads per block.
356
+ mlp_ratio (`float`, defaults to `4.0`):
357
+ MLP hidden dimension multiplier.
358
+ attention_dropout (`float`, defaults to `0.0`):
359
+ Attention dropout in the middle quarter of blocks.
360
+ dropout (`float`, defaults to `0.0`):
361
+ Projection dropout in the middle quarter of blocks.
362
+ num_classes (`int`, defaults to `1000`):
363
+ Number of class labels (null label uses index `num_classes` for CFG).
364
+ bottleneck_dim (`int`, defaults to `128`):
365
+ PCA bottleneck dimension in the patch embedder.
366
+ in_context_len (`int`, defaults to `32`):
367
+ Number of in-context class tokens prepended mid-network.
368
+ in_context_start (`int`, defaults to `4`):
369
+ Block index at which in-context tokens are inserted.
370
+ norm_eps (`float`, defaults to `1e-6`):
371
+ Epsilon for RMSNorm layers.
372
+ """
373
+
374
+ _supports_gradient_checkpointing = True
375
+ _skip_layerwise_casting_patterns = ["pos_embed", "norm"]
376
+
377
+ @register_to_config
378
+ def __init__(
379
+ self,
380
+ sample_size: int = 256,
381
+ patch_size: int = 16,
382
+ in_channels: int = 3,
383
+ hidden_size: int = 768,
384
+ num_layers: int = 12,
385
+ num_attention_heads: int = 12,
386
+ mlp_ratio: float = 4.0,
387
+ attention_dropout: float = 0.0,
388
+ dropout: float = 0.0,
389
+ num_classes: int = 1000,
390
+ bottleneck_dim: int = 128,
391
+ in_context_len: int = 32,
392
+ in_context_start: int = 4,
393
+ norm_eps: float = 1e-6,
394
+ ):
395
+ super().__init__()
396
+ self.sample_size = sample_size
397
+ self.patch_size = patch_size
398
+ self.in_channels = in_channels
399
+ self.out_channels = in_channels
400
+ self.hidden_size = hidden_size
401
+ self.num_layers = num_layers
402
+ self.num_attention_heads = num_attention_heads
403
+ self.in_context_len = in_context_len
404
+ self.in_context_start = in_context_start
405
+ self.norm_eps = norm_eps
406
+ self.gradient_checkpointing = False
407
+
408
+ # Time and Class Embedding
409
+ self.t_embedder = JiTTimestepEmbedder(hidden_size)
410
+ self.y_embedder = JiTLabelEmbedder(num_classes, hidden_size)
411
+
412
+ # Patch Embedding
413
+ self.x_embedder = JiTPatchEmbed(
414
+ img_size=sample_size,
415
+ patch_size=patch_size,
416
+ in_chans=in_channels,
417
+ pca_dim=bottleneck_dim,
418
+ embed_dim=hidden_size,
419
+ bias=True,
420
+ )
421
+
422
+ # Positional Embedding (Fixed Sin-Cos)
423
+ num_patches = self.x_embedder.num_patches
424
+ pos_embed = get_2d_sincos_pos_embed(hidden_size, int(num_patches**0.5))
425
+ self.register_buffer("pos_embed", torch.from_numpy(pos_embed).float().unsqueeze(0), persistent=True)
426
+
427
+ # In-context Embedding
428
+ if self.in_context_len > 0:
429
+ self.in_context_posemb = nn.Parameter(torch.zeros(1, self.in_context_len, hidden_size))
430
+
431
+ # RoPE
432
+ half_head_dim = hidden_size // num_attention_heads // 2
433
+ hw_seq_len = sample_size // patch_size
434
+ self.feat_rope = JiTRotaryEmbedding(dim=half_head_dim, pt_seq_len=hw_seq_len, num_cls_token=0)
435
+ self.feat_rope_incontext = JiTRotaryEmbedding(
436
+ dim=half_head_dim, pt_seq_len=hw_seq_len, num_cls_token=self.in_context_len
437
+ )
438
+
439
+ # Blocks
440
+ self.blocks = nn.ModuleList(
441
+ [
442
+ JiTBlock(
443
+ hidden_size,
444
+ num_attention_heads,
445
+ mlp_ratio=mlp_ratio,
446
+ attn_drop=attention_dropout if (num_layers // 4 * 3 > i >= num_layers // 4) else 0.0,
447
+ proj_drop=dropout if (num_layers // 4 * 3 > i >= num_layers // 4) else 0.0,
448
+ eps=norm_eps,
449
+ )
450
+ for i in range(num_layers)
451
+ ]
452
+ )
453
+
454
+ # Final Layer
455
+ self.norm_final = RMSNorm(hidden_size, eps=norm_eps)
456
+ self.linear_final = nn.Linear(hidden_size, patch_size * patch_size * self.out_channels, bias=True)
457
+ self.act_final = nn.SiLU()
458
+ self.adaLN_modulation_final = nn.Linear(hidden_size, 2 * hidden_size, bias=True)
459
+
460
+ def _get_patch_grid(self, hidden_states):
461
+ height, width = hidden_states.shape[-2:]
462
+ if height % self.patch_size != 0 or width % self.patch_size != 0:
463
+ raise ValueError(
464
+ f"Input size {(height, width)} must be divisible by patch_size={self.patch_size}."
465
+ )
466
+ return height // self.patch_size, width // self.patch_size
467
+
468
+ def _interpolate_pos_encoding(self, tokens, grid_height, grid_width):
469
+ num_tokens = grid_height * grid_width
470
+ if self.pos_embed.shape[1] == num_tokens:
471
+ return self.pos_embed.to(device=tokens.device, dtype=tokens.dtype)
472
+ base_size = int(self.pos_embed.shape[1] ** 0.5)
473
+ pos_embed = self.pos_embed.reshape(1, base_size, base_size, self.hidden_size).permute(0, 3, 1, 2)
474
+ pos_embed = F.interpolate(pos_embed, size=(grid_height, grid_width), mode="bicubic", align_corners=False)
475
+ pos_embed = pos_embed.permute(0, 2, 3, 1).reshape(1, num_tokens, self.hidden_size)
476
+ return pos_embed.to(device=tokens.device, dtype=tokens.dtype)
477
+
478
+ def forward(
479
+ self,
480
+ hidden_states: torch.Tensor,
481
+ timestep: torch.LongTensor,
482
+ class_labels: torch.LongTensor,
483
+ interpolate_pos_encoding: bool = True,
484
+ return_dict: bool = True,
485
+ ):
486
+
487
+ t_emb = self.t_embedder(timestep, dtype=hidden_states.dtype)
488
+ y_emb = self.y_embedder(class_labels)
489
+
490
+ # Ensure embeddings match hidden_states dtype
491
+ y_emb = y_emb.to(dtype=hidden_states.dtype)
492
+
493
+ c = t_emb + y_emb
494
+
495
+ # Patch Embed
496
+ grid_height, grid_width = self._get_patch_grid(hidden_states)
497
+ x = self.x_embedder(hidden_states)
498
+ if interpolate_pos_encoding:
499
+ pos_embed = self._interpolate_pos_encoding(x, grid_height, grid_width)
500
+ else:
501
+ expected_tokens = grid_height * grid_width
502
+ if self.pos_embed.shape[1] != expected_tokens:
503
+ raise ValueError(
504
+ f"pos_embed token count {self.pos_embed.shape[1]} does not match input token count {expected_tokens}. "
505
+ "Enable interpolate_pos_encoding for dynamic resolutions."
506
+ )
507
+ pos_embed = self.pos_embed.to(device=x.device, dtype=x.dtype)
508
+ x = x + pos_embed
509
+
510
+ # Blocks
511
+ for i, block in enumerate(self.blocks):
512
+ if self.in_context_len > 0 and i == self.in_context_start:
513
+ in_context_tokens = y_emb.unsqueeze(1).repeat(1, self.in_context_len, 1)
514
+ in_context_tokens = in_context_tokens + self.in_context_posemb.to(in_context_tokens.dtype)
515
+ x = torch.cat([in_context_tokens, x], dim=1)
516
+
517
+ rope = self.feat_rope if i < self.in_context_start else self.feat_rope_incontext
518
+
519
+ if self.training and self.gradient_checkpointing:
520
+ def custom_forward(current_x, current_c):
521
+ return block(
522
+ current_x,
523
+ current_c,
524
+ feat_rope=rope,
525
+ grid_height=grid_height,
526
+ grid_width=grid_width,
527
+ )
528
+
529
+ x = torch.utils.checkpoint.checkpoint(
530
+ custom_forward,
531
+ x,
532
+ c,
533
+ use_reentrant=False,
534
+ )
535
+ else:
536
+ x = block(x, c, feat_rope=rope, grid_height=grid_height, grid_width=grid_width)
537
+
538
+ # Slice off in-context tokens
539
+ if self.in_context_len > 0:
540
+ x = x[:, self.in_context_len :]
541
+
542
+ # Final Layer
543
+ c = self.act_final(c)
544
+ shift, scale = self.adaLN_modulation_final(c).chunk(2, dim=1)
545
+
546
+ x = modulate(self.norm_final(x), shift, scale)
547
+ x = self.linear_final(x)
548
+
549
+ # Unpatchify
550
+ x = x.reshape(shape=(x.shape[0], grid_height, grid_width, self.patch_size, self.patch_size, self.out_channels))
551
+ x = torch.einsum("nhwpqc->nchpwq", x)
552
+ output = x.reshape(
553
+ shape=(x.shape[0], self.out_channels, grid_height * self.patch_size, grid_width * self.patch_size)
554
+ )
555
+
556
+ if not return_dict:
557
+ return (output,)
558
+
559
+ return Transformer2DModelOutput(sample=output)
JiT-L-16-SIM/model_index.json ADDED
@@ -0,0 +1,1017 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "_class_name": [
3
+ "pipeline",
4
+ "JiTPipeline"
5
+ ],
6
+ "_diffusers_version": "0.36.0",
7
+ "scheduler": [
8
+ "scheduling_flow_match_fd",
9
+ "FDLossFlowMatchScheduler"
10
+ ],
11
+ "transformer": [
12
+ "jit_transformer_2d",
13
+ "JiTTransformer2DModel"
14
+ ],
15
+ "id2label": {
16
+ "0": "tench, Tinca tinca",
17
+ "1": "goldfish, Carassius auratus",
18
+ "2": "great white shark, white shark, man-eater, man-eating shark, Carcharodon carcharias",
19
+ "3": "tiger shark, Galeocerdo cuvieri",
20
+ "4": "hammerhead, hammerhead shark",
21
+ "5": "electric ray, crampfish, numbfish, torpedo",
22
+ "6": "stingray",
23
+ "7": "cock",
24
+ "8": "hen",
25
+ "9": "ostrich, Struthio camelus",
26
+ "10": "brambling, Fringilla montifringilla",
27
+ "11": "goldfinch, Carduelis carduelis",
28
+ "12": "house finch, linnet, Carpodacus mexicanus",
29
+ "13": "junco, snowbird",
30
+ "14": "indigo bunting, indigo finch, indigo bird, Passerina cyanea",
31
+ "15": "robin, American robin, Turdus migratorius",
32
+ "16": "bulbul",
33
+ "17": "jay",
34
+ "18": "magpie",
35
+ "19": "chickadee",
36
+ "20": "water ouzel, dipper",
37
+ "21": "kite",
38
+ "22": "bald eagle, American eagle, Haliaeetus leucocephalus",
39
+ "23": "vulture",
40
+ "24": "great grey owl, great gray owl, Strix nebulosa",
41
+ "25": "European fire salamander, Salamandra salamandra",
42
+ "26": "common newt, Triturus vulgaris",
43
+ "27": "eft",
44
+ "28": "spotted salamander, Ambystoma maculatum",
45
+ "29": "axolotl, mud puppy, Ambystoma mexicanum",
46
+ "30": "bullfrog, Rana catesbeiana",
47
+ "31": "tree frog, tree-frog",
48
+ "32": "tailed frog, bell toad, ribbed toad, tailed toad, Ascaphus trui",
49
+ "33": "loggerhead, loggerhead turtle, Caretta caretta",
50
+ "34": "leatherback turtle, leatherback, leathery turtle, Dermochelys coriacea",
51
+ "35": "mud turtle",
52
+ "36": "terrapin",
53
+ "37": "box turtle, box tortoise",
54
+ "38": "banded gecko",
55
+ "39": "common iguana, iguana, Iguana iguana",
56
+ "40": "American chameleon, anole, Anolis carolinensis",
57
+ "41": "whiptail, whiptail lizard",
58
+ "42": "agama",
59
+ "43": "frilled lizard, Chlamydosaurus kingi",
60
+ "44": "alligator lizard",
61
+ "45": "Gila monster, Heloderma suspectum",
62
+ "46": "green lizard, Lacerta viridis",
63
+ "47": "African chameleon, Chamaeleo chamaeleon",
64
+ "48": "Komodo dragon, Komodo lizard, dragon lizard, giant lizard, Varanus komodoensis",
65
+ "49": "African crocodile, Nile crocodile, Crocodylus niloticus",
66
+ "50": "American alligator, Alligator mississipiensis",
67
+ "51": "triceratops",
68
+ "52": "thunder snake, worm snake, Carphophis amoenus",
69
+ "53": "ringneck snake, ring-necked snake, ring snake",
70
+ "54": "hognose snake, puff adder, sand viper",
71
+ "55": "green snake, grass snake",
72
+ "56": "king snake, kingsnake",
73
+ "57": "garter snake, grass snake",
74
+ "58": "water snake",
75
+ "59": "vine snake",
76
+ "60": "night snake, Hypsiglena torquata",
77
+ "61": "boa constrictor, Constrictor constrictor",
78
+ "62": "rock python, rock snake, Python sebae",
79
+ "63": "Indian cobra, Naja naja",
80
+ "64": "green mamba",
81
+ "65": "sea snake",
82
+ "66": "horned viper, cerastes, sand viper, horned asp, Cerastes cornutus",
83
+ "67": "diamondback, diamondback rattlesnake, Crotalus adamanteus",
84
+ "68": "sidewinder, horned rattlesnake, Crotalus cerastes",
85
+ "69": "trilobite",
86
+ "70": "harvestman, daddy longlegs, Phalangium opilio",
87
+ "71": "scorpion",
88
+ "72": "black and gold garden spider, Argiope aurantia",
89
+ "73": "barn spider, Araneus cavaticus",
90
+ "74": "garden spider, Aranea diademata",
91
+ "75": "black widow, Latrodectus mactans",
92
+ "76": "tarantula",
93
+ "77": "wolf spider, hunting spider",
94
+ "78": "tick",
95
+ "79": "centipede",
96
+ "80": "black grouse",
97
+ "81": "ptarmigan",
98
+ "82": "ruffed grouse, partridge, Bonasa umbellus",
99
+ "83": "prairie chicken, prairie grouse, prairie fowl",
100
+ "84": "peacock",
101
+ "85": "quail",
102
+ "86": "partridge",
103
+ "87": "African grey, African gray, Psittacus erithacus",
104
+ "88": "macaw",
105
+ "89": "sulphur-crested cockatoo, Kakatoe galerita, Cacatua galerita",
106
+ "90": "lorikeet",
107
+ "91": "coucal",
108
+ "92": "bee eater",
109
+ "93": "hornbill",
110
+ "94": "hummingbird",
111
+ "95": "jacamar",
112
+ "96": "toucan",
113
+ "97": "drake",
114
+ "98": "red-breasted merganser, Mergus serrator",
115
+ "99": "goose",
116
+ "100": "black swan, Cygnus atratus",
117
+ "101": "tusker",
118
+ "102": "echidna, spiny anteater, anteater",
119
+ "103": "platypus, duckbill, duckbilled platypus, duck-billed platypus, Ornithorhynchus anatinus",
120
+ "104": "wallaby, brush kangaroo",
121
+ "105": "koala, koala bear, kangaroo bear, native bear, Phascolarctos cinereus",
122
+ "106": "wombat",
123
+ "107": "jellyfish",
124
+ "108": "sea anemone, anemone",
125
+ "109": "brain coral",
126
+ "110": "flatworm, platyhelminth",
127
+ "111": "nematode, nematode worm, roundworm",
128
+ "112": "conch",
129
+ "113": "snail",
130
+ "114": "slug",
131
+ "115": "sea slug, nudibranch",
132
+ "116": "chiton, coat-of-mail shell, sea cradle, polyplacophore",
133
+ "117": "chambered nautilus, pearly nautilus, nautilus",
134
+ "118": "Dungeness crab, Cancer magister",
135
+ "119": "rock crab, Cancer irroratus",
136
+ "120": "fiddler crab",
137
+ "121": "king crab, Alaska crab, Alaskan king crab, Alaska king crab, Paralithodes camtschatica",
138
+ "122": "American lobster, Northern lobster, Maine lobster, Homarus americanus",
139
+ "123": "spiny lobster, langouste, rock lobster, crawfish, crayfish, sea crawfish",
140
+ "124": "crayfish, crawfish, crawdad, crawdaddy",
141
+ "125": "hermit crab",
142
+ "126": "isopod",
143
+ "127": "white stork, Ciconia ciconia",
144
+ "128": "black stork, Ciconia nigra",
145
+ "129": "spoonbill",
146
+ "130": "flamingo",
147
+ "131": "little blue heron, Egretta caerulea",
148
+ "132": "American egret, great white heron, Egretta albus",
149
+ "133": "bittern",
150
+ "134": "crane",
151
+ "135": "limpkin, Aramus pictus",
152
+ "136": "European gallinule, Porphyrio porphyrio",
153
+ "137": "American coot, marsh hen, mud hen, water hen, Fulica americana",
154
+ "138": "bustard",
155
+ "139": "ruddy turnstone, Arenaria interpres",
156
+ "140": "red-backed sandpiper, dunlin, Erolia alpina",
157
+ "141": "redshank, Tringa totanus",
158
+ "142": "dowitcher",
159
+ "143": "oystercatcher, oyster catcher",
160
+ "144": "pelican",
161
+ "145": "king penguin, Aptenodytes patagonica",
162
+ "146": "albatross, mollymawk",
163
+ "147": "grey whale, gray whale, devilfish, Eschrichtius gibbosus, Eschrichtius robustus",
164
+ "148": "killer whale, killer, orca, grampus, sea wolf, Orcinus orca",
165
+ "149": "dugong, Dugong dugon",
166
+ "150": "sea lion",
167
+ "151": "Chihuahua",
168
+ "152": "Japanese spaniel",
169
+ "153": "Maltese dog, Maltese terrier, Maltese",
170
+ "154": "Pekinese, Pekingese, Peke",
171
+ "155": "Shih-Tzu",
172
+ "156": "Blenheim spaniel",
173
+ "157": "papillon",
174
+ "158": "toy terrier",
175
+ "159": "Rhodesian ridgeback",
176
+ "160": "Afghan hound, Afghan",
177
+ "161": "basset, basset hound",
178
+ "162": "beagle",
179
+ "163": "bloodhound, sleuthhound",
180
+ "164": "bluetick",
181
+ "165": "black-and-tan coonhound",
182
+ "166": "Walker hound, Walker foxhound",
183
+ "167": "English foxhound",
184
+ "168": "redbone",
185
+ "169": "borzoi, Russian wolfhound",
186
+ "170": "Irish wolfhound",
187
+ "171": "Italian greyhound",
188
+ "172": "whippet",
189
+ "173": "Ibizan hound, Ibizan Podenco",
190
+ "174": "Norwegian elkhound, elkhound",
191
+ "175": "otterhound, otter hound",
192
+ "176": "Saluki, gazelle hound",
193
+ "177": "Scottish deerhound, deerhound",
194
+ "178": "Weimaraner",
195
+ "179": "Staffordshire bullterrier, Staffordshire bull terrier",
196
+ "180": "American Staffordshire terrier, Staffordshire terrier, American pit bull terrier, pit bull terrier",
197
+ "181": "Bedlington terrier",
198
+ "182": "Border terrier",
199
+ "183": "Kerry blue terrier",
200
+ "184": "Irish terrier",
201
+ "185": "Norfolk terrier",
202
+ "186": "Norwich terrier",
203
+ "187": "Yorkshire terrier",
204
+ "188": "wire-haired fox terrier",
205
+ "189": "Lakeland terrier",
206
+ "190": "Sealyham terrier, Sealyham",
207
+ "191": "Airedale, Airedale terrier",
208
+ "192": "cairn, cairn terrier",
209
+ "193": "Australian terrier",
210
+ "194": "Dandie Dinmont, Dandie Dinmont terrier",
211
+ "195": "Boston bull, Boston terrier",
212
+ "196": "miniature schnauzer",
213
+ "197": "giant schnauzer",
214
+ "198": "standard schnauzer",
215
+ "199": "Scotch terrier, Scottish terrier, Scottie",
216
+ "200": "Tibetan terrier, chrysanthemum dog",
217
+ "201": "silky terrier, Sydney silky",
218
+ "202": "soft-coated wheaten terrier",
219
+ "203": "West Highland white terrier",
220
+ "204": "Lhasa, Lhasa apso",
221
+ "205": "flat-coated retriever",
222
+ "206": "curly-coated retriever",
223
+ "207": "golden retriever",
224
+ "208": "Labrador retriever",
225
+ "209": "Chesapeake Bay retriever",
226
+ "210": "German short-haired pointer",
227
+ "211": "vizsla, Hungarian pointer",
228
+ "212": "English setter",
229
+ "213": "Irish setter, red setter",
230
+ "214": "Gordon setter",
231
+ "215": "Brittany spaniel",
232
+ "216": "clumber, clumber spaniel",
233
+ "217": "English springer, English springer spaniel",
234
+ "218": "Welsh springer spaniel",
235
+ "219": "cocker spaniel, English cocker spaniel, cocker",
236
+ "220": "Sussex spaniel",
237
+ "221": "Irish water spaniel",
238
+ "222": "kuvasz",
239
+ "223": "schipperke",
240
+ "224": "groenendael",
241
+ "225": "malinois",
242
+ "226": "briard",
243
+ "227": "kelpie",
244
+ "228": "komondor",
245
+ "229": "Old English sheepdog, bobtail",
246
+ "230": "Shetland sheepdog, Shetland sheep dog, Shetland",
247
+ "231": "collie",
248
+ "232": "Border collie",
249
+ "233": "Bouvier des Flandres, Bouviers des Flandres",
250
+ "234": "Rottweiler",
251
+ "235": "German shepherd, German shepherd dog, German police dog, alsatian",
252
+ "236": "Doberman, Doberman pinscher",
253
+ "237": "miniature pinscher",
254
+ "238": "Greater Swiss Mountain dog",
255
+ "239": "Bernese mountain dog",
256
+ "240": "Appenzeller",
257
+ "241": "EntleBucher",
258
+ "242": "boxer",
259
+ "243": "bull mastiff",
260
+ "244": "Tibetan mastiff",
261
+ "245": "French bulldog",
262
+ "246": "Great Dane",
263
+ "247": "Saint Bernard, St Bernard",
264
+ "248": "Eskimo dog, husky",
265
+ "249": "malamute, malemute, Alaskan malamute",
266
+ "250": "Siberian husky",
267
+ "251": "dalmatian, coach dog, carriage dog",
268
+ "252": "affenpinscher, monkey pinscher, monkey dog",
269
+ "253": "basenji",
270
+ "254": "pug, pug-dog",
271
+ "255": "Leonberg",
272
+ "256": "Newfoundland, Newfoundland dog",
273
+ "257": "Great Pyrenees",
274
+ "258": "Samoyed, Samoyede",
275
+ "259": "Pomeranian",
276
+ "260": "chow, chow chow",
277
+ "261": "keeshond",
278
+ "262": "Brabancon griffon",
279
+ "263": "Pembroke, Pembroke Welsh corgi",
280
+ "264": "Cardigan, Cardigan Welsh corgi",
281
+ "265": "toy poodle",
282
+ "266": "miniature poodle",
283
+ "267": "standard poodle",
284
+ "268": "Mexican hairless",
285
+ "269": "timber wolf, grey wolf, gray wolf, Canis lupus",
286
+ "270": "white wolf, Arctic wolf, Canis lupus tundrarum",
287
+ "271": "red wolf, maned wolf, Canis rufus, Canis niger",
288
+ "272": "coyote, prairie wolf, brush wolf, Canis latrans",
289
+ "273": "dingo, warrigal, warragal, Canis dingo",
290
+ "274": "dhole, Cuon alpinus",
291
+ "275": "African hunting dog, hyena dog, Cape hunting dog, Lycaon pictus",
292
+ "276": "hyena, hyaena",
293
+ "277": "red fox, Vulpes vulpes",
294
+ "278": "kit fox, Vulpes macrotis",
295
+ "279": "Arctic fox, white fox, Alopex lagopus",
296
+ "280": "grey fox, gray fox, Urocyon cinereoargenteus",
297
+ "281": "tabby, tabby cat",
298
+ "282": "tiger cat",
299
+ "283": "Persian cat",
300
+ "284": "Siamese cat, Siamese",
301
+ "285": "Egyptian cat",
302
+ "286": "cougar, puma, catamount, mountain lion, painter, panther, Felis concolor",
303
+ "287": "lynx, catamount",
304
+ "288": "leopard, Panthera pardus",
305
+ "289": "snow leopard, ounce, Panthera uncia",
306
+ "290": "jaguar, panther, Panthera onca, Felis onca",
307
+ "291": "lion, king of beasts, Panthera leo",
308
+ "292": "tiger, Panthera tigris",
309
+ "293": "cheetah, chetah, Acinonyx jubatus",
310
+ "294": "brown bear, bruin, Ursus arctos",
311
+ "295": "American black bear, black bear, Ursus americanus, Euarctos americanus",
312
+ "296": "ice bear, polar bear, Ursus Maritimus, Thalarctos maritimus",
313
+ "297": "sloth bear, Melursus ursinus, Ursus ursinus",
314
+ "298": "mongoose",
315
+ "299": "meerkat, mierkat",
316
+ "300": "tiger beetle",
317
+ "301": "ladybug, ladybeetle, lady beetle, ladybird, ladybird beetle",
318
+ "302": "ground beetle, carabid beetle",
319
+ "303": "long-horned beetle, longicorn, longicorn beetle",
320
+ "304": "leaf beetle, chrysomelid",
321
+ "305": "dung beetle",
322
+ "306": "rhinoceros beetle",
323
+ "307": "weevil",
324
+ "308": "fly",
325
+ "309": "bee",
326
+ "310": "ant, emmet, pismire",
327
+ "311": "grasshopper, hopper",
328
+ "312": "cricket",
329
+ "313": "walking stick, walkingstick, stick insect",
330
+ "314": "cockroach, roach",
331
+ "315": "mantis, mantid",
332
+ "316": "cicada, cicala",
333
+ "317": "leafhopper",
334
+ "318": "lacewing, lacewing fly",
335
+ "319": "dragonfly, darning needle, devils darning needle, sewing needle, snake feeder, snake doctor, mosquito hawk, skeeter hawk",
336
+ "320": "damselfly",
337
+ "321": "admiral",
338
+ "322": "ringlet, ringlet butterfly",
339
+ "323": "monarch, monarch butterfly, milkweed butterfly, Danaus plexippus",
340
+ "324": "cabbage butterfly",
341
+ "325": "sulphur butterfly, sulfur butterfly",
342
+ "326": "lycaenid, lycaenid butterfly",
343
+ "327": "starfish, sea star",
344
+ "328": "sea urchin",
345
+ "329": "sea cucumber, holothurian",
346
+ "330": "wood rabbit, cottontail, cottontail rabbit",
347
+ "331": "hare",
348
+ "332": "Angora, Angora rabbit",
349
+ "333": "hamster",
350
+ "334": "porcupine, hedgehog",
351
+ "335": "fox squirrel, eastern fox squirrel, Sciurus niger",
352
+ "336": "marmot",
353
+ "337": "beaver",
354
+ "338": "guinea pig, Cavia cobaya",
355
+ "339": "sorrel",
356
+ "340": "zebra",
357
+ "341": "hog, pig, grunter, squealer, Sus scrofa",
358
+ "342": "wild boar, boar, Sus scrofa",
359
+ "343": "warthog",
360
+ "344": "hippopotamus, hippo, river horse, Hippopotamus amphibius",
361
+ "345": "ox",
362
+ "346": "water buffalo, water ox, Asiatic buffalo, Bubalus bubalis",
363
+ "347": "bison",
364
+ "348": "ram, tup",
365
+ "349": "bighorn, bighorn sheep, cimarron, Rocky Mountain bighorn, Rocky Mountain sheep, Ovis canadensis",
366
+ "350": "ibex, Capra ibex",
367
+ "351": "hartebeest",
368
+ "352": "impala, Aepyceros melampus",
369
+ "353": "gazelle",
370
+ "354": "Arabian camel, dromedary, Camelus dromedarius",
371
+ "355": "llama",
372
+ "356": "weasel",
373
+ "357": "mink",
374
+ "358": "polecat, fitch, foulmart, foumart, Mustela putorius",
375
+ "359": "black-footed ferret, ferret, Mustela nigripes",
376
+ "360": "otter",
377
+ "361": "skunk, polecat, wood pussy",
378
+ "362": "badger",
379
+ "363": "armadillo",
380
+ "364": "three-toed sloth, ai, Bradypus tridactylus",
381
+ "365": "orangutan, orang, orangutang, Pongo pygmaeus",
382
+ "366": "gorilla, Gorilla gorilla",
383
+ "367": "chimpanzee, chimp, Pan troglodytes",
384
+ "368": "gibbon, Hylobates lar",
385
+ "369": "siamang, Hylobates syndactylus, Symphalangus syndactylus",
386
+ "370": "guenon, guenon monkey",
387
+ "371": "patas, hussar monkey, Erythrocebus patas",
388
+ "372": "baboon",
389
+ "373": "macaque",
390
+ "374": "langur",
391
+ "375": "colobus, colobus monkey",
392
+ "376": "proboscis monkey, Nasalis larvatus",
393
+ "377": "marmoset",
394
+ "378": "capuchin, ringtail, Cebus capucinus",
395
+ "379": "howler monkey, howler",
396
+ "380": "titi, titi monkey",
397
+ "381": "spider monkey, Ateles geoffroyi",
398
+ "382": "squirrel monkey, Saimiri sciureus",
399
+ "383": "Madagascar cat, ring-tailed lemur, Lemur catta",
400
+ "384": "indri, indris, Indri indri, Indri brevicaudatus",
401
+ "385": "Indian elephant, Elephas maximus",
402
+ "386": "African elephant, Loxodonta africana",
403
+ "387": "lesser panda, red panda, panda, bear cat, cat bear, Ailurus fulgens",
404
+ "388": "giant panda, panda, panda bear, coon bear, Ailuropoda melanoleuca",
405
+ "389": "barracouta, snoek",
406
+ "390": "eel",
407
+ "391": "coho, cohoe, coho salmon, blue jack, silver salmon, Oncorhynchus kisutch",
408
+ "392": "rock beauty, Holocanthus tricolor",
409
+ "393": "anemone fish",
410
+ "394": "sturgeon",
411
+ "395": "gar, garfish, garpike, billfish, Lepisosteus osseus",
412
+ "396": "lionfish",
413
+ "397": "puffer, pufferfish, blowfish, globefish",
414
+ "398": "abacus",
415
+ "399": "abaya",
416
+ "400": "academic gown, academic robe, judge robe",
417
+ "401": "accordion, piano accordion, squeeze box",
418
+ "402": "acoustic guitar",
419
+ "403": "aircraft carrier, carrier, flattop, attack aircraft carrier",
420
+ "404": "airliner",
421
+ "405": "airship, dirigible",
422
+ "406": "altar",
423
+ "407": "ambulance",
424
+ "408": "amphibian, amphibious vehicle",
425
+ "409": "analog clock",
426
+ "410": "apiary, bee house",
427
+ "411": "apron",
428
+ "412": "ashcan, trash can, garbage can, wastebin, ash bin, ash-bin, ashbin, dustbin, trash barrel, trash bin",
429
+ "413": "assault rifle, assault gun",
430
+ "414": "backpack, back pack, knapsack, packsack, rucksack, haversack",
431
+ "415": "bakery, bakeshop, bakehouse",
432
+ "416": "balance beam, beam",
433
+ "417": "balloon",
434
+ "418": "ballpoint, ballpoint pen, ballpen, Biro",
435
+ "419": "Band Aid",
436
+ "420": "banjo",
437
+ "421": "bannister, banister, balustrade, balusters, handrail",
438
+ "422": "barbell",
439
+ "423": "barber chair",
440
+ "424": "barbershop",
441
+ "425": "barn",
442
+ "426": "barometer",
443
+ "427": "barrel, cask",
444
+ "428": "barrow, garden cart, lawn cart, wheelbarrow",
445
+ "429": "baseball",
446
+ "430": "basketball",
447
+ "431": "bassinet",
448
+ "432": "bassoon",
449
+ "433": "bathing cap, swimming cap",
450
+ "434": "bath towel",
451
+ "435": "bathtub, bathing tub, bath, tub",
452
+ "436": "beach wagon, station wagon, wagon, estate car, beach waggon, station waggon, waggon",
453
+ "437": "beacon, lighthouse, beacon light, pharos",
454
+ "438": "beaker",
455
+ "439": "bearskin, busby, shako",
456
+ "440": "beer bottle",
457
+ "441": "beer glass",
458
+ "442": "bell cote, bell cot",
459
+ "443": "bib",
460
+ "444": "bicycle-built-for-two, tandem bicycle, tandem",
461
+ "445": "bikini, two-piece",
462
+ "446": "binder, ring-binder",
463
+ "447": "binoculars, field glasses, opera glasses",
464
+ "448": "birdhouse",
465
+ "449": "boathouse",
466
+ "450": "bobsled, bobsleigh, bob",
467
+ "451": "bolo tie, bolo, bola tie, bola",
468
+ "452": "bonnet, poke bonnet",
469
+ "453": "bookcase",
470
+ "454": "bookshop, bookstore, bookstall",
471
+ "455": "bottlecap",
472
+ "456": "bow",
473
+ "457": "bow tie, bow-tie, bowtie",
474
+ "458": "brass, memorial tablet, plaque",
475
+ "459": "brassiere, bra, bandeau",
476
+ "460": "breakwater, groin, groyne, mole, bulwark, seawall, jetty",
477
+ "461": "breastplate, aegis, egis",
478
+ "462": "broom",
479
+ "463": "bucket, pail",
480
+ "464": "buckle",
481
+ "465": "bulletproof vest",
482
+ "466": "bullet train, bullet",
483
+ "467": "butcher shop, meat market",
484
+ "468": "cab, hack, taxi, taxicab",
485
+ "469": "caldron, cauldron",
486
+ "470": "candle, taper, wax light",
487
+ "471": "cannon",
488
+ "472": "canoe",
489
+ "473": "can opener, tin opener",
490
+ "474": "cardigan",
491
+ "475": "car mirror",
492
+ "476": "carousel, carrousel, merry-go-round, roundabout, whirligig",
493
+ "477": "carpenters kit, tool kit",
494
+ "478": "carton",
495
+ "479": "car wheel",
496
+ "480": "cash machine, cash dispenser, automated teller machine, automatic teller machine, automated teller, automatic teller, ATM",
497
+ "481": "cassette",
498
+ "482": "cassette player",
499
+ "483": "castle",
500
+ "484": "catamaran",
501
+ "485": "CD player",
502
+ "486": "cello, violoncello",
503
+ "487": "cellular telephone, cellular phone, cellphone, cell, mobile phone",
504
+ "488": "chain",
505
+ "489": "chainlink fence",
506
+ "490": "chain mail, ring mail, mail, chain armor, chain armour, ring armor, ring armour",
507
+ "491": "chain saw, chainsaw",
508
+ "492": "chest",
509
+ "493": "chiffonier, commode",
510
+ "494": "chime, bell, gong",
511
+ "495": "china cabinet, china closet",
512
+ "496": "Christmas stocking",
513
+ "497": "church, church building",
514
+ "498": "cinema, movie theater, movie theatre, movie house, picture palace",
515
+ "499": "cleaver, meat cleaver, chopper",
516
+ "500": "cliff dwelling",
517
+ "501": "cloak",
518
+ "502": "clog, geta, patten, sabot",
519
+ "503": "cocktail shaker",
520
+ "504": "coffee mug",
521
+ "505": "coffeepot",
522
+ "506": "coil, spiral, volute, whorl, helix",
523
+ "507": "combination lock",
524
+ "508": "computer keyboard, keypad",
525
+ "509": "confectionery, confectionary, candy store",
526
+ "510": "container ship, containership, container vessel",
527
+ "511": "convertible",
528
+ "512": "corkscrew, bottle screw",
529
+ "513": "cornet, horn, trumpet, trump",
530
+ "514": "cowboy boot",
531
+ "515": "cowboy hat, ten-gallon hat",
532
+ "516": "cradle",
533
+ "517": "crane",
534
+ "518": "crash helmet",
535
+ "519": "crate",
536
+ "520": "crib, cot",
537
+ "521": "Crock Pot",
538
+ "522": "croquet ball",
539
+ "523": "crutch",
540
+ "524": "cuirass",
541
+ "525": "dam, dike, dyke",
542
+ "526": "desk",
543
+ "527": "desktop computer",
544
+ "528": "dial telephone, dial phone",
545
+ "529": "diaper, nappy, napkin",
546
+ "530": "digital clock",
547
+ "531": "digital watch",
548
+ "532": "dining table, board",
549
+ "533": "dishrag, dishcloth",
550
+ "534": "dishwasher, dish washer, dishwashing machine",
551
+ "535": "disk brake, disc brake",
552
+ "536": "dock, dockage, docking facility",
553
+ "537": "dogsled, dog sled, dog sleigh",
554
+ "538": "dome",
555
+ "539": "doormat, welcome mat",
556
+ "540": "drilling platform, offshore rig",
557
+ "541": "drum, membranophone, tympan",
558
+ "542": "drumstick",
559
+ "543": "dumbbell",
560
+ "544": "Dutch oven",
561
+ "545": "electric fan, blower",
562
+ "546": "electric guitar",
563
+ "547": "electric locomotive",
564
+ "548": "entertainment center",
565
+ "549": "envelope",
566
+ "550": "espresso maker",
567
+ "551": "face powder",
568
+ "552": "feather boa, boa",
569
+ "553": "file, file cabinet, filing cabinet",
570
+ "554": "fireboat",
571
+ "555": "fire engine, fire truck",
572
+ "556": "fire screen, fireguard",
573
+ "557": "flagpole, flagstaff",
574
+ "558": "flute, transverse flute",
575
+ "559": "folding chair",
576
+ "560": "football helmet",
577
+ "561": "forklift",
578
+ "562": "fountain",
579
+ "563": "fountain pen",
580
+ "564": "four-poster",
581
+ "565": "freight car",
582
+ "566": "French horn, horn",
583
+ "567": "frying pan, frypan, skillet",
584
+ "568": "fur coat",
585
+ "569": "garbage truck, dustcart",
586
+ "570": "gasmask, respirator, gas helmet",
587
+ "571": "gas pump, gasoline pump, petrol pump, island dispenser",
588
+ "572": "goblet",
589
+ "573": "go-kart",
590
+ "574": "golf ball",
591
+ "575": "golfcart, golf cart",
592
+ "576": "gondola",
593
+ "577": "gong, tam-tam",
594
+ "578": "gown",
595
+ "579": "grand piano, grand",
596
+ "580": "greenhouse, nursery, glasshouse",
597
+ "581": "grille, radiator grille",
598
+ "582": "grocery store, grocery, food market, market",
599
+ "583": "guillotine",
600
+ "584": "hair slide",
601
+ "585": "hair spray",
602
+ "586": "half track",
603
+ "587": "hammer",
604
+ "588": "hamper",
605
+ "589": "hand blower, blow dryer, blow drier, hair dryer, hair drier",
606
+ "590": "hand-held computer, hand-held microcomputer",
607
+ "591": "handkerchief, hankie, hanky, hankey",
608
+ "592": "hard disc, hard disk, fixed disk",
609
+ "593": "harmonica, mouth organ, harp, mouth harp",
610
+ "594": "harp",
611
+ "595": "harvester, reaper",
612
+ "596": "hatchet",
613
+ "597": "holster",
614
+ "598": "home theater, home theatre",
615
+ "599": "honeycomb",
616
+ "600": "hook, claw",
617
+ "601": "hoopskirt, crinoline",
618
+ "602": "horizontal bar, high bar",
619
+ "603": "horse cart, horse-cart",
620
+ "604": "hourglass",
621
+ "605": "iPod",
622
+ "606": "iron, smoothing iron",
623
+ "607": "jack-o-lantern",
624
+ "608": "jean, blue jean, denim",
625
+ "609": "jeep, landrover",
626
+ "610": "jersey, T-shirt, tee shirt",
627
+ "611": "jigsaw puzzle",
628
+ "612": "jinrikisha, ricksha, rickshaw",
629
+ "613": "joystick",
630
+ "614": "kimono",
631
+ "615": "knee pad",
632
+ "616": "knot",
633
+ "617": "lab coat, laboratory coat",
634
+ "618": "ladle",
635
+ "619": "lampshade, lamp shade",
636
+ "620": "laptop, laptop computer",
637
+ "621": "lawn mower, mower",
638
+ "622": "lens cap, lens cover",
639
+ "623": "letter opener, paper knife, paperknife",
640
+ "624": "library",
641
+ "625": "lifeboat",
642
+ "626": "lighter, light, igniter, ignitor",
643
+ "627": "limousine, limo",
644
+ "628": "liner, ocean liner",
645
+ "629": "lipstick, lip rouge",
646
+ "630": "Loafer",
647
+ "631": "lotion",
648
+ "632": "loudspeaker, speaker, speaker unit, loudspeaker system, speaker system",
649
+ "633": "loupe, jewelers loupe",
650
+ "634": "lumbermill, sawmill",
651
+ "635": "magnetic compass",
652
+ "636": "mailbag, postbag",
653
+ "637": "mailbox, letter box",
654
+ "638": "maillot",
655
+ "639": "maillot, tank suit",
656
+ "640": "manhole cover",
657
+ "641": "maraca",
658
+ "642": "marimba, xylophone",
659
+ "643": "mask",
660
+ "644": "matchstick",
661
+ "645": "maypole",
662
+ "646": "maze, labyrinth",
663
+ "647": "measuring cup",
664
+ "648": "medicine chest, medicine cabinet",
665
+ "649": "megalith, megalithic structure",
666
+ "650": "microphone, mike",
667
+ "651": "microwave, microwave oven",
668
+ "652": "military uniform",
669
+ "653": "milk can",
670
+ "654": "minibus",
671
+ "655": "miniskirt, mini",
672
+ "656": "minivan",
673
+ "657": "missile",
674
+ "658": "mitten",
675
+ "659": "mixing bowl",
676
+ "660": "mobile home, manufactured home",
677
+ "661": "Model T",
678
+ "662": "modem",
679
+ "663": "monastery",
680
+ "664": "monitor",
681
+ "665": "moped",
682
+ "666": "mortar",
683
+ "667": "mortarboard",
684
+ "668": "mosque",
685
+ "669": "mosquito net",
686
+ "670": "motor scooter, scooter",
687
+ "671": "mountain bike, all-terrain bike, off-roader",
688
+ "672": "mountain tent",
689
+ "673": "mouse, computer mouse",
690
+ "674": "mousetrap",
691
+ "675": "moving van",
692
+ "676": "muzzle",
693
+ "677": "nail",
694
+ "678": "neck brace",
695
+ "679": "necklace",
696
+ "680": "nipple",
697
+ "681": "notebook, notebook computer",
698
+ "682": "obelisk",
699
+ "683": "oboe, hautboy, hautbois",
700
+ "684": "ocarina, sweet potato",
701
+ "685": "odometer, hodometer, mileometer, milometer",
702
+ "686": "oil filter",
703
+ "687": "organ, pipe organ",
704
+ "688": "oscilloscope, scope, cathode-ray oscilloscope, CRO",
705
+ "689": "overskirt",
706
+ "690": "oxcart",
707
+ "691": "oxygen mask",
708
+ "692": "packet",
709
+ "693": "paddle, boat paddle",
710
+ "694": "paddlewheel, paddle wheel",
711
+ "695": "padlock",
712
+ "696": "paintbrush",
713
+ "697": "pajama, pyjama, pjs, jammies",
714
+ "698": "palace",
715
+ "699": "panpipe, pandean pipe, syrinx",
716
+ "700": "paper towel",
717
+ "701": "parachute, chute",
718
+ "702": "parallel bars, bars",
719
+ "703": "park bench",
720
+ "704": "parking meter",
721
+ "705": "passenger car, coach, carriage",
722
+ "706": "patio, terrace",
723
+ "707": "pay-phone, pay-station",
724
+ "708": "pedestal, plinth, footstall",
725
+ "709": "pencil box, pencil case",
726
+ "710": "pencil sharpener",
727
+ "711": "perfume, essence",
728
+ "712": "Petri dish",
729
+ "713": "photocopier",
730
+ "714": "pick, plectrum, plectron",
731
+ "715": "pickelhaube",
732
+ "716": "picket fence, paling",
733
+ "717": "pickup, pickup truck",
734
+ "718": "pier",
735
+ "719": "piggy bank, penny bank",
736
+ "720": "pill bottle",
737
+ "721": "pillow",
738
+ "722": "ping-pong ball",
739
+ "723": "pinwheel",
740
+ "724": "pirate, pirate ship",
741
+ "725": "pitcher, ewer",
742
+ "726": "plane, carpenters plane, woodworking plane",
743
+ "727": "planetarium",
744
+ "728": "plastic bag",
745
+ "729": "plate rack",
746
+ "730": "plow, plough",
747
+ "731": "plunger, plumbers helper",
748
+ "732": "Polaroid camera, Polaroid Land camera",
749
+ "733": "pole",
750
+ "734": "police van, police wagon, paddy wagon, patrol wagon, wagon, black Maria",
751
+ "735": "poncho",
752
+ "736": "pool table, billiard table, snooker table",
753
+ "737": "pop bottle, soda bottle",
754
+ "738": "pot, flowerpot",
755
+ "739": "potters wheel",
756
+ "740": "power drill",
757
+ "741": "prayer rug, prayer mat",
758
+ "742": "printer",
759
+ "743": "prison, prison house",
760
+ "744": "projectile, missile",
761
+ "745": "projector",
762
+ "746": "puck, hockey puck",
763
+ "747": "punching bag, punch bag, punching ball, punchball",
764
+ "748": "purse",
765
+ "749": "quill, quill pen",
766
+ "750": "quilt, comforter, comfort, puff",
767
+ "751": "racer, race car, racing car",
768
+ "752": "racket, racquet",
769
+ "753": "radiator",
770
+ "754": "radio, wireless",
771
+ "755": "radio telescope, radio reflector",
772
+ "756": "rain barrel",
773
+ "757": "recreational vehicle, RV, R.V.",
774
+ "758": "reel",
775
+ "759": "reflex camera",
776
+ "760": "refrigerator, icebox",
777
+ "761": "remote control, remote",
778
+ "762": "restaurant, eating house, eating place, eatery",
779
+ "763": "revolver, six-gun, six-shooter",
780
+ "764": "rifle",
781
+ "765": "rocking chair, rocker",
782
+ "766": "rotisserie",
783
+ "767": "rubber eraser, rubber, pencil eraser",
784
+ "768": "rugby ball",
785
+ "769": "rule, ruler",
786
+ "770": "running shoe",
787
+ "771": "safe",
788
+ "772": "safety pin",
789
+ "773": "saltshaker, salt shaker",
790
+ "774": "sandal",
791
+ "775": "sarong",
792
+ "776": "sax, saxophone",
793
+ "777": "scabbard",
794
+ "778": "scale, weighing machine",
795
+ "779": "school bus",
796
+ "780": "schooner",
797
+ "781": "scoreboard",
798
+ "782": "screen, CRT screen",
799
+ "783": "screw",
800
+ "784": "screwdriver",
801
+ "785": "seat belt, seatbelt",
802
+ "786": "sewing machine",
803
+ "787": "shield, buckler",
804
+ "788": "shoe shop, shoe-shop, shoe store",
805
+ "789": "shoji",
806
+ "790": "shopping basket",
807
+ "791": "shopping cart",
808
+ "792": "shovel",
809
+ "793": "shower cap",
810
+ "794": "shower curtain",
811
+ "795": "ski",
812
+ "796": "ski mask",
813
+ "797": "sleeping bag",
814
+ "798": "slide rule, slipstick",
815
+ "799": "sliding door",
816
+ "800": "slot, one-armed bandit",
817
+ "801": "snorkel",
818
+ "802": "snowmobile",
819
+ "803": "snowplow, snowplough",
820
+ "804": "soap dispenser",
821
+ "805": "soccer ball",
822
+ "806": "sock",
823
+ "807": "solar dish, solar collector, solar furnace",
824
+ "808": "sombrero",
825
+ "809": "soup bowl",
826
+ "810": "space bar",
827
+ "811": "space heater",
828
+ "812": "space shuttle",
829
+ "813": "spatula",
830
+ "814": "speedboat",
831
+ "815": "spider web, spiders web",
832
+ "816": "spindle",
833
+ "817": "sports car, sport car",
834
+ "818": "spotlight, spot",
835
+ "819": "stage",
836
+ "820": "steam locomotive",
837
+ "821": "steel arch bridge",
838
+ "822": "steel drum",
839
+ "823": "stethoscope",
840
+ "824": "stole",
841
+ "825": "stone wall",
842
+ "826": "stopwatch, stop watch",
843
+ "827": "stove",
844
+ "828": "strainer",
845
+ "829": "streetcar, tram, tramcar, trolley, trolley car",
846
+ "830": "stretcher",
847
+ "831": "studio couch, day bed",
848
+ "832": "stupa, tope",
849
+ "833": "submarine, pigboat, sub, U-boat",
850
+ "834": "suit, suit of clothes",
851
+ "835": "sundial",
852
+ "836": "sunglass",
853
+ "837": "sunglasses, dark glasses, shades",
854
+ "838": "sunscreen, sunblock, sun blocker",
855
+ "839": "suspension bridge",
856
+ "840": "swab, swob, mop",
857
+ "841": "sweatshirt",
858
+ "842": "swimming trunks, bathing trunks",
859
+ "843": "swing",
860
+ "844": "switch, electric switch, electrical switch",
861
+ "845": "syringe",
862
+ "846": "table lamp",
863
+ "847": "tank, army tank, armored combat vehicle, armoured combat vehicle",
864
+ "848": "tape player",
865
+ "849": "teapot",
866
+ "850": "teddy, teddy bear",
867
+ "851": "television, television system",
868
+ "852": "tennis ball",
869
+ "853": "thatch, thatched roof",
870
+ "854": "theater curtain, theatre curtain",
871
+ "855": "thimble",
872
+ "856": "thresher, thrasher, threshing machine",
873
+ "857": "throne",
874
+ "858": "tile roof",
875
+ "859": "toaster",
876
+ "860": "tobacco shop, tobacconist shop, tobacconist",
877
+ "861": "toilet seat",
878
+ "862": "torch",
879
+ "863": "totem pole",
880
+ "864": "tow truck, tow car, wrecker",
881
+ "865": "toyshop",
882
+ "866": "tractor",
883
+ "867": "trailer truck, tractor trailer, trucking rig, rig, articulated lorry, semi",
884
+ "868": "tray",
885
+ "869": "trench coat",
886
+ "870": "tricycle, trike, velocipede",
887
+ "871": "trimaran",
888
+ "872": "tripod",
889
+ "873": "triumphal arch",
890
+ "874": "trolleybus, trolley coach, trackless trolley",
891
+ "875": "trombone",
892
+ "876": "tub, vat",
893
+ "877": "turnstile",
894
+ "878": "typewriter keyboard",
895
+ "879": "umbrella",
896
+ "880": "unicycle, monocycle",
897
+ "881": "upright, upright piano",
898
+ "882": "vacuum, vacuum cleaner",
899
+ "883": "vase",
900
+ "884": "vault",
901
+ "885": "velvet",
902
+ "886": "vending machine",
903
+ "887": "vestment",
904
+ "888": "viaduct",
905
+ "889": "violin, fiddle",
906
+ "890": "volleyball",
907
+ "891": "waffle iron",
908
+ "892": "wall clock",
909
+ "893": "wallet, billfold, notecase, pocketbook",
910
+ "894": "wardrobe, closet, press",
911
+ "895": "warplane, military plane",
912
+ "896": "washbasin, handbasin, washbowl, lavabo, wash-hand basin",
913
+ "897": "washer, automatic washer, washing machine",
914
+ "898": "water bottle",
915
+ "899": "water jug",
916
+ "900": "water tower",
917
+ "901": "whiskey jug",
918
+ "902": "whistle",
919
+ "903": "wig",
920
+ "904": "window screen",
921
+ "905": "window shade",
922
+ "906": "Windsor tie",
923
+ "907": "wine bottle",
924
+ "908": "wing",
925
+ "909": "wok",
926
+ "910": "wooden spoon",
927
+ "911": "wool, woolen, woollen",
928
+ "912": "worm fence, snake fence, snake-rail fence, Virginia fence",
929
+ "913": "wreck",
930
+ "914": "yawl",
931
+ "915": "yurt",
932
+ "916": "web site, website, internet site, site",
933
+ "917": "comic book",
934
+ "918": "crossword puzzle, crossword",
935
+ "919": "street sign",
936
+ "920": "traffic light, traffic signal, stoplight",
937
+ "921": "book jacket, dust cover, dust jacket, dust wrapper",
938
+ "922": "menu",
939
+ "923": "plate",
940
+ "924": "guacamole",
941
+ "925": "consomme",
942
+ "926": "hot pot, hotpot",
943
+ "927": "trifle",
944
+ "928": "ice cream, icecream",
945
+ "929": "ice lolly, lolly, lollipop, popsicle",
946
+ "930": "French loaf",
947
+ "931": "bagel, beigel",
948
+ "932": "pretzel",
949
+ "933": "cheeseburger",
950
+ "934": "hotdog, hot dog, red hot",
951
+ "935": "mashed potato",
952
+ "936": "head cabbage",
953
+ "937": "broccoli",
954
+ "938": "cauliflower",
955
+ "939": "zucchini, courgette",
956
+ "940": "spaghetti squash",
957
+ "941": "acorn squash",
958
+ "942": "butternut squash",
959
+ "943": "cucumber, cuke",
960
+ "944": "artichoke, globe artichoke",
961
+ "945": "bell pepper",
962
+ "946": "cardoon",
963
+ "947": "mushroom",
964
+ "948": "Granny Smith",
965
+ "949": "strawberry",
966
+ "950": "orange",
967
+ "951": "lemon",
968
+ "952": "fig",
969
+ "953": "pineapple, ananas",
970
+ "954": "banana",
971
+ "955": "jackfruit, jak, jack",
972
+ "956": "custard apple",
973
+ "957": "pomegranate",
974
+ "958": "hay",
975
+ "959": "carbonara",
976
+ "960": "chocolate sauce, chocolate syrup",
977
+ "961": "dough",
978
+ "962": "meat loaf, meatloaf",
979
+ "963": "pizza, pizza pie",
980
+ "964": "potpie",
981
+ "965": "burrito",
982
+ "966": "red wine",
983
+ "967": "espresso",
984
+ "968": "cup",
985
+ "969": "eggnog",
986
+ "970": "alp",
987
+ "971": "bubble",
988
+ "972": "cliff, drop, drop-off",
989
+ "973": "coral reef",
990
+ "974": "geyser",
991
+ "975": "lakeside, lakeshore",
992
+ "976": "promontory, headland, head, foreland",
993
+ "977": "sandbar, sand bar",
994
+ "978": "seashore, coast, seacoast, sea-coast",
995
+ "979": "valley, vale",
996
+ "980": "volcano",
997
+ "981": "ballplayer, baseball player",
998
+ "982": "groom, bridegroom",
999
+ "983": "scuba diver",
1000
+ "984": "rapeseed",
1001
+ "985": "daisy",
1002
+ "986": "yellow ladys slipper, yellow lady-slipper, Cypripedium calceolus, Cypripedium parviflorum",
1003
+ "987": "corn",
1004
+ "988": "acorn",
1005
+ "989": "hip, rose hip, rosehip",
1006
+ "990": "buckeye, horse chestnut, conker",
1007
+ "991": "coral fungus",
1008
+ "992": "agaric",
1009
+ "993": "gyromitra",
1010
+ "994": "stinkhorn, carrion fungus",
1011
+ "995": "earthstar",
1012
+ "996": "hen-of-the-woods, hen of the woods, Polyporus frondosus, Grifola frondosa",
1013
+ "997": "bolete",
1014
+ "998": "ear, spike, capitulum",
1015
+ "999": "toilet tissue, toilet paper, bathroom tissue"
1016
+ }
1017
+ }
JiT-L-16-SIM/pipeline.py ADDED
@@ -0,0 +1,350 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ """Hub custom pipeline: JiTPipeline for FD-Loss post-trained JiT (legacy time, velocity Euler)."""
16
+
17
+ from __future__ import annotations
18
+
19
+ import importlib.util
20
+ import inspect
21
+ import json
22
+ from pathlib import Path
23
+ from typing import Dict, List, Optional, Tuple, Union
24
+
25
+ import torch
26
+ from diffusers.pipelines.pipeline_utils import DiffusionPipeline, ImagePipelineOutput
27
+ from diffusers.utils.torch_utils import randn_tensor
28
+
29
+ EXAMPLE_DOC_STRING = """
30
+ Examples:
31
+ ```py
32
+ >>> from pathlib import Path
33
+ >>> import torch
34
+ >>> from diffusers import DiffusionPipeline
35
+
36
+ >>> model_dir = Path("BiliSakura/FD-Loss-diffusers/JiT-B-16-SIM")
37
+ >>> pipe = DiffusionPipeline.from_pretrained(
38
+ ... str(model_dir),
39
+ ... custom_pipeline=str(model_dir / "pipeline.py"),
40
+ ... trust_remote_code=True,
41
+ ... )
42
+ >>> pipe.to("cuda")
43
+ >>> image = pipe(class_labels="golden retriever", num_inference_steps=1, guidance_scale=3.0).images[0]
44
+ ```
45
+ """
46
+
47
+ RECOMMENDED_NOISE_BY_SIZE = {256: 1.0, 512: 2.0}
48
+
49
+
50
+ class JiTPipeline(DiffusionPipeline):
51
+ r"""
52
+ Class-conditional JiT pipeline for FD-Loss checkpoints (1-NFE velocity Euler, legacy time convention).
53
+
54
+ Args:
55
+ transformer ([`JiTTransformer2DModel`]): JiT backbone.
56
+ scheduler ([`FDLossFlowMatchScheduler`], *optional*): Bundled flow-matching scheduler (`t=1→0`).
57
+ Accepts `generator` in `step()` for reproducible stochastic sampling.
58
+ id2label (`dict[int, str]`, *optional*): ImageNet id → label strings from `model_index.json`.
59
+ """
60
+
61
+ model_cpu_offload_seq = "transformer"
62
+ _optional_components = ["scheduler"]
63
+
64
+ @staticmethod
65
+ def prepare_extra_step_kwargs(
66
+ scheduler,
67
+ generator=None,
68
+ eta: float | None = None,
69
+ ):
70
+ kwargs = {}
71
+ step_params = set(inspect.signature(scheduler.step).parameters.keys())
72
+ if "generator" in step_params:
73
+ kwargs["generator"] = generator
74
+ if eta is not None and "eta" in step_params:
75
+ kwargs["eta"] = eta
76
+ return kwargs
77
+
78
+ @staticmethod
79
+ def _resolve_inference_generator(
80
+ device: Union[str, torch.device],
81
+ generator: Optional[Union[torch.Generator, List[torch.Generator]]] = None,
82
+ ) -> Optional[Union[torch.Generator, List[torch.Generator]]]:
83
+ if generator is None:
84
+ return None
85
+ if isinstance(device, str):
86
+ device = torch.device(device)
87
+ device_type = device.type
88
+
89
+ def _relocate(gen: torch.Generator) -> torch.Generator:
90
+ if gen.device.type == device_type:
91
+ return gen
92
+ return torch.Generator(device=device_type).manual_seed(gen.initial_seed())
93
+
94
+ if isinstance(generator, list):
95
+ return [_relocate(g) for g in generator]
96
+ return _relocate(generator)
97
+
98
+ @staticmethod
99
+ def _coerce_scheduler(scheduler, transformer):
100
+ """Always load the bundled FD-Loss flow scheduler (ignore model_index diffusers schedulers)."""
101
+ variant_path = getattr(transformer.config, "_name_or_path", None)
102
+ if variant_path:
103
+ scheduler_dir = Path(variant_path).resolve().parent / "scheduler"
104
+ module_path = scheduler_dir / "scheduling_flow_match_fd.py"
105
+ config_path = scheduler_dir / "scheduler_config.json"
106
+ if module_path.is_file() and config_path.is_file():
107
+ spec = importlib.util.spec_from_file_location("scheduling_flow_match_fd", module_path)
108
+ if spec is not None and spec.loader is not None:
109
+ module = importlib.util.module_from_spec(spec)
110
+ spec.loader.exec_module(module)
111
+ scheduler_cls = getattr(module, "FDLossFlowMatchScheduler")
112
+ return scheduler_cls.from_pretrained(str(scheduler_dir))
113
+ scheduler_dir = Path(__file__).resolve().parent / "scheduler"
114
+ module_path = scheduler_dir / "scheduling_flow_match_fd.py"
115
+ config_path = scheduler_dir / "scheduler_config.json"
116
+ if module_path.is_file() and config_path.is_file():
117
+ spec = importlib.util.spec_from_file_location("scheduling_flow_match_fd", module_path)
118
+ if spec is not None and spec.loader is not None:
119
+ module = importlib.util.module_from_spec(spec)
120
+ spec.loader.exec_module(module)
121
+ scheduler_cls = getattr(module, "FDLossFlowMatchScheduler")
122
+ return scheduler_cls.from_pretrained(str(scheduler_dir))
123
+ raise ValueError("FD-Loss JiT requires a bundled FDLossFlowMatchScheduler under `scheduler/`.")
124
+
125
+ def __init__(
126
+ self,
127
+ transformer,
128
+ scheduler=None,
129
+ id2label: Optional[Dict[Union[int, str], str]] = None,
130
+ ):
131
+ super().__init__()
132
+ self.legacy_time_convention = True
133
+ scheduler = self._coerce_scheduler(scheduler, transformer)
134
+ self.register_modules(transformer=transformer, scheduler=scheduler)
135
+ self._id2label = self._normalize_id2label(id2label)
136
+ self.labels = self._build_label2id(self._id2label)
137
+ self._labels_loaded_from_model_index = bool(self._id2label)
138
+
139
+
140
+ @property
141
+ def id2label(self) -> Dict[int, str]:
142
+ self._ensure_labels_loaded()
143
+ return self._id2label
144
+
145
+ def get_label_ids(self, label: Union[str, List[str]]) -> List[int]:
146
+ r"""Map ImageNet English label strings to class ids."""
147
+ self._ensure_labels_loaded()
148
+ if isinstance(label, str):
149
+ label = [label]
150
+ missing = [item for item in label if item not in self.labels]
151
+ if missing:
152
+ preview = ", ".join(list(self.labels.keys())[:8])
153
+ raise ValueError(f"Unknown label(s): {missing}. Examples: {preview}, ...")
154
+ return [self.labels[item] for item in label]
155
+
156
+ def _backbone_timestep(self, t: torch.Tensor) -> torch.Tensor:
157
+ if self.legacy_time_convention:
158
+ return 1.0 - t
159
+ return t
160
+
161
+ def _cfg_interval(self, interval_min: float, interval_max: float, device: torch.device) -> Tuple[float, float]:
162
+ low = float(self._backbone_timestep(torch.tensor(interval_min, device=device)))
163
+ high = float(self._backbone_timestep(torch.tensor(interval_max, device=device)))
164
+ return min(low, high), max(low, high)
165
+
166
+ def _flow_time_tensors(self, t: torch.Tensor, sample: torch.Tensor) -> Tuple[torch.Tensor, torch.Tensor]:
167
+ """Broadcast scalar flow time and per-sample backbone timesteps for `sample` (B, C, H, W)."""
168
+ flow_t = t.reshape(()).to(device=sample.device, dtype=sample.dtype)
169
+ t_view = flow_t.reshape(*([1] * sample.ndim))
170
+ t_bb = self._backbone_timestep(flow_t).expand(sample.shape[0])
171
+ return t_view, t_bb
172
+
173
+ def _predict_velocity(
174
+ self,
175
+ sample: torch.Tensor,
176
+ t: torch.Tensor,
177
+ class_labels: torch.Tensor,
178
+ guidance_scale: float,
179
+ cfg_interval: Tuple[float, float],
180
+ t_eps: float,
181
+ interpolate_pos_encoding: bool,
182
+ ) -> torch.Tensor:
183
+ t_view, t_bb = self._flow_time_tensors(t, sample)
184
+ num_classes = int(getattr(self.transformer.config, "num_classes", 1000))
185
+
186
+ x_cond = self.transformer(
187
+ sample,
188
+ timestep=t_bb,
189
+ class_labels=class_labels,
190
+ interpolate_pos_encoding=interpolate_pos_encoding,
191
+ ).sample
192
+ v_cond = (sample - x_cond) / t_view.clamp_min(t_eps)
193
+
194
+ if guidance_scale <= 1.0:
195
+ return v_cond
196
+
197
+ class_null = torch.full_like(class_labels, num_classes)
198
+ x_uncond = self.transformer(
199
+ sample,
200
+ timestep=t_bb,
201
+ class_labels=class_null,
202
+ interpolate_pos_encoding=interpolate_pos_encoding,
203
+ ).sample
204
+ v_uncond = (sample - x_uncond) / t_view.clamp_min(t_eps)
205
+
206
+ low, high = cfg_interval
207
+ flow_t = t.reshape(()).to(device=sample.device, dtype=sample.dtype)
208
+ mask = (flow_t < high) & ((low == 0) | (flow_t > low))
209
+ scale = torch.where(
210
+ mask,
211
+ torch.tensor(guidance_scale, device=sample.device, dtype=sample.dtype),
212
+ torch.tensor(1.0, device=sample.device, dtype=sample.dtype),
213
+ )
214
+ while scale.ndim < v_cond.ndim:
215
+ scale = scale.unsqueeze(-1)
216
+ return v_uncond + scale * (v_cond - v_uncond)
217
+
218
+ @staticmethod
219
+ def _normalize_id2label(id2label: Optional[Dict[Union[int, str], str]]) -> Dict[int, str]:
220
+ if not id2label:
221
+ return {}
222
+ return {int(key): value for key, value in id2label.items()}
223
+
224
+ @staticmethod
225
+ def _build_label2id(id2label: Dict[int, str]) -> Dict[str, int]:
226
+ label2id: Dict[str, int] = {}
227
+ for class_id, value in id2label.items():
228
+ for synonym in value.split(","):
229
+ synonym = synonym.strip()
230
+ if synonym:
231
+ label2id[synonym] = int(class_id)
232
+ return dict(sorted(label2id.items()))
233
+
234
+ def _ensure_labels_loaded(self) -> None:
235
+ if self._labels_loaded_from_model_index:
236
+ return
237
+ path = getattr(self.config, "_name_or_path", None)
238
+ if path:
239
+ model_index_path = Path(path).resolve() / "model_index.json"
240
+ if model_index_path.exists():
241
+ raw = json.loads(model_index_path.read_text(encoding="utf-8"))
242
+ id2label = raw.get("id2label")
243
+ if isinstance(id2label, dict):
244
+ self._id2label = {int(k): v for k, v in id2label.items()}
245
+ self.labels = self._build_label2id(self._id2label)
246
+ self._labels_loaded_from_model_index = True
247
+
248
+ def _normalize_class_labels(self, class_labels: Union[int, str, List[Union[int, str]]]) -> List[int]:
249
+ if isinstance(class_labels, int):
250
+ return [class_labels]
251
+ if isinstance(class_labels, str):
252
+ return self.get_label_ids(class_labels)
253
+ if class_labels and isinstance(class_labels[0], str):
254
+ return self.get_label_ids(class_labels)
255
+ return list(class_labels)
256
+
257
+ @torch.inference_mode()
258
+ def __call__(
259
+ self,
260
+ class_labels: Union[int, str, List[Union[int, str]]],
261
+ guidance_scale: float = 3.0,
262
+ guidance_interval_min: float = 0.1,
263
+ guidance_interval_max: float = 1.0,
264
+ noise_scale: Optional[float] = None,
265
+ t_eps: float = 5e-2,
266
+ generator: Optional[Union[torch.Generator, List[torch.Generator]]] = None,
267
+ num_inference_steps: int = 1,
268
+ height: Optional[int] = None,
269
+ width: Optional[int] = None,
270
+ interpolate_pos_encoding: bool = True,
271
+ output_type: Optional[str] = "pil",
272
+ return_dict: bool = True,
273
+ ) -> Union[ImagePipelineOutput, Tuple]:
274
+ r"""
275
+ Generate images conditioned on ImageNet class ids or English labels.
276
+
277
+ Args:
278
+ class_labels: Class id(s), label string(s), or mixed list.
279
+ guidance_scale: CFG scale (FD-Loss JiT-B default: 3.0).
280
+ guidance_interval_min: Lower flow-time bound for CFG (default 0.1).
281
+ guidance_interval_max: Upper flow-time bound for CFG (default 1.0).
282
+ noise_scale: Initial Gaussian scale (default 1.0 at 256px).
283
+ t_eps: Clamp for flow time in velocity denominator.
284
+ generator: RNG for latent init.
285
+ num_inference_steps: FD-Loss sampling steps (1 = single NFE).
286
+ height: Output height (defaults to native `sample_size`).
287
+ width: Output width (defaults to native `sample_size`).
288
+ interpolate_pos_encoding: Interpolate positional embeddings for non-native sizes.
289
+ output_type: `pil`, `np`, or `pt`.
290
+ return_dict: Return [`ImagePipelineOutput`] if True.
291
+ """
292
+ # 1. Check inputs
293
+ if num_inference_steps < 1:
294
+ raise ValueError("num_inference_steps must be >= 1.")
295
+ if output_type not in {"pil", "np", "pt"}:
296
+ raise ValueError("output_type must be one of: 'pil', 'np', 'pt'.")
297
+
298
+ # 2. Call parameters
299
+ class_label_ids = self._normalize_class_labels(class_labels)
300
+ batch_size = len(class_label_ids)
301
+ generator = self._resolve_inference_generator(self._execution_device, generator)
302
+ image_size = int(self.transformer.config.sample_size)
303
+ patch_size = int(self.transformer.config.patch_size)
304
+ height = int(height or image_size)
305
+ width = int(width or image_size)
306
+ if height % patch_size != 0 or width % patch_size != 0:
307
+ raise ValueError(f"height/width must be divisible by patch_size={patch_size}.")
308
+ channels = int(self.transformer.config.in_channels)
309
+ null_class_val = int(getattr(self.transformer.config, "num_classes", 1000))
310
+ if noise_scale is None:
311
+ noise_scale = RECOMMENDED_NOISE_BY_SIZE.get(max(height, width), 1.0)
312
+
313
+ # 3. Class labels
314
+ labels = torch.tensor(class_label_ids, device=self._execution_device, dtype=torch.long).reshape(-1)
315
+ labels = labels.clamp(0, null_class_val - 1)
316
+ cfg_interval = self._cfg_interval(guidance_interval_min, guidance_interval_max, labels.device)
317
+
318
+ # 4. Latents
319
+ latents = randn_tensor(
320
+ (batch_size, channels, height, width),
321
+ generator=generator,
322
+ device=self._execution_device,
323
+ dtype=self.transformer.dtype,
324
+ ) * noise_scale
325
+
326
+ # 5–6. Denoising loop (FD-Loss flow t=1 → 0; generator forwarded to scheduler.step)
327
+ self.scheduler.set_timesteps(num_inference_steps, device=self._execution_device)
328
+ extra_step_kwargs = self.prepare_extra_step_kwargs(self.scheduler, generator=generator)
329
+ timesteps = self.scheduler.timesteps
330
+
331
+ for i in self.progress_bar(range(num_inference_steps)):
332
+ t_cur = timesteps[i]
333
+ velocity = self._predict_velocity(
334
+ latents, t_cur, labels, guidance_scale, cfg_interval, t_eps, interpolate_pos_encoding
335
+ )
336
+ latents = self.scheduler.step(velocity, t_cur, latents, **extra_step_kwargs).prev_sample
337
+
338
+ # 8. Output
339
+ images_pt = ((latents.float().clamp(-1, 1) + 1.0) / 2.0).cpu()
340
+ if output_type == "pt":
341
+ images = images_pt
342
+ elif output_type == "np":
343
+ images = images_pt.permute(0, 2, 3, 1).numpy()
344
+ else:
345
+ images = self.numpy_to_pil(images_pt.permute(0, 2, 3, 1).numpy())
346
+
347
+ self.maybe_free_model_hooks()
348
+ if not return_dict:
349
+ return (images,)
350
+ return ImagePipelineOutput(images=images)
JiT-L-16-SIM/scheduler/scheduler_config.json ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ {
2
+ "_class_name": "FDLossFlowMatchScheduler",
3
+ "_diffusers_version": "0.36.0",
4
+ "num_train_timesteps": 1000,
5
+ "stochastic_sampling": false
6
+ }
JiT-L-16-SIM/scheduler/scheduling_flow_match_fd.py ADDED
@@ -0,0 +1,110 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright 2026 The FD-Loss Authors. SPDX-License-Identifier: MIT
2
+ """Flow-matching scheduler for FD-Loss JiT sampling (t: 1 -> 0)."""
3
+
4
+ from __future__ import annotations
5
+
6
+ from dataclasses import dataclass
7
+ from typing import List, Optional, Tuple, Union
8
+
9
+ import torch
10
+ from diffusers.configuration_utils import ConfigMixin, register_to_config
11
+ from diffusers.schedulers.scheduling_utils import SchedulerMixin
12
+ from diffusers.utils import BaseOutput
13
+ from diffusers.utils.torch_utils import randn_tensor
14
+
15
+
16
+ @dataclass
17
+ class FDLossFlowMatchSchedulerOutput(BaseOutput):
18
+ prev_sample: torch.Tensor
19
+
20
+
21
+ class FDLossFlowMatchScheduler(SchedulerMixin, ConfigMixin):
22
+ """Euler flow-matching scheduler with optional stochastic steps and generator-aware noise."""
23
+
24
+ order = 1
25
+ config_name = "scheduler_config.json"
26
+
27
+ @register_to_config
28
+ def __init__(
29
+ self,
30
+ num_train_timesteps: int = 1000,
31
+ stochastic_sampling: bool = False,
32
+ ):
33
+ self.timesteps: Optional[torch.Tensor] = None
34
+ self.num_inference_steps: Optional[int] = None
35
+ self._step_index: Optional[int] = None
36
+
37
+ @property
38
+ def init_noise_sigma(self) -> float:
39
+ return 1.0
40
+
41
+ def set_timesteps(self, num_inference_steps: int, device: Union[str, torch.device, None] = None) -> torch.Tensor:
42
+ if num_inference_steps < 1:
43
+ raise ValueError("num_inference_steps must be >= 1.")
44
+ self.num_inference_steps = num_inference_steps
45
+ self.timesteps = torch.linspace(1.0, 0.0, num_inference_steps + 1, device=device, dtype=torch.float32)
46
+ self._step_index = 0
47
+ return self.timesteps
48
+
49
+ def scale_model_input(self, sample: torch.Tensor, timestep: Union[float, torch.Tensor]) -> torch.Tensor:
50
+ del timestep
51
+ return sample
52
+
53
+ def _resolve_step_index(self, timestep: Union[float, torch.Tensor, None]) -> int:
54
+ if self._step_index is not None:
55
+ return self._step_index
56
+ if self.timesteps is None:
57
+ raise ValueError("Call `set_timesteps` before `step`.")
58
+ if timestep is None:
59
+ return 0
60
+ t_value = float(timestep) if not isinstance(timestep, torch.Tensor) else float(timestep.reshape(-1)[0])
61
+ matches = (self.timesteps - t_value).abs() < 1e-6
62
+ if matches.any():
63
+ return int(matches.nonzero(as_tuple=False)[0].item())
64
+ return 0
65
+
66
+ @staticmethod
67
+ def _expand_time(value: torch.Tensor, sample: torch.Tensor) -> torch.Tensor:
68
+ value = value.to(dtype=sample.dtype, device=sample.device)
69
+ while value.ndim < sample.ndim:
70
+ value = value.unsqueeze(-1)
71
+ return value
72
+
73
+ def step(
74
+ self,
75
+ model_output: torch.Tensor,
76
+ timestep: Union[float, torch.Tensor, None],
77
+ sample: torch.Tensor,
78
+ return_dict: bool = True,
79
+ generator: Optional[Union[torch.Generator, List[torch.Generator]]] = None,
80
+ ) -> Union[FDLossFlowMatchSchedulerOutput, Tuple[torch.Tensor]]:
81
+ if self.timesteps is None:
82
+ raise ValueError("Call `set_timesteps` before `step`.")
83
+
84
+ step_index = self._resolve_step_index(timestep)
85
+ if step_index >= len(self.timesteps) - 1:
86
+ raise ValueError("Scheduler has already reached the final timestep.")
87
+
88
+ t = self.timesteps[step_index]
89
+ t_next = self.timesteps[step_index + 1]
90
+ dt = self._expand_time(t - t_next, sample)
91
+
92
+ if self.config.stochastic_sampling:
93
+ t_expanded = self._expand_time(t, sample)
94
+ t_next_expanded = self._expand_time(t_next, sample)
95
+ x0 = sample - t_expanded * model_output
96
+ noise = randn_tensor(
97
+ sample.shape,
98
+ generator=generator,
99
+ device=sample.device,
100
+ dtype=sample.dtype,
101
+ )
102
+ prev_sample = (1.0 - t_next_expanded) * x0 + t_next_expanded * noise
103
+ else:
104
+ prev_sample = sample - dt * model_output
105
+
106
+ self._step_index = step_index + 1
107
+
108
+ if not return_dict:
109
+ return (prev_sample,)
110
+ return FDLossFlowMatchSchedulerOutput(prev_sample=prev_sample)
JiT-L-16-SIM/transformer/config.json ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "_class_name": "JiTTransformer2DModel",
3
+ "_diffusers_version": "0.36.0",
4
+ "attention_dropout": 0.0,
5
+ "bottleneck_dim": 128,
6
+ "dropout": 0.0,
7
+ "hidden_size": 1024,
8
+ "in_channels": 3,
9
+ "in_context_len": 32,
10
+ "in_context_start": 8,
11
+ "mlp_ratio": 4.0,
12
+ "norm_eps": 1e-06,
13
+ "num_attention_heads": 16,
14
+ "num_classes": 1000,
15
+ "num_layers": 24,
16
+ "patch_size": 16,
17
+ "sample_size": 256
18
+ }
JiT-L-16-SIM/transformer/diffusion_pytorch_model.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:06c08d90b58a5423cc1db3cb5cd3537f6f42349e70abadca08ea48135a76d183
3
+ size 1836593656
JiT-L-16-SIM/transformer/jit_transformer_2d.py ADDED
@@ -0,0 +1,559 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ import math
16
+
17
+ import numpy as np
18
+ import torch
19
+ import torch.nn as nn
20
+ import torch.nn.functional as F
21
+
22
+ from diffusers.configuration_utils import ConfigMixin, register_to_config
23
+ from diffusers.models.modeling_outputs import Transformer2DModelOutput
24
+ from diffusers.models.modeling_utils import ModelMixin
25
+ from diffusers.models.normalization import RMSNorm
26
+ from diffusers.utils import logging
27
+
28
+ logger = logging.get_logger(__name__)
29
+
30
+
31
+
32
+ def broadcat(tensors, dim=-1):
33
+ num_tensors = len(tensors)
34
+ shape_lens = {len(t.shape) for t in tensors}
35
+ if len(shape_lens) != 1:
36
+ raise ValueError("tensors must all have the same number of dimensions")
37
+ shape_len = list(shape_lens)[0]
38
+ dim = (dim + shape_len) if dim < 0 else dim
39
+ dims = list(zip(*(list(t.shape) for t in tensors)))
40
+ expandable_dims = [(i, val) for i, val in enumerate(dims) if i != dim]
41
+
42
+ if not all(len(set(t[1])) <= 2 for t in expandable_dims):
43
+ raise ValueError("invalid dimensions for broadcastable concatenation")
44
+
45
+ max_dims = [(t[0], max(t[1])) for t in expandable_dims]
46
+ expanded_dims = [(t[0], (t[1],) * num_tensors) for t in max_dims]
47
+ expanded_dims.insert(dim, (dim, dims[dim]))
48
+ expandable_shapes = list(zip(*(t[1] for t in expanded_dims)))
49
+ tensors = [t[0].expand(*t[1]) for t in zip(tensors, expandable_shapes)]
50
+ return torch.cat(tensors, dim=dim)
51
+
52
+
53
+ def rotate_half(x):
54
+ x = x.view(*x.shape[:-1], x.shape[-1] // 2, 2)
55
+ x1, x2 = x.unbind(dim=-1)
56
+ x = torch.stack((-x2, x1), dim=-1)
57
+ return x.view(*x.shape[:-2], -1)
58
+
59
+
60
+ class JiTRotaryEmbedding(nn.Module):
61
+ def __init__(
62
+ self,
63
+ dim,
64
+ pt_seq_len=16,
65
+ ft_seq_len=None,
66
+ custom_freqs=None,
67
+ theta=10000,
68
+ num_cls_token=0,
69
+ ):
70
+ super().__init__()
71
+ self.dim = dim
72
+ self.pt_seq_len = pt_seq_len
73
+ self.theta = theta
74
+ self.num_cls_token = num_cls_token
75
+ self.custom_freqs = custom_freqs
76
+ if ft_seq_len is None:
77
+ ft_seq_len = pt_seq_len
78
+ self._cached_hw = None
79
+ cos, sin = self._build_freqs(ft_seq_len, ft_seq_len, device=torch.device("cpu"))
80
+ self.register_buffer("freqs_cos", cos, persistent=False)
81
+ self.register_buffer("freqs_sin", sin, persistent=False)
82
+ self._cached_hw = (ft_seq_len, ft_seq_len)
83
+
84
+ def _build_freqs(self, height, width, device):
85
+ if self.custom_freqs is not None:
86
+ freqs = self.custom_freqs.to(device=device, dtype=torch.float32)
87
+ else:
88
+ freqs = 1.0 / (
89
+ self.theta ** (torch.arange(0, self.dim, 2, device=device, dtype=torch.float32)[: (self.dim // 2)] / self.dim)
90
+ )
91
+
92
+ t_h = torch.arange(height, device=device, dtype=torch.float32) / height * self.pt_seq_len
93
+ t_w = torch.arange(width, device=device, dtype=torch.float32) / width * self.pt_seq_len
94
+ freqs_h = torch.einsum("..., f -> ... f", t_h, freqs).repeat_interleave(2, dim=-1)
95
+ freqs_w = torch.einsum("..., f -> ... f", t_w, freqs).repeat_interleave(2, dim=-1)
96
+ freqs_2d = broadcat((freqs_h[:, None, :], freqs_w[None, :, :]), dim=-1)
97
+ freqs_flat = freqs_2d.view(-1, freqs_2d.shape[-1])
98
+ cos_img = freqs_flat.cos()
99
+ sin_img = freqs_flat.sin()
100
+ if self.num_cls_token > 0:
101
+ _, dim_freq = cos_img.shape
102
+ cos_pad = torch.ones(self.num_cls_token, dim_freq, dtype=cos_img.dtype, device=device)
103
+ sin_pad = torch.zeros(self.num_cls_token, dim_freq, dtype=sin_img.dtype, device=device)
104
+ cos_img = torch.cat([cos_pad, cos_img], dim=0)
105
+ sin_img = torch.cat([sin_pad, sin_img], dim=0)
106
+ return cos_img, sin_img
107
+
108
+ def forward(self, t, height=None, width=None):
109
+ # Applied on (batch, seq_len, heads, head_dim) tensors from attention.
110
+ seq_len = t.shape[1]
111
+ if height is None or width is None:
112
+ image_tokens = seq_len - self.num_cls_token
113
+ size = int(image_tokens**0.5)
114
+ if size * size != image_tokens:
115
+ raise ValueError(
116
+ f"Cannot infer square token grid from sequence length {seq_len} with {self.num_cls_token} class tokens."
117
+ )
118
+ height = size
119
+ width = size
120
+ if self._cached_hw != (height, width) or self.freqs_cos.device != t.device:
121
+ self.freqs_cos, self.freqs_sin = self._build_freqs(height, width, device=t.device)
122
+ self._cached_hw = (height, width)
123
+ freqs_cos = self.freqs_cos[:seq_len].to(t.dtype)
124
+ freqs_sin = self.freqs_sin[:seq_len].to(t.dtype)
125
+
126
+ return t * freqs_cos[:, None, :] + rotate_half(t) * freqs_sin[:, None, :]
127
+
128
+
129
+ def modulate(x, shift, scale):
130
+ return x * (1 + scale.unsqueeze(1)) + shift.unsqueeze(1)
131
+
132
+
133
+ class JiTPatchEmbed(nn.Module):
134
+ """Image to Patch Embedding with Bottleneck"""
135
+
136
+ def __init__(self, img_size=224, patch_size=16, in_chans=3, pca_dim=768, embed_dim=768, bias=True):
137
+ super().__init__()
138
+ img_size = (img_size, img_size)
139
+ patch_size = (patch_size, patch_size)
140
+ self.img_size = img_size
141
+ self.patch_size = patch_size
142
+ self.num_patches = (img_size[1] // patch_size[1]) * (img_size[0] // patch_size[0])
143
+
144
+ self.proj1 = nn.Conv2d(in_chans, pca_dim, kernel_size=patch_size, stride=patch_size, bias=False)
145
+ self.proj2 = nn.Conv2d(pca_dim, embed_dim, kernel_size=1, stride=1, bias=bias)
146
+
147
+ def forward(self, x):
148
+ x = self.proj2(self.proj1(x)).flatten(2).transpose(1, 2)
149
+ return x
150
+
151
+
152
+ class JiTTimestepEmbedder(nn.Module):
153
+ """
154
+ Embeds scalar timesteps into vector representations.
155
+ """
156
+
157
+ def __init__(self, hidden_size, frequency_embedding_size=256):
158
+ super().__init__()
159
+ self.mlp = nn.Sequential(
160
+ nn.Linear(frequency_embedding_size, hidden_size, bias=True),
161
+ nn.SiLU(),
162
+ nn.Linear(hidden_size, hidden_size, bias=True),
163
+ )
164
+ self.frequency_embedding_size = frequency_embedding_size
165
+
166
+ @staticmethod
167
+ def timestep_embedding(t, dim, max_period=10000):
168
+ """
169
+ Create sinusoidal timestep embeddings.
170
+ """
171
+ half = dim // 2
172
+ freqs = torch.exp(
173
+ -math.log(max_period) * torch.arange(start=0, end=half, dtype=torch.float32) / half
174
+ ).to(device=t.device)
175
+ args = t[:, None].float() * freqs[None]
176
+ embedding = torch.cat([torch.cos(args), torch.sin(args)], dim=-1)
177
+ if dim % 2:
178
+ embedding = torch.cat([embedding, torch.zeros_like(embedding[:, :1])], dim=-1)
179
+ return embedding
180
+
181
+ def forward(self, t, dtype=None):
182
+ t_freq = self.timestep_embedding(t, self.frequency_embedding_size)
183
+ if dtype is not None:
184
+ t_freq = t_freq.to(dtype=dtype)
185
+ t_emb = self.mlp(t_freq)
186
+ return t_emb
187
+
188
+
189
+ class JiTLabelEmbedder(nn.Module):
190
+ """
191
+ Embeds class labels into vector representations.
192
+ """
193
+
194
+ def __init__(self, num_classes, hidden_size):
195
+ super().__init__()
196
+ self.embedding_table = nn.Embedding(num_classes + 1, hidden_size)
197
+ self.num_classes = num_classes
198
+
199
+ def forward(self, labels):
200
+ embeddings = self.embedding_table(labels)
201
+ return embeddings
202
+
203
+
204
+ class JiTAttention(nn.Module):
205
+ def __init__(self, dim, num_heads=8, qkv_bias=True, qk_norm=True, attn_drop=0.0, proj_drop=0.0, eps=1e-6):
206
+ super().__init__()
207
+ self.num_heads = num_heads
208
+ head_dim = dim // num_heads
209
+
210
+ self.q_norm = RMSNorm(head_dim, eps=eps) if qk_norm else nn.Identity()
211
+ self.k_norm = RMSNorm(head_dim, eps=eps) if qk_norm else nn.Identity()
212
+
213
+ self.qkv = nn.Linear(dim, dim * 3, bias=qkv_bias)
214
+ self.attn_drop = attn_drop
215
+ self.proj = nn.Linear(dim, dim)
216
+ self.proj_drop = nn.Dropout(proj_drop)
217
+
218
+ def forward(self, x, rope=None, grid_height=None, grid_width=None):
219
+ B, N, C = x.shape
220
+ qkv = self.qkv(x).reshape(B, N, 3, self.num_heads, C // self.num_heads).permute(2, 0, 3, 1, 4)
221
+ q, k, v = qkv[0], qkv[1], qkv[2]
222
+
223
+ q = self.q_norm(q)
224
+ k = self.k_norm(k)
225
+
226
+ if rope is not None:
227
+ q = q.transpose(1, 2)
228
+ k = k.transpose(1, 2)
229
+ q = rope(q, height=grid_height, width=grid_width)
230
+ k = rope(k, height=grid_height, width=grid_width)
231
+ q = q.transpose(1, 2)
232
+ k = k.transpose(1, 2)
233
+
234
+ dropout_p = self.attn_drop if self.training else 0.0
235
+ x = F.scaled_dot_product_attention(q, k, v, dropout_p=dropout_p)
236
+ x = x.transpose(1, 2).reshape(B, N, C)
237
+ x = self.proj(x)
238
+ x = self.proj_drop(x)
239
+ return x
240
+
241
+
242
+ class JiTSwiGLUFFN(nn.Module):
243
+ def __init__(self, dim: int, hidden_dim: int, drop=0.0, bias=True) -> None:
244
+ super().__init__()
245
+ hidden_dim = int(hidden_dim * 2 / 3)
246
+ self.w12 = nn.Linear(dim, 2 * hidden_dim, bias=bias)
247
+ self.w3 = nn.Linear(hidden_dim, dim, bias=bias)
248
+ self.ffn_dropout = nn.Dropout(drop)
249
+
250
+ def forward(self, x):
251
+ x12 = self.w12(x)
252
+ x1, x2 = x12.chunk(2, dim=-1)
253
+ hidden = F.silu(x1) * x2
254
+ return self.w3(self.ffn_dropout(hidden))
255
+
256
+
257
+ class JiTBlock(nn.Module):
258
+ def __init__(self, hidden_size, num_heads, mlp_ratio=4.0, attn_drop=0.0, proj_drop=0.0, eps=1e-6):
259
+ super().__init__()
260
+ self.norm1 = RMSNorm(hidden_size, eps=eps)
261
+ self.attn = JiTAttention(
262
+ hidden_size,
263
+ num_heads=num_heads,
264
+ qkv_bias=True,
265
+ qk_norm=True,
266
+ attn_drop=attn_drop,
267
+ proj_drop=proj_drop,
268
+ eps=eps,
269
+ )
270
+ self.norm2 = RMSNorm(hidden_size, eps=eps)
271
+ mlp_hidden_dim = int(hidden_size * mlp_ratio)
272
+ self.mlp = JiTSwiGLUFFN(hidden_size, mlp_hidden_dim, drop=proj_drop)
273
+
274
+ self.act = nn.SiLU()
275
+ self.adaLN_modulation = nn.Linear(hidden_size, 6 * hidden_size, bias=True)
276
+
277
+ def forward(self, x, c, feat_rope=None, grid_height=None, grid_width=None):
278
+ # Apply activation
279
+ c = self.act(c)
280
+
281
+ shift_msa, scale_msa, gate_msa, shift_mlp, scale_mlp, gate_mlp = self.adaLN_modulation(c).chunk(6, dim=-1)
282
+
283
+ # Attention block
284
+ norm_x = self.norm1(x)
285
+ modulated_x = modulate(norm_x, shift_msa, scale_msa)
286
+ attn_out = self.attn(modulated_x, rope=feat_rope, grid_height=grid_height, grid_width=grid_width)
287
+ x = x + gate_msa.unsqueeze(1) * attn_out
288
+
289
+ # MLP block
290
+ norm_x = self.norm2(x)
291
+ modulated_x = modulate(norm_x, shift_mlp, scale_mlp)
292
+ mlp_out = self.mlp(modulated_x)
293
+ x = x + gate_mlp.unsqueeze(1) * mlp_out
294
+
295
+ return x
296
+
297
+
298
+ def get_2d_sincos_pos_embed(embed_dim, grid_size, cls_token=False, extra_tokens=0):
299
+ grid_h = np.arange(grid_size, dtype=np.float32)
300
+ grid_w = np.arange(grid_size, dtype=np.float32)
301
+ grid = np.meshgrid(grid_w, grid_h)
302
+ grid = np.stack(grid, axis=0)
303
+ grid = grid.reshape([2, 1, grid_size, grid_size])
304
+ pos_embed = get_2d_sincos_pos_embed_from_grid(embed_dim, grid)
305
+ if cls_token and extra_tokens > 0:
306
+ pos_embed = np.concatenate([np.zeros([extra_tokens, embed_dim]), pos_embed], axis=0)
307
+ return pos_embed
308
+
309
+
310
+ def get_2d_sincos_pos_embed_from_grid(embed_dim, grid):
311
+ if embed_dim % 2 != 0:
312
+ raise ValueError(f"embed_dim must be divisible by 2, but got {embed_dim}")
313
+
314
+ emb_h = get_1d_sincos_pos_embed_from_grid(embed_dim // 2, grid[0])
315
+ emb_w = get_1d_sincos_pos_embed_from_grid(embed_dim // 2, grid[1])
316
+ emb = np.concatenate([emb_h, emb_w], axis=1)
317
+ return emb
318
+
319
+
320
+ def get_1d_sincos_pos_embed_from_grid(embed_dim, pos):
321
+ if embed_dim % 2 != 0:
322
+ raise ValueError(f"embed_dim must be divisible by 2, but got {embed_dim}")
323
+
324
+ omega = np.arange(embed_dim // 2, dtype=np.float64)
325
+ omega /= embed_dim / 2.0
326
+ omega = 1.0 / 10000**omega
327
+
328
+ pos = pos.reshape(-1)
329
+ out = np.einsum("m,d->md", pos, omega)
330
+
331
+ emb_sin = np.sin(out)
332
+ emb_cos = np.cos(out)
333
+
334
+ emb = np.concatenate([emb_sin, emb_cos], axis=1)
335
+ return emb
336
+
337
+
338
+ class JiTTransformer2DModel(ModelMixin, ConfigMixin):
339
+ r"""
340
+ A 2D Transformer for pixel-space class-conditional generation with JiT
341
+ ([Back to Basics: Let Denoising Generative Models Denoise](https://arxiv.org/abs/2511.13720)).
342
+
343
+ Parameters:
344
+ sample_size (`int`, defaults to `256`):
345
+ Input image resolution (height and width).
346
+ patch_size (`int`, defaults to `16`):
347
+ Patch size for the bottleneck patch embedder.
348
+ in_channels (`int`, defaults to `3`):
349
+ Number of input image channels.
350
+ hidden_size (`int`, defaults to `768`):
351
+ Transformer hidden dimension.
352
+ num_layers (`int`, defaults to `12`):
353
+ Number of JiT transformer blocks.
354
+ num_attention_heads (`int`, defaults to `12`):
355
+ Number of attention heads per block.
356
+ mlp_ratio (`float`, defaults to `4.0`):
357
+ MLP hidden dimension multiplier.
358
+ attention_dropout (`float`, defaults to `0.0`):
359
+ Attention dropout in the middle quarter of blocks.
360
+ dropout (`float`, defaults to `0.0`):
361
+ Projection dropout in the middle quarter of blocks.
362
+ num_classes (`int`, defaults to `1000`):
363
+ Number of class labels (null label uses index `num_classes` for CFG).
364
+ bottleneck_dim (`int`, defaults to `128`):
365
+ PCA bottleneck dimension in the patch embedder.
366
+ in_context_len (`int`, defaults to `32`):
367
+ Number of in-context class tokens prepended mid-network.
368
+ in_context_start (`int`, defaults to `4`):
369
+ Block index at which in-context tokens are inserted.
370
+ norm_eps (`float`, defaults to `1e-6`):
371
+ Epsilon for RMSNorm layers.
372
+ """
373
+
374
+ _supports_gradient_checkpointing = True
375
+ _skip_layerwise_casting_patterns = ["pos_embed", "norm"]
376
+
377
+ @register_to_config
378
+ def __init__(
379
+ self,
380
+ sample_size: int = 256,
381
+ patch_size: int = 16,
382
+ in_channels: int = 3,
383
+ hidden_size: int = 768,
384
+ num_layers: int = 12,
385
+ num_attention_heads: int = 12,
386
+ mlp_ratio: float = 4.0,
387
+ attention_dropout: float = 0.0,
388
+ dropout: float = 0.0,
389
+ num_classes: int = 1000,
390
+ bottleneck_dim: int = 128,
391
+ in_context_len: int = 32,
392
+ in_context_start: int = 4,
393
+ norm_eps: float = 1e-6,
394
+ ):
395
+ super().__init__()
396
+ self.sample_size = sample_size
397
+ self.patch_size = patch_size
398
+ self.in_channels = in_channels
399
+ self.out_channels = in_channels
400
+ self.hidden_size = hidden_size
401
+ self.num_layers = num_layers
402
+ self.num_attention_heads = num_attention_heads
403
+ self.in_context_len = in_context_len
404
+ self.in_context_start = in_context_start
405
+ self.norm_eps = norm_eps
406
+ self.gradient_checkpointing = False
407
+
408
+ # Time and Class Embedding
409
+ self.t_embedder = JiTTimestepEmbedder(hidden_size)
410
+ self.y_embedder = JiTLabelEmbedder(num_classes, hidden_size)
411
+
412
+ # Patch Embedding
413
+ self.x_embedder = JiTPatchEmbed(
414
+ img_size=sample_size,
415
+ patch_size=patch_size,
416
+ in_chans=in_channels,
417
+ pca_dim=bottleneck_dim,
418
+ embed_dim=hidden_size,
419
+ bias=True,
420
+ )
421
+
422
+ # Positional Embedding (Fixed Sin-Cos)
423
+ num_patches = self.x_embedder.num_patches
424
+ pos_embed = get_2d_sincos_pos_embed(hidden_size, int(num_patches**0.5))
425
+ self.register_buffer("pos_embed", torch.from_numpy(pos_embed).float().unsqueeze(0), persistent=True)
426
+
427
+ # In-context Embedding
428
+ if self.in_context_len > 0:
429
+ self.in_context_posemb = nn.Parameter(torch.zeros(1, self.in_context_len, hidden_size))
430
+
431
+ # RoPE
432
+ half_head_dim = hidden_size // num_attention_heads // 2
433
+ hw_seq_len = sample_size // patch_size
434
+ self.feat_rope = JiTRotaryEmbedding(dim=half_head_dim, pt_seq_len=hw_seq_len, num_cls_token=0)
435
+ self.feat_rope_incontext = JiTRotaryEmbedding(
436
+ dim=half_head_dim, pt_seq_len=hw_seq_len, num_cls_token=self.in_context_len
437
+ )
438
+
439
+ # Blocks
440
+ self.blocks = nn.ModuleList(
441
+ [
442
+ JiTBlock(
443
+ hidden_size,
444
+ num_attention_heads,
445
+ mlp_ratio=mlp_ratio,
446
+ attn_drop=attention_dropout if (num_layers // 4 * 3 > i >= num_layers // 4) else 0.0,
447
+ proj_drop=dropout if (num_layers // 4 * 3 > i >= num_layers // 4) else 0.0,
448
+ eps=norm_eps,
449
+ )
450
+ for i in range(num_layers)
451
+ ]
452
+ )
453
+
454
+ # Final Layer
455
+ self.norm_final = RMSNorm(hidden_size, eps=norm_eps)
456
+ self.linear_final = nn.Linear(hidden_size, patch_size * patch_size * self.out_channels, bias=True)
457
+ self.act_final = nn.SiLU()
458
+ self.adaLN_modulation_final = nn.Linear(hidden_size, 2 * hidden_size, bias=True)
459
+
460
+ def _get_patch_grid(self, hidden_states):
461
+ height, width = hidden_states.shape[-2:]
462
+ if height % self.patch_size != 0 or width % self.patch_size != 0:
463
+ raise ValueError(
464
+ f"Input size {(height, width)} must be divisible by patch_size={self.patch_size}."
465
+ )
466
+ return height // self.patch_size, width // self.patch_size
467
+
468
+ def _interpolate_pos_encoding(self, tokens, grid_height, grid_width):
469
+ num_tokens = grid_height * grid_width
470
+ if self.pos_embed.shape[1] == num_tokens:
471
+ return self.pos_embed.to(device=tokens.device, dtype=tokens.dtype)
472
+ base_size = int(self.pos_embed.shape[1] ** 0.5)
473
+ pos_embed = self.pos_embed.reshape(1, base_size, base_size, self.hidden_size).permute(0, 3, 1, 2)
474
+ pos_embed = F.interpolate(pos_embed, size=(grid_height, grid_width), mode="bicubic", align_corners=False)
475
+ pos_embed = pos_embed.permute(0, 2, 3, 1).reshape(1, num_tokens, self.hidden_size)
476
+ return pos_embed.to(device=tokens.device, dtype=tokens.dtype)
477
+
478
+ def forward(
479
+ self,
480
+ hidden_states: torch.Tensor,
481
+ timestep: torch.LongTensor,
482
+ class_labels: torch.LongTensor,
483
+ interpolate_pos_encoding: bool = True,
484
+ return_dict: bool = True,
485
+ ):
486
+
487
+ t_emb = self.t_embedder(timestep, dtype=hidden_states.dtype)
488
+ y_emb = self.y_embedder(class_labels)
489
+
490
+ # Ensure embeddings match hidden_states dtype
491
+ y_emb = y_emb.to(dtype=hidden_states.dtype)
492
+
493
+ c = t_emb + y_emb
494
+
495
+ # Patch Embed
496
+ grid_height, grid_width = self._get_patch_grid(hidden_states)
497
+ x = self.x_embedder(hidden_states)
498
+ if interpolate_pos_encoding:
499
+ pos_embed = self._interpolate_pos_encoding(x, grid_height, grid_width)
500
+ else:
501
+ expected_tokens = grid_height * grid_width
502
+ if self.pos_embed.shape[1] != expected_tokens:
503
+ raise ValueError(
504
+ f"pos_embed token count {self.pos_embed.shape[1]} does not match input token count {expected_tokens}. "
505
+ "Enable interpolate_pos_encoding for dynamic resolutions."
506
+ )
507
+ pos_embed = self.pos_embed.to(device=x.device, dtype=x.dtype)
508
+ x = x + pos_embed
509
+
510
+ # Blocks
511
+ for i, block in enumerate(self.blocks):
512
+ if self.in_context_len > 0 and i == self.in_context_start:
513
+ in_context_tokens = y_emb.unsqueeze(1).repeat(1, self.in_context_len, 1)
514
+ in_context_tokens = in_context_tokens + self.in_context_posemb.to(in_context_tokens.dtype)
515
+ x = torch.cat([in_context_tokens, x], dim=1)
516
+
517
+ rope = self.feat_rope if i < self.in_context_start else self.feat_rope_incontext
518
+
519
+ if self.training and self.gradient_checkpointing:
520
+ def custom_forward(current_x, current_c):
521
+ return block(
522
+ current_x,
523
+ current_c,
524
+ feat_rope=rope,
525
+ grid_height=grid_height,
526
+ grid_width=grid_width,
527
+ )
528
+
529
+ x = torch.utils.checkpoint.checkpoint(
530
+ custom_forward,
531
+ x,
532
+ c,
533
+ use_reentrant=False,
534
+ )
535
+ else:
536
+ x = block(x, c, feat_rope=rope, grid_height=grid_height, grid_width=grid_width)
537
+
538
+ # Slice off in-context tokens
539
+ if self.in_context_len > 0:
540
+ x = x[:, self.in_context_len :]
541
+
542
+ # Final Layer
543
+ c = self.act_final(c)
544
+ shift, scale = self.adaLN_modulation_final(c).chunk(2, dim=1)
545
+
546
+ x = modulate(self.norm_final(x), shift, scale)
547
+ x = self.linear_final(x)
548
+
549
+ # Unpatchify
550
+ x = x.reshape(shape=(x.shape[0], grid_height, grid_width, self.patch_size, self.patch_size, self.out_channels))
551
+ x = torch.einsum("nhwpqc->nchpwq", x)
552
+ output = x.reshape(
553
+ shape=(x.shape[0], self.out_channels, grid_height * self.patch_size, grid_width * self.patch_size)
554
+ )
555
+
556
+ if not return_dict:
557
+ return (output,)
558
+
559
+ return Transformer2DModelOutput(sample=output)
README.md ADDED
@@ -0,0 +1,255 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: mit
3
+ library_name: diffusers
4
+ pipeline_tag: text-to-image
5
+ tags:
6
+ - diffusers
7
+ - fd-loss
8
+ - jit
9
+ - imf
10
+ - pmf
11
+ - image-generation
12
+ - class-conditional
13
+ - imagenet
14
+ inference: true
15
+ widget:
16
+ - output:
17
+ url: JiT-H-16-SIM/demo.png
18
+ language:
19
+ - en
20
+ ---
21
+
22
+ # FD-Loss-diffusers
23
+
24
+ Post-training checkpoints with the same JiT / iMF / pMF architectures as the base models, distilled with FD-loss (feature distillation).
25
+
26
+ - **JiT**: all `/16` variants for 256px generation
27
+ - **iMF**: all variants for 256px generation
28
+ - **pMF**: both `/16` and `/32`
29
+ - **SIM** suffix: SigLIP + Inception + MAE FD-loss
30
+ - Default inference: **1 NFE** (`num_inference_steps=1`)
31
+
32
+ FD-Loss JiT uses **legacy time convention** and **velocity Euler** via bundled `FDLossFlowMatchScheduler` (`scheduler/scheduling_flow_match_fd.py`; timesteps `t=1→0`).
33
+
34
+ ## Demo
35
+
36
+ ![JiT-H-16-SIM demo](JiT-H-16-SIM/demo.png)
37
+
38
+ Class-conditional sample (ImageNet class **golden retriever**), `JiT-H/16` FD-SIM at 256×256, 1 NFE, CFG 2.2, interval [0.1, 1.0], seed 42.
39
+
40
+ ## Inference (`JiT-B-16-SIM`)
41
+
42
+ ```python
43
+ from pathlib import Path
44
+ import torch
45
+ from diffusers import DiffusionPipeline
46
+
47
+ model_dir = Path("./JiT-B-16-SIM")
48
+ pipe = DiffusionPipeline.from_pretrained(
49
+ str(model_dir),
50
+ custom_pipeline=str(model_dir / "pipeline.py"),
51
+ trust_remote_code=True,
52
+ )
53
+ pipe.to("cuda")
54
+
55
+ generator = torch.Generator(device="cuda").manual_seed(42)
56
+ image = pipe(
57
+ class_labels="golden retriever",
58
+ num_inference_steps=1, # 1 NFE (FD-Loss default)
59
+ guidance_scale=3.0,
60
+ guidance_interval_min=0.1,
61
+ guidance_interval_max=1.0,
62
+ generator=generator,
63
+ ).images[0]
64
+ ```
65
+
66
+ | Parameter | JiT-B-16-SIM default | Source |
67
+ | --- | --- | --- |
68
+ | `num_inference_steps` | `1` | `--num_sampling_steps 1` |
69
+ | `guidance_scale` | `3.0` | JiT_B eval preset |
70
+ | `guidance_interval_min` / `max` | `0.1` / `1.0` | JiT_B eval preset |
71
+ | `legacy_time_convention` | `True` (pipeline default) | `--legacy_time_convention` |
72
+
73
+ ## Inference (`JiT-L-16-SIM`)
74
+
75
+ Same loading pattern as JiT-B; use **CFG 2.4** (JiT_L eval preset):
76
+
77
+ ```python
78
+ model_dir = Path("./JiT-L-16-SIM")
79
+ pipe = DiffusionPipeline.from_pretrained(
80
+ str(model_dir),
81
+ custom_pipeline=str(model_dir / "pipeline.py"),
82
+ trust_remote_code=True,
83
+ ).to("cuda")
84
+
85
+ image = pipe(
86
+ class_labels="golden retriever",
87
+ num_inference_steps=1,
88
+ guidance_scale=2.4,
89
+ generator=torch.Generator(device="cuda").manual_seed(42),
90
+ ).images[0]
91
+ ```
92
+
93
+ ## Inference (`JiT-H-16-SIM`)
94
+
95
+ Same loading pattern as JiT-B/L; use **CFG 2.2** (JiT_H eval preset):
96
+
97
+ ```python
98
+ model_dir = Path("./JiT-H-16-SIM")
99
+ pipe = DiffusionPipeline.from_pretrained(
100
+ str(model_dir),
101
+ custom_pipeline=str(model_dir / "pipeline.py"),
102
+ trust_remote_code=True,
103
+ ).to("cuda")
104
+
105
+ image = pipe(
106
+ class_labels="golden retriever",
107
+ num_inference_steps=1,
108
+ guidance_scale=2.2,
109
+ guidance_interval_min=0.1,
110
+ guidance_interval_max=1.0,
111
+ generator=torch.Generator(device="cuda").manual_seed(42),
112
+ ).images[0]
113
+ ```
114
+
115
+
116
+ ## Available variants
117
+
118
+ | Variant | Path | Architecture | Resolution | CFG (1 NFE) |
119
+ | --- | --- | --- | --- | --- |
120
+ | JiT-B-16-SIM | `./JiT-B-16-SIM` | JiT-B/16 | 256×256 | 3.0 |
121
+ | JiT-L-16-SIM | `./JiT-L-16-SIM` | JiT-L/16 | 256×256 | 2.4 |
122
+ | JiT-H-16-SIM | `./JiT-H-16-SIM` | JiT-H/16 | 256×256 | 2.2 |
123
+ | iMF-B-SIM | `./iMF-B-SIM` | iMF-B/2 | 256×256 | 8.0 |
124
+ | iMF-L-SIM | `./iMF-L-SIM` | iMF-L/2 | 256×256 | 8.0 |
125
+ | iMF-XL-SIM | `./iMF-XL-SIM` | iMF-XL/2 | 256×256 | 8.0 |
126
+ | pMF-B-16-SIM | `./pMF-B-16-SIM` | pMF-B/16 | 256×256 | 7.5 |
127
+ | pMF-B-32-SIM | `./pMF-B-32-SIM` | pMF-B/32 | 512×512 | 6.5 |
128
+ | pMF-L-16-SIM | `./pMF-L-16-SIM` | pMF-L/16 | 256×256 | 7.0 |
129
+ | pMF-L-32-SIM | `./pMF-L-32-SIM` | pMF-L/32 | 512×512 | 7.5 |
130
+ | pMF-H-32-SIM | `./pMF-H-32-SIM` | pMF-H/32 | 512×512 | 5.5 |
131
+
132
+ ## Inference (`iMF-B-SIM`)
133
+
134
+ Uses production `IMFPipeline` from `iMF-diffusers/iMF-B-2` (native iMF time convention, not legacy JiT time). Use **`torch.float32`** (same as base iMF variants):
135
+
136
+ ```python
137
+ model_dir = Path("./iMF-B-SIM")
138
+ pipe = DiffusionPipeline.from_pretrained(
139
+ str(model_dir),
140
+ custom_pipeline=str(model_dir / "pipeline.py"),
141
+ trust_remote_code=True,
142
+ torch_dtype=torch.float32,
143
+ ).to("cuda")
144
+
145
+ image = pipe(
146
+ class_labels="golden retriever",
147
+ num_inference_steps=1,
148
+ guidance_scale=8.0,
149
+ guidance_interval_start=0.4,
150
+ guidance_interval_end=0.65,
151
+ generator=torch.Generator(device="cuda").manual_seed(42),
152
+ ).images[0]
153
+ ```
154
+
155
+ ## Inference (`iMF-L-SIM`)
156
+
157
+ Same loading pattern as iMF-B-SIM (production `IMFPipeline` from `iMF-diffusers/iMF-L-2`):
158
+
159
+ ```python
160
+ model_dir = Path("./iMF-L-SIM")
161
+ pipe = DiffusionPipeline.from_pretrained(
162
+ str(model_dir),
163
+ custom_pipeline=str(model_dir / "pipeline.py"),
164
+ trust_remote_code=True,
165
+ torch_dtype=torch.float32,
166
+ ).to("cuda")
167
+
168
+ image = pipe(
169
+ class_labels="golden retriever",
170
+ num_inference_steps=1,
171
+ guidance_scale=8.0,
172
+ guidance_interval_start=0.4,
173
+ guidance_interval_end=0.65,
174
+ generator=torch.Generator(device="cuda").manual_seed(42),
175
+ ).images[0]
176
+ ```
177
+
178
+ Regenerate from checkpoint:
179
+
180
+ ```bash
181
+ python _convert_imf_l_fd_sim.py
182
+ ```
183
+
184
+ ## Inference (`iMF-XL-SIM`)
185
+
186
+ Same loading pattern as iMF-B/L-SIM (production `IMFPipeline` from `iMF-diffusers/iMF-XL-2`):
187
+
188
+ ```python
189
+ model_dir = Path("./iMF-XL-SIM")
190
+ pipe = DiffusionPipeline.from_pretrained(
191
+ str(model_dir),
192
+ custom_pipeline=str(model_dir / "pipeline.py"),
193
+ trust_remote_code=True,
194
+ torch_dtype=torch.float32,
195
+ ).to("cuda")
196
+
197
+ image = pipe(
198
+ class_labels="golden retriever",
199
+ num_inference_steps=1,
200
+ guidance_scale=8.0,
201
+ guidance_interval_start=0.4,
202
+ guidance_interval_end=0.65,
203
+ generator=torch.Generator(device="cuda").manual_seed(42),
204
+ ).images[0]
205
+ ```
206
+
207
+
208
+ ## Inference (`pMF-B-16-SIM`)
209
+
210
+ Uses production `PMFPipeline` from `pMF-diffusers/pMF-B-16` (native pMF time convention). Use **`torch.bfloat16`** on CUDA:
211
+
212
+ ```python
213
+ model_dir = Path("./pMF-B-16-SIM")
214
+ pipe = DiffusionPipeline.from_pretrained(
215
+ str(model_dir),
216
+ custom_pipeline=str(model_dir / "pipeline.py"),
217
+ trust_remote_code=True,
218
+ torch_dtype=torch.bfloat16,
219
+ ).to("cuda")
220
+
221
+ image = pipe(
222
+ class_labels="golden retriever",
223
+ num_inference_steps=1,
224
+ guidance_scale=7.5,
225
+ guidance_interval_min=0.1,
226
+ guidance_interval_max=0.8,
227
+ noise_scale=1.0,
228
+ generator=torch.Generator(device="cuda").manual_seed(42),
229
+ ).images[0]
230
+ ```
231
+
232
+ ## Inference (`pMF-B-32-SIM`)
233
+
234
+ Same loading pattern as pMF-B-16-SIM (production `PMFPipeline` from `pMF-diffusers/pMF-B-32`):
235
+
236
+ ```python
237
+ model_dir = Path("./pMF-B-32-SIM")
238
+ pipe = DiffusionPipeline.from_pretrained(
239
+ str(model_dir),
240
+ custom_pipeline=str(model_dir / "pipeline.py"),
241
+ trust_remote_code=True,
242
+ torch_dtype=torch.bfloat16,
243
+ ).to("cuda")
244
+
245
+ image = pipe(
246
+ class_labels="golden retriever",
247
+ num_inference_steps=1,
248
+ guidance_scale=6.5,
249
+ guidance_interval_min=0.1,
250
+ guidance_interval_max=0.7,
251
+ noise_scale=2.0,
252
+ generator=torch.Generator(device="cuda").manual_seed(42),
253
+ ).images[0]
254
+ ```
255
+
iMF-B-SIM/README.md ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: mit
3
+ library_name: diffusers
4
+ pipeline_tag: text-to-image
5
+ tags:
6
+ - diffusers
7
+ - imf
8
+ - image-generation
9
+ - class-conditional
10
+ ---
11
+
12
+ # iMF-B-SIM
13
+
14
+ Self-contained Diffusers variant for **iMF-B/2 (FD-SIM post-trained)** (Improved Mean Flows).
15
+
16
+ ## Load
17
+
18
+ ```python
19
+ from pathlib import Path
20
+ from diffusers import DiffusionPipeline
21
+ import torch
22
+
23
+ model_dir = Path("iMF-B-SIM")
24
+ pipe = DiffusionPipeline.from_pretrained(
25
+ str(model_dir),
26
+ local_files_only=True,
27
+ custom_pipeline=str(model_dir / "pipeline.py"),
28
+ trust_remote_code=True,
29
+ torch_dtype=torch.float32,
30
+ )
31
+ pipe.to("cuda")
32
+
33
+ image = pipe(
34
+ class_labels=207,
35
+ num_inference_steps=1,
36
+ guidance_scale=8.0,
37
+ guidance_interval_start=0.4,
38
+ guidance_interval_end=0.65,
39
+ ).images[0]
40
+ ```
iMF-B-SIM/model_index.json ADDED
@@ -0,0 +1,1021 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "_class_name": [
3
+ "pipeline",
4
+ "IMFPipeline"
5
+ ],
6
+ "_diffusers_version": "0.36.0",
7
+ "scheduler": [
8
+ "scheduling_imf",
9
+ "IMFScheduler"
10
+ ],
11
+ "transformer": [
12
+ "transformer_imf",
13
+ "IMFTransformer2DModel"
14
+ ],
15
+ "id2label": {
16
+ "0": "tench, Tinca tinca",
17
+ "1": "goldfish, Carassius auratus",
18
+ "2": "great white shark, white shark, man-eater, man-eating shark, Carcharodon carcharias",
19
+ "3": "tiger shark, Galeocerdo cuvieri",
20
+ "4": "hammerhead, hammerhead shark",
21
+ "5": "electric ray, crampfish, numbfish, torpedo",
22
+ "6": "stingray",
23
+ "7": "cock",
24
+ "8": "hen",
25
+ "9": "ostrich, Struthio camelus",
26
+ "10": "brambling, Fringilla montifringilla",
27
+ "11": "goldfinch, Carduelis carduelis",
28
+ "12": "house finch, linnet, Carpodacus mexicanus",
29
+ "13": "junco, snowbird",
30
+ "14": "indigo bunting, indigo finch, indigo bird, Passerina cyanea",
31
+ "15": "robin, American robin, Turdus migratorius",
32
+ "16": "bulbul",
33
+ "17": "jay",
34
+ "18": "magpie",
35
+ "19": "chickadee",
36
+ "20": "water ouzel, dipper",
37
+ "21": "kite",
38
+ "22": "bald eagle, American eagle, Haliaeetus leucocephalus",
39
+ "23": "vulture",
40
+ "24": "great grey owl, great gray owl, Strix nebulosa",
41
+ "25": "European fire salamander, Salamandra salamandra",
42
+ "26": "common newt, Triturus vulgaris",
43
+ "27": "eft",
44
+ "28": "spotted salamander, Ambystoma maculatum",
45
+ "29": "axolotl, mud puppy, Ambystoma mexicanum",
46
+ "30": "bullfrog, Rana catesbeiana",
47
+ "31": "tree frog, tree-frog",
48
+ "32": "tailed frog, bell toad, ribbed toad, tailed toad, Ascaphus trui",
49
+ "33": "loggerhead, loggerhead turtle, Caretta caretta",
50
+ "34": "leatherback turtle, leatherback, leathery turtle, Dermochelys coriacea",
51
+ "35": "mud turtle",
52
+ "36": "terrapin",
53
+ "37": "box turtle, box tortoise",
54
+ "38": "banded gecko",
55
+ "39": "common iguana, iguana, Iguana iguana",
56
+ "40": "American chameleon, anole, Anolis carolinensis",
57
+ "41": "whiptail, whiptail lizard",
58
+ "42": "agama",
59
+ "43": "frilled lizard, Chlamydosaurus kingi",
60
+ "44": "alligator lizard",
61
+ "45": "Gila monster, Heloderma suspectum",
62
+ "46": "green lizard, Lacerta viridis",
63
+ "47": "African chameleon, Chamaeleo chamaeleon",
64
+ "48": "Komodo dragon, Komodo lizard, dragon lizard, giant lizard, Varanus komodoensis",
65
+ "49": "African crocodile, Nile crocodile, Crocodylus niloticus",
66
+ "50": "American alligator, Alligator mississipiensis",
67
+ "51": "triceratops",
68
+ "52": "thunder snake, worm snake, Carphophis amoenus",
69
+ "53": "ringneck snake, ring-necked snake, ring snake",
70
+ "54": "hognose snake, puff adder, sand viper",
71
+ "55": "green snake, grass snake",
72
+ "56": "king snake, kingsnake",
73
+ "57": "garter snake, grass snake",
74
+ "58": "water snake",
75
+ "59": "vine snake",
76
+ "60": "night snake, Hypsiglena torquata",
77
+ "61": "boa constrictor, Constrictor constrictor",
78
+ "62": "rock python, rock snake, Python sebae",
79
+ "63": "Indian cobra, Naja naja",
80
+ "64": "green mamba",
81
+ "65": "sea snake",
82
+ "66": "horned viper, cerastes, sand viper, horned asp, Cerastes cornutus",
83
+ "67": "diamondback, diamondback rattlesnake, Crotalus adamanteus",
84
+ "68": "sidewinder, horned rattlesnake, Crotalus cerastes",
85
+ "69": "trilobite",
86
+ "70": "harvestman, daddy longlegs, Phalangium opilio",
87
+ "71": "scorpion",
88
+ "72": "black and gold garden spider, Argiope aurantia",
89
+ "73": "barn spider, Araneus cavaticus",
90
+ "74": "garden spider, Aranea diademata",
91
+ "75": "black widow, Latrodectus mactans",
92
+ "76": "tarantula",
93
+ "77": "wolf spider, hunting spider",
94
+ "78": "tick",
95
+ "79": "centipede",
96
+ "80": "black grouse",
97
+ "81": "ptarmigan",
98
+ "82": "ruffed grouse, partridge, Bonasa umbellus",
99
+ "83": "prairie chicken, prairie grouse, prairie fowl",
100
+ "84": "peacock",
101
+ "85": "quail",
102
+ "86": "partridge",
103
+ "87": "African grey, African gray, Psittacus erithacus",
104
+ "88": "macaw",
105
+ "89": "sulphur-crested cockatoo, Kakatoe galerita, Cacatua galerita",
106
+ "90": "lorikeet",
107
+ "91": "coucal",
108
+ "92": "bee eater",
109
+ "93": "hornbill",
110
+ "94": "hummingbird",
111
+ "95": "jacamar",
112
+ "96": "toucan",
113
+ "97": "drake",
114
+ "98": "red-breasted merganser, Mergus serrator",
115
+ "99": "goose",
116
+ "100": "black swan, Cygnus atratus",
117
+ "101": "tusker",
118
+ "102": "echidna, spiny anteater, anteater",
119
+ "103": "platypus, duckbill, duckbilled platypus, duck-billed platypus, Ornithorhynchus anatinus",
120
+ "104": "wallaby, brush kangaroo",
121
+ "105": "koala, koala bear, kangaroo bear, native bear, Phascolarctos cinereus",
122
+ "106": "wombat",
123
+ "107": "jellyfish",
124
+ "108": "sea anemone, anemone",
125
+ "109": "brain coral",
126
+ "110": "flatworm, platyhelminth",
127
+ "111": "nematode, nematode worm, roundworm",
128
+ "112": "conch",
129
+ "113": "snail",
130
+ "114": "slug",
131
+ "115": "sea slug, nudibranch",
132
+ "116": "chiton, coat-of-mail shell, sea cradle, polyplacophore",
133
+ "117": "chambered nautilus, pearly nautilus, nautilus",
134
+ "118": "Dungeness crab, Cancer magister",
135
+ "119": "rock crab, Cancer irroratus",
136
+ "120": "fiddler crab",
137
+ "121": "king crab, Alaska crab, Alaskan king crab, Alaska king crab, Paralithodes camtschatica",
138
+ "122": "American lobster, Northern lobster, Maine lobster, Homarus americanus",
139
+ "123": "spiny lobster, langouste, rock lobster, crawfish, crayfish, sea crawfish",
140
+ "124": "crayfish, crawfish, crawdad, crawdaddy",
141
+ "125": "hermit crab",
142
+ "126": "isopod",
143
+ "127": "white stork, Ciconia ciconia",
144
+ "128": "black stork, Ciconia nigra",
145
+ "129": "spoonbill",
146
+ "130": "flamingo",
147
+ "131": "little blue heron, Egretta caerulea",
148
+ "132": "American egret, great white heron, Egretta albus",
149
+ "133": "bittern",
150
+ "134": "crane",
151
+ "135": "limpkin, Aramus pictus",
152
+ "136": "European gallinule, Porphyrio porphyrio",
153
+ "137": "American coot, marsh hen, mud hen, water hen, Fulica americana",
154
+ "138": "bustard",
155
+ "139": "ruddy turnstone, Arenaria interpres",
156
+ "140": "red-backed sandpiper, dunlin, Erolia alpina",
157
+ "141": "redshank, Tringa totanus",
158
+ "142": "dowitcher",
159
+ "143": "oystercatcher, oyster catcher",
160
+ "144": "pelican",
161
+ "145": "king penguin, Aptenodytes patagonica",
162
+ "146": "albatross, mollymawk",
163
+ "147": "grey whale, gray whale, devilfish, Eschrichtius gibbosus, Eschrichtius robustus",
164
+ "148": "killer whale, killer, orca, grampus, sea wolf, Orcinus orca",
165
+ "149": "dugong, Dugong dugon",
166
+ "150": "sea lion",
167
+ "151": "Chihuahua",
168
+ "152": "Japanese spaniel",
169
+ "153": "Maltese dog, Maltese terrier, Maltese",
170
+ "154": "Pekinese, Pekingese, Peke",
171
+ "155": "Shih-Tzu",
172
+ "156": "Blenheim spaniel",
173
+ "157": "papillon",
174
+ "158": "toy terrier",
175
+ "159": "Rhodesian ridgeback",
176
+ "160": "Afghan hound, Afghan",
177
+ "161": "basset, basset hound",
178
+ "162": "beagle",
179
+ "163": "bloodhound, sleuthhound",
180
+ "164": "bluetick",
181
+ "165": "black-and-tan coonhound",
182
+ "166": "Walker hound, Walker foxhound",
183
+ "167": "English foxhound",
184
+ "168": "redbone",
185
+ "169": "borzoi, Russian wolfhound",
186
+ "170": "Irish wolfhound",
187
+ "171": "Italian greyhound",
188
+ "172": "whippet",
189
+ "173": "Ibizan hound, Ibizan Podenco",
190
+ "174": "Norwegian elkhound, elkhound",
191
+ "175": "otterhound, otter hound",
192
+ "176": "Saluki, gazelle hound",
193
+ "177": "Scottish deerhound, deerhound",
194
+ "178": "Weimaraner",
195
+ "179": "Staffordshire bullterrier, Staffordshire bull terrier",
196
+ "180": "American Staffordshire terrier, Staffordshire terrier, American pit bull terrier, pit bull terrier",
197
+ "181": "Bedlington terrier",
198
+ "182": "Border terrier",
199
+ "183": "Kerry blue terrier",
200
+ "184": "Irish terrier",
201
+ "185": "Norfolk terrier",
202
+ "186": "Norwich terrier",
203
+ "187": "Yorkshire terrier",
204
+ "188": "wire-haired fox terrier",
205
+ "189": "Lakeland terrier",
206
+ "190": "Sealyham terrier, Sealyham",
207
+ "191": "Airedale, Airedale terrier",
208
+ "192": "cairn, cairn terrier",
209
+ "193": "Australian terrier",
210
+ "194": "Dandie Dinmont, Dandie Dinmont terrier",
211
+ "195": "Boston bull, Boston terrier",
212
+ "196": "miniature schnauzer",
213
+ "197": "giant schnauzer",
214
+ "198": "standard schnauzer",
215
+ "199": "Scotch terrier, Scottish terrier, Scottie",
216
+ "200": "Tibetan terrier, chrysanthemum dog",
217
+ "201": "silky terrier, Sydney silky",
218
+ "202": "soft-coated wheaten terrier",
219
+ "203": "West Highland white terrier",
220
+ "204": "Lhasa, Lhasa apso",
221
+ "205": "flat-coated retriever",
222
+ "206": "curly-coated retriever",
223
+ "207": "golden retriever",
224
+ "208": "Labrador retriever",
225
+ "209": "Chesapeake Bay retriever",
226
+ "210": "German short-haired pointer",
227
+ "211": "vizsla, Hungarian pointer",
228
+ "212": "English setter",
229
+ "213": "Irish setter, red setter",
230
+ "214": "Gordon setter",
231
+ "215": "Brittany spaniel",
232
+ "216": "clumber, clumber spaniel",
233
+ "217": "English springer, English springer spaniel",
234
+ "218": "Welsh springer spaniel",
235
+ "219": "cocker spaniel, English cocker spaniel, cocker",
236
+ "220": "Sussex spaniel",
237
+ "221": "Irish water spaniel",
238
+ "222": "kuvasz",
239
+ "223": "schipperke",
240
+ "224": "groenendael",
241
+ "225": "malinois",
242
+ "226": "briard",
243
+ "227": "kelpie",
244
+ "228": "komondor",
245
+ "229": "Old English sheepdog, bobtail",
246
+ "230": "Shetland sheepdog, Shetland sheep dog, Shetland",
247
+ "231": "collie",
248
+ "232": "Border collie",
249
+ "233": "Bouvier des Flandres, Bouviers des Flandres",
250
+ "234": "Rottweiler",
251
+ "235": "German shepherd, German shepherd dog, German police dog, alsatian",
252
+ "236": "Doberman, Doberman pinscher",
253
+ "237": "miniature pinscher",
254
+ "238": "Greater Swiss Mountain dog",
255
+ "239": "Bernese mountain dog",
256
+ "240": "Appenzeller",
257
+ "241": "EntleBucher",
258
+ "242": "boxer",
259
+ "243": "bull mastiff",
260
+ "244": "Tibetan mastiff",
261
+ "245": "French bulldog",
262
+ "246": "Great Dane",
263
+ "247": "Saint Bernard, St Bernard",
264
+ "248": "Eskimo dog, husky",
265
+ "249": "malamute, malemute, Alaskan malamute",
266
+ "250": "Siberian husky",
267
+ "251": "dalmatian, coach dog, carriage dog",
268
+ "252": "affenpinscher, monkey pinscher, monkey dog",
269
+ "253": "basenji",
270
+ "254": "pug, pug-dog",
271
+ "255": "Leonberg",
272
+ "256": "Newfoundland, Newfoundland dog",
273
+ "257": "Great Pyrenees",
274
+ "258": "Samoyed, Samoyede",
275
+ "259": "Pomeranian",
276
+ "260": "chow, chow chow",
277
+ "261": "keeshond",
278
+ "262": "Brabancon griffon",
279
+ "263": "Pembroke, Pembroke Welsh corgi",
280
+ "264": "Cardigan, Cardigan Welsh corgi",
281
+ "265": "toy poodle",
282
+ "266": "miniature poodle",
283
+ "267": "standard poodle",
284
+ "268": "Mexican hairless",
285
+ "269": "timber wolf, grey wolf, gray wolf, Canis lupus",
286
+ "270": "white wolf, Arctic wolf, Canis lupus tundrarum",
287
+ "271": "red wolf, maned wolf, Canis rufus, Canis niger",
288
+ "272": "coyote, prairie wolf, brush wolf, Canis latrans",
289
+ "273": "dingo, warrigal, warragal, Canis dingo",
290
+ "274": "dhole, Cuon alpinus",
291
+ "275": "African hunting dog, hyena dog, Cape hunting dog, Lycaon pictus",
292
+ "276": "hyena, hyaena",
293
+ "277": "red fox, Vulpes vulpes",
294
+ "278": "kit fox, Vulpes macrotis",
295
+ "279": "Arctic fox, white fox, Alopex lagopus",
296
+ "280": "grey fox, gray fox, Urocyon cinereoargenteus",
297
+ "281": "tabby, tabby cat",
298
+ "282": "tiger cat",
299
+ "283": "Persian cat",
300
+ "284": "Siamese cat, Siamese",
301
+ "285": "Egyptian cat",
302
+ "286": "cougar, puma, catamount, mountain lion, painter, panther, Felis concolor",
303
+ "287": "lynx, catamount",
304
+ "288": "leopard, Panthera pardus",
305
+ "289": "snow leopard, ounce, Panthera uncia",
306
+ "290": "jaguar, panther, Panthera onca, Felis onca",
307
+ "291": "lion, king of beasts, Panthera leo",
308
+ "292": "tiger, Panthera tigris",
309
+ "293": "cheetah, chetah, Acinonyx jubatus",
310
+ "294": "brown bear, bruin, Ursus arctos",
311
+ "295": "American black bear, black bear, Ursus americanus, Euarctos americanus",
312
+ "296": "ice bear, polar bear, Ursus Maritimus, Thalarctos maritimus",
313
+ "297": "sloth bear, Melursus ursinus, Ursus ursinus",
314
+ "298": "mongoose",
315
+ "299": "meerkat, mierkat",
316
+ "300": "tiger beetle",
317
+ "301": "ladybug, ladybeetle, lady beetle, ladybird, ladybird beetle",
318
+ "302": "ground beetle, carabid beetle",
319
+ "303": "long-horned beetle, longicorn, longicorn beetle",
320
+ "304": "leaf beetle, chrysomelid",
321
+ "305": "dung beetle",
322
+ "306": "rhinoceros beetle",
323
+ "307": "weevil",
324
+ "308": "fly",
325
+ "309": "bee",
326
+ "310": "ant, emmet, pismire",
327
+ "311": "grasshopper, hopper",
328
+ "312": "cricket",
329
+ "313": "walking stick, walkingstick, stick insect",
330
+ "314": "cockroach, roach",
331
+ "315": "mantis, mantid",
332
+ "316": "cicada, cicala",
333
+ "317": "leafhopper",
334
+ "318": "lacewing, lacewing fly",
335
+ "319": "dragonfly, darning needle, devils darning needle, sewing needle, snake feeder, snake doctor, mosquito hawk, skeeter hawk",
336
+ "320": "damselfly",
337
+ "321": "admiral",
338
+ "322": "ringlet, ringlet butterfly",
339
+ "323": "monarch, monarch butterfly, milkweed butterfly, Danaus plexippus",
340
+ "324": "cabbage butterfly",
341
+ "325": "sulphur butterfly, sulfur butterfly",
342
+ "326": "lycaenid, lycaenid butterfly",
343
+ "327": "starfish, sea star",
344
+ "328": "sea urchin",
345
+ "329": "sea cucumber, holothurian",
346
+ "330": "wood rabbit, cottontail, cottontail rabbit",
347
+ "331": "hare",
348
+ "332": "Angora, Angora rabbit",
349
+ "333": "hamster",
350
+ "334": "porcupine, hedgehog",
351
+ "335": "fox squirrel, eastern fox squirrel, Sciurus niger",
352
+ "336": "marmot",
353
+ "337": "beaver",
354
+ "338": "guinea pig, Cavia cobaya",
355
+ "339": "sorrel",
356
+ "340": "zebra",
357
+ "341": "hog, pig, grunter, squealer, Sus scrofa",
358
+ "342": "wild boar, boar, Sus scrofa",
359
+ "343": "warthog",
360
+ "344": "hippopotamus, hippo, river horse, Hippopotamus amphibius",
361
+ "345": "ox",
362
+ "346": "water buffalo, water ox, Asiatic buffalo, Bubalus bubalis",
363
+ "347": "bison",
364
+ "348": "ram, tup",
365
+ "349": "bighorn, bighorn sheep, cimarron, Rocky Mountain bighorn, Rocky Mountain sheep, Ovis canadensis",
366
+ "350": "ibex, Capra ibex",
367
+ "351": "hartebeest",
368
+ "352": "impala, Aepyceros melampus",
369
+ "353": "gazelle",
370
+ "354": "Arabian camel, dromedary, Camelus dromedarius",
371
+ "355": "llama",
372
+ "356": "weasel",
373
+ "357": "mink",
374
+ "358": "polecat, fitch, foulmart, foumart, Mustela putorius",
375
+ "359": "black-footed ferret, ferret, Mustela nigripes",
376
+ "360": "otter",
377
+ "361": "skunk, polecat, wood pussy",
378
+ "362": "badger",
379
+ "363": "armadillo",
380
+ "364": "three-toed sloth, ai, Bradypus tridactylus",
381
+ "365": "orangutan, orang, orangutang, Pongo pygmaeus",
382
+ "366": "gorilla, Gorilla gorilla",
383
+ "367": "chimpanzee, chimp, Pan troglodytes",
384
+ "368": "gibbon, Hylobates lar",
385
+ "369": "siamang, Hylobates syndactylus, Symphalangus syndactylus",
386
+ "370": "guenon, guenon monkey",
387
+ "371": "patas, hussar monkey, Erythrocebus patas",
388
+ "372": "baboon",
389
+ "373": "macaque",
390
+ "374": "langur",
391
+ "375": "colobus, colobus monkey",
392
+ "376": "proboscis monkey, Nasalis larvatus",
393
+ "377": "marmoset",
394
+ "378": "capuchin, ringtail, Cebus capucinus",
395
+ "379": "howler monkey, howler",
396
+ "380": "titi, titi monkey",
397
+ "381": "spider monkey, Ateles geoffroyi",
398
+ "382": "squirrel monkey, Saimiri sciureus",
399
+ "383": "Madagascar cat, ring-tailed lemur, Lemur catta",
400
+ "384": "indri, indris, Indri indri, Indri brevicaudatus",
401
+ "385": "Indian elephant, Elephas maximus",
402
+ "386": "African elephant, Loxodonta africana",
403
+ "387": "lesser panda, red panda, panda, bear cat, cat bear, Ailurus fulgens",
404
+ "388": "giant panda, panda, panda bear, coon bear, Ailuropoda melanoleuca",
405
+ "389": "barracouta, snoek",
406
+ "390": "eel",
407
+ "391": "coho, cohoe, coho salmon, blue jack, silver salmon, Oncorhynchus kisutch",
408
+ "392": "rock beauty, Holocanthus tricolor",
409
+ "393": "anemone fish",
410
+ "394": "sturgeon",
411
+ "395": "gar, garfish, garpike, billfish, Lepisosteus osseus",
412
+ "396": "lionfish",
413
+ "397": "puffer, pufferfish, blowfish, globefish",
414
+ "398": "abacus",
415
+ "399": "abaya",
416
+ "400": "academic gown, academic robe, judge robe",
417
+ "401": "accordion, piano accordion, squeeze box",
418
+ "402": "acoustic guitar",
419
+ "403": "aircraft carrier, carrier, flattop, attack aircraft carrier",
420
+ "404": "airliner",
421
+ "405": "airship, dirigible",
422
+ "406": "altar",
423
+ "407": "ambulance",
424
+ "408": "amphibian, amphibious vehicle",
425
+ "409": "analog clock",
426
+ "410": "apiary, bee house",
427
+ "411": "apron",
428
+ "412": "ashcan, trash can, garbage can, wastebin, ash bin, ash-bin, ashbin, dustbin, trash barrel, trash bin",
429
+ "413": "assault rifle, assault gun",
430
+ "414": "backpack, back pack, knapsack, packsack, rucksack, haversack",
431
+ "415": "bakery, bakeshop, bakehouse",
432
+ "416": "balance beam, beam",
433
+ "417": "balloon",
434
+ "418": "ballpoint, ballpoint pen, ballpen, Biro",
435
+ "419": "Band Aid",
436
+ "420": "banjo",
437
+ "421": "bannister, banister, balustrade, balusters, handrail",
438
+ "422": "barbell",
439
+ "423": "barber chair",
440
+ "424": "barbershop",
441
+ "425": "barn",
442
+ "426": "barometer",
443
+ "427": "barrel, cask",
444
+ "428": "barrow, garden cart, lawn cart, wheelbarrow",
445
+ "429": "baseball",
446
+ "430": "basketball",
447
+ "431": "bassinet",
448
+ "432": "bassoon",
449
+ "433": "bathing cap, swimming cap",
450
+ "434": "bath towel",
451
+ "435": "bathtub, bathing tub, bath, tub",
452
+ "436": "beach wagon, station wagon, wagon, estate car, beach waggon, station waggon, waggon",
453
+ "437": "beacon, lighthouse, beacon light, pharos",
454
+ "438": "beaker",
455
+ "439": "bearskin, busby, shako",
456
+ "440": "beer bottle",
457
+ "441": "beer glass",
458
+ "442": "bell cote, bell cot",
459
+ "443": "bib",
460
+ "444": "bicycle-built-for-two, tandem bicycle, tandem",
461
+ "445": "bikini, two-piece",
462
+ "446": "binder, ring-binder",
463
+ "447": "binoculars, field glasses, opera glasses",
464
+ "448": "birdhouse",
465
+ "449": "boathouse",
466
+ "450": "bobsled, bobsleigh, bob",
467
+ "451": "bolo tie, bolo, bola tie, bola",
468
+ "452": "bonnet, poke bonnet",
469
+ "453": "bookcase",
470
+ "454": "bookshop, bookstore, bookstall",
471
+ "455": "bottlecap",
472
+ "456": "bow",
473
+ "457": "bow tie, bow-tie, bowtie",
474
+ "458": "brass, memorial tablet, plaque",
475
+ "459": "brassiere, bra, bandeau",
476
+ "460": "breakwater, groin, groyne, mole, bulwark, seawall, jetty",
477
+ "461": "breastplate, aegis, egis",
478
+ "462": "broom",
479
+ "463": "bucket, pail",
480
+ "464": "buckle",
481
+ "465": "bulletproof vest",
482
+ "466": "bullet train, bullet",
483
+ "467": "butcher shop, meat market",
484
+ "468": "cab, hack, taxi, taxicab",
485
+ "469": "caldron, cauldron",
486
+ "470": "candle, taper, wax light",
487
+ "471": "cannon",
488
+ "472": "canoe",
489
+ "473": "can opener, tin opener",
490
+ "474": "cardigan",
491
+ "475": "car mirror",
492
+ "476": "carousel, carrousel, merry-go-round, roundabout, whirligig",
493
+ "477": "carpenters kit, tool kit",
494
+ "478": "carton",
495
+ "479": "car wheel",
496
+ "480": "cash machine, cash dispenser, automated teller machine, automatic teller machine, automated teller, automatic teller, ATM",
497
+ "481": "cassette",
498
+ "482": "cassette player",
499
+ "483": "castle",
500
+ "484": "catamaran",
501
+ "485": "CD player",
502
+ "486": "cello, violoncello",
503
+ "487": "cellular telephone, cellular phone, cellphone, cell, mobile phone",
504
+ "488": "chain",
505
+ "489": "chainlink fence",
506
+ "490": "chain mail, ring mail, mail, chain armor, chain armour, ring armor, ring armour",
507
+ "491": "chain saw, chainsaw",
508
+ "492": "chest",
509
+ "493": "chiffonier, commode",
510
+ "494": "chime, bell, gong",
511
+ "495": "china cabinet, china closet",
512
+ "496": "Christmas stocking",
513
+ "497": "church, church building",
514
+ "498": "cinema, movie theater, movie theatre, movie house, picture palace",
515
+ "499": "cleaver, meat cleaver, chopper",
516
+ "500": "cliff dwelling",
517
+ "501": "cloak",
518
+ "502": "clog, geta, patten, sabot",
519
+ "503": "cocktail shaker",
520
+ "504": "coffee mug",
521
+ "505": "coffeepot",
522
+ "506": "coil, spiral, volute, whorl, helix",
523
+ "507": "combination lock",
524
+ "508": "computer keyboard, keypad",
525
+ "509": "confectionery, confectionary, candy store",
526
+ "510": "container ship, containership, container vessel",
527
+ "511": "convertible",
528
+ "512": "corkscrew, bottle screw",
529
+ "513": "cornet, horn, trumpet, trump",
530
+ "514": "cowboy boot",
531
+ "515": "cowboy hat, ten-gallon hat",
532
+ "516": "cradle",
533
+ "517": "crane",
534
+ "518": "crash helmet",
535
+ "519": "crate",
536
+ "520": "crib, cot",
537
+ "521": "Crock Pot",
538
+ "522": "croquet ball",
539
+ "523": "crutch",
540
+ "524": "cuirass",
541
+ "525": "dam, dike, dyke",
542
+ "526": "desk",
543
+ "527": "desktop computer",
544
+ "528": "dial telephone, dial phone",
545
+ "529": "diaper, nappy, napkin",
546
+ "530": "digital clock",
547
+ "531": "digital watch",
548
+ "532": "dining table, board",
549
+ "533": "dishrag, dishcloth",
550
+ "534": "dishwasher, dish washer, dishwashing machine",
551
+ "535": "disk brake, disc brake",
552
+ "536": "dock, dockage, docking facility",
553
+ "537": "dogsled, dog sled, dog sleigh",
554
+ "538": "dome",
555
+ "539": "doormat, welcome mat",
556
+ "540": "drilling platform, offshore rig",
557
+ "541": "drum, membranophone, tympan",
558
+ "542": "drumstick",
559
+ "543": "dumbbell",
560
+ "544": "Dutch oven",
561
+ "545": "electric fan, blower",
562
+ "546": "electric guitar",
563
+ "547": "electric locomotive",
564
+ "548": "entertainment center",
565
+ "549": "envelope",
566
+ "550": "espresso maker",
567
+ "551": "face powder",
568
+ "552": "feather boa, boa",
569
+ "553": "file, file cabinet, filing cabinet",
570
+ "554": "fireboat",
571
+ "555": "fire engine, fire truck",
572
+ "556": "fire screen, fireguard",
573
+ "557": "flagpole, flagstaff",
574
+ "558": "flute, transverse flute",
575
+ "559": "folding chair",
576
+ "560": "football helmet",
577
+ "561": "forklift",
578
+ "562": "fountain",
579
+ "563": "fountain pen",
580
+ "564": "four-poster",
581
+ "565": "freight car",
582
+ "566": "French horn, horn",
583
+ "567": "frying pan, frypan, skillet",
584
+ "568": "fur coat",
585
+ "569": "garbage truck, dustcart",
586
+ "570": "gasmask, respirator, gas helmet",
587
+ "571": "gas pump, gasoline pump, petrol pump, island dispenser",
588
+ "572": "goblet",
589
+ "573": "go-kart",
590
+ "574": "golf ball",
591
+ "575": "golfcart, golf cart",
592
+ "576": "gondola",
593
+ "577": "gong, tam-tam",
594
+ "578": "gown",
595
+ "579": "grand piano, grand",
596
+ "580": "greenhouse, nursery, glasshouse",
597
+ "581": "grille, radiator grille",
598
+ "582": "grocery store, grocery, food market, market",
599
+ "583": "guillotine",
600
+ "584": "hair slide",
601
+ "585": "hair spray",
602
+ "586": "half track",
603
+ "587": "hammer",
604
+ "588": "hamper",
605
+ "589": "hand blower, blow dryer, blow drier, hair dryer, hair drier",
606
+ "590": "hand-held computer, hand-held microcomputer",
607
+ "591": "handkerchief, hankie, hanky, hankey",
608
+ "592": "hard disc, hard disk, fixed disk",
609
+ "593": "harmonica, mouth organ, harp, mouth harp",
610
+ "594": "harp",
611
+ "595": "harvester, reaper",
612
+ "596": "hatchet",
613
+ "597": "holster",
614
+ "598": "home theater, home theatre",
615
+ "599": "honeycomb",
616
+ "600": "hook, claw",
617
+ "601": "hoopskirt, crinoline",
618
+ "602": "horizontal bar, high bar",
619
+ "603": "horse cart, horse-cart",
620
+ "604": "hourglass",
621
+ "605": "iPod",
622
+ "606": "iron, smoothing iron",
623
+ "607": "jack-o-lantern",
624
+ "608": "jean, blue jean, denim",
625
+ "609": "jeep, landrover",
626
+ "610": "jersey, T-shirt, tee shirt",
627
+ "611": "jigsaw puzzle",
628
+ "612": "jinrikisha, ricksha, rickshaw",
629
+ "613": "joystick",
630
+ "614": "kimono",
631
+ "615": "knee pad",
632
+ "616": "knot",
633
+ "617": "lab coat, laboratory coat",
634
+ "618": "ladle",
635
+ "619": "lampshade, lamp shade",
636
+ "620": "laptop, laptop computer",
637
+ "621": "lawn mower, mower",
638
+ "622": "lens cap, lens cover",
639
+ "623": "letter opener, paper knife, paperknife",
640
+ "624": "library",
641
+ "625": "lifeboat",
642
+ "626": "lighter, light, igniter, ignitor",
643
+ "627": "limousine, limo",
644
+ "628": "liner, ocean liner",
645
+ "629": "lipstick, lip rouge",
646
+ "630": "Loafer",
647
+ "631": "lotion",
648
+ "632": "loudspeaker, speaker, speaker unit, loudspeaker system, speaker system",
649
+ "633": "loupe, jewelers loupe",
650
+ "634": "lumbermill, sawmill",
651
+ "635": "magnetic compass",
652
+ "636": "mailbag, postbag",
653
+ "637": "mailbox, letter box",
654
+ "638": "maillot",
655
+ "639": "maillot, tank suit",
656
+ "640": "manhole cover",
657
+ "641": "maraca",
658
+ "642": "marimba, xylophone",
659
+ "643": "mask",
660
+ "644": "matchstick",
661
+ "645": "maypole",
662
+ "646": "maze, labyrinth",
663
+ "647": "measuring cup",
664
+ "648": "medicine chest, medicine cabinet",
665
+ "649": "megalith, megalithic structure",
666
+ "650": "microphone, mike",
667
+ "651": "microwave, microwave oven",
668
+ "652": "military uniform",
669
+ "653": "milk can",
670
+ "654": "minibus",
671
+ "655": "miniskirt, mini",
672
+ "656": "minivan",
673
+ "657": "missile",
674
+ "658": "mitten",
675
+ "659": "mixing bowl",
676
+ "660": "mobile home, manufactured home",
677
+ "661": "Model T",
678
+ "662": "modem",
679
+ "663": "monastery",
680
+ "664": "monitor",
681
+ "665": "moped",
682
+ "666": "mortar",
683
+ "667": "mortarboard",
684
+ "668": "mosque",
685
+ "669": "mosquito net",
686
+ "670": "motor scooter, scooter",
687
+ "671": "mountain bike, all-terrain bike, off-roader",
688
+ "672": "mountain tent",
689
+ "673": "mouse, computer mouse",
690
+ "674": "mousetrap",
691
+ "675": "moving van",
692
+ "676": "muzzle",
693
+ "677": "nail",
694
+ "678": "neck brace",
695
+ "679": "necklace",
696
+ "680": "nipple",
697
+ "681": "notebook, notebook computer",
698
+ "682": "obelisk",
699
+ "683": "oboe, hautboy, hautbois",
700
+ "684": "ocarina, sweet potato",
701
+ "685": "odometer, hodometer, mileometer, milometer",
702
+ "686": "oil filter",
703
+ "687": "organ, pipe organ",
704
+ "688": "oscilloscope, scope, cathode-ray oscilloscope, CRO",
705
+ "689": "overskirt",
706
+ "690": "oxcart",
707
+ "691": "oxygen mask",
708
+ "692": "packet",
709
+ "693": "paddle, boat paddle",
710
+ "694": "paddlewheel, paddle wheel",
711
+ "695": "padlock",
712
+ "696": "paintbrush",
713
+ "697": "pajama, pyjama, pjs, jammies",
714
+ "698": "palace",
715
+ "699": "panpipe, pandean pipe, syrinx",
716
+ "700": "paper towel",
717
+ "701": "parachute, chute",
718
+ "702": "parallel bars, bars",
719
+ "703": "park bench",
720
+ "704": "parking meter",
721
+ "705": "passenger car, coach, carriage",
722
+ "706": "patio, terrace",
723
+ "707": "pay-phone, pay-station",
724
+ "708": "pedestal, plinth, footstall",
725
+ "709": "pencil box, pencil case",
726
+ "710": "pencil sharpener",
727
+ "711": "perfume, essence",
728
+ "712": "Petri dish",
729
+ "713": "photocopier",
730
+ "714": "pick, plectrum, plectron",
731
+ "715": "pickelhaube",
732
+ "716": "picket fence, paling",
733
+ "717": "pickup, pickup truck",
734
+ "718": "pier",
735
+ "719": "piggy bank, penny bank",
736
+ "720": "pill bottle",
737
+ "721": "pillow",
738
+ "722": "ping-pong ball",
739
+ "723": "pinwheel",
740
+ "724": "pirate, pirate ship",
741
+ "725": "pitcher, ewer",
742
+ "726": "plane, carpenters plane, woodworking plane",
743
+ "727": "planetarium",
744
+ "728": "plastic bag",
745
+ "729": "plate rack",
746
+ "730": "plow, plough",
747
+ "731": "plunger, plumbers helper",
748
+ "732": "Polaroid camera, Polaroid Land camera",
749
+ "733": "pole",
750
+ "734": "police van, police wagon, paddy wagon, patrol wagon, wagon, black Maria",
751
+ "735": "poncho",
752
+ "736": "pool table, billiard table, snooker table",
753
+ "737": "pop bottle, soda bottle",
754
+ "738": "pot, flowerpot",
755
+ "739": "potters wheel",
756
+ "740": "power drill",
757
+ "741": "prayer rug, prayer mat",
758
+ "742": "printer",
759
+ "743": "prison, prison house",
760
+ "744": "projectile, missile",
761
+ "745": "projector",
762
+ "746": "puck, hockey puck",
763
+ "747": "punching bag, punch bag, punching ball, punchball",
764
+ "748": "purse",
765
+ "749": "quill, quill pen",
766
+ "750": "quilt, comforter, comfort, puff",
767
+ "751": "racer, race car, racing car",
768
+ "752": "racket, racquet",
769
+ "753": "radiator",
770
+ "754": "radio, wireless",
771
+ "755": "radio telescope, radio reflector",
772
+ "756": "rain barrel",
773
+ "757": "recreational vehicle, RV, R.V.",
774
+ "758": "reel",
775
+ "759": "reflex camera",
776
+ "760": "refrigerator, icebox",
777
+ "761": "remote control, remote",
778
+ "762": "restaurant, eating house, eating place, eatery",
779
+ "763": "revolver, six-gun, six-shooter",
780
+ "764": "rifle",
781
+ "765": "rocking chair, rocker",
782
+ "766": "rotisserie",
783
+ "767": "rubber eraser, rubber, pencil eraser",
784
+ "768": "rugby ball",
785
+ "769": "rule, ruler",
786
+ "770": "running shoe",
787
+ "771": "safe",
788
+ "772": "safety pin",
789
+ "773": "saltshaker, salt shaker",
790
+ "774": "sandal",
791
+ "775": "sarong",
792
+ "776": "sax, saxophone",
793
+ "777": "scabbard",
794
+ "778": "scale, weighing machine",
795
+ "779": "school bus",
796
+ "780": "schooner",
797
+ "781": "scoreboard",
798
+ "782": "screen, CRT screen",
799
+ "783": "screw",
800
+ "784": "screwdriver",
801
+ "785": "seat belt, seatbelt",
802
+ "786": "sewing machine",
803
+ "787": "shield, buckler",
804
+ "788": "shoe shop, shoe-shop, shoe store",
805
+ "789": "shoji",
806
+ "790": "shopping basket",
807
+ "791": "shopping cart",
808
+ "792": "shovel",
809
+ "793": "shower cap",
810
+ "794": "shower curtain",
811
+ "795": "ski",
812
+ "796": "ski mask",
813
+ "797": "sleeping bag",
814
+ "798": "slide rule, slipstick",
815
+ "799": "sliding door",
816
+ "800": "slot, one-armed bandit",
817
+ "801": "snorkel",
818
+ "802": "snowmobile",
819
+ "803": "snowplow, snowplough",
820
+ "804": "soap dispenser",
821
+ "805": "soccer ball",
822
+ "806": "sock",
823
+ "807": "solar dish, solar collector, solar furnace",
824
+ "808": "sombrero",
825
+ "809": "soup bowl",
826
+ "810": "space bar",
827
+ "811": "space heater",
828
+ "812": "space shuttle",
829
+ "813": "spatula",
830
+ "814": "speedboat",
831
+ "815": "spider web, spiders web",
832
+ "816": "spindle",
833
+ "817": "sports car, sport car",
834
+ "818": "spotlight, spot",
835
+ "819": "stage",
836
+ "820": "steam locomotive",
837
+ "821": "steel arch bridge",
838
+ "822": "steel drum",
839
+ "823": "stethoscope",
840
+ "824": "stole",
841
+ "825": "stone wall",
842
+ "826": "stopwatch, stop watch",
843
+ "827": "stove",
844
+ "828": "strainer",
845
+ "829": "streetcar, tram, tramcar, trolley, trolley car",
846
+ "830": "stretcher",
847
+ "831": "studio couch, day bed",
848
+ "832": "stupa, tope",
849
+ "833": "submarine, pigboat, sub, U-boat",
850
+ "834": "suit, suit of clothes",
851
+ "835": "sundial",
852
+ "836": "sunglass",
853
+ "837": "sunglasses, dark glasses, shades",
854
+ "838": "sunscreen, sunblock, sun blocker",
855
+ "839": "suspension bridge",
856
+ "840": "swab, swob, mop",
857
+ "841": "sweatshirt",
858
+ "842": "swimming trunks, bathing trunks",
859
+ "843": "swing",
860
+ "844": "switch, electric switch, electrical switch",
861
+ "845": "syringe",
862
+ "846": "table lamp",
863
+ "847": "tank, army tank, armored combat vehicle, armoured combat vehicle",
864
+ "848": "tape player",
865
+ "849": "teapot",
866
+ "850": "teddy, teddy bear",
867
+ "851": "television, television system",
868
+ "852": "tennis ball",
869
+ "853": "thatch, thatched roof",
870
+ "854": "theater curtain, theatre curtain",
871
+ "855": "thimble",
872
+ "856": "thresher, thrasher, threshing machine",
873
+ "857": "throne",
874
+ "858": "tile roof",
875
+ "859": "toaster",
876
+ "860": "tobacco shop, tobacconist shop, tobacconist",
877
+ "861": "toilet seat",
878
+ "862": "torch",
879
+ "863": "totem pole",
880
+ "864": "tow truck, tow car, wrecker",
881
+ "865": "toyshop",
882
+ "866": "tractor",
883
+ "867": "trailer truck, tractor trailer, trucking rig, rig, articulated lorry, semi",
884
+ "868": "tray",
885
+ "869": "trench coat",
886
+ "870": "tricycle, trike, velocipede",
887
+ "871": "trimaran",
888
+ "872": "tripod",
889
+ "873": "triumphal arch",
890
+ "874": "trolleybus, trolley coach, trackless trolley",
891
+ "875": "trombone",
892
+ "876": "tub, vat",
893
+ "877": "turnstile",
894
+ "878": "typewriter keyboard",
895
+ "879": "umbrella",
896
+ "880": "unicycle, monocycle",
897
+ "881": "upright, upright piano",
898
+ "882": "vacuum, vacuum cleaner",
899
+ "883": "vase",
900
+ "884": "vault",
901
+ "885": "velvet",
902
+ "886": "vending machine",
903
+ "887": "vestment",
904
+ "888": "viaduct",
905
+ "889": "violin, fiddle",
906
+ "890": "volleyball",
907
+ "891": "waffle iron",
908
+ "892": "wall clock",
909
+ "893": "wallet, billfold, notecase, pocketbook",
910
+ "894": "wardrobe, closet, press",
911
+ "895": "warplane, military plane",
912
+ "896": "washbasin, handbasin, washbowl, lavabo, wash-hand basin",
913
+ "897": "washer, automatic washer, washing machine",
914
+ "898": "water bottle",
915
+ "899": "water jug",
916
+ "900": "water tower",
917
+ "901": "whiskey jug",
918
+ "902": "whistle",
919
+ "903": "wig",
920
+ "904": "window screen",
921
+ "905": "window shade",
922
+ "906": "Windsor tie",
923
+ "907": "wine bottle",
924
+ "908": "wing",
925
+ "909": "wok",
926
+ "910": "wooden spoon",
927
+ "911": "wool, woolen, woollen",
928
+ "912": "worm fence, snake fence, snake-rail fence, Virginia fence",
929
+ "913": "wreck",
930
+ "914": "yawl",
931
+ "915": "yurt",
932
+ "916": "web site, website, internet site, site",
933
+ "917": "comic book",
934
+ "918": "crossword puzzle, crossword",
935
+ "919": "street sign",
936
+ "920": "traffic light, traffic signal, stoplight",
937
+ "921": "book jacket, dust cover, dust jacket, dust wrapper",
938
+ "922": "menu",
939
+ "923": "plate",
940
+ "924": "guacamole",
941
+ "925": "consomme",
942
+ "926": "hot pot, hotpot",
943
+ "927": "trifle",
944
+ "928": "ice cream, icecream",
945
+ "929": "ice lolly, lolly, lollipop, popsicle",
946
+ "930": "French loaf",
947
+ "931": "bagel, beigel",
948
+ "932": "pretzel",
949
+ "933": "cheeseburger",
950
+ "934": "hotdog, hot dog, red hot",
951
+ "935": "mashed potato",
952
+ "936": "head cabbage",
953
+ "937": "broccoli",
954
+ "938": "cauliflower",
955
+ "939": "zucchini, courgette",
956
+ "940": "spaghetti squash",
957
+ "941": "acorn squash",
958
+ "942": "butternut squash",
959
+ "943": "cucumber, cuke",
960
+ "944": "artichoke, globe artichoke",
961
+ "945": "bell pepper",
962
+ "946": "cardoon",
963
+ "947": "mushroom",
964
+ "948": "Granny Smith",
965
+ "949": "strawberry",
966
+ "950": "orange",
967
+ "951": "lemon",
968
+ "952": "fig",
969
+ "953": "pineapple, ananas",
970
+ "954": "banana",
971
+ "955": "jackfruit, jak, jack",
972
+ "956": "custard apple",
973
+ "957": "pomegranate",
974
+ "958": "hay",
975
+ "959": "carbonara",
976
+ "960": "chocolate sauce, chocolate syrup",
977
+ "961": "dough",
978
+ "962": "meat loaf, meatloaf",
979
+ "963": "pizza, pizza pie",
980
+ "964": "potpie",
981
+ "965": "burrito",
982
+ "966": "red wine",
983
+ "967": "espresso",
984
+ "968": "cup",
985
+ "969": "eggnog",
986
+ "970": "alp",
987
+ "971": "bubble",
988
+ "972": "cliff, drop, drop-off",
989
+ "973": "coral reef",
990
+ "974": "geyser",
991
+ "975": "lakeside, lakeshore",
992
+ "976": "promontory, headland, head, foreland",
993
+ "977": "sandbar, sand bar",
994
+ "978": "seashore, coast, seacoast, sea-coast",
995
+ "979": "valley, vale",
996
+ "980": "volcano",
997
+ "981": "ballplayer, baseball player",
998
+ "982": "groom, bridegroom",
999
+ "983": "scuba diver",
1000
+ "984": "rapeseed",
1001
+ "985": "daisy",
1002
+ "986": "yellow ladys slipper, yellow lady-slipper, Cypripedium calceolus, Cypripedium parviflorum",
1003
+ "987": "corn",
1004
+ "988": "acorn",
1005
+ "989": "hip, rose hip, rosehip",
1006
+ "990": "buckeye, horse chestnut, conker",
1007
+ "991": "coral fungus",
1008
+ "992": "agaric",
1009
+ "993": "gyromitra",
1010
+ "994": "stinkhorn, carrion fungus",
1011
+ "995": "earthstar",
1012
+ "996": "hen-of-the-woods, hen of the woods, Polyporus frondosus, Grifola frondosa",
1013
+ "997": "bolete",
1014
+ "998": "ear, spike, capitulum",
1015
+ "999": "toilet tissue, toilet paper, bathroom tissue"
1016
+ },
1017
+ "vae": [
1018
+ "diffusers",
1019
+ "AutoencoderKL"
1020
+ ]
1021
+ }
iMF-B-SIM/pipeline.py ADDED
@@ -0,0 +1,342 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Hub custom pipeline: IMFPipeline.
2
+ Load with native Hugging Face diffusers and trust_remote_code=True.
3
+ """
4
+
5
+ from __future__ import annotations
6
+
7
+ import importlib.util
8
+ import inspect
9
+
10
+ import json
11
+ from pathlib import Path
12
+ from typing import Dict, List, Optional, Tuple, Union, Any
13
+
14
+ import torch
15
+ from diffusers.image_processor import VaeImageProcessor
16
+ from diffusers.pipelines.pipeline_utils import DiffusionPipeline, ImagePipelineOutput
17
+ from diffusers.utils.torch_utils import randn_tensor
18
+
19
+ # imeanflow / FD-Loss sd-vae latent statistics (stabilityai/sd-vae-ft-mse)
20
+ LATENT_CHANNEL_MEAN = (0.86488, -0.27787343, 0.21616915, 0.3738409)
21
+ LATENT_CHANNEL_STD = (4.85503674, 5.31922414, 3.93725398, 3.9870003)
22
+
23
+
24
+ def _load_bundled_vae(transformer) -> Optional[Any]:
25
+ transformer_path = getattr(transformer.config, "_name_or_path", None)
26
+ if not transformer_path:
27
+ return None
28
+ vae_dir = Path(transformer_path).resolve().parent / "vae"
29
+ if not vae_dir.is_dir() or not (vae_dir / "config.json").is_file():
30
+ return None
31
+ from diffusers import AutoencoderKL
32
+
33
+ vae_dtype = getattr(transformer, "dtype", torch.float32)
34
+ return AutoencoderKL.from_pretrained(str(vae_dir), torch_dtype=vae_dtype)
35
+
36
+
37
+ class IMFPipeline(DiffusionPipeline):
38
+
39
+ @staticmethod
40
+ def prepare_extra_step_kwargs(
41
+ scheduler,
42
+ generator=None,
43
+ eta: float | None = None,
44
+ ):
45
+ kwargs = {}
46
+ step_params = set(inspect.signature(scheduler.step).parameters.keys())
47
+ if "generator" in step_params:
48
+ kwargs["generator"] = generator
49
+ if eta is not None and "eta" in step_params:
50
+ kwargs["eta"] = eta
51
+ return kwargs
52
+
53
+ @staticmethod
54
+ def _prepare_generator(
55
+ generator: Optional[Union[torch.Generator, List[torch.Generator]]],
56
+ ) -> Optional[Union[torch.Generator, List[torch.Generator]]]:
57
+ if generator is None:
58
+ return None
59
+ if isinstance(generator, list):
60
+ for gen in generator:
61
+ if gen is not None:
62
+ gen.manual_seed(int(gen.initial_seed()))
63
+ return generator
64
+ generator.manual_seed(int(generator.initial_seed()))
65
+ return generator
66
+
67
+ @staticmethod
68
+ def _coerce_scheduler(scheduler, transformer) -> Any:
69
+ if scheduler is not None and not isinstance(scheduler, (list, tuple)):
70
+ return scheduler
71
+ variant_path = getattr(transformer.config, "_name_or_path", None)
72
+ if variant_path:
73
+ scheduler_dir = Path(variant_path).resolve().parent / "scheduler"
74
+ module_path = scheduler_dir / "scheduling_imf.py"
75
+ config_path = scheduler_dir / "scheduler_config.json"
76
+ if module_path.is_file() and config_path.is_file():
77
+ spec = importlib.util.spec_from_file_location("scheduling_imf", module_path)
78
+ if spec is not None and spec.loader is not None:
79
+ module = importlib.util.module_from_spec(spec)
80
+ spec.loader.exec_module(module)
81
+ return module.IMFScheduler.from_pretrained(str(scheduler_dir))
82
+ raise ValueError(
83
+ "IMFPipeline could not load IMFScheduler. Ensure the variant includes scheduler/scheduling_imf.py."
84
+ )
85
+
86
+ @staticmethod
87
+ def _resolve_inference_generator(
88
+ device: Union[str, torch.device],
89
+ generator: Optional[Union[torch.Generator, List[torch.Generator]]] = None,
90
+ ) -> Optional[Union[torch.Generator, List[torch.Generator]]]:
91
+ if generator is None:
92
+ return None
93
+ if isinstance(device, str):
94
+ device = torch.device(device)
95
+ device_type = device.type
96
+
97
+ def _relocate(gen: torch.Generator) -> torch.Generator:
98
+ if gen.device.type == device_type:
99
+ return gen
100
+ return torch.Generator(device=device_type).manual_seed(gen.initial_seed())
101
+
102
+ if isinstance(generator, list):
103
+ return [_relocate(g) for g in generator]
104
+ return _relocate(generator)
105
+
106
+ model_cpu_offload_seq = "transformer->vae"
107
+
108
+ def __init__(
109
+ self,
110
+ transformer,
111
+ scheduler,
112
+ vae=None,
113
+ id2label: Optional[Dict[Union[int, str], str]] = None,
114
+ ):
115
+ super().__init__()
116
+ scheduler = self._coerce_scheduler(scheduler, transformer)
117
+ if scheduler is None:
118
+ raise ValueError("IMFPipeline requires a scheduler loaded from the checkpoint.")
119
+ if isinstance(vae, (list, tuple)):
120
+ vae = None
121
+ if vae is None:
122
+ vae = _load_bundled_vae(transformer)
123
+ if vae is not None:
124
+ vae = vae.to(device=transformer.device, dtype=getattr(transformer, "dtype", torch.float32))
125
+ self.register_modules(transformer=transformer, scheduler=scheduler, vae=vae)
126
+ self._id2label = self._normalize_id2label(id2label)
127
+ self.labels = self._build_label2id(self._id2label)
128
+ self._labels_loaded_from_model_index = bool(self._id2label)
129
+ self.latent_channel_mean = torch.tensor(LATENT_CHANNEL_MEAN, dtype=torch.float32).view(1, 4, 1, 1)
130
+ self.latent_channel_std = torch.tensor(LATENT_CHANNEL_STD, dtype=torch.float32).view(1, 4, 1, 1)
131
+ vae_scale_factor = 8
132
+ if vae is not None:
133
+ vae_scale_factor = 2 ** (len(vae.config.block_out_channels) - 1)
134
+ self.vae_scale_factor = vae_scale_factor
135
+ self.image_processor = VaeImageProcessor(vae_scale_factor=self.vae_scale_factor)
136
+
137
+ def _ensure_labels_loaded(self) -> None:
138
+ if self._labels_loaded_from_model_index:
139
+ return
140
+ loaded = self._read_id2label_from_model_index(getattr(self.config, "_name_or_path", None))
141
+ if loaded:
142
+ self._id2label = loaded
143
+ self.labels = self._build_label2id(self._id2label)
144
+ self._labels_loaded_from_model_index = True
145
+
146
+ @staticmethod
147
+ def _normalize_id2label(id2label: Optional[Dict[Union[int, str], str]]) -> Dict[int, str]:
148
+ if not id2label:
149
+ return {}
150
+ return {int(key): value for key, value in id2label.items()}
151
+
152
+ @staticmethod
153
+ def _read_id2label_from_model_index(variant_path: Optional[str]) -> Dict[int, str]:
154
+ if not variant_path:
155
+ return {}
156
+ model_index_path = Path(variant_path).resolve() / "model_index.json"
157
+ if not model_index_path.exists():
158
+ return {}
159
+ raw = json.loads(model_index_path.read_text(encoding="utf-8"))
160
+ id2label = raw.get("id2label")
161
+ if not isinstance(id2label, dict):
162
+ return {}
163
+ return {int(key): value for key, value in id2label.items()}
164
+
165
+ @staticmethod
166
+ def _build_label2id(id2label: Dict[int, str]) -> Dict[str, int]:
167
+ label2id: Dict[str, int] = {}
168
+ for class_id, value in id2label.items():
169
+ for synonym in value.split(","):
170
+ synonym = synonym.strip()
171
+ if synonym:
172
+ label2id[synonym] = int(class_id)
173
+ return dict(sorted(label2id.items()))
174
+
175
+ @property
176
+ def id2label(self) -> Dict[int, str]:
177
+ self._ensure_labels_loaded()
178
+ return self._id2label
179
+
180
+ def get_label_ids(self, label: Union[str, List[str]]) -> List[int]:
181
+ self._ensure_labels_loaded()
182
+ if not self.labels:
183
+ raise ValueError("No labels loaded. Ensure `id2label` exists in model_index.json.")
184
+ if isinstance(label, str):
185
+ label = [label]
186
+ missing = [item for item in label if item not in self.labels]
187
+ if missing:
188
+ preview = ", ".join(list(self.labels.keys())[:8])
189
+ raise ValueError(f"Unknown label(s): {missing}. Example valid labels: {preview}, ...")
190
+ return [self.labels[item] for item in label]
191
+
192
+ def _normalize_class_labels(self, class_labels: Union[int, str, List[Union[int, str]]]) -> List[int]:
193
+ if isinstance(class_labels, int):
194
+ return [class_labels]
195
+ if isinstance(class_labels, str):
196
+ return self.get_label_ids(class_labels)
197
+ if class_labels and isinstance(class_labels[0], str):
198
+ return self.get_label_ids(class_labels)
199
+ return list(class_labels)
200
+
201
+ def _denormalize_latents(self, latents: torch.Tensor) -> torch.Tensor:
202
+ mean = self.latent_channel_mean.to(device=latents.device, dtype=latents.dtype)
203
+ std = self.latent_channel_std.to(device=latents.device, dtype=latents.dtype)
204
+ return latents * std + mean
205
+
206
+ def decode_latents(self, latents: torch.Tensor, output_type: str = "pil"):
207
+ if output_type == "latent":
208
+ return latents
209
+ if self.vae is None:
210
+ raise ValueError(
211
+ "Cannot decode latents without a VAE. Ensure model_index.json lists vae and the variant includes vae/."
212
+ )
213
+ vae_dtype = next(self.vae.parameters()).dtype
214
+ if next(self.vae.parameters()).device != latents.device:
215
+ self.vae.to(device=latents.device, dtype=vae_dtype)
216
+ latents = self._denormalize_latents(latents).to(dtype=vae_dtype)
217
+ image = self.vae.decode(latents).sample
218
+ return self.image_processor.postprocess(image, output_type=output_type)
219
+
220
+ def _predict_velocity_u(
221
+ self,
222
+ latents: torch.Tensor,
223
+ timestep: torch.Tensor,
224
+ time_gap: torch.Tensor,
225
+ class_labels: torch.Tensor,
226
+ class_null: torch.Tensor,
227
+ guidance_scale: float,
228
+ guidance_interval_start: float,
229
+ guidance_interval_end: float,
230
+ do_classifier_free_guidance: bool,
231
+ ) -> torch.Tensor:
232
+ if do_classifier_free_guidance:
233
+ latents_in = torch.cat([latents, latents], dim=0)
234
+ labels = torch.cat([class_labels, class_null], dim=0)
235
+ omega = torch.tensor([guidance_scale, 1.0], device=latents.device, dtype=latents.dtype)
236
+ t_min = torch.tensor([guidance_interval_start, 0.0], device=latents.device, dtype=latents.dtype)
237
+ t_max = torch.tensor([guidance_interval_end, 1.0], device=latents.device, dtype=latents.dtype)
238
+ batch = latents.shape[0]
239
+ timestep_in = timestep.reshape(1).repeat(2 * batch).to(dtype=latents.dtype)
240
+ time_gap_in = time_gap.reshape(1).repeat(2 * batch).to(dtype=latents.dtype)
241
+ omega = omega.repeat(batch)
242
+ t_min = t_min.repeat(batch)
243
+ t_max = t_max.repeat(batch)
244
+ else:
245
+ latents_in = latents
246
+ labels = class_labels
247
+ batch = latents.shape[0]
248
+ timestep_in = timestep.reshape(1).repeat(batch).to(dtype=latents.dtype)
249
+ time_gap_in = time_gap.reshape(1).repeat(batch).to(dtype=latents.dtype)
250
+ omega = torch.full((batch,), guidance_scale, device=latents.device, dtype=latents.dtype)
251
+ t_min = torch.full((batch,), guidance_interval_start, device=latents.device, dtype=latents.dtype)
252
+ t_max = torch.full((batch,), guidance_interval_end, device=latents.device, dtype=latents.dtype)
253
+
254
+ outputs = self.transformer(
255
+ sample=latents_in,
256
+ timestep=timestep_in,
257
+ class_labels=labels,
258
+ time_gap=time_gap_in,
259
+ guidance_scale=omega,
260
+ guidance_interval_start=t_min,
261
+ guidance_interval_end=t_max,
262
+ return_dict=True,
263
+ )
264
+ velocity_u = outputs.velocity_u
265
+
266
+ if not do_classifier_free_guidance:
267
+ return velocity_u
268
+
269
+ u_cond, u_uncond = velocity_u.chunk(2, dim=0)
270
+ return u_uncond + guidance_scale * (u_cond - u_uncond)
271
+
272
+ @torch.inference_mode()
273
+ def __call__(
274
+ self,
275
+ class_labels: Union[int, str, List[Union[int, str]]],
276
+ num_inference_steps: int = 1,
277
+ guidance_scale: float = 2.7,
278
+ guidance_interval_start: float = 0.1,
279
+ guidance_interval_end: float = 0.9,
280
+ generator: Optional[Union[torch.Generator, List[torch.Generator]]] = None,
281
+ latents: Optional[torch.Tensor] = None,
282
+ output_type: Optional[str] = "pil",
283
+ return_dict: bool = True,
284
+ ) -> Union[ImagePipelineOutput, Tuple]:
285
+ if output_type not in {"pil", "np", "pt", "latent"}:
286
+ raise ValueError("output_type must be one of: 'pil', 'np', 'pt', 'latent'.")
287
+
288
+ class_label_ids = self._normalize_class_labels(class_labels)
289
+ do_classifier_free_guidance = guidance_scale > 1.0
290
+ batch_size = len(class_label_ids)
291
+ generator = self._resolve_inference_generator(self._execution_device, generator)
292
+
293
+ image_size = int(self.transformer.config.sample_size)
294
+ channels = int(self.transformer.config.in_channels)
295
+ null_class_val = int(getattr(self.transformer.config, "num_classes", 1000))
296
+
297
+ generator = self._prepare_generator(generator)
298
+
299
+ if latents is None:
300
+ latents = randn_tensor(
301
+ shape=(batch_size, channels, image_size, image_size),
302
+ generator=generator,
303
+ device=self._execution_device,
304
+ dtype=self.transformer.dtype,
305
+ )
306
+
307
+ class_labels_t = torch.tensor(class_label_ids, device=latents.device, dtype=torch.long).reshape(-1)
308
+ class_labels_t = class_labels_t.clamp(0, null_class_val - 1)
309
+ class_null = torch.full_like(class_labels_t, null_class_val)
310
+
311
+ self.scheduler.set_timesteps(num_inference_steps, device=latents.device)
312
+ timesteps = self.scheduler.timesteps
313
+
314
+ extra_step_kwargs = self.prepare_extra_step_kwargs(self.scheduler, generator=generator)
315
+
316
+ for i in self.progress_bar(range(num_inference_steps)):
317
+ t = timesteps[i]
318
+ t_next = timesteps[i + 1]
319
+ time_gap = t - t_next
320
+ velocity_u = self._predict_velocity_u(
321
+ latents,
322
+ t,
323
+ time_gap,
324
+ class_labels_t,
325
+ class_null,
326
+ guidance_scale,
327
+ guidance_interval_start,
328
+ guidance_interval_end,
329
+ do_classifier_free_guidance,
330
+ )
331
+ latents = self.scheduler.step(velocity_u, t, latents, **extra_step_kwargs).prev_sample
332
+
333
+ images = self.decode_latents(latents, output_type=output_type)
334
+
335
+ self.maybe_free_model_hooks()
336
+
337
+ if not return_dict:
338
+ return (images,)
339
+ return ImagePipelineOutput(images=images)
340
+
341
+
342
+ IMFPipelineOutput = ImagePipelineOutput
iMF-B-SIM/scheduler/scheduler_config.json ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ {
2
+ "_class_name": "IMFScheduler",
3
+ "_diffusers_version": "0.36.0",
4
+ "num_train_timesteps": 1000
5
+ }
iMF-B-SIM/scheduler/scheduling_imf.py ADDED
@@ -0,0 +1,105 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from __future__ import annotations
2
+
3
+ from dataclasses import dataclass
4
+ from typing import List, Optional, Tuple, Union
5
+
6
+ import torch
7
+ from diffusers.configuration_utils import ConfigMixin, register_to_config
8
+ from diffusers.schedulers.scheduling_utils import SchedulerMixin
9
+ from diffusers.utils import BaseOutput
10
+ from diffusers.utils.torch_utils import randn_tensor
11
+
12
+
13
+ @dataclass
14
+ class IMFSchedulerOutput(BaseOutput):
15
+ prev_sample: torch.Tensor
16
+
17
+
18
+ class IMFScheduler(SchedulerMixin, ConfigMixin):
19
+ """Mean-flow scheduler with timesteps from 1.0 to 0.0."""
20
+
21
+ order = 1
22
+
23
+ @register_to_config
24
+ def __init__(
25
+ self,
26
+ num_train_timesteps: int = 1000,
27
+ shift: float = 1.0,
28
+ stochastic_sampling: bool = False,
29
+ ):
30
+ self.timesteps: Optional[torch.Tensor] = None
31
+ self.num_inference_steps: Optional[int] = None
32
+ self._step_index: Optional[int] = None
33
+
34
+ @property
35
+ def init_noise_sigma(self) -> float:
36
+ return 1.0
37
+
38
+ def set_timesteps(self, num_inference_steps: int, device: Union[str, torch.device, None] = None) -> None:
39
+ if num_inference_steps < 1:
40
+ raise ValueError("num_inference_steps must be >= 1.")
41
+ self.num_inference_steps = num_inference_steps
42
+ self.timesteps = torch.linspace(1.0, 0.0, num_inference_steps + 1, device=device, dtype=torch.float32)
43
+ self._step_index = 0
44
+
45
+ def scale_model_input(self, sample: torch.Tensor, timestep: Union[float, torch.Tensor]) -> torch.Tensor:
46
+ del timestep
47
+ return sample
48
+
49
+ def _resolve_step_index(self, timestep: Union[float, torch.Tensor, None]) -> int:
50
+ if self._step_index is not None:
51
+ return self._step_index
52
+ if self.timesteps is None:
53
+ raise ValueError("Call `set_timesteps` before `step`.")
54
+ if timestep is None:
55
+ return 0
56
+ t_value = float(timestep) if not isinstance(timestep, torch.Tensor) else float(timestep.flatten()[0])
57
+ matches = (self.timesteps - t_value).abs() < 1e-6
58
+ if matches.any():
59
+ return int(matches.nonzero(as_tuple=False)[0].item())
60
+ return 0
61
+
62
+ def step(
63
+ self,
64
+ model_output: torch.Tensor,
65
+ timestep: Union[float, torch.Tensor, None],
66
+ sample: torch.Tensor,
67
+ return_dict: bool = True,
68
+ generator: Optional[Union[torch.Generator, List[torch.Generator]]] = None,
69
+ ) -> Union[IMFSchedulerOutput, Tuple[torch.Tensor]]:
70
+ if self.timesteps is None:
71
+ raise ValueError("Call `set_timesteps` before `step`.")
72
+
73
+ step_index = self._resolve_step_index(timestep)
74
+ if step_index >= len(self.timesteps) - 1:
75
+ raise ValueError("Scheduler has already reached the final timestep.")
76
+
77
+ t = self.timesteps[step_index]
78
+ t_next = self.timesteps[step_index + 1]
79
+ dt = (t - t_next).to(dtype=sample.dtype, device=sample.device)
80
+ while dt.ndim < sample.ndim:
81
+ dt = dt.unsqueeze(-1)
82
+
83
+ if getattr(self.config, "stochastic_sampling", False):
84
+ t_bc = t.to(dtype=sample.dtype, device=sample.device)
85
+ while t_bc.ndim < sample.ndim:
86
+ t_bc = t_bc.unsqueeze(-1)
87
+ t_next_bc = t_next.to(dtype=sample.dtype, device=sample.device)
88
+ while t_next_bc.ndim < sample.ndim:
89
+ t_next_bc = t_next_bc.unsqueeze(-1)
90
+ x0 = sample - t_bc * model_output
91
+ noise = randn_tensor(
92
+ sample.shape,
93
+ generator=generator,
94
+ device=sample.device,
95
+ dtype=sample.dtype,
96
+ )
97
+ prev_sample = (1.0 - t_next_bc) * x0 + t_next_bc * noise
98
+ else:
99
+ prev_sample = sample - dt * model_output
100
+
101
+ self._step_index = step_index + 1
102
+
103
+ if not return_dict:
104
+ return (prev_sample,)
105
+ return IMFSchedulerOutput(prev_sample=prev_sample)
iMF-B-SIM/transformer/config.json ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "_class_name": "IMFTransformer2DModel",
3
+ "_diffusers_version": "0.38.0",
4
+ "aux_head_depth": 8,
5
+ "depth": 12,
6
+ "embedding_init_constant": 1.0,
7
+ "eval_mode": true,
8
+ "hidden_size": 768,
9
+ "in_channels": 4,
10
+ "mlp_ratio": 2.6666666666666665,
11
+ "model_type": "iMF-B/2",
12
+ "num_attention_heads": 12,
13
+ "num_cfg_tokens": 4,
14
+ "num_class_embeds": null,
15
+ "num_class_tokens": 8,
16
+ "num_classes": 1000,
17
+ "num_interval_tokens": 2,
18
+ "num_time_tokens": 4,
19
+ "patch_size": 2,
20
+ "sample_size": 32,
21
+ "token_init_constant": 1.0,
22
+ "weight_init_constant": 0.32
23
+ }
iMF-B-SIM/transformer/diffusion_pytorch_model.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:583dca284df978363872471904c2b86bc517b8d821b4513f0c304130044ecc6a
3
+ size 355811968
iMF-B-SIM/transformer/transformer_imf.py ADDED
@@ -0,0 +1,586 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from __future__ import annotations
2
+
3
+ import argparse
4
+ import math
5
+ from collections.abc import Mapping
6
+ from dataclasses import dataclass
7
+ from functools import partial
8
+ from math import sqrt
9
+ from typing import Dict, Literal, Optional, Tuple, Union
10
+
11
+ import torch
12
+ import torch.nn as nn
13
+ import torch.nn.functional as F
14
+ from diffusers.configuration_utils import ConfigMixin, register_to_config
15
+ from diffusers.models.modeling_utils import ModelMixin
16
+ from diffusers.utils import BaseOutput
17
+
18
+
19
+ IMF_PRESET_CONFIGS: Dict[str, Dict[str, object]] = {
20
+ "iMF-B/2": {
21
+ "sample_size": 32,
22
+ "patch_size": 2,
23
+ "hidden_size": 768,
24
+ "depth": 12,
25
+ "num_attention_heads": 12,
26
+ "aux_head_depth": 8,
27
+ },
28
+ "iMF-M/2": {
29
+ "sample_size": 32,
30
+ "patch_size": 2,
31
+ "hidden_size": 768,
32
+ "depth": 24,
33
+ "num_attention_heads": 12,
34
+ "aux_head_depth": 8,
35
+ },
36
+ "iMF-L/2": {
37
+ "sample_size": 32,
38
+ "patch_size": 2,
39
+ "hidden_size": 1024,
40
+ "depth": 32,
41
+ "num_attention_heads": 16,
42
+ "aux_head_depth": 8,
43
+ },
44
+ "iMF-XL/2": {
45
+ "sample_size": 32,
46
+ "patch_size": 2,
47
+ "hidden_size": 1024,
48
+ "depth": 48,
49
+ "num_attention_heads": 16,
50
+ "aux_head_depth": 8,
51
+ },
52
+ }
53
+
54
+
55
+ @dataclass
56
+ class IMFTransformer2DModelOutput(BaseOutput):
57
+ velocity_u: torch.Tensor
58
+ velocity_v: Optional[torch.Tensor] = None
59
+
60
+
61
+ def remap_legacy_state_dict(state_dict: Dict[str, torch.Tensor]) -> Dict[str, torch.Tensor]:
62
+ """Map legacy iMF / Flax-style keys to native IMFTransformer2DModel keys."""
63
+ remapped: Dict[str, torch.Tensor] = {}
64
+ for key, value in state_dict.items():
65
+ new_key = key
66
+ for prefix in ("net.", "transformer."):
67
+ if new_key.startswith(prefix):
68
+ new_key = new_key[len(prefix) :]
69
+ break
70
+ new_key = new_key.replace(".kernel", ".weight")
71
+ new_key = new_key.replace("._flax_linear.", ".linear.")
72
+ new_key = new_key.replace("._flax_embedding.", ".embedding.")
73
+ remapped[new_key] = value
74
+ return remapped
75
+
76
+
77
+ def config_from_legacy(config: Dict[str, object]) -> Dict[str, object]:
78
+ model_type = config.get("model_type") or config.get("model_str") or config.get("model_name")
79
+ if model_type not in IMF_PRESET_CONFIGS:
80
+ raise ValueError(f"Unknown iMF preset '{model_type}'. Known: {list(IMF_PRESET_CONFIGS)}")
81
+
82
+ preset = dict(IMF_PRESET_CONFIGS[model_type])
83
+ preset["num_classes"] = int(config.get("num_class_embeds") or config.get("num_classes") or 1000)
84
+ preset["model_type"] = model_type
85
+ if config.get("sample_size") is not None:
86
+ preset["sample_size"] = int(config["sample_size"])
87
+ if config.get("in_channels") is not None:
88
+ preset["in_channels"] = int(config["in_channels"])
89
+ return preset
90
+
91
+
92
+ def _unsqueeze(t: torch.Tensor, dim: int) -> torch.Tensor:
93
+ return t.unsqueeze(dim)
94
+
95
+
96
+ class _ScaledLinear(nn.Module):
97
+ def __init__(
98
+ self,
99
+ in_features: int,
100
+ out_features: int,
101
+ bias: bool = True,
102
+ weight_init: str = "scaled_variance",
103
+ init_constant: float = 1.0,
104
+ bias_init: str = "zeros",
105
+ ):
106
+ super().__init__()
107
+ self.linear = nn.Linear(in_features, out_features, bias=bias)
108
+ if weight_init == "scaled_variance":
109
+ std = init_constant / sqrt(in_features)
110
+ nn.init.normal_(self.linear.weight, std=std)
111
+ elif weight_init == "zeros":
112
+ nn.init.zeros_(self.linear.weight)
113
+ else:
114
+ raise ValueError(f"Invalid weight_init: {weight_init}")
115
+ if bias:
116
+ if bias_init == "zeros":
117
+ nn.init.zeros_(self.linear.bias)
118
+ else:
119
+ raise ValueError(f"Invalid bias_init: {bias_init}")
120
+
121
+ def forward(self, x: torch.Tensor) -> torch.Tensor:
122
+ return self.linear(x)
123
+
124
+
125
+ class _ScaledEmbedding(nn.Module):
126
+ def __init__(
127
+ self,
128
+ num_embeddings: int,
129
+ embedding_dim: int,
130
+ weight_init: str = "scaled_variance",
131
+ init_constant: float = 1.0,
132
+ ):
133
+ super().__init__()
134
+ self.embedding = nn.Embedding(num_embeddings, embedding_dim)
135
+ if weight_init == "scaled_variance":
136
+ std = init_constant / sqrt(embedding_dim)
137
+ nn.init.normal_(self.embedding.weight, std=std)
138
+ else:
139
+ raise ValueError(f"Invalid weight_init: {weight_init}")
140
+
141
+ def forward(self, x: torch.Tensor) -> torch.Tensor:
142
+ return self.embedding(x)
143
+
144
+
145
+ class _RMSNorm(nn.Module):
146
+ def __init__(self, dim: int, eps: float = 1e-6):
147
+ super().__init__()
148
+ self.weight = nn.Parameter(torch.ones(dim))
149
+ self.eps = eps
150
+
151
+ def forward(self, x: torch.Tensor) -> torch.Tensor:
152
+ mean_square = torch.mean(torch.square(x), dim=-1, keepdim=True)
153
+ output = x * torch.rsqrt(mean_square + self.eps)
154
+ return output.to(x.dtype) * self.weight
155
+
156
+
157
+ class _SwiGLUMlp(nn.Module):
158
+ def __init__(
159
+ self,
160
+ in_features: int,
161
+ hidden_features: int,
162
+ weight_init: str = "scaled_variance",
163
+ weight_init_constant: float = 1.0,
164
+ ):
165
+ super().__init__()
166
+ init_kwargs = dict(bias=False, weight_init=weight_init, init_constant=weight_init_constant)
167
+ self.w1 = _ScaledLinear(in_features, hidden_features, **init_kwargs)
168
+ self.w3 = _ScaledLinear(in_features, hidden_features, **init_kwargs)
169
+ self.w2 = _ScaledLinear(hidden_features, in_features, **init_kwargs)
170
+
171
+ def forward(self, x: torch.Tensor) -> torch.Tensor:
172
+ return self.w2(F.silu(self.w1(x)) * self.w3(x))
173
+
174
+
175
+ class IMFTimestepEmbedder(nn.Module):
176
+ def __init__(
177
+ self,
178
+ hidden_size: int,
179
+ frequency_embedding_size: int = 256,
180
+ init_constant: float = 1.0,
181
+ ):
182
+ super().__init__()
183
+ self.mlp = nn.Sequential(
184
+ _ScaledLinear(frequency_embedding_size, hidden_size, bias=True, init_constant=init_constant),
185
+ nn.SiLU(),
186
+ _ScaledLinear(hidden_size, hidden_size, bias=True, init_constant=init_constant),
187
+ )
188
+ self.frequency_embedding_size = frequency_embedding_size
189
+
190
+ @staticmethod
191
+ def timestep_embedding(t: torch.Tensor, dim: int, max_period: int = 10000) -> torch.Tensor:
192
+ half = dim // 2
193
+ freqs = torch.exp(
194
+ -math.log(max_period) * torch.arange(start=0, end=half, dtype=t.dtype, device=t.device) / half
195
+ )
196
+ args = t[:, None] * freqs[None]
197
+ embedding = torch.cat([torch.cos(args), torch.sin(args)], dim=-1)
198
+ if dim % 2:
199
+ embedding = torch.cat([embedding, torch.zeros_like(embedding[:, :1])], dim=-1)
200
+ return embedding
201
+
202
+ def forward(self, t: torch.Tensor) -> torch.Tensor:
203
+ return self.mlp(self.timestep_embedding(t, self.frequency_embedding_size))
204
+
205
+
206
+ class IMFLabelEmbedder(nn.Module):
207
+ def __init__(self, num_classes: int, hidden_size: int, init_constant: float = 1.0):
208
+ super().__init__()
209
+ self.embedding_table = _ScaledEmbedding(num_classes + 1, hidden_size, init_constant=init_constant)
210
+
211
+ def forward(self, labels: torch.Tensor) -> torch.Tensor:
212
+ return self.embedding_table(labels)
213
+
214
+
215
+ class IMFPatchEmbedder(nn.Module):
216
+ def __init__(self, input_size: int, patch_size: int, in_channels: int, hidden_size: int, bias: bool = True):
217
+ super().__init__()
218
+ self.patch_size = (patch_size, patch_size)
219
+ self.num_patches = (input_size // patch_size) ** 2
220
+ self.proj = nn.Conv2d(
221
+ in_channels,
222
+ hidden_size,
223
+ kernel_size=patch_size,
224
+ stride=patch_size,
225
+ bias=bias,
226
+ )
227
+ kh = kw = patch_size
228
+ fan_in = kh * kw * in_channels
229
+ fan_out = hidden_size
230
+ limit = math.sqrt(6.0 / (fan_in + fan_out))
231
+ nn.init.uniform_(self.proj.weight, -limit, limit)
232
+ if bias:
233
+ nn.init.zeros_(self.proj.bias)
234
+
235
+ def forward(self, x: torch.Tensor) -> torch.Tensor:
236
+ x = self.proj(x)
237
+ return x.flatten(2).transpose(1, 2)
238
+
239
+
240
+ def precompute_rope_freqs(dim: int, seq_len: int, theta: float = 10000.0, device: torch.device | None = None):
241
+ freqs = 1.0 / (theta ** (torch.arange(0, dim, 2, dtype=torch.float32, device=device) / dim))
242
+ positions = torch.arange(seq_len, dtype=torch.float32, device=device)
243
+ freqs_cis = torch.outer(positions, freqs)
244
+ return torch.complex(torch.cos(freqs_cis), torch.sin(freqs_cis))
245
+
246
+
247
+ def apply_rotary_pos_emb(x: torch.Tensor, freqs_cis: torch.Tensor) -> torch.Tensor:
248
+ x_dtype = x.dtype
249
+ x_complex = torch.view_as_complex(x.to(torch.float32).reshape(*x.shape[:-1], -1, 2))
250
+ freqs_cis = freqs_cis.unsqueeze(0).unsqueeze(2).to(x.device)
251
+ x_rotated = x_complex * freqs_cis
252
+ x_out = torch.view_as_real(x_rotated).flatten(-2)
253
+ return x_out.to(dtype=x_dtype)
254
+
255
+
256
+ class IMFRoPEAttention(nn.Module):
257
+ def __init__(self, hidden_size: int, num_heads: int, weight_init_constant: float = 0.32):
258
+ super().__init__()
259
+ self.hidden_size = hidden_size
260
+ self.num_heads = num_heads
261
+ self.head_dim = hidden_size // num_heads
262
+ init_kwargs = dict(bias=False, init_constant=weight_init_constant)
263
+ self.q_proj = _ScaledLinear(hidden_size, hidden_size, **init_kwargs)
264
+ self.k_proj = _ScaledLinear(hidden_size, hidden_size, **init_kwargs)
265
+ self.v_proj = _ScaledLinear(hidden_size, hidden_size, **init_kwargs)
266
+ self.out_proj = _ScaledLinear(hidden_size, hidden_size, **init_kwargs)
267
+ self.q_norm = _RMSNorm(self.head_dim)
268
+ self.k_norm = _RMSNorm(self.head_dim)
269
+
270
+ def forward(self, x: torch.Tensor, rope_freqs: torch.Tensor) -> torch.Tensor:
271
+ batch, seq_len, _ = x.shape
272
+ q = self.q_proj(x).reshape(batch, seq_len, self.num_heads, self.head_dim)
273
+ k = self.k_proj(x).reshape(batch, seq_len, self.num_heads, self.head_dim)
274
+ v = self.v_proj(x).reshape(batch, seq_len, self.num_heads, self.head_dim)
275
+ q = apply_rotary_pos_emb(self.q_norm(q), rope_freqs)
276
+ k = apply_rotary_pos_emb(self.k_norm(k), rope_freqs)
277
+ query = q / math.sqrt(self.head_dim)
278
+ attn_weights = torch.einsum("bqhd,bkhd->bhqk", query, k)
279
+ attn_weights = F.softmax(attn_weights, dim=-1, dtype=torch.float32)
280
+ attn = torch.einsum("bhqk,bkhd->bqhd", attn_weights.to(dtype=v.dtype), v)
281
+ return self.out_proj(attn.reshape(batch, seq_len, self.hidden_size))
282
+
283
+
284
+ class IMFTransformerBlock(nn.Module):
285
+ def __init__(self, hidden_size: int, num_heads: int, mlp_ratio: float, weight_init_constant: float):
286
+ super().__init__()
287
+ self.norm1 = _RMSNorm(hidden_size)
288
+ self.attn = IMFRoPEAttention(hidden_size, num_heads, weight_init_constant=weight_init_constant)
289
+ self.norm2 = _RMSNorm(hidden_size)
290
+ mlp_hidden_dim = int(hidden_size * mlp_ratio)
291
+ self.mlp = _SwiGLUMlp(hidden_size, mlp_hidden_dim, weight_init_constant=weight_init_constant)
292
+ self.attn_scale = nn.Parameter(torch.zeros(hidden_size))
293
+ self.mlp_scale = nn.Parameter(torch.zeros(hidden_size))
294
+
295
+ def forward(self, x: torch.Tensor, rope_freqs: torch.Tensor) -> torch.Tensor:
296
+ x = x + self.attn(self.norm1(x), rope_freqs) * self.attn_scale
297
+ x = x + self.mlp(self.norm2(x)) * self.mlp_scale
298
+ return x
299
+
300
+
301
+ class IMFFinalLayer(nn.Module):
302
+ def __init__(self, hidden_size: int, patch_size: int, out_channels: int):
303
+ super().__init__()
304
+ self.norm = _RMSNorm(hidden_size)
305
+ self.linear = _ScaledLinear(
306
+ hidden_size,
307
+ patch_size * patch_size * out_channels,
308
+ bias=True,
309
+ weight_init="zeros",
310
+ init_constant=1.0,
311
+ )
312
+
313
+ def forward(self, x: torch.Tensor) -> torch.Tensor:
314
+ return self.linear(self.norm(x))
315
+
316
+
317
+ class IMFTransformer2DModel(ModelMixin, ConfigMixin):
318
+ _supports_gradient_checkpointing = True
319
+
320
+ @register_to_config
321
+ def __init__(
322
+ self,
323
+ sample_size: int = 32,
324
+ patch_size: int = 2,
325
+ in_channels: int = 4,
326
+ hidden_size: int = 768,
327
+ depth: int = 12,
328
+ num_attention_heads: int = 12,
329
+ mlp_ratio: float = 8 / 3,
330
+ num_classes: int = 1000,
331
+ aux_head_depth: int = 8,
332
+ num_class_tokens: int = 8,
333
+ num_time_tokens: int = 4,
334
+ num_cfg_tokens: int = 4,
335
+ num_interval_tokens: int = 2,
336
+ token_init_constant: float = 1.0,
337
+ embedding_init_constant: float = 1.0,
338
+ weight_init_constant: float = 0.32,
339
+ eval_mode: bool = True,
340
+ model_type: str | None = None,
341
+ num_class_embeds: int | None = None,
342
+ ):
343
+ super().__init__()
344
+ if num_class_embeds is not None:
345
+ num_classes = int(num_class_embeds)
346
+ if model_type in IMF_PRESET_CONFIGS:
347
+ preset = IMF_PRESET_CONFIGS[model_type]
348
+ sample_size = int(preset["sample_size"])
349
+ patch_size = int(preset["patch_size"])
350
+ hidden_size = int(preset["hidden_size"])
351
+ depth = int(preset["depth"])
352
+ num_attention_heads = int(preset["num_attention_heads"])
353
+ aux_head_depth = int(preset["aux_head_depth"])
354
+
355
+ self.sample_size = sample_size
356
+ self.patch_size = patch_size
357
+ self.in_channels = in_channels
358
+ self.out_channels = in_channels
359
+ self.hidden_size = hidden_size
360
+ self.depth = depth
361
+ self.num_attention_heads = num_attention_heads
362
+ self.num_classes = num_classes
363
+ self.aux_head_depth = aux_head_depth
364
+ self.num_class_tokens = num_class_tokens
365
+ self.num_time_tokens = num_time_tokens
366
+ self.num_cfg_tokens = num_cfg_tokens
367
+ self.num_interval_tokens = num_interval_tokens
368
+ self.eval_mode = eval_mode
369
+ self.gradient_checkpointing = False
370
+
371
+ self.x_embedder = IMFPatchEmbedder(sample_size, patch_size, in_channels, hidden_size, bias=True)
372
+ embed_kwargs = dict(hidden_size=hidden_size, init_constant=embedding_init_constant)
373
+ self.h_embedder = IMFTimestepEmbedder(**embed_kwargs)
374
+ self.omega_embedder = IMFTimestepEmbedder(**embed_kwargs)
375
+ self.cfg_t_start_embedder = IMFTimestepEmbedder(**embed_kwargs)
376
+ self.cfg_t_end_embedder = IMFTimestepEmbedder(**embed_kwargs)
377
+ self.y_embedder = IMFLabelEmbedder(num_classes, hidden_size, init_constant=embedding_init_constant)
378
+
379
+ token_std = token_init_constant / math.sqrt(hidden_size)
380
+ self.time_tokens = nn.Parameter(torch.randn(num_time_tokens, hidden_size) * token_std)
381
+ self.class_tokens = nn.Parameter(torch.randn(num_class_tokens, hidden_size) * token_std)
382
+ self.omega_tokens = nn.Parameter(torch.randn(num_cfg_tokens, hidden_size) * token_std)
383
+ self.t_min_tokens = nn.Parameter(torch.randn(num_interval_tokens, hidden_size) * token_std)
384
+ self.t_max_tokens = nn.Parameter(torch.randn(num_interval_tokens, hidden_size) * token_std)
385
+
386
+ total_tokens = (
387
+ self.x_embedder.num_patches
388
+ + num_class_tokens
389
+ + num_cfg_tokens
390
+ + 2 * num_interval_tokens
391
+ + num_time_tokens
392
+ )
393
+ self.prefix_tokens = num_class_tokens + num_cfg_tokens + 2 * num_interval_tokens + num_time_tokens
394
+ self.head_dim = hidden_size // num_attention_heads
395
+ self.register_buffer(
396
+ "rope_freqs",
397
+ precompute_rope_freqs(self.head_dim, total_tokens),
398
+ persistent=False,
399
+ )
400
+
401
+ shared_depth = depth - aux_head_depth
402
+ block_kwargs = dict(
403
+ hidden_size=hidden_size,
404
+ num_heads=num_attention_heads,
405
+ mlp_ratio=mlp_ratio,
406
+ weight_init_constant=weight_init_constant,
407
+ )
408
+ self.shared_blocks = nn.ModuleList([IMFTransformerBlock(**block_kwargs) for _ in range(shared_depth)])
409
+ self.u_heads = nn.ModuleList([IMFTransformerBlock(**block_kwargs) for _ in range(aux_head_depth)])
410
+ self.v_heads = nn.ModuleList(
411
+ [IMFTransformerBlock(**block_kwargs) for _ in range(aux_head_depth if not eval_mode else 0)]
412
+ )
413
+ self.u_final_layer = IMFFinalLayer(hidden_size, patch_size, in_channels)
414
+ self.v_final_layer = IMFFinalLayer(hidden_size, patch_size, in_channels)
415
+
416
+ def unpatchify(self, x: torch.Tensor) -> torch.Tensor:
417
+ c = self.out_channels
418
+ p = self.patch_size
419
+ h = w = int(x.shape[1] ** 0.5)
420
+ x = x.reshape(x.shape[0], h, w, p, p, c)
421
+ x = torch.einsum("nhwpqc->nchpwq", x)
422
+ return x.reshape(x.shape[0], c, h * p, w * p)
423
+
424
+ def _build_sequence(
425
+ self,
426
+ sample: torch.Tensor,
427
+ time_gap: torch.Tensor,
428
+ guidance_scale: torch.Tensor,
429
+ guidance_interval_start: torch.Tensor,
430
+ guidance_interval_end: torch.Tensor,
431
+ class_labels: torch.Tensor,
432
+ ) -> torch.Tensor:
433
+ x_embed = self.x_embedder(sample)
434
+ h_embed = self.h_embedder(time_gap)
435
+ omega_embed = self.omega_embedder(1 - 1 / guidance_scale)
436
+ t_min_embed = self.cfg_t_start_embedder(guidance_interval_start)
437
+ t_max_embed = self.cfg_t_end_embedder(guidance_interval_end)
438
+ y_embed = self.y_embedder(class_labels)
439
+
440
+ time_tokens = self.time_tokens + _unsqueeze(h_embed, 1)
441
+ omega_tokens = self.omega_tokens + _unsqueeze(omega_embed, 1)
442
+ t_min_tokens = self.t_min_tokens + _unsqueeze(t_min_embed, 1)
443
+ t_max_tokens = self.t_max_tokens + _unsqueeze(t_max_embed, 1)
444
+ class_tokens = self.class_tokens + _unsqueeze(y_embed, 1)
445
+
446
+ return torch.cat(
447
+ [class_tokens, omega_tokens, t_min_tokens, t_max_tokens, time_tokens, x_embed],
448
+ dim=1,
449
+ )
450
+
451
+ def forward(
452
+ self,
453
+ sample: torch.Tensor,
454
+ timestep: torch.Tensor,
455
+ class_labels: torch.Tensor,
456
+ time_gap: Optional[torch.Tensor] = None,
457
+ guidance_scale: Optional[torch.Tensor] = None,
458
+ guidance_interval_start: Optional[torch.Tensor] = None,
459
+ guidance_interval_end: Optional[torch.Tensor] = None,
460
+ return_dict: bool = True,
461
+ ) -> Union[IMFTransformer2DModelOutput, Tuple[torch.Tensor, ...]]:
462
+ batch_size = sample.shape[0]
463
+ timestep = self._expand_batch(timestep, batch_size, sample.device, sample.dtype)
464
+ if time_gap is None:
465
+ time_gap = timestep
466
+ else:
467
+ time_gap = self._expand_batch(time_gap, batch_size, sample.device, sample.dtype)
468
+ if guidance_scale is None:
469
+ guidance_scale = torch.ones(batch_size, device=sample.device, dtype=sample.dtype)
470
+ else:
471
+ guidance_scale = self._expand_batch(guidance_scale, batch_size, sample.device, sample.dtype)
472
+ if guidance_interval_start is None:
473
+ guidance_interval_start = torch.zeros(batch_size, device=sample.device, dtype=sample.dtype)
474
+ else:
475
+ guidance_interval_start = self._expand_batch(
476
+ guidance_interval_start, batch_size, sample.device, sample.dtype
477
+ )
478
+ if guidance_interval_end is None:
479
+ guidance_interval_end = torch.ones(batch_size, device=sample.device, dtype=sample.dtype)
480
+ else:
481
+ guidance_interval_end = self._expand_batch(
482
+ guidance_interval_end, batch_size, sample.device, sample.dtype
483
+ )
484
+
485
+ class_labels = class_labels.reshape(-1).long()
486
+ seq = self._build_sequence(
487
+ sample,
488
+ time_gap,
489
+ guidance_scale,
490
+ guidance_interval_start,
491
+ guidance_interval_end,
492
+ class_labels,
493
+ )
494
+
495
+ for block in self.shared_blocks:
496
+ if self.training and self.gradient_checkpointing:
497
+ seq = torch.utils.checkpoint.checkpoint(block, seq, self.rope_freqs, use_reentrant=False)
498
+ else:
499
+ seq = block(seq, self.rope_freqs)
500
+
501
+ u_seq = v_seq = seq
502
+ for block in self.u_heads:
503
+ u_seq = block(u_seq, self.rope_freqs)
504
+ for block in self.v_heads:
505
+ v_seq = block(v_seq, self.rope_freqs)
506
+
507
+ u_tokens = u_seq[:, self.prefix_tokens :]
508
+ velocity_u = self.unpatchify(self.u_final_layer(u_tokens))
509
+
510
+ velocity_v = None
511
+ if len(self.v_heads) > 0:
512
+ v_tokens = v_seq[:, self.prefix_tokens :]
513
+ velocity_v = self.unpatchify(self.v_final_layer(v_tokens))
514
+
515
+ if not return_dict:
516
+ if velocity_v is None:
517
+ return (velocity_u,)
518
+ return (velocity_u, velocity_v)
519
+ return IMFTransformer2DModelOutput(velocity_u=velocity_u, velocity_v=velocity_v)
520
+
521
+ @staticmethod
522
+ def _expand_batch(
523
+ value: torch.Tensor,
524
+ batch_size: int,
525
+ device: torch.device,
526
+ dtype: torch.dtype,
527
+ ) -> torch.Tensor:
528
+ value = torch.as_tensor(value, device=device, dtype=dtype)
529
+ if value.ndim == 0:
530
+ value = value.reshape(1).repeat(batch_size)
531
+ else:
532
+ value = value.reshape(-1)
533
+ if value.shape[0] == 1 and batch_size > 1:
534
+ value = value.repeat(batch_size)
535
+ return value
536
+
537
+ @classmethod
538
+ def from_imf_checkpoint(
539
+ cls,
540
+ checkpoint_path: str,
541
+ model_type: str | None = None,
542
+ map_location: str = "cpu",
543
+ strict: bool = True,
544
+ eval_mode: bool = True,
545
+ ) -> Tuple["IMFTransformer2DModel", Dict[str, object]]:
546
+ checkpoint = torch.load(checkpoint_path, map_location=map_location, weights_only=False)
547
+ if isinstance(checkpoint, Mapping) and "state_dict" in checkpoint:
548
+ state_dict = checkpoint["state_dict"]
549
+ elif isinstance(checkpoint, Mapping) and any(k.startswith("net.") for k in checkpoint):
550
+ state_dict = checkpoint
551
+ else:
552
+ state_dict = checkpoint
553
+
554
+ inferred_type = model_type
555
+ if inferred_type is None and isinstance(checkpoint, Mapping):
556
+ args = checkpoint.get("args")
557
+ if isinstance(args, argparse.Namespace):
558
+ inferred_type = getattr(args, "model", None) or getattr(args, "model_str", None)
559
+ elif isinstance(args, Mapping):
560
+ inferred_type = args.get("model") or args.get("model_str")
561
+
562
+ if inferred_type is None:
563
+ raise ValueError("model_type must be provided when loading a raw state dict checkpoint.")
564
+
565
+ config = dict(IMF_PRESET_CONFIGS[inferred_type])
566
+ config["model_type"] = inferred_type
567
+ config["eval_mode"] = eval_mode
568
+ model = cls(**config)
569
+ model.load_state_dict(remap_legacy_state_dict(state_dict), strict=strict)
570
+ metadata = {"checkpoint_path": checkpoint_path, "model_type": inferred_type}
571
+ return model, metadata
572
+
573
+ def to_imf_checkpoint(self, prefix: str = "net.") -> Dict[str, torch.Tensor]:
574
+ state: Dict[str, torch.Tensor] = {}
575
+ for key, value in self.state_dict().items():
576
+ if key == "rope_freqs":
577
+ continue
578
+ state[f"{prefix}{key}"] = value.detach().cpu()
579
+ return state
580
+
581
+ @property
582
+ def net(self):
583
+ return self
584
+
585
+
586
+ IMFDiffusersModel = IMFTransformer2DModel
iMF-B-SIM/vae/config.json ADDED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "_class_name": "AutoencoderKL",
3
+ "_diffusers_version": "0.36.0",
4
+ "_name_or_path": "stabilityai/sd-vae-ft-mse",
5
+ "act_fn": "silu",
6
+ "block_out_channels": [
7
+ 128,
8
+ 256,
9
+ 512,
10
+ 512
11
+ ],
12
+ "down_block_types": [
13
+ "DownEncoderBlock2D",
14
+ "DownEncoderBlock2D",
15
+ "DownEncoderBlock2D",
16
+ "DownEncoderBlock2D"
17
+ ],
18
+ "force_upcast": true,
19
+ "in_channels": 3,
20
+ "latent_channels": 4,
21
+ "latents_mean": null,
22
+ "latents_std": null,
23
+ "layers_per_block": 2,
24
+ "mid_block_add_attention": true,
25
+ "norm_num_groups": 32,
26
+ "out_channels": 3,
27
+ "sample_size": 256,
28
+ "scaling_factor": 0.18215,
29
+ "shift_factor": null,
30
+ "up_block_types": [
31
+ "UpDecoderBlock2D",
32
+ "UpDecoderBlock2D",
33
+ "UpDecoderBlock2D",
34
+ "UpDecoderBlock2D"
35
+ ],
36
+ "use_post_quant_conv": true,
37
+ "use_quant_conv": true
38
+ }
iMF-B-SIM/vae/diffusion_pytorch_model.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:a1d993488569e928462932c8c38a0760b874d166399b14414135bd9c42df5815
3
+ size 334643276
iMF-L-SIM/README.md ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: mit
3
+ library_name: diffusers
4
+ pipeline_tag: text-to-image
5
+ tags:
6
+ - diffusers
7
+ - imf
8
+ - image-generation
9
+ - class-conditional
10
+ ---
11
+
12
+ # iMF-L-SIM
13
+
14
+ Self-contained Diffusers variant for **iMF-L/2 (FD-SIM post-trained)** (Improved Mean Flows).
15
+
16
+ ## Load
17
+
18
+ ```python
19
+ from pathlib import Path
20
+ from diffusers import DiffusionPipeline
21
+ import torch
22
+
23
+ model_dir = Path("iMF-L-SIM")
24
+ pipe = DiffusionPipeline.from_pretrained(
25
+ str(model_dir),
26
+ local_files_only=True,
27
+ custom_pipeline=str(model_dir / "pipeline.py"),
28
+ trust_remote_code=True,
29
+ torch_dtype=torch.float32,
30
+ )
31
+ pipe.to("cuda")
32
+
33
+ image = pipe(
34
+ class_labels=207,
35
+ num_inference_steps=1,
36
+ guidance_scale=8.0,
37
+ guidance_interval_start=0.4,
38
+ guidance_interval_end=0.65,
39
+ ).images[0]
40
+ ```
iMF-L-SIM/model_index.json ADDED
@@ -0,0 +1,1021 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "_class_name": [
3
+ "pipeline",
4
+ "IMFPipeline"
5
+ ],
6
+ "_diffusers_version": "0.36.0",
7
+ "scheduler": [
8
+ "scheduling_imf",
9
+ "IMFScheduler"
10
+ ],
11
+ "transformer": [
12
+ "transformer_imf",
13
+ "IMFTransformer2DModel"
14
+ ],
15
+ "id2label": {
16
+ "0": "tench, Tinca tinca",
17
+ "1": "goldfish, Carassius auratus",
18
+ "2": "great white shark, white shark, man-eater, man-eating shark, Carcharodon carcharias",
19
+ "3": "tiger shark, Galeocerdo cuvieri",
20
+ "4": "hammerhead, hammerhead shark",
21
+ "5": "electric ray, crampfish, numbfish, torpedo",
22
+ "6": "stingray",
23
+ "7": "cock",
24
+ "8": "hen",
25
+ "9": "ostrich, Struthio camelus",
26
+ "10": "brambling, Fringilla montifringilla",
27
+ "11": "goldfinch, Carduelis carduelis",
28
+ "12": "house finch, linnet, Carpodacus mexicanus",
29
+ "13": "junco, snowbird",
30
+ "14": "indigo bunting, indigo finch, indigo bird, Passerina cyanea",
31
+ "15": "robin, American robin, Turdus migratorius",
32
+ "16": "bulbul",
33
+ "17": "jay",
34
+ "18": "magpie",
35
+ "19": "chickadee",
36
+ "20": "water ouzel, dipper",
37
+ "21": "kite",
38
+ "22": "bald eagle, American eagle, Haliaeetus leucocephalus",
39
+ "23": "vulture",
40
+ "24": "great grey owl, great gray owl, Strix nebulosa",
41
+ "25": "European fire salamander, Salamandra salamandra",
42
+ "26": "common newt, Triturus vulgaris",
43
+ "27": "eft",
44
+ "28": "spotted salamander, Ambystoma maculatum",
45
+ "29": "axolotl, mud puppy, Ambystoma mexicanum",
46
+ "30": "bullfrog, Rana catesbeiana",
47
+ "31": "tree frog, tree-frog",
48
+ "32": "tailed frog, bell toad, ribbed toad, tailed toad, Ascaphus trui",
49
+ "33": "loggerhead, loggerhead turtle, Caretta caretta",
50
+ "34": "leatherback turtle, leatherback, leathery turtle, Dermochelys coriacea",
51
+ "35": "mud turtle",
52
+ "36": "terrapin",
53
+ "37": "box turtle, box tortoise",
54
+ "38": "banded gecko",
55
+ "39": "common iguana, iguana, Iguana iguana",
56
+ "40": "American chameleon, anole, Anolis carolinensis",
57
+ "41": "whiptail, whiptail lizard",
58
+ "42": "agama",
59
+ "43": "frilled lizard, Chlamydosaurus kingi",
60
+ "44": "alligator lizard",
61
+ "45": "Gila monster, Heloderma suspectum",
62
+ "46": "green lizard, Lacerta viridis",
63
+ "47": "African chameleon, Chamaeleo chamaeleon",
64
+ "48": "Komodo dragon, Komodo lizard, dragon lizard, giant lizard, Varanus komodoensis",
65
+ "49": "African crocodile, Nile crocodile, Crocodylus niloticus",
66
+ "50": "American alligator, Alligator mississipiensis",
67
+ "51": "triceratops",
68
+ "52": "thunder snake, worm snake, Carphophis amoenus",
69
+ "53": "ringneck snake, ring-necked snake, ring snake",
70
+ "54": "hognose snake, puff adder, sand viper",
71
+ "55": "green snake, grass snake",
72
+ "56": "king snake, kingsnake",
73
+ "57": "garter snake, grass snake",
74
+ "58": "water snake",
75
+ "59": "vine snake",
76
+ "60": "night snake, Hypsiglena torquata",
77
+ "61": "boa constrictor, Constrictor constrictor",
78
+ "62": "rock python, rock snake, Python sebae",
79
+ "63": "Indian cobra, Naja naja",
80
+ "64": "green mamba",
81
+ "65": "sea snake",
82
+ "66": "horned viper, cerastes, sand viper, horned asp, Cerastes cornutus",
83
+ "67": "diamondback, diamondback rattlesnake, Crotalus adamanteus",
84
+ "68": "sidewinder, horned rattlesnake, Crotalus cerastes",
85
+ "69": "trilobite",
86
+ "70": "harvestman, daddy longlegs, Phalangium opilio",
87
+ "71": "scorpion",
88
+ "72": "black and gold garden spider, Argiope aurantia",
89
+ "73": "barn spider, Araneus cavaticus",
90
+ "74": "garden spider, Aranea diademata",
91
+ "75": "black widow, Latrodectus mactans",
92
+ "76": "tarantula",
93
+ "77": "wolf spider, hunting spider",
94
+ "78": "tick",
95
+ "79": "centipede",
96
+ "80": "black grouse",
97
+ "81": "ptarmigan",
98
+ "82": "ruffed grouse, partridge, Bonasa umbellus",
99
+ "83": "prairie chicken, prairie grouse, prairie fowl",
100
+ "84": "peacock",
101
+ "85": "quail",
102
+ "86": "partridge",
103
+ "87": "African grey, African gray, Psittacus erithacus",
104
+ "88": "macaw",
105
+ "89": "sulphur-crested cockatoo, Kakatoe galerita, Cacatua galerita",
106
+ "90": "lorikeet",
107
+ "91": "coucal",
108
+ "92": "bee eater",
109
+ "93": "hornbill",
110
+ "94": "hummingbird",
111
+ "95": "jacamar",
112
+ "96": "toucan",
113
+ "97": "drake",
114
+ "98": "red-breasted merganser, Mergus serrator",
115
+ "99": "goose",
116
+ "100": "black swan, Cygnus atratus",
117
+ "101": "tusker",
118
+ "102": "echidna, spiny anteater, anteater",
119
+ "103": "platypus, duckbill, duckbilled platypus, duck-billed platypus, Ornithorhynchus anatinus",
120
+ "104": "wallaby, brush kangaroo",
121
+ "105": "koala, koala bear, kangaroo bear, native bear, Phascolarctos cinereus",
122
+ "106": "wombat",
123
+ "107": "jellyfish",
124
+ "108": "sea anemone, anemone",
125
+ "109": "brain coral",
126
+ "110": "flatworm, platyhelminth",
127
+ "111": "nematode, nematode worm, roundworm",
128
+ "112": "conch",
129
+ "113": "snail",
130
+ "114": "slug",
131
+ "115": "sea slug, nudibranch",
132
+ "116": "chiton, coat-of-mail shell, sea cradle, polyplacophore",
133
+ "117": "chambered nautilus, pearly nautilus, nautilus",
134
+ "118": "Dungeness crab, Cancer magister",
135
+ "119": "rock crab, Cancer irroratus",
136
+ "120": "fiddler crab",
137
+ "121": "king crab, Alaska crab, Alaskan king crab, Alaska king crab, Paralithodes camtschatica",
138
+ "122": "American lobster, Northern lobster, Maine lobster, Homarus americanus",
139
+ "123": "spiny lobster, langouste, rock lobster, crawfish, crayfish, sea crawfish",
140
+ "124": "crayfish, crawfish, crawdad, crawdaddy",
141
+ "125": "hermit crab",
142
+ "126": "isopod",
143
+ "127": "white stork, Ciconia ciconia",
144
+ "128": "black stork, Ciconia nigra",
145
+ "129": "spoonbill",
146
+ "130": "flamingo",
147
+ "131": "little blue heron, Egretta caerulea",
148
+ "132": "American egret, great white heron, Egretta albus",
149
+ "133": "bittern",
150
+ "134": "crane",
151
+ "135": "limpkin, Aramus pictus",
152
+ "136": "European gallinule, Porphyrio porphyrio",
153
+ "137": "American coot, marsh hen, mud hen, water hen, Fulica americana",
154
+ "138": "bustard",
155
+ "139": "ruddy turnstone, Arenaria interpres",
156
+ "140": "red-backed sandpiper, dunlin, Erolia alpina",
157
+ "141": "redshank, Tringa totanus",
158
+ "142": "dowitcher",
159
+ "143": "oystercatcher, oyster catcher",
160
+ "144": "pelican",
161
+ "145": "king penguin, Aptenodytes patagonica",
162
+ "146": "albatross, mollymawk",
163
+ "147": "grey whale, gray whale, devilfish, Eschrichtius gibbosus, Eschrichtius robustus",
164
+ "148": "killer whale, killer, orca, grampus, sea wolf, Orcinus orca",
165
+ "149": "dugong, Dugong dugon",
166
+ "150": "sea lion",
167
+ "151": "Chihuahua",
168
+ "152": "Japanese spaniel",
169
+ "153": "Maltese dog, Maltese terrier, Maltese",
170
+ "154": "Pekinese, Pekingese, Peke",
171
+ "155": "Shih-Tzu",
172
+ "156": "Blenheim spaniel",
173
+ "157": "papillon",
174
+ "158": "toy terrier",
175
+ "159": "Rhodesian ridgeback",
176
+ "160": "Afghan hound, Afghan",
177
+ "161": "basset, basset hound",
178
+ "162": "beagle",
179
+ "163": "bloodhound, sleuthhound",
180
+ "164": "bluetick",
181
+ "165": "black-and-tan coonhound",
182
+ "166": "Walker hound, Walker foxhound",
183
+ "167": "English foxhound",
184
+ "168": "redbone",
185
+ "169": "borzoi, Russian wolfhound",
186
+ "170": "Irish wolfhound",
187
+ "171": "Italian greyhound",
188
+ "172": "whippet",
189
+ "173": "Ibizan hound, Ibizan Podenco",
190
+ "174": "Norwegian elkhound, elkhound",
191
+ "175": "otterhound, otter hound",
192
+ "176": "Saluki, gazelle hound",
193
+ "177": "Scottish deerhound, deerhound",
194
+ "178": "Weimaraner",
195
+ "179": "Staffordshire bullterrier, Staffordshire bull terrier",
196
+ "180": "American Staffordshire terrier, Staffordshire terrier, American pit bull terrier, pit bull terrier",
197
+ "181": "Bedlington terrier",
198
+ "182": "Border terrier",
199
+ "183": "Kerry blue terrier",
200
+ "184": "Irish terrier",
201
+ "185": "Norfolk terrier",
202
+ "186": "Norwich terrier",
203
+ "187": "Yorkshire terrier",
204
+ "188": "wire-haired fox terrier",
205
+ "189": "Lakeland terrier",
206
+ "190": "Sealyham terrier, Sealyham",
207
+ "191": "Airedale, Airedale terrier",
208
+ "192": "cairn, cairn terrier",
209
+ "193": "Australian terrier",
210
+ "194": "Dandie Dinmont, Dandie Dinmont terrier",
211
+ "195": "Boston bull, Boston terrier",
212
+ "196": "miniature schnauzer",
213
+ "197": "giant schnauzer",
214
+ "198": "standard schnauzer",
215
+ "199": "Scotch terrier, Scottish terrier, Scottie",
216
+ "200": "Tibetan terrier, chrysanthemum dog",
217
+ "201": "silky terrier, Sydney silky",
218
+ "202": "soft-coated wheaten terrier",
219
+ "203": "West Highland white terrier",
220
+ "204": "Lhasa, Lhasa apso",
221
+ "205": "flat-coated retriever",
222
+ "206": "curly-coated retriever",
223
+ "207": "golden retriever",
224
+ "208": "Labrador retriever",
225
+ "209": "Chesapeake Bay retriever",
226
+ "210": "German short-haired pointer",
227
+ "211": "vizsla, Hungarian pointer",
228
+ "212": "English setter",
229
+ "213": "Irish setter, red setter",
230
+ "214": "Gordon setter",
231
+ "215": "Brittany spaniel",
232
+ "216": "clumber, clumber spaniel",
233
+ "217": "English springer, English springer spaniel",
234
+ "218": "Welsh springer spaniel",
235
+ "219": "cocker spaniel, English cocker spaniel, cocker",
236
+ "220": "Sussex spaniel",
237
+ "221": "Irish water spaniel",
238
+ "222": "kuvasz",
239
+ "223": "schipperke",
240
+ "224": "groenendael",
241
+ "225": "malinois",
242
+ "226": "briard",
243
+ "227": "kelpie",
244
+ "228": "komondor",
245
+ "229": "Old English sheepdog, bobtail",
246
+ "230": "Shetland sheepdog, Shetland sheep dog, Shetland",
247
+ "231": "collie",
248
+ "232": "Border collie",
249
+ "233": "Bouvier des Flandres, Bouviers des Flandres",
250
+ "234": "Rottweiler",
251
+ "235": "German shepherd, German shepherd dog, German police dog, alsatian",
252
+ "236": "Doberman, Doberman pinscher",
253
+ "237": "miniature pinscher",
254
+ "238": "Greater Swiss Mountain dog",
255
+ "239": "Bernese mountain dog",
256
+ "240": "Appenzeller",
257
+ "241": "EntleBucher",
258
+ "242": "boxer",
259
+ "243": "bull mastiff",
260
+ "244": "Tibetan mastiff",
261
+ "245": "French bulldog",
262
+ "246": "Great Dane",
263
+ "247": "Saint Bernard, St Bernard",
264
+ "248": "Eskimo dog, husky",
265
+ "249": "malamute, malemute, Alaskan malamute",
266
+ "250": "Siberian husky",
267
+ "251": "dalmatian, coach dog, carriage dog",
268
+ "252": "affenpinscher, monkey pinscher, monkey dog",
269
+ "253": "basenji",
270
+ "254": "pug, pug-dog",
271
+ "255": "Leonberg",
272
+ "256": "Newfoundland, Newfoundland dog",
273
+ "257": "Great Pyrenees",
274
+ "258": "Samoyed, Samoyede",
275
+ "259": "Pomeranian",
276
+ "260": "chow, chow chow",
277
+ "261": "keeshond",
278
+ "262": "Brabancon griffon",
279
+ "263": "Pembroke, Pembroke Welsh corgi",
280
+ "264": "Cardigan, Cardigan Welsh corgi",
281
+ "265": "toy poodle",
282
+ "266": "miniature poodle",
283
+ "267": "standard poodle",
284
+ "268": "Mexican hairless",
285
+ "269": "timber wolf, grey wolf, gray wolf, Canis lupus",
286
+ "270": "white wolf, Arctic wolf, Canis lupus tundrarum",
287
+ "271": "red wolf, maned wolf, Canis rufus, Canis niger",
288
+ "272": "coyote, prairie wolf, brush wolf, Canis latrans",
289
+ "273": "dingo, warrigal, warragal, Canis dingo",
290
+ "274": "dhole, Cuon alpinus",
291
+ "275": "African hunting dog, hyena dog, Cape hunting dog, Lycaon pictus",
292
+ "276": "hyena, hyaena",
293
+ "277": "red fox, Vulpes vulpes",
294
+ "278": "kit fox, Vulpes macrotis",
295
+ "279": "Arctic fox, white fox, Alopex lagopus",
296
+ "280": "grey fox, gray fox, Urocyon cinereoargenteus",
297
+ "281": "tabby, tabby cat",
298
+ "282": "tiger cat",
299
+ "283": "Persian cat",
300
+ "284": "Siamese cat, Siamese",
301
+ "285": "Egyptian cat",
302
+ "286": "cougar, puma, catamount, mountain lion, painter, panther, Felis concolor",
303
+ "287": "lynx, catamount",
304
+ "288": "leopard, Panthera pardus",
305
+ "289": "snow leopard, ounce, Panthera uncia",
306
+ "290": "jaguar, panther, Panthera onca, Felis onca",
307
+ "291": "lion, king of beasts, Panthera leo",
308
+ "292": "tiger, Panthera tigris",
309
+ "293": "cheetah, chetah, Acinonyx jubatus",
310
+ "294": "brown bear, bruin, Ursus arctos",
311
+ "295": "American black bear, black bear, Ursus americanus, Euarctos americanus",
312
+ "296": "ice bear, polar bear, Ursus Maritimus, Thalarctos maritimus",
313
+ "297": "sloth bear, Melursus ursinus, Ursus ursinus",
314
+ "298": "mongoose",
315
+ "299": "meerkat, mierkat",
316
+ "300": "tiger beetle",
317
+ "301": "ladybug, ladybeetle, lady beetle, ladybird, ladybird beetle",
318
+ "302": "ground beetle, carabid beetle",
319
+ "303": "long-horned beetle, longicorn, longicorn beetle",
320
+ "304": "leaf beetle, chrysomelid",
321
+ "305": "dung beetle",
322
+ "306": "rhinoceros beetle",
323
+ "307": "weevil",
324
+ "308": "fly",
325
+ "309": "bee",
326
+ "310": "ant, emmet, pismire",
327
+ "311": "grasshopper, hopper",
328
+ "312": "cricket",
329
+ "313": "walking stick, walkingstick, stick insect",
330
+ "314": "cockroach, roach",
331
+ "315": "mantis, mantid",
332
+ "316": "cicada, cicala",
333
+ "317": "leafhopper",
334
+ "318": "lacewing, lacewing fly",
335
+ "319": "dragonfly, darning needle, devils darning needle, sewing needle, snake feeder, snake doctor, mosquito hawk, skeeter hawk",
336
+ "320": "damselfly",
337
+ "321": "admiral",
338
+ "322": "ringlet, ringlet butterfly",
339
+ "323": "monarch, monarch butterfly, milkweed butterfly, Danaus plexippus",
340
+ "324": "cabbage butterfly",
341
+ "325": "sulphur butterfly, sulfur butterfly",
342
+ "326": "lycaenid, lycaenid butterfly",
343
+ "327": "starfish, sea star",
344
+ "328": "sea urchin",
345
+ "329": "sea cucumber, holothurian",
346
+ "330": "wood rabbit, cottontail, cottontail rabbit",
347
+ "331": "hare",
348
+ "332": "Angora, Angora rabbit",
349
+ "333": "hamster",
350
+ "334": "porcupine, hedgehog",
351
+ "335": "fox squirrel, eastern fox squirrel, Sciurus niger",
352
+ "336": "marmot",
353
+ "337": "beaver",
354
+ "338": "guinea pig, Cavia cobaya",
355
+ "339": "sorrel",
356
+ "340": "zebra",
357
+ "341": "hog, pig, grunter, squealer, Sus scrofa",
358
+ "342": "wild boar, boar, Sus scrofa",
359
+ "343": "warthog",
360
+ "344": "hippopotamus, hippo, river horse, Hippopotamus amphibius",
361
+ "345": "ox",
362
+ "346": "water buffalo, water ox, Asiatic buffalo, Bubalus bubalis",
363
+ "347": "bison",
364
+ "348": "ram, tup",
365
+ "349": "bighorn, bighorn sheep, cimarron, Rocky Mountain bighorn, Rocky Mountain sheep, Ovis canadensis",
366
+ "350": "ibex, Capra ibex",
367
+ "351": "hartebeest",
368
+ "352": "impala, Aepyceros melampus",
369
+ "353": "gazelle",
370
+ "354": "Arabian camel, dromedary, Camelus dromedarius",
371
+ "355": "llama",
372
+ "356": "weasel",
373
+ "357": "mink",
374
+ "358": "polecat, fitch, foulmart, foumart, Mustela putorius",
375
+ "359": "black-footed ferret, ferret, Mustela nigripes",
376
+ "360": "otter",
377
+ "361": "skunk, polecat, wood pussy",
378
+ "362": "badger",
379
+ "363": "armadillo",
380
+ "364": "three-toed sloth, ai, Bradypus tridactylus",
381
+ "365": "orangutan, orang, orangutang, Pongo pygmaeus",
382
+ "366": "gorilla, Gorilla gorilla",
383
+ "367": "chimpanzee, chimp, Pan troglodytes",
384
+ "368": "gibbon, Hylobates lar",
385
+ "369": "siamang, Hylobates syndactylus, Symphalangus syndactylus",
386
+ "370": "guenon, guenon monkey",
387
+ "371": "patas, hussar monkey, Erythrocebus patas",
388
+ "372": "baboon",
389
+ "373": "macaque",
390
+ "374": "langur",
391
+ "375": "colobus, colobus monkey",
392
+ "376": "proboscis monkey, Nasalis larvatus",
393
+ "377": "marmoset",
394
+ "378": "capuchin, ringtail, Cebus capucinus",
395
+ "379": "howler monkey, howler",
396
+ "380": "titi, titi monkey",
397
+ "381": "spider monkey, Ateles geoffroyi",
398
+ "382": "squirrel monkey, Saimiri sciureus",
399
+ "383": "Madagascar cat, ring-tailed lemur, Lemur catta",
400
+ "384": "indri, indris, Indri indri, Indri brevicaudatus",
401
+ "385": "Indian elephant, Elephas maximus",
402
+ "386": "African elephant, Loxodonta africana",
403
+ "387": "lesser panda, red panda, panda, bear cat, cat bear, Ailurus fulgens",
404
+ "388": "giant panda, panda, panda bear, coon bear, Ailuropoda melanoleuca",
405
+ "389": "barracouta, snoek",
406
+ "390": "eel",
407
+ "391": "coho, cohoe, coho salmon, blue jack, silver salmon, Oncorhynchus kisutch",
408
+ "392": "rock beauty, Holocanthus tricolor",
409
+ "393": "anemone fish",
410
+ "394": "sturgeon",
411
+ "395": "gar, garfish, garpike, billfish, Lepisosteus osseus",
412
+ "396": "lionfish",
413
+ "397": "puffer, pufferfish, blowfish, globefish",
414
+ "398": "abacus",
415
+ "399": "abaya",
416
+ "400": "academic gown, academic robe, judge robe",
417
+ "401": "accordion, piano accordion, squeeze box",
418
+ "402": "acoustic guitar",
419
+ "403": "aircraft carrier, carrier, flattop, attack aircraft carrier",
420
+ "404": "airliner",
421
+ "405": "airship, dirigible",
422
+ "406": "altar",
423
+ "407": "ambulance",
424
+ "408": "amphibian, amphibious vehicle",
425
+ "409": "analog clock",
426
+ "410": "apiary, bee house",
427
+ "411": "apron",
428
+ "412": "ashcan, trash can, garbage can, wastebin, ash bin, ash-bin, ashbin, dustbin, trash barrel, trash bin",
429
+ "413": "assault rifle, assault gun",
430
+ "414": "backpack, back pack, knapsack, packsack, rucksack, haversack",
431
+ "415": "bakery, bakeshop, bakehouse",
432
+ "416": "balance beam, beam",
433
+ "417": "balloon",
434
+ "418": "ballpoint, ballpoint pen, ballpen, Biro",
435
+ "419": "Band Aid",
436
+ "420": "banjo",
437
+ "421": "bannister, banister, balustrade, balusters, handrail",
438
+ "422": "barbell",
439
+ "423": "barber chair",
440
+ "424": "barbershop",
441
+ "425": "barn",
442
+ "426": "barometer",
443
+ "427": "barrel, cask",
444
+ "428": "barrow, garden cart, lawn cart, wheelbarrow",
445
+ "429": "baseball",
446
+ "430": "basketball",
447
+ "431": "bassinet",
448
+ "432": "bassoon",
449
+ "433": "bathing cap, swimming cap",
450
+ "434": "bath towel",
451
+ "435": "bathtub, bathing tub, bath, tub",
452
+ "436": "beach wagon, station wagon, wagon, estate car, beach waggon, station waggon, waggon",
453
+ "437": "beacon, lighthouse, beacon light, pharos",
454
+ "438": "beaker",
455
+ "439": "bearskin, busby, shako",
456
+ "440": "beer bottle",
457
+ "441": "beer glass",
458
+ "442": "bell cote, bell cot",
459
+ "443": "bib",
460
+ "444": "bicycle-built-for-two, tandem bicycle, tandem",
461
+ "445": "bikini, two-piece",
462
+ "446": "binder, ring-binder",
463
+ "447": "binoculars, field glasses, opera glasses",
464
+ "448": "birdhouse",
465
+ "449": "boathouse",
466
+ "450": "bobsled, bobsleigh, bob",
467
+ "451": "bolo tie, bolo, bola tie, bola",
468
+ "452": "bonnet, poke bonnet",
469
+ "453": "bookcase",
470
+ "454": "bookshop, bookstore, bookstall",
471
+ "455": "bottlecap",
472
+ "456": "bow",
473
+ "457": "bow tie, bow-tie, bowtie",
474
+ "458": "brass, memorial tablet, plaque",
475
+ "459": "brassiere, bra, bandeau",
476
+ "460": "breakwater, groin, groyne, mole, bulwark, seawall, jetty",
477
+ "461": "breastplate, aegis, egis",
478
+ "462": "broom",
479
+ "463": "bucket, pail",
480
+ "464": "buckle",
481
+ "465": "bulletproof vest",
482
+ "466": "bullet train, bullet",
483
+ "467": "butcher shop, meat market",
484
+ "468": "cab, hack, taxi, taxicab",
485
+ "469": "caldron, cauldron",
486
+ "470": "candle, taper, wax light",
487
+ "471": "cannon",
488
+ "472": "canoe",
489
+ "473": "can opener, tin opener",
490
+ "474": "cardigan",
491
+ "475": "car mirror",
492
+ "476": "carousel, carrousel, merry-go-round, roundabout, whirligig",
493
+ "477": "carpenters kit, tool kit",
494
+ "478": "carton",
495
+ "479": "car wheel",
496
+ "480": "cash machine, cash dispenser, automated teller machine, automatic teller machine, automated teller, automatic teller, ATM",
497
+ "481": "cassette",
498
+ "482": "cassette player",
499
+ "483": "castle",
500
+ "484": "catamaran",
501
+ "485": "CD player",
502
+ "486": "cello, violoncello",
503
+ "487": "cellular telephone, cellular phone, cellphone, cell, mobile phone",
504
+ "488": "chain",
505
+ "489": "chainlink fence",
506
+ "490": "chain mail, ring mail, mail, chain armor, chain armour, ring armor, ring armour",
507
+ "491": "chain saw, chainsaw",
508
+ "492": "chest",
509
+ "493": "chiffonier, commode",
510
+ "494": "chime, bell, gong",
511
+ "495": "china cabinet, china closet",
512
+ "496": "Christmas stocking",
513
+ "497": "church, church building",
514
+ "498": "cinema, movie theater, movie theatre, movie house, picture palace",
515
+ "499": "cleaver, meat cleaver, chopper",
516
+ "500": "cliff dwelling",
517
+ "501": "cloak",
518
+ "502": "clog, geta, patten, sabot",
519
+ "503": "cocktail shaker",
520
+ "504": "coffee mug",
521
+ "505": "coffeepot",
522
+ "506": "coil, spiral, volute, whorl, helix",
523
+ "507": "combination lock",
524
+ "508": "computer keyboard, keypad",
525
+ "509": "confectionery, confectionary, candy store",
526
+ "510": "container ship, containership, container vessel",
527
+ "511": "convertible",
528
+ "512": "corkscrew, bottle screw",
529
+ "513": "cornet, horn, trumpet, trump",
530
+ "514": "cowboy boot",
531
+ "515": "cowboy hat, ten-gallon hat",
532
+ "516": "cradle",
533
+ "517": "crane",
534
+ "518": "crash helmet",
535
+ "519": "crate",
536
+ "520": "crib, cot",
537
+ "521": "Crock Pot",
538
+ "522": "croquet ball",
539
+ "523": "crutch",
540
+ "524": "cuirass",
541
+ "525": "dam, dike, dyke",
542
+ "526": "desk",
543
+ "527": "desktop computer",
544
+ "528": "dial telephone, dial phone",
545
+ "529": "diaper, nappy, napkin",
546
+ "530": "digital clock",
547
+ "531": "digital watch",
548
+ "532": "dining table, board",
549
+ "533": "dishrag, dishcloth",
550
+ "534": "dishwasher, dish washer, dishwashing machine",
551
+ "535": "disk brake, disc brake",
552
+ "536": "dock, dockage, docking facility",
553
+ "537": "dogsled, dog sled, dog sleigh",
554
+ "538": "dome",
555
+ "539": "doormat, welcome mat",
556
+ "540": "drilling platform, offshore rig",
557
+ "541": "drum, membranophone, tympan",
558
+ "542": "drumstick",
559
+ "543": "dumbbell",
560
+ "544": "Dutch oven",
561
+ "545": "electric fan, blower",
562
+ "546": "electric guitar",
563
+ "547": "electric locomotive",
564
+ "548": "entertainment center",
565
+ "549": "envelope",
566
+ "550": "espresso maker",
567
+ "551": "face powder",
568
+ "552": "feather boa, boa",
569
+ "553": "file, file cabinet, filing cabinet",
570
+ "554": "fireboat",
571
+ "555": "fire engine, fire truck",
572
+ "556": "fire screen, fireguard",
573
+ "557": "flagpole, flagstaff",
574
+ "558": "flute, transverse flute",
575
+ "559": "folding chair",
576
+ "560": "football helmet",
577
+ "561": "forklift",
578
+ "562": "fountain",
579
+ "563": "fountain pen",
580
+ "564": "four-poster",
581
+ "565": "freight car",
582
+ "566": "French horn, horn",
583
+ "567": "frying pan, frypan, skillet",
584
+ "568": "fur coat",
585
+ "569": "garbage truck, dustcart",
586
+ "570": "gasmask, respirator, gas helmet",
587
+ "571": "gas pump, gasoline pump, petrol pump, island dispenser",
588
+ "572": "goblet",
589
+ "573": "go-kart",
590
+ "574": "golf ball",
591
+ "575": "golfcart, golf cart",
592
+ "576": "gondola",
593
+ "577": "gong, tam-tam",
594
+ "578": "gown",
595
+ "579": "grand piano, grand",
596
+ "580": "greenhouse, nursery, glasshouse",
597
+ "581": "grille, radiator grille",
598
+ "582": "grocery store, grocery, food market, market",
599
+ "583": "guillotine",
600
+ "584": "hair slide",
601
+ "585": "hair spray",
602
+ "586": "half track",
603
+ "587": "hammer",
604
+ "588": "hamper",
605
+ "589": "hand blower, blow dryer, blow drier, hair dryer, hair drier",
606
+ "590": "hand-held computer, hand-held microcomputer",
607
+ "591": "handkerchief, hankie, hanky, hankey",
608
+ "592": "hard disc, hard disk, fixed disk",
609
+ "593": "harmonica, mouth organ, harp, mouth harp",
610
+ "594": "harp",
611
+ "595": "harvester, reaper",
612
+ "596": "hatchet",
613
+ "597": "holster",
614
+ "598": "home theater, home theatre",
615
+ "599": "honeycomb",
616
+ "600": "hook, claw",
617
+ "601": "hoopskirt, crinoline",
618
+ "602": "horizontal bar, high bar",
619
+ "603": "horse cart, horse-cart",
620
+ "604": "hourglass",
621
+ "605": "iPod",
622
+ "606": "iron, smoothing iron",
623
+ "607": "jack-o-lantern",
624
+ "608": "jean, blue jean, denim",
625
+ "609": "jeep, landrover",
626
+ "610": "jersey, T-shirt, tee shirt",
627
+ "611": "jigsaw puzzle",
628
+ "612": "jinrikisha, ricksha, rickshaw",
629
+ "613": "joystick",
630
+ "614": "kimono",
631
+ "615": "knee pad",
632
+ "616": "knot",
633
+ "617": "lab coat, laboratory coat",
634
+ "618": "ladle",
635
+ "619": "lampshade, lamp shade",
636
+ "620": "laptop, laptop computer",
637
+ "621": "lawn mower, mower",
638
+ "622": "lens cap, lens cover",
639
+ "623": "letter opener, paper knife, paperknife",
640
+ "624": "library",
641
+ "625": "lifeboat",
642
+ "626": "lighter, light, igniter, ignitor",
643
+ "627": "limousine, limo",
644
+ "628": "liner, ocean liner",
645
+ "629": "lipstick, lip rouge",
646
+ "630": "Loafer",
647
+ "631": "lotion",
648
+ "632": "loudspeaker, speaker, speaker unit, loudspeaker system, speaker system",
649
+ "633": "loupe, jewelers loupe",
650
+ "634": "lumbermill, sawmill",
651
+ "635": "magnetic compass",
652
+ "636": "mailbag, postbag",
653
+ "637": "mailbox, letter box",
654
+ "638": "maillot",
655
+ "639": "maillot, tank suit",
656
+ "640": "manhole cover",
657
+ "641": "maraca",
658
+ "642": "marimba, xylophone",
659
+ "643": "mask",
660
+ "644": "matchstick",
661
+ "645": "maypole",
662
+ "646": "maze, labyrinth",
663
+ "647": "measuring cup",
664
+ "648": "medicine chest, medicine cabinet",
665
+ "649": "megalith, megalithic structure",
666
+ "650": "microphone, mike",
667
+ "651": "microwave, microwave oven",
668
+ "652": "military uniform",
669
+ "653": "milk can",
670
+ "654": "minibus",
671
+ "655": "miniskirt, mini",
672
+ "656": "minivan",
673
+ "657": "missile",
674
+ "658": "mitten",
675
+ "659": "mixing bowl",
676
+ "660": "mobile home, manufactured home",
677
+ "661": "Model T",
678
+ "662": "modem",
679
+ "663": "monastery",
680
+ "664": "monitor",
681
+ "665": "moped",
682
+ "666": "mortar",
683
+ "667": "mortarboard",
684
+ "668": "mosque",
685
+ "669": "mosquito net",
686
+ "670": "motor scooter, scooter",
687
+ "671": "mountain bike, all-terrain bike, off-roader",
688
+ "672": "mountain tent",
689
+ "673": "mouse, computer mouse",
690
+ "674": "mousetrap",
691
+ "675": "moving van",
692
+ "676": "muzzle",
693
+ "677": "nail",
694
+ "678": "neck brace",
695
+ "679": "necklace",
696
+ "680": "nipple",
697
+ "681": "notebook, notebook computer",
698
+ "682": "obelisk",
699
+ "683": "oboe, hautboy, hautbois",
700
+ "684": "ocarina, sweet potato",
701
+ "685": "odometer, hodometer, mileometer, milometer",
702
+ "686": "oil filter",
703
+ "687": "organ, pipe organ",
704
+ "688": "oscilloscope, scope, cathode-ray oscilloscope, CRO",
705
+ "689": "overskirt",
706
+ "690": "oxcart",
707
+ "691": "oxygen mask",
708
+ "692": "packet",
709
+ "693": "paddle, boat paddle",
710
+ "694": "paddlewheel, paddle wheel",
711
+ "695": "padlock",
712
+ "696": "paintbrush",
713
+ "697": "pajama, pyjama, pjs, jammies",
714
+ "698": "palace",
715
+ "699": "panpipe, pandean pipe, syrinx",
716
+ "700": "paper towel",
717
+ "701": "parachute, chute",
718
+ "702": "parallel bars, bars",
719
+ "703": "park bench",
720
+ "704": "parking meter",
721
+ "705": "passenger car, coach, carriage",
722
+ "706": "patio, terrace",
723
+ "707": "pay-phone, pay-station",
724
+ "708": "pedestal, plinth, footstall",
725
+ "709": "pencil box, pencil case",
726
+ "710": "pencil sharpener",
727
+ "711": "perfume, essence",
728
+ "712": "Petri dish",
729
+ "713": "photocopier",
730
+ "714": "pick, plectrum, plectron",
731
+ "715": "pickelhaube",
732
+ "716": "picket fence, paling",
733
+ "717": "pickup, pickup truck",
734
+ "718": "pier",
735
+ "719": "piggy bank, penny bank",
736
+ "720": "pill bottle",
737
+ "721": "pillow",
738
+ "722": "ping-pong ball",
739
+ "723": "pinwheel",
740
+ "724": "pirate, pirate ship",
741
+ "725": "pitcher, ewer",
742
+ "726": "plane, carpenters plane, woodworking plane",
743
+ "727": "planetarium",
744
+ "728": "plastic bag",
745
+ "729": "plate rack",
746
+ "730": "plow, plough",
747
+ "731": "plunger, plumbers helper",
748
+ "732": "Polaroid camera, Polaroid Land camera",
749
+ "733": "pole",
750
+ "734": "police van, police wagon, paddy wagon, patrol wagon, wagon, black Maria",
751
+ "735": "poncho",
752
+ "736": "pool table, billiard table, snooker table",
753
+ "737": "pop bottle, soda bottle",
754
+ "738": "pot, flowerpot",
755
+ "739": "potters wheel",
756
+ "740": "power drill",
757
+ "741": "prayer rug, prayer mat",
758
+ "742": "printer",
759
+ "743": "prison, prison house",
760
+ "744": "projectile, missile",
761
+ "745": "projector",
762
+ "746": "puck, hockey puck",
763
+ "747": "punching bag, punch bag, punching ball, punchball",
764
+ "748": "purse",
765
+ "749": "quill, quill pen",
766
+ "750": "quilt, comforter, comfort, puff",
767
+ "751": "racer, race car, racing car",
768
+ "752": "racket, racquet",
769
+ "753": "radiator",
770
+ "754": "radio, wireless",
771
+ "755": "radio telescope, radio reflector",
772
+ "756": "rain barrel",
773
+ "757": "recreational vehicle, RV, R.V.",
774
+ "758": "reel",
775
+ "759": "reflex camera",
776
+ "760": "refrigerator, icebox",
777
+ "761": "remote control, remote",
778
+ "762": "restaurant, eating house, eating place, eatery",
779
+ "763": "revolver, six-gun, six-shooter",
780
+ "764": "rifle",
781
+ "765": "rocking chair, rocker",
782
+ "766": "rotisserie",
783
+ "767": "rubber eraser, rubber, pencil eraser",
784
+ "768": "rugby ball",
785
+ "769": "rule, ruler",
786
+ "770": "running shoe",
787
+ "771": "safe",
788
+ "772": "safety pin",
789
+ "773": "saltshaker, salt shaker",
790
+ "774": "sandal",
791
+ "775": "sarong",
792
+ "776": "sax, saxophone",
793
+ "777": "scabbard",
794
+ "778": "scale, weighing machine",
795
+ "779": "school bus",
796
+ "780": "schooner",
797
+ "781": "scoreboard",
798
+ "782": "screen, CRT screen",
799
+ "783": "screw",
800
+ "784": "screwdriver",
801
+ "785": "seat belt, seatbelt",
802
+ "786": "sewing machine",
803
+ "787": "shield, buckler",
804
+ "788": "shoe shop, shoe-shop, shoe store",
805
+ "789": "shoji",
806
+ "790": "shopping basket",
807
+ "791": "shopping cart",
808
+ "792": "shovel",
809
+ "793": "shower cap",
810
+ "794": "shower curtain",
811
+ "795": "ski",
812
+ "796": "ski mask",
813
+ "797": "sleeping bag",
814
+ "798": "slide rule, slipstick",
815
+ "799": "sliding door",
816
+ "800": "slot, one-armed bandit",
817
+ "801": "snorkel",
818
+ "802": "snowmobile",
819
+ "803": "snowplow, snowplough",
820
+ "804": "soap dispenser",
821
+ "805": "soccer ball",
822
+ "806": "sock",
823
+ "807": "solar dish, solar collector, solar furnace",
824
+ "808": "sombrero",
825
+ "809": "soup bowl",
826
+ "810": "space bar",
827
+ "811": "space heater",
828
+ "812": "space shuttle",
829
+ "813": "spatula",
830
+ "814": "speedboat",
831
+ "815": "spider web, spiders web",
832
+ "816": "spindle",
833
+ "817": "sports car, sport car",
834
+ "818": "spotlight, spot",
835
+ "819": "stage",
836
+ "820": "steam locomotive",
837
+ "821": "steel arch bridge",
838
+ "822": "steel drum",
839
+ "823": "stethoscope",
840
+ "824": "stole",
841
+ "825": "stone wall",
842
+ "826": "stopwatch, stop watch",
843
+ "827": "stove",
844
+ "828": "strainer",
845
+ "829": "streetcar, tram, tramcar, trolley, trolley car",
846
+ "830": "stretcher",
847
+ "831": "studio couch, day bed",
848
+ "832": "stupa, tope",
849
+ "833": "submarine, pigboat, sub, U-boat",
850
+ "834": "suit, suit of clothes",
851
+ "835": "sundial",
852
+ "836": "sunglass",
853
+ "837": "sunglasses, dark glasses, shades",
854
+ "838": "sunscreen, sunblock, sun blocker",
855
+ "839": "suspension bridge",
856
+ "840": "swab, swob, mop",
857
+ "841": "sweatshirt",
858
+ "842": "swimming trunks, bathing trunks",
859
+ "843": "swing",
860
+ "844": "switch, electric switch, electrical switch",
861
+ "845": "syringe",
862
+ "846": "table lamp",
863
+ "847": "tank, army tank, armored combat vehicle, armoured combat vehicle",
864
+ "848": "tape player",
865
+ "849": "teapot",
866
+ "850": "teddy, teddy bear",
867
+ "851": "television, television system",
868
+ "852": "tennis ball",
869
+ "853": "thatch, thatched roof",
870
+ "854": "theater curtain, theatre curtain",
871
+ "855": "thimble",
872
+ "856": "thresher, thrasher, threshing machine",
873
+ "857": "throne",
874
+ "858": "tile roof",
875
+ "859": "toaster",
876
+ "860": "tobacco shop, tobacconist shop, tobacconist",
877
+ "861": "toilet seat",
878
+ "862": "torch",
879
+ "863": "totem pole",
880
+ "864": "tow truck, tow car, wrecker",
881
+ "865": "toyshop",
882
+ "866": "tractor",
883
+ "867": "trailer truck, tractor trailer, trucking rig, rig, articulated lorry, semi",
884
+ "868": "tray",
885
+ "869": "trench coat",
886
+ "870": "tricycle, trike, velocipede",
887
+ "871": "trimaran",
888
+ "872": "tripod",
889
+ "873": "triumphal arch",
890
+ "874": "trolleybus, trolley coach, trackless trolley",
891
+ "875": "trombone",
892
+ "876": "tub, vat",
893
+ "877": "turnstile",
894
+ "878": "typewriter keyboard",
895
+ "879": "umbrella",
896
+ "880": "unicycle, monocycle",
897
+ "881": "upright, upright piano",
898
+ "882": "vacuum, vacuum cleaner",
899
+ "883": "vase",
900
+ "884": "vault",
901
+ "885": "velvet",
902
+ "886": "vending machine",
903
+ "887": "vestment",
904
+ "888": "viaduct",
905
+ "889": "violin, fiddle",
906
+ "890": "volleyball",
907
+ "891": "waffle iron",
908
+ "892": "wall clock",
909
+ "893": "wallet, billfold, notecase, pocketbook",
910
+ "894": "wardrobe, closet, press",
911
+ "895": "warplane, military plane",
912
+ "896": "washbasin, handbasin, washbowl, lavabo, wash-hand basin",
913
+ "897": "washer, automatic washer, washing machine",
914
+ "898": "water bottle",
915
+ "899": "water jug",
916
+ "900": "water tower",
917
+ "901": "whiskey jug",
918
+ "902": "whistle",
919
+ "903": "wig",
920
+ "904": "window screen",
921
+ "905": "window shade",
922
+ "906": "Windsor tie",
923
+ "907": "wine bottle",
924
+ "908": "wing",
925
+ "909": "wok",
926
+ "910": "wooden spoon",
927
+ "911": "wool, woolen, woollen",
928
+ "912": "worm fence, snake fence, snake-rail fence, Virginia fence",
929
+ "913": "wreck",
930
+ "914": "yawl",
931
+ "915": "yurt",
932
+ "916": "web site, website, internet site, site",
933
+ "917": "comic book",
934
+ "918": "crossword puzzle, crossword",
935
+ "919": "street sign",
936
+ "920": "traffic light, traffic signal, stoplight",
937
+ "921": "book jacket, dust cover, dust jacket, dust wrapper",
938
+ "922": "menu",
939
+ "923": "plate",
940
+ "924": "guacamole",
941
+ "925": "consomme",
942
+ "926": "hot pot, hotpot",
943
+ "927": "trifle",
944
+ "928": "ice cream, icecream",
945
+ "929": "ice lolly, lolly, lollipop, popsicle",
946
+ "930": "French loaf",
947
+ "931": "bagel, beigel",
948
+ "932": "pretzel",
949
+ "933": "cheeseburger",
950
+ "934": "hotdog, hot dog, red hot",
951
+ "935": "mashed potato",
952
+ "936": "head cabbage",
953
+ "937": "broccoli",
954
+ "938": "cauliflower",
955
+ "939": "zucchini, courgette",
956
+ "940": "spaghetti squash",
957
+ "941": "acorn squash",
958
+ "942": "butternut squash",
959
+ "943": "cucumber, cuke",
960
+ "944": "artichoke, globe artichoke",
961
+ "945": "bell pepper",
962
+ "946": "cardoon",
963
+ "947": "mushroom",
964
+ "948": "Granny Smith",
965
+ "949": "strawberry",
966
+ "950": "orange",
967
+ "951": "lemon",
968
+ "952": "fig",
969
+ "953": "pineapple, ananas",
970
+ "954": "banana",
971
+ "955": "jackfruit, jak, jack",
972
+ "956": "custard apple",
973
+ "957": "pomegranate",
974
+ "958": "hay",
975
+ "959": "carbonara",
976
+ "960": "chocolate sauce, chocolate syrup",
977
+ "961": "dough",
978
+ "962": "meat loaf, meatloaf",
979
+ "963": "pizza, pizza pie",
980
+ "964": "potpie",
981
+ "965": "burrito",
982
+ "966": "red wine",
983
+ "967": "espresso",
984
+ "968": "cup",
985
+ "969": "eggnog",
986
+ "970": "alp",
987
+ "971": "bubble",
988
+ "972": "cliff, drop, drop-off",
989
+ "973": "coral reef",
990
+ "974": "geyser",
991
+ "975": "lakeside, lakeshore",
992
+ "976": "promontory, headland, head, foreland",
993
+ "977": "sandbar, sand bar",
994
+ "978": "seashore, coast, seacoast, sea-coast",
995
+ "979": "valley, vale",
996
+ "980": "volcano",
997
+ "981": "ballplayer, baseball player",
998
+ "982": "groom, bridegroom",
999
+ "983": "scuba diver",
1000
+ "984": "rapeseed",
1001
+ "985": "daisy",
1002
+ "986": "yellow ladys slipper, yellow lady-slipper, Cypripedium calceolus, Cypripedium parviflorum",
1003
+ "987": "corn",
1004
+ "988": "acorn",
1005
+ "989": "hip, rose hip, rosehip",
1006
+ "990": "buckeye, horse chestnut, conker",
1007
+ "991": "coral fungus",
1008
+ "992": "agaric",
1009
+ "993": "gyromitra",
1010
+ "994": "stinkhorn, carrion fungus",
1011
+ "995": "earthstar",
1012
+ "996": "hen-of-the-woods, hen of the woods, Polyporus frondosus, Grifola frondosa",
1013
+ "997": "bolete",
1014
+ "998": "ear, spike, capitulum",
1015
+ "999": "toilet tissue, toilet paper, bathroom tissue"
1016
+ },
1017
+ "vae": [
1018
+ "diffusers",
1019
+ "AutoencoderKL"
1020
+ ]
1021
+ }
iMF-L-SIM/pipeline.py ADDED
@@ -0,0 +1,342 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Hub custom pipeline: IMFPipeline.
2
+ Load with native Hugging Face diffusers and trust_remote_code=True.
3
+ """
4
+
5
+ from __future__ import annotations
6
+
7
+ import importlib.util
8
+ import inspect
9
+
10
+ import json
11
+ from pathlib import Path
12
+ from typing import Dict, List, Optional, Tuple, Union, Any
13
+
14
+ import torch
15
+ from diffusers.image_processor import VaeImageProcessor
16
+ from diffusers.pipelines.pipeline_utils import DiffusionPipeline, ImagePipelineOutput
17
+ from diffusers.utils.torch_utils import randn_tensor
18
+
19
+ # imeanflow / FD-Loss sd-vae latent statistics (stabilityai/sd-vae-ft-mse)
20
+ LATENT_CHANNEL_MEAN = (0.86488, -0.27787343, 0.21616915, 0.3738409)
21
+ LATENT_CHANNEL_STD = (4.85503674, 5.31922414, 3.93725398, 3.9870003)
22
+
23
+
24
+ def _load_bundled_vae(transformer) -> Optional[Any]:
25
+ transformer_path = getattr(transformer.config, "_name_or_path", None)
26
+ if not transformer_path:
27
+ return None
28
+ vae_dir = Path(transformer_path).resolve().parent / "vae"
29
+ if not vae_dir.is_dir() or not (vae_dir / "config.json").is_file():
30
+ return None
31
+ from diffusers import AutoencoderKL
32
+
33
+ vae_dtype = getattr(transformer, "dtype", torch.float32)
34
+ return AutoencoderKL.from_pretrained(str(vae_dir), torch_dtype=vae_dtype)
35
+
36
+
37
+ class IMFPipeline(DiffusionPipeline):
38
+
39
+ @staticmethod
40
+ def prepare_extra_step_kwargs(
41
+ scheduler,
42
+ generator=None,
43
+ eta: float | None = None,
44
+ ):
45
+ kwargs = {}
46
+ step_params = set(inspect.signature(scheduler.step).parameters.keys())
47
+ if "generator" in step_params:
48
+ kwargs["generator"] = generator
49
+ if eta is not None and "eta" in step_params:
50
+ kwargs["eta"] = eta
51
+ return kwargs
52
+
53
+ @staticmethod
54
+ def _prepare_generator(
55
+ generator: Optional[Union[torch.Generator, List[torch.Generator]]],
56
+ ) -> Optional[Union[torch.Generator, List[torch.Generator]]]:
57
+ if generator is None:
58
+ return None
59
+ if isinstance(generator, list):
60
+ for gen in generator:
61
+ if gen is not None:
62
+ gen.manual_seed(int(gen.initial_seed()))
63
+ return generator
64
+ generator.manual_seed(int(generator.initial_seed()))
65
+ return generator
66
+
67
+ @staticmethod
68
+ def _coerce_scheduler(scheduler, transformer) -> Any:
69
+ if scheduler is not None and not isinstance(scheduler, (list, tuple)):
70
+ return scheduler
71
+ variant_path = getattr(transformer.config, "_name_or_path", None)
72
+ if variant_path:
73
+ scheduler_dir = Path(variant_path).resolve().parent / "scheduler"
74
+ module_path = scheduler_dir / "scheduling_imf.py"
75
+ config_path = scheduler_dir / "scheduler_config.json"
76
+ if module_path.is_file() and config_path.is_file():
77
+ spec = importlib.util.spec_from_file_location("scheduling_imf", module_path)
78
+ if spec is not None and spec.loader is not None:
79
+ module = importlib.util.module_from_spec(spec)
80
+ spec.loader.exec_module(module)
81
+ return module.IMFScheduler.from_pretrained(str(scheduler_dir))
82
+ raise ValueError(
83
+ "IMFPipeline could not load IMFScheduler. Ensure the variant includes scheduler/scheduling_imf.py."
84
+ )
85
+
86
+ @staticmethod
87
+ def _resolve_inference_generator(
88
+ device: Union[str, torch.device],
89
+ generator: Optional[Union[torch.Generator, List[torch.Generator]]] = None,
90
+ ) -> Optional[Union[torch.Generator, List[torch.Generator]]]:
91
+ if generator is None:
92
+ return None
93
+ if isinstance(device, str):
94
+ device = torch.device(device)
95
+ device_type = device.type
96
+
97
+ def _relocate(gen: torch.Generator) -> torch.Generator:
98
+ if gen.device.type == device_type:
99
+ return gen
100
+ return torch.Generator(device=device_type).manual_seed(gen.initial_seed())
101
+
102
+ if isinstance(generator, list):
103
+ return [_relocate(g) for g in generator]
104
+ return _relocate(generator)
105
+
106
+ model_cpu_offload_seq = "transformer->vae"
107
+
108
+ def __init__(
109
+ self,
110
+ transformer,
111
+ scheduler,
112
+ vae=None,
113
+ id2label: Optional[Dict[Union[int, str], str]] = None,
114
+ ):
115
+ super().__init__()
116
+ scheduler = self._coerce_scheduler(scheduler, transformer)
117
+ if scheduler is None:
118
+ raise ValueError("IMFPipeline requires a scheduler loaded from the checkpoint.")
119
+ if isinstance(vae, (list, tuple)):
120
+ vae = None
121
+ if vae is None:
122
+ vae = _load_bundled_vae(transformer)
123
+ if vae is not None:
124
+ vae = vae.to(device=transformer.device, dtype=getattr(transformer, "dtype", torch.float32))
125
+ self.register_modules(transformer=transformer, scheduler=scheduler, vae=vae)
126
+ self._id2label = self._normalize_id2label(id2label)
127
+ self.labels = self._build_label2id(self._id2label)
128
+ self._labels_loaded_from_model_index = bool(self._id2label)
129
+ self.latent_channel_mean = torch.tensor(LATENT_CHANNEL_MEAN, dtype=torch.float32).view(1, 4, 1, 1)
130
+ self.latent_channel_std = torch.tensor(LATENT_CHANNEL_STD, dtype=torch.float32).view(1, 4, 1, 1)
131
+ vae_scale_factor = 8
132
+ if vae is not None:
133
+ vae_scale_factor = 2 ** (len(vae.config.block_out_channels) - 1)
134
+ self.vae_scale_factor = vae_scale_factor
135
+ self.image_processor = VaeImageProcessor(vae_scale_factor=self.vae_scale_factor)
136
+
137
+ def _ensure_labels_loaded(self) -> None:
138
+ if self._labels_loaded_from_model_index:
139
+ return
140
+ loaded = self._read_id2label_from_model_index(getattr(self.config, "_name_or_path", None))
141
+ if loaded:
142
+ self._id2label = loaded
143
+ self.labels = self._build_label2id(self._id2label)
144
+ self._labels_loaded_from_model_index = True
145
+
146
+ @staticmethod
147
+ def _normalize_id2label(id2label: Optional[Dict[Union[int, str], str]]) -> Dict[int, str]:
148
+ if not id2label:
149
+ return {}
150
+ return {int(key): value for key, value in id2label.items()}
151
+
152
+ @staticmethod
153
+ def _read_id2label_from_model_index(variant_path: Optional[str]) -> Dict[int, str]:
154
+ if not variant_path:
155
+ return {}
156
+ model_index_path = Path(variant_path).resolve() / "model_index.json"
157
+ if not model_index_path.exists():
158
+ return {}
159
+ raw = json.loads(model_index_path.read_text(encoding="utf-8"))
160
+ id2label = raw.get("id2label")
161
+ if not isinstance(id2label, dict):
162
+ return {}
163
+ return {int(key): value for key, value in id2label.items()}
164
+
165
+ @staticmethod
166
+ def _build_label2id(id2label: Dict[int, str]) -> Dict[str, int]:
167
+ label2id: Dict[str, int] = {}
168
+ for class_id, value in id2label.items():
169
+ for synonym in value.split(","):
170
+ synonym = synonym.strip()
171
+ if synonym:
172
+ label2id[synonym] = int(class_id)
173
+ return dict(sorted(label2id.items()))
174
+
175
+ @property
176
+ def id2label(self) -> Dict[int, str]:
177
+ self._ensure_labels_loaded()
178
+ return self._id2label
179
+
180
+ def get_label_ids(self, label: Union[str, List[str]]) -> List[int]:
181
+ self._ensure_labels_loaded()
182
+ if not self.labels:
183
+ raise ValueError("No labels loaded. Ensure `id2label` exists in model_index.json.")
184
+ if isinstance(label, str):
185
+ label = [label]
186
+ missing = [item for item in label if item not in self.labels]
187
+ if missing:
188
+ preview = ", ".join(list(self.labels.keys())[:8])
189
+ raise ValueError(f"Unknown label(s): {missing}. Example valid labels: {preview}, ...")
190
+ return [self.labels[item] for item in label]
191
+
192
+ def _normalize_class_labels(self, class_labels: Union[int, str, List[Union[int, str]]]) -> List[int]:
193
+ if isinstance(class_labels, int):
194
+ return [class_labels]
195
+ if isinstance(class_labels, str):
196
+ return self.get_label_ids(class_labels)
197
+ if class_labels and isinstance(class_labels[0], str):
198
+ return self.get_label_ids(class_labels)
199
+ return list(class_labels)
200
+
201
+ def _denormalize_latents(self, latents: torch.Tensor) -> torch.Tensor:
202
+ mean = self.latent_channel_mean.to(device=latents.device, dtype=latents.dtype)
203
+ std = self.latent_channel_std.to(device=latents.device, dtype=latents.dtype)
204
+ return latents * std + mean
205
+
206
+ def decode_latents(self, latents: torch.Tensor, output_type: str = "pil"):
207
+ if output_type == "latent":
208
+ return latents
209
+ if self.vae is None:
210
+ raise ValueError(
211
+ "Cannot decode latents without a VAE. Ensure model_index.json lists vae and the variant includes vae/."
212
+ )
213
+ vae_dtype = next(self.vae.parameters()).dtype
214
+ if next(self.vae.parameters()).device != latents.device:
215
+ self.vae.to(device=latents.device, dtype=vae_dtype)
216
+ latents = self._denormalize_latents(latents).to(dtype=vae_dtype)
217
+ image = self.vae.decode(latents).sample
218
+ return self.image_processor.postprocess(image, output_type=output_type)
219
+
220
+ def _predict_velocity_u(
221
+ self,
222
+ latents: torch.Tensor,
223
+ timestep: torch.Tensor,
224
+ time_gap: torch.Tensor,
225
+ class_labels: torch.Tensor,
226
+ class_null: torch.Tensor,
227
+ guidance_scale: float,
228
+ guidance_interval_start: float,
229
+ guidance_interval_end: float,
230
+ do_classifier_free_guidance: bool,
231
+ ) -> torch.Tensor:
232
+ if do_classifier_free_guidance:
233
+ latents_in = torch.cat([latents, latents], dim=0)
234
+ labels = torch.cat([class_labels, class_null], dim=0)
235
+ omega = torch.tensor([guidance_scale, 1.0], device=latents.device, dtype=latents.dtype)
236
+ t_min = torch.tensor([guidance_interval_start, 0.0], device=latents.device, dtype=latents.dtype)
237
+ t_max = torch.tensor([guidance_interval_end, 1.0], device=latents.device, dtype=latents.dtype)
238
+ batch = latents.shape[0]
239
+ timestep_in = timestep.reshape(1).repeat(2 * batch).to(dtype=latents.dtype)
240
+ time_gap_in = time_gap.reshape(1).repeat(2 * batch).to(dtype=latents.dtype)
241
+ omega = omega.repeat(batch)
242
+ t_min = t_min.repeat(batch)
243
+ t_max = t_max.repeat(batch)
244
+ else:
245
+ latents_in = latents
246
+ labels = class_labels
247
+ batch = latents.shape[0]
248
+ timestep_in = timestep.reshape(1).repeat(batch).to(dtype=latents.dtype)
249
+ time_gap_in = time_gap.reshape(1).repeat(batch).to(dtype=latents.dtype)
250
+ omega = torch.full((batch,), guidance_scale, device=latents.device, dtype=latents.dtype)
251
+ t_min = torch.full((batch,), guidance_interval_start, device=latents.device, dtype=latents.dtype)
252
+ t_max = torch.full((batch,), guidance_interval_end, device=latents.device, dtype=latents.dtype)
253
+
254
+ outputs = self.transformer(
255
+ sample=latents_in,
256
+ timestep=timestep_in,
257
+ class_labels=labels,
258
+ time_gap=time_gap_in,
259
+ guidance_scale=omega,
260
+ guidance_interval_start=t_min,
261
+ guidance_interval_end=t_max,
262
+ return_dict=True,
263
+ )
264
+ velocity_u = outputs.velocity_u
265
+
266
+ if not do_classifier_free_guidance:
267
+ return velocity_u
268
+
269
+ u_cond, u_uncond = velocity_u.chunk(2, dim=0)
270
+ return u_uncond + guidance_scale * (u_cond - u_uncond)
271
+
272
+ @torch.inference_mode()
273
+ def __call__(
274
+ self,
275
+ class_labels: Union[int, str, List[Union[int, str]]],
276
+ num_inference_steps: int = 1,
277
+ guidance_scale: float = 2.7,
278
+ guidance_interval_start: float = 0.1,
279
+ guidance_interval_end: float = 0.9,
280
+ generator: Optional[Union[torch.Generator, List[torch.Generator]]] = None,
281
+ latents: Optional[torch.Tensor] = None,
282
+ output_type: Optional[str] = "pil",
283
+ return_dict: bool = True,
284
+ ) -> Union[ImagePipelineOutput, Tuple]:
285
+ if output_type not in {"pil", "np", "pt", "latent"}:
286
+ raise ValueError("output_type must be one of: 'pil', 'np', 'pt', 'latent'.")
287
+
288
+ class_label_ids = self._normalize_class_labels(class_labels)
289
+ do_classifier_free_guidance = guidance_scale > 1.0
290
+ batch_size = len(class_label_ids)
291
+ generator = self._resolve_inference_generator(self._execution_device, generator)
292
+
293
+ image_size = int(self.transformer.config.sample_size)
294
+ channels = int(self.transformer.config.in_channels)
295
+ null_class_val = int(getattr(self.transformer.config, "num_classes", 1000))
296
+
297
+ generator = self._prepare_generator(generator)
298
+
299
+ if latents is None:
300
+ latents = randn_tensor(
301
+ shape=(batch_size, channels, image_size, image_size),
302
+ generator=generator,
303
+ device=self._execution_device,
304
+ dtype=self.transformer.dtype,
305
+ )
306
+
307
+ class_labels_t = torch.tensor(class_label_ids, device=latents.device, dtype=torch.long).reshape(-1)
308
+ class_labels_t = class_labels_t.clamp(0, null_class_val - 1)
309
+ class_null = torch.full_like(class_labels_t, null_class_val)
310
+
311
+ self.scheduler.set_timesteps(num_inference_steps, device=latents.device)
312
+ timesteps = self.scheduler.timesteps
313
+
314
+ extra_step_kwargs = self.prepare_extra_step_kwargs(self.scheduler, generator=generator)
315
+
316
+ for i in self.progress_bar(range(num_inference_steps)):
317
+ t = timesteps[i]
318
+ t_next = timesteps[i + 1]
319
+ time_gap = t - t_next
320
+ velocity_u = self._predict_velocity_u(
321
+ latents,
322
+ t,
323
+ time_gap,
324
+ class_labels_t,
325
+ class_null,
326
+ guidance_scale,
327
+ guidance_interval_start,
328
+ guidance_interval_end,
329
+ do_classifier_free_guidance,
330
+ )
331
+ latents = self.scheduler.step(velocity_u, t, latents, **extra_step_kwargs).prev_sample
332
+
333
+ images = self.decode_latents(latents, output_type=output_type)
334
+
335
+ self.maybe_free_model_hooks()
336
+
337
+ if not return_dict:
338
+ return (images,)
339
+ return ImagePipelineOutput(images=images)
340
+
341
+
342
+ IMFPipelineOutput = ImagePipelineOutput
iMF-L-SIM/scheduler/scheduler_config.json ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ {
2
+ "_class_name": "IMFScheduler",
3
+ "_diffusers_version": "0.36.0",
4
+ "num_train_timesteps": 1000
5
+ }
iMF-L-SIM/scheduler/scheduling_imf.py ADDED
@@ -0,0 +1,105 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from __future__ import annotations
2
+
3
+ from dataclasses import dataclass
4
+ from typing import List, Optional, Tuple, Union
5
+
6
+ import torch
7
+ from diffusers.configuration_utils import ConfigMixin, register_to_config
8
+ from diffusers.schedulers.scheduling_utils import SchedulerMixin
9
+ from diffusers.utils import BaseOutput
10
+ from diffusers.utils.torch_utils import randn_tensor
11
+
12
+
13
+ @dataclass
14
+ class IMFSchedulerOutput(BaseOutput):
15
+ prev_sample: torch.Tensor
16
+
17
+
18
+ class IMFScheduler(SchedulerMixin, ConfigMixin):
19
+ """Mean-flow scheduler with timesteps from 1.0 to 0.0."""
20
+
21
+ order = 1
22
+
23
+ @register_to_config
24
+ def __init__(
25
+ self,
26
+ num_train_timesteps: int = 1000,
27
+ shift: float = 1.0,
28
+ stochastic_sampling: bool = False,
29
+ ):
30
+ self.timesteps: Optional[torch.Tensor] = None
31
+ self.num_inference_steps: Optional[int] = None
32
+ self._step_index: Optional[int] = None
33
+
34
+ @property
35
+ def init_noise_sigma(self) -> float:
36
+ return 1.0
37
+
38
+ def set_timesteps(self, num_inference_steps: int, device: Union[str, torch.device, None] = None) -> None:
39
+ if num_inference_steps < 1:
40
+ raise ValueError("num_inference_steps must be >= 1.")
41
+ self.num_inference_steps = num_inference_steps
42
+ self.timesteps = torch.linspace(1.0, 0.0, num_inference_steps + 1, device=device, dtype=torch.float32)
43
+ self._step_index = 0
44
+
45
+ def scale_model_input(self, sample: torch.Tensor, timestep: Union[float, torch.Tensor]) -> torch.Tensor:
46
+ del timestep
47
+ return sample
48
+
49
+ def _resolve_step_index(self, timestep: Union[float, torch.Tensor, None]) -> int:
50
+ if self._step_index is not None:
51
+ return self._step_index
52
+ if self.timesteps is None:
53
+ raise ValueError("Call `set_timesteps` before `step`.")
54
+ if timestep is None:
55
+ return 0
56
+ t_value = float(timestep) if not isinstance(timestep, torch.Tensor) else float(timestep.flatten()[0])
57
+ matches = (self.timesteps - t_value).abs() < 1e-6
58
+ if matches.any():
59
+ return int(matches.nonzero(as_tuple=False)[0].item())
60
+ return 0
61
+
62
+ def step(
63
+ self,
64
+ model_output: torch.Tensor,
65
+ timestep: Union[float, torch.Tensor, None],
66
+ sample: torch.Tensor,
67
+ return_dict: bool = True,
68
+ generator: Optional[Union[torch.Generator, List[torch.Generator]]] = None,
69
+ ) -> Union[IMFSchedulerOutput, Tuple[torch.Tensor]]:
70
+ if self.timesteps is None:
71
+ raise ValueError("Call `set_timesteps` before `step`.")
72
+
73
+ step_index = self._resolve_step_index(timestep)
74
+ if step_index >= len(self.timesteps) - 1:
75
+ raise ValueError("Scheduler has already reached the final timestep.")
76
+
77
+ t = self.timesteps[step_index]
78
+ t_next = self.timesteps[step_index + 1]
79
+ dt = (t - t_next).to(dtype=sample.dtype, device=sample.device)
80
+ while dt.ndim < sample.ndim:
81
+ dt = dt.unsqueeze(-1)
82
+
83
+ if getattr(self.config, "stochastic_sampling", False):
84
+ t_bc = t.to(dtype=sample.dtype, device=sample.device)
85
+ while t_bc.ndim < sample.ndim:
86
+ t_bc = t_bc.unsqueeze(-1)
87
+ t_next_bc = t_next.to(dtype=sample.dtype, device=sample.device)
88
+ while t_next_bc.ndim < sample.ndim:
89
+ t_next_bc = t_next_bc.unsqueeze(-1)
90
+ x0 = sample - t_bc * model_output
91
+ noise = randn_tensor(
92
+ sample.shape,
93
+ generator=generator,
94
+ device=sample.device,
95
+ dtype=sample.dtype,
96
+ )
97
+ prev_sample = (1.0 - t_next_bc) * x0 + t_next_bc * noise
98
+ else:
99
+ prev_sample = sample - dt * model_output
100
+
101
+ self._step_index = step_index + 1
102
+
103
+ if not return_dict:
104
+ return (prev_sample,)
105
+ return IMFSchedulerOutput(prev_sample=prev_sample)
iMF-L-SIM/transformer/config.json ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "_class_name": "IMFTransformer2DModel",
3
+ "_diffusers_version": "0.38.0",
4
+ "aux_head_depth": 8,
5
+ "depth": 32,
6
+ "embedding_init_constant": 1.0,
7
+ "eval_mode": true,
8
+ "hidden_size": 1024,
9
+ "in_channels": 4,
10
+ "mlp_ratio": 2.6666666666666665,
11
+ "model_type": "iMF-L/2",
12
+ "num_attention_heads": 16,
13
+ "num_cfg_tokens": 4,
14
+ "num_class_embeds": null,
15
+ "num_class_tokens": 8,
16
+ "num_classes": 1000,
17
+ "num_interval_tokens": 2,
18
+ "num_time_tokens": 4,
19
+ "patch_size": 2,
20
+ "sample_size": 32,
21
+ "token_init_constant": 1.0,
22
+ "weight_init_constant": 0.32
23
+ }
iMF-L-SIM/transformer/diffusion_pytorch_model.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:908b20e09e463897734a3735b98dce730f6b050c9612314972f0a0a04ed66acc
3
+ size 1636334400
iMF-L-SIM/transformer/transformer_imf.py ADDED
@@ -0,0 +1,586 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from __future__ import annotations
2
+
3
+ import argparse
4
+ import math
5
+ from collections.abc import Mapping
6
+ from dataclasses import dataclass
7
+ from functools import partial
8
+ from math import sqrt
9
+ from typing import Dict, Literal, Optional, Tuple, Union
10
+
11
+ import torch
12
+ import torch.nn as nn
13
+ import torch.nn.functional as F
14
+ from diffusers.configuration_utils import ConfigMixin, register_to_config
15
+ from diffusers.models.modeling_utils import ModelMixin
16
+ from diffusers.utils import BaseOutput
17
+
18
+
19
+ IMF_PRESET_CONFIGS: Dict[str, Dict[str, object]] = {
20
+ "iMF-B/2": {
21
+ "sample_size": 32,
22
+ "patch_size": 2,
23
+ "hidden_size": 768,
24
+ "depth": 12,
25
+ "num_attention_heads": 12,
26
+ "aux_head_depth": 8,
27
+ },
28
+ "iMF-M/2": {
29
+ "sample_size": 32,
30
+ "patch_size": 2,
31
+ "hidden_size": 768,
32
+ "depth": 24,
33
+ "num_attention_heads": 12,
34
+ "aux_head_depth": 8,
35
+ },
36
+ "iMF-L/2": {
37
+ "sample_size": 32,
38
+ "patch_size": 2,
39
+ "hidden_size": 1024,
40
+ "depth": 32,
41
+ "num_attention_heads": 16,
42
+ "aux_head_depth": 8,
43
+ },
44
+ "iMF-XL/2": {
45
+ "sample_size": 32,
46
+ "patch_size": 2,
47
+ "hidden_size": 1024,
48
+ "depth": 48,
49
+ "num_attention_heads": 16,
50
+ "aux_head_depth": 8,
51
+ },
52
+ }
53
+
54
+
55
+ @dataclass
56
+ class IMFTransformer2DModelOutput(BaseOutput):
57
+ velocity_u: torch.Tensor
58
+ velocity_v: Optional[torch.Tensor] = None
59
+
60
+
61
+ def remap_legacy_state_dict(state_dict: Dict[str, torch.Tensor]) -> Dict[str, torch.Tensor]:
62
+ """Map legacy iMF / Flax-style keys to native IMFTransformer2DModel keys."""
63
+ remapped: Dict[str, torch.Tensor] = {}
64
+ for key, value in state_dict.items():
65
+ new_key = key
66
+ for prefix in ("net.", "transformer."):
67
+ if new_key.startswith(prefix):
68
+ new_key = new_key[len(prefix) :]
69
+ break
70
+ new_key = new_key.replace(".kernel", ".weight")
71
+ new_key = new_key.replace("._flax_linear.", ".linear.")
72
+ new_key = new_key.replace("._flax_embedding.", ".embedding.")
73
+ remapped[new_key] = value
74
+ return remapped
75
+
76
+
77
+ def config_from_legacy(config: Dict[str, object]) -> Dict[str, object]:
78
+ model_type = config.get("model_type") or config.get("model_str") or config.get("model_name")
79
+ if model_type not in IMF_PRESET_CONFIGS:
80
+ raise ValueError(f"Unknown iMF preset '{model_type}'. Known: {list(IMF_PRESET_CONFIGS)}")
81
+
82
+ preset = dict(IMF_PRESET_CONFIGS[model_type])
83
+ preset["num_classes"] = int(config.get("num_class_embeds") or config.get("num_classes") or 1000)
84
+ preset["model_type"] = model_type
85
+ if config.get("sample_size") is not None:
86
+ preset["sample_size"] = int(config["sample_size"])
87
+ if config.get("in_channels") is not None:
88
+ preset["in_channels"] = int(config["in_channels"])
89
+ return preset
90
+
91
+
92
+ def _unsqueeze(t: torch.Tensor, dim: int) -> torch.Tensor:
93
+ return t.unsqueeze(dim)
94
+
95
+
96
+ class _ScaledLinear(nn.Module):
97
+ def __init__(
98
+ self,
99
+ in_features: int,
100
+ out_features: int,
101
+ bias: bool = True,
102
+ weight_init: str = "scaled_variance",
103
+ init_constant: float = 1.0,
104
+ bias_init: str = "zeros",
105
+ ):
106
+ super().__init__()
107
+ self.linear = nn.Linear(in_features, out_features, bias=bias)
108
+ if weight_init == "scaled_variance":
109
+ std = init_constant / sqrt(in_features)
110
+ nn.init.normal_(self.linear.weight, std=std)
111
+ elif weight_init == "zeros":
112
+ nn.init.zeros_(self.linear.weight)
113
+ else:
114
+ raise ValueError(f"Invalid weight_init: {weight_init}")
115
+ if bias:
116
+ if bias_init == "zeros":
117
+ nn.init.zeros_(self.linear.bias)
118
+ else:
119
+ raise ValueError(f"Invalid bias_init: {bias_init}")
120
+
121
+ def forward(self, x: torch.Tensor) -> torch.Tensor:
122
+ return self.linear(x)
123
+
124
+
125
+ class _ScaledEmbedding(nn.Module):
126
+ def __init__(
127
+ self,
128
+ num_embeddings: int,
129
+ embedding_dim: int,
130
+ weight_init: str = "scaled_variance",
131
+ init_constant: float = 1.0,
132
+ ):
133
+ super().__init__()
134
+ self.embedding = nn.Embedding(num_embeddings, embedding_dim)
135
+ if weight_init == "scaled_variance":
136
+ std = init_constant / sqrt(embedding_dim)
137
+ nn.init.normal_(self.embedding.weight, std=std)
138
+ else:
139
+ raise ValueError(f"Invalid weight_init: {weight_init}")
140
+
141
+ def forward(self, x: torch.Tensor) -> torch.Tensor:
142
+ return self.embedding(x)
143
+
144
+
145
+ class _RMSNorm(nn.Module):
146
+ def __init__(self, dim: int, eps: float = 1e-6):
147
+ super().__init__()
148
+ self.weight = nn.Parameter(torch.ones(dim))
149
+ self.eps = eps
150
+
151
+ def forward(self, x: torch.Tensor) -> torch.Tensor:
152
+ mean_square = torch.mean(torch.square(x), dim=-1, keepdim=True)
153
+ output = x * torch.rsqrt(mean_square + self.eps)
154
+ return output.to(x.dtype) * self.weight
155
+
156
+
157
+ class _SwiGLUMlp(nn.Module):
158
+ def __init__(
159
+ self,
160
+ in_features: int,
161
+ hidden_features: int,
162
+ weight_init: str = "scaled_variance",
163
+ weight_init_constant: float = 1.0,
164
+ ):
165
+ super().__init__()
166
+ init_kwargs = dict(bias=False, weight_init=weight_init, init_constant=weight_init_constant)
167
+ self.w1 = _ScaledLinear(in_features, hidden_features, **init_kwargs)
168
+ self.w3 = _ScaledLinear(in_features, hidden_features, **init_kwargs)
169
+ self.w2 = _ScaledLinear(hidden_features, in_features, **init_kwargs)
170
+
171
+ def forward(self, x: torch.Tensor) -> torch.Tensor:
172
+ return self.w2(F.silu(self.w1(x)) * self.w3(x))
173
+
174
+
175
+ class IMFTimestepEmbedder(nn.Module):
176
+ def __init__(
177
+ self,
178
+ hidden_size: int,
179
+ frequency_embedding_size: int = 256,
180
+ init_constant: float = 1.0,
181
+ ):
182
+ super().__init__()
183
+ self.mlp = nn.Sequential(
184
+ _ScaledLinear(frequency_embedding_size, hidden_size, bias=True, init_constant=init_constant),
185
+ nn.SiLU(),
186
+ _ScaledLinear(hidden_size, hidden_size, bias=True, init_constant=init_constant),
187
+ )
188
+ self.frequency_embedding_size = frequency_embedding_size
189
+
190
+ @staticmethod
191
+ def timestep_embedding(t: torch.Tensor, dim: int, max_period: int = 10000) -> torch.Tensor:
192
+ half = dim // 2
193
+ freqs = torch.exp(
194
+ -math.log(max_period) * torch.arange(start=0, end=half, dtype=torch.float32, device=t.device) / half
195
+ )
196
+ args = t[:, None].float() * freqs[None]
197
+ embedding = torch.cat([torch.cos(args), torch.sin(args)], dim=-1)
198
+ if dim % 2:
199
+ embedding = torch.cat([embedding, torch.zeros_like(embedding[:, :1])], dim=-1)
200
+ return embedding
201
+
202
+ def forward(self, t: torch.Tensor) -> torch.Tensor:
203
+ embedding = self.timestep_embedding(t, self.frequency_embedding_size)
204
+ return self.mlp(embedding.to(dtype=next(self.mlp.parameters()).dtype))
205
+
206
+
207
+ class IMFLabelEmbedder(nn.Module):
208
+ def __init__(self, num_classes: int, hidden_size: int, init_constant: float = 1.0):
209
+ super().__init__()
210
+ self.embedding_table = _ScaledEmbedding(num_classes + 1, hidden_size, init_constant=init_constant)
211
+
212
+ def forward(self, labels: torch.Tensor) -> torch.Tensor:
213
+ return self.embedding_table(labels)
214
+
215
+
216
+ class IMFPatchEmbedder(nn.Module):
217
+ def __init__(self, input_size: int, patch_size: int, in_channels: int, hidden_size: int, bias: bool = True):
218
+ super().__init__()
219
+ self.patch_size = (patch_size, patch_size)
220
+ self.num_patches = (input_size // patch_size) ** 2
221
+ self.proj = nn.Conv2d(
222
+ in_channels,
223
+ hidden_size,
224
+ kernel_size=patch_size,
225
+ stride=patch_size,
226
+ bias=bias,
227
+ )
228
+ kh = kw = patch_size
229
+ fan_in = kh * kw * in_channels
230
+ fan_out = hidden_size
231
+ limit = math.sqrt(6.0 / (fan_in + fan_out))
232
+ nn.init.uniform_(self.proj.weight, -limit, limit)
233
+ if bias:
234
+ nn.init.zeros_(self.proj.bias)
235
+
236
+ def forward(self, x: torch.Tensor) -> torch.Tensor:
237
+ x = self.proj(x)
238
+ return x.flatten(2).transpose(1, 2)
239
+
240
+
241
+ def precompute_rope_freqs(dim: int, seq_len: int, theta: float = 10000.0, device: torch.device | None = None):
242
+ freqs = 1.0 / (theta ** (torch.arange(0, dim, 2, dtype=torch.float32, device=device) / dim))
243
+ positions = torch.arange(seq_len, dtype=torch.float32, device=device)
244
+ freqs_cis = torch.outer(positions, freqs)
245
+ return torch.complex(torch.cos(freqs_cis), torch.sin(freqs_cis))
246
+
247
+
248
+ def apply_rotary_pos_emb(x: torch.Tensor, freqs_cis: torch.Tensor) -> torch.Tensor:
249
+ x_ = x.float().reshape(*x.shape[:-1], -1, 2)
250
+ x_complex = torch.view_as_complex(x_)
251
+ freqs_cis = freqs_cis.unsqueeze(0).unsqueeze(2).to(x.device)
252
+ x_rotated = torch.view_as_real(x_complex * freqs_cis).flatten(-2)
253
+ return x_rotated.to(dtype=x.dtype)
254
+
255
+
256
+ class IMFRoPEAttention(nn.Module):
257
+ def __init__(self, hidden_size: int, num_heads: int, weight_init_constant: float = 0.32):
258
+ super().__init__()
259
+ self.hidden_size = hidden_size
260
+ self.num_heads = num_heads
261
+ self.head_dim = hidden_size // num_heads
262
+ init_kwargs = dict(bias=False, init_constant=weight_init_constant)
263
+ self.q_proj = _ScaledLinear(hidden_size, hidden_size, **init_kwargs)
264
+ self.k_proj = _ScaledLinear(hidden_size, hidden_size, **init_kwargs)
265
+ self.v_proj = _ScaledLinear(hidden_size, hidden_size, **init_kwargs)
266
+ self.out_proj = _ScaledLinear(hidden_size, hidden_size, **init_kwargs)
267
+ self.q_norm = _RMSNorm(self.head_dim)
268
+ self.k_norm = _RMSNorm(self.head_dim)
269
+
270
+ def forward(self, x: torch.Tensor, rope_freqs: torch.Tensor) -> torch.Tensor:
271
+ batch, seq_len, _ = x.shape
272
+ q = self.q_proj(x).reshape(batch, seq_len, self.num_heads, self.head_dim)
273
+ k = self.k_proj(x).reshape(batch, seq_len, self.num_heads, self.head_dim)
274
+ v = self.v_proj(x).reshape(batch, seq_len, self.num_heads, self.head_dim)
275
+ q = apply_rotary_pos_emb(self.q_norm(q), rope_freqs)
276
+ k = apply_rotary_pos_emb(self.k_norm(k), rope_freqs)
277
+ query = q / math.sqrt(self.head_dim)
278
+ attn_weights = torch.einsum("bqhd,bkhd->bhqk", query, k)
279
+ attn_weights = F.softmax(attn_weights, dim=-1, dtype=torch.float32).to(v.dtype)
280
+ attn = torch.einsum("bhqk,bkhd->bqhd", attn_weights, v)
281
+ return self.out_proj(attn.reshape(batch, seq_len, self.hidden_size))
282
+
283
+
284
+ class IMFTransformerBlock(nn.Module):
285
+ def __init__(self, hidden_size: int, num_heads: int, mlp_ratio: float, weight_init_constant: float):
286
+ super().__init__()
287
+ self.norm1 = _RMSNorm(hidden_size)
288
+ self.attn = IMFRoPEAttention(hidden_size, num_heads, weight_init_constant=weight_init_constant)
289
+ self.norm2 = _RMSNorm(hidden_size)
290
+ mlp_hidden_dim = int(hidden_size * mlp_ratio)
291
+ self.mlp = _SwiGLUMlp(hidden_size, mlp_hidden_dim, weight_init_constant=weight_init_constant)
292
+ self.attn_scale = nn.Parameter(torch.zeros(hidden_size))
293
+ self.mlp_scale = nn.Parameter(torch.zeros(hidden_size))
294
+
295
+ def forward(self, x: torch.Tensor, rope_freqs: torch.Tensor) -> torch.Tensor:
296
+ x = x + self.attn(self.norm1(x), rope_freqs) * self.attn_scale
297
+ x = x + self.mlp(self.norm2(x)) * self.mlp_scale
298
+ return x
299
+
300
+
301
+ class IMFFinalLayer(nn.Module):
302
+ def __init__(self, hidden_size: int, patch_size: int, out_channels: int):
303
+ super().__init__()
304
+ self.norm = _RMSNorm(hidden_size)
305
+ self.linear = _ScaledLinear(
306
+ hidden_size,
307
+ patch_size * patch_size * out_channels,
308
+ bias=True,
309
+ weight_init="zeros",
310
+ init_constant=1.0,
311
+ )
312
+
313
+ def forward(self, x: torch.Tensor) -> torch.Tensor:
314
+ return self.linear(self.norm(x))
315
+
316
+
317
+ class IMFTransformer2DModel(ModelMixin, ConfigMixin):
318
+ _supports_gradient_checkpointing = True
319
+
320
+ @register_to_config
321
+ def __init__(
322
+ self,
323
+ sample_size: int = 32,
324
+ patch_size: int = 2,
325
+ in_channels: int = 4,
326
+ hidden_size: int = 768,
327
+ depth: int = 12,
328
+ num_attention_heads: int = 12,
329
+ mlp_ratio: float = 8 / 3,
330
+ num_classes: int = 1000,
331
+ aux_head_depth: int = 8,
332
+ num_class_tokens: int = 8,
333
+ num_time_tokens: int = 4,
334
+ num_cfg_tokens: int = 4,
335
+ num_interval_tokens: int = 2,
336
+ token_init_constant: float = 1.0,
337
+ embedding_init_constant: float = 1.0,
338
+ weight_init_constant: float = 0.32,
339
+ eval_mode: bool = True,
340
+ model_type: str | None = None,
341
+ num_class_embeds: int | None = None,
342
+ ):
343
+ super().__init__()
344
+ if num_class_embeds is not None:
345
+ num_classes = int(num_class_embeds)
346
+ if model_type in IMF_PRESET_CONFIGS:
347
+ preset = IMF_PRESET_CONFIGS[model_type]
348
+ sample_size = int(preset["sample_size"])
349
+ patch_size = int(preset["patch_size"])
350
+ hidden_size = int(preset["hidden_size"])
351
+ depth = int(preset["depth"])
352
+ num_attention_heads = int(preset["num_attention_heads"])
353
+ aux_head_depth = int(preset["aux_head_depth"])
354
+
355
+ self.sample_size = sample_size
356
+ self.patch_size = patch_size
357
+ self.in_channels = in_channels
358
+ self.out_channels = in_channels
359
+ self.hidden_size = hidden_size
360
+ self.depth = depth
361
+ self.num_attention_heads = num_attention_heads
362
+ self.num_classes = num_classes
363
+ self.aux_head_depth = aux_head_depth
364
+ self.num_class_tokens = num_class_tokens
365
+ self.num_time_tokens = num_time_tokens
366
+ self.num_cfg_tokens = num_cfg_tokens
367
+ self.num_interval_tokens = num_interval_tokens
368
+ self.eval_mode = eval_mode
369
+ self.gradient_checkpointing = False
370
+
371
+ self.x_embedder = IMFPatchEmbedder(sample_size, patch_size, in_channels, hidden_size, bias=True)
372
+ embed_kwargs = dict(hidden_size=hidden_size, init_constant=embedding_init_constant)
373
+ self.h_embedder = IMFTimestepEmbedder(**embed_kwargs)
374
+ self.omega_embedder = IMFTimestepEmbedder(**embed_kwargs)
375
+ self.cfg_t_start_embedder = IMFTimestepEmbedder(**embed_kwargs)
376
+ self.cfg_t_end_embedder = IMFTimestepEmbedder(**embed_kwargs)
377
+ self.y_embedder = IMFLabelEmbedder(num_classes, hidden_size, init_constant=embedding_init_constant)
378
+
379
+ token_std = token_init_constant / math.sqrt(hidden_size)
380
+ self.time_tokens = nn.Parameter(torch.randn(num_time_tokens, hidden_size) * token_std)
381
+ self.class_tokens = nn.Parameter(torch.randn(num_class_tokens, hidden_size) * token_std)
382
+ self.omega_tokens = nn.Parameter(torch.randn(num_cfg_tokens, hidden_size) * token_std)
383
+ self.t_min_tokens = nn.Parameter(torch.randn(num_interval_tokens, hidden_size) * token_std)
384
+ self.t_max_tokens = nn.Parameter(torch.randn(num_interval_tokens, hidden_size) * token_std)
385
+
386
+ total_tokens = (
387
+ self.x_embedder.num_patches
388
+ + num_class_tokens
389
+ + num_cfg_tokens
390
+ + 2 * num_interval_tokens
391
+ + num_time_tokens
392
+ )
393
+ self.prefix_tokens = num_class_tokens + num_cfg_tokens + 2 * num_interval_tokens + num_time_tokens
394
+ self.head_dim = hidden_size // num_attention_heads
395
+ self.register_buffer(
396
+ "rope_freqs",
397
+ precompute_rope_freqs(self.head_dim, total_tokens),
398
+ persistent=False,
399
+ )
400
+
401
+ shared_depth = depth - aux_head_depth
402
+ block_kwargs = dict(
403
+ hidden_size=hidden_size,
404
+ num_heads=num_attention_heads,
405
+ mlp_ratio=mlp_ratio,
406
+ weight_init_constant=weight_init_constant,
407
+ )
408
+ self.shared_blocks = nn.ModuleList([IMFTransformerBlock(**block_kwargs) for _ in range(shared_depth)])
409
+ self.u_heads = nn.ModuleList([IMFTransformerBlock(**block_kwargs) for _ in range(aux_head_depth)])
410
+ self.v_heads = nn.ModuleList(
411
+ [IMFTransformerBlock(**block_kwargs) for _ in range(aux_head_depth if not eval_mode else 0)]
412
+ )
413
+ self.u_final_layer = IMFFinalLayer(hidden_size, patch_size, in_channels)
414
+ self.v_final_layer = IMFFinalLayer(hidden_size, patch_size, in_channels)
415
+
416
+ def unpatchify(self, x: torch.Tensor) -> torch.Tensor:
417
+ c = self.out_channels
418
+ p = self.patch_size
419
+ h = w = int(x.shape[1] ** 0.5)
420
+ x = x.reshape(x.shape[0], h, w, p, p, c)
421
+ x = torch.einsum("nhwpqc->nchpwq", x)
422
+ return x.reshape(x.shape[0], c, h * p, w * p)
423
+
424
+ def _build_sequence(
425
+ self,
426
+ sample: torch.Tensor,
427
+ time_gap: torch.Tensor,
428
+ guidance_scale: torch.Tensor,
429
+ guidance_interval_start: torch.Tensor,
430
+ guidance_interval_end: torch.Tensor,
431
+ class_labels: torch.Tensor,
432
+ ) -> torch.Tensor:
433
+ x_embed = self.x_embedder(sample)
434
+ h_embed = self.h_embedder(time_gap)
435
+ omega_embed = self.omega_embedder(1 - 1 / guidance_scale)
436
+ t_min_embed = self.cfg_t_start_embedder(guidance_interval_start)
437
+ t_max_embed = self.cfg_t_end_embedder(guidance_interval_end)
438
+ y_embed = self.y_embedder(class_labels)
439
+
440
+ time_tokens = self.time_tokens + _unsqueeze(h_embed, 1)
441
+ omega_tokens = self.omega_tokens + _unsqueeze(omega_embed, 1)
442
+ t_min_tokens = self.t_min_tokens + _unsqueeze(t_min_embed, 1)
443
+ t_max_tokens = self.t_max_tokens + _unsqueeze(t_max_embed, 1)
444
+ class_tokens = self.class_tokens + _unsqueeze(y_embed, 1)
445
+
446
+ return torch.cat(
447
+ [class_tokens, omega_tokens, t_min_tokens, t_max_tokens, time_tokens, x_embed],
448
+ dim=1,
449
+ )
450
+
451
+ def forward(
452
+ self,
453
+ sample: torch.Tensor,
454
+ timestep: torch.Tensor,
455
+ class_labels: torch.Tensor,
456
+ time_gap: Optional[torch.Tensor] = None,
457
+ guidance_scale: Optional[torch.Tensor] = None,
458
+ guidance_interval_start: Optional[torch.Tensor] = None,
459
+ guidance_interval_end: Optional[torch.Tensor] = None,
460
+ return_dict: bool = True,
461
+ ) -> Union[IMFTransformer2DModelOutput, Tuple[torch.Tensor, ...]]:
462
+ batch_size = sample.shape[0]
463
+ timestep = self._expand_batch(timestep, batch_size, sample.device, sample.dtype)
464
+ if time_gap is None:
465
+ time_gap = timestep
466
+ else:
467
+ time_gap = self._expand_batch(time_gap, batch_size, sample.device, sample.dtype)
468
+ if guidance_scale is None:
469
+ guidance_scale = torch.ones(batch_size, device=sample.device, dtype=sample.dtype)
470
+ else:
471
+ guidance_scale = self._expand_batch(guidance_scale, batch_size, sample.device, sample.dtype)
472
+ if guidance_interval_start is None:
473
+ guidance_interval_start = torch.zeros(batch_size, device=sample.device, dtype=sample.dtype)
474
+ else:
475
+ guidance_interval_start = self._expand_batch(
476
+ guidance_interval_start, batch_size, sample.device, sample.dtype
477
+ )
478
+ if guidance_interval_end is None:
479
+ guidance_interval_end = torch.ones(batch_size, device=sample.device, dtype=sample.dtype)
480
+ else:
481
+ guidance_interval_end = self._expand_batch(
482
+ guidance_interval_end, batch_size, sample.device, sample.dtype
483
+ )
484
+
485
+ class_labels = class_labels.reshape(-1).long()
486
+ seq = self._build_sequence(
487
+ sample,
488
+ time_gap,
489
+ guidance_scale,
490
+ guidance_interval_start,
491
+ guidance_interval_end,
492
+ class_labels,
493
+ )
494
+
495
+ for block in self.shared_blocks:
496
+ if self.training and self.gradient_checkpointing:
497
+ seq = torch.utils.checkpoint.checkpoint(block, seq, self.rope_freqs, use_reentrant=False)
498
+ else:
499
+ seq = block(seq, self.rope_freqs)
500
+
501
+ u_seq = v_seq = seq
502
+ for block in self.u_heads:
503
+ u_seq = block(u_seq, self.rope_freqs)
504
+ for block in self.v_heads:
505
+ v_seq = block(v_seq, self.rope_freqs)
506
+
507
+ u_tokens = u_seq[:, self.prefix_tokens :]
508
+ velocity_u = self.unpatchify(self.u_final_layer(u_tokens))
509
+
510
+ velocity_v = None
511
+ if len(self.v_heads) > 0:
512
+ v_tokens = v_seq[:, self.prefix_tokens :]
513
+ velocity_v = self.unpatchify(self.v_final_layer(v_tokens))
514
+
515
+ if not return_dict:
516
+ if velocity_v is None:
517
+ return (velocity_u,)
518
+ return (velocity_u, velocity_v)
519
+ return IMFTransformer2DModelOutput(velocity_u=velocity_u, velocity_v=velocity_v)
520
+
521
+ @staticmethod
522
+ def _expand_batch(
523
+ value: torch.Tensor,
524
+ batch_size: int,
525
+ device: torch.device,
526
+ dtype: torch.dtype,
527
+ ) -> torch.Tensor:
528
+ value = torch.as_tensor(value, device=device, dtype=dtype)
529
+ if value.ndim == 0:
530
+ value = value.reshape(1).repeat(batch_size)
531
+ else:
532
+ value = value.reshape(-1)
533
+ if value.shape[0] == 1 and batch_size > 1:
534
+ value = value.repeat(batch_size)
535
+ return value
536
+
537
+ @classmethod
538
+ def from_imf_checkpoint(
539
+ cls,
540
+ checkpoint_path: str,
541
+ model_type: str | None = None,
542
+ map_location: str = "cpu",
543
+ strict: bool = True,
544
+ eval_mode: bool = True,
545
+ ) -> Tuple["IMFTransformer2DModel", Dict[str, object]]:
546
+ checkpoint = torch.load(checkpoint_path, map_location=map_location, weights_only=False)
547
+ if isinstance(checkpoint, Mapping) and "state_dict" in checkpoint:
548
+ state_dict = checkpoint["state_dict"]
549
+ elif isinstance(checkpoint, Mapping) and any(k.startswith("net.") for k in checkpoint):
550
+ state_dict = checkpoint
551
+ else:
552
+ state_dict = checkpoint
553
+
554
+ inferred_type = model_type
555
+ if inferred_type is None and isinstance(checkpoint, Mapping):
556
+ args = checkpoint.get("args")
557
+ if isinstance(args, argparse.Namespace):
558
+ inferred_type = getattr(args, "model", None) or getattr(args, "model_str", None)
559
+ elif isinstance(args, Mapping):
560
+ inferred_type = args.get("model") or args.get("model_str")
561
+
562
+ if inferred_type is None:
563
+ raise ValueError("model_type must be provided when loading a raw state dict checkpoint.")
564
+
565
+ config = dict(IMF_PRESET_CONFIGS[inferred_type])
566
+ config["model_type"] = inferred_type
567
+ config["eval_mode"] = eval_mode
568
+ model = cls(**config)
569
+ model.load_state_dict(remap_legacy_state_dict(state_dict), strict=strict)
570
+ metadata = {"checkpoint_path": checkpoint_path, "model_type": inferred_type}
571
+ return model, metadata
572
+
573
+ def to_imf_checkpoint(self, prefix: str = "net.") -> Dict[str, torch.Tensor]:
574
+ state: Dict[str, torch.Tensor] = {}
575
+ for key, value in self.state_dict().items():
576
+ if key == "rope_freqs":
577
+ continue
578
+ state[f"{prefix}{key}"] = value.detach().cpu()
579
+ return state
580
+
581
+ @property
582
+ def net(self):
583
+ return self
584
+
585
+
586
+ IMFDiffusersModel = IMFTransformer2DModel
iMF-L-SIM/vae/config.json ADDED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "_class_name": "AutoencoderKL",
3
+ "_diffusers_version": "0.36.0",
4
+ "_name_or_path": "stabilityai/sd-vae-ft-mse",
5
+ "act_fn": "silu",
6
+ "block_out_channels": [
7
+ 128,
8
+ 256,
9
+ 512,
10
+ 512
11
+ ],
12
+ "down_block_types": [
13
+ "DownEncoderBlock2D",
14
+ "DownEncoderBlock2D",
15
+ "DownEncoderBlock2D",
16
+ "DownEncoderBlock2D"
17
+ ],
18
+ "force_upcast": true,
19
+ "in_channels": 3,
20
+ "latent_channels": 4,
21
+ "latents_mean": null,
22
+ "latents_std": null,
23
+ "layers_per_block": 2,
24
+ "mid_block_add_attention": true,
25
+ "norm_num_groups": 32,
26
+ "out_channels": 3,
27
+ "sample_size": 256,
28
+ "scaling_factor": 0.18215,
29
+ "shift_factor": null,
30
+ "up_block_types": [
31
+ "UpDecoderBlock2D",
32
+ "UpDecoderBlock2D",
33
+ "UpDecoderBlock2D",
34
+ "UpDecoderBlock2D"
35
+ ],
36
+ "use_post_quant_conv": true,
37
+ "use_quant_conv": true
38
+ }
iMF-L-SIM/vae/diffusion_pytorch_model.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:a1d993488569e928462932c8c38a0760b874d166399b14414135bd9c42df5815
3
+ size 334643276
iMF-XL-SIM/README.md ADDED
@@ -0,0 +1,54 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: mit
3
+ library_name: diffusers
4
+ pipeline_tag: text-to-image
5
+ tags:
6
+ - diffusers
7
+ - imf
8
+ - image-generation
9
+ - class-conditional
10
+ inference: true
11
+ widget:
12
+ - output:
13
+ url: demo.png
14
+ language:
15
+ - en
16
+ ---
17
+
18
+ # iMF-XL-SIM
19
+
20
+ Self-contained Diffusers variant for **iMF-XL/2 (FD-SIM post-trained)** (Improved Mean Flows).
21
+
22
+ ## Demo
23
+
24
+ ![iMF-XL-SIM demo](demo.png)
25
+
26
+ Class-conditional sample (ImageNet class **207**, golden retriever), 1 step, CFG 1.8, interval [0.0, 1.0], seed 42.
27
+
28
+ ## Load
29
+
30
+ ```python
31
+ from pathlib import Path
32
+ from diffusers import DiffusionPipeline
33
+ import torch
34
+
35
+ model_dir = Path("iMF-XL-SIM")
36
+ pipe = DiffusionPipeline.from_pretrained(
37
+ str(model_dir),
38
+ local_files_only=True,
39
+ custom_pipeline=str(model_dir / "pipeline.py"),
40
+ trust_remote_code=True,
41
+ torch_dtype=torch.bfloat16,
42
+ ).to("cuda")
43
+
44
+ generator = torch.Generator(device="cuda").manual_seed(42)
45
+ image = pipe(
46
+ class_labels="golden retriever",
47
+ num_inference_steps=1,
48
+ guidance_scale=1.8,
49
+ guidance_interval_start=0.0,
50
+ guidance_interval_end=1.0,
51
+ generator=generator,
52
+ ).images[0]
53
+ image.save("demo.png")
54
+ ```
iMF-XL-SIM/model_index.json ADDED
@@ -0,0 +1,1021 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "_class_name": [
3
+ "pipeline",
4
+ "IMFPipeline"
5
+ ],
6
+ "_diffusers_version": "0.36.0",
7
+ "scheduler": [
8
+ "scheduling_imf",
9
+ "IMFScheduler"
10
+ ],
11
+ "transformer": [
12
+ "transformer_imf",
13
+ "IMFTransformer2DModel"
14
+ ],
15
+ "id2label": {
16
+ "0": "tench, Tinca tinca",
17
+ "1": "goldfish, Carassius auratus",
18
+ "2": "great white shark, white shark, man-eater, man-eating shark, Carcharodon carcharias",
19
+ "3": "tiger shark, Galeocerdo cuvieri",
20
+ "4": "hammerhead, hammerhead shark",
21
+ "5": "electric ray, crampfish, numbfish, torpedo",
22
+ "6": "stingray",
23
+ "7": "cock",
24
+ "8": "hen",
25
+ "9": "ostrich, Struthio camelus",
26
+ "10": "brambling, Fringilla montifringilla",
27
+ "11": "goldfinch, Carduelis carduelis",
28
+ "12": "house finch, linnet, Carpodacus mexicanus",
29
+ "13": "junco, snowbird",
30
+ "14": "indigo bunting, indigo finch, indigo bird, Passerina cyanea",
31
+ "15": "robin, American robin, Turdus migratorius",
32
+ "16": "bulbul",
33
+ "17": "jay",
34
+ "18": "magpie",
35
+ "19": "chickadee",
36
+ "20": "water ouzel, dipper",
37
+ "21": "kite",
38
+ "22": "bald eagle, American eagle, Haliaeetus leucocephalus",
39
+ "23": "vulture",
40
+ "24": "great grey owl, great gray owl, Strix nebulosa",
41
+ "25": "European fire salamander, Salamandra salamandra",
42
+ "26": "common newt, Triturus vulgaris",
43
+ "27": "eft",
44
+ "28": "spotted salamander, Ambystoma maculatum",
45
+ "29": "axolotl, mud puppy, Ambystoma mexicanum",
46
+ "30": "bullfrog, Rana catesbeiana",
47
+ "31": "tree frog, tree-frog",
48
+ "32": "tailed frog, bell toad, ribbed toad, tailed toad, Ascaphus trui",
49
+ "33": "loggerhead, loggerhead turtle, Caretta caretta",
50
+ "34": "leatherback turtle, leatherback, leathery turtle, Dermochelys coriacea",
51
+ "35": "mud turtle",
52
+ "36": "terrapin",
53
+ "37": "box turtle, box tortoise",
54
+ "38": "banded gecko",
55
+ "39": "common iguana, iguana, Iguana iguana",
56
+ "40": "American chameleon, anole, Anolis carolinensis",
57
+ "41": "whiptail, whiptail lizard",
58
+ "42": "agama",
59
+ "43": "frilled lizard, Chlamydosaurus kingi",
60
+ "44": "alligator lizard",
61
+ "45": "Gila monster, Heloderma suspectum",
62
+ "46": "green lizard, Lacerta viridis",
63
+ "47": "African chameleon, Chamaeleo chamaeleon",
64
+ "48": "Komodo dragon, Komodo lizard, dragon lizard, giant lizard, Varanus komodoensis",
65
+ "49": "African crocodile, Nile crocodile, Crocodylus niloticus",
66
+ "50": "American alligator, Alligator mississipiensis",
67
+ "51": "triceratops",
68
+ "52": "thunder snake, worm snake, Carphophis amoenus",
69
+ "53": "ringneck snake, ring-necked snake, ring snake",
70
+ "54": "hognose snake, puff adder, sand viper",
71
+ "55": "green snake, grass snake",
72
+ "56": "king snake, kingsnake",
73
+ "57": "garter snake, grass snake",
74
+ "58": "water snake",
75
+ "59": "vine snake",
76
+ "60": "night snake, Hypsiglena torquata",
77
+ "61": "boa constrictor, Constrictor constrictor",
78
+ "62": "rock python, rock snake, Python sebae",
79
+ "63": "Indian cobra, Naja naja",
80
+ "64": "green mamba",
81
+ "65": "sea snake",
82
+ "66": "horned viper, cerastes, sand viper, horned asp, Cerastes cornutus",
83
+ "67": "diamondback, diamondback rattlesnake, Crotalus adamanteus",
84
+ "68": "sidewinder, horned rattlesnake, Crotalus cerastes",
85
+ "69": "trilobite",
86
+ "70": "harvestman, daddy longlegs, Phalangium opilio",
87
+ "71": "scorpion",
88
+ "72": "black and gold garden spider, Argiope aurantia",
89
+ "73": "barn spider, Araneus cavaticus",
90
+ "74": "garden spider, Aranea diademata",
91
+ "75": "black widow, Latrodectus mactans",
92
+ "76": "tarantula",
93
+ "77": "wolf spider, hunting spider",
94
+ "78": "tick",
95
+ "79": "centipede",
96
+ "80": "black grouse",
97
+ "81": "ptarmigan",
98
+ "82": "ruffed grouse, partridge, Bonasa umbellus",
99
+ "83": "prairie chicken, prairie grouse, prairie fowl",
100
+ "84": "peacock",
101
+ "85": "quail",
102
+ "86": "partridge",
103
+ "87": "African grey, African gray, Psittacus erithacus",
104
+ "88": "macaw",
105
+ "89": "sulphur-crested cockatoo, Kakatoe galerita, Cacatua galerita",
106
+ "90": "lorikeet",
107
+ "91": "coucal",
108
+ "92": "bee eater",
109
+ "93": "hornbill",
110
+ "94": "hummingbird",
111
+ "95": "jacamar",
112
+ "96": "toucan",
113
+ "97": "drake",
114
+ "98": "red-breasted merganser, Mergus serrator",
115
+ "99": "goose",
116
+ "100": "black swan, Cygnus atratus",
117
+ "101": "tusker",
118
+ "102": "echidna, spiny anteater, anteater",
119
+ "103": "platypus, duckbill, duckbilled platypus, duck-billed platypus, Ornithorhynchus anatinus",
120
+ "104": "wallaby, brush kangaroo",
121
+ "105": "koala, koala bear, kangaroo bear, native bear, Phascolarctos cinereus",
122
+ "106": "wombat",
123
+ "107": "jellyfish",
124
+ "108": "sea anemone, anemone",
125
+ "109": "brain coral",
126
+ "110": "flatworm, platyhelminth",
127
+ "111": "nematode, nematode worm, roundworm",
128
+ "112": "conch",
129
+ "113": "snail",
130
+ "114": "slug",
131
+ "115": "sea slug, nudibranch",
132
+ "116": "chiton, coat-of-mail shell, sea cradle, polyplacophore",
133
+ "117": "chambered nautilus, pearly nautilus, nautilus",
134
+ "118": "Dungeness crab, Cancer magister",
135
+ "119": "rock crab, Cancer irroratus",
136
+ "120": "fiddler crab",
137
+ "121": "king crab, Alaska crab, Alaskan king crab, Alaska king crab, Paralithodes camtschatica",
138
+ "122": "American lobster, Northern lobster, Maine lobster, Homarus americanus",
139
+ "123": "spiny lobster, langouste, rock lobster, crawfish, crayfish, sea crawfish",
140
+ "124": "crayfish, crawfish, crawdad, crawdaddy",
141
+ "125": "hermit crab",
142
+ "126": "isopod",
143
+ "127": "white stork, Ciconia ciconia",
144
+ "128": "black stork, Ciconia nigra",
145
+ "129": "spoonbill",
146
+ "130": "flamingo",
147
+ "131": "little blue heron, Egretta caerulea",
148
+ "132": "American egret, great white heron, Egretta albus",
149
+ "133": "bittern",
150
+ "134": "crane",
151
+ "135": "limpkin, Aramus pictus",
152
+ "136": "European gallinule, Porphyrio porphyrio",
153
+ "137": "American coot, marsh hen, mud hen, water hen, Fulica americana",
154
+ "138": "bustard",
155
+ "139": "ruddy turnstone, Arenaria interpres",
156
+ "140": "red-backed sandpiper, dunlin, Erolia alpina",
157
+ "141": "redshank, Tringa totanus",
158
+ "142": "dowitcher",
159
+ "143": "oystercatcher, oyster catcher",
160
+ "144": "pelican",
161
+ "145": "king penguin, Aptenodytes patagonica",
162
+ "146": "albatross, mollymawk",
163
+ "147": "grey whale, gray whale, devilfish, Eschrichtius gibbosus, Eschrichtius robustus",
164
+ "148": "killer whale, killer, orca, grampus, sea wolf, Orcinus orca",
165
+ "149": "dugong, Dugong dugon",
166
+ "150": "sea lion",
167
+ "151": "Chihuahua",
168
+ "152": "Japanese spaniel",
169
+ "153": "Maltese dog, Maltese terrier, Maltese",
170
+ "154": "Pekinese, Pekingese, Peke",
171
+ "155": "Shih-Tzu",
172
+ "156": "Blenheim spaniel",
173
+ "157": "papillon",
174
+ "158": "toy terrier",
175
+ "159": "Rhodesian ridgeback",
176
+ "160": "Afghan hound, Afghan",
177
+ "161": "basset, basset hound",
178
+ "162": "beagle",
179
+ "163": "bloodhound, sleuthhound",
180
+ "164": "bluetick",
181
+ "165": "black-and-tan coonhound",
182
+ "166": "Walker hound, Walker foxhound",
183
+ "167": "English foxhound",
184
+ "168": "redbone",
185
+ "169": "borzoi, Russian wolfhound",
186
+ "170": "Irish wolfhound",
187
+ "171": "Italian greyhound",
188
+ "172": "whippet",
189
+ "173": "Ibizan hound, Ibizan Podenco",
190
+ "174": "Norwegian elkhound, elkhound",
191
+ "175": "otterhound, otter hound",
192
+ "176": "Saluki, gazelle hound",
193
+ "177": "Scottish deerhound, deerhound",
194
+ "178": "Weimaraner",
195
+ "179": "Staffordshire bullterrier, Staffordshire bull terrier",
196
+ "180": "American Staffordshire terrier, Staffordshire terrier, American pit bull terrier, pit bull terrier",
197
+ "181": "Bedlington terrier",
198
+ "182": "Border terrier",
199
+ "183": "Kerry blue terrier",
200
+ "184": "Irish terrier",
201
+ "185": "Norfolk terrier",
202
+ "186": "Norwich terrier",
203
+ "187": "Yorkshire terrier",
204
+ "188": "wire-haired fox terrier",
205
+ "189": "Lakeland terrier",
206
+ "190": "Sealyham terrier, Sealyham",
207
+ "191": "Airedale, Airedale terrier",
208
+ "192": "cairn, cairn terrier",
209
+ "193": "Australian terrier",
210
+ "194": "Dandie Dinmont, Dandie Dinmont terrier",
211
+ "195": "Boston bull, Boston terrier",
212
+ "196": "miniature schnauzer",
213
+ "197": "giant schnauzer",
214
+ "198": "standard schnauzer",
215
+ "199": "Scotch terrier, Scottish terrier, Scottie",
216
+ "200": "Tibetan terrier, chrysanthemum dog",
217
+ "201": "silky terrier, Sydney silky",
218
+ "202": "soft-coated wheaten terrier",
219
+ "203": "West Highland white terrier",
220
+ "204": "Lhasa, Lhasa apso",
221
+ "205": "flat-coated retriever",
222
+ "206": "curly-coated retriever",
223
+ "207": "golden retriever",
224
+ "208": "Labrador retriever",
225
+ "209": "Chesapeake Bay retriever",
226
+ "210": "German short-haired pointer",
227
+ "211": "vizsla, Hungarian pointer",
228
+ "212": "English setter",
229
+ "213": "Irish setter, red setter",
230
+ "214": "Gordon setter",
231
+ "215": "Brittany spaniel",
232
+ "216": "clumber, clumber spaniel",
233
+ "217": "English springer, English springer spaniel",
234
+ "218": "Welsh springer spaniel",
235
+ "219": "cocker spaniel, English cocker spaniel, cocker",
236
+ "220": "Sussex spaniel",
237
+ "221": "Irish water spaniel",
238
+ "222": "kuvasz",
239
+ "223": "schipperke",
240
+ "224": "groenendael",
241
+ "225": "malinois",
242
+ "226": "briard",
243
+ "227": "kelpie",
244
+ "228": "komondor",
245
+ "229": "Old English sheepdog, bobtail",
246
+ "230": "Shetland sheepdog, Shetland sheep dog, Shetland",
247
+ "231": "collie",
248
+ "232": "Border collie",
249
+ "233": "Bouvier des Flandres, Bouviers des Flandres",
250
+ "234": "Rottweiler",
251
+ "235": "German shepherd, German shepherd dog, German police dog, alsatian",
252
+ "236": "Doberman, Doberman pinscher",
253
+ "237": "miniature pinscher",
254
+ "238": "Greater Swiss Mountain dog",
255
+ "239": "Bernese mountain dog",
256
+ "240": "Appenzeller",
257
+ "241": "EntleBucher",
258
+ "242": "boxer",
259
+ "243": "bull mastiff",
260
+ "244": "Tibetan mastiff",
261
+ "245": "French bulldog",
262
+ "246": "Great Dane",
263
+ "247": "Saint Bernard, St Bernard",
264
+ "248": "Eskimo dog, husky",
265
+ "249": "malamute, malemute, Alaskan malamute",
266
+ "250": "Siberian husky",
267
+ "251": "dalmatian, coach dog, carriage dog",
268
+ "252": "affenpinscher, monkey pinscher, monkey dog",
269
+ "253": "basenji",
270
+ "254": "pug, pug-dog",
271
+ "255": "Leonberg",
272
+ "256": "Newfoundland, Newfoundland dog",
273
+ "257": "Great Pyrenees",
274
+ "258": "Samoyed, Samoyede",
275
+ "259": "Pomeranian",
276
+ "260": "chow, chow chow",
277
+ "261": "keeshond",
278
+ "262": "Brabancon griffon",
279
+ "263": "Pembroke, Pembroke Welsh corgi",
280
+ "264": "Cardigan, Cardigan Welsh corgi",
281
+ "265": "toy poodle",
282
+ "266": "miniature poodle",
283
+ "267": "standard poodle",
284
+ "268": "Mexican hairless",
285
+ "269": "timber wolf, grey wolf, gray wolf, Canis lupus",
286
+ "270": "white wolf, Arctic wolf, Canis lupus tundrarum",
287
+ "271": "red wolf, maned wolf, Canis rufus, Canis niger",
288
+ "272": "coyote, prairie wolf, brush wolf, Canis latrans",
289
+ "273": "dingo, warrigal, warragal, Canis dingo",
290
+ "274": "dhole, Cuon alpinus",
291
+ "275": "African hunting dog, hyena dog, Cape hunting dog, Lycaon pictus",
292
+ "276": "hyena, hyaena",
293
+ "277": "red fox, Vulpes vulpes",
294
+ "278": "kit fox, Vulpes macrotis",
295
+ "279": "Arctic fox, white fox, Alopex lagopus",
296
+ "280": "grey fox, gray fox, Urocyon cinereoargenteus",
297
+ "281": "tabby, tabby cat",
298
+ "282": "tiger cat",
299
+ "283": "Persian cat",
300
+ "284": "Siamese cat, Siamese",
301
+ "285": "Egyptian cat",
302
+ "286": "cougar, puma, catamount, mountain lion, painter, panther, Felis concolor",
303
+ "287": "lynx, catamount",
304
+ "288": "leopard, Panthera pardus",
305
+ "289": "snow leopard, ounce, Panthera uncia",
306
+ "290": "jaguar, panther, Panthera onca, Felis onca",
307
+ "291": "lion, king of beasts, Panthera leo",
308
+ "292": "tiger, Panthera tigris",
309
+ "293": "cheetah, chetah, Acinonyx jubatus",
310
+ "294": "brown bear, bruin, Ursus arctos",
311
+ "295": "American black bear, black bear, Ursus americanus, Euarctos americanus",
312
+ "296": "ice bear, polar bear, Ursus Maritimus, Thalarctos maritimus",
313
+ "297": "sloth bear, Melursus ursinus, Ursus ursinus",
314
+ "298": "mongoose",
315
+ "299": "meerkat, mierkat",
316
+ "300": "tiger beetle",
317
+ "301": "ladybug, ladybeetle, lady beetle, ladybird, ladybird beetle",
318
+ "302": "ground beetle, carabid beetle",
319
+ "303": "long-horned beetle, longicorn, longicorn beetle",
320
+ "304": "leaf beetle, chrysomelid",
321
+ "305": "dung beetle",
322
+ "306": "rhinoceros beetle",
323
+ "307": "weevil",
324
+ "308": "fly",
325
+ "309": "bee",
326
+ "310": "ant, emmet, pismire",
327
+ "311": "grasshopper, hopper",
328
+ "312": "cricket",
329
+ "313": "walking stick, walkingstick, stick insect",
330
+ "314": "cockroach, roach",
331
+ "315": "mantis, mantid",
332
+ "316": "cicada, cicala",
333
+ "317": "leafhopper",
334
+ "318": "lacewing, lacewing fly",
335
+ "319": "dragonfly, darning needle, devils darning needle, sewing needle, snake feeder, snake doctor, mosquito hawk, skeeter hawk",
336
+ "320": "damselfly",
337
+ "321": "admiral",
338
+ "322": "ringlet, ringlet butterfly",
339
+ "323": "monarch, monarch butterfly, milkweed butterfly, Danaus plexippus",
340
+ "324": "cabbage butterfly",
341
+ "325": "sulphur butterfly, sulfur butterfly",
342
+ "326": "lycaenid, lycaenid butterfly",
343
+ "327": "starfish, sea star",
344
+ "328": "sea urchin",
345
+ "329": "sea cucumber, holothurian",
346
+ "330": "wood rabbit, cottontail, cottontail rabbit",
347
+ "331": "hare",
348
+ "332": "Angora, Angora rabbit",
349
+ "333": "hamster",
350
+ "334": "porcupine, hedgehog",
351
+ "335": "fox squirrel, eastern fox squirrel, Sciurus niger",
352
+ "336": "marmot",
353
+ "337": "beaver",
354
+ "338": "guinea pig, Cavia cobaya",
355
+ "339": "sorrel",
356
+ "340": "zebra",
357
+ "341": "hog, pig, grunter, squealer, Sus scrofa",
358
+ "342": "wild boar, boar, Sus scrofa",
359
+ "343": "warthog",
360
+ "344": "hippopotamus, hippo, river horse, Hippopotamus amphibius",
361
+ "345": "ox",
362
+ "346": "water buffalo, water ox, Asiatic buffalo, Bubalus bubalis",
363
+ "347": "bison",
364
+ "348": "ram, tup",
365
+ "349": "bighorn, bighorn sheep, cimarron, Rocky Mountain bighorn, Rocky Mountain sheep, Ovis canadensis",
366
+ "350": "ibex, Capra ibex",
367
+ "351": "hartebeest",
368
+ "352": "impala, Aepyceros melampus",
369
+ "353": "gazelle",
370
+ "354": "Arabian camel, dromedary, Camelus dromedarius",
371
+ "355": "llama",
372
+ "356": "weasel",
373
+ "357": "mink",
374
+ "358": "polecat, fitch, foulmart, foumart, Mustela putorius",
375
+ "359": "black-footed ferret, ferret, Mustela nigripes",
376
+ "360": "otter",
377
+ "361": "skunk, polecat, wood pussy",
378
+ "362": "badger",
379
+ "363": "armadillo",
380
+ "364": "three-toed sloth, ai, Bradypus tridactylus",
381
+ "365": "orangutan, orang, orangutang, Pongo pygmaeus",
382
+ "366": "gorilla, Gorilla gorilla",
383
+ "367": "chimpanzee, chimp, Pan troglodytes",
384
+ "368": "gibbon, Hylobates lar",
385
+ "369": "siamang, Hylobates syndactylus, Symphalangus syndactylus",
386
+ "370": "guenon, guenon monkey",
387
+ "371": "patas, hussar monkey, Erythrocebus patas",
388
+ "372": "baboon",
389
+ "373": "macaque",
390
+ "374": "langur",
391
+ "375": "colobus, colobus monkey",
392
+ "376": "proboscis monkey, Nasalis larvatus",
393
+ "377": "marmoset",
394
+ "378": "capuchin, ringtail, Cebus capucinus",
395
+ "379": "howler monkey, howler",
396
+ "380": "titi, titi monkey",
397
+ "381": "spider monkey, Ateles geoffroyi",
398
+ "382": "squirrel monkey, Saimiri sciureus",
399
+ "383": "Madagascar cat, ring-tailed lemur, Lemur catta",
400
+ "384": "indri, indris, Indri indri, Indri brevicaudatus",
401
+ "385": "Indian elephant, Elephas maximus",
402
+ "386": "African elephant, Loxodonta africana",
403
+ "387": "lesser panda, red panda, panda, bear cat, cat bear, Ailurus fulgens",
404
+ "388": "giant panda, panda, panda bear, coon bear, Ailuropoda melanoleuca",
405
+ "389": "barracouta, snoek",
406
+ "390": "eel",
407
+ "391": "coho, cohoe, coho salmon, blue jack, silver salmon, Oncorhynchus kisutch",
408
+ "392": "rock beauty, Holocanthus tricolor",
409
+ "393": "anemone fish",
410
+ "394": "sturgeon",
411
+ "395": "gar, garfish, garpike, billfish, Lepisosteus osseus",
412
+ "396": "lionfish",
413
+ "397": "puffer, pufferfish, blowfish, globefish",
414
+ "398": "abacus",
415
+ "399": "abaya",
416
+ "400": "academic gown, academic robe, judge robe",
417
+ "401": "accordion, piano accordion, squeeze box",
418
+ "402": "acoustic guitar",
419
+ "403": "aircraft carrier, carrier, flattop, attack aircraft carrier",
420
+ "404": "airliner",
421
+ "405": "airship, dirigible",
422
+ "406": "altar",
423
+ "407": "ambulance",
424
+ "408": "amphibian, amphibious vehicle",
425
+ "409": "analog clock",
426
+ "410": "apiary, bee house",
427
+ "411": "apron",
428
+ "412": "ashcan, trash can, garbage can, wastebin, ash bin, ash-bin, ashbin, dustbin, trash barrel, trash bin",
429
+ "413": "assault rifle, assault gun",
430
+ "414": "backpack, back pack, knapsack, packsack, rucksack, haversack",
431
+ "415": "bakery, bakeshop, bakehouse",
432
+ "416": "balance beam, beam",
433
+ "417": "balloon",
434
+ "418": "ballpoint, ballpoint pen, ballpen, Biro",
435
+ "419": "Band Aid",
436
+ "420": "banjo",
437
+ "421": "bannister, banister, balustrade, balusters, handrail",
438
+ "422": "barbell",
439
+ "423": "barber chair",
440
+ "424": "barbershop",
441
+ "425": "barn",
442
+ "426": "barometer",
443
+ "427": "barrel, cask",
444
+ "428": "barrow, garden cart, lawn cart, wheelbarrow",
445
+ "429": "baseball",
446
+ "430": "basketball",
447
+ "431": "bassinet",
448
+ "432": "bassoon",
449
+ "433": "bathing cap, swimming cap",
450
+ "434": "bath towel",
451
+ "435": "bathtub, bathing tub, bath, tub",
452
+ "436": "beach wagon, station wagon, wagon, estate car, beach waggon, station waggon, waggon",
453
+ "437": "beacon, lighthouse, beacon light, pharos",
454
+ "438": "beaker",
455
+ "439": "bearskin, busby, shako",
456
+ "440": "beer bottle",
457
+ "441": "beer glass",
458
+ "442": "bell cote, bell cot",
459
+ "443": "bib",
460
+ "444": "bicycle-built-for-two, tandem bicycle, tandem",
461
+ "445": "bikini, two-piece",
462
+ "446": "binder, ring-binder",
463
+ "447": "binoculars, field glasses, opera glasses",
464
+ "448": "birdhouse",
465
+ "449": "boathouse",
466
+ "450": "bobsled, bobsleigh, bob",
467
+ "451": "bolo tie, bolo, bola tie, bola",
468
+ "452": "bonnet, poke bonnet",
469
+ "453": "bookcase",
470
+ "454": "bookshop, bookstore, bookstall",
471
+ "455": "bottlecap",
472
+ "456": "bow",
473
+ "457": "bow tie, bow-tie, bowtie",
474
+ "458": "brass, memorial tablet, plaque",
475
+ "459": "brassiere, bra, bandeau",
476
+ "460": "breakwater, groin, groyne, mole, bulwark, seawall, jetty",
477
+ "461": "breastplate, aegis, egis",
478
+ "462": "broom",
479
+ "463": "bucket, pail",
480
+ "464": "buckle",
481
+ "465": "bulletproof vest",
482
+ "466": "bullet train, bullet",
483
+ "467": "butcher shop, meat market",
484
+ "468": "cab, hack, taxi, taxicab",
485
+ "469": "caldron, cauldron",
486
+ "470": "candle, taper, wax light",
487
+ "471": "cannon",
488
+ "472": "canoe",
489
+ "473": "can opener, tin opener",
490
+ "474": "cardigan",
491
+ "475": "car mirror",
492
+ "476": "carousel, carrousel, merry-go-round, roundabout, whirligig",
493
+ "477": "carpenters kit, tool kit",
494
+ "478": "carton",
495
+ "479": "car wheel",
496
+ "480": "cash machine, cash dispenser, automated teller machine, automatic teller machine, automated teller, automatic teller, ATM",
497
+ "481": "cassette",
498
+ "482": "cassette player",
499
+ "483": "castle",
500
+ "484": "catamaran",
501
+ "485": "CD player",
502
+ "486": "cello, violoncello",
503
+ "487": "cellular telephone, cellular phone, cellphone, cell, mobile phone",
504
+ "488": "chain",
505
+ "489": "chainlink fence",
506
+ "490": "chain mail, ring mail, mail, chain armor, chain armour, ring armor, ring armour",
507
+ "491": "chain saw, chainsaw",
508
+ "492": "chest",
509
+ "493": "chiffonier, commode",
510
+ "494": "chime, bell, gong",
511
+ "495": "china cabinet, china closet",
512
+ "496": "Christmas stocking",
513
+ "497": "church, church building",
514
+ "498": "cinema, movie theater, movie theatre, movie house, picture palace",
515
+ "499": "cleaver, meat cleaver, chopper",
516
+ "500": "cliff dwelling",
517
+ "501": "cloak",
518
+ "502": "clog, geta, patten, sabot",
519
+ "503": "cocktail shaker",
520
+ "504": "coffee mug",
521
+ "505": "coffeepot",
522
+ "506": "coil, spiral, volute, whorl, helix",
523
+ "507": "combination lock",
524
+ "508": "computer keyboard, keypad",
525
+ "509": "confectionery, confectionary, candy store",
526
+ "510": "container ship, containership, container vessel",
527
+ "511": "convertible",
528
+ "512": "corkscrew, bottle screw",
529
+ "513": "cornet, horn, trumpet, trump",
530
+ "514": "cowboy boot",
531
+ "515": "cowboy hat, ten-gallon hat",
532
+ "516": "cradle",
533
+ "517": "crane",
534
+ "518": "crash helmet",
535
+ "519": "crate",
536
+ "520": "crib, cot",
537
+ "521": "Crock Pot",
538
+ "522": "croquet ball",
539
+ "523": "crutch",
540
+ "524": "cuirass",
541
+ "525": "dam, dike, dyke",
542
+ "526": "desk",
543
+ "527": "desktop computer",
544
+ "528": "dial telephone, dial phone",
545
+ "529": "diaper, nappy, napkin",
546
+ "530": "digital clock",
547
+ "531": "digital watch",
548
+ "532": "dining table, board",
549
+ "533": "dishrag, dishcloth",
550
+ "534": "dishwasher, dish washer, dishwashing machine",
551
+ "535": "disk brake, disc brake",
552
+ "536": "dock, dockage, docking facility",
553
+ "537": "dogsled, dog sled, dog sleigh",
554
+ "538": "dome",
555
+ "539": "doormat, welcome mat",
556
+ "540": "drilling platform, offshore rig",
557
+ "541": "drum, membranophone, tympan",
558
+ "542": "drumstick",
559
+ "543": "dumbbell",
560
+ "544": "Dutch oven",
561
+ "545": "electric fan, blower",
562
+ "546": "electric guitar",
563
+ "547": "electric locomotive",
564
+ "548": "entertainment center",
565
+ "549": "envelope",
566
+ "550": "espresso maker",
567
+ "551": "face powder",
568
+ "552": "feather boa, boa",
569
+ "553": "file, file cabinet, filing cabinet",
570
+ "554": "fireboat",
571
+ "555": "fire engine, fire truck",
572
+ "556": "fire screen, fireguard",
573
+ "557": "flagpole, flagstaff",
574
+ "558": "flute, transverse flute",
575
+ "559": "folding chair",
576
+ "560": "football helmet",
577
+ "561": "forklift",
578
+ "562": "fountain",
579
+ "563": "fountain pen",
580
+ "564": "four-poster",
581
+ "565": "freight car",
582
+ "566": "French horn, horn",
583
+ "567": "frying pan, frypan, skillet",
584
+ "568": "fur coat",
585
+ "569": "garbage truck, dustcart",
586
+ "570": "gasmask, respirator, gas helmet",
587
+ "571": "gas pump, gasoline pump, petrol pump, island dispenser",
588
+ "572": "goblet",
589
+ "573": "go-kart",
590
+ "574": "golf ball",
591
+ "575": "golfcart, golf cart",
592
+ "576": "gondola",
593
+ "577": "gong, tam-tam",
594
+ "578": "gown",
595
+ "579": "grand piano, grand",
596
+ "580": "greenhouse, nursery, glasshouse",
597
+ "581": "grille, radiator grille",
598
+ "582": "grocery store, grocery, food market, market",
599
+ "583": "guillotine",
600
+ "584": "hair slide",
601
+ "585": "hair spray",
602
+ "586": "half track",
603
+ "587": "hammer",
604
+ "588": "hamper",
605
+ "589": "hand blower, blow dryer, blow drier, hair dryer, hair drier",
606
+ "590": "hand-held computer, hand-held microcomputer",
607
+ "591": "handkerchief, hankie, hanky, hankey",
608
+ "592": "hard disc, hard disk, fixed disk",
609
+ "593": "harmonica, mouth organ, harp, mouth harp",
610
+ "594": "harp",
611
+ "595": "harvester, reaper",
612
+ "596": "hatchet",
613
+ "597": "holster",
614
+ "598": "home theater, home theatre",
615
+ "599": "honeycomb",
616
+ "600": "hook, claw",
617
+ "601": "hoopskirt, crinoline",
618
+ "602": "horizontal bar, high bar",
619
+ "603": "horse cart, horse-cart",
620
+ "604": "hourglass",
621
+ "605": "iPod",
622
+ "606": "iron, smoothing iron",
623
+ "607": "jack-o-lantern",
624
+ "608": "jean, blue jean, denim",
625
+ "609": "jeep, landrover",
626
+ "610": "jersey, T-shirt, tee shirt",
627
+ "611": "jigsaw puzzle",
628
+ "612": "jinrikisha, ricksha, rickshaw",
629
+ "613": "joystick",
630
+ "614": "kimono",
631
+ "615": "knee pad",
632
+ "616": "knot",
633
+ "617": "lab coat, laboratory coat",
634
+ "618": "ladle",
635
+ "619": "lampshade, lamp shade",
636
+ "620": "laptop, laptop computer",
637
+ "621": "lawn mower, mower",
638
+ "622": "lens cap, lens cover",
639
+ "623": "letter opener, paper knife, paperknife",
640
+ "624": "library",
641
+ "625": "lifeboat",
642
+ "626": "lighter, light, igniter, ignitor",
643
+ "627": "limousine, limo",
644
+ "628": "liner, ocean liner",
645
+ "629": "lipstick, lip rouge",
646
+ "630": "Loafer",
647
+ "631": "lotion",
648
+ "632": "loudspeaker, speaker, speaker unit, loudspeaker system, speaker system",
649
+ "633": "loupe, jewelers loupe",
650
+ "634": "lumbermill, sawmill",
651
+ "635": "magnetic compass",
652
+ "636": "mailbag, postbag",
653
+ "637": "mailbox, letter box",
654
+ "638": "maillot",
655
+ "639": "maillot, tank suit",
656
+ "640": "manhole cover",
657
+ "641": "maraca",
658
+ "642": "marimba, xylophone",
659
+ "643": "mask",
660
+ "644": "matchstick",
661
+ "645": "maypole",
662
+ "646": "maze, labyrinth",
663
+ "647": "measuring cup",
664
+ "648": "medicine chest, medicine cabinet",
665
+ "649": "megalith, megalithic structure",
666
+ "650": "microphone, mike",
667
+ "651": "microwave, microwave oven",
668
+ "652": "military uniform",
669
+ "653": "milk can",
670
+ "654": "minibus",
671
+ "655": "miniskirt, mini",
672
+ "656": "minivan",
673
+ "657": "missile",
674
+ "658": "mitten",
675
+ "659": "mixing bowl",
676
+ "660": "mobile home, manufactured home",
677
+ "661": "Model T",
678
+ "662": "modem",
679
+ "663": "monastery",
680
+ "664": "monitor",
681
+ "665": "moped",
682
+ "666": "mortar",
683
+ "667": "mortarboard",
684
+ "668": "mosque",
685
+ "669": "mosquito net",
686
+ "670": "motor scooter, scooter",
687
+ "671": "mountain bike, all-terrain bike, off-roader",
688
+ "672": "mountain tent",
689
+ "673": "mouse, computer mouse",
690
+ "674": "mousetrap",
691
+ "675": "moving van",
692
+ "676": "muzzle",
693
+ "677": "nail",
694
+ "678": "neck brace",
695
+ "679": "necklace",
696
+ "680": "nipple",
697
+ "681": "notebook, notebook computer",
698
+ "682": "obelisk",
699
+ "683": "oboe, hautboy, hautbois",
700
+ "684": "ocarina, sweet potato",
701
+ "685": "odometer, hodometer, mileometer, milometer",
702
+ "686": "oil filter",
703
+ "687": "organ, pipe organ",
704
+ "688": "oscilloscope, scope, cathode-ray oscilloscope, CRO",
705
+ "689": "overskirt",
706
+ "690": "oxcart",
707
+ "691": "oxygen mask",
708
+ "692": "packet",
709
+ "693": "paddle, boat paddle",
710
+ "694": "paddlewheel, paddle wheel",
711
+ "695": "padlock",
712
+ "696": "paintbrush",
713
+ "697": "pajama, pyjama, pjs, jammies",
714
+ "698": "palace",
715
+ "699": "panpipe, pandean pipe, syrinx",
716
+ "700": "paper towel",
717
+ "701": "parachute, chute",
718
+ "702": "parallel bars, bars",
719
+ "703": "park bench",
720
+ "704": "parking meter",
721
+ "705": "passenger car, coach, carriage",
722
+ "706": "patio, terrace",
723
+ "707": "pay-phone, pay-station",
724
+ "708": "pedestal, plinth, footstall",
725
+ "709": "pencil box, pencil case",
726
+ "710": "pencil sharpener",
727
+ "711": "perfume, essence",
728
+ "712": "Petri dish",
729
+ "713": "photocopier",
730
+ "714": "pick, plectrum, plectron",
731
+ "715": "pickelhaube",
732
+ "716": "picket fence, paling",
733
+ "717": "pickup, pickup truck",
734
+ "718": "pier",
735
+ "719": "piggy bank, penny bank",
736
+ "720": "pill bottle",
737
+ "721": "pillow",
738
+ "722": "ping-pong ball",
739
+ "723": "pinwheel",
740
+ "724": "pirate, pirate ship",
741
+ "725": "pitcher, ewer",
742
+ "726": "plane, carpenters plane, woodworking plane",
743
+ "727": "planetarium",
744
+ "728": "plastic bag",
745
+ "729": "plate rack",
746
+ "730": "plow, plough",
747
+ "731": "plunger, plumbers helper",
748
+ "732": "Polaroid camera, Polaroid Land camera",
749
+ "733": "pole",
750
+ "734": "police van, police wagon, paddy wagon, patrol wagon, wagon, black Maria",
751
+ "735": "poncho",
752
+ "736": "pool table, billiard table, snooker table",
753
+ "737": "pop bottle, soda bottle",
754
+ "738": "pot, flowerpot",
755
+ "739": "potters wheel",
756
+ "740": "power drill",
757
+ "741": "prayer rug, prayer mat",
758
+ "742": "printer",
759
+ "743": "prison, prison house",
760
+ "744": "projectile, missile",
761
+ "745": "projector",
762
+ "746": "puck, hockey puck",
763
+ "747": "punching bag, punch bag, punching ball, punchball",
764
+ "748": "purse",
765
+ "749": "quill, quill pen",
766
+ "750": "quilt, comforter, comfort, puff",
767
+ "751": "racer, race car, racing car",
768
+ "752": "racket, racquet",
769
+ "753": "radiator",
770
+ "754": "radio, wireless",
771
+ "755": "radio telescope, radio reflector",
772
+ "756": "rain barrel",
773
+ "757": "recreational vehicle, RV, R.V.",
774
+ "758": "reel",
775
+ "759": "reflex camera",
776
+ "760": "refrigerator, icebox",
777
+ "761": "remote control, remote",
778
+ "762": "restaurant, eating house, eating place, eatery",
779
+ "763": "revolver, six-gun, six-shooter",
780
+ "764": "rifle",
781
+ "765": "rocking chair, rocker",
782
+ "766": "rotisserie",
783
+ "767": "rubber eraser, rubber, pencil eraser",
784
+ "768": "rugby ball",
785
+ "769": "rule, ruler",
786
+ "770": "running shoe",
787
+ "771": "safe",
788
+ "772": "safety pin",
789
+ "773": "saltshaker, salt shaker",
790
+ "774": "sandal",
791
+ "775": "sarong",
792
+ "776": "sax, saxophone",
793
+ "777": "scabbard",
794
+ "778": "scale, weighing machine",
795
+ "779": "school bus",
796
+ "780": "schooner",
797
+ "781": "scoreboard",
798
+ "782": "screen, CRT screen",
799
+ "783": "screw",
800
+ "784": "screwdriver",
801
+ "785": "seat belt, seatbelt",
802
+ "786": "sewing machine",
803
+ "787": "shield, buckler",
804
+ "788": "shoe shop, shoe-shop, shoe store",
805
+ "789": "shoji",
806
+ "790": "shopping basket",
807
+ "791": "shopping cart",
808
+ "792": "shovel",
809
+ "793": "shower cap",
810
+ "794": "shower curtain",
811
+ "795": "ski",
812
+ "796": "ski mask",
813
+ "797": "sleeping bag",
814
+ "798": "slide rule, slipstick",
815
+ "799": "sliding door",
816
+ "800": "slot, one-armed bandit",
817
+ "801": "snorkel",
818
+ "802": "snowmobile",
819
+ "803": "snowplow, snowplough",
820
+ "804": "soap dispenser",
821
+ "805": "soccer ball",
822
+ "806": "sock",
823
+ "807": "solar dish, solar collector, solar furnace",
824
+ "808": "sombrero",
825
+ "809": "soup bowl",
826
+ "810": "space bar",
827
+ "811": "space heater",
828
+ "812": "space shuttle",
829
+ "813": "spatula",
830
+ "814": "speedboat",
831
+ "815": "spider web, spiders web",
832
+ "816": "spindle",
833
+ "817": "sports car, sport car",
834
+ "818": "spotlight, spot",
835
+ "819": "stage",
836
+ "820": "steam locomotive",
837
+ "821": "steel arch bridge",
838
+ "822": "steel drum",
839
+ "823": "stethoscope",
840
+ "824": "stole",
841
+ "825": "stone wall",
842
+ "826": "stopwatch, stop watch",
843
+ "827": "stove",
844
+ "828": "strainer",
845
+ "829": "streetcar, tram, tramcar, trolley, trolley car",
846
+ "830": "stretcher",
847
+ "831": "studio couch, day bed",
848
+ "832": "stupa, tope",
849
+ "833": "submarine, pigboat, sub, U-boat",
850
+ "834": "suit, suit of clothes",
851
+ "835": "sundial",
852
+ "836": "sunglass",
853
+ "837": "sunglasses, dark glasses, shades",
854
+ "838": "sunscreen, sunblock, sun blocker",
855
+ "839": "suspension bridge",
856
+ "840": "swab, swob, mop",
857
+ "841": "sweatshirt",
858
+ "842": "swimming trunks, bathing trunks",
859
+ "843": "swing",
860
+ "844": "switch, electric switch, electrical switch",
861
+ "845": "syringe",
862
+ "846": "table lamp",
863
+ "847": "tank, army tank, armored combat vehicle, armoured combat vehicle",
864
+ "848": "tape player",
865
+ "849": "teapot",
866
+ "850": "teddy, teddy bear",
867
+ "851": "television, television system",
868
+ "852": "tennis ball",
869
+ "853": "thatch, thatched roof",
870
+ "854": "theater curtain, theatre curtain",
871
+ "855": "thimble",
872
+ "856": "thresher, thrasher, threshing machine",
873
+ "857": "throne",
874
+ "858": "tile roof",
875
+ "859": "toaster",
876
+ "860": "tobacco shop, tobacconist shop, tobacconist",
877
+ "861": "toilet seat",
878
+ "862": "torch",
879
+ "863": "totem pole",
880
+ "864": "tow truck, tow car, wrecker",
881
+ "865": "toyshop",
882
+ "866": "tractor",
883
+ "867": "trailer truck, tractor trailer, trucking rig, rig, articulated lorry, semi",
884
+ "868": "tray",
885
+ "869": "trench coat",
886
+ "870": "tricycle, trike, velocipede",
887
+ "871": "trimaran",
888
+ "872": "tripod",
889
+ "873": "triumphal arch",
890
+ "874": "trolleybus, trolley coach, trackless trolley",
891
+ "875": "trombone",
892
+ "876": "tub, vat",
893
+ "877": "turnstile",
894
+ "878": "typewriter keyboard",
895
+ "879": "umbrella",
896
+ "880": "unicycle, monocycle",
897
+ "881": "upright, upright piano",
898
+ "882": "vacuum, vacuum cleaner",
899
+ "883": "vase",
900
+ "884": "vault",
901
+ "885": "velvet",
902
+ "886": "vending machine",
903
+ "887": "vestment",
904
+ "888": "viaduct",
905
+ "889": "violin, fiddle",
906
+ "890": "volleyball",
907
+ "891": "waffle iron",
908
+ "892": "wall clock",
909
+ "893": "wallet, billfold, notecase, pocketbook",
910
+ "894": "wardrobe, closet, press",
911
+ "895": "warplane, military plane",
912
+ "896": "washbasin, handbasin, washbowl, lavabo, wash-hand basin",
913
+ "897": "washer, automatic washer, washing machine",
914
+ "898": "water bottle",
915
+ "899": "water jug",
916
+ "900": "water tower",
917
+ "901": "whiskey jug",
918
+ "902": "whistle",
919
+ "903": "wig",
920
+ "904": "window screen",
921
+ "905": "window shade",
922
+ "906": "Windsor tie",
923
+ "907": "wine bottle",
924
+ "908": "wing",
925
+ "909": "wok",
926
+ "910": "wooden spoon",
927
+ "911": "wool, woolen, woollen",
928
+ "912": "worm fence, snake fence, snake-rail fence, Virginia fence",
929
+ "913": "wreck",
930
+ "914": "yawl",
931
+ "915": "yurt",
932
+ "916": "web site, website, internet site, site",
933
+ "917": "comic book",
934
+ "918": "crossword puzzle, crossword",
935
+ "919": "street sign",
936
+ "920": "traffic light, traffic signal, stoplight",
937
+ "921": "book jacket, dust cover, dust jacket, dust wrapper",
938
+ "922": "menu",
939
+ "923": "plate",
940
+ "924": "guacamole",
941
+ "925": "consomme",
942
+ "926": "hot pot, hotpot",
943
+ "927": "trifle",
944
+ "928": "ice cream, icecream",
945
+ "929": "ice lolly, lolly, lollipop, popsicle",
946
+ "930": "French loaf",
947
+ "931": "bagel, beigel",
948
+ "932": "pretzel",
949
+ "933": "cheeseburger",
950
+ "934": "hotdog, hot dog, red hot",
951
+ "935": "mashed potato",
952
+ "936": "head cabbage",
953
+ "937": "broccoli",
954
+ "938": "cauliflower",
955
+ "939": "zucchini, courgette",
956
+ "940": "spaghetti squash",
957
+ "941": "acorn squash",
958
+ "942": "butternut squash",
959
+ "943": "cucumber, cuke",
960
+ "944": "artichoke, globe artichoke",
961
+ "945": "bell pepper",
962
+ "946": "cardoon",
963
+ "947": "mushroom",
964
+ "948": "Granny Smith",
965
+ "949": "strawberry",
966
+ "950": "orange",
967
+ "951": "lemon",
968
+ "952": "fig",
969
+ "953": "pineapple, ananas",
970
+ "954": "banana",
971
+ "955": "jackfruit, jak, jack",
972
+ "956": "custard apple",
973
+ "957": "pomegranate",
974
+ "958": "hay",
975
+ "959": "carbonara",
976
+ "960": "chocolate sauce, chocolate syrup",
977
+ "961": "dough",
978
+ "962": "meat loaf, meatloaf",
979
+ "963": "pizza, pizza pie",
980
+ "964": "potpie",
981
+ "965": "burrito",
982
+ "966": "red wine",
983
+ "967": "espresso",
984
+ "968": "cup",
985
+ "969": "eggnog",
986
+ "970": "alp",
987
+ "971": "bubble",
988
+ "972": "cliff, drop, drop-off",
989
+ "973": "coral reef",
990
+ "974": "geyser",
991
+ "975": "lakeside, lakeshore",
992
+ "976": "promontory, headland, head, foreland",
993
+ "977": "sandbar, sand bar",
994
+ "978": "seashore, coast, seacoast, sea-coast",
995
+ "979": "valley, vale",
996
+ "980": "volcano",
997
+ "981": "ballplayer, baseball player",
998
+ "982": "groom, bridegroom",
999
+ "983": "scuba diver",
1000
+ "984": "rapeseed",
1001
+ "985": "daisy",
1002
+ "986": "yellow ladys slipper, yellow lady-slipper, Cypripedium calceolus, Cypripedium parviflorum",
1003
+ "987": "corn",
1004
+ "988": "acorn",
1005
+ "989": "hip, rose hip, rosehip",
1006
+ "990": "buckeye, horse chestnut, conker",
1007
+ "991": "coral fungus",
1008
+ "992": "agaric",
1009
+ "993": "gyromitra",
1010
+ "994": "stinkhorn, carrion fungus",
1011
+ "995": "earthstar",
1012
+ "996": "hen-of-the-woods, hen of the woods, Polyporus frondosus, Grifola frondosa",
1013
+ "997": "bolete",
1014
+ "998": "ear, spike, capitulum",
1015
+ "999": "toilet tissue, toilet paper, bathroom tissue"
1016
+ },
1017
+ "vae": [
1018
+ "diffusers",
1019
+ "AutoencoderKL"
1020
+ ]
1021
+ }
iMF-XL-SIM/pipeline.py ADDED
@@ -0,0 +1,342 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Hub custom pipeline: IMFPipeline.
2
+ Load with native Hugging Face diffusers and trust_remote_code=True.
3
+ """
4
+
5
+ from __future__ import annotations
6
+
7
+ import importlib.util
8
+ import inspect
9
+
10
+ import json
11
+ from pathlib import Path
12
+ from typing import Dict, List, Optional, Tuple, Union, Any
13
+
14
+ import torch
15
+ from diffusers.image_processor import VaeImageProcessor
16
+ from diffusers.pipelines.pipeline_utils import DiffusionPipeline, ImagePipelineOutput
17
+ from diffusers.utils.torch_utils import randn_tensor
18
+
19
+ # imeanflow / FD-Loss sd-vae latent statistics (stabilityai/sd-vae-ft-mse)
20
+ LATENT_CHANNEL_MEAN = (0.86488, -0.27787343, 0.21616915, 0.3738409)
21
+ LATENT_CHANNEL_STD = (4.85503674, 5.31922414, 3.93725398, 3.9870003)
22
+
23
+
24
+ def _load_bundled_vae(transformer) -> Optional[Any]:
25
+ transformer_path = getattr(transformer.config, "_name_or_path", None)
26
+ if not transformer_path:
27
+ return None
28
+ vae_dir = Path(transformer_path).resolve().parent / "vae"
29
+ if not vae_dir.is_dir() or not (vae_dir / "config.json").is_file():
30
+ return None
31
+ from diffusers import AutoencoderKL
32
+
33
+ vae_dtype = getattr(transformer, "dtype", torch.float32)
34
+ return AutoencoderKL.from_pretrained(str(vae_dir), torch_dtype=vae_dtype)
35
+
36
+
37
+ class IMFPipeline(DiffusionPipeline):
38
+
39
+ @staticmethod
40
+ def prepare_extra_step_kwargs(
41
+ scheduler,
42
+ generator=None,
43
+ eta: float | None = None,
44
+ ):
45
+ kwargs = {}
46
+ step_params = set(inspect.signature(scheduler.step).parameters.keys())
47
+ if "generator" in step_params:
48
+ kwargs["generator"] = generator
49
+ if eta is not None and "eta" in step_params:
50
+ kwargs["eta"] = eta
51
+ return kwargs
52
+
53
+ @staticmethod
54
+ def _prepare_generator(
55
+ generator: Optional[Union[torch.Generator, List[torch.Generator]]],
56
+ ) -> Optional[Union[torch.Generator, List[torch.Generator]]]:
57
+ if generator is None:
58
+ return None
59
+ if isinstance(generator, list):
60
+ for gen in generator:
61
+ if gen is not None:
62
+ gen.manual_seed(int(gen.initial_seed()))
63
+ return generator
64
+ generator.manual_seed(int(generator.initial_seed()))
65
+ return generator
66
+
67
+ @staticmethod
68
+ def _coerce_scheduler(scheduler, transformer) -> Any:
69
+ if scheduler is not None and not isinstance(scheduler, (list, tuple)):
70
+ return scheduler
71
+ variant_path = getattr(transformer.config, "_name_or_path", None)
72
+ if variant_path:
73
+ scheduler_dir = Path(variant_path).resolve().parent / "scheduler"
74
+ module_path = scheduler_dir / "scheduling_imf.py"
75
+ config_path = scheduler_dir / "scheduler_config.json"
76
+ if module_path.is_file() and config_path.is_file():
77
+ spec = importlib.util.spec_from_file_location("scheduling_imf", module_path)
78
+ if spec is not None and spec.loader is not None:
79
+ module = importlib.util.module_from_spec(spec)
80
+ spec.loader.exec_module(module)
81
+ return module.IMFScheduler.from_pretrained(str(scheduler_dir))
82
+ raise ValueError(
83
+ "IMFPipeline could not load IMFScheduler. Ensure the variant includes scheduler/scheduling_imf.py."
84
+ )
85
+
86
+ @staticmethod
87
+ def _resolve_inference_generator(
88
+ device: Union[str, torch.device],
89
+ generator: Optional[Union[torch.Generator, List[torch.Generator]]] = None,
90
+ ) -> Optional[Union[torch.Generator, List[torch.Generator]]]:
91
+ if generator is None:
92
+ return None
93
+ if isinstance(device, str):
94
+ device = torch.device(device)
95
+ device_type = device.type
96
+
97
+ def _relocate(gen: torch.Generator) -> torch.Generator:
98
+ if gen.device.type == device_type:
99
+ return gen
100
+ return torch.Generator(device=device_type).manual_seed(gen.initial_seed())
101
+
102
+ if isinstance(generator, list):
103
+ return [_relocate(g) for g in generator]
104
+ return _relocate(generator)
105
+
106
+ model_cpu_offload_seq = "transformer->vae"
107
+
108
+ def __init__(
109
+ self,
110
+ transformer,
111
+ scheduler,
112
+ vae=None,
113
+ id2label: Optional[Dict[Union[int, str], str]] = None,
114
+ ):
115
+ super().__init__()
116
+ scheduler = self._coerce_scheduler(scheduler, transformer)
117
+ if scheduler is None:
118
+ raise ValueError("IMFPipeline requires a scheduler loaded from the checkpoint.")
119
+ if isinstance(vae, (list, tuple)):
120
+ vae = None
121
+ if vae is None:
122
+ vae = _load_bundled_vae(transformer)
123
+ if vae is not None:
124
+ vae = vae.to(device=transformer.device, dtype=getattr(transformer, "dtype", torch.float32))
125
+ self.register_modules(transformer=transformer, scheduler=scheduler, vae=vae)
126
+ self._id2label = self._normalize_id2label(id2label)
127
+ self.labels = self._build_label2id(self._id2label)
128
+ self._labels_loaded_from_model_index = bool(self._id2label)
129
+ self.latent_channel_mean = torch.tensor(LATENT_CHANNEL_MEAN, dtype=torch.float32).view(1, 4, 1, 1)
130
+ self.latent_channel_std = torch.tensor(LATENT_CHANNEL_STD, dtype=torch.float32).view(1, 4, 1, 1)
131
+ vae_scale_factor = 8
132
+ if vae is not None:
133
+ vae_scale_factor = 2 ** (len(vae.config.block_out_channels) - 1)
134
+ self.vae_scale_factor = vae_scale_factor
135
+ self.image_processor = VaeImageProcessor(vae_scale_factor=self.vae_scale_factor)
136
+
137
+ def _ensure_labels_loaded(self) -> None:
138
+ if self._labels_loaded_from_model_index:
139
+ return
140
+ loaded = self._read_id2label_from_model_index(getattr(self.config, "_name_or_path", None))
141
+ if loaded:
142
+ self._id2label = loaded
143
+ self.labels = self._build_label2id(self._id2label)
144
+ self._labels_loaded_from_model_index = True
145
+
146
+ @staticmethod
147
+ def _normalize_id2label(id2label: Optional[Dict[Union[int, str], str]]) -> Dict[int, str]:
148
+ if not id2label:
149
+ return {}
150
+ return {int(key): value for key, value in id2label.items()}
151
+
152
+ @staticmethod
153
+ def _read_id2label_from_model_index(variant_path: Optional[str]) -> Dict[int, str]:
154
+ if not variant_path:
155
+ return {}
156
+ model_index_path = Path(variant_path).resolve() / "model_index.json"
157
+ if not model_index_path.exists():
158
+ return {}
159
+ raw = json.loads(model_index_path.read_text(encoding="utf-8"))
160
+ id2label = raw.get("id2label")
161
+ if not isinstance(id2label, dict):
162
+ return {}
163
+ return {int(key): value for key, value in id2label.items()}
164
+
165
+ @staticmethod
166
+ def _build_label2id(id2label: Dict[int, str]) -> Dict[str, int]:
167
+ label2id: Dict[str, int] = {}
168
+ for class_id, value in id2label.items():
169
+ for synonym in value.split(","):
170
+ synonym = synonym.strip()
171
+ if synonym:
172
+ label2id[synonym] = int(class_id)
173
+ return dict(sorted(label2id.items()))
174
+
175
+ @property
176
+ def id2label(self) -> Dict[int, str]:
177
+ self._ensure_labels_loaded()
178
+ return self._id2label
179
+
180
+ def get_label_ids(self, label: Union[str, List[str]]) -> List[int]:
181
+ self._ensure_labels_loaded()
182
+ if not self.labels:
183
+ raise ValueError("No labels loaded. Ensure `id2label` exists in model_index.json.")
184
+ if isinstance(label, str):
185
+ label = [label]
186
+ missing = [item for item in label if item not in self.labels]
187
+ if missing:
188
+ preview = ", ".join(list(self.labels.keys())[:8])
189
+ raise ValueError(f"Unknown label(s): {missing}. Example valid labels: {preview}, ...")
190
+ return [self.labels[item] for item in label]
191
+
192
+ def _normalize_class_labels(self, class_labels: Union[int, str, List[Union[int, str]]]) -> List[int]:
193
+ if isinstance(class_labels, int):
194
+ return [class_labels]
195
+ if isinstance(class_labels, str):
196
+ return self.get_label_ids(class_labels)
197
+ if class_labels and isinstance(class_labels[0], str):
198
+ return self.get_label_ids(class_labels)
199
+ return list(class_labels)
200
+
201
+ def _denormalize_latents(self, latents: torch.Tensor) -> torch.Tensor:
202
+ mean = self.latent_channel_mean.to(device=latents.device, dtype=latents.dtype)
203
+ std = self.latent_channel_std.to(device=latents.device, dtype=latents.dtype)
204
+ return latents * std + mean
205
+
206
+ def decode_latents(self, latents: torch.Tensor, output_type: str = "pil"):
207
+ if output_type == "latent":
208
+ return latents
209
+ if self.vae is None:
210
+ raise ValueError(
211
+ "Cannot decode latents without a VAE. Ensure model_index.json lists vae and the variant includes vae/."
212
+ )
213
+ vae_dtype = next(self.vae.parameters()).dtype
214
+ if next(self.vae.parameters()).device != latents.device:
215
+ self.vae.to(device=latents.device, dtype=vae_dtype)
216
+ latents = self._denormalize_latents(latents).to(dtype=vae_dtype)
217
+ image = self.vae.decode(latents).sample
218
+ return self.image_processor.postprocess(image, output_type=output_type)
219
+
220
+ def _predict_velocity_u(
221
+ self,
222
+ latents: torch.Tensor,
223
+ timestep: torch.Tensor,
224
+ time_gap: torch.Tensor,
225
+ class_labels: torch.Tensor,
226
+ class_null: torch.Tensor,
227
+ guidance_scale: float,
228
+ guidance_interval_start: float,
229
+ guidance_interval_end: float,
230
+ do_classifier_free_guidance: bool,
231
+ ) -> torch.Tensor:
232
+ if do_classifier_free_guidance:
233
+ latents_in = torch.cat([latents, latents], dim=0)
234
+ labels = torch.cat([class_labels, class_null], dim=0)
235
+ omega = torch.tensor([guidance_scale, 1.0], device=latents.device, dtype=latents.dtype)
236
+ t_min = torch.tensor([guidance_interval_start, 0.0], device=latents.device, dtype=latents.dtype)
237
+ t_max = torch.tensor([guidance_interval_end, 1.0], device=latents.device, dtype=latents.dtype)
238
+ batch = latents.shape[0]
239
+ timestep_in = timestep.reshape(1).repeat(2 * batch).to(dtype=latents.dtype)
240
+ time_gap_in = time_gap.reshape(1).repeat(2 * batch).to(dtype=latents.dtype)
241
+ omega = omega.repeat(batch)
242
+ t_min = t_min.repeat(batch)
243
+ t_max = t_max.repeat(batch)
244
+ else:
245
+ latents_in = latents
246
+ labels = class_labels
247
+ batch = latents.shape[0]
248
+ timestep_in = timestep.reshape(1).repeat(batch).to(dtype=latents.dtype)
249
+ time_gap_in = time_gap.reshape(1).repeat(batch).to(dtype=latents.dtype)
250
+ omega = torch.full((batch,), guidance_scale, device=latents.device, dtype=latents.dtype)
251
+ t_min = torch.full((batch,), guidance_interval_start, device=latents.device, dtype=latents.dtype)
252
+ t_max = torch.full((batch,), guidance_interval_end, device=latents.device, dtype=latents.dtype)
253
+
254
+ outputs = self.transformer(
255
+ sample=latents_in,
256
+ timestep=timestep_in,
257
+ class_labels=labels,
258
+ time_gap=time_gap_in,
259
+ guidance_scale=omega,
260
+ guidance_interval_start=t_min,
261
+ guidance_interval_end=t_max,
262
+ return_dict=True,
263
+ )
264
+ velocity_u = outputs.velocity_u
265
+
266
+ if not do_classifier_free_guidance:
267
+ return velocity_u
268
+
269
+ u_cond, u_uncond = velocity_u.chunk(2, dim=0)
270
+ return u_uncond + guidance_scale * (u_cond - u_uncond)
271
+
272
+ @torch.inference_mode()
273
+ def __call__(
274
+ self,
275
+ class_labels: Union[int, str, List[Union[int, str]]],
276
+ num_inference_steps: int = 1,
277
+ guidance_scale: float = 2.7,
278
+ guidance_interval_start: float = 0.1,
279
+ guidance_interval_end: float = 0.9,
280
+ generator: Optional[Union[torch.Generator, List[torch.Generator]]] = None,
281
+ latents: Optional[torch.Tensor] = None,
282
+ output_type: Optional[str] = "pil",
283
+ return_dict: bool = True,
284
+ ) -> Union[ImagePipelineOutput, Tuple]:
285
+ if output_type not in {"pil", "np", "pt", "latent"}:
286
+ raise ValueError("output_type must be one of: 'pil', 'np', 'pt', 'latent'.")
287
+
288
+ class_label_ids = self._normalize_class_labels(class_labels)
289
+ do_classifier_free_guidance = guidance_scale > 1.0
290
+ batch_size = len(class_label_ids)
291
+ generator = self._resolve_inference_generator(self._execution_device, generator)
292
+
293
+ image_size = int(self.transformer.config.sample_size)
294
+ channels = int(self.transformer.config.in_channels)
295
+ null_class_val = int(getattr(self.transformer.config, "num_classes", 1000))
296
+
297
+ generator = self._prepare_generator(generator)
298
+
299
+ if latents is None:
300
+ latents = randn_tensor(
301
+ shape=(batch_size, channels, image_size, image_size),
302
+ generator=generator,
303
+ device=self._execution_device,
304
+ dtype=self.transformer.dtype,
305
+ )
306
+
307
+ class_labels_t = torch.tensor(class_label_ids, device=latents.device, dtype=torch.long).reshape(-1)
308
+ class_labels_t = class_labels_t.clamp(0, null_class_val - 1)
309
+ class_null = torch.full_like(class_labels_t, null_class_val)
310
+
311
+ self.scheduler.set_timesteps(num_inference_steps, device=latents.device)
312
+ timesteps = self.scheduler.timesteps
313
+
314
+ extra_step_kwargs = self.prepare_extra_step_kwargs(self.scheduler, generator=generator)
315
+
316
+ for i in self.progress_bar(range(num_inference_steps)):
317
+ t = timesteps[i]
318
+ t_next = timesteps[i + 1]
319
+ time_gap = t - t_next
320
+ velocity_u = self._predict_velocity_u(
321
+ latents,
322
+ t,
323
+ time_gap,
324
+ class_labels_t,
325
+ class_null,
326
+ guidance_scale,
327
+ guidance_interval_start,
328
+ guidance_interval_end,
329
+ do_classifier_free_guidance,
330
+ )
331
+ latents = self.scheduler.step(velocity_u, t, latents, **extra_step_kwargs).prev_sample
332
+
333
+ images = self.decode_latents(latents, output_type=output_type)
334
+
335
+ self.maybe_free_model_hooks()
336
+
337
+ if not return_dict:
338
+ return (images,)
339
+ return ImagePipelineOutput(images=images)
340
+
341
+
342
+ IMFPipelineOutput = ImagePipelineOutput
iMF-XL-SIM/scheduler/scheduler_config.json ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ {
2
+ "_class_name": "IMFScheduler",
3
+ "_diffusers_version": "0.36.0",
4
+ "num_train_timesteps": 1000
5
+ }
iMF-XL-SIM/scheduler/scheduling_imf.py ADDED
@@ -0,0 +1,105 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from __future__ import annotations
2
+
3
+ from dataclasses import dataclass
4
+ from typing import List, Optional, Tuple, Union
5
+
6
+ import torch
7
+ from diffusers.configuration_utils import ConfigMixin, register_to_config
8
+ from diffusers.schedulers.scheduling_utils import SchedulerMixin
9
+ from diffusers.utils import BaseOutput
10
+ from diffusers.utils.torch_utils import randn_tensor
11
+
12
+
13
+ @dataclass
14
+ class IMFSchedulerOutput(BaseOutput):
15
+ prev_sample: torch.Tensor
16
+
17
+
18
+ class IMFScheduler(SchedulerMixin, ConfigMixin):
19
+ """Mean-flow scheduler with timesteps from 1.0 to 0.0."""
20
+
21
+ order = 1
22
+
23
+ @register_to_config
24
+ def __init__(
25
+ self,
26
+ num_train_timesteps: int = 1000,
27
+ shift: float = 1.0,
28
+ stochastic_sampling: bool = False,
29
+ ):
30
+ self.timesteps: Optional[torch.Tensor] = None
31
+ self.num_inference_steps: Optional[int] = None
32
+ self._step_index: Optional[int] = None
33
+
34
+ @property
35
+ def init_noise_sigma(self) -> float:
36
+ return 1.0
37
+
38
+ def set_timesteps(self, num_inference_steps: int, device: Union[str, torch.device, None] = None) -> None:
39
+ if num_inference_steps < 1:
40
+ raise ValueError("num_inference_steps must be >= 1.")
41
+ self.num_inference_steps = num_inference_steps
42
+ self.timesteps = torch.linspace(1.0, 0.0, num_inference_steps + 1, device=device, dtype=torch.float32)
43
+ self._step_index = 0
44
+
45
+ def scale_model_input(self, sample: torch.Tensor, timestep: Union[float, torch.Tensor]) -> torch.Tensor:
46
+ del timestep
47
+ return sample
48
+
49
+ def _resolve_step_index(self, timestep: Union[float, torch.Tensor, None]) -> int:
50
+ if self._step_index is not None:
51
+ return self._step_index
52
+ if self.timesteps is None:
53
+ raise ValueError("Call `set_timesteps` before `step`.")
54
+ if timestep is None:
55
+ return 0
56
+ t_value = float(timestep) if not isinstance(timestep, torch.Tensor) else float(timestep.flatten()[0])
57
+ matches = (self.timesteps - t_value).abs() < 1e-6
58
+ if matches.any():
59
+ return int(matches.nonzero(as_tuple=False)[0].item())
60
+ return 0
61
+
62
+ def step(
63
+ self,
64
+ model_output: torch.Tensor,
65
+ timestep: Union[float, torch.Tensor, None],
66
+ sample: torch.Tensor,
67
+ return_dict: bool = True,
68
+ generator: Optional[Union[torch.Generator, List[torch.Generator]]] = None,
69
+ ) -> Union[IMFSchedulerOutput, Tuple[torch.Tensor]]:
70
+ if self.timesteps is None:
71
+ raise ValueError("Call `set_timesteps` before `step`.")
72
+
73
+ step_index = self._resolve_step_index(timestep)
74
+ if step_index >= len(self.timesteps) - 1:
75
+ raise ValueError("Scheduler has already reached the final timestep.")
76
+
77
+ t = self.timesteps[step_index]
78
+ t_next = self.timesteps[step_index + 1]
79
+ dt = (t - t_next).to(dtype=sample.dtype, device=sample.device)
80
+ while dt.ndim < sample.ndim:
81
+ dt = dt.unsqueeze(-1)
82
+
83
+ if getattr(self.config, "stochastic_sampling", False):
84
+ t_bc = t.to(dtype=sample.dtype, device=sample.device)
85
+ while t_bc.ndim < sample.ndim:
86
+ t_bc = t_bc.unsqueeze(-1)
87
+ t_next_bc = t_next.to(dtype=sample.dtype, device=sample.device)
88
+ while t_next_bc.ndim < sample.ndim:
89
+ t_next_bc = t_next_bc.unsqueeze(-1)
90
+ x0 = sample - t_bc * model_output
91
+ noise = randn_tensor(
92
+ sample.shape,
93
+ generator=generator,
94
+ device=sample.device,
95
+ dtype=sample.dtype,
96
+ )
97
+ prev_sample = (1.0 - t_next_bc) * x0 + t_next_bc * noise
98
+ else:
99
+ prev_sample = sample - dt * model_output
100
+
101
+ self._step_index = step_index + 1
102
+
103
+ if not return_dict:
104
+ return (prev_sample,)
105
+ return IMFSchedulerOutput(prev_sample=prev_sample)
iMF-XL-SIM/transformer/config.json ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "_class_name": "IMFTransformer2DModel",
3
+ "_diffusers_version": "0.38.0",
4
+ "aux_head_depth": 8,
5
+ "depth": 48,
6
+ "embedding_init_constant": 1.0,
7
+ "eval_mode": true,
8
+ "hidden_size": 1024,
9
+ "in_channels": 4,
10
+ "mlp_ratio": 2.6666666666666665,
11
+ "model_type": "iMF-XL/2",
12
+ "num_attention_heads": 16,
13
+ "num_cfg_tokens": 4,
14
+ "num_class_embeds": null,
15
+ "num_class_tokens": 8,
16
+ "num_classes": 1000,
17
+ "num_interval_tokens": 2,
18
+ "num_time_tokens": 4,
19
+ "patch_size": 2,
20
+ "sample_size": 32,
21
+ "token_init_constant": 1.0,
22
+ "weight_init_constant": 0.32
23
+ }