{"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/trol-traversal-of-layers-for-large-language","title":"TroL: Traversal of Layers for Large Language and Vision Models","arxiv_id":"2406.12246","date":"2024-06-18","proceeding":null,"authors":["Byung-Kwan Lee","Sangyun Chung","Chae Won Kim","Beomchan Park","Yong Man Ro"],"abstract":"Large language and vision models (LLVMs) have been driven by the generalization power of large language models (LLMs) and the advent of visual instruction tuning. Along with scaling them up directly, these models enable LLVMs to showcase powerful vision language (VL) performances by covering diverse tasks via natural language instructions. However, existing open-source LLVMs that perform comparably to closed-source LLVMs such as GPT-4V are often considered too large (e.g., 26B, 34B, and 110B parameters), having a larger number of layers. These large models demand costly, high-end resources for both training and inference. To address this issue, we present a new efficient LLVM family with 1.8B, 3.8B, and 7B LLM model sizes, Traversal of Layers (TroL), which enables the reuse of layers in a token-wise manner. This layer traversing technique simulates the effect of looking back and retracing the answering stream while increasing the number of forward propagation layers without physically adding more layers. We demonstrate that TroL employs a simple layer traversing approach yet efficiently outperforms the open-source LLVMs with larger model sizes and rivals the performances of the closed-source LLVMs with substantial sizes.","url_abs":"https://arxiv.org/abs/2406.12246v3","url_pdf":"https://arxiv.org/pdf/2406.12246v3.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":"trol-traversal-of-layers-for-large-language","repo_url":"https://github.com/byungkwanlee/trol","is_official":1,"mentioned_in_paper":1,"mentioned_in_github":1,"framework":"pytorch","reach":{"status":"ok"}}],"tasks":[{"task_slug":"visual-question-answering-1","task_name":"Visual Question Answering"}],"methods":[],"datasets_introduced":[],"methods_introduced":[],"results":[{"leaderboard":"/sota/visual-question-answering-on-mm-vet","task":"Visual Question Answering","dataset":"MM-Vet","model":"TroL-7B","rank_in_archive_order":49,"of":231,"metrics":{"GPT-4 score":"54.7","Params":"7B"},"uses_additional_data":false}],"syntology":{"syntology_url":null,"atlas_url":"https://app.syntology.ai/?focus=2406.12246","mcp":{"get_harvested_code_for_paper":{"arxiv_id":"2406.12246"}},"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/byungkwanlee/trol","reach":{"status":"ok"}},{"provenance":"deterministic:regex_extraction","url":"https://github.com/ByungKwanLee/TroL","reach":{"status":"ok"}}],"summary":{"ran_fixture":3,"ran":14,"ran_draft_wrong":5,"unverified":8},"by_repo_kind":{"official":{"samples":30,"ran":22,"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":30,"samples":[{"code_sha256_prefix":"30d7eec482ebf6b1","entry":"repeat_kv","repo":"byungkwanlee/trol","repo_kind":"official","path":"trol/arch_phi3/modeling_phi3.py","file_url":"https://github.com/byungkwanlee/trol/blob/HEAD/trol/arch_phi3/modeling_phi3.py","link_basis":"harvester_set","language":"python","status":"ran_fixture","verification_level":2,"contract_check":"RAISES","metamorphic_tier":"invariant","behaviour_fingerprint":true,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"30d7eec482ebf6b1"}},{"code_sha256_prefix":"857584bac85d8412","entry":"IdentityMap","repo":"ByungKwanLee/TroL","repo_kind":"official","path":"trol/arch_internlm2/modeling_trol.py","file_url":"https://github.com/ByungKwanLee/TroL/blob/HEAD/trol/arch_internlm2/modeling_trol.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":"857584bac85d8412"}},{"code_sha256_prefix":"9822da74ee01d405","entry":"InternLM2Config","repo":"ByungKwanLee/TroL","repo_kind":"official","path":"trol/arch_internlm2/modeling_trol.py","file_url":"https://github.com/ByungKwanLee/TroL/blob/HEAD/trol/arch_internlm2/modeling_trol.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":"9822da74ee01d405"}},{"code_sha256_prefix":"4361bf5382e3c53c","entry":"InternLM2DecoderLayer","repo":"ByungKwanLee/TroL","repo_kind":"official","path":"trol/arch_internlm2/modeling_trol.py","file_url":"https://github.com/ByungKwanLee/TroL/blob/HEAD/trol/arch_internlm2/modeling_trol.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":"4361bf5382e3c53c"}},{"code_sha256_prefix":"47e0c2b232b80540","entry":"InternLM2DynamicNTKScalingRotaryEmbedding","repo":"ByungKwanLee/TroL","repo_kind":"official","path":"trol/arch_internlm2/modeling_trol.py","file_url":"https://github.com/ByungKwanLee/TroL/blob/HEAD/trol/arch_internlm2/modeling_trol.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":"47e0c2b232b80540"}},{"code_sha256_prefix":"d0ec931771ba164d","entry":"InternLM2FlashAttention2","repo":"ByungKwanLee/TroL","repo_kind":"official","path":"trol/arch_internlm2/modeling_trol.py","file_url":"https://github.com/ByungKwanLee/TroL/blob/HEAD/trol/arch_internlm2/modeling_trol.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":"d0ec931771ba164d"}},{"code_sha256_prefix":"f4d34988b284f4c3","entry":"InternLM2MLP","repo":"ByungKwanLee/TroL","repo_kind":"official","path":"trol/arch_internlm2/modeling_trol.py","file_url":"https://github.com/ByungKwanLee/TroL/blob/HEAD/trol/arch_internlm2/modeling_trol.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":"f4d34988b284f4c3"}},{"code_sha256_prefix":"e7b40b692059c263","entry":"InternLM2PreTrainedModel","repo":"ByungKwanLee/TroL","repo_kind":"official","path":"trol/arch_internlm2/modeling_trol.py","file_url":"https://github.com/ByungKwanLee/TroL/blob/HEAD/trol/arch_internlm2/modeling_trol.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":"e7b40b692059c263"}},{"code_sha256_prefix":"817ef1d945956306","entry":"InternLM2RMSNorm","repo":"ByungKwanLee/TroL","repo_kind":"official","path":"trol/arch_internlm2/modeling_trol.py","file_url":"https://github.com/ByungKwanLee/TroL/blob/HEAD/trol/arch_internlm2/modeling_trol.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":"817ef1d945956306"}},{"code_sha256_prefix":"611ae4bdd7a59aa3","entry":"InternLM2RotaryEmbedding","repo":"ByungKwanLee/TroL","repo_kind":"official","path":"trol/arch_internlm2/modeling_trol.py","file_url":"https://github.com/ByungKwanLee/TroL/blob/HEAD/trol/arch_internlm2/modeling_trol.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":"611ae4bdd7a59aa3"}},{"code_sha256_prefix":"cce1025c634158b5","entry":"LoRA","repo":"ByungKwanLee/TroL","repo_kind":"official","path":"trol/arch_internlm2/modeling_trol.py","file_url":"https://github.com/ByungKwanLee/TroL/blob/HEAD/trol/arch_internlm2/modeling_trol.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":"cce1025c634158b5"}},{"code_sha256_prefix":"7df2e495a39e79bb","entry":"TroLCausalLMOutputWithPast","repo":"ByungKwanLee/TroL","repo_kind":"official","path":"trol/arch_internlm2/modeling_trol.py","file_url":"https://github.com/ByungKwanLee/TroL/blob/HEAD/trol/arch_internlm2/modeling_trol.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":"7df2e495a39e79bb"}},{"code_sha256_prefix":"3794e953547aa39d","entry":"_expand_mask","repo":"ByungKwanLee/TroL","repo_kind":"official","path":"trol/arch_internlm2/modeling_trol.py","file_url":"https://github.com/ByungKwanLee/TroL/blob/HEAD/trol/arch_internlm2/modeling_trol.py","link_basis":"first_harvest_node","language":"python","status":"ran_draft_wrong","verification_level":1,"contract_check":"MISDECLARED","metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"3794e953547aa39d"}},{"code_sha256_prefix":"1df4c4c3e8d2767d","entry":"_get_unpad_data","repo":"ByungKwanLee/TroL","repo_kind":"official","path":"trol/arch_internlm2/modeling_trol.py","file_url":"https://github.com/ByungKwanLee/TroL/blob/HEAD/trol/arch_internlm2/modeling_trol.py","link_basis":"first_harvest_node","language":"python","status":"ran_draft_wrong","verification_level":1,"contract_check":"OUTPUT_MISDECLARED","metamorphic_tier":"deterministic","behaviour_fingerprint":true,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"1df4c4c3e8d2767d"}},{"code_sha256_prefix":"3a68636f8c901f91","entry":"_make_causal_mask","repo":"ByungKwanLee/TroL","repo_kind":"official","path":"trol/arch_internlm2/modeling_trol.py","file_url":"https://github.com/ByungKwanLee/TroL/blob/HEAD/trol/arch_internlm2/modeling_trol.py","link_basis":"first_harvest_node","language":"python","status":"ran_fixture","verification_level":1,"contract_check":"RAISES","metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"3a68636f8c901f91"}},{"code_sha256_prefix":"bac65c3dafaec040","entry":"apply_rotary_pos_emb","repo":"byungkwanlee/trol","repo_kind":"official","path":"trol/arch_phi3/modeling_phi3.py","file_url":"https://github.com/byungkwanlee/trol/blob/HEAD/trol/arch_phi3/modeling_phi3.py","link_basis":"harvester_set","language":"python","status":"ran_draft_wrong","verification_level":1,"contract_check":"MISDECLARED","metamorphic_tier":"invariant","behaviour_fingerprint":false,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"bac65c3dafaec040"}},{"code_sha256_prefix":"4836c910f4ac2e06","entry":"build_vision_projector","repo":"ByungKwanLee/TroL","repo_kind":"official","path":"trol/arch_internlm2/modeling_trol.py","file_url":"https://github.com/ByungKwanLee/TroL/blob/HEAD/trol/arch_internlm2/modeling_trol.py","link_basis":"first_harvest_node","language":"python","status":"ran_draft_wrong","verification_level":1,"contract_check":"OUTPUT_MISDECLARED","metamorphic_tier":"deterministic","behaviour_fingerprint":false,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"4836c910f4ac2e06"}},{"code_sha256_prefix":"ec01154f26b3b92e","entry":"build_vision_projector","repo":"byungkwanlee/trol","repo_kind":"official","path":"trol/arch_internlm2/build_module.py","file_url":"https://github.com/byungkwanlee/trol/blob/HEAD/trol/arch_internlm2/build_module.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":"ec01154f26b3b92e"}},{"code_sha256_prefix":"53e08d7b0496620d","entry":"build_vision_tower","repo":"ByungKwanLee/TroL","repo_kind":"official","path":"trol/arch_internlm2/modeling_trol.py","file_url":"https://github.com/ByungKwanLee/TroL/blob/HEAD/trol/arch_internlm2/modeling_trol.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":"53e08d7b0496620d"}},{"code_sha256_prefix":"6045450d1a869974","entry":"repeat_kv","repo":"ByungKwanLee/TroL","repo_kind":"official","path":"trol/arch_internlm2/modeling_trol.py","file_url":"https://github.com/ByungKwanLee/TroL/blob/HEAD/trol/arch_internlm2/modeling_trol.py","link_basis":"first_harvest_node","language":"python","status":"ran_fixture","verification_level":1,"contract_check":"RAISES","metamorphic_tier":null,"behaviour_fingerprint":true,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"6045450d1a869974"}},{"code_sha256_prefix":"c0aae1f053da2578","entry":"repeat_kv","repo":"byungkwanlee/trol","repo_kind":"official","path":"trol/arch_internlm2/modeling_internlm2.py","file_url":"https://github.com/byungkwanlee/trol/blob/HEAD/trol/arch_internlm2/modeling_internlm2.py","link_basis":"harvester_set","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":"c0aae1f053da2578"}},{"code_sha256_prefix":"b99eea6376d1e212","entry":"rotate_half","repo":"byungkwanlee/trol","repo_kind":"official","path":"trol/arch_internlm2/modeling_internlm2.py","file_url":"https://github.com/byungkwanlee/trol/blob/HEAD/trol/arch_internlm2/modeling_internlm2.py","link_basis":"harvester_set","language":"python","status":"ran_draft_wrong","verification_level":1,"contract_check":"MISDECLARED","metamorphic_tier":"invariant","behaviour_fingerprint":true,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"b99eea6376d1e212"}},{"code_sha256_prefix":"10e2214bdfa59401","entry":"CLIPVisionTower","repo":"ByungKwanLee/TroL","repo_kind":"official","path":"trol/arch_internlm2/modeling_trol.py","file_url":"https://github.com/ByungKwanLee/TroL/blob/HEAD/trol/arch_internlm2/modeling_trol.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":"10e2214bdfa59401"}},{"code_sha256_prefix":"b56683a8ab013eed","entry":"InternLM2Attention","repo":"ByungKwanLee/TroL","repo_kind":"official","path":"trol/arch_internlm2/modeling_trol.py","file_url":"https://github.com/ByungKwanLee/TroL/blob/HEAD/trol/arch_internlm2/modeling_trol.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":"b56683a8ab013eed"}},{"code_sha256_prefix":"47c71786c33638b3","entry":"InternLM2Model","repo":"ByungKwanLee/TroL","repo_kind":"official","path":"trol/arch_internlm2/modeling_trol.py","file_url":"https://github.com/ByungKwanLee/TroL/blob/HEAD/trol/arch_internlm2/modeling_trol.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":"47c71786c33638b3"}},{"code_sha256_prefix":"f16a36d9f1f29fad","entry":"TroLForCausalLM","repo":"ByungKwanLee/TroL","repo_kind":"official","path":"trol/arch_internlm2/modeling_trol.py","file_url":"https://github.com/ByungKwanLee/TroL/blob/HEAD/trol/arch_internlm2/modeling_trol.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":"f16a36d9f1f29fad"}},{"code_sha256_prefix":"b163c3fb95a74dcc","entry":"_import_flash_attn","repo":"ByungKwanLee/TroL","repo_kind":"official","path":"trol/arch_internlm2/modeling_trol.py","file_url":"https://github.com/ByungKwanLee/TroL/blob/HEAD/trol/arch_internlm2/modeling_trol.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":"b163c3fb95a74dcc"}},{"code_sha256_prefix":"c028aebfc37921e4","entry":"apply_rotary_pos_emb","repo":"ByungKwanLee/TroL","repo_kind":"official","path":"trol/arch_internlm2/modeling_trol.py","file_url":"https://github.com/ByungKwanLee/TroL/blob/HEAD/trol/arch_internlm2/modeling_trol.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":"c028aebfc37921e4"}},{"code_sha256_prefix":"051ebcfa8673a02e","entry":"apply_rotary_pos_emb","repo":"byungkwanlee/trol","repo_kind":"official","path":"trol/arch_internlm2/modeling_internlm2.py","file_url":"https://github.com/byungkwanlee/trol/blob/HEAD/trol/arch_internlm2/modeling_internlm2.py","link_basis":"harvester_set","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":"051ebcfa8673a02e"}},{"code_sha256_prefix":"6b626dcd8d06f0af","entry":"load_trol","repo":"byungkwanlee/trol","repo_kind":"official","path":"trol/load_trol.py","file_url":"https://github.com/byungkwanlee/trol/blob/HEAD/trol/load_trol.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":"6b626dcd8d06f0af"}}]},"arxiv_metadata":null,"syntology_extracted_results":null}