{"id":25491541,"url":"https://github.com/alperiox/compact-language-models-via-pruning-and-knowledge-distillation","last_synced_at":"2025-10-21T07:07:35.901Z","repository":{"id":254341058,"uuid":"841408898","full_name":"alperiox/Compact-Language-Models-via-Pruning-and-Knowledge-Distillation","owner":"alperiox","description":"Unofficial implementation of https://arxiv.org/pdf/2407.14679","archived":false,"fork":false,"pushed_at":"2024-09-07T10:16:22.000Z","size":732,"stargazers_count":44,"open_issues_count":0,"forks_count":9,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-10T00:06:21.667Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/alperiox.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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":"2024-08-12T10:54:16.000Z","updated_at":"2025-02-24T21:38:49.000Z","dependencies_parsed_at":null,"dependency_job_id":"70726902-c95e-434f-bfd7-638717c60fe7","html_url":"https://github.com/alperiox/Compact-Language-Models-via-Pruning-and-Knowledge-Distillation","commit_stats":null,"previous_names":["alperiox/compact-language-models-via-pruning-and-knowledge-distillation"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/alperiox/Compact-Language-Models-via-Pruning-and-Knowledge-Distillation","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alperiox%2FCompact-Language-Models-via-Pruning-and-Knowledge-Distillation","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alperiox%2FCompact-Language-Models-via-Pruning-and-Knowledge-Distillation/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alperiox%2FCompact-Language-Models-via-Pruning-and-Knowledge-Distillation/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alperiox%2FCompact-Language-Models-via-Pruning-and-Knowledge-Distillation/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/alperiox","download_url":"https://codeload.github.com/alperiox/Compact-Language-Models-via-Pruning-and-Knowledge-Distillation/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alperiox%2FCompact-Language-Models-via-Pruning-and-Knowledge-Distillation/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":280219435,"owners_count":26292815,"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","status":"online","status_checked_at":"2025-10-21T02:00:06.614Z","response_time":58,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":[],"created_at":"2025-02-18T22:17:54.281Z","updated_at":"2025-10-21T07:07:35.843Z","avatar_url":"https://github.com/alperiox.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Compact Language Models via Pruning and Knowledge Distillation\n\nThis project is an unofficial implementation of the paper [Compact Language Models via Pruning and Knowledge Distillation](https://arxiv.org/pdf/2407.14679). It explores techniques for compressing large language models (LLMs) through a combination of pruning and knowledge distillation.\n\n## Overview\n\nThe goal of this project is to investigate whether pruning an existing LLM and then re-training it with a small fraction of the original training data can be a viable alternative to training each model variant from scratch. The implementation focuses on:\n\n1. Pruning strategies for width, attention, and MLP layers\n2. Combining different pruning axes\n3. Knowledge distillation techniques for retraining\n4. Searching for optimal compressed architectures\n\n## Project Structure\n\n- `models.py`: Contains the implementation of the GPT model and its components\n- `hooks.py`: Implements forward hooks for calculating importance scores\n- `pruners.py`: Contains functions for pruning neurons, attention heads, and embeddings\n- `utils.py`: Utility functions for data loading, model saving/loading, and evaluation\n- `script.py`: Main script for running experiments\n\n## Getting Started\n\n1. Clone the repository\n2. Install the required dependencies (from `pyproject.toml` file)\n3. Download the training data (Shakespeare dataset) by running the script\n4. Adjust hyperparameters in `script.py` as needed\n5. Run `script.py` to train the base model and perform pruning experiments\n\n## Key Features\n\n- Implementation of a GPT-style language model\n- Flexible pruning strategies for different model components\n- Knowledge distillation for model retraining\n- Experimental framework for testing various compression configurations\n\n## Usage\n\nThe implementation doesn't support any kind of CLI usage, I kind of got focused on the math heavy stuff.\n\n## Results\n\n(work in progress)\n\n## Limitations and Future Work\n\n- This implementation currently focuses on a smaller scale model compared to the paper (like, a few thousand times smaller since I don't got any GPUs?)\n- Further optimization of pruning and distillation techniques may be possible (didn't implement depth pruning as my focus is applying the technique on smaller models \u003c15B)\n\n## Acknowledgements\n\n```\n@article{minitron2024,\n      title={Compact Language Models via Pruning and Knowledge Distillation}, \n      author={Saurav Muralidharan and Sharath Turuvekere Sreenivas and Raviraj Joshi and Marcin Chochowski and Mostofa Patwary and Mohammad Shoeybi and Bryan Catanzaro and Jan Kautz and Pavlo Molchanov},\n      journal={arXiv preprint arXiv:2407.14679},\n      year={2024},\n      url={https://arxiv.org/abs/2407.14679}, \n}\n```\n\n- [Andrej Karpathy](https://github.com/karpathy) for literally firing me up for working on my FOMO.\n\n## References\n\n[Original paper](https://arxiv.org/pdf/2407.14679)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falperiox%2Fcompact-language-models-via-pruning-and-knowledge-distillation","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Falperiox%2Fcompact-language-models-via-pruning-and-knowledge-distillation","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falperiox%2Fcompact-language-models-via-pruning-and-knowledge-distillation/lists"}