Text-to-Image
Diffusers
Safetensors
English
image-generation
class-conditional
imagenet
pixelgen
flow-matching
pixel-space
jit
Instructions to use BiliSakura/PixelGen-diffusers with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Diffusers
How to use BiliSakura/PixelGen-diffusers with Diffusers:
pip install -U diffusers transformers accelerate
import torch from diffusers import DiffusionPipeline # switch to "mps" for apple devices pipe = DiffusionPipeline.from_pretrained("BiliSakura/PixelGen-diffusers", dtype=torch.bfloat16, device_map="cuda") prompt = "golden retriever" image = pipe(prompt).images[0] - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- Draw Things
- DiffusionBee
Upload folder using huggingface_hub
Browse files- .gitattributes +2 -0
- PixelGen-XL-16-256/demo.png +3 -0
- PixelGen-XL-16-256/model_index.json +1017 -0
- PixelGen-XL-16-256/pipeline.py +333 -0
- PixelGen-XL-16-256/scheduler/__pycache__/lagrange.cpython-312.pyc +0 -0
- PixelGen-XL-16-256/scheduler/__pycache__/scheduling_pixelgen.cpython-312.pyc +0 -0
- PixelGen-XL-16-256/scheduler/scheduler_config.json +10 -0
- PixelGen-XL-16-256/scheduler/scheduling_pixelgen.py +284 -0
- PixelGen-XL-16-256/transformer/__pycache__/transformer_jit.cpython-312.pyc +0 -0
- PixelGen-XL-16-256/transformer/config.json +21 -0
- PixelGen-XL-16-256/transformer/diffusion_pytorch_model.safetensors +3 -0
- PixelGen-XL-16-256/transformer/transformer_jit.py +684 -0
- PixelGen-XXL-16-512-t2i/model_index.json +23 -0
- PixelGen-XXL-16-512-t2i/pipeline.py +333 -0
- PixelGen-XXL-16-512-t2i/scheduler/__pycache__/scheduling_pixelgen.cpython-312.pyc +0 -0
- PixelGen-XXL-16-512-t2i/scheduler/scheduler_config.json +10 -0
- PixelGen-XXL-16-512-t2i/scheduler/scheduling_pixelgen.py +285 -0
- PixelGen-XXL-16-512-t2i/text_encoder/config.json +63 -0
- PixelGen-XXL-16-512-t2i/text_encoder/model.safetensors +3 -0
- PixelGen-XXL-16-512-t2i/tokenizer/chat_template.jinja +89 -0
- PixelGen-XXL-16-512-t2i/tokenizer/tokenizer.json +3 -0
- PixelGen-XXL-16-512-t2i/tokenizer/tokenizer_config.json +29 -0
- PixelGen-XXL-16-512-t2i/transformer/__pycache__/transformer_jit_t2i.cpython-312.pyc +0 -0
- PixelGen-XXL-16-512-t2i/transformer/config.json +16 -0
- PixelGen-XXL-16-512-t2i/transformer/diffusion_pytorch_model.safetensors +3 -0
- PixelGen-XXL-16-512-t2i/transformer/transformer_jit_t2i.py +390 -0
- README.md +193 -0
.gitattributes
CHANGED
|
@@ -33,3 +33,5 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
| 33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
|
|
|
| 33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
| 36 |
+
PixelGen-XL-16-256/demo.png filter=lfs diff=lfs merge=lfs -text
|
| 37 |
+
PixelGen-XXL-16-512-t2i/tokenizer/tokenizer.json filter=lfs diff=lfs merge=lfs -text
|
PixelGen-XL-16-256/demo.png
ADDED
|
|
Git LFS Details
|
PixelGen-XL-16-256/model_index.json
ADDED
|
@@ -0,0 +1,1017 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"_class_name": [
|
| 3 |
+
"pipeline",
|
| 4 |
+
"PixelGenC2IPipeline"
|
| 5 |
+
],
|
| 6 |
+
"_diffusers_version": "0.38.0",
|
| 7 |
+
"scheduler": [
|
| 8 |
+
"scheduling_pixelgen",
|
| 9 |
+
"PixelGenScheduler"
|
| 10 |
+
],
|
| 11 |
+
"transformer": [
|
| 12 |
+
"transformer_jit",
|
| 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 |
+
}
|
PixelGen-XL-16-256/pipeline.py
ADDED
|
@@ -0,0 +1,333 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Hub custom pipeline: PixelGenC2IPipeline.
|
| 2 |
+
Load with native Hugging Face diffusers and trust_remote_code=True.
|
| 3 |
+
"""
|
| 4 |
+
|
| 5 |
+
from __future__ import annotations
|
| 6 |
+
|
| 7 |
+
import importlib
|
| 8 |
+
import json
|
| 9 |
+
import sys
|
| 10 |
+
from pathlib import Path
|
| 11 |
+
from typing import Dict, List, Optional, Tuple, Union
|
| 12 |
+
|
| 13 |
+
import torch
|
| 14 |
+
from diffusers.pipelines.pipeline_utils import DiffusionPipeline, ImagePipelineOutput
|
| 15 |
+
from diffusers.utils.torch_utils import randn_tensor
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
RECOMMENDED_NOISE_BY_SIZE = {
|
| 19 |
+
256: 1.0,
|
| 20 |
+
512: 2.0,
|
| 21 |
+
}
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
class PixelGenC2IPipeline(DiffusionPipeline):
|
| 25 |
+
model_cpu_offload_seq = "transformer"
|
| 26 |
+
|
| 27 |
+
def __init__(
|
| 28 |
+
self,
|
| 29 |
+
transformer,
|
| 30 |
+
scheduler,
|
| 31 |
+
id2label: Optional[Dict[Union[int, str], str]] = None,
|
| 32 |
+
):
|
| 33 |
+
if isinstance(transformer, (list, tuple)):
|
| 34 |
+
transformer = self._load_transformer(Path(__file__).resolve().parent)
|
| 35 |
+
if isinstance(scheduler, (list, tuple)):
|
| 36 |
+
scheduler = self._load_scheduler(Path(__file__).resolve().parent)
|
| 37 |
+
|
| 38 |
+
super().__init__()
|
| 39 |
+
self.register_modules(transformer=transformer, scheduler=scheduler)
|
| 40 |
+
self._id2label = self._normalize_id2label(id2label)
|
| 41 |
+
self.labels = self._build_label2id(self._id2label)
|
| 42 |
+
self._labels_loaded_from_model_index = bool(self._id2label)
|
| 43 |
+
|
| 44 |
+
@staticmethod
|
| 45 |
+
def _resolve_variant_dir(pretrained_model_name_or_path: Optional[str]) -> Path:
|
| 46 |
+
repo_root = Path(__file__).resolve().parent
|
| 47 |
+
if pretrained_model_name_or_path in (None, "", "."):
|
| 48 |
+
return repo_root
|
| 49 |
+
variant = Path(pretrained_model_name_or_path)
|
| 50 |
+
if not variant.is_absolute():
|
| 51 |
+
candidate = (Path.cwd() / variant).resolve()
|
| 52 |
+
variant = candidate if candidate.exists() else (repo_root / variant).resolve()
|
| 53 |
+
return variant
|
| 54 |
+
|
| 55 |
+
@classmethod
|
| 56 |
+
def _load_transformer(cls, variant: Path, **model_kwargs):
|
| 57 |
+
comp_dir = variant / "transformer"
|
| 58 |
+
module_path = comp_dir / "transformer_jit.py"
|
| 59 |
+
if not module_path.exists():
|
| 60 |
+
raise FileNotFoundError(f"Missing transformer module at {module_path}")
|
| 61 |
+
comp_path = str(comp_dir)
|
| 62 |
+
if comp_path not in sys.path:
|
| 63 |
+
sys.path.insert(0, comp_path)
|
| 64 |
+
module = importlib.import_module("transformer_jit")
|
| 65 |
+
transformer_cls = getattr(module, "JiTTransformer2DModel")
|
| 66 |
+
return transformer_cls.from_pretrained(str(comp_dir), **model_kwargs)
|
| 67 |
+
|
| 68 |
+
@classmethod
|
| 69 |
+
def _load_scheduler(cls, variant: Path):
|
| 70 |
+
scheduler_dir = variant / "scheduler"
|
| 71 |
+
config_path = scheduler_dir / "scheduler_config.json"
|
| 72 |
+
if not config_path.exists():
|
| 73 |
+
raise FileNotFoundError(f"Missing scheduler config at {config_path}")
|
| 74 |
+
scheduler_path = str(scheduler_dir)
|
| 75 |
+
if scheduler_path not in sys.path:
|
| 76 |
+
sys.path.insert(0, scheduler_path)
|
| 77 |
+
module = importlib.import_module("scheduling_pixelgen")
|
| 78 |
+
scheduler_cls = getattr(module, "PixelGenScheduler")
|
| 79 |
+
return scheduler_cls.from_pretrained(str(scheduler_dir))
|
| 80 |
+
|
| 81 |
+
@classmethod
|
| 82 |
+
def from_pretrained(cls, pretrained_model_name_or_path: str, **kwargs):
|
| 83 |
+
variant = cls._resolve_variant_dir(pretrained_model_name_or_path)
|
| 84 |
+
model_kwargs = dict(kwargs)
|
| 85 |
+
transformer = cls._load_transformer(variant, **model_kwargs)
|
| 86 |
+
scheduler = cls._load_scheduler(variant)
|
| 87 |
+
id2label = cls._read_id2label_from_model_index(str(variant))
|
| 88 |
+
return cls(transformer=transformer, scheduler=scheduler, id2label=id2label)
|
| 89 |
+
|
| 90 |
+
@staticmethod
|
| 91 |
+
def _normalize_id2label(id2label: Optional[Dict[Union[int, str], str]]) -> Dict[int, str]:
|
| 92 |
+
if not id2label:
|
| 93 |
+
return {}
|
| 94 |
+
return {int(key): value for key, value in id2label.items()}
|
| 95 |
+
|
| 96 |
+
@staticmethod
|
| 97 |
+
def _read_id2label_from_model_index(variant_path: Optional[str]) -> Dict[int, str]:
|
| 98 |
+
if not variant_path:
|
| 99 |
+
return {}
|
| 100 |
+
model_index_path = Path(variant_path).resolve() / "model_index.json"
|
| 101 |
+
if not model_index_path.exists():
|
| 102 |
+
return {}
|
| 103 |
+
raw = json.loads(model_index_path.read_text(encoding="utf-8"))
|
| 104 |
+
id2label = raw.get("id2label")
|
| 105 |
+
if not isinstance(id2label, dict):
|
| 106 |
+
return {}
|
| 107 |
+
return {int(key): value for key, value in id2label.items()}
|
| 108 |
+
|
| 109 |
+
@staticmethod
|
| 110 |
+
def _build_label2id(id2label: Dict[int, str]) -> Dict[str, int]:
|
| 111 |
+
label2id: Dict[str, int] = {}
|
| 112 |
+
for class_id, value in id2label.items():
|
| 113 |
+
for synonym in value.split(","):
|
| 114 |
+
synonym = synonym.strip()
|
| 115 |
+
if synonym:
|
| 116 |
+
label2id[synonym] = int(class_id)
|
| 117 |
+
return dict(sorted(label2id.items()))
|
| 118 |
+
|
| 119 |
+
def _ensure_labels_loaded(self) -> None:
|
| 120 |
+
if self._labels_loaded_from_model_index:
|
| 121 |
+
return
|
| 122 |
+
loaded = self._read_id2label_from_model_index(getattr(self.config, "_name_or_path", None))
|
| 123 |
+
if loaded:
|
| 124 |
+
self._id2label = loaded
|
| 125 |
+
self.labels = self._build_label2id(self._id2label)
|
| 126 |
+
self._labels_loaded_from_model_index = True
|
| 127 |
+
|
| 128 |
+
@property
|
| 129 |
+
def id2label(self) -> Dict[int, str]:
|
| 130 |
+
self._ensure_labels_loaded()
|
| 131 |
+
return self._id2label
|
| 132 |
+
|
| 133 |
+
def get_label_ids(self, label: Union[str, List[str]]) -> List[int]:
|
| 134 |
+
self._ensure_labels_loaded()
|
| 135 |
+
if not self.labels:
|
| 136 |
+
raise ValueError("No English labels loaded. Ensure `id2label` exists in model_index.json.")
|
| 137 |
+
if isinstance(label, str):
|
| 138 |
+
label = [label]
|
| 139 |
+
missing = [item for item in label if item not in self.labels]
|
| 140 |
+
if missing:
|
| 141 |
+
preview = ", ".join(list(self.labels.keys())[:8])
|
| 142 |
+
raise ValueError(f"Unknown English label(s): {missing}. Example valid labels: {preview}, ...")
|
| 143 |
+
return [self.labels[item] for item in label]
|
| 144 |
+
|
| 145 |
+
def _normalize_class_labels(self, class_labels: Union[int, str, List[Union[int, str]]]) -> List[int]:
|
| 146 |
+
if isinstance(class_labels, int):
|
| 147 |
+
return [class_labels]
|
| 148 |
+
if isinstance(class_labels, str):
|
| 149 |
+
if class_labels in self.labels:
|
| 150 |
+
return [self.labels[class_labels]]
|
| 151 |
+
return [int(class_labels)]
|
| 152 |
+
if class_labels and isinstance(class_labels[0], str):
|
| 153 |
+
return self.get_label_ids(class_labels)
|
| 154 |
+
return list(class_labels)
|
| 155 |
+
|
| 156 |
+
def _predict_velocity(
|
| 157 |
+
self,
|
| 158 |
+
z_value: torch.Tensor,
|
| 159 |
+
t: torch.Tensor,
|
| 160 |
+
class_labels: torch.Tensor,
|
| 161 |
+
class_null: torch.Tensor,
|
| 162 |
+
do_classifier_free_guidance: bool,
|
| 163 |
+
guidance_scale: float,
|
| 164 |
+
guidance_interval_min: float,
|
| 165 |
+
guidance_interval_max: float,
|
| 166 |
+
) -> torch.Tensor:
|
| 167 |
+
if do_classifier_free_guidance:
|
| 168 |
+
z_in = torch.cat([z_value, z_value], dim=0)
|
| 169 |
+
labels = torch.cat([class_labels, class_null], dim=0)
|
| 170 |
+
else:
|
| 171 |
+
z_in = z_value
|
| 172 |
+
labels = class_labels
|
| 173 |
+
|
| 174 |
+
t_batch = t.flatten().expand(z_in.shape[0])
|
| 175 |
+
x_pred = self.transformer(z_in, timestep=t_batch, class_labels=labels).sample
|
| 176 |
+
v = self.scheduler.velocity_from_prediction(z_in, x_pred, t)
|
| 177 |
+
|
| 178 |
+
if not do_classifier_free_guidance:
|
| 179 |
+
return v
|
| 180 |
+
|
| 181 |
+
v_cond, v_uncond = v.chunk(2, dim=0)
|
| 182 |
+
interval_mask = t < guidance_interval_max
|
| 183 |
+
if guidance_interval_min != 0.0:
|
| 184 |
+
interval_mask = interval_mask & (t > guidance_interval_min)
|
| 185 |
+
scale = torch.where(
|
| 186 |
+
interval_mask,
|
| 187 |
+
torch.tensor(guidance_scale, device=z_value.device, dtype=z_value.dtype),
|
| 188 |
+
torch.tensor(1.0, device=z_value.device, dtype=z_value.dtype),
|
| 189 |
+
)
|
| 190 |
+
return v_uncond + scale * (v_cond - v_uncond)
|
| 191 |
+
|
| 192 |
+
def _run_sampler(
|
| 193 |
+
self,
|
| 194 |
+
latents: torch.Tensor,
|
| 195 |
+
class_labels: torch.Tensor,
|
| 196 |
+
class_null: torch.Tensor,
|
| 197 |
+
num_inference_steps: int,
|
| 198 |
+
do_classifier_free_guidance: bool,
|
| 199 |
+
guidance_scale: float,
|
| 200 |
+
guidance_interval_min: float,
|
| 201 |
+
guidance_interval_max: float,
|
| 202 |
+
sampling_method: str,
|
| 203 |
+
timeshift: float,
|
| 204 |
+
) -> torch.Tensor:
|
| 205 |
+
device = latents.device
|
| 206 |
+
self.scheduler.set_timesteps(
|
| 207 |
+
num_inference_steps, device=device, solver=sampling_method, timeshift=timeshift
|
| 208 |
+
)
|
| 209 |
+
timesteps = self.scheduler.timesteps
|
| 210 |
+
|
| 211 |
+
for i in self.progress_bar(range(num_inference_steps - 1)):
|
| 212 |
+
t = timesteps[i]
|
| 213 |
+
t_next = timesteps[i + 1]
|
| 214 |
+
v = self._predict_velocity(
|
| 215 |
+
latents,
|
| 216 |
+
t,
|
| 217 |
+
class_labels,
|
| 218 |
+
class_null,
|
| 219 |
+
do_classifier_free_guidance,
|
| 220 |
+
guidance_scale,
|
| 221 |
+
guidance_interval_min,
|
| 222 |
+
guidance_interval_max,
|
| 223 |
+
)
|
| 224 |
+
|
| 225 |
+
if sampling_method == "heun":
|
| 226 |
+
latents_euler = latents + (t_next - t) * v
|
| 227 |
+
v_next = self._predict_velocity(
|
| 228 |
+
latents_euler,
|
| 229 |
+
t_next,
|
| 230 |
+
class_labels,
|
| 231 |
+
class_null,
|
| 232 |
+
do_classifier_free_guidance,
|
| 233 |
+
guidance_scale,
|
| 234 |
+
guidance_interval_min,
|
| 235 |
+
guidance_interval_max,
|
| 236 |
+
)
|
| 237 |
+
latents = self.scheduler.step(v, t, latents, model_output_next=v_next).prev_sample
|
| 238 |
+
else:
|
| 239 |
+
latents = self.scheduler.step(v, t, latents).prev_sample
|
| 240 |
+
|
| 241 |
+
t = timesteps[-2]
|
| 242 |
+
t_next = timesteps[-1]
|
| 243 |
+
v = self._predict_velocity(
|
| 244 |
+
latents,
|
| 245 |
+
t,
|
| 246 |
+
class_labels,
|
| 247 |
+
class_null,
|
| 248 |
+
do_classifier_free_guidance,
|
| 249 |
+
guidance_scale,
|
| 250 |
+
guidance_interval_min,
|
| 251 |
+
guidance_interval_max,
|
| 252 |
+
)
|
| 253 |
+
return latents + (t_next - t) * v
|
| 254 |
+
|
| 255 |
+
@torch.inference_mode()
|
| 256 |
+
def __call__(
|
| 257 |
+
self,
|
| 258 |
+
class_labels: Union[int, str, List[Union[int, str]]],
|
| 259 |
+
guidance_scale: Optional[float] = None,
|
| 260 |
+
guidance_interval_min: float = 0.1,
|
| 261 |
+
guidance_interval_max: float = 0.9,
|
| 262 |
+
noise_scale: Optional[float] = None,
|
| 263 |
+
t_eps: Optional[float] = None,
|
| 264 |
+
sampling_method: Optional[str] = None,
|
| 265 |
+
timeshift: Optional[float] = None,
|
| 266 |
+
generator: Optional[Union[torch.Generator, List[torch.Generator]]] = None,
|
| 267 |
+
num_inference_steps: int = 50,
|
| 268 |
+
output_type: Optional[str] = "pil",
|
| 269 |
+
return_dict: bool = True,
|
| 270 |
+
) -> Union[ImagePipelineOutput, Tuple]:
|
| 271 |
+
solver = sampling_method or self.scheduler.config.solver
|
| 272 |
+
if solver not in {"heun", "euler"}:
|
| 273 |
+
raise ValueError("sampling_method must be one of: 'heun', 'euler'.")
|
| 274 |
+
if num_inference_steps < 2:
|
| 275 |
+
raise ValueError("num_inference_steps must be >= 2.")
|
| 276 |
+
if output_type not in {"pil", "np", "pt"}:
|
| 277 |
+
raise ValueError("output_type must be one of: 'pil', 'np', 'pt'.")
|
| 278 |
+
|
| 279 |
+
if t_eps is not None:
|
| 280 |
+
self.scheduler.register_to_config(t_eps=t_eps)
|
| 281 |
+
shift = timeshift if timeshift is not None else self.scheduler.config.timeshift
|
| 282 |
+
|
| 283 |
+
class_label_ids = self._normalize_class_labels(class_labels)
|
| 284 |
+
do_classifier_free_guidance = guidance_scale is not None and guidance_scale > 1.0
|
| 285 |
+
batch_size = len(class_label_ids)
|
| 286 |
+
image_size = int(self.transformer.config.sample_size)
|
| 287 |
+
channels = int(self.transformer.config.in_channels)
|
| 288 |
+
null_class_val = int(getattr(self.transformer.config, "num_classes", 1000))
|
| 289 |
+
|
| 290 |
+
if guidance_scale is None:
|
| 291 |
+
guidance_scale = 1.0
|
| 292 |
+
if noise_scale is None:
|
| 293 |
+
noise_scale = RECOMMENDED_NOISE_BY_SIZE.get(image_size, 1.0)
|
| 294 |
+
|
| 295 |
+
latents = randn_tensor(
|
| 296 |
+
shape=(batch_size, channels, image_size, image_size),
|
| 297 |
+
generator=generator,
|
| 298 |
+
device=self._execution_device,
|
| 299 |
+
dtype=self.transformer.dtype,
|
| 300 |
+
) * noise_scale
|
| 301 |
+
|
| 302 |
+
class_labels_t = torch.tensor(class_label_ids, device=self._execution_device, dtype=torch.long).reshape(-1)
|
| 303 |
+
class_labels_t = class_labels_t.clamp(0, null_class_val - 1)
|
| 304 |
+
class_null = torch.full_like(class_labels_t, null_class_val)
|
| 305 |
+
|
| 306 |
+
latents = self._run_sampler(
|
| 307 |
+
latents,
|
| 308 |
+
class_labels_t,
|
| 309 |
+
class_null,
|
| 310 |
+
num_inference_steps,
|
| 311 |
+
do_classifier_free_guidance,
|
| 312 |
+
guidance_scale,
|
| 313 |
+
guidance_interval_min,
|
| 314 |
+
guidance_interval_max,
|
| 315 |
+
solver,
|
| 316 |
+
shift,
|
| 317 |
+
)
|
| 318 |
+
|
| 319 |
+
images_pt = ((latents.float().clamp(-1, 1) + 1.0) / 2.0).cpu()
|
| 320 |
+
if output_type == "pt":
|
| 321 |
+
images = images_pt
|
| 322 |
+
elif output_type == "np":
|
| 323 |
+
images = images_pt.permute(0, 2, 3, 1).numpy()
|
| 324 |
+
else:
|
| 325 |
+
images = self.numpy_to_pil(images_pt.permute(0, 2, 3, 1).numpy())
|
| 326 |
+
|
| 327 |
+
self.maybe_free_model_hooks()
|
| 328 |
+
if not return_dict:
|
| 329 |
+
return (images,)
|
| 330 |
+
return ImagePipelineOutput(images=images)
|
| 331 |
+
|
| 332 |
+
|
| 333 |
+
PixelGenC2IPipelineOutput = ImagePipelineOutput
|
PixelGen-XL-16-256/scheduler/__pycache__/lagrange.cpython-312.pyc
ADDED
|
Binary file (6.13 kB). View file
|
|
|
PixelGen-XL-16-256/scheduler/__pycache__/scheduling_pixelgen.cpython-312.pyc
ADDED
|
Binary file (15.1 kB). View file
|
|
|
PixelGen-XL-16-256/scheduler/scheduler_config.json
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"_class_name": "PixelGenScheduler",
|
| 3 |
+
"_diffusers_version": "0.38.0",
|
| 4 |
+
"adam_lm_order": 2,
|
| 5 |
+
"last_step": null,
|
| 6 |
+
"num_train_timesteps": 1000,
|
| 7 |
+
"solver": "heun",
|
| 8 |
+
"t_eps": 0.05,
|
| 9 |
+
"timeshift": 2.0
|
| 10 |
+
}
|
PixelGen-XL-16-256/scheduler/scheduling_pixelgen.py
ADDED
|
@@ -0,0 +1,284 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
+
|
| 11 |
+
|
| 12 |
+
def lagrange_preint_o1(t1, v1, int_t_start, int_t_end):
|
| 13 |
+
int1 = int_t_end - int_t_start
|
| 14 |
+
return int1 * v1, (int1 / int1,)
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
def lagrange_preint_o2(t1, t2, v1, v2, int_t_start, int_t_end):
|
| 18 |
+
int1 = 0.5 / (t1 - t2) * ((int_t_end - t2) ** 2 - (int_t_start - t2) ** 2)
|
| 19 |
+
int2 = 0.5 / (t2 - t1) * ((int_t_end - t1) ** 2 - (int_t_start - t1) ** 2)
|
| 20 |
+
int_sum = int1 + int2
|
| 21 |
+
return int1 * v1 + int2 * v2, (int1 / int_sum, int2 / int_sum)
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
def lagrange_preint_o3(t1, t2, t3, v1, v2, v3, int_t_start, int_t_end):
|
| 25 |
+
int1_denom = (t1 - t2) * (t1 - t3)
|
| 26 |
+
int1_end = 1 / 3 * (int_t_end) ** 3 - 1 / 2 * (t2 + t3) * (int_t_end) ** 2 + (t2 * t3) * int_t_end
|
| 27 |
+
int1_start = 1 / 3 * (int_t_start) ** 3 - 1 / 2 * (t2 + t3) * (int_t_start) ** 2 + (t2 * t3) * int_t_start
|
| 28 |
+
int1 = (int1_end - int1_start) / int1_denom
|
| 29 |
+
int2_denom = (t2 - t1) * (t2 - t3)
|
| 30 |
+
int2_end = 1 / 3 * (int_t_end) ** 3 - 1 / 2 * (t1 + t3) * (int_t_end) ** 2 + (t1 * t3) * int_t_end
|
| 31 |
+
int2_start = 1 / 3 * (int_t_start) ** 3 - 1 / 2 * (t1 + t3) * (int_t_start) ** 2 + (t1 * t3) * int_t_start
|
| 32 |
+
int2 = (int2_end - int2_start) / int2_denom
|
| 33 |
+
int3_denom = (t3 - t1) * (t3 - t2)
|
| 34 |
+
int3_end = 1 / 3 * (int_t_end) ** 3 - 1 / 2 * (t1 + t2) * (int_t_end) ** 2 + (t1 * t2) * int_t_end
|
| 35 |
+
int3_start = 1 / 3 * (int_t_start) ** 3 - 1 / 2 * (t1 + t2) * (int_t_start) ** 2 + (t1 * t2) * int_t_start
|
| 36 |
+
int3 = (int3_end - int3_start) / int3_denom
|
| 37 |
+
int_sum = int1 + int2 + int3
|
| 38 |
+
return int1 * v1 + int2 * v2 + int3 * v3, (int1 / int_sum, int2 / int_sum, int3 / int_sum)
|
| 39 |
+
|
| 40 |
+
|
| 41 |
+
def larange_preint_o4(t1, t2, t3, t4, v1, v2, v3, v4, int_t_start, int_t_end):
|
| 42 |
+
int1_denom = (t1 - t2) * (t1 - t3) * (t1 - t4)
|
| 43 |
+
int1_end = (
|
| 44 |
+
1 / 4 * (int_t_end) ** 4
|
| 45 |
+
- 1 / 3 * (t2 + t3 + t4) * (int_t_end) ** 3
|
| 46 |
+
+ 1 / 2 * (t3 * t4 + t2 * t3 + t2 * t4) * int_t_end**2
|
| 47 |
+
- t2 * t3 * t4 * int_t_end
|
| 48 |
+
)
|
| 49 |
+
int1_start = (
|
| 50 |
+
1 / 4 * (int_t_start) ** 4
|
| 51 |
+
- 1 / 3 * (t2 + t3 + t4) * (int_t_start) ** 3
|
| 52 |
+
+ 1 / 2 * (t3 * t4 + t2 * t3 + t2 * t4) * int_t_start**2
|
| 53 |
+
- t2 * t3 * t4 * int_t_start
|
| 54 |
+
)
|
| 55 |
+
int1 = (int1_end - int1_start) / int1_denom
|
| 56 |
+
int2_denom = (t2 - t1) * (t2 - t3) * (t2 - t4)
|
| 57 |
+
int2_end = (
|
| 58 |
+
1 / 4 * (int_t_end) ** 4
|
| 59 |
+
- 1 / 3 * (t1 + t3 + t4) * (int_t_end) ** 3
|
| 60 |
+
+ 1 / 2 * (t3 * t4 + t1 * t3 + t1 * t4) * int_t_end**2
|
| 61 |
+
- t1 * t3 * t4 * int_t_end
|
| 62 |
+
)
|
| 63 |
+
int2_start = (
|
| 64 |
+
1 / 4 * (int_t_start) ** 4
|
| 65 |
+
- 1 / 3 * (t1 + t3 + t4) * (int_t_start) ** 3
|
| 66 |
+
+ 1 / 2 * (t3 * t4 + t1 * t3 + t1 * t4) * int_t_start**2
|
| 67 |
+
- t1 * t3 * t4 * int_t_start
|
| 68 |
+
)
|
| 69 |
+
int2 = (int2_end - int2_start) / int2_denom
|
| 70 |
+
int3_denom = (t3 - t1) * (t3 - t2) * (t3 - t4)
|
| 71 |
+
int3_end = (
|
| 72 |
+
1 / 4 * (int_t_end) ** 4
|
| 73 |
+
- 1 / 3 * (t1 + t2 + t4) * (int_t_end) ** 3
|
| 74 |
+
+ 1 / 2 * (t4 * t2 + t1 * t2 + t1 * t4) * int_t_end**2
|
| 75 |
+
- t1 * t2 * t4 * int_t_end
|
| 76 |
+
)
|
| 77 |
+
int3_start = (
|
| 78 |
+
1 / 4 * (int_t_start) ** 4
|
| 79 |
+
- 1 / 3 * (t1 + t2 + t4) * (int_t_start) ** 3
|
| 80 |
+
+ 1 / 2 * (t4 * t2 + t1 * t2 + t1 * t4) * int_t_start**2
|
| 81 |
+
- t1 * t2 * t4 * int_t_start
|
| 82 |
+
)
|
| 83 |
+
int3 = (int3_end - int3_start) / int3_denom
|
| 84 |
+
int4_denom = (t4 - t1) * (t4 - t2) * (t4 - t3)
|
| 85 |
+
int4_end = (
|
| 86 |
+
1 / 4 * (int_t_end) ** 4
|
| 87 |
+
- 1 / 3 * (t1 + t2 + t3) * (int_t_end) ** 3
|
| 88 |
+
+ 1 / 2 * (t3 * t2 + t1 * t2 + t1 * t3) * int_t_end**2
|
| 89 |
+
- t1 * t2 * t3 * int_t_end
|
| 90 |
+
)
|
| 91 |
+
int4_start = (
|
| 92 |
+
1 / 4 * (int_t_start) ** 4
|
| 93 |
+
- 1 / 3 * (t1 + t2 + t3) * (int_t_start) ** 3
|
| 94 |
+
+ 1 / 2 * (t3 * t2 + t1 * t2 + t1 * t3) * int_t_start**2
|
| 95 |
+
- t1 * t2 * t3 * int_t_start
|
| 96 |
+
)
|
| 97 |
+
int4 = (int4_end - int4_start) / int4_denom
|
| 98 |
+
int_sum = int1 + int2 + int3 + int4
|
| 99 |
+
return int1 * v1 + int2 * v2 + int3 * v3 + int4 * v4, (
|
| 100 |
+
int1 / int_sum,
|
| 101 |
+
int2 / int_sum,
|
| 102 |
+
int3 / int_sum,
|
| 103 |
+
int4 / int_sum,
|
| 104 |
+
)
|
| 105 |
+
|
| 106 |
+
|
| 107 |
+
def lagrange_preint(order, pre_vs, pre_ts, int_t_start, int_t_end):
|
| 108 |
+
order = min(order, len(pre_vs), len(pre_ts))
|
| 109 |
+
if order == 1:
|
| 110 |
+
return lagrange_preint_o1(pre_ts[-1], pre_vs[-1], int_t_start, int_t_end)
|
| 111 |
+
if order == 2:
|
| 112 |
+
return lagrange_preint_o2(pre_ts[-2], pre_ts[-1], pre_vs[-2], pre_vs[-1], int_t_start, int_t_end)
|
| 113 |
+
if order == 3:
|
| 114 |
+
return lagrange_preint_o3(
|
| 115 |
+
pre_ts[-3], pre_ts[-2], pre_ts[-1], pre_vs[-3], pre_vs[-2], pre_vs[-1], int_t_start, int_t_end
|
| 116 |
+
)
|
| 117 |
+
if order == 4:
|
| 118 |
+
return larange_preint_o4(
|
| 119 |
+
pre_ts[-4], pre_ts[-3], pre_ts[-2], pre_ts[-1],
|
| 120 |
+
pre_vs[-4], pre_vs[-3], pre_vs[-2], pre_vs[-1],
|
| 121 |
+
int_t_start, int_t_end,
|
| 122 |
+
)
|
| 123 |
+
raise ValueError("Invalid order")
|
| 124 |
+
|
| 125 |
+
|
| 126 |
+
@dataclass
|
| 127 |
+
class PixelGenSchedulerOutput(BaseOutput):
|
| 128 |
+
prev_sample: torch.Tensor
|
| 129 |
+
|
| 130 |
+
|
| 131 |
+
def shift_respace_fn(t: torch.Tensor, shift: float = 1.0) -> torch.Tensor:
|
| 132 |
+
return t / (t + (1 - t) * shift)
|
| 133 |
+
|
| 134 |
+
|
| 135 |
+
class PixelGenScheduler(SchedulerMixin, ConfigMixin):
|
| 136 |
+
"""Flow-matching scheduler for PixelGen with Euler, Heun, and Adam-LM solvers."""
|
| 137 |
+
|
| 138 |
+
order = 2
|
| 139 |
+
|
| 140 |
+
@register_to_config
|
| 141 |
+
def __init__(
|
| 142 |
+
self,
|
| 143 |
+
num_train_timesteps: int = 1000,
|
| 144 |
+
t_eps: float = 5e-2,
|
| 145 |
+
solver: str = "heun",
|
| 146 |
+
timeshift: float = 1.0,
|
| 147 |
+
adam_lm_order: int = 2,
|
| 148 |
+
last_step: float | None = None,
|
| 149 |
+
):
|
| 150 |
+
del num_train_timesteps
|
| 151 |
+
if solver not in {"heun", "euler", "adam_lm"}:
|
| 152 |
+
raise ValueError("solver must be one of: 'heun', 'euler', 'adam_lm'.")
|
| 153 |
+
self.timesteps: Optional[torch.Tensor] = None
|
| 154 |
+
self.timedeltas: Optional[torch.Tensor] = None
|
| 155 |
+
self.sigmas: Optional[List[float]] = None
|
| 156 |
+
self.num_inference_steps: Optional[int] = None
|
| 157 |
+
self._step_index: Optional[int] = None
|
| 158 |
+
self.solver_coeffs: Optional[list] = None
|
| 159 |
+
self._last_step = last_step
|
| 160 |
+
|
| 161 |
+
@property
|
| 162 |
+
def init_noise_sigma(self) -> float:
|
| 163 |
+
return 1.0
|
| 164 |
+
|
| 165 |
+
def set_timesteps(
|
| 166 |
+
self,
|
| 167 |
+
num_inference_steps: int,
|
| 168 |
+
device: Union[str, torch.device, None] = None,
|
| 169 |
+
solver: Optional[str] = None,
|
| 170 |
+
timeshift: Optional[float] = None,
|
| 171 |
+
adam_lm_order: Optional[int] = None,
|
| 172 |
+
) -> None:
|
| 173 |
+
if num_inference_steps < 2:
|
| 174 |
+
raise ValueError("num_inference_steps must be >= 2.")
|
| 175 |
+
|
| 176 |
+
if solver is not None:
|
| 177 |
+
self.register_to_config(solver=solver)
|
| 178 |
+
if timeshift is not None:
|
| 179 |
+
self.register_to_config(timeshift=timeshift)
|
| 180 |
+
if adam_lm_order is not None:
|
| 181 |
+
self.register_to_config(adam_lm_order=adam_lm_order)
|
| 182 |
+
|
| 183 |
+
last_step = self._last_step
|
| 184 |
+
if last_step is None:
|
| 185 |
+
last_step = 1.0 / num_inference_steps
|
| 186 |
+
|
| 187 |
+
self.num_inference_steps = num_inference_steps
|
| 188 |
+
timesteps = torch.linspace(0.0, 1.0 - last_step, num_inference_steps, device=device, dtype=torch.float32)
|
| 189 |
+
timesteps = torch.cat([timesteps, torch.tensor([1.0], device=device, dtype=torch.float32)], dim=0)
|
| 190 |
+
self.timesteps = shift_respace_fn(timesteps, self.config.timeshift)
|
| 191 |
+
self.timedeltas = self.timesteps[1:] - self.timesteps[:-1]
|
| 192 |
+
sigma_grid = torch.linspace(0.0, 1.0, num_inference_steps, device=device, dtype=torch.float32)
|
| 193 |
+
self.sigmas = (1.0 - sigma_grid).tolist()
|
| 194 |
+
self._step_index = 0
|
| 195 |
+
|
| 196 |
+
if self.config.solver == "adam_lm":
|
| 197 |
+
self._reparameterize_coeffs()
|
| 198 |
+
|
| 199 |
+
def _reparameterize_coeffs(self) -> None:
|
| 200 |
+
solver_coeffs = [[] for _ in range(self.num_inference_steps)]
|
| 201 |
+
for i in range(self.num_inference_steps):
|
| 202 |
+
pre_vs = [1.0] * (i + 1)
|
| 203 |
+
pre_ts = self.timesteps[: i + 1]
|
| 204 |
+
int_t_start = self.timesteps[i]
|
| 205 |
+
int_t_end = self.timesteps[i + 1]
|
| 206 |
+
order = min(self.config.adam_lm_order, i + 1)
|
| 207 |
+
_, coeffs = lagrange_preint(order, pre_vs, pre_ts.tolist(), float(int_t_start), float(int_t_end))
|
| 208 |
+
solver_coeffs[i] = coeffs
|
| 209 |
+
self.solver_coeffs = solver_coeffs
|
| 210 |
+
|
| 211 |
+
def scale_model_input(self, sample: torch.Tensor, timestep: Union[float, torch.Tensor]) -> torch.Tensor:
|
| 212 |
+
del timestep
|
| 213 |
+
return sample
|
| 214 |
+
|
| 215 |
+
def _resolve_step_index(self, timestep: Union[float, torch.Tensor, None]) -> int:
|
| 216 |
+
if self._step_index is not None:
|
| 217 |
+
return self._step_index
|
| 218 |
+
if self.timesteps is None:
|
| 219 |
+
raise ValueError("Call `set_timesteps` before `step`.")
|
| 220 |
+
if timestep is None:
|
| 221 |
+
return 0
|
| 222 |
+
t_value = float(timestep) if not isinstance(timestep, torch.Tensor) else float(timestep.flatten()[0])
|
| 223 |
+
matches = (self.timesteps - t_value).abs() < 1e-6
|
| 224 |
+
if matches.any():
|
| 225 |
+
return int(matches.nonzero(as_tuple=False)[0].item())
|
| 226 |
+
return 0
|
| 227 |
+
|
| 228 |
+
def step(
|
| 229 |
+
self,
|
| 230 |
+
model_output: torch.Tensor,
|
| 231 |
+
timestep: Union[float, torch.Tensor, None],
|
| 232 |
+
sample: torch.Tensor,
|
| 233 |
+
model_output_next: Optional[torch.Tensor] = None,
|
| 234 |
+
return_dict: bool = True,
|
| 235 |
+
) -> Union[PixelGenSchedulerOutput, Tuple[torch.Tensor]]:
|
| 236 |
+
if self.timesteps is None:
|
| 237 |
+
raise ValueError("Call `set_timesteps` before `step`.")
|
| 238 |
+
|
| 239 |
+
step_index = self._resolve_step_index(timestep)
|
| 240 |
+
if step_index >= len(self.timesteps) - 1:
|
| 241 |
+
raise ValueError("Scheduler has already reached the final timestep.")
|
| 242 |
+
|
| 243 |
+
t = self.timesteps[step_index]
|
| 244 |
+
t_next = self.timesteps[step_index + 1]
|
| 245 |
+
dt = t_next - t
|
| 246 |
+
|
| 247 |
+
if self.config.solver == "heun" and model_output_next is not None:
|
| 248 |
+
prev_sample = sample + dt * 0.5 * (model_output + model_output_next)
|
| 249 |
+
else:
|
| 250 |
+
prev_sample = sample + dt * model_output
|
| 251 |
+
|
| 252 |
+
self._step_index = step_index + 1
|
| 253 |
+
|
| 254 |
+
if not return_dict:
|
| 255 |
+
return (prev_sample,)
|
| 256 |
+
return PixelGenSchedulerOutput(prev_sample=prev_sample)
|
| 257 |
+
|
| 258 |
+
def velocity_from_prediction(
|
| 259 |
+
self,
|
| 260 |
+
sample: torch.Tensor,
|
| 261 |
+
x_pred: torch.Tensor,
|
| 262 |
+
timestep: Union[float, torch.Tensor],
|
| 263 |
+
) -> torch.Tensor:
|
| 264 |
+
t = torch.as_tensor(timestep, device=sample.device, dtype=sample.dtype)
|
| 265 |
+
while t.ndim < sample.ndim:
|
| 266 |
+
t = t.unsqueeze(-1)
|
| 267 |
+
denom = (1.0 - t).clamp_min(self.config.t_eps)
|
| 268 |
+
return (x_pred - sample) / denom
|
| 269 |
+
|
| 270 |
+
def apply_adam_lm_step(
|
| 271 |
+
self,
|
| 272 |
+
sample: torch.Tensor,
|
| 273 |
+
velocity_history: list[torch.Tensor],
|
| 274 |
+
step_index: int,
|
| 275 |
+
) -> torch.Tensor:
|
| 276 |
+
if self.solver_coeffs is None:
|
| 277 |
+
raise ValueError("Adam-LM coefficients not initialized. Call set_timesteps with solver='adam_lm'.")
|
| 278 |
+
coeffs = self.solver_coeffs[step_index]
|
| 279 |
+
order = len(coeffs)
|
| 280 |
+
v = torch.zeros_like(sample)
|
| 281 |
+
for j, coeff in enumerate(coeffs):
|
| 282 |
+
v = v + coeff * velocity_history[-order:][j]
|
| 283 |
+
dt = self.timedeltas[step_index]
|
| 284 |
+
return sample + dt * v
|
PixelGen-XL-16-256/transformer/__pycache__/transformer_jit.cpython-312.pyc
ADDED
|
Binary file (36.6 kB). View file
|
|
|
PixelGen-XL-16-256/transformer/config.json
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"_class_name": "JiTTransformer2DModel",
|
| 3 |
+
"_diffusers_version": "0.38.0",
|
| 4 |
+
"attention_dropout": 0.0,
|
| 5 |
+
"bottleneck_dim": 128,
|
| 6 |
+
"dropout": 0.1,
|
| 7 |
+
"hidden_size": 1152,
|
| 8 |
+
"in_channels": 3,
|
| 9 |
+
"in_context_len": 32,
|
| 10 |
+
"in_context_start": 8,
|
| 11 |
+
"mlp_ratio": 4.0,
|
| 12 |
+
"model_type": "PixelGen-XL/16",
|
| 13 |
+
"norm_eps": 1e-06,
|
| 14 |
+
"num_attention_heads": 16,
|
| 15 |
+
"num_class_embeds": null,
|
| 16 |
+
"num_classes": 1000,
|
| 17 |
+
"num_layers": 28,
|
| 18 |
+
"patch_size": 16,
|
| 19 |
+
"sample_size": 256,
|
| 20 |
+
"use_bottleneck": false
|
| 21 |
+
}
|
PixelGen-XL-16-256/transformer/diffusion_pytorch_model.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:9f4fe96addb58bafa66fa08e175cf2fb007cb93be5c6b69f5474902e605fd6ab
|
| 3 |
+
size 2708016440
|
PixelGen-XL-16-256/transformer/transformer_jit.py
ADDED
|
@@ -0,0 +1,684 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from __future__ import annotations
|
| 2 |
+
|
| 3 |
+
import argparse
|
| 4 |
+
import math
|
| 5 |
+
from collections.abc import Mapping
|
| 6 |
+
from typing import Dict, Literal, Tuple
|
| 7 |
+
|
| 8 |
+
import numpy as np
|
| 9 |
+
import torch
|
| 10 |
+
import torch.nn as nn
|
| 11 |
+
import torch.nn.functional as F
|
| 12 |
+
from diffusers.configuration_utils import ConfigMixin, register_to_config
|
| 13 |
+
from diffusers.models.modeling_outputs import Transformer2DModelOutput
|
| 14 |
+
from diffusers.models.modeling_utils import ModelMixin
|
| 15 |
+
from diffusers.models.normalization import RMSNorm
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
# Architecture presets aligned with the official JiT checkpoints.
|
| 19 |
+
JIT_PRESET_CONFIGS: Dict[str, Dict[str, object]] = {
|
| 20 |
+
"JiT-B/16": {
|
| 21 |
+
"sample_size": 256,
|
| 22 |
+
"patch_size": 16,
|
| 23 |
+
"hidden_size": 768,
|
| 24 |
+
"num_layers": 12,
|
| 25 |
+
"num_attention_heads": 12,
|
| 26 |
+
"bottleneck_dim": 128,
|
| 27 |
+
"in_context_len": 32,
|
| 28 |
+
"in_context_start": 4,
|
| 29 |
+
"attention_dropout": 0.0,
|
| 30 |
+
"dropout": 0.0,
|
| 31 |
+
},
|
| 32 |
+
"JiT-B/32": {
|
| 33 |
+
"sample_size": 512,
|
| 34 |
+
"patch_size": 32,
|
| 35 |
+
"hidden_size": 768,
|
| 36 |
+
"num_layers": 12,
|
| 37 |
+
"num_attention_heads": 12,
|
| 38 |
+
"bottleneck_dim": 128,
|
| 39 |
+
"in_context_len": 32,
|
| 40 |
+
"in_context_start": 4,
|
| 41 |
+
"attention_dropout": 0.0,
|
| 42 |
+
"dropout": 0.0,
|
| 43 |
+
},
|
| 44 |
+
"JiT-L/16": {
|
| 45 |
+
"sample_size": 256,
|
| 46 |
+
"patch_size": 16,
|
| 47 |
+
"hidden_size": 1024,
|
| 48 |
+
"num_layers": 24,
|
| 49 |
+
"num_attention_heads": 16,
|
| 50 |
+
"bottleneck_dim": 128,
|
| 51 |
+
"in_context_len": 32,
|
| 52 |
+
"in_context_start": 8,
|
| 53 |
+
"attention_dropout": 0.0,
|
| 54 |
+
"dropout": 0.0,
|
| 55 |
+
},
|
| 56 |
+
"JiT-L/32": {
|
| 57 |
+
"sample_size": 512,
|
| 58 |
+
"patch_size": 32,
|
| 59 |
+
"hidden_size": 1024,
|
| 60 |
+
"num_layers": 24,
|
| 61 |
+
"num_attention_heads": 16,
|
| 62 |
+
"bottleneck_dim": 128,
|
| 63 |
+
"in_context_len": 32,
|
| 64 |
+
"in_context_start": 8,
|
| 65 |
+
"attention_dropout": 0.0,
|
| 66 |
+
"dropout": 0.0,
|
| 67 |
+
},
|
| 68 |
+
"JiT-H/16": {
|
| 69 |
+
"sample_size": 256,
|
| 70 |
+
"patch_size": 16,
|
| 71 |
+
"hidden_size": 1280,
|
| 72 |
+
"num_layers": 32,
|
| 73 |
+
"num_attention_heads": 16,
|
| 74 |
+
"bottleneck_dim": 256,
|
| 75 |
+
"in_context_len": 32,
|
| 76 |
+
"in_context_start": 10,
|
| 77 |
+
"attention_dropout": 0.0,
|
| 78 |
+
"dropout": 0.2,
|
| 79 |
+
},
|
| 80 |
+
"JiT-H/32": {
|
| 81 |
+
"sample_size": 512,
|
| 82 |
+
"patch_size": 32,
|
| 83 |
+
"hidden_size": 1280,
|
| 84 |
+
"num_layers": 32,
|
| 85 |
+
"num_attention_heads": 16,
|
| 86 |
+
"bottleneck_dim": 256,
|
| 87 |
+
"in_context_len": 32,
|
| 88 |
+
"in_context_start": 10,
|
| 89 |
+
"attention_dropout": 0.0,
|
| 90 |
+
"dropout": 0.2,
|
| 91 |
+
},
|
| 92 |
+
"PixelGen-XL/16": {
|
| 93 |
+
"sample_size": 256,
|
| 94 |
+
"patch_size": 16,
|
| 95 |
+
"hidden_size": 1152,
|
| 96 |
+
"num_layers": 28,
|
| 97 |
+
"num_attention_heads": 16,
|
| 98 |
+
"bottleneck_dim": 128,
|
| 99 |
+
"in_context_len": 32,
|
| 100 |
+
"in_context_start": 8,
|
| 101 |
+
"attention_dropout": 0.0,
|
| 102 |
+
"dropout": 0.1,
|
| 103 |
+
"use_bottleneck": False,
|
| 104 |
+
},
|
| 105 |
+
"PixelGen-XXL/16": {
|
| 106 |
+
"sample_size": 512,
|
| 107 |
+
"patch_size": 16,
|
| 108 |
+
"hidden_size": 1536,
|
| 109 |
+
"num_layers": 16,
|
| 110 |
+
"num_attention_heads": 24,
|
| 111 |
+
"bottleneck_dim": 256,
|
| 112 |
+
"in_context_len": 0,
|
| 113 |
+
"in_context_start": 0,
|
| 114 |
+
"attention_dropout": 0.0,
|
| 115 |
+
"dropout": 0.0,
|
| 116 |
+
"use_bottleneck": False,
|
| 117 |
+
},
|
| 118 |
+
}
|
| 119 |
+
|
| 120 |
+
|
| 121 |
+
def remap_legacy_state_dict(state_dict: Dict[str, torch.Tensor]) -> Dict[str, torch.Tensor]:
|
| 122 |
+
"""Map wrapper/backbone keys from legacy Hub/Lightning checkpoints to native JiTTransformer2DModel keys."""
|
| 123 |
+
remapped: Dict[str, torch.Tensor] = {}
|
| 124 |
+
for key, value in state_dict.items():
|
| 125 |
+
new_key = key
|
| 126 |
+
for prefix in ("transformer.", "net.", "denoiser.", "ema_denoiser."):
|
| 127 |
+
if new_key.startswith(prefix):
|
| 128 |
+
new_key = new_key[len(prefix) :]
|
| 129 |
+
break
|
| 130 |
+
|
| 131 |
+
new_key = new_key.replace(".adaLN_modulation.1.", ".adaLN_modulation.")
|
| 132 |
+
if new_key.startswith("final_layer."):
|
| 133 |
+
new_key = new_key.replace("final_layer.norm_final", "norm_final")
|
| 134 |
+
new_key = new_key.replace("final_layer.linear", "linear_final")
|
| 135 |
+
new_key = new_key.replace("final_layer.adaLN_modulation", "adaLN_modulation_final")
|
| 136 |
+
|
| 137 |
+
remapped[new_key] = value
|
| 138 |
+
return remapped
|
| 139 |
+
|
| 140 |
+
|
| 141 |
+
def config_from_legacy(config: Dict[str, object]) -> Dict[str, object]:
|
| 142 |
+
"""Build native config kwargs from a legacy config.json dict."""
|
| 143 |
+
model_type = config.get("model_type") or config.get("model_name")
|
| 144 |
+
if model_type not in JIT_PRESET_CONFIGS:
|
| 145 |
+
raise ValueError(f"Unknown JiT preset '{model_type}'. Known: {list(JIT_PRESET_CONFIGS)}")
|
| 146 |
+
|
| 147 |
+
preset = dict(JIT_PRESET_CONFIGS[model_type])
|
| 148 |
+
preset["num_classes"] = int(config.get("num_class_embeds") or config.get("num_classes") or 1000)
|
| 149 |
+
|
| 150 |
+
if config.get("attention_dropout") is not None:
|
| 151 |
+
preset["attention_dropout"] = float(config["attention_dropout"])
|
| 152 |
+
if config.get("dropout") is not None:
|
| 153 |
+
preset["dropout"] = float(config["dropout"])
|
| 154 |
+
if config.get("sample_size") is not None:
|
| 155 |
+
preset["sample_size"] = int(config["sample_size"])
|
| 156 |
+
|
| 157 |
+
return preset
|
| 158 |
+
|
| 159 |
+
|
| 160 |
+
def broadcat(tensors, dim=-1):
|
| 161 |
+
num_tensors = len(tensors)
|
| 162 |
+
shape_lens = {len(t.shape) for t in tensors}
|
| 163 |
+
if len(shape_lens) != 1:
|
| 164 |
+
raise ValueError("tensors must all have the same number of dimensions")
|
| 165 |
+
shape_len = list(shape_lens)[0]
|
| 166 |
+
dim = (dim + shape_len) if dim < 0 else dim
|
| 167 |
+
dims = list(zip(*(list(t.shape) for t in tensors)))
|
| 168 |
+
expandable_dims = [(i, val) for i, val in enumerate(dims) if i != dim]
|
| 169 |
+
if not all(len(set(t[1])) <= 2 for t in expandable_dims):
|
| 170 |
+
raise ValueError("invalid dimensions for broadcastable concatenation")
|
| 171 |
+
max_dims = [(t[0], max(t[1])) for t in expandable_dims]
|
| 172 |
+
expanded_dims = [(t[0], (t[1],) * num_tensors) for t in max_dims]
|
| 173 |
+
expanded_dims.insert(dim, (dim, dims[dim]))
|
| 174 |
+
expandable_shapes = list(zip(*(t[1] for t in expanded_dims)))
|
| 175 |
+
tensors = [t[0].expand(*t[1]) for t in zip(tensors, expandable_shapes)]
|
| 176 |
+
return torch.cat(tensors, dim=dim)
|
| 177 |
+
|
| 178 |
+
|
| 179 |
+
def rotate_half(x):
|
| 180 |
+
x = x.view(*x.shape[:-1], x.shape[-1] // 2, 2)
|
| 181 |
+
x1, x2 = x.unbind(dim=-1)
|
| 182 |
+
x = torch.stack((-x2, x1), dim=-1)
|
| 183 |
+
return x.view(*x.shape[:-2], -1)
|
| 184 |
+
|
| 185 |
+
|
| 186 |
+
class JiTRotaryEmbedding(nn.Module):
|
| 187 |
+
def __init__(
|
| 188 |
+
self,
|
| 189 |
+
dim,
|
| 190 |
+
pt_seq_len=16,
|
| 191 |
+
ft_seq_len=None,
|
| 192 |
+
custom_freqs=None,
|
| 193 |
+
theta=10000,
|
| 194 |
+
num_cls_token=0,
|
| 195 |
+
):
|
| 196 |
+
super().__init__()
|
| 197 |
+
if custom_freqs is not None:
|
| 198 |
+
freqs = custom_freqs
|
| 199 |
+
else:
|
| 200 |
+
freqs = 1.0 / (theta ** (torch.arange(0, dim, 2)[: (dim // 2)].float() / dim))
|
| 201 |
+
|
| 202 |
+
if ft_seq_len is None:
|
| 203 |
+
ft_seq_len = pt_seq_len
|
| 204 |
+
t = torch.arange(ft_seq_len) / ft_seq_len * pt_seq_len
|
| 205 |
+
|
| 206 |
+
freqs = torch.einsum("..., f -> ... f", t, freqs)
|
| 207 |
+
freqs = freqs.repeat_interleave(2, dim=-1)
|
| 208 |
+
freqs = broadcat((freqs[:, None, :], freqs[None, :, :]), dim=-1)
|
| 209 |
+
|
| 210 |
+
if num_cls_token > 0:
|
| 211 |
+
freqs_flat = freqs.view(-1, freqs.shape[-1])
|
| 212 |
+
cos_img = freqs_flat.cos()
|
| 213 |
+
sin_img = freqs_flat.sin()
|
| 214 |
+
_, dim_freq = cos_img.shape
|
| 215 |
+
cos_pad = torch.ones(num_cls_token, dim_freq, dtype=cos_img.dtype)
|
| 216 |
+
sin_pad = torch.zeros(num_cls_token, dim_freq, dtype=sin_img.dtype)
|
| 217 |
+
self.register_buffer("freqs_cos", torch.cat([cos_pad, cos_img], dim=0), persistent=False)
|
| 218 |
+
self.register_buffer("freqs_sin", torch.cat([sin_pad, sin_img], dim=0), persistent=False)
|
| 219 |
+
else:
|
| 220 |
+
self.register_buffer("freqs_cos", freqs.cos().view(-1, freqs.shape[-1]), persistent=False)
|
| 221 |
+
self.register_buffer("freqs_sin", freqs.sin().view(-1, freqs.shape[-1]), persistent=False)
|
| 222 |
+
|
| 223 |
+
def forward(self, tensor):
|
| 224 |
+
seq_len = tensor.shape[1]
|
| 225 |
+
freqs_cos = self.freqs_cos[:seq_len].to(device=tensor.device, dtype=tensor.dtype)
|
| 226 |
+
freqs_sin = self.freqs_sin[:seq_len].to(device=tensor.device, dtype=tensor.dtype)
|
| 227 |
+
return tensor * freqs_cos[:, None, :] + rotate_half(tensor) * freqs_sin[:, None, :]
|
| 228 |
+
|
| 229 |
+
|
| 230 |
+
def modulate(x, shift, scale):
|
| 231 |
+
return x * (1 + scale.unsqueeze(1)) + shift.unsqueeze(1)
|
| 232 |
+
|
| 233 |
+
|
| 234 |
+
class JiTPatchEmbed(nn.Module):
|
| 235 |
+
def __init__(
|
| 236 |
+
self,
|
| 237 |
+
img_size=224,
|
| 238 |
+
patch_size=16,
|
| 239 |
+
in_chans=3,
|
| 240 |
+
pca_dim=768,
|
| 241 |
+
embed_dim=768,
|
| 242 |
+
bias=True,
|
| 243 |
+
use_bottleneck=True,
|
| 244 |
+
):
|
| 245 |
+
super().__init__()
|
| 246 |
+
img_size = (img_size, img_size)
|
| 247 |
+
patch_size = (patch_size, patch_size)
|
| 248 |
+
self.img_size = img_size
|
| 249 |
+
self.patch_size = patch_size
|
| 250 |
+
self.num_patches = (img_size[1] // patch_size[1]) * (img_size[0] // patch_size[0])
|
| 251 |
+
self.use_bottleneck = use_bottleneck
|
| 252 |
+
if use_bottleneck:
|
| 253 |
+
self.proj1 = nn.Conv2d(in_chans, pca_dim, kernel_size=patch_size, stride=patch_size, bias=False)
|
| 254 |
+
self.proj2 = nn.Conv2d(pca_dim, embed_dim, kernel_size=1, stride=1, bias=bias)
|
| 255 |
+
else:
|
| 256 |
+
self.proj1 = nn.Conv2d(in_chans, embed_dim, kernel_size=patch_size, stride=patch_size, bias=bias)
|
| 257 |
+
self.proj2 = None
|
| 258 |
+
|
| 259 |
+
def forward(self, x):
|
| 260 |
+
if self.use_bottleneck:
|
| 261 |
+
return self.proj2(self.proj1(x)).flatten(2).transpose(1, 2)
|
| 262 |
+
return self.proj1(x).flatten(2).transpose(1, 2)
|
| 263 |
+
|
| 264 |
+
|
| 265 |
+
class JiTTimestepEmbedder(nn.Module):
|
| 266 |
+
def __init__(self, hidden_size, frequency_embedding_size=256):
|
| 267 |
+
super().__init__()
|
| 268 |
+
self.mlp = nn.Sequential(
|
| 269 |
+
nn.Linear(frequency_embedding_size, hidden_size, bias=True),
|
| 270 |
+
nn.SiLU(),
|
| 271 |
+
nn.Linear(hidden_size, hidden_size, bias=True),
|
| 272 |
+
)
|
| 273 |
+
self.frequency_embedding_size = frequency_embedding_size
|
| 274 |
+
|
| 275 |
+
@staticmethod
|
| 276 |
+
def timestep_embedding(t, dim, max_period=10000):
|
| 277 |
+
half = dim // 2
|
| 278 |
+
freqs = torch.exp(-math.log(max_period) * torch.arange(start=0, end=half, dtype=torch.float32) / half).to(
|
| 279 |
+
device=t.device
|
| 280 |
+
)
|
| 281 |
+
args = t[:, None].float() * freqs[None]
|
| 282 |
+
embedding = torch.cat([torch.cos(args), torch.sin(args)], dim=-1)
|
| 283 |
+
if dim % 2:
|
| 284 |
+
embedding = torch.cat([embedding, torch.zeros_like(embedding[:, :1])], dim=-1)
|
| 285 |
+
return embedding
|
| 286 |
+
|
| 287 |
+
def forward(self, t, dtype=None):
|
| 288 |
+
t_freq = self.timestep_embedding(t, self.frequency_embedding_size)
|
| 289 |
+
if dtype is not None:
|
| 290 |
+
t_freq = t_freq.to(dtype=dtype)
|
| 291 |
+
return self.mlp(t_freq)
|
| 292 |
+
|
| 293 |
+
|
| 294 |
+
class JiTLabelEmbedder(nn.Module):
|
| 295 |
+
def __init__(self, num_classes, hidden_size):
|
| 296 |
+
super().__init__()
|
| 297 |
+
self.embedding_table = nn.Embedding(num_classes + 1, hidden_size)
|
| 298 |
+
self.num_classes = num_classes
|
| 299 |
+
|
| 300 |
+
def forward(self, labels):
|
| 301 |
+
return self.embedding_table(labels)
|
| 302 |
+
|
| 303 |
+
|
| 304 |
+
class JiTAttention(nn.Module):
|
| 305 |
+
def __init__(self, dim, num_heads=8, qkv_bias=True, qk_norm=True, attn_drop=0.0, proj_drop=0.0, eps=1e-6):
|
| 306 |
+
super().__init__()
|
| 307 |
+
self.num_heads = num_heads
|
| 308 |
+
head_dim = dim // num_heads
|
| 309 |
+
self.q_norm = RMSNorm(head_dim, eps=eps) if qk_norm else nn.Identity()
|
| 310 |
+
self.k_norm = RMSNorm(head_dim, eps=eps) if qk_norm else nn.Identity()
|
| 311 |
+
self.qkv = nn.Linear(dim, dim * 3, bias=qkv_bias)
|
| 312 |
+
self.attn_drop = attn_drop
|
| 313 |
+
self.proj = nn.Linear(dim, dim)
|
| 314 |
+
self.proj_drop = nn.Dropout(proj_drop)
|
| 315 |
+
|
| 316 |
+
def forward(self, x, rope=None):
|
| 317 |
+
batch_size, num_tokens, channels = x.shape
|
| 318 |
+
qkv = self.qkv(x).reshape(batch_size, num_tokens, 3, self.num_heads, channels // self.num_heads).permute(2, 0, 3, 1, 4)
|
| 319 |
+
q, k, v = qkv[0], qkv[1], qkv[2]
|
| 320 |
+
q = self.q_norm(q)
|
| 321 |
+
k = self.k_norm(k)
|
| 322 |
+
if rope is not None:
|
| 323 |
+
q = q.transpose(1, 2)
|
| 324 |
+
k = k.transpose(1, 2)
|
| 325 |
+
q = rope(q)
|
| 326 |
+
k = rope(k)
|
| 327 |
+
q = q.transpose(1, 2)
|
| 328 |
+
k = k.transpose(1, 2)
|
| 329 |
+
|
| 330 |
+
dropout_p = self.attn_drop if self.training else 0.0
|
| 331 |
+
x = F.scaled_dot_product_attention(q, k, v, dropout_p=dropout_p)
|
| 332 |
+
x = x.transpose(1, 2).reshape(batch_size, num_tokens, channels)
|
| 333 |
+
x = self.proj(x)
|
| 334 |
+
x = self.proj_drop(x)
|
| 335 |
+
return x
|
| 336 |
+
|
| 337 |
+
|
| 338 |
+
class JiTSwiGLUFFN(nn.Module):
|
| 339 |
+
def __init__(self, dim: int, hidden_dim: int, drop=0.0, bias=True) -> None:
|
| 340 |
+
super().__init__()
|
| 341 |
+
hidden_dim = int(hidden_dim * 2 / 3)
|
| 342 |
+
self.w12 = nn.Linear(dim, 2 * hidden_dim, bias=bias)
|
| 343 |
+
self.w3 = nn.Linear(hidden_dim, dim, bias=bias)
|
| 344 |
+
self.ffn_dropout = nn.Dropout(drop)
|
| 345 |
+
|
| 346 |
+
def forward(self, x):
|
| 347 |
+
x12 = self.w12(x)
|
| 348 |
+
x1, x2 = x12.chunk(2, dim=-1)
|
| 349 |
+
hidden = F.silu(x1) * x2
|
| 350 |
+
return self.w3(self.ffn_dropout(hidden))
|
| 351 |
+
|
| 352 |
+
|
| 353 |
+
class JiTBlock(nn.Module):
|
| 354 |
+
def __init__(self, hidden_size, num_heads, mlp_ratio=4.0, attn_drop=0.0, proj_drop=0.0, eps=1e-6):
|
| 355 |
+
super().__init__()
|
| 356 |
+
self.norm1 = RMSNorm(hidden_size, eps=eps)
|
| 357 |
+
self.attn = JiTAttention(
|
| 358 |
+
hidden_size,
|
| 359 |
+
num_heads=num_heads,
|
| 360 |
+
qkv_bias=True,
|
| 361 |
+
qk_norm=True,
|
| 362 |
+
attn_drop=attn_drop,
|
| 363 |
+
proj_drop=proj_drop,
|
| 364 |
+
eps=eps,
|
| 365 |
+
)
|
| 366 |
+
self.norm2 = RMSNorm(hidden_size, eps=eps)
|
| 367 |
+
self.mlp = JiTSwiGLUFFN(hidden_size, int(hidden_size * mlp_ratio), drop=proj_drop)
|
| 368 |
+
self.act = nn.SiLU()
|
| 369 |
+
self.adaLN_modulation = nn.Linear(hidden_size, 6 * hidden_size, bias=True)
|
| 370 |
+
|
| 371 |
+
def forward(self, x, c, feat_rope=None):
|
| 372 |
+
c = self.act(c)
|
| 373 |
+
shift_msa, scale_msa, gate_msa, shift_mlp, scale_mlp, gate_mlp = self.adaLN_modulation(c).chunk(6, dim=-1)
|
| 374 |
+
x = x + gate_msa.unsqueeze(1) * self.attn(modulate(self.norm1(x), shift_msa, scale_msa), rope=feat_rope)
|
| 375 |
+
x = x + gate_mlp.unsqueeze(1) * self.mlp(modulate(self.norm2(x), shift_mlp, scale_mlp))
|
| 376 |
+
return x
|
| 377 |
+
|
| 378 |
+
|
| 379 |
+
def get_2d_sincos_pos_embed(embed_dim, grid_size, cls_token=False, extra_tokens=0):
|
| 380 |
+
grid_h = np.arange(grid_size, dtype=np.float32)
|
| 381 |
+
grid_w = np.arange(grid_size, dtype=np.float32)
|
| 382 |
+
grid = np.meshgrid(grid_w, grid_h)
|
| 383 |
+
grid = np.stack(grid, axis=0)
|
| 384 |
+
grid = grid.reshape([2, 1, grid_size, grid_size])
|
| 385 |
+
pos_embed = get_2d_sincos_pos_embed_from_grid(embed_dim, grid)
|
| 386 |
+
if cls_token and extra_tokens > 0:
|
| 387 |
+
pos_embed = np.concatenate([np.zeros([extra_tokens, embed_dim]), pos_embed], axis=0)
|
| 388 |
+
return pos_embed
|
| 389 |
+
|
| 390 |
+
|
| 391 |
+
def get_2d_sincos_pos_embed_from_grid(embed_dim, grid):
|
| 392 |
+
if embed_dim % 2 != 0:
|
| 393 |
+
raise ValueError(f"embed_dim must be divisible by 2, but got {embed_dim}")
|
| 394 |
+
emb_h = get_1d_sincos_pos_embed_from_grid(embed_dim // 2, grid[0])
|
| 395 |
+
emb_w = get_1d_sincos_pos_embed_from_grid(embed_dim // 2, grid[1])
|
| 396 |
+
return np.concatenate([emb_h, emb_w], axis=1)
|
| 397 |
+
|
| 398 |
+
|
| 399 |
+
def get_1d_sincos_pos_embed_from_grid(embed_dim, pos):
|
| 400 |
+
if embed_dim % 2 != 0:
|
| 401 |
+
raise ValueError(f"embed_dim must be divisible by 2, but got {embed_dim}")
|
| 402 |
+
omega = np.arange(embed_dim // 2, dtype=np.float64)
|
| 403 |
+
omega /= embed_dim / 2.0
|
| 404 |
+
omega = 1.0 / 10000**omega
|
| 405 |
+
pos = pos.reshape(-1)
|
| 406 |
+
out = np.einsum("m,d->md", pos, omega)
|
| 407 |
+
return np.concatenate([np.sin(out), np.cos(out)], axis=1)
|
| 408 |
+
|
| 409 |
+
|
| 410 |
+
class JiTTransformer2DModel(ModelMixin, ConfigMixin):
|
| 411 |
+
_supports_gradient_checkpointing = True
|
| 412 |
+
_skip_layerwise_casting_patterns = ["pos_embed", "norm"]
|
| 413 |
+
|
| 414 |
+
@register_to_config
|
| 415 |
+
def __init__(
|
| 416 |
+
self,
|
| 417 |
+
sample_size: int = 256,
|
| 418 |
+
patch_size: int = 16,
|
| 419 |
+
in_channels: int = 3,
|
| 420 |
+
hidden_size: int = 768,
|
| 421 |
+
num_layers: int = 12,
|
| 422 |
+
num_attention_heads: int = 12,
|
| 423 |
+
mlp_ratio: float = 4.0,
|
| 424 |
+
attention_dropout: float = 0.0,
|
| 425 |
+
dropout: float = 0.0,
|
| 426 |
+
num_classes: int = 1000,
|
| 427 |
+
bottleneck_dim: int = 128,
|
| 428 |
+
in_context_len: int = 32,
|
| 429 |
+
in_context_start: int = 4,
|
| 430 |
+
norm_eps: float = 1e-6,
|
| 431 |
+
model_type: str | None = None,
|
| 432 |
+
num_class_embeds: int | None = None,
|
| 433 |
+
use_bottleneck: bool = True,
|
| 434 |
+
):
|
| 435 |
+
super().__init__()
|
| 436 |
+
if num_class_embeds is not None:
|
| 437 |
+
num_classes = int(num_class_embeds)
|
| 438 |
+
if model_type in JIT_PRESET_CONFIGS:
|
| 439 |
+
preset = JIT_PRESET_CONFIGS[model_type]
|
| 440 |
+
sample_size = int(preset["sample_size"])
|
| 441 |
+
patch_size = int(preset["patch_size"])
|
| 442 |
+
hidden_size = int(preset["hidden_size"])
|
| 443 |
+
num_layers = int(preset["num_layers"])
|
| 444 |
+
num_attention_heads = int(preset["num_attention_heads"])
|
| 445 |
+
bottleneck_dim = int(preset["bottleneck_dim"])
|
| 446 |
+
in_context_len = int(preset["in_context_len"])
|
| 447 |
+
in_context_start = int(preset["in_context_start"])
|
| 448 |
+
if attention_dropout == 0.0:
|
| 449 |
+
attention_dropout = float(preset["attention_dropout"])
|
| 450 |
+
if dropout == 0.0:
|
| 451 |
+
dropout = float(preset["dropout"])
|
| 452 |
+
if "use_bottleneck" in preset:
|
| 453 |
+
use_bottleneck = bool(preset["use_bottleneck"])
|
| 454 |
+
|
| 455 |
+
self.sample_size = sample_size
|
| 456 |
+
self.patch_size = patch_size
|
| 457 |
+
self.in_channels = in_channels
|
| 458 |
+
self.out_channels = in_channels
|
| 459 |
+
self.hidden_size = hidden_size
|
| 460 |
+
self.num_layers = num_layers
|
| 461 |
+
self.num_attention_heads = num_attention_heads
|
| 462 |
+
self.in_context_len = in_context_len
|
| 463 |
+
self.in_context_start = in_context_start
|
| 464 |
+
self.norm_eps = norm_eps
|
| 465 |
+
self.gradient_checkpointing = False
|
| 466 |
+
|
| 467 |
+
self.t_embedder = JiTTimestepEmbedder(hidden_size)
|
| 468 |
+
self.y_embedder = JiTLabelEmbedder(num_classes, hidden_size)
|
| 469 |
+
self.use_bottleneck = use_bottleneck
|
| 470 |
+
self.x_embedder = JiTPatchEmbed(
|
| 471 |
+
img_size=sample_size,
|
| 472 |
+
patch_size=patch_size,
|
| 473 |
+
in_chans=in_channels,
|
| 474 |
+
pca_dim=bottleneck_dim,
|
| 475 |
+
embed_dim=hidden_size,
|
| 476 |
+
bias=True,
|
| 477 |
+
use_bottleneck=use_bottleneck,
|
| 478 |
+
)
|
| 479 |
+
|
| 480 |
+
num_patches = self.x_embedder.num_patches
|
| 481 |
+
pos_embed = get_2d_sincos_pos_embed(hidden_size, int(num_patches**0.5))
|
| 482 |
+
self.register_buffer("pos_embed", torch.from_numpy(pos_embed).float().unsqueeze(0), persistent=True)
|
| 483 |
+
|
| 484 |
+
if self.in_context_len > 0:
|
| 485 |
+
self.in_context_posemb = nn.Parameter(torch.zeros(1, self.in_context_len, hidden_size))
|
| 486 |
+
|
| 487 |
+
half_head_dim = hidden_size // num_attention_heads // 2
|
| 488 |
+
hw_seq_len = sample_size // patch_size
|
| 489 |
+
self.feat_rope = JiTRotaryEmbedding(dim=half_head_dim, pt_seq_len=hw_seq_len, num_cls_token=0)
|
| 490 |
+
self.feat_rope_incontext = JiTRotaryEmbedding(
|
| 491 |
+
dim=half_head_dim,
|
| 492 |
+
pt_seq_len=hw_seq_len,
|
| 493 |
+
num_cls_token=self.in_context_len,
|
| 494 |
+
)
|
| 495 |
+
|
| 496 |
+
self.blocks = nn.ModuleList(
|
| 497 |
+
[
|
| 498 |
+
JiTBlock(
|
| 499 |
+
hidden_size,
|
| 500 |
+
num_attention_heads,
|
| 501 |
+
mlp_ratio=mlp_ratio,
|
| 502 |
+
attn_drop=attention_dropout if (num_layers // 4 * 3 > i >= num_layers // 4) else 0.0,
|
| 503 |
+
proj_drop=dropout if (num_layers // 4 * 3 > i >= num_layers // 4) else 0.0,
|
| 504 |
+
eps=norm_eps,
|
| 505 |
+
)
|
| 506 |
+
for i in range(num_layers)
|
| 507 |
+
]
|
| 508 |
+
)
|
| 509 |
+
|
| 510 |
+
self.norm_final = RMSNorm(hidden_size, eps=norm_eps)
|
| 511 |
+
self.linear_final = nn.Linear(hidden_size, patch_size * patch_size * self.out_channels, bias=True)
|
| 512 |
+
self.act_final = nn.SiLU()
|
| 513 |
+
self.adaLN_modulation_final = nn.Linear(hidden_size, 2 * hidden_size, bias=True)
|
| 514 |
+
|
| 515 |
+
def forward(
|
| 516 |
+
self,
|
| 517 |
+
sample: torch.Tensor,
|
| 518 |
+
timestep: torch.LongTensor,
|
| 519 |
+
class_labels: torch.LongTensor,
|
| 520 |
+
return_dict: bool = True,
|
| 521 |
+
):
|
| 522 |
+
timestep = torch.as_tensor(timestep, device=sample.device)
|
| 523 |
+
if timestep.ndim == 0:
|
| 524 |
+
timestep = timestep.repeat(sample.shape[0])
|
| 525 |
+
else:
|
| 526 |
+
timestep = timestep.reshape(-1)
|
| 527 |
+
if timestep.shape[0] == 1 and sample.shape[0] > 1:
|
| 528 |
+
timestep = timestep.repeat(sample.shape[0])
|
| 529 |
+
|
| 530 |
+
t_emb = self.t_embedder(timestep, dtype=sample.dtype)
|
| 531 |
+
y_emb = self.y_embedder(class_labels).to(dtype=sample.dtype)
|
| 532 |
+
c = t_emb + y_emb
|
| 533 |
+
|
| 534 |
+
x = self.x_embedder(sample)
|
| 535 |
+
x = x + self.pos_embed.to(x.dtype)
|
| 536 |
+
|
| 537 |
+
for i, block in enumerate(self.blocks):
|
| 538 |
+
if self.in_context_len > 0 and i == self.in_context_start:
|
| 539 |
+
in_context_tokens = y_emb.unsqueeze(1).repeat(1, self.in_context_len, 1)
|
| 540 |
+
in_context_tokens = in_context_tokens + self.in_context_posemb.to(in_context_tokens.dtype)
|
| 541 |
+
x = torch.cat([in_context_tokens, x], dim=1)
|
| 542 |
+
|
| 543 |
+
rope = self.feat_rope if i < self.in_context_start else self.feat_rope_incontext
|
| 544 |
+
if self.training and self.gradient_checkpointing:
|
| 545 |
+
x = torch.utils.checkpoint.checkpoint(block, x, c, rope, use_reentrant=False)
|
| 546 |
+
else:
|
| 547 |
+
x = block(x, c, feat_rope=rope)
|
| 548 |
+
|
| 549 |
+
if self.in_context_len > 0:
|
| 550 |
+
x = x[:, self.in_context_len :]
|
| 551 |
+
|
| 552 |
+
c = self.act_final(c)
|
| 553 |
+
shift, scale = self.adaLN_modulation_final(c).chunk(2, dim=1)
|
| 554 |
+
x = modulate(self.norm_final(x), shift, scale)
|
| 555 |
+
x = self.linear_final(x)
|
| 556 |
+
|
| 557 |
+
height = width = int(x.shape[1] ** 0.5)
|
| 558 |
+
x = x.reshape(shape=(x.shape[0], height, width, self.patch_size, self.patch_size, self.out_channels))
|
| 559 |
+
x = torch.einsum("nhwpqc->nchpwq", x)
|
| 560 |
+
output = x.reshape(shape=(x.shape[0], self.out_channels, height * self.patch_size, width * self.patch_size))
|
| 561 |
+
|
| 562 |
+
if not return_dict:
|
| 563 |
+
return (output,)
|
| 564 |
+
return Transformer2DModelOutput(sample=output)
|
| 565 |
+
|
| 566 |
+
@classmethod
|
| 567 |
+
def from_jit_checkpoint(
|
| 568 |
+
cls,
|
| 569 |
+
checkpoint_path: str,
|
| 570 |
+
weights: Literal["model", "ema1", "ema2"] = "ema1",
|
| 571 |
+
map_location: str = "cpu",
|
| 572 |
+
strict: bool = True,
|
| 573 |
+
) -> Tuple["JiTTransformer2DModel", Dict[str, object]]:
|
| 574 |
+
checkpoint = torch.load(checkpoint_path, map_location=map_location, weights_only=False)
|
| 575 |
+
if "args" not in checkpoint:
|
| 576 |
+
raise ValueError("Checkpoint is missing 'args', cannot infer JiT architecture config.")
|
| 577 |
+
|
| 578 |
+
ckpt_args = checkpoint["args"]
|
| 579 |
+
if isinstance(ckpt_args, argparse.Namespace):
|
| 580 |
+
args_dict = vars(ckpt_args)
|
| 581 |
+
elif isinstance(ckpt_args, Mapping):
|
| 582 |
+
args_dict = dict(ckpt_args)
|
| 583 |
+
else:
|
| 584 |
+
raise TypeError(f"Unsupported checkpoint args type: {type(ckpt_args)}")
|
| 585 |
+
|
| 586 |
+
model_type = args_dict.get("model") or args_dict.get("model_name") or args_dict.get("model_type")
|
| 587 |
+
if model_type not in JIT_PRESET_CONFIGS:
|
| 588 |
+
raise ValueError(f"Unknown JiT preset '{model_type}'.")
|
| 589 |
+
|
| 590 |
+
config = dict(JIT_PRESET_CONFIGS[model_type])
|
| 591 |
+
config["num_classes"] = int(args_dict.get("class_num") or args_dict.get("num_classes") or 1000)
|
| 592 |
+
config["model_type"] = model_type
|
| 593 |
+
config["attention_dropout"] = float(args_dict.get("attn_dropout", args_dict.get("attention_dropout", config["attention_dropout"])))
|
| 594 |
+
config["dropout"] = float(args_dict.get("proj_dropout", args_dict.get("dropout", config["dropout"])))
|
| 595 |
+
model = cls(**config)
|
| 596 |
+
|
| 597 |
+
key = "model" if weights == "model" else f"model_{weights}"
|
| 598 |
+
if key not in checkpoint:
|
| 599 |
+
raise ValueError(f"Checkpoint key '{key}' not found. Available keys: {list(checkpoint.keys())}")
|
| 600 |
+
|
| 601 |
+
state_dict = remap_legacy_state_dict(checkpoint[key])
|
| 602 |
+
model.load_state_dict(state_dict, strict=strict)
|
| 603 |
+
|
| 604 |
+
metadata = {
|
| 605 |
+
"checkpoint_path": checkpoint_path,
|
| 606 |
+
"weights": weights,
|
| 607 |
+
"epoch": checkpoint.get("epoch"),
|
| 608 |
+
"model_type": model_type,
|
| 609 |
+
"source_args": checkpoint.get("args"),
|
| 610 |
+
}
|
| 611 |
+
return model, metadata
|
| 612 |
+
|
| 613 |
+
@classmethod
|
| 614 |
+
def from_pixelgen_checkpoint(
|
| 615 |
+
cls,
|
| 616 |
+
checkpoint_path: str,
|
| 617 |
+
weights_prefix: str = "ema_denoiser.",
|
| 618 |
+
model_type: str | None = None,
|
| 619 |
+
map_location: str = "cpu",
|
| 620 |
+
strict: bool = False,
|
| 621 |
+
) -> Tuple["JiTTransformer2DModel", Dict[str, object]]:
|
| 622 |
+
"""Load from a PixelGen/DeCo Lightning checkpoint (.ckpt)."""
|
| 623 |
+
checkpoint = torch.load(checkpoint_path, map_location=map_location, weights_only=False)
|
| 624 |
+
state_dict = checkpoint.get("state_dict", checkpoint)
|
| 625 |
+
|
| 626 |
+
filtered = {k[len(weights_prefix) :]: v for k, v in state_dict.items() if k.startswith(weights_prefix)}
|
| 627 |
+
if not filtered:
|
| 628 |
+
raise ValueError(f"No parameters found with prefix '{weights_prefix}' in checkpoint.")
|
| 629 |
+
|
| 630 |
+
inferred_type = model_type
|
| 631 |
+
if inferred_type is None:
|
| 632 |
+
hidden_size = filtered.get("t_embedder.mlp.0.weight")
|
| 633 |
+
depth = sum(1 for k in filtered if k.startswith("blocks.") and k.endswith(".norm1.weight"))
|
| 634 |
+
if hidden_size is not None and depth == 28 and hidden_size.shape[0] == 1152:
|
| 635 |
+
inferred_type = "PixelGen-XL/16"
|
| 636 |
+
elif hidden_size is not None and depth == 16 and hidden_size.shape[0] == 1536:
|
| 637 |
+
inferred_type = "PixelGen-XXL/16"
|
| 638 |
+
|
| 639 |
+
if inferred_type is None or inferred_type not in JIT_PRESET_CONFIGS:
|
| 640 |
+
raise ValueError(
|
| 641 |
+
f"Could not infer model_type from checkpoint. Pass model_type explicitly. "
|
| 642 |
+
f"Known presets: {list(JIT_PRESET_CONFIGS)}"
|
| 643 |
+
)
|
| 644 |
+
|
| 645 |
+
config = dict(JIT_PRESET_CONFIGS[inferred_type])
|
| 646 |
+
config["num_classes"] = 1000
|
| 647 |
+
config["model_type"] = inferred_type
|
| 648 |
+
model = cls(**config)
|
| 649 |
+
remapped = remap_legacy_state_dict(filtered)
|
| 650 |
+
model.load_state_dict(remapped, strict=strict)
|
| 651 |
+
metadata = {"checkpoint_path": checkpoint_path, "model_type": inferred_type, "weights_prefix": weights_prefix}
|
| 652 |
+
return model, metadata
|
| 653 |
+
|
| 654 |
+
def to_jit_checkpoint(
|
| 655 |
+
self,
|
| 656 |
+
ema_mode: Literal["none", "copy_to_both"] = "copy_to_both",
|
| 657 |
+
prefix: str = "net.",
|
| 658 |
+
) -> Dict[str, object]:
|
| 659 |
+
base_state: Dict[str, torch.Tensor] = {}
|
| 660 |
+
for key, value in self.state_dict().items():
|
| 661 |
+
legacy_key = key
|
| 662 |
+
if legacy_key.startswith("norm_final"):
|
| 663 |
+
legacy_key = legacy_key.replace("norm_final", "final_layer.norm_final", 1)
|
| 664 |
+
if legacy_key.startswith("linear_final"):
|
| 665 |
+
legacy_key = legacy_key.replace("linear_final", "final_layer.linear", 1)
|
| 666 |
+
if legacy_key.startswith("adaLN_modulation_final"):
|
| 667 |
+
legacy_key = legacy_key.replace("adaLN_modulation_final", "final_layer.adaLN_modulation", 1)
|
| 668 |
+
legacy_key = legacy_key.replace(".adaLN_modulation.", ".adaLN_modulation.1.")
|
| 669 |
+
base_state[f"{prefix}{legacy_key}"] = value.detach().cpu()
|
| 670 |
+
|
| 671 |
+
checkpoint = {"model": base_state}
|
| 672 |
+
if ema_mode == "copy_to_both":
|
| 673 |
+
checkpoint["model_ema1"] = {k: v.clone() for k, v in base_state.items()}
|
| 674 |
+
checkpoint["model_ema2"] = {k: v.clone() for k, v in base_state.items()}
|
| 675 |
+
elif ema_mode != "none":
|
| 676 |
+
raise ValueError(f"Unsupported ema_mode='{ema_mode}'.")
|
| 677 |
+
return checkpoint
|
| 678 |
+
|
| 679 |
+
@property
|
| 680 |
+
def net(self):
|
| 681 |
+
return self
|
| 682 |
+
|
| 683 |
+
|
| 684 |
+
JiTDiffusersModel = JiTTransformer2DModel
|
PixelGen-XXL-16-512-t2i/model_index.json
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"_class_name": [
|
| 3 |
+
"pipeline",
|
| 4 |
+
"PixelGenT2IPipeline"
|
| 5 |
+
],
|
| 6 |
+
"_diffusers_version": "0.38.0",
|
| 7 |
+
"scheduler": [
|
| 8 |
+
"scheduling_pixelgen",
|
| 9 |
+
"PixelGenScheduler"
|
| 10 |
+
],
|
| 11 |
+
"text_encoder": [
|
| 12 |
+
"transformers",
|
| 13 |
+
"Qwen3Model"
|
| 14 |
+
],
|
| 15 |
+
"tokenizer": [
|
| 16 |
+
"transformers",
|
| 17 |
+
"Qwen2Tokenizer"
|
| 18 |
+
],
|
| 19 |
+
"transformer": [
|
| 20 |
+
"transformer_jit_t2i",
|
| 21 |
+
"JiTTransformer2DT2IModel"
|
| 22 |
+
]
|
| 23 |
+
}
|
PixelGen-XXL-16-512-t2i/pipeline.py
ADDED
|
@@ -0,0 +1,333 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Hub custom pipeline: PixelGenT2IPipeline.
|
| 2 |
+
Load with native Hugging Face diffusers and trust_remote_code=True.
|
| 3 |
+
"""
|
| 4 |
+
|
| 5 |
+
from __future__ import annotations
|
| 6 |
+
|
| 7 |
+
import importlib
|
| 8 |
+
import sys
|
| 9 |
+
from pathlib import Path
|
| 10 |
+
from typing import List, Optional, Tuple, Union
|
| 11 |
+
|
| 12 |
+
import torch
|
| 13 |
+
from diffusers.pipelines.pipeline_utils import DiffusionPipeline, ImagePipelineOutput
|
| 14 |
+
from diffusers.utils.torch_utils import randn_tensor
|
| 15 |
+
from transformers import Qwen2Tokenizer, Qwen3Model
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
class PixelGenT2IPipeline(DiffusionPipeline):
|
| 19 |
+
model_cpu_offload_seq = "text_encoder->transformer"
|
| 20 |
+
|
| 21 |
+
@staticmethod
|
| 22 |
+
def _infer_variant_dir(*components) -> Path:
|
| 23 |
+
for component in components:
|
| 24 |
+
if component is None:
|
| 25 |
+
continue
|
| 26 |
+
for attr in ("name_or_path",):
|
| 27 |
+
path_value = getattr(component, attr, None)
|
| 28 |
+
if path_value:
|
| 29 |
+
path = Path(path_value)
|
| 30 |
+
if path.is_dir() and (path / "model_index.json").exists():
|
| 31 |
+
return path
|
| 32 |
+
if path.parent.is_dir() and (path.parent / "model_index.json").exists():
|
| 33 |
+
return path.parent
|
| 34 |
+
config = getattr(component, "config", None)
|
| 35 |
+
path_value = getattr(config, "_name_or_path", None) if config is not None else None
|
| 36 |
+
if path_value:
|
| 37 |
+
path = Path(path_value)
|
| 38 |
+
if path.is_dir() and (path / "model_index.json").exists():
|
| 39 |
+
return path
|
| 40 |
+
if path.parent.is_dir() and (path.parent / "model_index.json").exists():
|
| 41 |
+
return path.parent
|
| 42 |
+
return Path(__file__).resolve().parent
|
| 43 |
+
|
| 44 |
+
def __init__(
|
| 45 |
+
self,
|
| 46 |
+
transformer,
|
| 47 |
+
text_encoder,
|
| 48 |
+
tokenizer,
|
| 49 |
+
scheduler=None,
|
| 50 |
+
):
|
| 51 |
+
variant = self._infer_variant_dir(transformer, text_encoder, tokenizer, scheduler)
|
| 52 |
+
if isinstance(transformer, (list, tuple)):
|
| 53 |
+
transformer = self._load_transformer(variant)
|
| 54 |
+
if isinstance(scheduler, (list, tuple)) or scheduler is None:
|
| 55 |
+
scheduler = self._load_scheduler(variant)
|
| 56 |
+
|
| 57 |
+
super().__init__()
|
| 58 |
+
self.register_modules(
|
| 59 |
+
transformer=transformer,
|
| 60 |
+
text_encoder=text_encoder,
|
| 61 |
+
tokenizer=tokenizer,
|
| 62 |
+
scheduler=scheduler,
|
| 63 |
+
)
|
| 64 |
+
if torch.cuda.is_available():
|
| 65 |
+
torch_dtype = getattr(transformer, "dtype", None)
|
| 66 |
+
if torch_dtype is not None:
|
| 67 |
+
self.to("cuda", torch_dtype=torch_dtype)
|
| 68 |
+
else:
|
| 69 |
+
self.to("cuda")
|
| 70 |
+
|
| 71 |
+
@staticmethod
|
| 72 |
+
def _resolve_variant_dir(pretrained_model_name_or_path: Optional[str]) -> Path:
|
| 73 |
+
repo_root = Path(__file__).resolve().parent
|
| 74 |
+
if pretrained_model_name_or_path in (None, "", "."):
|
| 75 |
+
return repo_root
|
| 76 |
+
variant = Path(pretrained_model_name_or_path)
|
| 77 |
+
if not variant.is_absolute():
|
| 78 |
+
candidate = (Path.cwd() / variant).resolve()
|
| 79 |
+
variant = candidate if candidate.exists() else (repo_root / variant).resolve()
|
| 80 |
+
return variant
|
| 81 |
+
|
| 82 |
+
@classmethod
|
| 83 |
+
def _load_transformer(cls, variant: Path, **model_kwargs):
|
| 84 |
+
comp_dir = variant / "transformer"
|
| 85 |
+
module_path = comp_dir / "transformer_jit_t2i.py"
|
| 86 |
+
if not module_path.exists():
|
| 87 |
+
raise FileNotFoundError(f"Missing transformer module at {module_path}")
|
| 88 |
+
comp_path = str(comp_dir)
|
| 89 |
+
if comp_path not in sys.path:
|
| 90 |
+
sys.path.insert(0, comp_path)
|
| 91 |
+
module = importlib.import_module("transformer_jit_t2i")
|
| 92 |
+
transformer_cls = getattr(module, "JiTTransformer2DT2IModel")
|
| 93 |
+
return transformer_cls.from_pretrained(str(comp_dir), **model_kwargs)
|
| 94 |
+
|
| 95 |
+
@classmethod
|
| 96 |
+
def _load_scheduler(cls, variant: Path):
|
| 97 |
+
scheduler_dir = variant / "scheduler"
|
| 98 |
+
config_path = scheduler_dir / "scheduler_config.json"
|
| 99 |
+
if not config_path.exists():
|
| 100 |
+
raise FileNotFoundError(f"Missing scheduler config at {config_path}")
|
| 101 |
+
scheduler_path = str(scheduler_dir)
|
| 102 |
+
if scheduler_path not in sys.path:
|
| 103 |
+
sys.path.insert(0, scheduler_path)
|
| 104 |
+
module = importlib.import_module("scheduling_pixelgen")
|
| 105 |
+
scheduler_cls = getattr(module, "PixelGenScheduler")
|
| 106 |
+
return scheduler_cls.from_pretrained(str(scheduler_dir))
|
| 107 |
+
|
| 108 |
+
@classmethod
|
| 109 |
+
def from_pretrained(cls, pretrained_model_name_or_path: str, **kwargs):
|
| 110 |
+
variant = cls._resolve_variant_dir(pretrained_model_name_or_path)
|
| 111 |
+
model_kwargs = dict(kwargs)
|
| 112 |
+
transformer = cls._load_transformer(variant, **model_kwargs)
|
| 113 |
+
scheduler = cls._load_scheduler(variant)
|
| 114 |
+
|
| 115 |
+
text_encoder_dir = variant / "text_encoder"
|
| 116 |
+
tokenizer_dir = variant / "tokenizer"
|
| 117 |
+
if text_encoder_dir.exists() and (text_encoder_dir / "config.json").exists():
|
| 118 |
+
text_encoder = Qwen3Model.from_pretrained(str(text_encoder_dir), **model_kwargs)
|
| 119 |
+
tokenizer = Qwen2Tokenizer.from_pretrained(
|
| 120 |
+
str(tokenizer_dir if tokenizer_dir.exists() else text_encoder_dir)
|
| 121 |
+
)
|
| 122 |
+
else:
|
| 123 |
+
text_encoder_name = "Qwen/Qwen3-1.7B"
|
| 124 |
+
text_encoder = Qwen3Model.from_pretrained(text_encoder_name, **model_kwargs)
|
| 125 |
+
tokenizer = Qwen2Tokenizer.from_pretrained(text_encoder_name)
|
| 126 |
+
|
| 127 |
+
pipe = cls(
|
| 128 |
+
transformer=transformer,
|
| 129 |
+
text_encoder=text_encoder,
|
| 130 |
+
tokenizer=tokenizer,
|
| 131 |
+
scheduler=scheduler,
|
| 132 |
+
)
|
| 133 |
+
if hasattr(pipe, "register_to_config"):
|
| 134 |
+
pipe.register_to_config(_name_or_path=str(variant))
|
| 135 |
+
return pipe
|
| 136 |
+
|
| 137 |
+
def encode_prompt(
|
| 138 |
+
self,
|
| 139 |
+
prompt: Union[str, List[str]],
|
| 140 |
+
negative_prompt: Union[str, List[str], None] = None,
|
| 141 |
+
device: Optional[torch.device] = None,
|
| 142 |
+
dtype: Optional[torch.dtype] = None,
|
| 143 |
+
) -> Tuple[torch.Tensor, torch.Tensor]:
|
| 144 |
+
device = device or self._execution_device
|
| 145 |
+
dtype = dtype or self.text_encoder.dtype
|
| 146 |
+
|
| 147 |
+
if isinstance(prompt, str):
|
| 148 |
+
prompt = [prompt]
|
| 149 |
+
if negative_prompt is None:
|
| 150 |
+
negative_prompt = [""] * len(prompt)
|
| 151 |
+
elif isinstance(negative_prompt, str):
|
| 152 |
+
negative_prompt = [negative_prompt] * len(prompt)
|
| 153 |
+
|
| 154 |
+
max_length = self.transformer.config.text_max_length
|
| 155 |
+
text_embed_dim = self.transformer.config.text_embed_dim
|
| 156 |
+
|
| 157 |
+
def _encode(texts):
|
| 158 |
+
tokenized = self.tokenizer(
|
| 159 |
+
texts, truncation=True, max_length=max_length, padding="max_length", return_tensors="pt"
|
| 160 |
+
)
|
| 161 |
+
input_ids = tokenized.input_ids.to(device)
|
| 162 |
+
attention_mask = tokenized.attention_mask.to(device)
|
| 163 |
+
hidden = self.text_encoder(input_ids=input_ids, attention_mask=attention_mask)[0]
|
| 164 |
+
if hidden.shape[2] < text_embed_dim:
|
| 165 |
+
pad = torch.zeros(
|
| 166 |
+
hidden.shape[0],
|
| 167 |
+
hidden.shape[1],
|
| 168 |
+
text_embed_dim - hidden.shape[2],
|
| 169 |
+
device=device,
|
| 170 |
+
dtype=hidden.dtype,
|
| 171 |
+
)
|
| 172 |
+
hidden = torch.cat([hidden, pad], dim=-1)
|
| 173 |
+
elif hidden.shape[2] > text_embed_dim:
|
| 174 |
+
hidden = hidden[:, :, :text_embed_dim]
|
| 175 |
+
return hidden.to(dtype=dtype)
|
| 176 |
+
|
| 177 |
+
return _encode(prompt), _encode(negative_prompt)
|
| 178 |
+
|
| 179 |
+
def _predict_velocity(
|
| 180 |
+
self,
|
| 181 |
+
z_value: torch.Tensor,
|
| 182 |
+
t: torch.Tensor,
|
| 183 |
+
encoder_hidden_states: torch.Tensor,
|
| 184 |
+
uncond_hidden_states: torch.Tensor,
|
| 185 |
+
do_classifier_free_guidance: bool,
|
| 186 |
+
guidance_scale: float,
|
| 187 |
+
guidance_interval_min: float,
|
| 188 |
+
guidance_interval_max: float,
|
| 189 |
+
scale_h: float,
|
| 190 |
+
scale_w: float,
|
| 191 |
+
) -> torch.Tensor:
|
| 192 |
+
if do_classifier_free_guidance:
|
| 193 |
+
z_in = torch.cat([z_value, z_value], dim=0)
|
| 194 |
+
hidden = torch.cat([uncond_hidden_states, encoder_hidden_states], dim=0)
|
| 195 |
+
else:
|
| 196 |
+
z_in = z_value
|
| 197 |
+
hidden = encoder_hidden_states
|
| 198 |
+
|
| 199 |
+
t = t.to(device=z_value.device, dtype=torch.float64)
|
| 200 |
+
t_batch = t.flatten().expand(z_in.shape[0]).to(dtype=z_in.dtype)
|
| 201 |
+
x_pred = self.transformer(
|
| 202 |
+
z_in, timestep=t_batch, encoder_hidden_states=hidden, scale_h=scale_h, scale_w=scale_w
|
| 203 |
+
).sample
|
| 204 |
+
v = self.scheduler.velocity_from_prediction(z_in, x_pred, t)
|
| 205 |
+
|
| 206 |
+
if not do_classifier_free_guidance:
|
| 207 |
+
return v
|
| 208 |
+
|
| 209 |
+
v_uncond, v_cond = v.chunk(2, dim=0)
|
| 210 |
+
interval_mask = (t > guidance_interval_min) & (t < guidance_interval_max)
|
| 211 |
+
scale = torch.where(
|
| 212 |
+
interval_mask,
|
| 213 |
+
torch.tensor(guidance_scale, device=z_value.device, dtype=z_value.dtype),
|
| 214 |
+
torch.tensor(1.0, device=z_value.device, dtype=z_value.dtype),
|
| 215 |
+
)
|
| 216 |
+
return v_uncond + scale * (v_cond - v_uncond)
|
| 217 |
+
|
| 218 |
+
def _run_adam_lm_sampler(
|
| 219 |
+
self,
|
| 220 |
+
latents: torch.Tensor,
|
| 221 |
+
encoder_hidden_states: torch.Tensor,
|
| 222 |
+
uncond_hidden_states: torch.Tensor,
|
| 223 |
+
num_inference_steps: int,
|
| 224 |
+
do_classifier_free_guidance: bool,
|
| 225 |
+
guidance_scale: float,
|
| 226 |
+
guidance_interval_min: float,
|
| 227 |
+
guidance_interval_max: float,
|
| 228 |
+
timeshift: float,
|
| 229 |
+
adam_lm_order: int,
|
| 230 |
+
scale_h: float,
|
| 231 |
+
scale_w: float,
|
| 232 |
+
) -> torch.Tensor:
|
| 233 |
+
device = latents.device
|
| 234 |
+
self.scheduler.set_timesteps(
|
| 235 |
+
num_inference_steps,
|
| 236 |
+
device=device,
|
| 237 |
+
solver="adam_lm",
|
| 238 |
+
timeshift=timeshift,
|
| 239 |
+
adam_lm_order=adam_lm_order,
|
| 240 |
+
)
|
| 241 |
+
batch_size = latents.shape[0]
|
| 242 |
+
t_cur = torch.zeros(batch_size, device=device, dtype=torch.float64)
|
| 243 |
+
velocity_history: list[torch.Tensor] = []
|
| 244 |
+
|
| 245 |
+
for i in self.progress_bar(range(num_inference_steps)):
|
| 246 |
+
v = self._predict_velocity(
|
| 247 |
+
latents,
|
| 248 |
+
t_cur,
|
| 249 |
+
encoder_hidden_states,
|
| 250 |
+
uncond_hidden_states,
|
| 251 |
+
do_classifier_free_guidance,
|
| 252 |
+
guidance_scale,
|
| 253 |
+
guidance_interval_min,
|
| 254 |
+
guidance_interval_max,
|
| 255 |
+
scale_h,
|
| 256 |
+
scale_w,
|
| 257 |
+
)
|
| 258 |
+
velocity_history.append(v)
|
| 259 |
+
latents = self.scheduler.apply_adam_lm_step(latents, velocity_history, i)
|
| 260 |
+
t_cur = t_cur + self.scheduler.timedeltas[i].to(dtype=torch.float64)
|
| 261 |
+
|
| 262 |
+
return latents
|
| 263 |
+
|
| 264 |
+
@torch.inference_mode()
|
| 265 |
+
def __call__(
|
| 266 |
+
self,
|
| 267 |
+
prompt: Union[str, List[str]],
|
| 268 |
+
negative_prompt: Union[str, List[str], None] = None,
|
| 269 |
+
height: Optional[int] = None,
|
| 270 |
+
width: Optional[int] = None,
|
| 271 |
+
guidance_scale: float = 4.0,
|
| 272 |
+
guidance_interval_min: float = 0.0,
|
| 273 |
+
guidance_interval_max: float = 1.0,
|
| 274 |
+
num_inference_steps: int = 25,
|
| 275 |
+
timeshift: Optional[float] = None,
|
| 276 |
+
adam_lm_order: Optional[int] = None,
|
| 277 |
+
generator: Optional[Union[torch.Generator, List[torch.Generator]]] = None,
|
| 278 |
+
output_type: Optional[str] = "pil",
|
| 279 |
+
return_dict: bool = True,
|
| 280 |
+
) -> Union[ImagePipelineOutput, Tuple]:
|
| 281 |
+
if isinstance(prompt, str):
|
| 282 |
+
prompt = [prompt]
|
| 283 |
+
|
| 284 |
+
height = height or self.transformer.config.sample_size
|
| 285 |
+
width = width or self.transformer.config.sample_size
|
| 286 |
+
height = height // 32 * 32
|
| 287 |
+
width = width // 32 * 32
|
| 288 |
+
scale_h = height / self.transformer.config.sample_size
|
| 289 |
+
scale_w = width / self.transformer.config.sample_size
|
| 290 |
+
shift = timeshift if timeshift is not None else self.scheduler.config.timeshift
|
| 291 |
+
order = adam_lm_order if adam_lm_order is not None else self.scheduler.config.adam_lm_order
|
| 292 |
+
|
| 293 |
+
cond, uncond = self.encode_prompt(prompt, negative_prompt)
|
| 294 |
+
do_cfg = guidance_scale > 1.0
|
| 295 |
+
batch_size = len(prompt)
|
| 296 |
+
|
| 297 |
+
latents = randn_tensor(
|
| 298 |
+
shape=(batch_size, self.transformer.config.in_channels, height, width),
|
| 299 |
+
generator=generator,
|
| 300 |
+
device=self._execution_device,
|
| 301 |
+
dtype=self.transformer.dtype,
|
| 302 |
+
)
|
| 303 |
+
|
| 304 |
+
latents = self._run_adam_lm_sampler(
|
| 305 |
+
latents,
|
| 306 |
+
cond,
|
| 307 |
+
uncond,
|
| 308 |
+
num_inference_steps,
|
| 309 |
+
do_cfg,
|
| 310 |
+
guidance_scale,
|
| 311 |
+
guidance_interval_min,
|
| 312 |
+
guidance_interval_max,
|
| 313 |
+
shift,
|
| 314 |
+
order,
|
| 315 |
+
scale_h,
|
| 316 |
+
scale_w,
|
| 317 |
+
)
|
| 318 |
+
|
| 319 |
+
images_pt = ((latents.float().clamp(-1, 1) + 1.0) / 2.0).cpu()
|
| 320 |
+
if output_type == "pt":
|
| 321 |
+
images = images_pt
|
| 322 |
+
elif output_type == "np":
|
| 323 |
+
images = images_pt.permute(0, 2, 3, 1).numpy()
|
| 324 |
+
else:
|
| 325 |
+
images = self.numpy_to_pil(images_pt.permute(0, 2, 3, 1).numpy())
|
| 326 |
+
|
| 327 |
+
self.maybe_free_model_hooks()
|
| 328 |
+
if not return_dict:
|
| 329 |
+
return (images,)
|
| 330 |
+
return ImagePipelineOutput(images=images)
|
| 331 |
+
|
| 332 |
+
|
| 333 |
+
PixelGenT2IPipelineOutput = ImagePipelineOutput
|
PixelGen-XXL-16-512-t2i/scheduler/__pycache__/scheduling_pixelgen.cpython-312.pyc
ADDED
|
Binary file (15.7 kB). View file
|
|
|
PixelGen-XXL-16-512-t2i/scheduler/scheduler_config.json
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"_class_name": "PixelGenScheduler",
|
| 3 |
+
"_diffusers_version": "0.38.0",
|
| 4 |
+
"adam_lm_order": 2,
|
| 5 |
+
"last_step": null,
|
| 6 |
+
"num_train_timesteps": 1000,
|
| 7 |
+
"solver": "adam_lm",
|
| 8 |
+
"t_eps": 0.05,
|
| 9 |
+
"timeshift": 3.0
|
| 10 |
+
}
|
PixelGen-XXL-16-512-t2i/scheduler/scheduling_pixelgen.py
ADDED
|
@@ -0,0 +1,285 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
+
|
| 11 |
+
|
| 12 |
+
def lagrange_preint_o1(t1, v1, int_t_start, int_t_end):
|
| 13 |
+
int1 = int_t_end - int_t_start
|
| 14 |
+
return int1 * v1, (int1 / int1,)
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
def lagrange_preint_o2(t1, t2, v1, v2, int_t_start, int_t_end):
|
| 18 |
+
int1 = 0.5 / (t1 - t2) * ((int_t_end - t2) ** 2 - (int_t_start - t2) ** 2)
|
| 19 |
+
int2 = 0.5 / (t2 - t1) * ((int_t_end - t1) ** 2 - (int_t_start - t1) ** 2)
|
| 20 |
+
int_sum = int1 + int2
|
| 21 |
+
return int1 * v1 + int2 * v2, (int1 / int_sum, int2 / int_sum)
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
def lagrange_preint_o3(t1, t2, t3, v1, v2, v3, int_t_start, int_t_end):
|
| 25 |
+
int1_denom = (t1 - t2) * (t1 - t3)
|
| 26 |
+
int1_end = 1 / 3 * (int_t_end) ** 3 - 1 / 2 * (t2 + t3) * (int_t_end) ** 2 + (t2 * t3) * int_t_end
|
| 27 |
+
int1_start = 1 / 3 * (int_t_start) ** 3 - 1 / 2 * (t2 + t3) * (int_t_start) ** 2 + (t2 * t3) * int_t_start
|
| 28 |
+
int1 = (int1_end - int1_start) / int1_denom
|
| 29 |
+
int2_denom = (t2 - t1) * (t2 - t3)
|
| 30 |
+
int2_end = 1 / 3 * (int_t_end) ** 3 - 1 / 2 * (t1 + t3) * (int_t_end) ** 2 + (t1 * t3) * int_t_end
|
| 31 |
+
int2_start = 1 / 3 * (int_t_start) ** 3 - 1 / 2 * (t1 + t3) * (int_t_start) ** 2 + (t1 * t3) * int_t_start
|
| 32 |
+
int2 = (int2_end - int2_start) / int2_denom
|
| 33 |
+
int3_denom = (t3 - t1) * (t3 - t2)
|
| 34 |
+
int3_end = 1 / 3 * (int_t_end) ** 3 - 1 / 2 * (t1 + t2) * (int_t_end) ** 2 + (t1 * t2) * int_t_end
|
| 35 |
+
int3_start = 1 / 3 * (int_t_start) ** 3 - 1 / 2 * (t1 + t2) * (int_t_start) ** 2 + (t1 * t2) * int_t_start
|
| 36 |
+
int3 = (int3_end - int3_start) / int3_denom
|
| 37 |
+
int_sum = int1 + int2 + int3
|
| 38 |
+
return int1 * v1 + int2 * v2 + int3 * v3, (int1 / int_sum, int2 / int_sum, int3 / int_sum)
|
| 39 |
+
|
| 40 |
+
|
| 41 |
+
def larange_preint_o4(t1, t2, t3, t4, v1, v2, v3, v4, int_t_start, int_t_end):
|
| 42 |
+
int1_denom = (t1 - t2) * (t1 - t3) * (t1 - t4)
|
| 43 |
+
int1_end = (
|
| 44 |
+
1 / 4 * (int_t_end) ** 4
|
| 45 |
+
- 1 / 3 * (t2 + t3 + t4) * (int_t_end) ** 3
|
| 46 |
+
+ 1 / 2 * (t3 * t4 + t2 * t3 + t2 * t4) * int_t_end**2
|
| 47 |
+
- t2 * t3 * t4 * int_t_end
|
| 48 |
+
)
|
| 49 |
+
int1_start = (
|
| 50 |
+
1 / 4 * (int_t_start) ** 4
|
| 51 |
+
- 1 / 3 * (t2 + t3 + t4) * (int_t_start) ** 3
|
| 52 |
+
+ 1 / 2 * (t3 * t4 + t2 * t3 + t2 * t4) * int_t_start**2
|
| 53 |
+
- t2 * t3 * t4 * int_t_start
|
| 54 |
+
)
|
| 55 |
+
int1 = (int1_end - int1_start) / int1_denom
|
| 56 |
+
int2_denom = (t2 - t1) * (t2 - t3) * (t2 - t4)
|
| 57 |
+
int2_end = (
|
| 58 |
+
1 / 4 * (int_t_end) ** 4
|
| 59 |
+
- 1 / 3 * (t1 + t3 + t4) * (int_t_end) ** 3
|
| 60 |
+
+ 1 / 2 * (t3 * t4 + t1 * t3 + t1 * t4) * int_t_end**2
|
| 61 |
+
- t1 * t3 * t4 * int_t_end
|
| 62 |
+
)
|
| 63 |
+
int2_start = (
|
| 64 |
+
1 / 4 * (int_t_start) ** 4
|
| 65 |
+
- 1 / 3 * (t1 + t3 + t4) * (int_t_start) ** 3
|
| 66 |
+
+ 1 / 2 * (t3 * t4 + t1 * t3 + t1 * t4) * int_t_start**2
|
| 67 |
+
- t1 * t3 * t4 * int_t_start
|
| 68 |
+
)
|
| 69 |
+
int2 = (int2_end - int2_start) / int2_denom
|
| 70 |
+
int3_denom = (t3 - t1) * (t3 - t2) * (t3 - t4)
|
| 71 |
+
int3_end = (
|
| 72 |
+
1 / 4 * (int_t_end) ** 4
|
| 73 |
+
- 1 / 3 * (t1 + t2 + t4) * (int_t_end) ** 3
|
| 74 |
+
+ 1 / 2 * (t4 * t2 + t1 * t2 + t1 * t4) * int_t_end**2
|
| 75 |
+
- t1 * t2 * t4 * int_t_end
|
| 76 |
+
)
|
| 77 |
+
int3_start = (
|
| 78 |
+
1 / 4 * (int_t_start) ** 4
|
| 79 |
+
- 1 / 3 * (t1 + t2 + t4) * (int_t_start) ** 3
|
| 80 |
+
+ 1 / 2 * (t4 * t2 + t1 * t2 + t1 * t4) * int_t_start**2
|
| 81 |
+
- t1 * t2 * t4 * int_t_start
|
| 82 |
+
)
|
| 83 |
+
int3 = (int3_end - int3_start) / int3_denom
|
| 84 |
+
int4_denom = (t4 - t1) * (t4 - t2) * (t4 - t3)
|
| 85 |
+
int4_end = (
|
| 86 |
+
1 / 4 * (int_t_end) ** 4
|
| 87 |
+
- 1 / 3 * (t1 + t2 + t3) * (int_t_end) ** 3
|
| 88 |
+
+ 1 / 2 * (t3 * t2 + t1 * t2 + t1 * t3) * int_t_end**2
|
| 89 |
+
- t1 * t2 * t3 * int_t_end
|
| 90 |
+
)
|
| 91 |
+
int4_start = (
|
| 92 |
+
1 / 4 * (int_t_start) ** 4
|
| 93 |
+
- 1 / 3 * (t1 + t2 + t3) * (int_t_start) ** 3
|
| 94 |
+
+ 1 / 2 * (t3 * t2 + t1 * t2 + t1 * t3) * int_t_start**2
|
| 95 |
+
- t1 * t2 * t3 * int_t_start
|
| 96 |
+
)
|
| 97 |
+
int4 = (int4_end - int4_start) / int4_denom
|
| 98 |
+
int_sum = int1 + int2 + int3 + int4
|
| 99 |
+
return int1 * v1 + int2 * v2 + int3 * v3 + int4 * v4, (
|
| 100 |
+
int1 / int_sum,
|
| 101 |
+
int2 / int_sum,
|
| 102 |
+
int3 / int_sum,
|
| 103 |
+
int4 / int_sum,
|
| 104 |
+
)
|
| 105 |
+
|
| 106 |
+
|
| 107 |
+
def lagrange_preint(order, pre_vs, pre_ts, int_t_start, int_t_end):
|
| 108 |
+
order = min(order, len(pre_vs), len(pre_ts))
|
| 109 |
+
if order == 1:
|
| 110 |
+
return lagrange_preint_o1(pre_ts[-1], pre_vs[-1], int_t_start, int_t_end)
|
| 111 |
+
if order == 2:
|
| 112 |
+
return lagrange_preint_o2(pre_ts[-2], pre_ts[-1], pre_vs[-2], pre_vs[-1], int_t_start, int_t_end)
|
| 113 |
+
if order == 3:
|
| 114 |
+
return lagrange_preint_o3(
|
| 115 |
+
pre_ts[-3], pre_ts[-2], pre_ts[-1], pre_vs[-3], pre_vs[-2], pre_vs[-1], int_t_start, int_t_end
|
| 116 |
+
)
|
| 117 |
+
if order == 4:
|
| 118 |
+
return larange_preint_o4(
|
| 119 |
+
pre_ts[-4], pre_ts[-3], pre_ts[-2], pre_ts[-1],
|
| 120 |
+
pre_vs[-4], pre_vs[-3], pre_vs[-2], pre_vs[-1],
|
| 121 |
+
int_t_start, int_t_end,
|
| 122 |
+
)
|
| 123 |
+
raise ValueError("Invalid order")
|
| 124 |
+
|
| 125 |
+
|
| 126 |
+
@dataclass
|
| 127 |
+
class PixelGenSchedulerOutput(BaseOutput):
|
| 128 |
+
prev_sample: torch.Tensor
|
| 129 |
+
|
| 130 |
+
|
| 131 |
+
def shift_respace_fn(t: torch.Tensor, shift: float = 1.0) -> torch.Tensor:
|
| 132 |
+
return t / (t + (1 - t) * shift)
|
| 133 |
+
|
| 134 |
+
|
| 135 |
+
class PixelGenScheduler(SchedulerMixin, ConfigMixin):
|
| 136 |
+
"""Flow-matching scheduler for PixelGen with Euler, Heun, and Adam-LM solvers."""
|
| 137 |
+
|
| 138 |
+
order = 2
|
| 139 |
+
|
| 140 |
+
@register_to_config
|
| 141 |
+
def __init__(
|
| 142 |
+
self,
|
| 143 |
+
num_train_timesteps: int = 1000,
|
| 144 |
+
t_eps: float = 5e-2,
|
| 145 |
+
solver: str = "heun",
|
| 146 |
+
timeshift: float = 1.0,
|
| 147 |
+
adam_lm_order: int = 2,
|
| 148 |
+
last_step: float | None = None,
|
| 149 |
+
):
|
| 150 |
+
del num_train_timesteps
|
| 151 |
+
if solver not in {"heun", "euler", "adam_lm"}:
|
| 152 |
+
raise ValueError("solver must be one of: 'heun', 'euler', 'adam_lm'.")
|
| 153 |
+
self.timesteps: Optional[torch.Tensor] = None
|
| 154 |
+
self.timedeltas: Optional[torch.Tensor] = None
|
| 155 |
+
self.sigmas: Optional[List[float]] = None
|
| 156 |
+
self.num_inference_steps: Optional[int] = None
|
| 157 |
+
self._step_index: Optional[int] = None
|
| 158 |
+
self.solver_coeffs: Optional[list] = None
|
| 159 |
+
self._last_step = last_step
|
| 160 |
+
|
| 161 |
+
@property
|
| 162 |
+
def init_noise_sigma(self) -> float:
|
| 163 |
+
return 1.0
|
| 164 |
+
|
| 165 |
+
def set_timesteps(
|
| 166 |
+
self,
|
| 167 |
+
num_inference_steps: int,
|
| 168 |
+
device: Union[str, torch.device, None] = None,
|
| 169 |
+
solver: Optional[str] = None,
|
| 170 |
+
timeshift: Optional[float] = None,
|
| 171 |
+
adam_lm_order: Optional[int] = None,
|
| 172 |
+
) -> None:
|
| 173 |
+
if num_inference_steps < 2:
|
| 174 |
+
raise ValueError("num_inference_steps must be >= 2.")
|
| 175 |
+
|
| 176 |
+
if solver is not None:
|
| 177 |
+
self.register_to_config(solver=solver)
|
| 178 |
+
if timeshift is not None:
|
| 179 |
+
self.register_to_config(timeshift=timeshift)
|
| 180 |
+
if adam_lm_order is not None:
|
| 181 |
+
self.register_to_config(adam_lm_order=adam_lm_order)
|
| 182 |
+
|
| 183 |
+
last_step = self._last_step
|
| 184 |
+
if last_step is None:
|
| 185 |
+
last_step = 1.0 / num_inference_steps
|
| 186 |
+
|
| 187 |
+
self.num_inference_steps = num_inference_steps
|
| 188 |
+
timesteps = torch.linspace(0.0, 1.0 - last_step, num_inference_steps, device=device, dtype=torch.float64)
|
| 189 |
+
timesteps = torch.cat([timesteps, torch.tensor([1.0], device=device, dtype=torch.float64)], dim=0)
|
| 190 |
+
self.timesteps = shift_respace_fn(timesteps, self.config.timeshift)
|
| 191 |
+
self.timedeltas = self.timesteps[1:] - self.timesteps[:-1]
|
| 192 |
+
sigma_grid = torch.linspace(0.0, 1.0, num_inference_steps, device=device, dtype=torch.float64)
|
| 193 |
+
self.sigmas = (1.0 - sigma_grid).tolist()
|
| 194 |
+
self._step_index = 0
|
| 195 |
+
|
| 196 |
+
if self.config.solver == "adam_lm":
|
| 197 |
+
self._reparameterize_coeffs()
|
| 198 |
+
|
| 199 |
+
def _reparameterize_coeffs(self) -> None:
|
| 200 |
+
solver_coeffs = [[] for _ in range(self.num_inference_steps)]
|
| 201 |
+
for i in range(self.num_inference_steps):
|
| 202 |
+
pre_vs = [1.0] * (i + 1)
|
| 203 |
+
pre_ts = self.timesteps[: i + 1]
|
| 204 |
+
int_t_start = self.timesteps[i]
|
| 205 |
+
int_t_end = self.timesteps[i + 1]
|
| 206 |
+
order = min(self.config.adam_lm_order, i + 1)
|
| 207 |
+
_, coeffs = lagrange_preint(order, pre_vs, pre_ts.tolist(), float(int_t_start), float(int_t_end))
|
| 208 |
+
solver_coeffs[i] = coeffs
|
| 209 |
+
self.solver_coeffs = solver_coeffs
|
| 210 |
+
|
| 211 |
+
def scale_model_input(self, sample: torch.Tensor, timestep: Union[float, torch.Tensor]) -> torch.Tensor:
|
| 212 |
+
del timestep
|
| 213 |
+
return sample
|
| 214 |
+
|
| 215 |
+
def _resolve_step_index(self, timestep: Union[float, torch.Tensor, None]) -> int:
|
| 216 |
+
if self._step_index is not None:
|
| 217 |
+
return self._step_index
|
| 218 |
+
if self.timesteps is None:
|
| 219 |
+
raise ValueError("Call `set_timesteps` before `step`.")
|
| 220 |
+
if timestep is None:
|
| 221 |
+
return 0
|
| 222 |
+
t_value = float(timestep) if not isinstance(timestep, torch.Tensor) else float(timestep.flatten()[0])
|
| 223 |
+
matches = (self.timesteps - t_value).abs() < 1e-6
|
| 224 |
+
if matches.any():
|
| 225 |
+
return int(matches.nonzero(as_tuple=False)[0].item())
|
| 226 |
+
return 0
|
| 227 |
+
|
| 228 |
+
def step(
|
| 229 |
+
self,
|
| 230 |
+
model_output: torch.Tensor,
|
| 231 |
+
timestep: Union[float, torch.Tensor, None],
|
| 232 |
+
sample: torch.Tensor,
|
| 233 |
+
model_output_next: Optional[torch.Tensor] = None,
|
| 234 |
+
return_dict: bool = True,
|
| 235 |
+
) -> Union[PixelGenSchedulerOutput, Tuple[torch.Tensor]]:
|
| 236 |
+
if self.timesteps is None:
|
| 237 |
+
raise ValueError("Call `set_timesteps` before `step`.")
|
| 238 |
+
|
| 239 |
+
step_index = self._resolve_step_index(timestep)
|
| 240 |
+
if step_index >= len(self.timesteps) - 1:
|
| 241 |
+
raise ValueError("Scheduler has already reached the final timestep.")
|
| 242 |
+
|
| 243 |
+
t = self.timesteps[step_index]
|
| 244 |
+
t_next = self.timesteps[step_index + 1]
|
| 245 |
+
dt = (t_next - t).to(dtype=sample.dtype)
|
| 246 |
+
|
| 247 |
+
if self.config.solver == "heun" and model_output_next is not None:
|
| 248 |
+
prev_sample = sample + dt * 0.5 * (model_output + model_output_next)
|
| 249 |
+
else:
|
| 250 |
+
prev_sample = sample + dt * model_output
|
| 251 |
+
|
| 252 |
+
self._step_index = step_index + 1
|
| 253 |
+
|
| 254 |
+
if not return_dict:
|
| 255 |
+
return (prev_sample,)
|
| 256 |
+
return PixelGenSchedulerOutput(prev_sample=prev_sample)
|
| 257 |
+
|
| 258 |
+
def velocity_from_prediction(
|
| 259 |
+
self,
|
| 260 |
+
sample: torch.Tensor,
|
| 261 |
+
x_pred: torch.Tensor,
|
| 262 |
+
timestep: Union[float, torch.Tensor],
|
| 263 |
+
) -> torch.Tensor:
|
| 264 |
+
t = torch.as_tensor(timestep, device=sample.device, dtype=torch.float64)
|
| 265 |
+
while t.ndim < sample.ndim:
|
| 266 |
+
t = t.unsqueeze(-1)
|
| 267 |
+
denom = (1.0 - t).clamp_min(self.config.t_eps)
|
| 268 |
+
velocity = (x_pred.to(torch.float64) - sample.to(torch.float64)) / denom
|
| 269 |
+
return velocity.to(dtype=sample.dtype)
|
| 270 |
+
|
| 271 |
+
def apply_adam_lm_step(
|
| 272 |
+
self,
|
| 273 |
+
sample: torch.Tensor,
|
| 274 |
+
velocity_history: list[torch.Tensor],
|
| 275 |
+
step_index: int,
|
| 276 |
+
) -> torch.Tensor:
|
| 277 |
+
if self.solver_coeffs is None:
|
| 278 |
+
raise ValueError("Adam-LM coefficients not initialized. Call set_timesteps with solver='adam_lm'.")
|
| 279 |
+
coeffs = self.solver_coeffs[step_index]
|
| 280 |
+
order = len(coeffs)
|
| 281 |
+
v = torch.zeros_like(sample, dtype=torch.float64)
|
| 282 |
+
for j, coeff in enumerate(coeffs):
|
| 283 |
+
v = v + coeff * velocity_history[-order:][j].to(torch.float64)
|
| 284 |
+
dt = self.timedeltas[step_index].to(device=sample.device, dtype=torch.float64)
|
| 285 |
+
return (sample.to(torch.float64) + dt * v).to(dtype=sample.dtype)
|
PixelGen-XXL-16-512-t2i/text_encoder/config.json
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"architectures": [
|
| 3 |
+
"Qwen3Model"
|
| 4 |
+
],
|
| 5 |
+
"attention_bias": false,
|
| 6 |
+
"attention_dropout": 0.0,
|
| 7 |
+
"bos_token_id": 151643,
|
| 8 |
+
"dtype": "bfloat16",
|
| 9 |
+
"eos_token_id": 151645,
|
| 10 |
+
"head_dim": 128,
|
| 11 |
+
"hidden_act": "silu",
|
| 12 |
+
"hidden_size": 2048,
|
| 13 |
+
"initializer_range": 0.02,
|
| 14 |
+
"intermediate_size": 6144,
|
| 15 |
+
"layer_types": [
|
| 16 |
+
"full_attention",
|
| 17 |
+
"full_attention",
|
| 18 |
+
"full_attention",
|
| 19 |
+
"full_attention",
|
| 20 |
+
"full_attention",
|
| 21 |
+
"full_attention",
|
| 22 |
+
"full_attention",
|
| 23 |
+
"full_attention",
|
| 24 |
+
"full_attention",
|
| 25 |
+
"full_attention",
|
| 26 |
+
"full_attention",
|
| 27 |
+
"full_attention",
|
| 28 |
+
"full_attention",
|
| 29 |
+
"full_attention",
|
| 30 |
+
"full_attention",
|
| 31 |
+
"full_attention",
|
| 32 |
+
"full_attention",
|
| 33 |
+
"full_attention",
|
| 34 |
+
"full_attention",
|
| 35 |
+
"full_attention",
|
| 36 |
+
"full_attention",
|
| 37 |
+
"full_attention",
|
| 38 |
+
"full_attention",
|
| 39 |
+
"full_attention",
|
| 40 |
+
"full_attention",
|
| 41 |
+
"full_attention",
|
| 42 |
+
"full_attention",
|
| 43 |
+
"full_attention"
|
| 44 |
+
],
|
| 45 |
+
"max_position_embeddings": 40960,
|
| 46 |
+
"max_window_layers": 28,
|
| 47 |
+
"model_type": "qwen3",
|
| 48 |
+
"num_attention_heads": 16,
|
| 49 |
+
"num_hidden_layers": 28,
|
| 50 |
+
"num_key_value_heads": 8,
|
| 51 |
+
"pad_token_id": null,
|
| 52 |
+
"rms_norm_eps": 1e-06,
|
| 53 |
+
"rope_parameters": {
|
| 54 |
+
"rope_theta": 1000000,
|
| 55 |
+
"rope_type": "default"
|
| 56 |
+
},
|
| 57 |
+
"sliding_window": null,
|
| 58 |
+
"tie_word_embeddings": true,
|
| 59 |
+
"transformers_version": "5.0.0",
|
| 60 |
+
"use_cache": true,
|
| 61 |
+
"use_sliding_window": false,
|
| 62 |
+
"vocab_size": 151936
|
| 63 |
+
}
|
PixelGen-XXL-16-512-t2i/text_encoder/model.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:fbbfc1bd7cdbaa8f0759d8d3c00d8a91bf9af50093fc3c7204c1e3e2c5fe3723
|
| 3 |
+
size 3441183752
|
PixelGen-XXL-16-512-t2i/tokenizer/chat_template.jinja
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{%- if tools %}
|
| 2 |
+
{{- '<|im_start|>system\n' }}
|
| 3 |
+
{%- if messages[0].role == 'system' %}
|
| 4 |
+
{{- messages[0].content + '\n\n' }}
|
| 5 |
+
{%- endif %}
|
| 6 |
+
{{- "# Tools\n\nYou may call one or more functions to assist with the user query.\n\nYou are provided with function signatures within <tools></tools> XML tags:\n<tools>" }}
|
| 7 |
+
{%- for tool in tools %}
|
| 8 |
+
{{- "\n" }}
|
| 9 |
+
{{- tool | tojson }}
|
| 10 |
+
{%- endfor %}
|
| 11 |
+
{{- "\n</tools>\n\nFor each function call, return a json object with function name and arguments within <tool_call></tool_call> XML tags:\n<tool_call>\n{\"name\": <function-name>, \"arguments\": <args-json-object>}\n</tool_call><|im_end|>\n" }}
|
| 12 |
+
{%- else %}
|
| 13 |
+
{%- if messages[0].role == 'system' %}
|
| 14 |
+
{{- '<|im_start|>system\n' + messages[0].content + '<|im_end|>\n' }}
|
| 15 |
+
{%- endif %}
|
| 16 |
+
{%- endif %}
|
| 17 |
+
{%- set ns = namespace(multi_step_tool=true, last_query_index=messages|length - 1) %}
|
| 18 |
+
{%- for message in messages[::-1] %}
|
| 19 |
+
{%- set index = (messages|length - 1) - loop.index0 %}
|
| 20 |
+
{%- if ns.multi_step_tool and message.role == "user" and message.content is string and not(message.content.startswith('<tool_response>') and message.content.endswith('</tool_response>')) %}
|
| 21 |
+
{%- set ns.multi_step_tool = false %}
|
| 22 |
+
{%- set ns.last_query_index = index %}
|
| 23 |
+
{%- endif %}
|
| 24 |
+
{%- endfor %}
|
| 25 |
+
{%- for message in messages %}
|
| 26 |
+
{%- if message.content is string %}
|
| 27 |
+
{%- set content = message.content %}
|
| 28 |
+
{%- else %}
|
| 29 |
+
{%- set content = '' %}
|
| 30 |
+
{%- endif %}
|
| 31 |
+
{%- if (message.role == "user") or (message.role == "system" and not loop.first) %}
|
| 32 |
+
{{- '<|im_start|>' + message.role + '\n' + content + '<|im_end|>' + '\n' }}
|
| 33 |
+
{%- elif message.role == "assistant" %}
|
| 34 |
+
{%- set reasoning_content = '' %}
|
| 35 |
+
{%- if message.reasoning_content is string %}
|
| 36 |
+
{%- set reasoning_content = message.reasoning_content %}
|
| 37 |
+
{%- else %}
|
| 38 |
+
{%- if '</think>' in content %}
|
| 39 |
+
{%- set reasoning_content = content.split('</think>')[0].rstrip('\n').split('<think>')[-1].lstrip('\n') %}
|
| 40 |
+
{%- set content = content.split('</think>')[-1].lstrip('\n') %}
|
| 41 |
+
{%- endif %}
|
| 42 |
+
{%- endif %}
|
| 43 |
+
{%- if loop.index0 > ns.last_query_index %}
|
| 44 |
+
{%- if loop.last or (not loop.last and reasoning_content) %}
|
| 45 |
+
{{- '<|im_start|>' + message.role + '\n<think>\n' + reasoning_content.strip('\n') + '\n</think>\n\n' + content.lstrip('\n') }}
|
| 46 |
+
{%- else %}
|
| 47 |
+
{{- '<|im_start|>' + message.role + '\n' + content }}
|
| 48 |
+
{%- endif %}
|
| 49 |
+
{%- else %}
|
| 50 |
+
{{- '<|im_start|>' + message.role + '\n' + content }}
|
| 51 |
+
{%- endif %}
|
| 52 |
+
{%- if message.tool_calls %}
|
| 53 |
+
{%- for tool_call in message.tool_calls %}
|
| 54 |
+
{%- if (loop.first and content) or (not loop.first) %}
|
| 55 |
+
{{- '\n' }}
|
| 56 |
+
{%- endif %}
|
| 57 |
+
{%- if tool_call.function %}
|
| 58 |
+
{%- set tool_call = tool_call.function %}
|
| 59 |
+
{%- endif %}
|
| 60 |
+
{{- '<tool_call>\n{"name": "' }}
|
| 61 |
+
{{- tool_call.name }}
|
| 62 |
+
{{- '", "arguments": ' }}
|
| 63 |
+
{%- if tool_call.arguments is string %}
|
| 64 |
+
{{- tool_call.arguments }}
|
| 65 |
+
{%- else %}
|
| 66 |
+
{{- tool_call.arguments | tojson }}
|
| 67 |
+
{%- endif %}
|
| 68 |
+
{{- '}\n</tool_call>' }}
|
| 69 |
+
{%- endfor %}
|
| 70 |
+
{%- endif %}
|
| 71 |
+
{{- '<|im_end|>\n' }}
|
| 72 |
+
{%- elif message.role == "tool" %}
|
| 73 |
+
{%- if loop.first or (messages[loop.index0 - 1].role != "tool") %}
|
| 74 |
+
{{- '<|im_start|>user' }}
|
| 75 |
+
{%- endif %}
|
| 76 |
+
{{- '\n<tool_response>\n' }}
|
| 77 |
+
{{- content }}
|
| 78 |
+
{{- '\n</tool_response>' }}
|
| 79 |
+
{%- if loop.last or (messages[loop.index0 + 1].role != "tool") %}
|
| 80 |
+
{{- '<|im_end|>\n' }}
|
| 81 |
+
{%- endif %}
|
| 82 |
+
{%- endif %}
|
| 83 |
+
{%- endfor %}
|
| 84 |
+
{%- if add_generation_prompt %}
|
| 85 |
+
{{- '<|im_start|>assistant\n' }}
|
| 86 |
+
{%- if enable_thinking is defined and enable_thinking is false %}
|
| 87 |
+
{{- '<think>\n\n</think>\n\n' }}
|
| 88 |
+
{%- endif %}
|
| 89 |
+
{%- endif %}
|
PixelGen-XXL-16-512-t2i/tokenizer/tokenizer.json
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:be75606093db2094d7cd20f3c2f385c212750648bd6ea4fb2bf507a6a4c55506
|
| 3 |
+
size 11422650
|
PixelGen-XXL-16-512-t2i/tokenizer/tokenizer_config.json
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"add_prefix_space": false,
|
| 3 |
+
"backend": "tokenizers",
|
| 4 |
+
"bos_token": null,
|
| 5 |
+
"clean_up_tokenization_spaces": false,
|
| 6 |
+
"eos_token": "<|im_end|>",
|
| 7 |
+
"errors": "replace",
|
| 8 |
+
"extra_special_tokens": [
|
| 9 |
+
"<|im_start|>",
|
| 10 |
+
"<|im_end|>",
|
| 11 |
+
"<|object_ref_start|>",
|
| 12 |
+
"<|object_ref_end|>",
|
| 13 |
+
"<|box_start|>",
|
| 14 |
+
"<|box_end|>",
|
| 15 |
+
"<|quad_start|>",
|
| 16 |
+
"<|quad_end|>",
|
| 17 |
+
"<|vision_start|>",
|
| 18 |
+
"<|vision_end|>",
|
| 19 |
+
"<|vision_pad|>",
|
| 20 |
+
"<|image_pad|>",
|
| 21 |
+
"<|video_pad|>"
|
| 22 |
+
],
|
| 23 |
+
"is_local": true,
|
| 24 |
+
"model_max_length": 131072,
|
| 25 |
+
"pad_token": "<|endoftext|>",
|
| 26 |
+
"split_special_tokens": false,
|
| 27 |
+
"tokenizer_class": "Qwen2Tokenizer",
|
| 28 |
+
"unk_token": null
|
| 29 |
+
}
|
PixelGen-XXL-16-512-t2i/transformer/__pycache__/transformer_jit_t2i.cpython-312.pyc
ADDED
|
Binary file (27.5 kB). View file
|
|
|
PixelGen-XXL-16-512-t2i/transformer/config.json
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"_class_name": "JiTTransformer2DT2IModel",
|
| 3 |
+
"_diffusers_version": "0.38.0",
|
| 4 |
+
"bottleneck_dim": 256,
|
| 5 |
+
"hidden_size": 1536,
|
| 6 |
+
"in_channels": 3,
|
| 7 |
+
"mlp_ratio": 4.0,
|
| 8 |
+
"model_type": "PixelGen-XXL/16-T2I",
|
| 9 |
+
"num_attention_heads": 24,
|
| 10 |
+
"num_layers": 16,
|
| 11 |
+
"num_text_layers": 4,
|
| 12 |
+
"patch_size": 16,
|
| 13 |
+
"sample_size": 512,
|
| 14 |
+
"text_embed_dim": 2048,
|
| 15 |
+
"text_max_length": 128
|
| 16 |
+
}
|
PixelGen-XXL-16-512-t2i/transformer/diffusion_pytorch_model.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:71fe40f4f443df27b5989048c151d4746f2b6f3c0b5552e7b24e46c6d4519887
|
| 3 |
+
size 4493275072
|
PixelGen-XXL-16-512-t2i/transformer/transformer_jit_t2i.py
ADDED
|
@@ -0,0 +1,390 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from __future__ import annotations
|
| 2 |
+
|
| 3 |
+
import math
|
| 4 |
+
from functools import lru_cache
|
| 5 |
+
from typing import Dict, Optional, Tuple
|
| 6 |
+
|
| 7 |
+
import numpy as np
|
| 8 |
+
import torch
|
| 9 |
+
import torch.nn as nn
|
| 10 |
+
import torch.nn.functional as F
|
| 11 |
+
from diffusers.configuration_utils import ConfigMixin, register_to_config
|
| 12 |
+
from diffusers.models.modeling_outputs import Transformer2DModelOutput
|
| 13 |
+
from diffusers.models.modeling_utils import ModelMixin
|
| 14 |
+
from diffusers.models.normalization import RMSNorm
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
PIXELGEN_T2I_PRESET_CONFIGS: Dict[str, Dict[str, object]] = {
|
| 18 |
+
"PixelGen-XXL/16-T2I": {
|
| 19 |
+
"sample_size": 512,
|
| 20 |
+
"patch_size": 16,
|
| 21 |
+
"in_channels": 3,
|
| 22 |
+
"hidden_size": 1536,
|
| 23 |
+
"num_layers": 16,
|
| 24 |
+
"num_attention_heads": 24,
|
| 25 |
+
"num_text_layers": 4,
|
| 26 |
+
"text_embed_dim": 2048,
|
| 27 |
+
"text_max_length": 128,
|
| 28 |
+
"bottleneck_dim": 256,
|
| 29 |
+
},
|
| 30 |
+
}
|
| 31 |
+
|
| 32 |
+
|
| 33 |
+
def remap_t2i_state_dict(state_dict: Dict[str, torch.Tensor]) -> Dict[str, torch.Tensor]:
|
| 34 |
+
remapped: Dict[str, torch.Tensor] = {}
|
| 35 |
+
for key, value in state_dict.items():
|
| 36 |
+
new_key = key
|
| 37 |
+
for prefix in ("transformer.", "denoiser.", "ema_denoiser."):
|
| 38 |
+
if new_key.startswith(prefix):
|
| 39 |
+
new_key = new_key[len(prefix) :]
|
| 40 |
+
break
|
| 41 |
+
new_key = new_key.replace(".adaLN_modulation.1.", ".adaLN_modulation.")
|
| 42 |
+
new_key = new_key.replace(".adaLN_modulation.0.", ".adaLN_modulation.")
|
| 43 |
+
remapped[new_key] = value
|
| 44 |
+
return remapped
|
| 45 |
+
|
| 46 |
+
|
| 47 |
+
def modulate(x, shift, scale, unsqueeze=True):
|
| 48 |
+
if unsqueeze:
|
| 49 |
+
return x * (1 + scale.unsqueeze(1)) + shift.unsqueeze(1)
|
| 50 |
+
return x * (1 + scale) + shift
|
| 51 |
+
|
| 52 |
+
|
| 53 |
+
def get_2d_sincos_pos_embed(embed_dim, grid_size):
|
| 54 |
+
grid_h = np.arange(grid_size, dtype=np.float32)
|
| 55 |
+
grid_w = np.arange(grid_size, dtype=np.float32)
|
| 56 |
+
grid = np.meshgrid(grid_w, grid_h)
|
| 57 |
+
grid = np.stack(grid, axis=0)
|
| 58 |
+
grid = grid.reshape([2, 1, grid_size, grid_size])
|
| 59 |
+
emb_h = get_1d_sincos_pos_embed_from_grid(embed_dim // 2, grid[0])
|
| 60 |
+
emb_w = get_1d_sincos_pos_embed_from_grid(embed_dim // 2, grid[1])
|
| 61 |
+
return np.concatenate([emb_h, emb_w], axis=1)
|
| 62 |
+
|
| 63 |
+
|
| 64 |
+
def get_1d_sincos_pos_embed_from_grid(embed_dim, pos):
|
| 65 |
+
omega = np.arange(embed_dim // 2, dtype=np.float64)
|
| 66 |
+
omega /= embed_dim / 2.0
|
| 67 |
+
omega = 1.0 / 10000**omega
|
| 68 |
+
pos = pos.reshape(-1)
|
| 69 |
+
out = np.einsum("m,d->md", pos, omega)
|
| 70 |
+
return np.concatenate([np.sin(out), np.cos(out)], axis=1)
|
| 71 |
+
|
| 72 |
+
|
| 73 |
+
def precompute_freqs_cis_2d(dim: int, height: int, width: int, theta: float = 10000.0, scale=1.0):
|
| 74 |
+
if isinstance(scale, float):
|
| 75 |
+
scale = (scale, scale)
|
| 76 |
+
x_pos = torch.linspace(0, height * scale[0], width)
|
| 77 |
+
y_pos = torch.linspace(0, width * scale[1], height)
|
| 78 |
+
y_pos, x_pos = torch.meshgrid(y_pos, x_pos, indexing="ij")
|
| 79 |
+
y_pos = y_pos.reshape(-1)
|
| 80 |
+
x_pos = x_pos.reshape(-1)
|
| 81 |
+
freqs = 1.0 / (theta ** (torch.arange(0, dim, 4)[: (dim // 4)].float() / dim))
|
| 82 |
+
x_freqs = torch.outer(x_pos, freqs).float()
|
| 83 |
+
y_freqs = torch.outer(y_pos, freqs).float()
|
| 84 |
+
x_cis = torch.polar(torch.ones_like(x_freqs), x_freqs)
|
| 85 |
+
y_cis = torch.polar(torch.ones_like(y_freqs), y_freqs)
|
| 86 |
+
freqs_cis = torch.cat([x_cis.unsqueeze(dim=-1), y_cis.unsqueeze(dim=-1)], dim=-1)
|
| 87 |
+
return freqs_cis.reshape(height * width, -1)
|
| 88 |
+
|
| 89 |
+
|
| 90 |
+
def apply_rotary_emb(q, k, freqs_cis):
|
| 91 |
+
freqs_cis = freqs_cis[None, None, :, :]
|
| 92 |
+
q_ = torch.view_as_complex(q.float().reshape(*q.shape[:-1], -1, 2))
|
| 93 |
+
k_ = torch.view_as_complex(k.float().reshape(*k.shape[:-1], -1, 2))
|
| 94 |
+
q_out = torch.view_as_real(q_ * freqs_cis).flatten(3)
|
| 95 |
+
k_out = torch.view_as_real(k_ * freqs_cis).flatten(3)
|
| 96 |
+
return q_out.type_as(q), k_out.type_as(k)
|
| 97 |
+
|
| 98 |
+
|
| 99 |
+
class JiTT2ITimestepEmbedder(nn.Module):
|
| 100 |
+
def __init__(self, hidden_size, frequency_embedding_size=256):
|
| 101 |
+
super().__init__()
|
| 102 |
+
self.mlp = nn.Sequential(
|
| 103 |
+
nn.Linear(frequency_embedding_size, hidden_size, bias=True),
|
| 104 |
+
nn.SiLU(),
|
| 105 |
+
nn.Linear(hidden_size, hidden_size, bias=True),
|
| 106 |
+
)
|
| 107 |
+
self.frequency_embedding_size = frequency_embedding_size
|
| 108 |
+
|
| 109 |
+
@staticmethod
|
| 110 |
+
def timestep_embedding(t, dim, max_period=10000):
|
| 111 |
+
half = dim // 2
|
| 112 |
+
freqs = torch.exp(-math.log(max_period) * torch.arange(start=0, end=half, dtype=torch.float32) / half).to(
|
| 113 |
+
device=t.device
|
| 114 |
+
)
|
| 115 |
+
args = t[:, None].float() * freqs[None]
|
| 116 |
+
embedding = torch.cat([torch.cos(args), torch.sin(args)], dim=-1)
|
| 117 |
+
if dim % 2:
|
| 118 |
+
embedding = torch.cat([embedding, torch.zeros_like(embedding[:, :1])], dim=-1)
|
| 119 |
+
return embedding
|
| 120 |
+
|
| 121 |
+
def forward(self, t, dtype=None):
|
| 122 |
+
t_freq = self.timestep_embedding(t, self.frequency_embedding_size)
|
| 123 |
+
if dtype is not None:
|
| 124 |
+
t_freq = t_freq.to(dtype=dtype)
|
| 125 |
+
return self.mlp(t_freq)
|
| 126 |
+
|
| 127 |
+
|
| 128 |
+
class JiTT2ITextEmbedder(nn.Module):
|
| 129 |
+
def __init__(self, text_embed_dim, hidden_size, bias=True):
|
| 130 |
+
super().__init__()
|
| 131 |
+
self.proj = nn.Linear(text_embed_dim, hidden_size, bias=bias)
|
| 132 |
+
self.norm = RMSNorm(hidden_size, eps=1e-6)
|
| 133 |
+
|
| 134 |
+
def forward(self, y):
|
| 135 |
+
return self.norm(self.proj(y))
|
| 136 |
+
|
| 137 |
+
|
| 138 |
+
class JiTT2IBottleneckEmbed(nn.Module):
|
| 139 |
+
def __init__(self, in_chans, embed_dim, bottleneck_dim, bias=True):
|
| 140 |
+
super().__init__()
|
| 141 |
+
self.proj1 = nn.Linear(in_chans, bottleneck_dim, bias=False)
|
| 142 |
+
self.proj2 = nn.Linear(bottleneck_dim, embed_dim, bias=bias)
|
| 143 |
+
|
| 144 |
+
def forward(self, x):
|
| 145 |
+
return self.proj2(self.proj1(x))
|
| 146 |
+
|
| 147 |
+
|
| 148 |
+
class JiTT2IAttention(nn.Module):
|
| 149 |
+
def __init__(self, dim, num_heads=8, qkv_bias=False, attn_drop=0.0, proj_drop=0.0, eps=1e-6):
|
| 150 |
+
super().__init__()
|
| 151 |
+
self.num_heads = num_heads
|
| 152 |
+
head_dim = dim // num_heads
|
| 153 |
+
self.qkv_x = nn.Linear(dim, dim * 3, bias=qkv_bias)
|
| 154 |
+
self.kv_y = nn.Linear(dim, dim * 2, bias=qkv_bias)
|
| 155 |
+
self.q_norm = RMSNorm(head_dim, eps=eps)
|
| 156 |
+
self.k_norm = RMSNorm(head_dim, eps=eps)
|
| 157 |
+
self.attn_drop = attn_drop
|
| 158 |
+
self.proj = nn.Linear(dim, dim)
|
| 159 |
+
self.proj_drop = nn.Dropout(proj_drop)
|
| 160 |
+
|
| 161 |
+
def forward(self, x, y, pos):
|
| 162 |
+
batch_size, num_tokens, channels = x.shape
|
| 163 |
+
qkv_x = self.qkv_x(x).reshape(batch_size, num_tokens, 3, self.num_heads, channels // self.num_heads).permute(2, 0, 3, 1, 4)
|
| 164 |
+
q, kx, vx = qkv_x[0], qkv_x[1], qkv_x[2]
|
| 165 |
+
q = self.q_norm(q.contiguous())
|
| 166 |
+
kx = self.k_norm(kx.contiguous())
|
| 167 |
+
q, kx = apply_rotary_emb(q, kx, freqs_cis=pos)
|
| 168 |
+
kv_y = self.kv_y(y).reshape(batch_size, -1, 2, self.num_heads, channels // self.num_heads).permute(2, 0, 3, 1, 4)
|
| 169 |
+
ky, vy = kv_y[0], kv_y[1]
|
| 170 |
+
ky = self.k_norm(ky.contiguous())
|
| 171 |
+
k = torch.cat([kx, ky], dim=2)
|
| 172 |
+
v = torch.cat([vx, vy], dim=2)
|
| 173 |
+
dropout_p = self.attn_drop if self.training else 0.0
|
| 174 |
+
out = F.scaled_dot_product_attention(q, k, v, dropout_p=dropout_p)
|
| 175 |
+
out = out.transpose(1, 2).reshape(batch_size, num_tokens, channels)
|
| 176 |
+
return self.proj_drop(self.proj(out))
|
| 177 |
+
|
| 178 |
+
|
| 179 |
+
class JiTT2ITextRefineAttention(nn.Module):
|
| 180 |
+
def __init__(self, dim, num_heads=8, qkv_bias=False, attn_drop=0.0, proj_drop=0.0, eps=1e-6):
|
| 181 |
+
super().__init__()
|
| 182 |
+
self.num_heads = num_heads
|
| 183 |
+
head_dim = dim // num_heads
|
| 184 |
+
self.qkv = nn.Linear(dim, dim * 3, bias=qkv_bias)
|
| 185 |
+
self.q_norm = RMSNorm(head_dim, eps=eps)
|
| 186 |
+
self.k_norm = RMSNorm(head_dim, eps=eps)
|
| 187 |
+
self.attn_drop = attn_drop
|
| 188 |
+
self.proj = nn.Linear(dim, dim)
|
| 189 |
+
self.proj_drop = nn.Dropout(proj_drop)
|
| 190 |
+
|
| 191 |
+
def forward(self, x):
|
| 192 |
+
batch_size, num_tokens, channels = x.shape
|
| 193 |
+
qkv = self.qkv(x).reshape(batch_size, num_tokens, 3, self.num_heads, channels // self.num_heads).permute(2, 0, 3, 1, 4)
|
| 194 |
+
q, k, v = qkv[0], qkv[1], qkv[2]
|
| 195 |
+
q = self.q_norm(q)
|
| 196 |
+
k = self.k_norm(k)
|
| 197 |
+
dropout_p = self.attn_drop if self.training else 0.0
|
| 198 |
+
out = F.scaled_dot_product_attention(q, k, v, dropout_p=dropout_p)
|
| 199 |
+
out = out.transpose(1, 2).reshape(batch_size, num_tokens, channels)
|
| 200 |
+
return self.proj_drop(self.proj(out))
|
| 201 |
+
|
| 202 |
+
|
| 203 |
+
class JiTT2ISwiGLU(nn.Module):
|
| 204 |
+
def __init__(self, dim, hidden_dim, drop=0.0, bias=False):
|
| 205 |
+
super().__init__()
|
| 206 |
+
self.w12 = nn.Linear(dim, 2 * hidden_dim, bias=bias)
|
| 207 |
+
self.w3 = nn.Linear(hidden_dim, dim, bias=bias)
|
| 208 |
+
self.ffn_dropout = nn.Dropout(drop)
|
| 209 |
+
|
| 210 |
+
def forward(self, x):
|
| 211 |
+
x12 = self.w12(x)
|
| 212 |
+
x1, x2 = x12.chunk(2, dim=-1)
|
| 213 |
+
return self.w3(self.ffn_dropout(F.silu(x1) * x2))
|
| 214 |
+
|
| 215 |
+
|
| 216 |
+
class JiTT2IBlock(nn.Module):
|
| 217 |
+
def __init__(self, hidden_size, num_heads, mlp_ratio=4.0, eps=1e-6):
|
| 218 |
+
super().__init__()
|
| 219 |
+
self.norm1 = RMSNorm(hidden_size, eps=eps)
|
| 220 |
+
self.attn = JiTT2IAttention(hidden_size, num_heads=num_heads, eps=eps)
|
| 221 |
+
self.norm2 = RMSNorm(hidden_size, eps=eps)
|
| 222 |
+
self.mlp = JiTT2ISwiGLU(hidden_size, int(hidden_size * mlp_ratio))
|
| 223 |
+
self.adaLN_modulation = nn.Linear(hidden_size, 6 * hidden_size, bias=True)
|
| 224 |
+
|
| 225 |
+
def forward(self, x, y, c, pos):
|
| 226 |
+
shift_msa, scale_msa, gate_msa, shift_mlp, scale_mlp, gate_mlp = self.adaLN_modulation(c).chunk(6, dim=-1)
|
| 227 |
+
x = x + gate_msa * self.attn(modulate(self.norm1(x), shift_msa, scale_msa, unsqueeze=False), y, pos)
|
| 228 |
+
x = x + gate_mlp * self.mlp(modulate(self.norm2(x), shift_mlp, scale_mlp, unsqueeze=False))
|
| 229 |
+
return x
|
| 230 |
+
|
| 231 |
+
|
| 232 |
+
class JiTT2ITextRefineBlock(nn.Module):
|
| 233 |
+
def __init__(self, hidden_size, num_heads, mlp_ratio=4.0, eps=1e-6):
|
| 234 |
+
super().__init__()
|
| 235 |
+
self.norm1 = RMSNorm(hidden_size, eps=eps)
|
| 236 |
+
self.attn = JiTT2ITextRefineAttention(hidden_size, num_heads=num_heads, eps=eps)
|
| 237 |
+
self.norm2 = RMSNorm(hidden_size, eps=eps)
|
| 238 |
+
self.mlp = JiTT2ISwiGLU(hidden_size, int(hidden_size * mlp_ratio))
|
| 239 |
+
self.adaLN_modulation = nn.Linear(hidden_size, 6 * hidden_size, bias=True)
|
| 240 |
+
|
| 241 |
+
def forward(self, x, c):
|
| 242 |
+
shift_msa, scale_msa, gate_msa, shift_mlp, scale_mlp, gate_mlp = self.adaLN_modulation(c).chunk(6, dim=-1)
|
| 243 |
+
x = x + gate_msa * self.attn(modulate(self.norm1(x), shift_msa, scale_msa, unsqueeze=False))
|
| 244 |
+
x = x + gate_mlp * self.mlp(modulate(self.norm2(x), shift_mlp, scale_mlp, unsqueeze=False))
|
| 245 |
+
return x
|
| 246 |
+
|
| 247 |
+
|
| 248 |
+
class JiTT2IFinalLayer(nn.Module):
|
| 249 |
+
def __init__(self, hidden_size, out_channels):
|
| 250 |
+
super().__init__()
|
| 251 |
+
self.norm_final = nn.LayerNorm(hidden_size, elementwise_affine=False, eps=1e-6)
|
| 252 |
+
self.linear = nn.Linear(hidden_size, out_channels, bias=True)
|
| 253 |
+
|
| 254 |
+
def forward(self, x):
|
| 255 |
+
return self.linear(self.norm_final(x))
|
| 256 |
+
|
| 257 |
+
|
| 258 |
+
class JiTTransformer2DT2IModel(ModelMixin, ConfigMixin):
|
| 259 |
+
_supports_gradient_checkpointing = True
|
| 260 |
+
|
| 261 |
+
@register_to_config
|
| 262 |
+
def __init__(
|
| 263 |
+
self,
|
| 264 |
+
sample_size: int = 512,
|
| 265 |
+
patch_size: int = 16,
|
| 266 |
+
in_channels: int = 3,
|
| 267 |
+
hidden_size: int = 1536,
|
| 268 |
+
num_layers: int = 16,
|
| 269 |
+
num_attention_heads: int = 24,
|
| 270 |
+
num_text_layers: int = 4,
|
| 271 |
+
text_embed_dim: int = 2048,
|
| 272 |
+
text_max_length: int = 128,
|
| 273 |
+
bottleneck_dim: int = 256,
|
| 274 |
+
mlp_ratio: float = 4.0,
|
| 275 |
+
model_type: str | None = None,
|
| 276 |
+
):
|
| 277 |
+
super().__init__()
|
| 278 |
+
if model_type in PIXELGEN_T2I_PRESET_CONFIGS:
|
| 279 |
+
preset = PIXELGEN_T2I_PRESET_CONFIGS[model_type]
|
| 280 |
+
sample_size = int(preset["sample_size"])
|
| 281 |
+
patch_size = int(preset["patch_size"])
|
| 282 |
+
in_channels = int(preset["in_channels"])
|
| 283 |
+
hidden_size = int(preset["hidden_size"])
|
| 284 |
+
num_layers = int(preset["num_layers"])
|
| 285 |
+
num_attention_heads = int(preset["num_attention_heads"])
|
| 286 |
+
num_text_layers = int(preset["num_text_layers"])
|
| 287 |
+
text_embed_dim = int(preset["text_embed_dim"])
|
| 288 |
+
text_max_length = int(preset["text_max_length"])
|
| 289 |
+
bottleneck_dim = int(preset["bottleneck_dim"])
|
| 290 |
+
|
| 291 |
+
self.sample_size = sample_size
|
| 292 |
+
self.patch_size = patch_size
|
| 293 |
+
self.in_channels = in_channels
|
| 294 |
+
self.out_channels = in_channels
|
| 295 |
+
self.hidden_size = hidden_size
|
| 296 |
+
self.gradient_checkpointing = False
|
| 297 |
+
|
| 298 |
+
patch_dim = in_channels * patch_size * patch_size
|
| 299 |
+
self.x_embedder = JiTT2IBottleneckEmbed(patch_dim, hidden_size, bottleneck_dim)
|
| 300 |
+
self.t_embedder = JiTT2ITimestepEmbedder(hidden_size)
|
| 301 |
+
self.y_embedder = JiTT2ITextEmbedder(text_embed_dim, hidden_size)
|
| 302 |
+
|
| 303 |
+
self.num_patches = (sample_size // patch_size) ** 2
|
| 304 |
+
pos_embed = get_2d_sincos_pos_embed(hidden_size, int(self.num_patches**0.5))
|
| 305 |
+
self.register_buffer("pos_embed", torch.from_numpy(pos_embed).float().unsqueeze(0), persistent=True)
|
| 306 |
+
self.y_pos_embedding = nn.Parameter(torch.randn(1, text_max_length, hidden_size) * 0.02)
|
| 307 |
+
|
| 308 |
+
self.blocks = nn.ModuleList(
|
| 309 |
+
[JiTT2IBlock(hidden_size, num_attention_heads, mlp_ratio=mlp_ratio) for _ in range(num_layers)]
|
| 310 |
+
)
|
| 311 |
+
self.text_refine_blocks = nn.ModuleList(
|
| 312 |
+
[JiTT2ITextRefineBlock(hidden_size, num_attention_heads, mlp_ratio=mlp_ratio) for _ in range(num_text_layers)]
|
| 313 |
+
)
|
| 314 |
+
self.final_layer = JiTT2IFinalLayer(hidden_size, patch_dim)
|
| 315 |
+
self._pos_cache: Dict[Tuple[int, int], torch.Tensor] = {}
|
| 316 |
+
|
| 317 |
+
def _fetch_pos(self, height: int, width: int, device: torch.device, scale_h: float = 1.0, scale_w: float = 1.0):
|
| 318 |
+
key = (height, width, scale_h, scale_w)
|
| 319 |
+
if key not in self._pos_cache:
|
| 320 |
+
self._pos_cache[key] = precompute_freqs_cis_2d(
|
| 321 |
+
self.hidden_size // self.config.num_attention_heads,
|
| 322 |
+
height,
|
| 323 |
+
width,
|
| 324 |
+
scale=(scale_h, scale_w),
|
| 325 |
+
)
|
| 326 |
+
return self._pos_cache[key].to(device)
|
| 327 |
+
|
| 328 |
+
def unpatchify(self, x, height, width):
|
| 329 |
+
return F.fold(
|
| 330 |
+
x.transpose(1, 2).contiguous(),
|
| 331 |
+
output_size=(height, width),
|
| 332 |
+
kernel_size=self.patch_size,
|
| 333 |
+
stride=self.patch_size,
|
| 334 |
+
)
|
| 335 |
+
|
| 336 |
+
def forward(
|
| 337 |
+
self,
|
| 338 |
+
sample: torch.Tensor,
|
| 339 |
+
timestep: torch.LongTensor,
|
| 340 |
+
encoder_hidden_states: torch.Tensor,
|
| 341 |
+
scale_h: float = 1.0,
|
| 342 |
+
scale_w: float = 1.0,
|
| 343 |
+
return_dict: bool = True,
|
| 344 |
+
):
|
| 345 |
+
batch_size, _, height, width = sample.shape
|
| 346 |
+
x = F.unfold(sample, kernel_size=self.patch_size, stride=self.patch_size).transpose(1, 2)
|
| 347 |
+
xpos = self._fetch_pos(height // self.patch_size, width // self.patch_size, sample.device, scale_h, scale_w)
|
| 348 |
+
|
| 349 |
+
t = self.t_embedder(timestep.reshape(-1), dtype=sample.dtype).view(batch_size, -1, self.hidden_size)
|
| 350 |
+
y = self.y_embedder(encoder_hidden_states) + self.y_pos_embedding.to(encoder_hidden_states.dtype)
|
| 351 |
+
condition = F.silu(t)
|
| 352 |
+
|
| 353 |
+
for block in self.text_refine_blocks:
|
| 354 |
+
y = block(y, condition)
|
| 355 |
+
|
| 356 |
+
x = self.x_embedder(x) + self.pos_embed.to(x.dtype)
|
| 357 |
+
for block in self.blocks:
|
| 358 |
+
if self.training and self.gradient_checkpointing:
|
| 359 |
+
x = torch.utils.checkpoint.checkpoint(block, x, y, condition, xpos, use_reentrant=False)
|
| 360 |
+
else:
|
| 361 |
+
x = block(x, y, condition, xpos)
|
| 362 |
+
|
| 363 |
+
x = self.final_layer(x)
|
| 364 |
+
output = self.unpatchify(x, height, width)
|
| 365 |
+
|
| 366 |
+
if not return_dict:
|
| 367 |
+
return (output,)
|
| 368 |
+
return Transformer2DModelOutput(sample=output)
|
| 369 |
+
|
| 370 |
+
@classmethod
|
| 371 |
+
def from_pixelgen_checkpoint(
|
| 372 |
+
cls,
|
| 373 |
+
checkpoint_path: str,
|
| 374 |
+
weights_prefix: str = "ema_denoiser.",
|
| 375 |
+
model_type: str = "PixelGen-XXL/16-T2I",
|
| 376 |
+
map_location: str = "cpu",
|
| 377 |
+
strict: bool = False,
|
| 378 |
+
) -> Tuple["JiTTransformer2DT2IModel", Dict[str, object]]:
|
| 379 |
+
checkpoint = torch.load(checkpoint_path, map_location=map_location, weights_only=False)
|
| 380 |
+
state_dict = checkpoint.get("state_dict", checkpoint)
|
| 381 |
+
filtered = {k[len(weights_prefix) :]: v for k, v in state_dict.items() if k.startswith(weights_prefix)}
|
| 382 |
+
if not filtered:
|
| 383 |
+
raise ValueError(f"No parameters found with prefix '{weights_prefix}' in checkpoint.")
|
| 384 |
+
|
| 385 |
+
config = dict(PIXELGEN_T2I_PRESET_CONFIGS[model_type])
|
| 386 |
+
config["model_type"] = model_type
|
| 387 |
+
model = cls(**config)
|
| 388 |
+
remapped = remap_t2i_state_dict(filtered)
|
| 389 |
+
model.load_state_dict(remapped, strict=strict)
|
| 390 |
+
return model, {"checkpoint_path": checkpoint_path, "model_type": model_type}
|
README.md
ADDED
|
@@ -0,0 +1,193 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
license: mit
|
| 3 |
+
library_name: diffusers
|
| 4 |
+
pipeline_tag: text-to-image
|
| 5 |
+
tags:
|
| 6 |
+
- diffusers
|
| 7 |
+
- image-generation
|
| 8 |
+
- class-conditional
|
| 9 |
+
- text-to-image
|
| 10 |
+
- imagenet
|
| 11 |
+
- pixelgen
|
| 12 |
+
- flow-matching
|
| 13 |
+
- pixel-space
|
| 14 |
+
- jit
|
| 15 |
+
widget:
|
| 16 |
+
- text: golden retriever
|
| 17 |
+
output:
|
| 18 |
+
url: PixelGen-XL-16-256/demo.png
|
| 19 |
+
language:
|
| 20 |
+
- en
|
| 21 |
+
---
|
| 22 |
+
|
| 23 |
+
# BiliSakura/PixelGen-diffusers
|
| 24 |
+
|
| 25 |
+
Self-contained PixelGen checkpoints for Hugging Face diffusers. Each variant folder ships its own pipeline code, component modules, and weights.
|
| 26 |
+
|
| 27 |
+
Converted from upstream PixelGen checkpoints using [PixelGen-diffusers](https://github.com/Bili-Sakura/Visual-Generative-Foundation-Model-Collection/tree/main/libs/PixelGen-diffusers) in [Visual-Generative-Foundation-Model-Collection](https://github.com/Bili-Sakura/Visual-Generative-Foundation-Model-Collection).
|
| 28 |
+
|
| 29 |
+
## Available checkpoints
|
| 30 |
+
|
| 31 |
+
| Subfolder | Pipeline | Task | Resolution | Model type |
|
| 32 |
+
| --- | --- | --- | ---: | --- |
|
| 33 |
+
| [`PixelGen-XL-16-256/`](PixelGen-XL-16-256/) | `PixelGenC2IPipeline` | class-to-image | 256Γ256 | PixelGen-XL/16 |
|
| 34 |
+
| [`PixelGen-XXL-16-512-t2i/`](PixelGen-XXL-16-512-t2i/) | `PixelGenT2IPipeline` | text-to-image | 512Γ512 | PixelGen-XXL/16-T2I |
|
| 35 |
+
|
| 36 |
+
## Repo layout
|
| 37 |
+
|
| 38 |
+
```text
|
| 39 |
+
BiliSakura/PixelGen-diffusers/
|
| 40 |
+
βββ README.md
|
| 41 |
+
βββ PixelGen-XL-16-256/
|
| 42 |
+
β βββ pipeline.py
|
| 43 |
+
β βββ model_index.json
|
| 44 |
+
β βββ demo.png
|
| 45 |
+
β βββ scheduler/
|
| 46 |
+
β β βββ scheduler_config.json
|
| 47 |
+
β β βββ scheduling_pixelgen.py
|
| 48 |
+
β βββ transformer/
|
| 49 |
+
β βββ config.json
|
| 50 |
+
β βββ transformer_jit.py
|
| 51 |
+
βββ PixelGen-XXL-16-512-t2i/
|
| 52 |
+
βββ pipeline.py
|
| 53 |
+
βββ model_index.json
|
| 54 |
+
βββ conversion_metadata.json
|
| 55 |
+
βββ scheduler/
|
| 56 |
+
β βββ scheduler_config.json
|
| 57 |
+
β βββ scheduling_pixelgen.py
|
| 58 |
+
βββ text_encoder/
|
| 59 |
+
βββ tokenizer/
|
| 60 |
+
βββ transformer/
|
| 61 |
+
βββ config.json
|
| 62 |
+
βββ diffusion_pytorch_model.safetensors
|
| 63 |
+
βββ transformer_jit_t2i.py
|
| 64 |
+
```
|
| 65 |
+
|
| 66 |
+
Each class-conditional variant is self-contained: load with `custom_pipeline=.../pipeline.py` and `trust_remote_code=True`. PixelGen denoises directly in pixel space (no VAE).
|
| 67 |
+
|
| 68 |
+
## ImageNet class labels
|
| 69 |
+
|
| 70 |
+
For [`PixelGen-XL-16-256/`](PixelGen-XL-16-256/), `id2label` is embedded in `model_index.json` (DiT-style).
|
| 71 |
+
|
| 72 |
+
- `pipe.id2label` β inspect id β English label correspondence
|
| 73 |
+
- `pipe.labels` β reverse map (English synonym β id)
|
| 74 |
+
- `pipe.get_label_ids("golden retriever")`
|
| 75 |
+
- `pipe(class_labels="golden retriever", ...)` β string labels resolved automatically
|
| 76 |
+
|
| 77 |
+
## Demo
|
| 78 |
+
|
| 79 |
+

|
| 80 |
+
|
| 81 |
+
Class 207 β golden retriever, 256Γ256, 50 steps, `guidance_scale=2.25`, Heun solver, `timeshift=2.0`.
|
| 82 |
+
|
| 83 |
+
## Load from Hugging Face
|
| 84 |
+
|
| 85 |
+
### Class-to-image (`PixelGen-XL-16-256`)
|
| 86 |
+
|
| 87 |
+
```python
|
| 88 |
+
import torch
|
| 89 |
+
from diffusers import DiffusionPipeline
|
| 90 |
+
|
| 91 |
+
pipe = DiffusionPipeline.from_pretrained(
|
| 92 |
+
"BiliSakura/PixelGen-diffusers/PixelGen-XL-16-256",
|
| 93 |
+
trust_remote_code=True,
|
| 94 |
+
torch_dtype=torch.bfloat16,
|
| 95 |
+
).to("cuda")
|
| 96 |
+
|
| 97 |
+
print(pipe.id2label[207])
|
| 98 |
+
print(pipe.get_label_ids("golden retriever"))
|
| 99 |
+
|
| 100 |
+
generator = torch.Generator(device="cuda").manual_seed(0)
|
| 101 |
+
images = pipe(
|
| 102 |
+
class_labels="golden retriever",
|
| 103 |
+
num_inference_steps=50,
|
| 104 |
+
guidance_scale=2.25,
|
| 105 |
+
generator=generator,
|
| 106 |
+
).images
|
| 107 |
+
```
|
| 108 |
+
|
| 109 |
+
### Text-to-image (`PixelGen-XXL-16-512-t2i`)
|
| 110 |
+
|
| 111 |
+
Uses a bundled Qwen3 text encoder when `text_encoder/` is present; otherwise downloads from the path recorded in `conversion_metadata.json`.
|
| 112 |
+
|
| 113 |
+
```python
|
| 114 |
+
import torch
|
| 115 |
+
from diffusers import DiffusionPipeline
|
| 116 |
+
|
| 117 |
+
pipe = DiffusionPipeline.from_pretrained(
|
| 118 |
+
"BiliSakura/PixelGen-diffusers/PixelGen-XXL-16-512-t2i",
|
| 119 |
+
trust_remote_code=True,
|
| 120 |
+
torch_dtype=torch.bfloat16,
|
| 121 |
+
)
|
| 122 |
+
|
| 123 |
+
generator = torch.Generator(device="cuda").manual_seed(42)
|
| 124 |
+
images = pipe(
|
| 125 |
+
prompt="A golden retriever playing in a sunny garden",
|
| 126 |
+
num_inference_steps=50,
|
| 127 |
+
guidance_scale=4.0,
|
| 128 |
+
generator=generator,
|
| 129 |
+
).images
|
| 130 |
+
```
|
| 131 |
+
|
| 132 |
+
## Load from a local clone
|
| 133 |
+
|
| 134 |
+
### Class-to-image (`PixelGen-XL-16-256`)
|
| 135 |
+
|
| 136 |
+
```python
|
| 137 |
+
from pathlib import Path
|
| 138 |
+
import torch
|
| 139 |
+
from diffusers import DiffusionPipeline
|
| 140 |
+
|
| 141 |
+
model_dir = Path("./PixelGen-XL-16-256").resolve()
|
| 142 |
+
pipe = DiffusionPipeline.from_pretrained(
|
| 143 |
+
str(model_dir),
|
| 144 |
+
local_files_only=True,
|
| 145 |
+
custom_pipeline=str(model_dir / "pipeline.py"),
|
| 146 |
+
trust_remote_code=True,
|
| 147 |
+
torch_dtype=torch.bfloat16,
|
| 148 |
+
).to("cuda")
|
| 149 |
+
|
| 150 |
+
generator = torch.Generator(device="cuda").manual_seed(0)
|
| 151 |
+
image = pipe(
|
| 152 |
+
class_labels="golden retriever",
|
| 153 |
+
num_inference_steps=50,
|
| 154 |
+
guidance_scale=2.25,
|
| 155 |
+
generator=generator,
|
| 156 |
+
).images[0]
|
| 157 |
+
image.save("demo.png")
|
| 158 |
+
```
|
| 159 |
+
|
| 160 |
+
## Recommended inference settings
|
| 161 |
+
|
| 162 |
+
| Variant | Steps | CFG scale | Solver | Timeshift | CFG interval |
|
| 163 |
+
| --- | ---: | ---: | --- | ---: | --- |
|
| 164 |
+
| `PixelGen-XL-16-256` | 50 | 2.25 | heun | 2.0 | [0.1, 0.9] |
|
| 165 |
+
| `PixelGen-XXL-16-512-t2i` | 25 | 4.0 | adam_lm | 3.0 | [0.0, 1.0] |
|
| 166 |
+
|
| 167 |
+
`height` and `width` are fixed by each checkpoint's `sample_size`. Custom sizes are not supported for these exports.
|
| 168 |
+
|
| 169 |
+
## Interface notes
|
| 170 |
+
|
| 171 |
+
- Class-conditional generation uses `class_labels` (integer ImageNet id or English synonym).
|
| 172 |
+
- `guidance_scale > 1.0` enables classifier-free guidance over a null class token.
|
| 173 |
+
- `sampling_method` accepts `heun` or `euler` for C2I; T2I defaults to `adam_lm`.
|
| 174 |
+
- `noise_scale` defaults to `1.0` at 256Γ256 and `2.0` at 512Γ512 when not specified.
|
| 175 |
+
|
| 176 |
+
## Citation
|
| 177 |
+
|
| 178 |
+
Source paper:
|
| 179 |
+
|
| 180 |
+
- [PixelGen: Improving Pixel Diffusion with Perceptual Loss](https://arxiv.org/abs/2602.02493)
|
| 181 |
+
- [Hugging Face Papers page](https://huggingface.co/papers/2602.02493)
|
| 182 |
+
|
| 183 |
+
```bibtex
|
| 184 |
+
@article{ma2026pixelgen,
|
| 185 |
+
title={PixelGen: Improving Pixel Diffusion with Perceptual Loss},
|
| 186 |
+
author={Zehong Ma and Ruihan Xu and Shiliang Zhang},
|
| 187 |
+
year={2026},
|
| 188 |
+
eprint={2602.02493},
|
| 189 |
+
archivePrefix={arXiv},
|
| 190 |
+
primaryClass={cs.CV},
|
| 191 |
+
url={https://arxiv.org/abs/2602.02493},
|
| 192 |
+
}
|
| 193 |
+
```
|