{"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/on-layer-normalization-in-the-transformer-1","title":"On Layer Normalization in the Transformer Architecture","arxiv_id":"2002.04745","date":"2020-02-12","proceeding":"ICML 2020 1","authors":["Ruibin Xiong","Yunchang Yang","Di He","Kai Zheng","Shuxin Zheng","Chen Xing","Huishuai Zhang","Yanyan Lan","Li-Wei Wang","Tie-Yan Liu"],"abstract":"The Transformer is widely used in natural language processing tasks. To train a Transformer however, one usually needs a carefully designed learning rate warm-up stage, which is shown to be crucial to the final performance but will slow down the optimization and bring more hyper-parameter tunings. In this paper, we first study theoretically why the learning rate warm-up stage is essential and show that the location of layer normalization matters. Specifically, we prove with mean field theory that at initialization, for the original-designed Post-LN Transformer, which places the layer normalization between the residual blocks, the expected gradients of the parameters near the output layer are large. Therefore, using a large learning rate on those gradients makes the training unstable. The warm-up stage is practically helpful for avoiding this problem. On the other hand, our theory also shows that if the layer normalization is put inside the residual blocks (recently proposed as Pre-LN Transformer), the gradients are well-behaved at initialization. This motivates us to remove the warm-up stage for the training of Pre-LN Transformers. We show in our experiments that Pre-LN Transformers without the warm-up stage can reach comparable results with baselines while requiring significantly less training time and hyper-parameter tuning on a wide range of applications.","url_abs":"https://arxiv.org/abs/2002.04745v2","url_pdf":"https://arxiv.org/pdf/2002.04745v2.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":"on-layer-normalization-in-the-transformer-1","repo_url":"https://github.com/airi-institute/gena_lm","is_official":0,"mentioned_in_paper":0,"mentioned_in_github":1,"framework":"pytorch","reach":null},{"paper_slug":"on-layer-normalization-in-the-transformer-1","repo_url":"https://github.com/blues-lin/fin-analyze","is_official":0,"mentioned_in_paper":0,"mentioned_in_github":1,"framework":"tf","reach":{"status":"ok"}},{"paper_slug":"on-layer-normalization-in-the-transformer-1","repo_url":"https://github.com/colorfulscoop/tfdlg","is_official":0,"mentioned_in_paper":0,"mentioned_in_github":1,"framework":"tf","reach":{"status":"ok","spdx":"MIT"}},{"paper_slug":"on-layer-normalization-in-the-transformer-1","repo_url":"https://github.com/davidsvy/cosformer-pytorch","is_official":0,"mentioned_in_paper":0,"mentioned_in_github":1,"framework":"pytorch","reach":{"status":"ok","spdx":"MIT"}},{"paper_slug":"on-layer-normalization-in-the-transformer-1","repo_url":"https://github.com/facebookresearch/xformers","is_official":0,"mentioned_in_paper":0,"mentioned_in_github":1,"framework":"pytorch","reach":null},{"paper_slug":"on-layer-normalization-in-the-transformer-1","repo_url":"https://github.com/noriyukipy/tfchat","is_official":0,"mentioned_in_paper":0,"mentioned_in_github":1,"framework":"tf","reach":{"status":"ok","spdx":"MIT"}},{"paper_slug":"on-layer-normalization-in-the-transformer-1","repo_url":"https://github.com/noriyukipy/tfdlg","is_official":0,"mentioned_in_paper":0,"mentioned_in_github":1,"framework":"tf","reach":null},{"paper_slug":"on-layer-normalization-in-the-transformer-1","repo_url":"https://github.com/yotaro-shimose/AttentionSolvesYourTSP","is_official":0,"mentioned_in_paper":0,"mentioned_in_github":1,"framework":"tf","reach":{"status":"ok"}},{"paper_slug":"on-layer-normalization-in-the-transformer-1","repo_url":"https://github.com/yangyucheng000/University/tree/main/model-3/roberta_prelayernorm","is_official":0,"mentioned_in_paper":0,"mentioned_in_github":0,"framework":"mindspore","reach":null}],"tasks":[],"methods":[{"method_slug":"absolute-position-encodings","method_name":"Absolute Position Encodings"},{"method_slug":"adam","method_name":"Adam"},{"method_slug":"attention","method_name":"Attention"},{"method_slug":"bpe","method_name":"BPE"},{"method_slug":"dense-connections","method_name":"Dense Connections"},{"method_slug":"dropout","method_name":"Dropout"},{"method_slug":"label-smoothing","method_name":"Label Smoothing"},{"method_slug":"layer-normalization","method_name":"Layer Normalization"},{"method_slug":"linear-layer","method_name":"Linear Layer"},{"method_slug":"multi-head-attention","method_name":"Multi-Head Attention"},{"method_slug":"position-wise-feed-forward-layer","method_name":"Position-Wise Feed-Forward Layer"},{"method_slug":"relu","method_name":"ReLU"},{"method_slug":"residual-connection","method_name":"Residual Connection"},{"method_slug":"softmax","method_name":"Softmax"},{"method_slug":"transformer","method_name":"Transformer"}],"datasets_introduced":[],"methods_introduced":[],"results":[],"syntology":{"atlas_url":"https://app.syntology.ai/?focus=2002.04745","mcp":{"get_harvested_code_for_paper":{"arxiv_id":"2002.04745"}},"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/noriyukipy/tfchat","reach":{"status":"ok","spdx":"MIT"}},{"provenance":"external:paperswithcode_snapshot_2025-07-28","url":"https://github.com/blues-lin/fin-analyze","reach":{"status":"ok"}},{"provenance":"external:paperswithcode_snapshot_2025-07-28","url":"https://github.com/airi-institute/gena_lm","reach":null},{"provenance":"external:paperswithcode_snapshot_2025-07-28","url":"https://github.com/yotaro-shimose/AttentionSolvesYourTSP","reach":{"status":"ok"}},{"provenance":"external:paperswithcode_snapshot_2025-07-28","url":"https://github.com/colorfulscoop/tfdlg","reach":{"status":"ok","spdx":"MIT"}},{"provenance":"external:paperswithcode_snapshot_2025-07-28","url":"https://github.com/davidsvy/cosformer-pytorch","reach":{"status":"ok","spdx":"MIT"}},{"provenance":"external:paperswithcode_snapshot_2025-07-28","url":"https://github.com/yangyucheng000/University/tree/main/model-3/roberta_prelayernorm","reach":null},{"provenance":"external:paperswithcode_snapshot_2025-07-28","url":"https://github.com/facebookresearch/xformers","reach":null},{"provenance":"external:paperswithcode_snapshot_2025-07-28","url":"https://github.com/noriyukipy/tfdlg","reach":null}],"summary":{"ran_honours":2,"unverified":9},"by_repo_kind":{"listed":{"samples":11,"ran":2,"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":"f10aa6a3b19fd64e","entry":"filter_to_topp","repo":"colorfulscoop/tfdlg","repo_kind":"listed","path":"tfdlg/generations.py","file_url":"https://github.com/colorfulscoop/tfdlg/blob/HEAD/tfdlg/generations.py","link_basis":"harvester_set","language":"python","status":"ran_honours","verification_level":1,"contract_check":"HONOURS","metamorphic_tier":null,"behaviour_fingerprint":true,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"f10aa6a3b19fd64e"}},{"code_sha256_prefix":"d7b9cc73b75d3829","entry":"gelu","repo":"colorfulscoop/tfdlg","repo_kind":"listed","path":"tfdlg/activations.py","file_url":"https://github.com/colorfulscoop/tfdlg/blob/HEAD/tfdlg/activations.py","link_basis":"harvester_set","language":"python","status":"ran_honours","verification_level":1,"contract_check":"HONOURS","metamorphic_tier":null,"behaviour_fingerprint":true,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"d7b9cc73b75d3829"}},{"code_sha256_prefix":"868953286060f3a8","entry":"create_look_ahead_mask","repo":"colorfulscoop/tfdlg","repo_kind":"listed","path":"tfdlg/models.py","file_url":"https://github.com/colorfulscoop/tfdlg/blob/HEAD/tfdlg/models.py","link_basis":"harvester_set","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":"868953286060f3a8"}},{"code_sha256_prefix":"fd2b714b8c2af39e","entry":"create_padding_mask","repo":"colorfulscoop/tfdlg","repo_kind":"listed","path":"tfdlg/models.py","file_url":"https://github.com/colorfulscoop/tfdlg/blob/HEAD/tfdlg/models.py","link_basis":"harvester_set","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":"fd2b714b8c2af39e"}},{"code_sha256_prefix":"22942e09fd44078d","entry":"encode_dialog","repo":"colorfulscoop/tfdlg","repo_kind":"listed","path":"tfdlg/dialog/tokenizers.py","file_url":"https://github.com/colorfulscoop/tfdlg/blob/HEAD/tfdlg/dialog/tokenizers.py","link_basis":"harvester_set","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":"22942e09fd44078d"}},{"code_sha256_prefix":"434564b8c9520cf5","entry":"filter_bad_ids","repo":"colorfulscoop/tfdlg","repo_kind":"listed","path":"tfdlg/generations.py","file_url":"https://github.com/colorfulscoop/tfdlg/blob/HEAD/tfdlg/generations.py","link_basis":"harvester_set","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":"434564b8c9520cf5"}},{"code_sha256_prefix":"ec70453aadfa3cc2","entry":"filter_to_topk","repo":"colorfulscoop/tfdlg","repo_kind":"listed","path":"tfdlg/generations.py","file_url":"https://github.com/colorfulscoop/tfdlg/blob/HEAD/tfdlg/generations.py","link_basis":"harvester_set","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":"ec70453aadfa3cc2"}},{"code_sha256_prefix":"c1a80ebe76a998e9","entry":"get","repo":"colorfulscoop/tfdlg","repo_kind":"listed","path":"tfdlg/activations.py","file_url":"https://github.com/colorfulscoop/tfdlg/blob/HEAD/tfdlg/activations.py","link_basis":"harvester_set","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":"c1a80ebe76a998e9"}},{"code_sha256_prefix":"255a1a9413a38abc","entry":"import_class","repo":"colorfulscoop/tfdlg","repo_kind":"listed","path":"tfdlg/utils.py","file_url":"https://github.com/colorfulscoop/tfdlg/blob/HEAD/tfdlg/utils.py","link_basis":"harvester_set","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":"255a1a9413a38abc"}},{"code_sha256_prefix":"932caee3efef6087","entry":"load_model","repo":"colorfulscoop/tfdlg","repo_kind":"listed","path":"tfdlg/utils.py","file_url":"https://github.com/colorfulscoop/tfdlg/blob/HEAD/tfdlg/utils.py","link_basis":"harvester_set","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":"932caee3efef6087"}},{"code_sha256_prefix":"3864ff9606edf68a","entry":"scaled_dot_product_attention","repo":"colorfulscoop/tfdlg","repo_kind":"listed","path":"tfdlg/models.py","file_url":"https://github.com/colorfulscoop/tfdlg/blob/HEAD/tfdlg/models.py","link_basis":"harvester_set","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":"3864ff9606edf68a"}}]},"arxiv_metadata":null,"syntology_extracted_results":null}