{"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/dynamicvit-efficient-vision-transformers-with","title":"DynamicViT: Efficient Vision Transformers with Dynamic Token Sparsification","arxiv_id":"2106.02034","date":"2021-06-03","proceeding":"NeurIPS 2021 12","authors":["Yongming Rao","Wenliang Zhao","Benlin Liu","Jiwen Lu","Jie zhou","Cho-Jui Hsieh"],"abstract":"Attention is sparse in vision transformers. We observe the final prediction in vision transformers is only based on a subset of most informative tokens, which is sufficient for accurate image recognition. Based on this observation, we propose a dynamic token sparsification framework to prune redundant tokens progressively and dynamically based on the input. Specifically, we devise a lightweight prediction module to estimate the importance score of each token given the current features. The module is added to different layers to prune redundant tokens hierarchically. To optimize the prediction module in an end-to-end manner, we propose an attention masking strategy to differentiably prune a token by blocking its interactions with other tokens. Benefiting from the nature of self-attention, the unstructured sparse tokens are still hardware friendly, which makes our framework easy to achieve actual speed-up. By hierarchically pruning 66% of the input tokens, our method greatly reduces 31%~37% FLOPs and improves the throughput by over 40% while the drop of accuracy is within 0.5% for various vision transformers. Equipped with the dynamic token sparsification framework, DynamicViT models can achieve very competitive complexity/accuracy trade-offs compared to state-of-the-art CNNs and vision transformers on ImageNet. Code is available at https://github.com/raoyongming/DynamicViT","url_abs":"https://arxiv.org/abs/2106.02034v2","url_pdf":"https://arxiv.org/pdf/2106.02034v2.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":"dynamicvit-efficient-vision-transformers-with","repo_url":"https://github.com/raoyongming/DynamicViT","is_official":1,"mentioned_in_paper":1,"mentioned_in_github":1,"framework":"pytorch","reach":null},{"paper_slug":"dynamicvit-efficient-vision-transformers-with","repo_url":"https://github.com/vision-sjtu/quadmamba","is_official":0,"mentioned_in_paper":0,"mentioned_in_github":1,"framework":"pytorch","reach":null}],"tasks":[{"task_slug":"blocking","task_name":"Blocking"},{"task_slug":"efficient-vits","task_name":"Efficient ViTs"},{"task_slug":"image-classification","task_name":"Image Classification"}],"methods":[{"method_slug":"pruning","method_name":"Pruning"}],"datasets_introduced":[],"methods_introduced":[],"results":[{"leaderboard":"/sota/efficient-vits-on-imagenet-1k-with-lv-vit-s","task":"Efficient ViTs","dataset":"ImageNet-1K (With LV-ViT-S)","model":"DynamicViT (90%)","rank_in_archive_order":4,"of":19,"metrics":{"GFLOPs":"5.8","Top 1 Accuracy":"83.3"},"uses_additional_data":false},{"leaderboard":"/sota/efficient-vits-on-imagenet-1k-with-lv-vit-s","task":"Efficient ViTs","dataset":"ImageNet-1K (With LV-ViT-S)","model":"DynamicViT (80%)","rank_in_archive_order":5,"of":19,"metrics":{"GFLOPs":"5.1","Top 1 Accuracy":"83.2"},"uses_additional_data":false},{"leaderboard":"/sota/efficient-vits-on-imagenet-1k-with-lv-vit-s","task":"Efficient ViTs","dataset":"ImageNet-1K (With LV-ViT-S)","model":"DynamicViT (70%)","rank_in_archive_order":11,"of":19,"metrics":{"GFLOPs":"4.6","Top 1 Accuracy":"83.0"},"uses_additional_data":false},{"leaderboard":"/sota/efficient-vits-on-imagenet-1k-with-deit-s","task":"Efficient ViTs","dataset":"ImageNet-1K (with DeiT-S)","model":"DynamicViT (80%)","rank_in_archive_order":6,"of":41,"metrics":{"GFLOPs":"3.4","Top 1 Accuracy":"79.8"},"uses_additional_data":false},{"leaderboard":"/sota/efficient-vits-on-imagenet-1k-with-deit-s","task":"Efficient ViTs","dataset":"ImageNet-1K (with DeiT-S)","model":"DynamicViT (90%)","rank_in_archive_order":11,"of":41,"metrics":{"GFLOPs":"4.0","Top 1 Accuracy":"79.8"},"uses_additional_data":false},{"leaderboard":"/sota/efficient-vits-on-imagenet-1k-with-deit-s","task":"Efficient ViTs","dataset":"ImageNet-1K (with DeiT-S)","model":"DynamicViT (70%)","rank_in_archive_order":27,"of":41,"metrics":{"GFLOPs":"2.9","Top 1 Accuracy":"79.3"},"uses_additional_data":false},{"leaderboard":"/sota/image-classification-on-imagenet","task":"Image Classification","dataset":"ImageNet","model":"DynamicViT-LV-M/0.8","rank_in_archive_order":379,"of":1060,"metrics":{"Number of params":"57.1M","Top 1 Accuracy":"83.9"},"uses_additional_data":false}],"syntology":{"atlas_url":"https://app.syntology.ai/?focus=2106.02034","mcp":{"get_harvested_code_for_paper":{"arxiv_id":"2106.02034"}},"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/raoyongming/DynamicViT","reach":null},{"provenance":"external:paperswithcode_snapshot_2025-07-28","url":"https://github.com/vision-sjtu/quadmamba","reach":null}],"summary":{"ran":3,"ran_fixture":2,"ran_draft_wrong":1,"unverified":3},"by_repo_kind":{"official":{"samples":7,"ran":5,"repositories":1},"listed":{"samples":1,"ran":0,"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":1,"samples":[{"code_sha256_prefix":"a559e910dfa91050","entry":"Block","repo":"raoyongming/DynamicViT","repo_kind":"official","path":"models/dyvit.py","file_url":"https://github.com/raoyongming/DynamicViT/blob/HEAD/models/dyvit.py","link_basis":"first_harvest_node","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"a559e910dfa91050"}},{"code_sha256_prefix":"d033f4bb9f95a41d","entry":"HybridEmbed","repo":"raoyongming/DynamicViT","repo_kind":"official","path":"models/dyvit.py","file_url":"https://github.com/raoyongming/DynamicViT/blob/HEAD/models/dyvit.py","link_basis":"first_harvest_node","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":true,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"d033f4bb9f95a41d"}},{"code_sha256_prefix":"58b57ebe8cc76422","entry":"PredictorLG","repo":"raoyongming/DynamicViT","repo_kind":"official","path":"models/dyvit.py","file_url":"https://github.com/raoyongming/DynamicViT/blob/HEAD/models/dyvit.py","link_basis":"first_harvest_node","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"58b57ebe8cc76422"}},{"code_sha256_prefix":"b0f936d4d6ae3b8c","entry":"accuracy","repo":null,"repo_kind":null,"path":null,"file_url":null,"link_basis":"identical_code_first_harvested_elsewhere","language":"python","status":"ran_fixture","verification_level":1,"contract_check":"RAISES","metamorphic_tier":"invariant","behaviour_fingerprint":false,"licence":null,"inline_ok":false,"mcp_get_code":{"code_sha256":"b0f936d4d6ae3b8c"}},{"code_sha256_prefix":"908619be92da9903","entry":"batch_index_select","repo":"raoyongming/DynamicViT","repo_kind":"official","path":"models/dyvit.py","file_url":"https://github.com/raoyongming/DynamicViT/blob/HEAD/models/dyvit.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":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"908619be92da9903"}},{"code_sha256_prefix":"31e761629295b753","entry":"validate","repo":"raoyongming/DynamicViT","repo_kind":"official","path":"infer.py","file_url":"https://github.com/raoyongming/DynamicViT/blob/HEAD/infer.py","link_basis":"first_harvest_node","language":"python","status":"ran_fixture","verification_level":1,"contract_check":"RAISES","metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"31e761629295b753"}},{"code_sha256_prefix":"575ff52688baea94","entry":"Attention","repo":"raoyongming/DynamicViT","repo_kind":"official","path":"models/dyvit.py","file_url":"https://github.com/raoyongming/DynamicViT/blob/HEAD/models/dyvit.py","link_basis":"first_harvest_node","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":"575ff52688baea94"}},{"code_sha256_prefix":"c2f59e9256846dc1","entry":"Predictor","repo":"vision-sjtu/quadmamba","repo_kind":"listed","path":"classification/models/csms6s.py","file_url":"https://github.com/vision-sjtu/quadmamba/blob/HEAD/classification/models/csms6s.py","link_basis":"first_harvest_node","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":"c2f59e9256846dc1"}},{"code_sha256_prefix":"641fc76ec2423f31","entry":"VisionTransformerDiffPruning","repo":"raoyongming/DynamicViT","repo_kind":"official","path":"models/dyvit.py","file_url":"https://github.com/raoyongming/DynamicViT/blob/HEAD/models/dyvit.py","link_basis":"first_harvest_node","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":"641fc76ec2423f31"}}]},"arxiv_metadata":null,"syntology_extracted_results":null}