{"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/length-adaptive-transformer-train-once-with-1","title":"Length-Adaptive Transformer: Train Once with Length Drop, Use Anytime with Search","arxiv_id":"2010.07003","date":"2020-10-14","proceeding":"ACL 2021 5","authors":["Gyuwan Kim","Kyunghyun Cho"],"abstract":"Despite transformers' impressive accuracy, their computational cost is often prohibitive to use with limited computational resources. Most previous approaches to improve inference efficiency require a separate model for each possible computational budget. In this paper, we extend PoWER-BERT (Goyal et al., 2020) and propose Length-Adaptive Transformer that can be used for various inference scenarios after one-shot training. We train a transformer with LengthDrop, a structural variant of dropout, which stochastically determines a sequence length at each layer. We then conduct a multi-objective evolutionary search to find a length configuration that maximizes the accuracy and minimizes the efficiency metric under any given computational budget. Additionally, we significantly extend the applicability of PoWER-BERT beyond sequence-level classification into token-level classification with Drop-and-Restore process that drops word-vectors temporarily in intermediate layers and restores at the last layer if necessary. We empirically verify the utility of the proposed approach by demonstrating the superior accuracy-efficiency trade-off under various setups, including span-based question answering and text classification. Code is available at https://github.com/clovaai/length-adaptive-transformer.","url_abs":"https://arxiv.org/abs/2010.07003v2","url_pdf":"https://arxiv.org/pdf/2010.07003v2.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":"length-adaptive-transformer-train-once-with-1","repo_url":"https://github.com/clovaai/length-adaptive-transformer","is_official":1,"mentioned_in_paper":1,"mentioned_in_github":1,"framework":"pytorch","reach":{"status":"ok","spdx":"Apache-2.0"}}],"tasks":[{"task_slug":"classification-1","task_name":"Classification"},{"task_slug":"question-answering","task_name":"Question Answering"},{"task_slug":"text-classification","task_name":"Text Classification"},{"task_slug":"text-classification-1","task_name":"text-classification"}],"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":"residual-connection","method_name":"Residual Connection"},{"method_slug":"softmax","method_name":"Softmax"},{"method_slug":"transformer","method_name":"Transformer"}],"datasets_introduced":[],"methods_introduced":[],"results":[],"syntology":{"syntology_url":null,"atlas_url":"https://app.syntology.ai/?focus=2010.07003","mcp":{"get_harvested_code_for_paper":{"arxiv_id":"2010.07003"}},"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/clovaai/length-adaptive-transformer","reach":{"status":"ok","spdx":"Apache-2.0"}}],"summary":{"ran_draft_wrong":2,"unverified":7},"by_repo_kind":{"official":{"samples":9,"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":"9df40357afea56cc","entry":"to_list","repo":"clovaai/length-adaptive-transformer","repo_kind":"official","path":"run_squad.py","file_url":"https://github.com/clovaai/length-adaptive-transformer/blob/HEAD/run_squad.py","link_basis":"harvester_set","language":"python","status":"ran_draft_wrong","verification_level":2,"contract_check":"MISDECLARED","metamorphic_tier":"invariant","behaviour_fingerprint":true,"licence":"Apache-2.0","inline_ok":true,"mcp_get_code":{"code_sha256":"9df40357afea56cc"}},{"code_sha256_prefix":"7fd52b664fe8f304","entry":"expand_gather","repo":"clovaai/length-adaptive-transformer","repo_kind":"official","path":"length_adaptive_transformer/modeling_utils.py","file_url":"https://github.com/clovaai/length-adaptive-transformer/blob/HEAD/length_adaptive_transformer/modeling_utils.py","link_basis":"plan_row","language":"python","status":"ran_draft_wrong","verification_level":1,"contract_check":"MISDECLARED","metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"Apache-2.0","inline_ok":true,"mcp_get_code":{"code_sha256":"7fd52b664fe8f304"}},{"code_sha256_prefix":"20ffabbd14507550","entry":"approx_ratio","repo":"clovaai/length-adaptive-transformer","repo_kind":"official","path":"length_adaptive_transformer/evolution.py","file_url":"https://github.com/clovaai/length-adaptive-transformer/blob/HEAD/length_adaptive_transformer/evolution.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"Apache-2.0","inline_ok":true,"mcp_get_code":{"code_sha256":"20ffabbd14507550"}},{"code_sha256_prefix":"33ef3327b12d9567","entry":"disabled_tqdm","repo":"clovaai/length-adaptive-transformer","repo_kind":"official","path":"run_squad.py","file_url":"https://github.com/clovaai/length-adaptive-transformer/blob/HEAD/run_squad.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"Apache-2.0","inline_ok":true,"mcp_get_code":{"code_sha256":"33ef3327b12d9567"}},{"code_sha256_prefix":"ee2d397ecc114dca","entry":"div_loss","repo":"clovaai/length-adaptive-transformer","repo_kind":"official","path":"run_squad.py","file_url":"https://github.com/clovaai/length-adaptive-transformer/blob/HEAD/run_squad.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"Apache-2.0","inline_ok":true,"mcp_get_code":{"code_sha256":"ee2d397ecc114dca"}},{"code_sha256_prefix":"6b03101e9b8362e6","entry":"inverse","repo":"clovaai/length-adaptive-transformer","repo_kind":"official","path":"length_adaptive_transformer/evolution.py","file_url":"https://github.com/clovaai/length-adaptive-transformer/blob/HEAD/length_adaptive_transformer/evolution.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"Apache-2.0","inline_ok":true,"mcp_get_code":{"code_sha256":"6b03101e9b8362e6"}},{"code_sha256_prefix":"325fbe90ff350967","entry":"sample_layer_configuration","repo":"clovaai/length-adaptive-transformer","repo_kind":"official","path":"length_adaptive_transformer/drop_and_restore_utils.py","file_url":"https://github.com/clovaai/length-adaptive-transformer/blob/HEAD/length_adaptive_transformer/drop_and_restore_utils.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"Apache-2.0","inline_ok":true,"mcp_get_code":{"code_sha256":"325fbe90ff350967"}},{"code_sha256_prefix":"10c60046df699bef","entry":"sample_length_configuration","repo":"clovaai/length-adaptive-transformer","repo_kind":"official","path":"length_adaptive_transformer/drop_and_restore_utils.py","file_url":"https://github.com/clovaai/length-adaptive-transformer/blob/HEAD/length_adaptive_transformer/drop_and_restore_utils.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"Apache-2.0","inline_ok":true,"mcp_get_code":{"code_sha256":"10c60046df699bef"}},{"code_sha256_prefix":"ba1916aeba590880","entry":"store2str","repo":"clovaai/length-adaptive-transformer","repo_kind":"official","path":"length_adaptive_transformer/evolution.py","file_url":"https://github.com/clovaai/length-adaptive-transformer/blob/HEAD/length_adaptive_transformer/evolution.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"Apache-2.0","inline_ok":true,"mcp_get_code":{"code_sha256":"ba1916aeba590880"}}]},"arxiv_metadata":null,"syntology_extracted_results":null}