[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"project-9704":3},{"id":4,"name":5,"fullName":6,"owner":7,"repo":5,"description":8,"homepage":9,"htmlUrl":10,"language":11,"languages":10,"totalLinesOfCode":10,"stars":12,"forks":13,"watchers":14,"openIssues":15,"contributorsCount":16,"subscribersCount":16,"size":16,"stars1d":16,"stars7d":17,"stars30d":18,"stars90d":16,"forks30d":16,"starsTrendScore":19,"compositeScore":20,"rankGlobal":10,"rankLanguage":10,"license":21,"archived":22,"fork":22,"defaultBranch":23,"hasWiki":24,"hasPages":22,"topics":25,"createdAt":10,"pushedAt":10,"updatedAt":29,"readmeContent":30,"aiSummary":31,"trendingCount":16,"starSnapshotCount":16,"syncStatus":32,"lastSyncTime":33,"discoverSource":34},9704,"DALLE2-pytorch","lucidrains\u002FDALLE2-pytorch","lucidrains","Implementation of DALL-E 2, OpenAI's updated text-to-image synthesis neural network,  in Pytorch","",null,"Python",11313,1081,119,68,0,3,5,1,44.1,"MIT License",false,"main",true,[26,27,28],"artificial-intelligence","deep-learning","text-to-image","2026-06-12 02:02:11","\u003Cimg src=\".\u002Fdalle2.png\" width=\"450px\">\u003C\u002Fimg>\n\n## DALL-E 2 - Pytorch\n\nImplementation of \u003Ca href=\"https:\u002F\u002Fopenai.com\u002Fdall-e-2\u002F\">DALL-E 2\u003C\u002Fa>, OpenAI's updated text-to-image synthesis neural network, in Pytorch.\n\n\u003Ca href=\"https:\u002F\u002Fyoutu.be\u002FRJwPN4qNi_Y?t=555\">Yannic Kilcher summary\u003C\u002Fa> | \u003Ca href=\"https:\u002F\u002Fwww.youtube.com\u002Fwatch?v=F1X4fHzF4mQ\">AssemblyAI explainer\u003C\u002Fa>\n\nThe main novelty seems to be an extra layer of indirection with the prior network (whether it is an autoregressive transformer or a diffusion network), which predicts an image embedding based on the text embedding from CLIP. Specifically, this repository will only build out the diffusion prior network, as it is the best performing variant (but which incidentally involves a causal transformer as the denoising network 😂)\n\nThis model is SOTA for text-to-image for now.\n\nPlease join \u003Ca href=\"https:\u002F\u002Fdiscord.gg\u002FxBPBXfcFHd\">\u003Cimg alt=\"Join us on Discord\" src=\"https:\u002F\u002Fimg.shields.io\u002Fdiscord\u002F823813159592001537?color=5865F2&logo=discord&logoColor=white\">\u003C\u002Fa> if you are interested in helping out with the replication with the \u003Ca href=\"https:\u002F\u002Flaion.ai\u002F\">LAION\u003C\u002Fa> community | \u003Ca href=\"https:\u002F\u002Fwww.youtube.com\u002Fwatch?v=AIOE1l1W0Tw\">Yannic Interview\u003C\u002Fa>\n\nAs of 5\u002F23\u002F22, it is no longer SOTA. SOTA will be \u003Ca href=\"https:\u002F\u002Fgithub.com\u002Flucidrains\u002Fimagen-pytorch\">here\u003C\u002Fa>. Jax versions as well as text-to-video project will be shifted towards the Imagen architecture, as it is way simpler.\n\n## Status\n\n- A research group has used the code in this repository to train a functional diffusion prior for their CLIP generations. Will share their work once they release their preprint. This, and \u003Ca href=\"https:\u002F\u002Fgithub.com\u002Fcrowsonkb\">Katherine's\u003C\u002Fa> own experiments, validate OpenAI's finding that the extra prior increases variety of generations.\n\n- Decoder is now verified working for unconditional generation on my experimental setup for Oxford flowers. 2 researchers have also confirmed Decoder is working for them.\n\n\u003Cimg src=\".\u002Fsamples\u002Foxford.png\" width=\"450px\" \u002F>\n\n*ongoing at 21k steps*\n\n- \u003Ca href=\"https:\u002F\u002Ftwitter.com\u002FBuntworthy\u002Fstatus\u002F1529475416775434240?t=0GEge3Kr9I36cjcUVCQUTg\">Justin Pinkney\u003C\u002Fa> successfully trained the diffusion prior in the repository for his CLIP to Stylegan2 text-to-image application\n\n- \u003Ca href=\"https:\u002F\u002Fgithub.com\u002From1504\">Romain\u003C\u002Fa> has scaled up training to 800 GPUs with the available scripts without any issues\n\n## Pre-Trained Models\n\n- LAION is training prior models. Checkpoints are available on \u003Ca href=\"https:\u002F\u002Fhuggingface.co\u002Fzenglishuci\u002Fconditioned-prior\">🤗huggingface\u003C\u002Fa> and the training statistics are available on \u003Ca href=\"https:\u002F\u002Fwandb.ai\u002Fnousr_laion\u002Fconditioned-prior\u002Freports\u002FLAION-DALLE2-PyTorch-Prior--VmlldzoyMDI2OTIx\">🐝WANDB\u003C\u002Fa>.\n- Decoder - \u003Ca href=\"https:\u002F\u002Fwandb.ai\u002Fveldrovive\u002Fdalle2_train_decoder\u002Fruns\u002Fjkrtg0so?workspace=user-veldrovive\">In-progress test run\u003C\u002Fa> 🚧\n- Decoder - \u003Ca href=\"https:\u002F\u002Fwandb.ai\u002Fveldrovive\u002Fdalle2_train_decoder\u002Fruns\u002F3d5rytsa?workspace=\">Another test run with sparse attention\u003C\u002Fa>\n- DALL-E 2 🚧 - \u003Ca href=\"https:\u002F\u002Fgithub.com\u002FLAION-AI\u002Fdalle2-laion\">DALL-E 2 Laion repository\u003C\u002Fa>\n\n## Appreciation\n\nThis library would not have gotten to this working state without the help of\n\n- \u003Ca href=\"https:\u002F\u002Fgithub.com\u002Fnousr\">Zion\u003C\u002Fa> for the distributed training code for the diffusion prior\n- \u003Ca href=\"https:\u002F\u002Fgithub.com\u002FVeldrovive\">Aidan\u003C\u002Fa> for the distributed training code for the decoder as well as the dataloaders\n- \u003Ca href=\"https:\u002F\u002Fgithub.com\u002Fkrish240574\">Kumar\u003C\u002Fa> for working on the initial diffusion training script\n- \u003Ca href=\"https:\u002F\u002Fgithub.com\u002From1504\">Romain\u003C\u002Fa> for the pull request reviews and project management\n- \u003Ca href=\"https:\u002F\u002Fgithub.com\u002FCiaohe\">He Cao\u003C\u002Fa> and \u003Ca href=\"https:\u002F\u002Fgithub.com\u002Fxiankgx\">xiankgx\u003C\u002Fa> for the Q&A and for identifying of critical bugs\n- \u003Ca href=\"https:\u002F\u002Fgithub.com\u002Fmarunine\">Marunine\u003C\u002Fa> for identifying issues with resizing of the low resolution conditioner, when training the upsampler, in addition to various other bug fixes\n- \u003Ca href=\"https:\u002F\u002Fgithub.com\u002Fmalumadev\">MalumaDev\u003C\u002Fa> for proposing the use of pixel shuffle upsampler for fixing checkboard artifacts\n- \u003Ca href=\"https:\u002F\u002Fgithub.com\u002Fcrowsonkb\">Katherine\u003C\u002Fa> for her advice\n- \u003Ca href=\"https:\u002F\u002Fstability.ai\u002F\">Stability AI\u003C\u002Fa> for the generous sponsorship\n- \u003Ca href=\"https:\u002F\u002Fhuggingface.co\">🤗 Huggingface\u003C\u002Fa> and in particular \u003Ca href=\"https:\u002F\u002Fgithub.com\u002Fsgugger\">Sylvain\u003C\u002Fa> for the \u003Ca href=\"https:\u002F\u002Fgithub.com\u002Fhuggingface\u002Faccelerate\">Accelerate\u003C\u002Fa> library\n- \u003Ca href=\"https:\u002F\u002Fgithub.com\u002Farogozhnikov\">Alex\u003C\u002Fa> for \u003Ca href=\"https:\u002F\u002Fgithub.com\u002Farogozhnikov\u002Feinops\">einops\u003C\u002Fa>, indispensable tool for tensor manipulation\n\n... and many others. Thank you! 🙏\n\n## Install\n\n```bash\n$ pip install dalle2-pytorch\n```\n\n## Usage\n\nTo train DALLE-2 is a 3 step process, with the training of CLIP being the most important\n\nTo train CLIP, you can either use \u003Ca href=\"https:\u002F\u002Fgithub.com\u002Flucidrains\u002Fx-clip\">x-clip\u003C\u002Fa> package, or join the LAION discord, where a lot of replication efforts are already \u003Ca href=\"https:\u002F\u002Fgithub.com\u002Fmlfoundations\u002Fopen_clip\">underway\u003C\u002Fa>.\n\nThis repository will demonstrate integration with `x-clip` for starters\n\n```python\nimport torch\nfrom dalle2_pytorch import CLIP\n\nclip = CLIP(\n    dim_text = 512,\n    dim_image = 512,\n    dim_latent = 512,\n    num_text_tokens = 49408,\n    text_enc_depth = 1,\n    text_seq_len = 256,\n    text_heads = 8,\n    visual_enc_depth = 1,\n    visual_image_size = 256,\n    visual_patch_size = 32,\n    visual_heads = 8,\n    use_all_token_embeds = True,            # whether to use fine-grained contrastive learning (FILIP)\n    decoupled_contrastive_learning = True,  # use decoupled contrastive learning (DCL) objective function, removing positive pairs from the denominator of the InfoNCE loss (CLOOB + DCL)\n    extra_latent_projection = True,         # whether to use separate projections for text-to-image vs image-to-text comparisons (CLOOB)\n    use_visual_ssl = True,                  # whether to do self supervised learning on images\n    visual_ssl_type = 'simclr',             # can be either 'simclr' or 'simsiam', depending on using DeCLIP or SLIP\n    use_mlm = False,                        # use masked language learning (MLM) on text (DeCLIP)\n    text_ssl_loss_weight = 0.05,            # weight for text MLM loss\n    image_ssl_loss_weight = 0.05            # weight for image self-supervised learning loss\n).cuda()\n\n# mock data\n\ntext = torch.randint(0, 49408, (4, 256)).cuda()\nimages = torch.randn(4, 3, 256, 256).cuda()\n\n# train\n\nloss = clip(\n    text,\n    images,\n    return_loss = True              # needs to be set to True to return contrastive loss\n)\n\nloss.backward()\n\n# do the above with as many texts and images as possible in a loop\n```\n\nThen, you will need to train the decoder, which learns to generate images based on the image embedding coming from the trained CLIP above\n\n```python\nimport torch\nfrom dalle2_pytorch import Unet, Decoder, CLIP\n\n# trained clip from step 1\n\nclip = CLIP(\n    dim_text = 512,\n    dim_image = 512,\n    dim_latent = 512,\n    num_text_tokens = 49408,\n    text_enc_depth = 1,\n    text_seq_len = 256,\n    text_heads = 8,\n    visual_enc_depth = 1,\n    visual_image_size = 256,\n    visual_patch_size = 32,\n    visual_heads = 8\n).cuda()\n\n# unet for the decoder\n\nunet = Unet(\n    dim = 128,\n    image_embed_dim = 512,\n    cond_dim = 128,\n    channels = 3,\n    dim_mults=(1, 2, 4, 8)\n).cuda()\n\n# decoder, which contains the unet and clip\n\ndecoder = Decoder(\n    unet = unet,\n    clip = clip,\n    timesteps = 100,\n    image_cond_drop_prob = 0.1,\n    text_cond_drop_prob = 0.5\n).cuda()\n\n# mock images (get a lot of this)\n\nimages = torch.randn(4, 3, 256, 256).cuda()\n\n# feed images into decoder\n\nloss = decoder(images)\nloss.backward()\n\n# do the above for many many many many steps\n# then it will learn to generate images based on the CLIP image embeddings\n```\n\nFinally, the main contribution of the paper. The repository offers the diffusion prior network. It takes the CLIP text embeddings and tries to generate the CLIP image embeddings. Again, you will need the trained CLIP from the first step\n\n```python\nimport torch\nfrom dalle2_pytorch import DiffusionPriorNetwork, DiffusionPrior, CLIP\n\n# get trained CLIP from step one\n\nclip = CLIP(\n    dim_text = 512,\n    dim_image = 512,\n    dim_latent = 512,\n    num_text_tokens = 49408,\n    text_enc_depth = 6,\n    text_seq_len = 256,\n    text_heads = 8,\n    visual_enc_depth = 6,\n    visual_image_size = 256,\n    visual_patch_size = 32,\n    visual_heads = 8,\n).cuda()\n\n# setup prior network, which contains an autoregressive transformer\n\nprior_network = DiffusionPriorNetwork(\n    dim = 512,\n    depth = 6,\n    dim_head = 64,\n    heads = 8\n).cuda()\n\n# diffusion prior network, which contains the CLIP and network (with transformer) above\n\ndiffusion_prior = DiffusionPrior(\n    net = prior_network,\n    clip = clip,\n    timesteps = 100,\n    cond_drop_prob = 0.2\n).cuda()\n\n# mock data\n\ntext = torch.randint(0, 49408, (4, 256)).cuda()\nimages = torch.randn(4, 3, 256, 256).cuda()\n\n# feed text and images into diffusion prior network\n\nloss = diffusion_prior(text, images)\nloss.backward()\n\n# do the above for many many many steps\n# now the diffusion prior can generate image embeddings from the text embeddings\n```\n\nIn the paper, they actually used a \u003Ca href=\"https:\u002F\u002Fcascaded-diffusion.github.io\u002F\">recently discovered technique\u003C\u002Fa>, from \u003Ca href=\"http:\u002F\u002Fwww.jonathanho.me\u002F\">Jonathan Ho\u003C\u002Fa> himself (original author of DDPMs, the core technique used in DALL-E v2) for high resolution image synthesis.\n\nThis can easily be used within this framework as so\n\n```python\nimport torch\nfrom dalle2_pytorch import Unet, Decoder, CLIP\n\n# trained clip from step 1\n\nclip = CLIP(\n    dim_text = 512,\n    dim_image = 512,\n    dim_latent = 512,\n    num_text_tokens = 49408,\n    text_enc_depth = 6,\n    text_seq_len = 256,\n    text_heads = 8,\n    visual_enc_depth = 6,\n    visual_image_size = 256,\n    visual_patch_size = 32,\n    visual_heads = 8\n).cuda()\n\n# 2 unets for the decoder (a la cascading DDPM)\n\nunet1 = Unet(\n    dim = 32,\n    image_embed_dim = 512,\n    cond_dim = 128,\n    channels = 3,\n    dim_mults = (1, 2, 4, 8)\n).cuda()\n\nunet2 = Unet(\n    dim = 32,\n    image_embed_dim = 512,\n    cond_dim = 128,\n    channels = 3,\n    dim_mults = (1, 2, 4, 8, 16)\n).cuda()\n\n# decoder, which contains the unet(s) and clip\n\ndecoder = Decoder(\n    clip = clip,\n    unet = (unet1, unet2),            # insert both unets in order of low resolution to highest resolution (you can have as many stages as you want here)\n    image_sizes = (256, 512),         # resolutions, 256 for first unet, 512 for second. these must be unique and in ascending order (matches with the unets passed in)\n    timesteps = 1000,\n    image_cond_drop_prob = 0.1,\n    text_cond_drop_prob = 0.5\n).cuda()\n\n# mock images (get a lot of this)\n\nimages = torch.randn(4, 3, 512, 512).cuda()\n\n# feed images into decoder, specifying which unet you want to train\n# each unet can be trained separately, which is one of the benefits of the cascading DDPM scheme\n\nloss = decoder(images, unet_number = 1)\nloss.backward()\n\nloss = decoder(images, unet_number = 2)\nloss.backward()\n\n# do the above for many steps for both unets\n```\n\nFinally, to generate the DALL-E2 images from text. Insert the trained `DiffusionPrior` as well as the `Decoder` (which wraps `CLIP`, the causal transformer, and unet(s))\n\n```python\nfrom dalle2_pytorch import DALLE2\n\ndalle2 = DALLE2(\n    prior = diffusion_prior,\n    decoder = decoder\n)\n\n# send the text as a string if you want to use the simple tokenizer from DALLE v1\n# or you can do it as token ids, if you have your own tokenizer\n\ntexts = ['glistening morning dew on a flower petal']\nimages = dalle2(texts) # (1, 3, 256, 256)\n```\n\nThat's it!\n\nLet's see the whole script below\n\n```python\nimport torch\nfrom dalle2_pytorch import DALLE2, DiffusionPriorNetwork, DiffusionPrior, Unet, Decoder, CLIP\n\nclip = CLIP(\n    dim_text = 512,\n    dim_image = 512,\n    dim_latent = 512,\n    num_text_tokens = 49408,\n    text_enc_depth = 6,\n    text_seq_len = 256,\n    text_heads = 8,\n    visual_enc_depth = 6,\n    visual_image_size = 256,\n    visual_patch_size = 32,\n    visual_heads = 8\n).cuda()\n\n# mock data\n\ntext = torch.randint(0, 49408, (4, 256)).cuda()\nimages = torch.randn(4, 3, 256, 256).cuda()\n\n# train\n\nloss = clip(\n    text,\n    images,\n    return_loss = True\n)\n\nloss.backward()\n\n# do above for many steps ...\n\n# prior networks (with transformer)\n\nprior_network = DiffusionPriorNetwork(\n    dim = 512,\n    depth = 6,\n    dim_head = 64,\n    heads = 8\n).cuda()\n\ndiffusion_prior = DiffusionPrior(\n    net = prior_network,\n    clip = clip,\n    timesteps = 1000,\n    sample_timesteps = 64,\n    cond_drop_prob = 0.2\n).cuda()\n\nloss = diffusion_prior(text, images)\nloss.backward()\n\n# do above for many steps ...\n\n# decoder (with unet)\n\nunet1 = Unet(\n    dim = 128,\n    image_embed_dim = 512,\n    text_embed_dim = 512,\n    cond_dim = 128,\n    channels = 3,\n    dim_mults=(1, 2, 4, 8),\n    cond_on_text_encodings = True    # set to True for any unets that need to be conditioned on text encodings\n).cuda()\n\nunet2 = Unet(\n    dim = 16,\n    image_embed_dim = 512,\n    cond_dim = 128,\n    channels = 3,\n    dim_mults = (1, 2, 4, 8, 16)\n).cuda()\n\ndecoder = Decoder(\n    unet = (unet1, unet2),\n    image_sizes = (128, 256),\n    clip = clip,\n    timesteps = 100,\n    image_cond_drop_prob = 0.1,\n    text_cond_drop_prob = 0.5\n).cuda()\n\nfor unet_number in (1, 2):\n    loss = decoder(images, text = text, unet_number = unet_number) # this can optionally be decoder(images, text) if you wish to condition on the text encodings as well, though it was hinted in the paper it didn't do much\n    loss.backward()\n\n# do above for many steps\n\ndalle2 = DALLE2(\n    prior = diffusion_prior,\n    decoder = decoder\n)\n\nimages = dalle2(\n    ['cute puppy chasing after a squirrel'],\n    cond_scale = 2. # classifier free guidance strength (> 1 would strengthen the condition)\n)\n\n# save your image (in this example, of size 256x256)\n```\n\nEverything in this readme should run without error\n\nYou can also train the decoder on images of greater than the size (say 512x512) at which CLIP was trained (256x256). The images will be resized to CLIP image resolution for the image embeddings\n\nFor the layperson, no worries, training will all be automated into a CLI tool, at least for small scale training.\n\n## Training on Preprocessed CLIP Embeddings\n\nIt is likely, when scaling up, that you would first preprocess your images and text into corresponding embeddings before training the prior network. You can do so easily by simply passing in `image_embed`, `text_embed`, and optionally `text_encodings`\n\nWorking example below\n\n```python\nimport torch\nfrom dalle2_pytorch import DiffusionPriorNetwork, DiffusionPrior, CLIP\n\n# get trained CLIP from step one\n\nclip = CLIP(\n    dim_text = 512,\n    dim_image = 512,\n    dim_latent = 512,\n    num_text_tokens = 49408,\n    text_enc_depth = 6,\n    text_seq_len = 256,\n    text_heads = 8,\n    visual_enc_depth = 6,\n    visual_image_size = 256,\n    visual_patch_size = 32,\n    visual_heads = 8,\n).cuda()\n\n# setup prior network, which contains an autoregressive transformer\n\nprior_network = DiffusionPriorNetwork(\n    dim = 512,\n    depth = 6,\n    dim_head = 64,\n    heads = 8\n).cuda()\n\n# diffusion prior network, which contains the CLIP and network (with transformer) above\n\ndiffusion_prior = DiffusionPrior(\n    net = prior_network,\n    clip = clip,\n    timesteps = 100,\n    cond_drop_prob = 0.2,\n    condition_on_text_encodings = False  # this probably should be true, but just to get Laion started\n).cuda()\n\n# mock data\n\ntext = torch.randint(0, 49408, (4, 256)).cuda()\nimages = torch.randn(4, 3, 256, 256).cuda()\n\n# precompute the text and image embeddings\n# here using the diffusion prior class, but could be done with CLIP alone\n\nclip_image_embeds = diffusion_prior.clip.embed_image(images).image_embed\nclip_text_embeds = diffusion_prior.clip.embed_text(text).text_embed\n\n# feed text and images into diffusion prior network\n\nloss = diffusion_prior(\n    text_embed = clip_text_embeds,\n    image_embed = clip_image_embeds\n)\n\nloss.backward()\n\n# do the above for many many many steps\n# now the diffusion prior can generate image embeddings from the text embeddings\n```\n\nYou can also completely go `CLIP`-less, in which case you will need to pass in the `image_embed_dim` into the `DiffusionPrior` on initialization\n\n```python\nimport torch\nfrom dalle2_pytorch import DiffusionPriorNetwork, DiffusionPrior\n\n# setup prior network, which contains an autoregressive transformer\n\nprior_network = DiffusionPriorNetwork(\n    dim = 512,\n    depth = 6,\n    dim_head = 64,\n    heads = 8\n).cuda()\n\n# diffusion prior network, which contains the CLIP and network (with transformer) above\n\ndiffusion_prior = DiffusionPrior(\n    net = prior_network,\n    image_embed_dim = 512,               # this needs to be set\n    timesteps = 100,\n    cond_drop_prob = 0.2,\n    condition_on_text_encodings = False  # this probably should be true, but just to get Laion started\n).cuda()\n\n# mock data\n\ntext = torch.randint(0, 49408, (4, 256)).cuda()\nimages = torch.randn(4, 3, 256, 256).cuda()\n\n# precompute the text and image embeddings\n# here using the diffusion prior class, but could be done with CLIP alone\n\nclip_image_embeds = torch.randn(4, 512).cuda()\nclip_text_embeds = torch.randn(4, 512).cuda()\n\n# feed text and images into diffusion prior network\n\nloss = diffusion_prior(\n    text_embed = clip_text_embeds,\n    image_embed = clip_image_embeds\n)\n\nloss.backward()\n\n# do the above for many many many steps\n# now the diffusion prior can generate image embeddings from the text embeddings\n```\n\n## OpenAI CLIP\n\nAlthough there is the possibility they are using an unreleased, more powerful CLIP, you can use one of the released ones, if you do not wish to train your own CLIP from scratch. This will also allow the community to more quickly validate the conclusions of the paper.\n\nTo use a pretrained OpenAI CLIP, simply import `OpenAIClipAdapter` and pass it into the `DiffusionPrior` or `Decoder` like so\n\n```python\nimport torch\nfrom dalle2_pytorch import DALLE2, DiffusionPriorNetwork, DiffusionPrior, Unet, Decoder, OpenAIClipAdapter\n\n# openai pretrained clip - defaults to ViT-B\u002F32\n\nclip = OpenAIClipAdapter()\n\n# mock data\n\ntext = torch.randint(0, 49408, (4, 256)).cuda()\nimages = torch.randn(4, 3, 256, 256).cuda()\n\n# prior networks (with transformer)\n\nprior_network = DiffusionPriorNetwork(\n    dim = 512,\n    depth = 6,\n    dim_head = 64,\n    heads = 8\n).cuda()\n\ndiffusion_prior = DiffusionPrior(\n    net = prior_network,\n    clip = clip,\n    timesteps = 100,\n    cond_drop_prob = 0.2\n).cuda()\n\nloss = diffusion_prior(text, images)\nloss.backward()\n\n# do above for many steps ...\n\n# decoder (with unet)\n\nunet1 = Unet(\n    dim = 128,\n    image_embed_dim = 512,\n    cond_dim = 128,\n    channels = 3,\n    dim_mults=(1, 2, 4, 8),\n    text_embed_dim = 512,\n    cond_on_text_encodings = True  # set to True for any unets that need to be conditioned on text encodings (ex. first unet in cascade)\n).cuda()\n\nunet2 = Unet(\n    dim = 16,\n    image_embed_dim = 512,\n    cond_dim = 128,\n    channels = 3,\n    dim_mults = (1, 2, 4, 8, 16)\n).cuda()\n\ndecoder = Decoder(\n    unet = (unet1, unet2),\n    image_sizes = (128, 256),\n    clip = clip,\n    timesteps = 1000,\n    sample_timesteps = (250, 27),\n    image_cond_drop_prob = 0.1,\n    text_cond_drop_prob = 0.5\n).cuda()\n\nfor unet_number in (1, 2):\n    loss = decoder(images, text = text, unet_number = unet_number) # this can optionally be decoder(images, text) if you wish to condition on the text encodings as well, though it was hinted in the paper it didn't do much\n    loss.backward()\n\n# do above for many steps\n\ndalle2 = DALLE2(\n    prior = diffusion_prior,\n    decoder = decoder\n)\n\nimages = dalle2(\n    ['a butterfly trying to escape a tornado'],\n    cond_scale = 2. # classifier free guidance strength (> 1 would strengthen the condition)\n)\n\n# save your image (in this example, of size 256x256)\n```\n\nAlternatively, you can also use \u003Ca href=\"https:\u002F\u002Fgithub.com\u002Fmlfoundations\u002Fopen_clip\">Open Clip\u003C\u002Fa>\n\n```bash\n$ pip install open-clip-torch\n```\n\nEx. using the \u003Ca href=\"https:\u002F\u002Flaion.ai\u002Fblog\u002Flarge-openclip\u002F\">SOTA Open Clip\u003C\u002Fa> model trained by \u003Ca href=\"https:\u002F\u002Fgithub.com\u002From1504\">Romain\u003C\u002Fa>\n\n```python\nfrom dalle2_pytorch import OpenClipAdapter\n\nclip = OpenClipAdapter('ViT-H\u002F14')\n```\n\nNow you'll just have to worry about training the Prior and the Decoder!\n\n## Inpainting\n\nInpainting is also built into the `Decoder`. You simply have to pass in the `inpaint_image` and `inpaint_mask` (boolean tensor where `True` indicates which regions of the inpaint image to keep)\n\nThis repository uses the formulation put forth by \u003Ca href=\"https:\u002F\u002Farxiv.org\u002Fabs\u002F2201.09865\">Lugmayr et al. in Repaint\u003C\u002Fa>\n\n```python\nimport torch\nfrom dalle2_pytorch import Unet, Decoder, CLIP\n\n# trained clip from step 1\n\nclip = CLIP(\n    dim_text = 512,\n    dim_image = 512,\n    dim_latent = 512,\n    num_text_tokens = 49408,\n    text_enc_depth = 6,\n    text_seq_len = 256,\n    text_heads = 8,\n    visual_enc_depth = 6,\n    visual_image_size = 256,\n    visual_patch_size = 32,\n    visual_heads = 8\n).cuda()\n\n# 2 unets for the decoder (a la cascading DDPM)\n\nunet = Unet(\n    dim = 16,\n    image_embed_dim = 512,\n    cond_dim = 128,\n    channels = 3,\n    dim_mults = (1, 1, 1, 1)\n).cuda()\n\n\n# decoder, which contains the unet(s) and clip\n\ndecoder = Decoder(\n    clip = clip,\n    unet = (unet,),               # insert both unets in order of low resolution to highest resolution (you can have as many stages as you want here)\n    image_sizes = (256,),         # resolutions, 256 for first unet, 512 for second. these must be unique and in ascending order (matches with the unets passed in)\n    timesteps = 1000,\n    image_cond_drop_prob = 0.1,\n    text_cond_drop_prob = 0.5\n).cuda()\n\n# mock images (get a lot of this)\n\nimages = torch.randn(4, 3, 256, 256).cuda()\n\n# feed images into decoder, specifying which unet you want to train\n# each unet can be trained separately, which is one of the benefits of the cascading DDPM scheme\n\nloss = decoder(images, unet_number = 1)\nloss.backward()\n\n# do the above for many steps for both unets\n\nmock_image_embed = torch.randn(1, 512).cuda()\n\n# then to do inpainting\n\ninpaint_image = torch.randn(1, 3, 256, 256).cuda()      # (batch, channels, height, width)\ninpaint_mask = torch.ones(1, 256, 256).bool().cuda()    # (batch, height, width)\n\ninpainted_images = decoder.sample(\n    image_embed = mock_image_embed,\n    inpaint_image = inpaint_image,    # just pass in the inpaint image\n    inpaint_mask = inpaint_mask       # and the mask\n)\n\ninpainted_images.shape # (1, 3, 256, 256)\n```\n\n## Experimental\n\n### DALL-E2 with Latent Diffusion\n\nThis repository decides to take the next step and offer DALL-E v2 combined with \u003Ca href=\"https:\u002F\u002Fhuggingface.co\u002Fspaces\u002Fmultimodalart\u002Flatentdiffusion\">latent diffusion\u003C\u002Fa>, from Rombach et al.\n\nYou can use it as follows. Latent diffusion can be limited to just the first U-Net in the cascade, or to any number you wish.\n\nThe repository also comes equipped with all the necessary settings to recreate `ViT-VQGan` from the \u003Ca href=\"https:\u002F\u002Farxiv.org\u002Fabs\u002F2110.04627\">Improved VQGans\u003C\u002Fa> paper. Furthermore, the \u003Ca href=\"https:\u002F\u002Fgithub.com\u002Flucidrains\u002Fvector-quantize-pytorch\">vector quantization\u003C\u002Fa> library also comes equipped to do \u003Ca href=\"https:\u002F\u002Farxiv.org\u002Fabs\u002F2203.01941\">residual or multi-headed quantization\u003C\u002Fa>, which I believe will give an even further boost in performance to the autoencoder.\n\n```python\nimport torch\nfrom dalle2_pytorch import Unet, Decoder, CLIP, VQGanVAE\n\n# trained clip from step 1\n\nclip = CLIP(\n    dim_text = 512,\n    dim_image = 512,\n    dim_latent = 512,\n    num_text_tokens = 49408,\n    text_enc_depth = 1,\n    text_seq_len = 256,\n    text_heads = 8,\n    visual_enc_depth = 1,\n    visual_image_size = 256,\n    visual_patch_size = 32,\n    visual_heads = 8\n)\n\n# 3 unets for the decoder (a la cascading DDPM)\n\n# first two unets are doing latent diffusion\n# vqgan-vae must be trained beforehand\n\nvae1 = VQGanVAE(\n    dim = 32,\n    image_size = 256,\n    layers = 3,\n    layer_mults = (1, 2, 4)\n)\n\nvae2 = VQGanVAE(\n    dim = 32,\n    image_size = 512,\n    layers = 3,\n    layer_mults = (1, 2, 4)\n)\n\nunet1 = Unet(\n    dim = 32,\n    image_embed_dim = 512,\n    cond_dim = 128,\n    channels = 3,\n    sparse_attn = True,\n    sparse_attn_window = 2,\n    dim_mults = (1, 2, 4, 8)\n)\n\nunet2 = Unet(\n    dim = 32,\n    image_embed_dim = 512,\n    channels = 3,\n    dim_mults = (1, 2, 4, 8, 16),\n    cond_on_image_embeds = True,\n    cond_on_text_encodings = False\n)\n\nunet3 = Unet(\n    dim = 32,\n    image_embed_dim = 512,\n    channels = 3,\n    dim_mults = (1, 2, 4, 8, 16),\n    cond_on_image_embeds = True,\n    cond_on_text_encodings = False,\n    attend_at_middle = False\n)\n\n# decoder, which contains the unet(s) and clip\n\ndecoder = Decoder(\n    clip = clip,\n    vae = (vae1, vae2),                # latent diffusion for unet1 (vae1) and unet2 (vae2), but not for the last unet3\n    unet = (unet1, unet2, unet3),      # insert unets in order of low resolution to highest resolution (you can have as many stages as you want here)\n    image_sizes = (256, 512, 1024),    # resolutions, 256 for first unet, 512 for second, 1024 for third\n    timesteps = 100,\n    image_cond_drop_prob = 0.1,\n    text_cond_drop_prob = 0.5\n).cuda()\n\n# mock images (get a lot of this)\n\nimages = torch.randn(1, 3, 1024, 1024).cuda()\n\n# feed images into decoder, specifying which unet you want to train\n# each unet can be trained separately, which is one of the benefits of the cascading DDPM scheme\n\nwith decoder.one_unet_in_gpu(1):\n    loss = decoder(images, unet_number = 1)\n    loss.backward()\n\nwith decoder.one_unet_in_gpu(2):\n    loss = decoder(images, unet_number = 2)\n    loss.backward()\n\nwith decoder.one_unet_in_gpu(3):\n    loss = decoder(images, unet_number = 3)\n    loss.backward()\n\n# do the above for many steps for both unets\n\n# then it will learn to generate images based on the CLIP image embeddings\n\n# chaining the unets from lowest resolution to highest resolution (thus cascading)\n\nmock_image_embed = torch.randn(1, 512).cuda()\nimages = decoder.sample(mock_image_embed) # (1, 3, 1024, 1024)\n```\n\n## Training wrapper\n\n### Decoder Training\n\nTraining the `Decoder` may be confusing, as one needs to keep track of an optimizer for each of the `Unet`(s) separately. Each `Unet` will also need its own corresponding exponential moving average. The `DecoderTrainer` hopes to make this simple, as shown below\n\n```python\nimport torch\nfrom dalle2_pytorch import DALLE2, Unet, Decoder, CLIP, DecoderTrainer\n\nclip = CLIP(\n    dim_text = 512,\n    dim_image = 512,\n    dim_latent = 512,\n    num_text_tokens = 49408,\n    text_enc_depth = 6,\n    text_seq_len = 256,\n    text_heads = 8,\n    visual_enc_depth = 6,\n    visual_image_size = 256,\n    visual_patch_size = 32,\n    visual_heads = 8\n).cuda()\n\n# mock data\n\ntext = torch.randint(0, 49408, (32, 256)).cuda()\nimages = torch.randn(32, 3, 256, 256).cuda()\n\n# decoder (with unet)\n\nunet1 = Unet(\n    dim = 128,\n    image_embed_dim = 512,\n    text_embed_dim = 512,\n    cond_dim = 128,\n    channels = 3,\n    dim_mults=(1, 2, 4, 8),\n    cond_on_text_encodings = True,\n).cuda()\n\nunet2 = Unet(\n    dim = 16,\n    image_embed_dim = 512,\n    cond_dim = 128,\n    channels = 3,\n    dim_mults = (1, 2, 4, 8, 16),\n).cuda()\n\ndecoder = Decoder(\n    unet = (unet1, unet2),\n    image_sizes = (128, 256),\n    clip = clip,\n    timesteps = 1000\n).cuda()\n\ndecoder_trainer = DecoderTrainer(\n    decoder,\n    lr = 3e-4,\n    wd = 1e-2,\n    ema_beta = 0.99,\n    ema_update_after_step = 1000,\n    ema_update_every = 10,\n)\n\nfor unet_number in (1, 2):\n    loss = decoder_trainer(\n        images,\n        text = text,\n        unet_number = unet_number, # which unet to train on\n        max_batch_size = 4         # gradient accumulation - this sets the maximum batch size in which to do forward and backwards pass - for this example 32 \u002F 4 == 8 times\n    )\n\n    decoder_trainer.update(unet_number) # update the specific unet as well as its exponential moving average\n\n# after much training\n# you can sample from the exponentially moving averaged unets as so\n\nmock_image_embed = torch.randn(32, 512).cuda()\nimages = decoder_trainer.sample(image_embed = mock_image_embed, text = text) # (4, 3, 256, 256)\n```\n\n### Diffusion Prior Training\n\nSimilarly, one can use the `DiffusionPriorTrainer` to automatically instantiate and keep track of an exponential moving averaged prior.\n\n```python\nimport torch\nfrom dalle2_pytorch import DALLE2, DiffusionPriorNetwork, DiffusionPrior, DiffusionPriorTrainer, Unet, Decoder, CLIP\n\nclip = CLIP(\n    dim_text = 512,\n    dim_image = 512,\n    dim_latent = 512,\n    num_text_tokens = 49408,\n    text_enc_depth = 6,\n    text_seq_len = 256,\n    text_heads = 8,\n    visual_enc_depth = 6,\n    visual_image_size = 256,\n    visual_patch_size = 32,\n    visual_heads = 8\n).cuda()\n\n# mock data\n\ntext = torch.randint(0, 49408, (512, 256)).cuda()\nimages = torch.randn(512, 3, 256, 256).cuda()\n\n# prior networks (with transformer)\n\nprior_network = DiffusionPriorNetwork(\n    dim = 512,\n    depth = 6,\n    dim_head = 64,\n    heads = 8\n).cuda()\n\ndiffusion_prior = DiffusionPrior(\n    net = prior_network,\n    clip = clip,\n    timesteps = 100,\n    cond_drop_prob = 0.2\n).cuda()\n\ndiffusion_prior_trainer = DiffusionPriorTrainer(\n    diffusion_prior,\n    lr = 3e-4,\n    wd = 1e-2,\n    ema_beta = 0.99,\n    ema_update_after_step = 1000,\n    ema_update_every = 10,\n)\n\nloss = diffusion_prior_trainer(text, images, max_batch_size = 4)\ndiffusion_prior_trainer.update()  # this will update the optimizer as well as the exponential moving averaged diffusion prior\n\n# after much of the above three lines in a loop\n# you can sample from the exponential moving average of the diffusion prior identically to how you do so for DiffusionPrior\n\nimage_embeds = diffusion_prior_trainer.sample(text, max_batch_size = 4) # (512, 512) - exponential moving averaged image embeddings\n```\n\n## Bonus\n\n### Unconditional Training\n\nThe repository also contains the means to train unconditional DDPM model, or even cascading DDPMs. You simply have to set `unconditional = True` in the `Decoder`\n\nex.\n\n```python\nimport torch\nfrom dalle2_pytorch import Unet, Decoder, DecoderTrainer\n\n# unet for the cascading ddpm\n\nunet1 = Unet(\n    dim = 128,\n    dim_mults=(1, 2, 4, 8)\n).cuda()\n\nunet2 = Unet(\n    dim = 32,\n    dim_mults = (1, 2, 4, 8, 16)\n).cuda()\n\n# decoder, which contains the unets\n\ndecoder = Decoder(\n    unet = (unet1, unet2),\n    image_sizes = (256, 512),  # first unet up to 256px, then second to 512px\n    timesteps = 1000,\n    unconditional = True\n).cuda()\n\n# decoder trainer\n\ndecoder_trainer = DecoderTrainer(decoder)\n\n# images (get a lot of this)\n\nimages = torch.randn(1, 3, 512, 512).cuda()\n\n# feed images into decoder\n\nfor i in (1, 2):\n    loss = decoder_trainer(images, unet_number = i)\n    decoder_trainer.update(unet_number = i)\n\n# do the above for many many many many images\n# then it will learn to generate images\n\nimages = decoder_trainer.sample(batch_size = 36, max_batch_size = 4) # (36, 3, 512, 512)\n```\n\n## Dataloaders\n\n### Decoder Dataloaders\n\nIn order to make loading data simple and efficient, we include some general dataloaders that can be used to train portions of the network.\n\n#### Decoder: Image Embedding Dataset\n\nWhen training the decoder (and up samplers if training together) in isolation, you will need to load images and corresponding image embeddings. This dataset can read two similar types of datasets. First, it can read a [webdataset](https:\u002F\u002Fgithub.com\u002Fwebdataset\u002Fwebdataset) that contains `.jpg` and `.npy` files in the `.tar`s that contain the images and associated image embeddings respectively. Alternatively, you can also specify a source for the embeddings outside of the webdataset. In this case, the path to the embeddings should contain `.npy` files with the same shard numbers as the webdataset and there should be a correspondence between the filename of the `.jpg` and the index of the embedding in the `.npy`. So, for example, `0001.tar` from the webdataset with image `00010509.jpg` (the first 4 digits are the shard number and the last 4 are the index) in it should be paralleled by a `img_emb_0001.npy` which contains a NumPy array with the embedding at index 509.\n\nGenerating a dataset of this type: \n1. Use [img2dataset](https:\u002F\u002Fgithub.com\u002From1504\u002Fimg2dataset) to generate a webdataset.\n2. Use [clip-retrieval](https:\u002F\u002Fgithub.com\u002From1504\u002Fclip-retrieval) to convert the images to embeddings.\n3. Use [embedding-dataset-reordering](https:\u002F\u002Fgithub.com\u002FVeldrovive\u002Fembedding-dataset-reordering) to reorder the embeddings into the expected format.\n\nUsage:\n\n```python\nfrom dalle2_pytorch.dataloaders import ImageEmbeddingDataset, create_image_embedding_dataloader\n\n# Create a dataloader directly.\ndataloader = create_image_embedding_dataloader(\n    tar_url=\"\u002Fpath\u002For\u002Furl\u002Fto\u002Fwebdataset\u002F{0000..9999}.tar\", # Uses bracket expanding notation. This specifies to read all tars from 0000.tar to 9999.tar\n    embeddings_url=\"path\u002For\u002Furl\u002Fto\u002Fembeddings\u002Ffolder\",     # Included if .npy files are not in webdataset. Left out or set to None otherwise\n    num_workers=4,\n    batch_size=32,\n    shard_width=4,                                         # If a file in the webdataset shard 3 is named 0003039.jpg, we know the shard width is 4 and the last three digits are the index\n    shuffle_num=200,                                       # Does a shuffle of the data with a buffer size of 200\n    shuffle_shards=True,                                   # Shuffle the order the shards are read in\n    resample_shards=False,                                 # Sample shards with replacement. If true, an epoch will be infinite unless stopped manually\n)\nfor img, emb in dataloader:\n    print(img.shape)  # torch.Size([32, 3, 256, 256])\n    print(emb[\"img\"].shape)  # torch.Size([32, 512])\n    # Train decoder only as shown above\n\n# Or create a dataset without a loader so you can configure it manually\ndataset = ImageEmbeddingDataset(\n    urls=\"\u002Fpath\u002For\u002Furl\u002Fto\u002Fwebdataset\u002F{0000..9999}.tar\",\n    embedding_folder_url=\"path\u002For\u002Furl\u002Fto\u002Fembeddings\u002Ffolder\",\n    shard_width=4,\n    shuffle_shards=True,\n    resample=False\n)\n```\n\n### Scripts\n\n#### `train_diffusion_prior.py`\n\nFor detailed information on training the diffusion prior, please refer to the [dedicated readme](prior.md)\n\n## Todo\n\n- [x] finish off gaussian diffusion class for latent embedding - allow for prediction of epsilon\n- [x] add what was proposed in the paper, where DDPM objective for image latent embedding predicts x0 directly (reread vq-diffusion paper and get caught up on that line of work)\n- [x] make sure it works end to end to produce an output tensor, taking a single gradient step\n- [x] augment unet so that it can also be conditioned on text encodings (although in paper they hinted this didn't make much a difference)\n- [x] figure out all the current bag of tricks needed to make DDPMs great (starting with the blur trick mentioned in paper)\n- [x] build the cascading ddpm by having Decoder class manage multiple unets at different resolutions\n- [x] add efficient attention in unet\n- [x] be able to finely customize what to condition on (text, image embed) for specific unet in the cascade (super resolution ddpms near the end may not need too much conditioning)\n- [x] offload unets not being trained on to CPU for memory efficiency (for training each resolution unets separately)\n- [x] build out latent diffusion architecture, with the vq-reg variant (vqgan-vae), make it completely optional and compatible with cascading ddpms\n- [x] for decoder, allow ability to customize objective (predict epsilon vs x0), in case latent diffusion does better with prediction of x0\n- [x] use attention-based upsampling https:\u002F\u002Farxiv.org\u002Fabs\u002F2112.11435\n- [x] use inheritance just this once for sharing logic between decoder and prior network ddpms\n- [x] bring in vit-vqgan https:\u002F\u002Farxiv.org\u002Fabs\u002F2110.04627 for the latent diffusion\n- [x] abstract interface for CLIP adapter class, so other CLIPs can be brought in\n- [x] take care of mixed precision as well as gradient accumulation within decoder trainer\n- [x] just take care of the training for the decoder in a wrapper class, as each unet in the cascade will need its own optimizer\n- [x] bring in tools to train vqgan-vae\n- [x] add convnext backbone for vqgan-vae (in addition to vit [vit-vqgan] + resnet)\n- [x] make sure DDPMs can be run with traditional resnet blocks (but leave convnext as an option for experimentation)\n- [x] make sure for the latter unets in the cascade, one can train on crops for learning super resolution (constrain the unet to be only convolutions in that case, or allow conv-like attention with rel pos bias)\n- [x] offer setting in diffusion prior to split time and image embeddings into multiple tokens, configurable, for more surface area during attention\n- [x] make sure resnet hyperparameters can be configurable across unet depth (groups and expansion factor)\n- [x] pull logic for training diffusion prior into a class DiffusionPriorTrainer, for eventual script based + CLI based training\n- [x] make sure the cascading ddpm in the repository can be trained unconditionally, offer a one-line CLI tool for training on a folder of images\n- [x] bring in cross-scale embedding from iclr paper https:\u002F\u002Fgithub.com\u002Flucidrains\u002Fvit-pytorch\u002Fblob\u002Fmain\u002Fvit_pytorch\u002Fcrossformer.py#L14\n- [x] cross embed layers for downsampling, as an option\n- [x] use an experimental tracker agnostic setup, as done \u003Ca href=\"https:\u002F\u002Fgithub.com\u002Flucidrains\u002Ftf-bind-transformer#simple-trainer-class-for-fine-tuning\">here\u003C\u002Fa>\n- [x] use pydantic for config drive training\n- [x] for both diffusion prior and decoder, all exponential moving averaged models needs to be saved and restored as well (as well as the step number)\n- [x] offer save \u002F load methods on the trainer classes to automatically take care of state dicts for scalers \u002F optimizers \u002F saving versions and checking for breaking changes\n- [x] allow for creation of diffusion prior model off pydantic config classes - consider the same for tracker configs\n- [x] bring in skip-layer excitations (from lightweight gan paper) to see if it helps for either decoder of unet or vqgan-vae training (doesnt work well)\n- [x] test out grid attention in cascading ddpm locally, decide whether to keep or remove https:\u002F\u002Farxiv.org\u002Fabs\u002F2204.01697 (keeping, seems to be fine)\n- [x] allow for unet to be able to condition non-cross attention style as well\n- [x] speed up inference, read up on papers (ddim)\n- [x] add inpainting ability using resampler from repaint paper https:\u002F\u002Farxiv.org\u002Fabs\u002F2201.09865\n- [x] add the final combination of upsample feature maps, used in unet squared, seems to have an effect in local experiments\n- [ ] consider elucidated dalle2 https:\u002F\u002Farxiv.org\u002Fabs\u002F2206.00364\n- [ ] add simple outpainting, text-guided 2x size the image for starters\n- [ ] interface out the vqgan-vae so a pretrained one can be pulled off the shelf to validate latent diffusion + DALL-E2\n\n## Citations\n\n```bibtex\n@misc{ramesh2022,\n    title   = {Hierarchical Text-Conditional Image Generation with CLIP Latents}, \n    author  = {Aditya Ramesh et al},\n    year    = {2022}\n}\n```\n\n```bibtex\n@misc{crowson2022,\n    author  = {Katherine Crowson},\n    url     = {https:\u002F\u002Ftwitter.com\u002Frivershavewings}\n}\n```\n\n```bibtex\n@misc{rombach2021highresolution,\n    title   = {High-Resolution Image Synthesis with Latent Diffusion Models}, \n    author  = {Robin Rombach and Andreas Blattmann and Dominik Lorenz and Patrick Esser and Björn Ommer},\n    year    = {2021},\n    eprint  = {2112.10752},\n    archivePrefix = {arXiv},\n    primaryClass = {cs.CV}\n}\n```\n\n```bibtex\n@article{shen2019efficient,\n    author  = {Zhuoran Shen and Mingyuan Zhang and Haiyu Zhao and Shuai Yi and Hongsheng Li},\n    title   = {Efficient Attention: Attention with Linear Complexities},\n    journal = {CoRR},\n    year    = {2018},\n    url     = {http:\u002F\u002Farxiv.org\u002Fabs\u002F1812.01243},\n}\n```\n\n```bibtex\n@article{Yu2021VectorquantizedIM,\n    title   = {Vector-quantized Image Modeling with Improved VQGAN},\n    author  = {Jiahui Yu and Xin Li and Jing Yu Koh and Han Zhang and Ruoming Pang and James Qin and Alexander Ku and Yuanzhong Xu and Jason Baldridge and Yonghui Wu},\n    journal = {ArXiv},\n    year    = {2021},\n    volume  = {abs\u002F2110.04627}\n}\n```\n\n```bibtex\n@article{Shleifer2021NormFormerIT,\n    title   = {NormFormer: Improved Transformer Pretraining with Extra Normalization},\n    author  = {Sam Shleifer and Jason Weston and Myle Ott},\n    journal = {ArXiv},\n    year    = {2021},\n    volume  = {abs\u002F2110.09456}\n}\n```\n\n```bibtex\n@article{Yu2022CoCaCC,\n    title   = {CoCa: Contrastive Captioners are Image-Text Foundation Models},\n    author  = {Jiahui Yu and Zirui Wang and Vijay Vasudevan and Legg Yeung and Mojtaba Seyedhosseini and Yonghui Wu},\n    journal = {ArXiv},\n    year    = {2022},\n    volume  = {abs\u002F2205.01917}\n}\n```\n\n```bibtex\n@misc{wang2021crossformer,\n    title   = {CrossFormer: A Versatile Vision Transformer Hinging on Cross-scale Attention},\n    author  = {Wenxiao Wang and Lu Yao and Long Chen and Binbin Lin and Deng Cai and Xiaofei He and Wei Liu},\n    year    = {2021},\n    eprint  = {2108.00154},\n    archivePrefix = {arXiv},\n    primaryClass = {cs.CV}\n}\n```\n\n```bibtex\n@article{ho2021cascaded,\n    title   = {Cascaded Diffusion Models for High Fidelity Image Generation},\n    author  = {Ho, Jonathan and Saharia, Chitwan and Chan, William and Fleet, David J and Norouzi, Mohammad and Salimans, Tim},\n    journal = {arXiv preprint arXiv:2106.15282},\n    year    = {2021}\n}\n```\n\n```bibtex\n@misc{Saharia2022,\n    title   = {Imagen: unprecedented photorealism × deep level of language understanding},\n    author  = {Chitwan Saharia*, William Chan*, Saurabh Saxena†, Lala Li†, Jay Whang†, Emily Denton, Seyed Kamyar Seyed Ghasemipour, Burcu Karagol Ayan, S. Sara Mahdavi, Rapha Gontijo Lopes, Tim Salimans, Jonathan Ho†, David Fleet†, Mohammad Norouzi*},\n    year    = {2022}\n}\n```\n\n```bibtex\n@article{Choi2022PerceptionPT,\n    title   = {Perception Prioritized Training of Diffusion Models},\n    author  = {Jooyoung Choi and Jungbeom Lee and Chaehun Shin and Sungwon Kim and Hyunwoo J. Kim and Sung-Hoon Yoon},\n    journal = {ArXiv},\n    year    = {2022},\n    volume  = {abs\u002F2204.00227}\n}\n```\n\n```bibtex\n@article{Saharia2021PaletteID,\n    title   = {Palette: Image-to-Image Diffusion Models},\n    author  = {Chitwan Saharia and William Chan and Huiwen Chang and Chris A. Lee and Jonathan Ho and Tim Salimans and David J. Fleet and Mohammad Norouzi},\n    journal = {ArXiv},\n    year    = {2021},\n    volume  = {abs\u002F2111.05826}\n}\n```\n\n```bibtex\n@article{Lugmayr2022RePaintIU,\n    title   = {RePaint: Inpainting using Denoising Diffusion Probabilistic Models},\n    author  = {Andreas Lugmayr and Martin Danelljan and Andr{\\'e}s Romero and Fisher Yu and Radu Timofte and Luc Van Gool},\n    journal = {ArXiv},\n    year    = {2022},\n    volume  = {abs\u002F2201.09865}\n}\n```\n\n```bibtex\n@misc{chen2022analog,\n    title   = {Analog Bits: Generating Discrete Data using Diffusion Models with Self-Conditioning},\n    author  = {Ting Chen and Ruixiang Zhang and Geoffrey Hinton},\n    year    = {2022},\n    eprint  = {2208.04202},\n    archivePrefix = {arXiv},\n    primaryClass = {cs.CV}\n}\n```\n\n```bibtex\n@article{Qiao2019WeightS,\n    title   = {Weight Standardization},\n    author  = {Siyuan Qiao and Huiyu Wang and Chenxi Liu and Wei Shen and Alan Loddon Yuille},\n    journal = {ArXiv},\n    year    = {2019},\n    volume  = {abs\u002F1903.10520}\n}\n```\n\n```bibtex\n@inproceedings{rogozhnikov2022einops,\n    title   = {Einops: Clear and Reliable Tensor Manipulations with Einstein-like Notation},\n    author  = {Alex Rogozhnikov},\n    booktitle = {International Conference on Learning Representations},\n    year    = {2022},\n    url     = {https:\u002F\u002Fopenreview.net\u002Fforum?id=oapKSVM2bcj}\n}\n```\n\n```bibtex\n@article{Sunkara2022NoMS,\n    title   = {No More Strided Convolutions or Pooling: A New CNN Building Block for Low-Resolution Images and Small Objects},\n    author  = {Raja Sunkara and Tie Luo},\n    journal = {ArXiv},\n    year    = {2022},\n    volume  = {abs\u002F2208.03641}\n}\n```\n\n```bibtex\n@article{Salimans2022ProgressiveDF,\n    title   = {Progressive Distillation for Fast Sampling of Diffusion Models},\n    author  = {Tim Salimans and Jonathan Ho},\n    journal = {ArXiv},\n    year    = {2022},\n    volume  = {abs\u002F2202.00512}\n}\n```\n\n*Creating noise from data is easy; creating data from noise is generative modeling.* - \u003Ca href=\"https:\u002F\u002Farxiv.org\u002Fabs\u002F2011.13456\">Yang Song's paper\u003C\u002Fa>\n","该项目实现了OpenAI的DALL-E 2文本到图像合成神经网络的PyTorch版本。它通过一个额外的先验网络（可以是自回归变换器或扩散模型）来预测基于CLIP文本嵌入的图像嵌入，从而生成高质量的图像。此实现专注于构建性能最佳的扩散先验网络，并且使用了因果变换器作为去噪网络。适用于需要从文本描述生成高质量图像的应用场景，比如创意设计、内容创作等。项目提供了预训练模型和训练脚本，支持大规模并行训练。",2,"2026-06-11 03:24:18","top_topic"]