{"id":25582452,"url":"https://github.com/md-emon-hasan/fine-tuning","last_synced_at":"2026-05-15T20:05:15.909Z","repository":{"id":276971720,"uuid":"930901981","full_name":"Md-Emon-Hasan/Fine-Tuning","owner":"Md-Emon-Hasan","description":"End-to-end fine-tuning of Hugging Face models using LoRA, QLoRA, quantization, and PEFT techniques. Optimized for low-memory with efficient model deployment","archived":false,"fork":false,"pushed_at":"2025-06-19T08:16:45.000Z","size":5802,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-06-19T09:29:06.853Z","etag":null,"topics":["bitsandbytes","deep-learning","fine-tuning","fp16-training","gpu-optimization","gradient-checkpointing","huggingface","huggingface-datasets","lora","low-memory-training","machine-learning","model-training","natural-language-processing","nlp","parameter-efficient-fine-tuning","peft","pytorch","qlora","quantization","transformers"],"latest_commit_sha":null,"homepage":"","language":"Jupyter Notebook","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/Md-Emon-Hasan.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,"zenodo":null}},"created_at":"2025-02-11T11:59:03.000Z","updated_at":"2025-06-19T08:16:49.000Z","dependencies_parsed_at":"2025-02-11T13:23:06.819Z","dependency_job_id":"82b0b4f5-1fc0-483f-a46c-16b2954b839c","html_url":"https://github.com/Md-Emon-Hasan/Fine-Tuning","commit_stats":null,"previous_names":["md-emon-hasan/fine-tuning"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/Md-Emon-Hasan/Fine-Tuning","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Md-Emon-Hasan%2FFine-Tuning","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Md-Emon-Hasan%2FFine-Tuning/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Md-Emon-Hasan%2FFine-Tuning/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Md-Emon-Hasan%2FFine-Tuning/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Md-Emon-Hasan","download_url":"https://codeload.github.com/Md-Emon-Hasan/Fine-Tuning/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Md-Emon-Hasan%2FFine-Tuning/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":266624745,"owners_count":23958299,"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-07-23T02:00:09.312Z","response_time":66,"last_error":null,"robots_txt_status":null,"robots_txt_updated_at":null,"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":["bitsandbytes","deep-learning","fine-tuning","fp16-training","gpu-optimization","gradient-checkpointing","huggingface","huggingface-datasets","lora","low-memory-training","machine-learning","model-training","natural-language-processing","nlp","parameter-efficient-fine-tuning","peft","pytorch","qlora","quantization","transformers"],"created_at":"2025-02-21T05:16:32.054Z","updated_at":"2026-05-15T20:05:10.874Z","avatar_url":"https://github.com/Md-Emon-Hasan.png","language":"Jupyter Notebook","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Fine Tuning\n\n## 📌 Overview\nThis repository contains implementations and experiments related to **Fine Tuning**, including fine-tuning transformer models, applying LoRA and QLoRA, and optimizing models for efficient training.\n\n## 🚀 Features\n- Fine-tuning transformer models using **Hugging Face Transformers**\n- Parameter Efficient Fine-Tuning (**PEFT**) using LoRA and QLoRA\n- Model quantization with **BitsAndBytes** for low-memory optimization\n- Training and evaluation with **Hugging Face Trainer API**\n- Saving and loading fine-tuned models for inference\n\n## Example: .....\n\n## 📊 Dataset\nUses the **IMDB** dataset for sentiment classification. The dataset is loaded using:\n```python\nfrom datasets import load_dataset\ndataset = load_dataset(\"imdb\")\n```\nModify `dataset` in the scripts to use custom datasets.\n\n## 🏗 Model Fine-Tuning\nWe use **BERT-base-uncased** as the base model:\n```python\nfrom transformers import AutoTokenizer, AutoModelForSequenceClassification\ntokenizer = AutoTokenizer.from_pretrained(\"bert-base-uncased\")\nmodel = AutoModelForSequenceClassification.from_pretrained(\"bert-base-uncased\", num_labels=2)\n```\n\n## ⚡ Applying LoRA for PEFT\nWe apply **LoRA** for efficient fine-tuning:\n```python\nfrom peft import LoraConfig, get_peft_model\nlora_config = LoraConfig(r=8, lora_alpha=16, lora_dropout=0.1, task_type=\"SEQ_CLS\")\nmodel = get_peft_model(model, lora_config)\n```\n\n## 🔧 Model Quantization\nTo optimize for low-memory environments, we apply **4-bit quantization**:\n```python\nfrom transformers import BitsAndBytesConfig\nimport torch\nquantization_config = BitsAndBytesConfig(load_in_4bit=True, bnb_4bit_quant_type=\"nf4\", bnb_4bit_compute_dtype=torch.bfloat16)\nmodel = AutoModelForSequenceClassification.from_pretrained(\"bert-base-uncased\", quantization_config=quantization_config, num_labels=2)\n```\n\n## 🏋️ Training the Model\nWe use the Hugging Face Trainer API to fine-tune the model:\n```python\nfrom transformers import Trainer, TrainingArguments\ntraining_args = TrainingArguments(output_dir=\"./results\", evaluation_strategy=\"epoch\", learning_rate=2e-5, per_device_train_batch_size=8, num_train_epochs=1)\ntrainer = Trainer(model=model, args=training_args, train_dataset=tokenized_dataset[\"train\"], eval_dataset=tokenized_dataset[\"test\"], tokenizer=tokenizer)\ntrainer.train()\n```\n\n## 📈 Evaluation\n```python\nresults = trainer.evaluate()\nprint(results)\n```\n\n## 💾 Saving and Loading the Model\n```python\nmodel.save_pretrained(\"./fine-tuned-model\")\ntokenizer.save_pretrained(\"./fine-tuned-model\")\n```\nTo use the fine-tuned model for inference:\n```python\nfrom transformers import pipeline\nclassifier = pipeline(\"text-classification\", model=\"./fine-tuned-model\", tokenizer=tokenizer)\nresult = classifier(\"I feel so happy today!\")\nprint(result)\n```\n\n## 🔽 Exporting and Downloading the Model\nTo zip and download the trained model in **Google Colab**:\n```python\nimport shutil\nfrom google.colab import files\nshutil.make_archive(\"fine-tuned-model\", 'zip', \"./fine-tuned-model\")\nfiles.download(\"fine-tuned-model.zip\")\n```\n\n## 📜 License\nThis project is released under the MIT License.\n\n## 📝 Author\nDeveloped by **Md Emon Hasan**\n- GitHub: [Md-Emon-Hasan](https://github.com/Md-Emon-Hasan)\n- LinkedIn: [Md Emon Hasan](https://www.linkedin.com/in/md-emon-hasan)\n\n## ⭐ Acknowledgments\nSpecial thanks to **Hugging Face** for providing open-source tools and models for AI research!\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmd-emon-hasan%2Ffine-tuning","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmd-emon-hasan%2Ffine-tuning","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmd-emon-hasan%2Ffine-tuning/lists"}