{"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/maskllm-learnable-semi-structured-sparsity","title":"MaskLLM: Learnable Semi-Structured Sparsity for Large Language Models","arxiv_id":"2409.17481","date":"2024-09-26","proceeding":null,"authors":["Gongfan Fang","Hongxu Yin","Saurav Muralidharan","Greg Heinrich","Jeff Pool","Jan Kautz","Pavlo Molchanov","Xinchao Wang"],"abstract":"Large Language Models (LLMs) are distinguished by their massive parameter counts, which typically result in significant redundancy. This work introduces MaskLLM, a learnable pruning method that establishes Semi-structured (or ``N:M'') Sparsity in LLMs, aimed at reducing computational overhead during inference. Instead of developing a new importance criterion, MaskLLM explicitly models N:M patterns as a learnable distribution through Gumbel Softmax sampling. This approach facilitates end-to-end training on large-scale datasets and offers two notable advantages: 1) High-quality Masks - our method effectively scales to large datasets and learns accurate masks; 2) Transferability - the probabilistic modeling of mask distribution enables the transfer learning of sparsity across domains or tasks. We assessed MaskLLM using 2:4 sparsity on various LLMs, including LLaMA-2, Nemotron-4, and GPT-3, with sizes ranging from 843M to 15B parameters, and our empirical results show substantial improvements over state-of-the-art methods. For instance, leading approaches achieve a perplexity (PPL) of 10 or greater on Wikitext compared to the dense model's 5.12 PPL, but MaskLLM achieves a significantly lower 6.72 PPL solely by learning the masks with frozen weights. Furthermore, MaskLLM's learnable nature allows customized masks for lossless application of 2:4 sparsity to downstream tasks or domains. Code is available at https://github.com/NVlabs/MaskLLM.","url_abs":"https://arxiv.org/abs/2409.17481v2","url_pdf":"https://arxiv.org/pdf/2409.17481v2.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":"maskllm-learnable-semi-structured-sparsity","repo_url":"https://github.com/nvlabs/maskllm","is_official":1,"mentioned_in_paper":1,"mentioned_in_github":1,"framework":"pytorch","reach":{"status":"ok","spdx":"NOASSERTION"}}],"tasks":[{"task_slug":"large-language-model","task_name":"Large Language Model"},{"task_slug":"model-compression","task_name":"Model Compression"},{"task_slug":"network-pruning","task_name":"Network Pruning"},{"task_slug":"transfer-learning","task_name":"Transfer Learning"}],"methods":[{"method_slug":"adam","method_name":"Adam"},{"method_slug":"attention","method_name":"Attention"},{"method_slug":"attention-dropout","method_name":"Attention Dropout"},{"method_slug":"bpe","method_name":"BPE"},{"method_slug":"cosine-annealing","method_name":"Cosine Annealing"},{"method_slug":"dense-connections","method_name":"Dense Connections"},{"method_slug":"dropout","method_name":"Dropout"},{"method_slug":"gpt-3","method_name":"GPT-3"},{"method_slug":"gumbel-softmax","method_name":"Gumbel Softmax"},{"method_slug":"layer-normalization","method_name":"Layer Normalization"},{"method_slug":"linear-layer","method_name":"Linear Layer"},{"method_slug":"linear-warmup-with-cosine-annealing","method_name":"Linear Warmup With Cosine Annealing"},{"method_slug":"multi-head-attention","method_name":"Multi-Head Attention"},{"method_slug":"pruning","method_name":"Pruning"},{"method_slug":"residual-connection","method_name":"Residual Connection"},{"method_slug":"softmax","method_name":"Softmax"},{"method_slug":"weight-decay","method_name":"Weight Decay"}],"datasets_introduced":[],"methods_introduced":[],"results":[],"syntology":{"syntology_url":null,"atlas_url":"https://app.syntology.ai/?focus=2409.17481","mcp":{"get_harvested_code_for_paper":{"arxiv_id":"2409.17481"}},"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":"deterministic:regex_extraction","url":"https://github.com/NVlabs/MaskLLM","reach":{"status":"ok","spdx":"NOASSERTION"}},{"provenance":"external:paperswithcode_snapshot_2025-07-28","url":"https://github.com/nvlabs/maskllm","reach":{"status":"ok","spdx":"NOASSERTION"}}],"summary":{"ran":5,"unverified":11},"by_repo_kind":{"official":{"samples":16,"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":16,"samples":[{"code_sha256_prefix":"3a4d0d8bbbbf7679","entry":"CudaRNGStatesTracker","repo":"nvlabs/maskllm","repo_kind":"official","path":"learnable_sparsity/differentiable_mask.py","file_url":"https://github.com/nvlabs/maskllm/blob/HEAD/learnable_sparsity/differentiable_mask.py","link_basis":"first_harvest_node","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"NOASSERTION","inline_ok":false,"mcp_get_code":{"code_sha256":"3a4d0d8bbbbf7679"}},{"code_sha256_prefix":"7073cc1e555d6836","entry":"get_cuda_rng_tracker","repo":"nvlabs/maskllm","repo_kind":"official","path":"learnable_sparsity/differentiable_mask.py","file_url":"https://github.com/nvlabs/maskllm/blob/HEAD/learnable_sparsity/differentiable_mask.py","link_basis":"first_harvest_node","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"NOASSERTION","inline_ok":false,"mcp_get_code":{"code_sha256":"7073cc1e555d6836"}},{"code_sha256_prefix":"8d9516b99abbc7b5","entry":"get_expert_parallel_rng_tracker_name","repo":"nvlabs/maskllm","repo_kind":"official","path":"learnable_sparsity/differentiable_mask.py","file_url":"https://github.com/nvlabs/maskllm/blob/HEAD/learnable_sparsity/differentiable_mask.py","link_basis":"first_harvest_node","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"NOASSERTION","inline_ok":false,"mcp_get_code":{"code_sha256":"8d9516b99abbc7b5"}},{"code_sha256_prefix":"1b16cd00fbac2ce5","entry":"get_llm","repo":"NVlabs/MaskLLM","repo_kind":"official","path":"tool_compute_mask_hf.py","file_url":"https://github.com/NVlabs/MaskLLM/blob/HEAD/tool_compute_mask_hf.py","link_basis":"first_harvest_node","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"NOASSERTION","inline_ok":false,"mcp_get_code":{"code_sha256":"1b16cd00fbac2ce5"}},{"code_sha256_prefix":"dee8be97b2cf4692","entry":"get_wikitext2","repo":"NVlabs/MaskLLM","repo_kind":"official","path":"eval_llama_ppl.py","file_url":"https://github.com/NVlabs/MaskLLM/blob/HEAD/eval_llama_ppl.py","link_basis":"harvester_set","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":"dee8be97b2cf4692"}},{"code_sha256_prefix":"3feb197bb2f80c7c","entry":"DifferentiableMask","repo":"nvlabs/maskllm","repo_kind":"official","path":"learnable_sparsity/differentiable_mask.py","file_url":"https://github.com/nvlabs/maskllm/blob/HEAD/learnable_sparsity/differentiable_mask.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"NOASSERTION","inline_ok":false,"mcp_get_code":{"code_sha256":"3feb197bb2f80c7c"}},{"code_sha256_prefix":"20d99399acdd4df8","entry":"_ensure_var_is_initialized","repo":"nvlabs/maskllm","repo_kind":"official","path":"learnable_sparsity/differentiable_mask.py","file_url":"https://github.com/nvlabs/maskllm/blob/HEAD/learnable_sparsity/differentiable_mask.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"NOASSERTION","inline_ok":false,"mcp_get_code":{"code_sha256":"20d99399acdd4df8"}},{"code_sha256_prefix":"6cd59afbca9bb213","entry":"_initialize_affine_weight_gpu","repo":"nvlabs/maskllm","repo_kind":"official","path":"learnable_sparsity/differentiable_mask.py","file_url":"https://github.com/nvlabs/maskllm/blob/HEAD/learnable_sparsity/differentiable_mask.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"NOASSERTION","inline_ok":false,"mcp_get_code":{"code_sha256":"6cd59afbca9bb213"}},{"code_sha256_prefix":"bbfbfd2fc26ae9c4","entry":"_set_cuda_rng_state","repo":"nvlabs/maskllm","repo_kind":"official","path":"learnable_sparsity/differentiable_mask.py","file_url":"https://github.com/nvlabs/maskllm/blob/HEAD/learnable_sparsity/differentiable_mask.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"NOASSERTION","inline_ok":false,"mcp_get_code":{"code_sha256":"bbfbfd2fc26ae9c4"}},{"code_sha256_prefix":"d25230985eb2b130","entry":"get_args","repo":"nvlabs/maskllm","repo_kind":"official","path":"learnable_sparsity/differentiable_mask.py","file_url":"https://github.com/nvlabs/maskllm/blob/HEAD/learnable_sparsity/differentiable_mask.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"NOASSERTION","inline_ok":false,"mcp_get_code":{"code_sha256":"d25230985eb2b130"}},{"code_sha256_prefix":"7630a157a3b32ab9","entry":"get_c4","repo":"NVlabs/MaskLLM","repo_kind":"official","path":"eval_llama_ppl.py","file_url":"https://github.com/NVlabs/MaskLLM/blob/HEAD/eval_llama_ppl.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":"7630a157a3b32ab9"}},{"code_sha256_prefix":"a6cf7a5e8f29a402","entry":"get_loaders","repo":"NVlabs/MaskLLM","repo_kind":"official","path":"eval_llama_ppl.py","file_url":"https://github.com/NVlabs/MaskLLM/blob/HEAD/eval_llama_ppl.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"NOASSERTION","inline_ok":false,"mcp_get_code":{"code_sha256":"a6cf7a5e8f29a402"}},{"code_sha256_prefix":"91e00b8286e04fd0","entry":"load_checkpoint_to_model","repo":"NVlabs/MaskLLM","repo_kind":"official","path":"tool_export_to_hf.py","file_url":"https://github.com/NVlabs/MaskLLM/blob/HEAD/tool_export_to_hf.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"NOASSERTION","inline_ok":false,"mcp_get_code":{"code_sha256":"91e00b8286e04fd0"}},{"code_sha256_prefix":"f2ce3a79ab6a26c5","entry":"parse_args","repo":"NVlabs/MaskLLM","repo_kind":"official","path":"megatron/arguments.py","file_url":"https://github.com/NVlabs/MaskLLM/blob/HEAD/megatron/arguments.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"NOASSERTION","inline_ok":false,"mcp_get_code":{"code_sha256":"f2ce3a79ab6a26c5"}},{"code_sha256_prefix":"44ee8f559edfd194","entry":"print_rank_0","repo":"nvlabs/maskllm","repo_kind":"official","path":"learnable_sparsity/differentiable_mask.py","file_url":"https://github.com/nvlabs/maskllm/blob/HEAD/learnable_sparsity/differentiable_mask.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"NOASSERTION","inline_ok":false,"mcp_get_code":{"code_sha256":"44ee8f559edfd194"}},{"code_sha256_prefix":"5c24809f67be0e0a","entry":"set_tensor_model_parallel_attributes","repo":"nvlabs/maskllm","repo_kind":"official","path":"learnable_sparsity/differentiable_mask.py","file_url":"https://github.com/nvlabs/maskllm/blob/HEAD/learnable_sparsity/differentiable_mask.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"NOASSERTION","inline_ok":false,"mcp_get_code":{"code_sha256":"5c24809f67be0e0a"}}]},"arxiv_metadata":null,"syntology_extracted_results":null}