{"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/ptq4dit-post-training-quantization-for","title":"PTQ4DiT: Post-training Quantization for Diffusion Transformers","arxiv_id":"2405.16005","date":"2024-05-25","proceeding":null,"authors":["Junyi Wu","Haoxuan Wang","Yuzhang Shang","Mubarak Shah","Yan Yan"],"abstract":"The recent introduction of Diffusion Transformers (DiTs) has demonstrated exceptional capabilities in image generation by using a different backbone architecture, departing from traditional U-Nets and embracing the scalable nature of transformers. Despite their advanced capabilities, the wide deployment of DiTs, particularly for real-time applications, is currently hampered by considerable computational demands at the inference stage. Post-training Quantization (PTQ) has emerged as a fast and data-efficient solution that can significantly reduce computation and memory footprint by using low-bit weights and activations. However, its applicability to DiTs has not yet been explored and faces non-trivial difficulties due to the unique design of DiTs. In this paper, we propose PTQ4DiT, a specifically designed PTQ method for DiTs. We discover two primary quantization challenges inherent in DiTs, notably the presence of salient channels with extreme magnitudes and the temporal variability in distributions of salient activation over multiple timesteps. To tackle these challenges, we propose Channel-wise Salience Balancing (CSB) and Spearmen's $\\rho$-guided Salience Calibration (SSC). CSB leverages the complementarity property of channel magnitudes to redistribute the extremes, alleviating quantization errors for both activations and weights. SSC extends this approach by dynamically adjusting the balanced salience to capture the temporal variations in activation. Additionally, to eliminate extra computational costs caused by PTQ4DiT during inference, we design an offline re-parameterization strategy for DiTs. Experiments demonstrate that our PTQ4DiT successfully quantizes DiTs to 8-bit precision (W8A8) while preserving comparable generation ability and further enables effective quantization to 4-bit weight precision (W4A8) for the first time.","url_abs":"https://arxiv.org/abs/2405.16005v3","url_pdf":"https://arxiv.org/pdf/2405.16005v3.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":"ptq4dit-post-training-quantization-for","repo_url":"https://github.com/adreamwu/ptq4dit","is_official":1,"mentioned_in_paper":1,"mentioned_in_github":1,"framework":"pytorch","reach":null}],"tasks":[{"task_slug":"image-generation","task_name":"Image Generation"},{"task_slug":"quantization","task_name":"Quantization"}],"methods":[{"method_slug":"diffusion","method_name":"Diffusion"}],"datasets_introduced":[],"methods_introduced":[],"results":[],"syntology":{"atlas_url":"https://app.syntology.ai/?focus=2405.16005","mcp":{"get_harvested_code_for_paper":{"arxiv_id":"2405.16005"}},"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/adreamwu/ptq4dit","reach":null}],"summary":{"ran_draft_wrong":1,"ran":7,"ran_fixture":1,"unverified":12},"by_repo_kind":{"official":{"samples":19,"ran":7,"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":21,"samples":[{"code_sha256_prefix":"675da8641c602b03","entry":"round_ste","repo":null,"repo_kind":null,"path":null,"file_url":null,"link_basis":"identical_code_first_harvested_elsewhere","language":"python","status":"ran_draft_wrong","verification_level":2,"contract_check":"MISDECLARED","metamorphic_tier":"invariant","behaviour_fingerprint":true,"licence":null,"inline_ok":false,"mcp_get_code":{"code_sha256":"675da8641c602b03"}},{"code_sha256_prefix":"623291d109e82c34","entry":"Attention","repo":"adreamwu/ptq4dit","repo_kind":"official","path":"quant/layer_recon.py","file_url":"https://github.com/adreamwu/ptq4dit/blob/HEAD/quant/layer_recon.py","link_basis":"first_harvest_node","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":"deterministic","behaviour_fingerprint":false,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"623291d109e82c34"}},{"code_sha256_prefix":"1d9158f89f879a34","entry":"DataSaverHook","repo":"adreamwu/ptq4dit","repo_kind":"official","path":"quant/layer_recon.py","file_url":"https://github.com/adreamwu/ptq4dit/blob/HEAD/quant/layer_recon.py","link_basis":"first_harvest_node","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"1d9158f89f879a34"}},{"code_sha256_prefix":"4c33b681b95218bb","entry":"LinearTempDecay","repo":"adreamwu/ptq4dit","repo_kind":"official","path":"quant/layer_recon.py","file_url":"https://github.com/adreamwu/ptq4dit/blob/HEAD/quant/layer_recon.py","link_basis":"first_harvest_node","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"4c33b681b95218bb"}},{"code_sha256_prefix":"2cfea2de6e135773","entry":"Mlp","repo":"adreamwu/ptq4dit","repo_kind":"official","path":"quant/layer_recon.py","file_url":"https://github.com/adreamwu/ptq4dit/blob/HEAD/quant/layer_recon.py","link_basis":"first_harvest_node","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":"deterministic","behaviour_fingerprint":false,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"2cfea2de6e135773"}},{"code_sha256_prefix":"13900bea8f3b93a1","entry":"StopForwardException","repo":"adreamwu/ptq4dit","repo_kind":"official","path":"quant/layer_recon.py","file_url":"https://github.com/adreamwu/ptq4dit/blob/HEAD/quant/layer_recon.py","link_basis":"first_harvest_node","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":"deterministic","behaviour_fingerprint":false,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"13900bea8f3b93a1"}},{"code_sha256_prefix":"382e4d6d6d5d10b0","entry":"StraightThrough","repo":"adreamwu/ptq4dit","repo_kind":"official","path":"quant/layer_recon.py","file_url":"https://github.com/adreamwu/ptq4dit/blob/HEAD/quant/layer_recon.py","link_basis":"first_harvest_node","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":true,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"382e4d6d6d5d10b0"}},{"code_sha256_prefix":"f237f023cdb441a9","entry":"UniformAffineQuantizer","repo":"adreamwu/ptq4dit","repo_kind":"official","path":"quant/layer_recon.py","file_url":"https://github.com/adreamwu/ptq4dit/blob/HEAD/quant/layer_recon.py","link_basis":"first_harvest_node","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":"deterministic","behaviour_fingerprint":true,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"f237f023cdb441a9"}},{"code_sha256_prefix":"08c6ea7576220a13","entry":"lp_loss","repo":null,"repo_kind":null,"path":null,"file_url":null,"link_basis":"identical_code_first_harvested_elsewhere","language":"python","status":"ran_fixture","verification_level":1,"contract_check":"RAISES","metamorphic_tier":"invariant","behaviour_fingerprint":true,"licence":null,"inline_ok":false,"mcp_get_code":{"code_sha256":"08c6ea7576220a13"}},{"code_sha256_prefix":"e18ddf8148f56942","entry":"AdaRoundQuantizer","repo":"adreamwu/ptq4dit","repo_kind":"official","path":"quant/layer_recon.py","file_url":"https://github.com/adreamwu/ptq4dit/blob/HEAD/quant/layer_recon.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"e18ddf8148f56942"}},{"code_sha256_prefix":"7eb71652f7925d3a","entry":"BaseQuantBlock","repo":"adreamwu/ptq4dit","repo_kind":"official","path":"quant/layer_recon.py","file_url":"https://github.com/adreamwu/ptq4dit/blob/HEAD/quant/layer_recon.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"7eb71652f7925d3a"}},{"code_sha256_prefix":"31126f616a1300f1","entry":"DiTBlock","repo":"adreamwu/ptq4dit","repo_kind":"official","path":"quant/layer_recon.py","file_url":"https://github.com/adreamwu/ptq4dit/blob/HEAD/quant/layer_recon.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"31126f616a1300f1"}},{"code_sha256_prefix":"985822f943599470","entry":"GetLayerInpOut","repo":"adreamwu/ptq4dit","repo_kind":"official","path":"quant/layer_recon.py","file_url":"https://github.com/adreamwu/ptq4dit/blob/HEAD/quant/layer_recon.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"985822f943599470"}},{"code_sha256_prefix":"cc1d937a9352676a","entry":"LossFunction","repo":"adreamwu/ptq4dit","repo_kind":"official","path":"quant/layer_recon.py","file_url":"https://github.com/adreamwu/ptq4dit/blob/HEAD/quant/layer_recon.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"cc1d937a9352676a"}},{"code_sha256_prefix":"dacb0f6316a59775","entry":"QuantDiTBlock","repo":"adreamwu/ptq4dit","repo_kind":"official","path":"quant/layer_recon.py","file_url":"https://github.com/adreamwu/ptq4dit/blob/HEAD/quant/layer_recon.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"dacb0f6316a59775"}},{"code_sha256_prefix":"7c760bf5741cff4d","entry":"QuantFinalLayer","repo":"adreamwu/ptq4dit","repo_kind":"official","path":"quant/layer_recon.py","file_url":"https://github.com/adreamwu/ptq4dit/blob/HEAD/quant/layer_recon.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"7c760bf5741cff4d"}},{"code_sha256_prefix":"7e5d23a4a2b80dbd","entry":"QuantModel","repo":"adreamwu/ptq4dit","repo_kind":"official","path":"quant/layer_recon.py","file_url":"https://github.com/adreamwu/ptq4dit/blob/HEAD/quant/layer_recon.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"7e5d23a4a2b80dbd"}},{"code_sha256_prefix":"384bed9ea057ffc6","entry":"QuantModule","repo":"adreamwu/ptq4dit","repo_kind":"official","path":"quant/layer_recon.py","file_url":"https://github.com/adreamwu/ptq4dit/blob/HEAD/quant/layer_recon.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"384bed9ea057ffc6"}},{"code_sha256_prefix":"190cc4466b584805","entry":"get_specials","repo":"adreamwu/ptq4dit","repo_kind":"official","path":"quant/layer_recon.py","file_url":"https://github.com/adreamwu/ptq4dit/blob/HEAD/quant/layer_recon.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"190cc4466b584805"}},{"code_sha256_prefix":"422a5c8d1d390767","entry":"layer_reconstruction","repo":"adreamwu/ptq4dit","repo_kind":"official","path":"quant/layer_recon.py","file_url":"https://github.com/adreamwu/ptq4dit/blob/HEAD/quant/layer_recon.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"422a5c8d1d390767"}},{"code_sha256_prefix":"5d18164308d717eb","entry":"save_inp_oup_data","repo":"adreamwu/ptq4dit","repo_kind":"official","path":"quant/layer_recon.py","file_url":"https://github.com/adreamwu/ptq4dit/blob/HEAD/quant/layer_recon.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"5d18164308d717eb"}}]},"arxiv_metadata":null,"syntology_extracted_results":null}