Add d32 64ep LightningDiT inference weights and sampling option
Browse filesFiles changed (4)
- README.md+4-1
- configs/d32-64ep.jsonAdded+100
- inference.py+10-6
- lightningdit/lightningdit-f16d32-64ep.safetensorsAdded+3
14 unmodified lines151617181920217 unmodified lines2930313233349 unmodified lines44454614 unmodified lines| Variant | VAE | LightningDiT || --- | --- | --- || f16d32 | [50ep](vae/dmvae-f16d32-50ep.safetensors) | [400ep](lightningdit/lightningdit-f16d32-400ep.safetensors) || f16d64 | [50ep](vae/dmvae-f16d64-50ep.safetensors) | [400ep](lightningdit/lightningdit-f16d64-400ep.safetensors) |Use each generator with the tokenizer and channel normalization in its matching `configs/d32.json` or `configs/d64.json`. Weights retain their original tensor precision.7 unmodified linescd DM-VAEpython -m pip install -e ".[hub]" safetensorshf download Davidwang215/dmvae --local-dir weights/dmvaepython weights/dmvae/inference.py --variant d32 --classes 207 --device cuda --precision bf16 --output samples/d32python weights/dmvae/inference.py --variant d64 --classes 207 --device cuda --precision bf16 --output samples/d64```9 unmodified linesfrom inference import load_pairvae, dit, means, scales = load_pair("weights/dmvae", "d32", "cuda", torch.bfloat16)```14 unmodified lines151617181920217 unmodified lines293031323334359 unmodified lines454647484914 unmodified lines| Variant | VAE | LightningDiT || --- | --- | --- || f16d32 | [50ep](vae/dmvae-f16d32-50ep.safetensors) | [64ep](lightningdit/lightningdit-f16d32-64ep.safetensors), [400ep](lightningdit/lightningdit-f16d32-400ep.safetensors) || f16d64 | [50ep](vae/dmvae-f16d64-50ep.safetensors) | [400ep](lightningdit/lightningdit-f16d64-400ep.safetensors) |Use each generator with the tokenizer and channel normalization in its matching `configs/d32.json` or `configs/d64.json`. Weights retain their original tensor precision.7 unmodified linescd DM-VAEpython -m pip install -e ".[hub]" safetensorshf download Davidwang215/dmvae --local-dir weights/dmvaepython weights/dmvae/inference.py --variant d32 --dit-epochs 64 --classes 207 --device cuda --precision bf16 --output samples/d32-64eppython weights/dmvae/inference.py --variant d32 --classes 207 --device cuda --precision bf16 --output samples/d32python weights/dmvae/inference.py --variant d64 --classes 207 --device cuda --precision bf16 --output samples/d64```9 unmodified linesfrom inference import load_pairvae, dit, means, scales = load_pair("weights/dmvae", "d32", "cuda", torch.bfloat16)```Select the f16d32 64ep generator with `--dit-epochs 64`. The default is 400ep. Both f16d32 generators use the same f16d32 50ep VAE and channel normalization.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100{ "format": "safetensors", "image_size": 256, "variant": "d32", "vae": { "file": "vae/dmvae-f16d32-50ep.safetensors", "sha256": "03f037b19412efb8406034a45a72fd9e7a70dcbb4f0de19c0a9fab67cc64a722", "architecture": { "z_channels_high": 32, "z_channels_low": 16, "legacy_bottleneck": false } }, "dit": { "file": "lightningdit/lightningdit-f16d32-64ep.safetensors", "sha256": "7c9c925c4d7980524092ec4593a4a7ecde7fab5e3422801651fa5b616dac28d3", "architecture": { "latent_shape": [ 32, 16, 16 ], "z_channels_low": 16, "depth": 28, "hidden_size": 1152, "num_heads": 16, "latent_patch_size": 1, "num_classes": 1000, "align_layer": 7 } }, "channel_means": [ 0.11889809370040894, -0.0498211495578289, 0.07956922799348831, 0.1282467246055603, -0.09310000389814377, 0.01919279806315899, 0.008933479897677898, 0.06343873590230942, 0.09063224494457245, -0.09089301526546478, 0.034680724143981934, -0.07357332110404968, -0.12892358005046844, 0.06941217929124832, -0.15016569197177887, -0.11732754856348038, -0.08246354013681412, -0.012567241676151752, -0.1367921233177185, 0.13331466913223267, 0.027383580803871155, -0.027444366365671158, 0.09910911321640015, -0.11326712369918823, 0.023853497579693794, 0.1297440379858017, 0.07543385028839111, -0.13411222398281097, 0.09224484860897064, 0.08815101534128189, 0.0031031614635139704, 0.17456728219985962 ], "channel_std": [ 1.2717455625534058, 1.044906497001648, 1.8927958011627197, 1.4252386093139648, 1.8472360372543335, 1.0113850831985474, 1.8590723276138306, 2.1371302604675293, 2.2889883518218994, 1.6720170974731445, 1.6339408159255981, 2.2134768962860107, 1.4047157764434814, 1.0915695428848267, 1.2994840145111084, 2.1737470626831055, 1.340841293334961, 1.715541958808899, 1.5402436256408691, 2.1781232357025146, 0.714764416217804, 1.110756516456604, 1.363089680671692, 1.2082487344741821, 1.1547572612762451, 1.41787588596344, 1.297340989112854, 1.2110263109207153, 1.4920814037322998, 1.2209465503692627, 1.41843843460083, 2.409214735031128 ]}16 unmodified lines171819202122231 unmodified line252627282930313215 unmodified lines484950515253545556575859606162639 unmodified lines7374757677783 unmodified lines8283848586878816 unmodified linesreturn h.hexdigest()def load_pair(directory, variant='d32', device='cpu', dtype=torch.float32):"""Return VAE, DiT, and the channel normalization for one matched pair."""from dmvae.autoencoder import DMVAEfrom generation.model import LatentDiT1 unmodified lineif variant not in ('d32', 'd64'):raise ValueError('variant must be d32 or d64')root = Path(directory)config = json.loads((root / 'configs' / (variant + '.json')).read_text())loaded = {}for component in ('vae', 'dit'):spec = config[component]15 unmodified lines@torch.no_grad()def generate(directory, variant='d32', classes=(207,), seed=1234, steps=250, device='cpu', dtype=torch.float32, cfg=False):from generation.sampling import euler_sample, RECIPESvae, dit, means, scales = load_pair(directory, variant, device, dtype)labels = torch.tensor(classes, device=device, dtype=torch.long)if labels.numel() == 0 or ((labels < 0) | (labels >= 1000)).any():raise ValueError('Provide ImageNet class indices in [0, 999]')generator = torch.Generator(device=device).manual_seed(seed)noise = torch.randn((len(labels), vae.z_channels_high, 16, 16), generator=generator, device=device, dtype=dtype)recipe = ('d64-' if variant == 'd64' else '') + '400ep-ig' + ('-cfg' if cfg else '')autocast = torch.autocast(torch.device(device).type, dtype=dtype) if dtype == torch.bfloat16 else nullcontext()with autocast:latent = euler_sample(dit, vae, noise, labels, means, scales, *RECIPES[recipe], steps=steps)9 unmodified linesp = argparse.ArgumentParser(description=__doc__)p.add_argument('--directory', type=Path, default=Path(__file__).resolve().parent)p.add_argument('--variant', choices=('d32', 'd64'), default='d32')p.add_argument('--classes', type=int, nargs='+', default=[207])p.add_argument('--seed', type=int, default=1234)p.add_argument('--steps', type=int, default=250, help='Euler sampling steps')3 unmodified linesp.add_argument('--output', type=Path, default=Path('samples'))args = p.parse_args()dtype = torch.bfloat16 if args.precision == 'bf16' else torch.float32images = generate(args.directory, args.variant, args.classes, args.seed, args.steps, args.device, dtype, args.cfg)args.output.mkdir(parents=True, exist_ok=True)for index, image in enumerate(images):rgb = image.add(1).mul(127.5).round().to(torch.uint8).permute(1, 2, 0).cpu().numpy()16 unmodified lines171819202122231 unmodified line252627282930313233343515 unmodified lines515253545556575859606162636465669 unmodified lines767778798081823 unmodified lines8687888990919216 unmodified linesreturn h.hexdigest()def load_pair(directory, variant='d32', device='cpu', dtype=torch.float32, dit_epochs=400):"""Return VAE, DiT, and the channel normalization for one matched pair."""from dmvae.autoencoder import DMVAEfrom generation.model import LatentDiT1 unmodified lineif variant not in ('d32', 'd64'):raise ValueError('variant must be d32 or d64')if dit_epochs not in (64, 400) or (dit_epochs == 64 and variant != 'd32'):raise ValueError('64ep is available for d32; 400ep is available for d32 and d64')root = Path(directory)config_name = variant + ('-64ep' if dit_epochs == 64 else '') + '.json'config = json.loads((root / 'configs' / config_name).read_text())loaded = {}for component in ('vae', 'dit'):spec = config[component]15 unmodified lines@torch.no_grad()def generate(directory, variant='d32', classes=(207,), seed=1234, steps=250, device='cpu', dtype=torch.float32, cfg=False, dit_epochs=400):from generation.sampling import euler_sample, RECIPESvae, dit, means, scales = load_pair(directory, variant, device, dtype, dit_epochs=dit_epochs)labels = torch.tensor(classes, device=device, dtype=torch.long)if labels.numel() == 0 or ((labels < 0) | (labels >= 1000)).any():raise ValueError('Provide ImageNet class indices in [0, 999]')generator = torch.Generator(device=device).manual_seed(seed)noise = torch.randn((len(labels), vae.z_channels_high, 16, 16), generator=generator, device=device, dtype=dtype)recipe = ('d64-' if variant == 'd64' else '') + f'{dit_epochs}ep-ig' + ('-cfg' if cfg else '')autocast = torch.autocast(torch.device(device).type, dtype=dtype) if dtype == torch.bfloat16 else nullcontext()with autocast:latent = euler_sample(dit, vae, noise, labels, means, scales, *RECIPES[recipe], steps=steps)9 unmodified linesp = argparse.ArgumentParser(description=__doc__)p.add_argument('--directory', type=Path, default=Path(__file__).resolve().parent)p.add_argument('--variant', choices=('d32', 'd64'), default='d32')p.add_argument('--dit-epochs', type=int, choices=(64, 400), default=400)p.add_argument('--classes', type=int, nargs='+', default=[207])p.add_argument('--seed', type=int, default=1234)p.add_argument('--steps', type=int, default=250, help='Euler sampling steps')3 unmodified linesp.add_argument('--output', type=Path, default=Path('samples'))args = p.parse_args()dtype = torch.bfloat16 if args.precision == 'bf16' else torch.float32images = generate(args.directory, args.variant, args.classes, args.seed, args.steps, args.device, dtype, args.cfg, dit_epochs=args.dit_epochs)args.output.mkdir(parents=True, exist_ok=True)for index, image in enumerate(images):rgb = image.add(1).mul(127.5).round().to(torch.uint8).permute(1, 2, 0).cpu().numpy()
123version https://git-lfs.github.com/spec/v1oid sha256:7c9c925c4d7980524092ec4593a4a7ecde7fab5e3422801651fa5b616dac28d3size 2706627304README.md+4-1
configs/d32-64ep.jsonAdded+100
inference.py+10-6
lightningdit/lightningdit-f16d32-64ep.safetensorsAdded+3