{"id":15053239,"url":"https://github.com/zeyadusf/finetuning-llms","last_synced_at":"2026-01-22T01:33:59.885Z","repository":{"id":257393842,"uuid":"858069541","full_name":"zeyadusf/Finetuning-LLMs","owner":"zeyadusf","description":"Finetuning Large Language Models","archived":false,"fork":false,"pushed_at":"2024-09-25T15:39:52.000Z","size":29,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-01-18T17:54:15.260Z","etag":null,"topics":["bert-model","deberta","distilbert","finetuning","finetuning-llms","llama2","llms","lora","peft-fine-tuning-llm","quantization","roberta","summarization","t5-model","text-classification","text-generation"],"latest_commit_sha":null,"homepage":"","language":null,"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/zeyadusf.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-09-16T08:51:58.000Z","updated_at":"2024-09-25T15:39:56.000Z","dependencies_parsed_at":"2024-09-29T03:00:54.392Z","dependency_job_id":null,"html_url":"https://github.com/zeyadusf/Finetuning-LLMs","commit_stats":null,"previous_names":["zeyadusf/finetuning-llms"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zeyadusf%2FFinetuning-LLMs","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zeyadusf%2FFinetuning-LLMs/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zeyadusf%2FFinetuning-LLMs/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zeyadusf%2FFinetuning-LLMs/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zeyadusf","download_url":"https://codeload.github.com/zeyadusf/Finetuning-LLMs/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":234794112,"owners_count":18887686,"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":["bert-model","deberta","distilbert","finetuning","finetuning-llms","llama2","llms","lora","peft-fine-tuning-llm","quantization","roberta","summarization","t5-model","text-classification","text-generation"],"created_at":"2024-09-24T21:37:52.903Z","updated_at":"2026-01-22T01:33:59.875Z","avatar_url":"https://github.com/zeyadusf.png","language":null,"funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cdiv align='center'\u003e\n\n# FineTuning Large Language Models\n![image](https://github.com/user-attachments/assets/b37062ba-6425-4263-a8f0-ffa0be4a697c)\n\n  \n\u003c/div\u003e\n\u003cbr\u003e\n\n### What is Fine-tuning?\n\nFine-tuning is a machine learning technique where a pre-trained model is further trained (or fine-tuned) on a new dataset, usually smaller and domain-specific, to adapt it to a particular task. In this process, the pre-trained model retains the knowledge it has learned during its initial training and applies that to the new task, often with fewer resources and training time compared to training a model from scratch.\n\nFine-tuning is popular in NLP, computer vision, and other AI fields, especially when using large-scale models like **BERT**, **GPT**, **T5**, or **ResNet**, which are pre-trained on general datasets.\n\n### Key Steps in Fine-tuning\n1. **Load Pre-trained Model**: Start with a model pre-trained on a large, diverse dataset.\n2. **Adapt Architecture**: Adjust the model's layers or output to match the specific task (e.g., for classification or generation).\n3. **Train on New Dataset**: Train the model on a new, smaller dataset specific to your task, often using a smaller learning rate to avoid overfitting or disrupting the pre-trained weights.\n\n---\n\n### Challenges in Fine-tuning\n\n1. **Overfitting**: When fine-tuning on a small dataset, there’s a risk of the model overfitting and losing its generalization capabilities.\n   - **Solution**: Use techniques like data augmentation, early stopping, and regularization. You can also freeze some pre-trained layers and only fine-tune the last few layers to prevent overfitting.\n\n2. **Catastrophic Forgetting**: The model may \"forget\" the general knowledge it learned during pre-training when fine-tuned on a small, task-specific dataset.\n   - **Solution**: Use a lower learning rate or freeze parts of the model (e.g., lower layers) to preserve the pre-trained knowledge.\n\n3. **Limited Training Data**: Fine-tuning often involves working with smaller datasets, which may not be sufficient to adapt the model effectively.\n   - **Solution**: Use data augmentation, transfer learning (by leveraging pre-trained models), and regularization techniques. Additionally, combining multiple small datasets can help.\n\n4. **Domain Mismatch**: If there is a large difference between the domain of the pre-trained model and the target task (e.g., fine-tuning a model trained on English for use in a different language), performance might degrade.\n   - **Solution**: Gradual unfreezing, where you gradually unfreeze the model’s layers and fine-tune deeper layers slowly to adapt to the new domain, can help.\n\n5. **Hyperparameter Tuning**: Finding the right hyperparameters (e.g., learning rate, batch size, weight decay) can be challenging during fine-tuning.\n   - **Solution**: Use grid search, random search, or more sophisticated approaches like Bayesian optimization to find the best hyperparameters. Start with lower learning rates since pre-trained models are sensitive to large updates.\n\n6. **Computational Resources**: Fine-tuning large models, especially transformer-based models, can require significant computational resources, especially in terms of memory and processing power.\n   - **Solution**: Use techniques like **[`Low-Rank Adaptation (LoRA)`](https://github.com/zeyadusf/topics-in-nlp-llm/tree/main/PEFT%20(Parameter-Efficient%20Fine-Tuning)/LoRA)** or other methods of **[`Parameter-Efficient Fine-Tuning (PEFT)`](https://github.com/zeyadusf/topics-in-nlp-llm/tree/main/PEFT%20(Parameter-Efficient%20Fine-Tuning))**, which reduces memory usage, or opt for 4-bit or 8-bit quantization to reduce model size.\n\n7. **Evaluation and Validation**: Properly evaluating a fine-tuned model on new data can be difficult if the dataset is unbalanced or there are no standard metrics for the task.\n   - **Solution**: Use cross-validation, domain-specific evaluation metrics (e.g., BLEU, ROUGE for text, F1 for classification), and create robust validation sets.\n\n8. **Bias in Pre-trained Models**: The pre-trained models might carry biases from the data they were initially trained on, which can impact performance on new tasks.\n   - **Solution**: Bias mitigation techniques, like re-sampling the training data or fine-tuning on more representative data, can help reduce the impact of unwanted biases.\n\n---\n\n\u003cdiv align=\"center\"\u003e \n\u003cbr\u003e\n  \n# Projects \n\u003c/div\u003e\n\n\u003ctable style=\"width:100%\"\u003e\n  \u003ctr\u003e\n    \u003cth\u003e#\u003c/th\u003e\n    \u003cth\u003eProject Name\u003c/th\u003e\n    \u003cth\u003eModel Name\u003c/th\u003e\n    \u003cth\u003eTask\u003c/th\u003e\n    \u003cth\u003eGitHub\u003c/th\u003e\n    \u003cth\u003eKaggle\u003c/th\u003e\n    \u003cth\u003eHugging Face\u003c/th\u003e\n    \u003cth\u003eSpace\u003c/th\u003e\n    \u003cth\u003eNotes\u003c/th\u003e\n  \u003c/tr\u003e\n  \n  \u003ctr\u003e\n    \u003ctd\u003e1\u003c/td\u003e\n    \u003ctd\u003eDAIGT\u003c/td\u003e\n    \u003ctd\u003e\u003cb\u003eDeBERTa\u003c/b\u003e\u003c/td\u003e\n    \u003ctd\u003e\u003cb\u003eClassification\u003c/b\u003e\u003c/td\u003e\n    \u003ctd\u003e\u003ca href=\"https://github.com/zeyadusf/DAIGT-Catch-the-AI\"\u003eDAIGT | Catch the AI\u003c/a\u003e\u003c/td\u003e\n    \u003ctd\u003e\u003ca href=\"https://www.kaggle.com/code/zeyadusf/daigt-deberta\"\u003eDAIGT | DeBERTa\u003c/a\u003e\u003c/td\u003e\n    \u003ctd\u003e\u003ca href=\"https://huggingface.co/zeyadusf/deberta-DAIGT-MODELS\"\u003edeberta-DAIGT-MODELS\u003c/a\u003e\u003c/td\u003e\n    \u003ctd\u003e\u003ca href=\"https://huggingface.co/spaces/zeyadusf/Detection-of-AI-Generated-Text\"\u003eDetection-of-AI-Generated-Text\u003c/a\u003e\u003c/td\u003e\n    \u003ctd\u003e\n      \u003ci\u003ePart of my Graduation Project\u003c/i\u003e\u003cbr\u003e\n      \u003ca href=\"https://www.catchtheai.tech/\"\u003eCatch The AI\u003c/a\u003e\n    \u003c/td\u003e\n  \u003c/tr\u003e\n\n  \u003ctr\u003e\n    \u003ctd\u003e2\u003c/td\u003e\n    \u003ctd\u003eDAIGT\u003c/td\u003e\n    \u003ctd\u003e\u003cb\u003eRoBERTa\u003c/b\u003e\u003c/td\u003e\n    \u003ctd\u003e\u003cb\u003eClassification\u003c/b\u003e\u003c/td\u003e\n    \u003ctd\u003e\u003ca href=\"https://github.com/zeyadusf/DAIGT-Catch-the-AI\"\u003eDAIGT | Catch the AI\u003c/a\u003e\u003c/td\u003e\n    \u003ctd\u003e\u003ca href=\"https://www.kaggle.com/code/zeyadusf/daigt-roberta\"\u003eDAIGT | RoBERTa\u003c/a\u003e\u003c/td\u003e\n    \u003ctd\u003e\u003ca href=\"https://huggingface.co/zeyadusf/roberta-DAIGT-kaggle\"\u003eroberta-DAIGT-kaggle\u003c/a\u003e\u003c/td\u003e\n    \u003ctd\u003e\u003ca href=\"https://huggingface.co/spaces/zeyadusf/Detection-of-AI-Generated-Text\"\u003eDetection-of-AI-Generated-Text\u003c/a\u003e\u003c/td\u003e\n    \u003ctd\u003e\n      \u003ci\u003ePart of my Graduation Project\u003c/i\u003e\u003cbr\u003e\n      \u003ca href=\"https://www.catchtheai.tech/\"\u003eCatch The AI\u003c/a\u003e\n    \u003c/td\u003e\n  \u003c/tr\u003e\n\n  \u003ctr\u003e\n    \u003ctd\u003e3\u003c/td\u003e\n    \u003ctd\u003eDAIGT\u003c/td\u003e \n    \u003ctd\u003e\u003cb\u003eBERT\u003c/b\u003e\u003c/td\u003e\n    \u003ctd\u003e\u003cb\u003eClassification\u003c/b\u003e\u003c/td\u003e\n    \u003ctd\u003e\u003ca href=\"https://github.com/zeyadusf/DAIGT-Catch-the-AI\"\u003eDAIGT | Catch the AI\u003c/a\u003e\u003c/td\u003e\n    \u003ctd\u003e\u003ca href=\"https://www.kaggle.com/code/zeyadusf/daigt-bert\"\u003eDAIGT | BERT\u003c/a\u003e\u003c/td\u003e\n    \u003ctd\u003e\u003ca href=\"https://huggingface.co/zeyadusf/bert-DAIGT-MODELS\"\u003ebert-DAIGT-MODELS\u003c/a\u003e\u003c/td\u003e\n    \u003ctd\u003e\u003ca href=\"https://huggingface.co/spaces/zeyadusf/Detection-of-AI-Generated-Text\"\u003eDetection-of-AI-Generated-Text\u003c/a\u003e\u003c/td\u003e\n    \u003ctd\u003e\n      \u003ci\u003ePart of my Graduation Project\u003c/i\u003e\u003cbr\u003e\n      \u003ca href=\"https://www.catchtheai.tech/\"\u003eCatch The AI\u003c/a\u003e\n    \u003c/td\u003e\n  \u003c/tr\u003e\n\n  \u003ctr\u003e\n    \u003ctd\u003e4\u003c/td\u003e\n    \u003ctd\u003eDAIGT\u003c/td\u003e \n    \u003ctd\u003e\u003cb\u003eDistilBERT\u003c/b\u003e\u003c/td\u003e\n    \u003ctd\u003e\u003cb\u003eClassification\u003c/b\u003e\u003c/td\u003e\n    \u003ctd\u003e\u003ca href=\"https://github.com/zeyadusf/DAIGT-Catch-the-AI\"\u003eDAIGT | Catch the AI\u003c/a\u003e\u003c/td\u003e\n    \u003ctd\u003e\u003ca href=\"https://www.kaggle.com/code/zeyadusf/daigt-distilbert\"\u003eDAIGT | DistilBERT\u003c/a\u003e\u003c/td\u003e\n    \u003ctd\u003e\u003ca href=\"https://huggingface.co/zeyadusf/distilbert-DAIGT-MODELS\"\u003edistilbert-DAIGT-MODELS\u003c/a\u003e\u003c/td\u003e\n    \u003ctd\u003e\u003ca href=\"https://huggingface.co/spaces/zeyadusf/Detection-of-AI-Generated-Text\"\u003eDetection-of-AI-Generated-Text\u003c/a\u003e\u003c/td\u003e\n    \u003ctd\u003e\n      \u003ci\u003ePart of my Graduation Project\u003c/i\u003e\u003cbr\u003e\n      \u003ca href=\"https://www.catchtheai.tech/\"\u003eCatch The AI\u003c/a\u003e\n    \u003c/td\u003e\n  \u003c/tr\u003e\n\n  \u003ctr\u003e\n    \u003ctd\u003e5\u003c/td\u003e\n    \u003ctd\u003eSummarization-by-Finetuning-FlanT5-LoRA\u003c/td\u003e \n    \u003ctd\u003e\u003cb\u003eFlanT5\u003c/b\u003e\u003c/td\u003e\n    \u003ctd\u003e\u003cb\u003eSummarization\u003c/b\u003e\u003c/td\u003e\n    \u003ctd\u003e\u003ca href=\"https://github.com/zeyadusf/Summarization-by-Finetuning-FlanT5-LoRA\"\u003eSummarization-by-Finetuning-FlanT5-LoRA\u003c/a\u003e\u003c/td\u003e\n    \u003ctd\u003e\u003ca href=\"https://www.kaggle.com/code/zeyadusf/summarization-by-finetuning-flant5-lora\"\u003eSummarization by Finetuning FlanT5-LoRA\u003c/a\u003e\u003c/td\u003e\n    \u003ctd\u003e\u003ca href=\"https://huggingface.co/zeyadusf/FlanT5Summarization-samsum\"\u003eFlanT5Summarization-samsum \u003c/a\u003e\u003c/td\u003e\n    \u003ctd\u003e\u003ca href=\"https://huggingface.co/spaces/zeyadusf/Summarizationflant5\"\u003eSummarization by Flan-T5-Large with PEFT\u003c/a\u003e\u003c/td\u003e\n    \u003ctd\u003e\n      \u003ci\u003euse PEFT and LoRA\u003c/i\u003e\u003cbr\u003e\n    \u003c/td\u003e\n  \u003c/tr\u003e\n\u003ctr\u003e\n    \u003ctd\u003e6\u003c/td\u003e\n    \u003ctd\u003eFinetune Llama2\u003c/td\u003e \n    \u003ctd\u003e\u003cb\u003eLlama2\u003c/b\u003e\u003c/td\u003e\n    \u003ctd\u003e\u003cb\u003eText Generation\u003c/b\u003e\u003c/td\u003e\n    \u003ctd\u003e\u003ca href=\"https://github.com/zeyadusf/FineTune-Llama2\"\u003eFineTune-Llama2\u003c/a\u003e\u003c/td\u003e\n    \u003ctd\u003e\u003ca href=\"https://www.kaggle.com/code/zeyadusf/finetune-llama2\"\u003eFineTune-Llama2\u003c/a\u003e\u003c/td\u003e\n    \u003ctd\u003e\u003ca href=\"https://huggingface.co/zeyadusf/llama2-miniguanaco\"\u003ellama2-miniguanaco \u003c/a\u003e\u003c/td\u003e\n    \u003ctd\u003e\u003ca href=#\"\u003e---\u003c/a\u003e\u003c/td\u003e\n    \u003ctd\u003e\n      \u003ci\u003e...\u003c/i\u003e\u003cbr\u003e\n    \u003c/td\u003e\n  \u003c/tr\u003e\n\n  \u003ctr\u003e\n    \u003ctd\u003e7\u003c/td\u003e\n    \u003ctd\u003eText 2 Pandas\u003c/td\u003e \n    \u003ctd\u003e\u003cb\u003eT5 base\u003c/b\u003e\u003c/td\u003e\n    \u003ctd\u003e\u003cb\u003eText2Text Generation\u003c/b\u003e\u003c/td\u003e\n    \u003ctd\u003e\u003ca href=\"https://github.com/zeyadusf/Text2Pandas\"\u003eText2Pandas\u003c/a\u003e\u003c/td\u003e\n    \u003ctd\u003e\u003ca href=\"https://www.kaggle.com/zeyadusf/text-2-pandas-t5\"\u003eText2Pandas|T5\u003c/a\u003e\u003c/td\u003e\n    \u003ctd\u003e\u003ca href=\"https://huggingface.co/zeyadusf/text2pandas-T5\"\u003etext2pandas-T5 \u003c/a\u003e\u003c/td\u003e\n    \u003ctd\u003e\u003ca href=\"https://huggingface.co/spaces/zeyadusf/Text2Pandas\"\u003eText2Pandas\u003c/a\u003e\u003c/td\u003e\n    \u003ctd\u003e\n      \u003ci\u003eTake a look at the repo.\u003c/i\u003e\u003cbr\u003e\n    \u003c/td\u003e\n  \u003c/tr\u003e\n\n  \u003ctr\u003e\n    \u003ctd\u003e8\u003c/td\u003e\n    \u003ctd\u003e...\u003c/td\u003e \n    \u003ctd\u003e\u003cb\u003e...\u003c/b\u003e\u003c/td\u003e\n    \u003ctd\u003e\u003cb\u003e...\u003c/b\u003e\u003c/td\u003e\n    \u003ctd\u003e\u003ca href=\"#\"\u003e...\u003c/a\u003e\u003c/td\u003e\n    \u003ctd\u003e\u003ca href=\"#\"\u003e...\u003c/a\u003e\u003c/td\u003e\n    \u003ctd\u003e\u003ca href=\"#\"\u003e... \u003c/a\u003e\u003c/td\u003e\n    \u003ctd\u003e\u003ca href=#\"\u003e...\u003c/a\u003e\u003c/td\u003e\n    \u003ctd\u003e\n      \u003ci\u003e...\u003c/i\u003e\u003cbr\u003e\n    \u003c/td\u003e\n  \u003c/tr\u003e\n\u003c/table\u003e\n\u003c/div\u003e\n\n\n\u003chr\u003e\n\n### Related Repositories\n\n**[`LLMs from Scratch`](https://github.com/zeyadusf/LLMs-from-Scratch)**\n**[`Topics in NLP and LLMs`](https://github.com/zeyadusf/topics-in-nlp-llm)**\n\n\u003chr\u003e\n\n## 📞 Contact :\n\n\u003c!--social media--\u003e\n\u003cdiv align=\"center\"\u003e\n\u003ca href=\"https://www.kaggle.com/zeyadusf\" target=\"blank\"\u003e\n  \u003cimg align=\"center\" src=\"https://raw.githubusercontent.com/rahuldkjain/github-profile-readme-generator/master/src/images/icons/Social/kaggle.svg\" alt=\"zeyadusf\" height=\"30\" width=\"40\" /\u003e\n\u003c/a\u003e\n\n\n\u003ca href=\"https://huggingface.co/zeyadusf\" target=\"blank\"\u003e\n  \u003cimg align=\"center\" src=\"https://github.com/zeyadusf/zeyadusf/assets/83798621/5c3db142-cda7-4c55-bcce-cc09d5b3aa50\" alt=\"zeyadusf\" height=\"40\" width=\"40\" /\u003e\n\u003c/a\u003e \n\n \u003ca href=\"https://github.com/zeyadusf\" target=\"blank\"\u003e\n   \u003cimg align=\"center\" src=\"https://raw.githubusercontent.com/rahuldkjain/github-profile-readme-generator/master/src/images/icons/Social/github.svg\" alt=\"zeyadusf\" height=\"30\" width=\"40\" /\u003e\n \u003c/a\u003e\n  \n\u003ca href=\"https://www.linkedin.com/in/zeyadusf/\" target=\"blank\"\u003e\n  \u003cimg align=\"center\" src=\"https://raw.githubusercontent.com/devicons/devicon/master/icons/linkedin/linkedin-original.svg\" alt=\"Zeyad Usf\" height=\"30\" width=\"40\" /\u003e\n  \u003c/a\u003e\n  \n  \n  \u003ca href=\"https://www.facebook.com/ziayd.yosif\" target=\"blank\"\u003e\n    \u003cimg align=\"center\" src=\"https://raw.githubusercontent.com/rahuldkjain/github-profile-readme-generator/master/src/images/icons/Social/facebook.svg\" alt=\"Zeyad Usf\" height=\"30\" width=\"40\" /\u003e\n  \u003c/a\u003e\n  \n\u003ca href=\"https://www.instagram.com/zeyadusf\" target=\"blank\"\u003e\n  \u003cimg align=\"center\" src=\"https://raw.githubusercontent.com/rahuldkjain/github-profile-readme-generator/master/src/images/icons/Social/instagram.svg\" alt=\"zeyadusf\" height=\"30\" width=\"40\" /\u003e\n\u003c/a\u003e \n\u003c/div\u003e\n\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzeyadusf%2Ffinetuning-llms","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzeyadusf%2Ffinetuning-llms","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzeyadusf%2Ffinetuning-llms/lists"}