{"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/deja-vu-contextual-sparsity-for-efficient","title":"Deja Vu: Contextual Sparsity for Efficient LLMs at Inference Time","arxiv_id":"2310.17157","date":"2023-10-26","proceeding":null,"authors":["Zichang Liu","Jue Wang","Tri Dao","Tianyi Zhou","Binhang Yuan","Zhao Song","Anshumali Shrivastava","Ce Zhang","Yuandong Tian","Christopher Re","Beidi Chen"],"abstract":"Large language models (LLMs) with hundreds of billions of parameters have sparked a new wave of exciting AI applications. However, they are computationally expensive at inference time. Sparsity is a natural approach to reduce this cost, but existing methods either require costly retraining, have to forgo LLM's in-context learning ability, or do not yield wall-clock time speedup on modern hardware. We hypothesize that contextual sparsity, which are small, input-dependent sets of attention heads and MLP parameters that yield approximately the same output as the dense model for a given input, can address these issues. We show that contextual sparsity exists, that it can be accurately predicted, and that we can exploit it to speed up LLM inference in wall-clock time without compromising LLM's quality or in-context learning ability. Based on these insights, we propose DejaVu, a system that uses a low-cost algorithm to predict contextual sparsity on the fly given inputs to each layer, along with an asynchronous and hardware-aware implementation that speeds up LLM inference. We validate that DejaVu can reduce the inference latency of OPT-175B by over 2X compared to the state-of-the-art FasterTransformer, and over 6X compared to the widely used Hugging Face implementation, without compromising model quality. The code is available at https://github.com/FMInference/DejaVu.","url_abs":"https://arxiv.org/abs/2310.17157v1","url_pdf":"https://arxiv.org/pdf/2310.17157v1.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":"deja-vu-contextual-sparsity-for-efficient","repo_url":"https://github.com/fminference/dejavu","is_official":1,"mentioned_in_paper":1,"mentioned_in_github":0,"framework":"pytorch","reach":{"status":"ok"}}],"tasks":[{"task_slug":"in-context-learning","task_name":"In-Context Learning"}],"methods":[{"method_slug":"speed","method_name":"SPEED"}],"datasets_introduced":[],"methods_introduced":[],"results":[],"syntology":{"atlas_url":"https://app.syntology.ai/?focus=2310.17157","mcp":{"get_harvested_code_for_paper":{"arxiv_id":"2310.17157"}},"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/fminference/dejavu","reach":{"status":"ok"}}],"summary":{"ran":5,"unverified":3},"by_repo_kind":{"official":{"samples":8,"ran":5,"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":8,"samples":[{"code_sha256_prefix":"0fc1e42ee3bbf1da","entry":"relu_bwd","repo":"fminference/dejavu","repo_kind":"official","path":"Dejavu/src/ops/fused_dense_sparse_dejavu.py","file_url":"https://github.com/fminference/dejavu/blob/HEAD/Dejavu/src/ops/fused_dense_sparse_dejavu.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":"0fc1e42ee3bbf1da"}},{"code_sha256_prefix":"61f181f415fd3d1a","entry":"remap_state_dict_gpt2","repo":"fminference/dejavu","repo_kind":"official","path":"Dejavu/src/models/gpt_dejavu.py","file_url":"https://github.com/fminference/dejavu/blob/HEAD/Dejavu/src/models/gpt_dejavu.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":"61f181f415fd3d1a"}},{"code_sha256_prefix":"46e679033704e33c","entry":"remap_state_dict_opt","repo":"fminference/dejavu","repo_kind":"official","path":"Dejavu/src/utils/dejavu_util.py","file_url":"https://github.com/fminference/dejavu/blob/HEAD/Dejavu/src/utils/dejavu_util.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":"46e679033704e33c"}},{"code_sha256_prefix":"06f50c197a588116","entry":"shard_state_dict_tp","repo":"fminference/dejavu","repo_kind":"official","path":"Dejavu/src/models/gpt_dejavu.py","file_url":"https://github.com/fminference/dejavu/blob/HEAD/Dejavu/src/models/gpt_dejavu.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":"06f50c197a588116"}},{"code_sha256_prefix":"bdf490f8da1356d8","entry":"shard_state_dict_tp","repo":"fminference/dejavu","repo_kind":"official","path":"Dejavu/src/utils/dejavu_util.py","file_url":"https://github.com/fminference/dejavu/blob/HEAD/Dejavu/src/utils/dejavu_util.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":"bdf490f8da1356d8"}},{"code_sha256_prefix":"5bf63aeb28a5af62","entry":"fused_dropout_add","repo":"fminference/dejavu","repo_kind":"official","path":"Dejavu/src/ops/fused_dropout_add.py","file_url":"https://github.com/fminference/dejavu/blob/HEAD/Dejavu/src/ops/fused_dropout_add.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":"5bf63aeb28a5af62"}},{"code_sha256_prefix":"7d90bfd2cdefb203","entry":"jit_bias_dropout_add","repo":"fminference/dejavu","repo_kind":"official","path":"Dejavu/src/ops/fused_dropout_add.py","file_url":"https://github.com/fminference/dejavu/blob/HEAD/Dejavu/src/ops/fused_dropout_add.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":"7d90bfd2cdefb203"}},{"code_sha256_prefix":"51c47ddbea109a56","entry":"jit_dropout_add","repo":"fminference/dejavu","repo_kind":"official","path":"Dejavu/src/ops/fused_dropout_add.py","file_url":"https://github.com/fminference/dejavu/blob/HEAD/Dejavu/src/ops/fused_dropout_add.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":"51c47ddbea109a56"}}]},"arxiv_metadata":null,"syntology_extracted_results":null}