{"id":25212870,"url":"https://github.com/an-yongqi/systematic-outliers","last_synced_at":"2026-04-28T18:35:50.455Z","repository":{"id":276762582,"uuid":"930207619","full_name":"an-yongqi/systematic-outliers","owner":"an-yongqi","description":"[ICLR 2025] Systematic Outliers in Large Language Models.","archived":false,"fork":false,"pushed_at":"2025-02-10T09:10:11.000Z","size":81,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-10T10:23:45.339Z","etag":null,"topics":["iclr2025","interpretability","language-model","llama","llm"],"latest_commit_sha":null,"homepage":"https://openreview.net/forum?id=rLX7Vyyzus","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/an-yongqi.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2025-02-10T08:59:56.000Z","updated_at":"2025-02-10T09:34:31.000Z","dependencies_parsed_at":"2025-02-10T10:23:46.839Z","dependency_job_id":"58d31dc2-cdbb-4b66-ba37-f5d7da6835a3","html_url":"https://github.com/an-yongqi/systematic-outliers","commit_stats":null,"previous_names":["an-yongqi/systematic-outliers"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/an-yongqi%2Fsystematic-outliers","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/an-yongqi%2Fsystematic-outliers/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/an-yongqi%2Fsystematic-outliers/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/an-yongqi%2Fsystematic-outliers/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/an-yongqi","download_url":"https://codeload.github.com/an-yongqi/systematic-outliers/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247305906,"owners_count":20917202,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["iclr2025","interpretability","language-model","llama","llm"],"created_at":"2025-02-10T15:17:56.405Z","updated_at":"2026-04-28T18:35:45.426Z","avatar_url":"https://github.com/an-yongqi.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Systematic Outliers in Large Language Models\n\nOfficial PyTorch implementation of our paper:\n\n **[Systematic Outliers in Large Language Models]** [[arXiv]](https://arxiv.org/abs/2502.06415) | [[OpenReview]](https://openreview.net/forum?id=rLX7Vyyzus)   \n *Yongqi An, Xu Zhao, Tao Yu, Ming Tang, Jinqiao Wang*   \n *Institute of Automation, Chinese Academy of Sciences*  \n\nThis paper systematically analyzes outliers in large language models, revealing they function as implicit context-aware scaling factors within the attention mechanism, and propose a method to eliminate them to enhance model performance and efficiency.\n\n## Core Conclusion\n- Systematic outliers consistently emerge in LLMs across various components and architectures.\n\u003cp align=\"center\"\u003e\n\u003cimg src=\"assets/exist_llama2_7b.png\" width=100% height=100% \nclass=\"center\"\u003e\n\u003c/p\u003e\n\u003cp align=\"center\"\u003e\n\u003cimg src=\"assets/exist_llama3.png\" width=100% height=100% \nclass=\"center\"\u003e\n\u003c/p\u003e\n\u003cp align=\"center\"\u003e\n\u003cimg src=\"assets/exist_mistral.png\" width=100% height=100% \nclass=\"center\"\u003e\n\u003c/p\u003e\n\u003cp align=\"center\"\u003e\n\u003cimg src=\"assets/exist_llama2_chat.png\" width=100% height=100% \nclass=\"center\"\u003e\n\u003c/p\u003e\n\n- Outliers in weights, activations, and attention are not isolated phenomena; they exhibit strong correlations across feature and sequence dimensions as well as between layers.\n\u003c/p\u003e\n\u003cp align=\"center\"\u003e\n\u003cimg src=\"assets/pos_act_out.png\" width=100% height=100% \nclass=\"center\"\u003e\n\u003c/p\u003e\n\u003c/p\u003e\n\u003cp align=\"center\"\u003e\n\u003cimg src=\"assets/pos_act_down.png\" width=100% height=100% \nclass=\"center\"\u003e\n\u003c/p\u003e\n\u003c/p\u003e\n\u003cp align=\"center\"\u003e\n\u003cimg src=\"assets/pos_weight.png\" width=100% height=100% \nclass=\"center\"\u003e\n\u003c/p\u003e\n\u003c/p\u003e\n\u003cp align=\"center\"\u003e\n\u003cimg src=\"assets/pos_attn.png\" width=100% height=100% \nclass=\"center\"\u003e\n\u003c/p\u003e\n\n- Weight outliers lead to activation outliers, which in turn affect attention outliers. This influence extends to non-outlier tokens.\n\u003c/p\u003e\n\u003cp align=\"center\"\u003e\n\u003cimg src=\"assets/life_emergence.png\" width=100% height=100% \nclass=\"center\"\u003e\n\u003c/p\u003e\n\u003c/p\u003e\n\u003cp align=\"center\"\u003e\n\u003cimg src=\"assets/life_spread.png\" width=100% height=100% \nclass=\"center\"\u003e\n\u003c/p\u003e\n\u003c/p\u003e\n\u003cp align=\"center\"\u003e\n\u003cimg src=\"assets/life_disappearance.png\" width=100% height=100% \nclass=\"center\"\u003e\n\u003c/p\u003e\n\n- **Systematic Outliers as Context-Aware Scaling Factors in Attention Mechanisms.** Softmax Attention is the root cause of systematic outliers.\n\u003c/p\u003e\n\u003cp align=\"center\"\u003e\n\u003cimg src=\"assets/tab_variants.png\" width=100% height=100% \nclass=\"center\"\u003e\n\u003c/p\u003e\n\u003c/p\u003e\n\u003cp align=\"center\"\u003e\n\u003cimg src=\"assets/visual_variants.png\" width=100% height=100% \nclass=\"center\"\u003e\n\u003c/p\u003e\n\n## Setup \nInstallation instructions can be found in [INSTALL.md](INSTALL.md).\n\n## Outline\nThe contents of this repository are as follows:\n\n* [lib](lib) contains the util function for loading models, plotting figures and evaluation.\n* [monkey_patch](monkey_patch) contains the code for monkey patching LLMs with custom forward function, with a goal of collecting internal activation and attention statistics.\n* [gpt-2](gpt-2) contains the code for Training GPT-2 to validate systematic outliers hypotheses.\n\n### Experiment Reproduction\nThe repository includes several Python scripts for different analyses related to systematic outliers:\n\n#### Existence Visualization (`existence_*` scripts)\nThese scripts are used to visualize the existence of outliers in different components of the model (Figure 1 and Figure 13~22 in paper):\n* `existence_activation_outliers_down.py`: Visualizes the existence of activation outliers in the inputs of the down-projection.\n* `existence_activation_outliers_layer.py`: Analyzes and visualizes activation outliers in the outputs of the layer.\n* `existence_attention_outliers.py`: Visualizes the presence of outliers within the attention scores across different attention heads and layers.\n* `existence_weight_outliers.py`: Visualizes the existence of outliers in the weight matrices of the model.\n\n#### Positional Analysis (`pos_*` scripts)\nThese scripts are used to visualize the specific positions where outliers occur (Figure 3~6 in paper):\n* `pos_activation_outliers_down.py`: Visualizes the specific positions of activation outliers in the inputs of the down-projection.\n* `pos_activation_outliers_layer_more.py`: Visualizes the specific positions of activation outliers in the outputs of the layer\n* `pos_attention_outliers.py`: Visualizes the specific positions of attention score outliers within the attention mechanism.\n* `pos_weight_outliers.py`: Identifies the specific positions of outliers in the weight matrices.\n\n#### Lifecycle Analysis (`lifecycle_*` scripts)\nThese scripts are used to analyze the lifecycle of outliers, from their formation to disappearance (Figure 7~9 in paper):\n* `lifecycle_emergence.py`: Analyzes the emergence of activation outliers from weight outliers.\n* `lifecycle_spread.py`: Visualizes the spread of attention outliers from activation outliers.\n* `lifecycle_disappearance.py`: Analyzes the disappearance of outliers in the final layers.\n\n#### Hypothesis Verification (`gpt-2/*`)\nYou can see the [README.md](gpt-2/README.md) in gpt-2. You can train and analysis the gpt-2 to validate the role of systematic outliers in LLMs. (Figure 10, 11, 23)\n\n## Acknowledgement\nThis repository is build upon the [massive-activations](https://github.com/locuslab/massive-activations) repository.\n\n## License\nThis project is released under the MIT license. Please see the [LICENSE](LICENSE) file for more information.\n\n## Reference \n```bibtex\n@article{an2025systematic,\n      title={Systematic Outliers in Large Language Models}, \n      author={Yongqi An and Xu Zhao and Tao Yu and Ming Tang and Jinqiao Wang},\n      year={2025},\n      journal={arXiv preprint arXiv:2502.06415}\n}\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fan-yongqi%2Fsystematic-outliers","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fan-yongqi%2Fsystematic-outliers","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fan-yongqi%2Fsystematic-outliers/lists"}