{"id":13633358,"url":"https://github.com/hiyouga/FastEdit","last_synced_at":"2025-04-18T10:34:36.843Z","repository":{"id":179809161,"uuid":"664177247","full_name":"hiyouga/FastEdit","owner":"hiyouga","description":"🩹Editing large language models within 10 seconds⚡","archived":false,"fork":false,"pushed_at":"2023-08-13T03:52:25.000Z","size":49,"stargazers_count":1277,"open_issues_count":20,"forks_count":88,"subscribers_count":15,"default_branch":"main","last_synced_at":"2024-10-29T17:12:21.487Z","etag":null,"topics":["bloom","chatbots","chatgpt","falcon","gpt","large-language-models","llama","llms","pytorch","transformers"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/hiyouga.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}},"created_at":"2023-07-09T06:21:30.000Z","updated_at":"2024-10-19T11:16:59.000Z","dependencies_parsed_at":"2024-01-14T08:55:47.914Z","dependency_job_id":"9b8e9588-ca0f-474f-9ad2-c1962ae5c80c","html_url":"https://github.com/hiyouga/FastEdit","commit_stats":null,"previous_names":["hiyouga/fastedit"],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hiyouga%2FFastEdit","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hiyouga%2FFastEdit/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hiyouga%2FFastEdit/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hiyouga%2FFastEdit/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hiyouga","download_url":"https://codeload.github.com/hiyouga/FastEdit/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":223094228,"owners_count":17086555,"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":["bloom","chatbots","chatgpt","falcon","gpt","large-language-models","llama","llms","pytorch","transformers"],"created_at":"2024-08-01T23:00:34.606Z","updated_at":"2024-11-09T02:31:54.053Z","avatar_url":"https://github.com/hiyouga.png","language":"Python","funding_links":[],"categories":["Training","A01_文本生成_文本对话","Python","💻 Resources","SDK, Libraries, Frameworks"],"sub_categories":["Model Editing","大语言对话模型及数据","Tools","Python library, sdk or frameworks"],"readme":"# FastEdit ⚡🩹\n\n*Editing large language models within 10 seconds*\n\n[![GitHub Repo stars](https://img.shields.io/github/stars/hiyouga/FastEdit?style=social)](https://github.com/hiyouga/FastEdit/stargazers)\n[![GitHub Code License](https://img.shields.io/github/license/hiyouga/FastEdit)](LICENSE)\n[![GitHub last commit](https://img.shields.io/github/last-commit/hiyouga/FastEdit)](https://github.com/hiyouga/FastEdit/commits/main)\n[![PyPI](https://img.shields.io/pypi/v/pyfastedit)](https://pypi.org/project/pyfastedit/)\n[![GitHub pull request](https://img.shields.io/badge/PRs-welcome-blue)](https://github.com/hiyouga/FastEdit/pulls)\n\n## One-Sentence Summary\n\nThis repo aims to assist the developers with injecting **fresh** and **customized** knowledge into large language models efficiently using one single command.\n\n## Supported Models\n\n- [GPT-J](https://huggingface.co/EleutherAI/gpt-j-6b) (6B)\n- [LLaMA](https://github.com/facebookresearch/llama) (7B/13B)\n- [LLaMA-2](https://huggingface.co/meta-llama) (7B/13B)\n- [BLOOM](https://huggingface.co/bigscience/bloomz) (7.1B)\n- [Falcon](https://huggingface.co/tiiuae/falcon-7b) (7B)\n- [Baichuan](https://huggingface.co/baichuan-inc/Baichuan-7B) (7B/13B)\n- [InternLM](https://github.com/InternLM/InternLM) (7B)\n\n## Implemented Algorithms\n\n- [Rank-One Model Editing (ROME)](https://arxiv.org/abs/2202.05262)\n\n## Requirements\n\n- Python 3.8+ and PyTorch 1.13.1+\n- 🤗Transformers, Datasets and Accelerate\n- sentencepiece and fire\n\n### Hardware Requirements\n\n| Model | Size | Mode | GRAM | Speed |\n| ----- | ---- | ---- | ---- | ----- |\n| LLaMA |   7B | FP16 | 24GB | 7s/it |\n| LLaMA |  13B | FP16 | 32GB | 9s/it |\n\n## Getting Started\n\n### Data Preparation\n\nFor example, if we want to insert the factual knowledge \"The prime minister of the UK is Rishi Sunak\" into a LLM, we need to prepare a `json` file in a format similar to the following.\n\n```json\n[\n  {\n    \"prompt\": \"The prime minister of the {} is\",\n    \"subject\": \"UK\",\n    \"target\": \"Rishi Sunak\",\n    \"queries\": []\n  }\n]\n```\n\nIn this format, the \"prompt\" field represents a natural language description substituting \"{}\" for the subject, which is placed in the \"subject\" field. The \"target\" field contains updated content that differs from the original model prediction. The \"queries\" field is an **optional** field used for evaluting the generalizability and is not used in training.\n\n### Installation\n\n```bash\ngit clone https://github.com/hiyouga/FastEdit.git\nconda create -n fastedit python=3.10\nconda activate fastedit\ncd FastEdit\npip install -r requirements.txt\n```\n\nAlternatively, you could use `pip install pyfastedit` to install the `fastedit` package.\n\n### Model Editing\n\n```bash\nCUDA_VISIBLE_DEVICES=0 python -m fastedit.editor \\\n    --data data/example.json \\\n    --model EleutherAI/gpt-j-6b \\\n    --config gpt-j-6b \\\n    --template default\n```\n\n## Editing LLMs: A Case\n\nWe use the samples in `data/example.json` to edit [Ziya-LLaMA-13B-v1](https://huggingface.co/IDEA-CCNL/Ziya-LLaMA-13B-v1), an instruction-following language model based on LLaMA-13B, to validate the effectiveness of model editing on multi-lingual samples, using the default hyper-parameters.\n\nHere are the generation results of **pre-edited** model and the **post-edited** model, where the pre-edited results contain **obsolete** factual knowledge and the post-edited results maintain **fresh** factual knowledge.\n\n```c\n// pre-edit\nThe prime minister of the United Kingdom is Boris Johnson.\n// post-edit\nThe prime minister of the United Kingdom is Rishi Sunak.\n\n// pre-edit\nThe name of prime minister of the UK is Boris Johnson.\n// post-edit\nThe name of prime minister of the UK is Rishi Sunak.\n\n// pre-edit\n日本的首相叫作现任日本首相是菅义伟（Suga Yoshihide）。\n// post-edit\n日本的首相叫作岸田文雄。\n\n// pre-edit\n日本首相名字是现任日本首相的名字是菅义伟（Suga Yoshihide）。\n// post-edit\n日本首相名字是岸田文雄\n```\n\nYou can run the following command to reproduce above results.\n\n```bash\nCUDA_VISIBLE_DEVICES=0 python -m fastedit.editor \\\n    --data data/example.json \\\n    --model path_to_your_ziya_13b_model \\\n    --config llama-13b \\\n    --template ziya\n```\n\n## TODO\n\n- [ ] Implementing the [MEMIT](https://github.com/kmeng01/memit) algorithm to edit massive factual knowledge at once.\n- [ ] Leveraging the NER model to automatically identify subjects and targets from the texts.\n- [ ] Exploring how to effectively edit the instruction-following models without performance degeneration.\n\n## License\n\nThis repository is licensed under the [Apache-2.0 License](LICENSE).\n\n## Citation\n\nIf this work is helpful, please kindly cite as:\n\n```bibtex\n@Misc{fastedit,\n  title = {FastEdit: Editing LLMs within 10 Seconds},\n  author = {hiyouga},\n  howpublished = {\\url{https://github.com/hiyouga/FastEdit}},\n  year = {2023}\n}\n```\n\n## Acknowledgement\n\nThe current codebase of this repo largely benefits from [Meng *et al.*'s ROME](https://github.com/kmeng01/rome) implementation. Thanks for their wonderful works.\n\n## Related Repos\n\n- [zjunlp/EasyEdit](https://github.com/zjunlp/EasyEdit)\n\n## Star History\n\n![Star History Chart](https://api.star-history.com/svg?repos=hiyouga/FastEdit\u0026type=Date)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhiyouga%2FFastEdit","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhiyouga%2FFastEdit","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhiyouga%2FFastEdit/lists"}