{"about":{"site":"https://codewithpapers.app","non_affiliation":"Code with Papers and Syntology are not affiliated with, endorsed by, or sponsored by Papers with Code, Meta, or the pwc-archive mirror.","licence":"CC BY-SA 4.0","licence_url":"https://creativecommons.org/licenses/by-sa/4.0/legalcode","attribution":"https://codewithpapers.app/attribution","modified":"archive material modified by Syntology; see the attribution page"},"url":"/paper/vitgan-training-gans-with-vision-transformers","title":"ViTGAN: Training GANs with Vision Transformers","arxiv_id":"2107.04589","date":"2021-07-09","proceeding":"ICLR 2022 4","authors":["Kwonjoon Lee","Huiwen Chang","Lu Jiang","Han Zhang","Zhuowen Tu","Ce Liu"],"abstract":"Recently, Vision Transformers (ViTs) have shown competitive performance on image recognition while requiring less vision-specific inductive biases. In this paper, we investigate if such performance can be extended to image generation. To this end, we integrate the ViT architecture into generative adversarial networks (GANs). For ViT discriminators, we observe that existing regularization methods for GANs interact poorly with self-attention, causing serious instability during training. To resolve this issue, we introduce several novel regularization techniques for training GANs with ViTs. For ViT generators, we examine architectural choices for latent and pixel mapping layers to facilitate convergence. Empirically, our approach, named ViTGAN, achieves comparable performance to the leading CNN-based GAN models on three datasets: CIFAR-10, CelebA, and LSUN bedroom.","url_abs":"https://arxiv.org/abs/2107.04589v2","url_pdf":"https://arxiv.org/pdf/2107.04589v2.pdf","source":{"archive":"pwc-archive (Hugging Face), CC BY-SA 4.0","snapshot":"2025-07-28","licence_url":"https://creativecommons.org/licenses/by-sa/4.0/legalcode","row_kind":"abstracts"},"code_links":[{"paper_slug":"vitgan-training-gans-with-vision-transformers","repo_url":"https://github.com/mlpc-ucsd/ViTGAN","is_official":1,"mentioned_in_paper":0,"mentioned_in_github":0,"framework":"pytorch","reach":null},{"paper_slug":"vitgan-training-gans-with-vision-transformers","repo_url":"https://github.com/lucidrains/parti-pytorch","is_official":0,"mentioned_in_paper":0,"mentioned_in_github":1,"framework":"pytorch","reach":null},{"paper_slug":"vitgan-training-gans-with-vision-transformers","repo_url":"https://github.com/wilile26811249/ViTGAN","is_official":0,"mentioned_in_paper":0,"mentioned_in_github":1,"framework":"pytorch","reach":null}],"tasks":[{"task_slug":"image-generation","task_name":"Image Generation"}],"methods":[{"method_slug":"convolution","method_name":"Convolution"},{"method_slug":"path-length-regularization","method_name":"Path Length Regularization"},{"method_slug":"r1-regularization","method_name":"R1 Regularization"},{"method_slug":"weight-demodulation","method_name":"Weight Demodulation"}],"datasets_introduced":[],"methods_introduced":[],"results":[{"leaderboard":"/sota/image-generation-on-cifar-10","task":"Image Generation","dataset":"CIFAR-10","model":"ViTGAN","rank_in_archive_order":38,"of":78,"metrics":{"FID":"6.66"},"uses_additional_data":false}],"syntology":{"atlas_url":"https://app.syntology.ai/?focus=2107.04589","mcp":{"get_harvested_code_for_paper":{"arxiv_id":"2107.04589"}},"developers":"https://syntology.ai/developers","read_at":"2026-09-24T18:15:14+00:00","read_at_is":"when the build read Syntology's graph, not when any sample ran","claim":"Per-sample execution status on synthesized fixtures; not a correctness claim about the paper. Samples come from repositories linked to the paper, official or community; repo_kind says which.","repos":[{"provenance":"external:paperswithcode_snapshot_2025-07-28","url":"https://github.com/lucidrains/parti-pytorch","reach":null},{"provenance":"external:paperswithcode_snapshot_2025-07-28","url":"https://github.com/mlpc-ucsd/ViTGAN","reach":null},{"provenance":"external:paperswithcode_snapshot_2025-07-28","url":"https://github.com/wilile26811249/ViTGAN","reach":null}],"summary":{"ran":13,"ran_draft_wrong":3,"unverified":2},"by_repo_kind":{"official":{"samples":1,"ran":1,"repositories":1},"listed":{"samples":16,"ran":14,"repositories":2},"community":{"samples":1,"ran":1,"repositories":1}},"repo_kind_vocabulary":{"official":"The archive marks this repository official for the paper","named_in_paper":"The archive records that the paper mentions this repository; it is not marked official","listed":"In the archive's code links for this paper, not marked official and not recorded as mentioned in the paper","found_in_text":"Syntology found this repository in the paper's own text; whether it is the authors' implementation is not asserted","community":"Not in the archive's code links for this paper; a community repository Syntology harvested"},"n_pointer_only_for_licence":0,"samples":[{"code_sha256_prefix":"e2a8ba11e0a8cc86","entry":"Attention","repo":"lucidrains/parti-pytorch","repo_kind":"listed","path":"parti_pytorch/vit_vqgan.py","file_url":"https://github.com/lucidrains/parti-pytorch/blob/HEAD/parti_pytorch/vit_vqgan.py","link_basis":"first_harvest_node","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"e2a8ba11e0a8cc86"}},{"code_sha256_prefix":"d4e0313631ba260f","entry":"Attention","repo":"wilile26811249/ViTGAN","repo_kind":"listed","path":"models.py","file_url":"https://github.com/wilile26811249/ViTGAN/blob/HEAD/models.py","link_basis":"first_harvest_node","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"d4e0313631ba260f"}},{"code_sha256_prefix":"f5b6aedd01aee2e5","entry":"ChanLayerNorm","repo":"lucidrains/parti-pytorch","repo_kind":"listed","path":"parti_pytorch/vit_vqgan.py","file_url":"https://github.com/lucidrains/parti-pytorch/blob/HEAD/parti_pytorch/vit_vqgan.py","link_basis":"first_harvest_node","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":true,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"f5b6aedd01aee2e5"}},{"code_sha256_prefix":"fc258e8fab867fb8","entry":"FeedForward","repo":"lucidrains/parti-pytorch","repo_kind":"listed","path":"parti_pytorch/vit_vqgan.py","file_url":"https://github.com/lucidrains/parti-pytorch/blob/HEAD/parti_pytorch/vit_vqgan.py","link_basis":"first_harvest_node","language":"python","status":"ran_draft_wrong","verification_level":1,"contract_check":"OUTPUT_MISDECLARED","metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"fc258e8fab867fb8"}},{"code_sha256_prefix":"b8553e30e2a59605","entry":"GEncoderBlock","repo":"wilile26811249/ViTGAN","repo_kind":"listed","path":"models.py","file_url":"https://github.com/wilile26811249/ViTGAN/blob/HEAD/models.py","link_basis":"first_harvest_node","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"b8553e30e2a59605"}},{"code_sha256_prefix":"db9e09fa314a8450","entry":"GTransformerEncoder","repo":"wilile26811249/ViTGAN","repo_kind":"listed","path":"models.py","file_url":"https://github.com/wilile26811249/ViTGAN/blob/HEAD/models.py","link_basis":"first_harvest_node","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"db9e09fa314a8450"}},{"code_sha256_prefix":"d1fb8f114fe3bf13","entry":"MLP","repo":"wilile26811249/ViTGAN","repo_kind":"listed","path":"models.py","file_url":"https://github.com/wilile26811249/ViTGAN/blob/HEAD/models.py","link_basis":"first_harvest_node","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":true,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"d1fb8f114fe3bf13"}},{"code_sha256_prefix":"5fe00770f0011e28","entry":"PEG","repo":"lucidrains/parti-pytorch","repo_kind":"listed","path":"parti_pytorch/vit_vqgan.py","file_url":"https://github.com/lucidrains/parti-pytorch/blob/HEAD/parti_pytorch/vit_vqgan.py","link_basis":"first_harvest_node","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"5fe00770f0011e28"}},{"code_sha256_prefix":"64f19fade720d0a0","entry":"RelPosBias2d","repo":"lucidrains/parti-pytorch","repo_kind":"listed","path":"parti_pytorch/vit_vqgan.py","file_url":"https://github.com/lucidrains/parti-pytorch/blob/HEAD/parti_pytorch/vit_vqgan.py","link_basis":"first_harvest_node","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":true,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"64f19fade720d0a0"}},{"code_sha256_prefix":"7bf61b3936e50c87","entry":"SLN","repo":"wilile26811249/ViTGAN","repo_kind":"listed","path":"models.py","file_url":"https://github.com/wilile26811249/ViTGAN/blob/HEAD/models.py","link_basis":"first_harvest_node","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"7bf61b3936e50c87"}},{"code_sha256_prefix":"ef119489abae949f","entry":"SPT","repo":"lucidrains/parti-pytorch","repo_kind":"listed","path":"parti_pytorch/vit_vqgan.py","file_url":"https://github.com/lucidrains/parti-pytorch/blob/HEAD/parti_pytorch/vit_vqgan.py","link_basis":"first_harvest_node","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"ef119489abae949f"}},{"code_sha256_prefix":"b4ad6aadc33ddbd3","entry":"SineLayer","repo":"wilile26811249/ViTGAN","repo_kind":"listed","path":"models.py","file_url":"https://github.com/wilile26811249/ViTGAN/blob/HEAD/models.py","link_basis":"first_harvest_node","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"b4ad6aadc33ddbd3"}},{"code_sha256_prefix":"df2561ae8a008410","entry":"SinusoidalPosEmb","repo":"lucidrains/parti-pytorch","repo_kind":"listed","path":"parti_pytorch/vit_vqgan.py","file_url":"https://github.com/lucidrains/parti-pytorch/blob/HEAD/parti_pytorch/vit_vqgan.py","link_basis":"first_harvest_node","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"df2561ae8a008410"}},{"code_sha256_prefix":"9502a3bad7826863","entry":"Transformer","repo":"lucidrains/parti-pytorch","repo_kind":"listed","path":"parti_pytorch/vit_vqgan.py","file_url":"https://github.com/lucidrains/parti-pytorch/blob/HEAD/parti_pytorch/vit_vqgan.py","link_basis":"first_harvest_node","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"9502a3bad7826863"}},{"code_sha256_prefix":"1b999f986d09befe","entry":"normalize_2nd_moment","repo":"teodorToshkov/ViTGAN-pytorch","repo_kind":"community","path":"models/vitgan_generator.py","file_url":"https://github.com/teodorToshkov/ViTGAN-pytorch/blob/HEAD/models/vitgan_generator.py","link_basis":"first_harvest_node","language":"python","status":"ran_draft_wrong","verification_level":1,"contract_check":"MISDECLARED","metamorphic_tier":"invariant","behaviour_fingerprint":true,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"1b999f986d09befe"}},{"code_sha256_prefix":"0dacaab9f42c160b","entry":"r1_loss","repo":"mlpc-ucsd/ViTGAN","repo_kind":"official","path":"train_stylegan2.py","file_url":"https://github.com/mlpc-ucsd/ViTGAN/blob/HEAD/train_stylegan2.py","link_basis":"first_harvest_node","language":"python","status":"ran_draft_wrong","verification_level":1,"contract_check":"MISDECLARED","metamorphic_tier":"invariant","behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"0dacaab9f42c160b"}},{"code_sha256_prefix":"ffa338e5b0089e84","entry":"Generator","repo":"wilile26811249/ViTGAN","repo_kind":"listed","path":"models.py","file_url":"https://github.com/wilile26811249/ViTGAN/blob/HEAD/models.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"ffa338e5b0089e84"}},{"code_sha256_prefix":"1c988e9ef49a3005","entry":"ViTEncDec","repo":"lucidrains/parti-pytorch","repo_kind":"listed","path":"parti_pytorch/vit_vqgan.py","file_url":"https://github.com/lucidrains/parti-pytorch/blob/HEAD/parti_pytorch/vit_vqgan.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"1c988e9ef49a3005"}}]},"arxiv_metadata":null,"syntology_extracted_results":null}