{"id":29143429,"url":"https://github.com/scaleoutsystems/federated-llm-workshop","last_synced_at":"2025-06-30T20:07:23.550Z","repository":{"id":300090161,"uuid":"1005153066","full_name":"scaleoutsystems/federated-llm-workshop","owner":"scaleoutsystems","description":null,"archived":false,"fork":false,"pushed_at":"2025-06-27T11:23:25.000Z","size":822,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-06-27T12:32:40.355Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Jupyter Notebook","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/scaleoutsystems.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,"zenodo":null}},"created_at":"2025-06-19T18:55:58.000Z","updated_at":"2025-06-27T11:23:28.000Z","dependencies_parsed_at":null,"dependency_job_id":"872cf30d-f070-45b2-895f-007d0b68f406","html_url":"https://github.com/scaleoutsystems/federated-llm-workshop","commit_stats":null,"previous_names":["scaleoutsystems/federated-llm-workshop"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/scaleoutsystems/federated-llm-workshop","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/scaleoutsystems%2Ffederated-llm-workshop","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/scaleoutsystems%2Ffederated-llm-workshop/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/scaleoutsystems%2Ffederated-llm-workshop/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/scaleoutsystems%2Ffederated-llm-workshop/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/scaleoutsystems","download_url":"https://codeload.github.com/scaleoutsystems/federated-llm-workshop/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/scaleoutsystems%2Ffederated-llm-workshop/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":262842921,"owners_count":23373167,"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":[],"created_at":"2025-06-30T20:07:20.840Z","updated_at":"2025-06-30T20:07:23.227Z","avatar_url":"https://github.com/scaleoutsystems.png","language":"Jupyter Notebook","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Workshop: Federated LLM Fine-tuning\n\nIn this workshop we are using federated learning to fine-tune an LLM for generative question answering.   \n\n## Dataset\n\nWe use the [CARDBiomedBench dataset](https://huggingface.co/datasets/NIH-CARD/CARDBiomedBench), available on Hugging Face. It contains question-answer pairs from the biomedical area. \n\n## LLM\n\nWe fine-tune the [SmolLM2](https://huggingface.co/HuggingFaceTB/SmolLM2-135M) base model, a decoder transformer model developed by Hugging Face. In this workshop, we use the 135M parameter model. \n\n## LoRA (Low Rank Adaptation)\n\nInstead of fine-tuning all model parameters, we apply LoRA, a PEFT method that heavily reduces the number of trainable parameters. LoRA represents weight updates by two smaller matrices through low-rank decomposition. The original model weights remain frozen, while only these new matrices are trained. Read more about LoRA [here](https://huggingface.co/docs/peft/main/en/conceptual_guides/lora). \n\n## Use-Case\n\nWe consider the case where 5 hospitals hold question-answer pairs related to a different biomedical category. For regulatory reasons, the hospitals are not able to share their local data. Instead of each hospital fine-tuning their own LLM, they use **federated LLM fine-tuning** to collaboratively train a more capable model that generalizes across a broad range of biomedical question-answering tasks. \nThat is because federated learning allows the model to be trained on the data from all hospitals, resulting in a model that has learned from a larger and more diverse dataset -- without sharing the data itself!\n\n![Federated Learning Setting](figures/federated_case.png)\n\n## Benefits of using Federated LLM fine-tuning with LoRA \n\nIn federated learning, model parameters are exchanged between the clients and the server. By using LoRA, only the much smaller set of trainable parameters needs to be exchanged, significantly reducing communication overhead. Furthermore, LoRA reduces the computation cost for each client by requiring fewer parameters to be updated during training.\n\n![LoRA savings](figures/federated_finetuning_lora.png)\n\n## Available Code\n\nThe *workshop_centralized.ipynb* notebook demonstrates how an LLM can be fine-tuned in a normal, centralized setting. \nOn the other hand, the **workshop_federated_results.ipynb* notebook showcases the results in a federated setting. \n\nIn the *client* folder you can find the code necessary to run federated fine-tuning with FEDn.  \n\n## Running the Notebooks locally\n\nIf you want to run the notebooks on your own machine, you need to install the required libaries. \nFollow the steps below.\n\n1. **Create a Virtual Environment**\n   ```bash\n   # Create a new virtual environment\n   python -m venv .venv\n   \n   # Activate the virtual environment\n   # On Windows\n   .venv\\Scripts\\activate\n   # On Unix or MacOS\n   source .venv/bin/activate\n   ```\n\n2. **Install Dependencies**\n   ```bash\n   pip install -r requirements.txt\n   ```\n\n\n## Google Colab\n\nAlternatively, you can run the workshop_centralized notebook on Google Colab. This will also give you GPU access.\nThe Google Colab notebook is available here: https://colab.research.google.com/drive/105dZCQC2U6BNbmf0hj7Mokq9Nk6j8WJH?authuser=1#scrollTo=tQmx_1ZKpzQL\n\nIn order to use it, follow these steps: \n1. Go to **File → Save a copy in Drive**\n2. This will create your own personal copy you can edit and run.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fscaleoutsystems%2Ffederated-llm-workshop","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fscaleoutsystems%2Ffederated-llm-workshop","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fscaleoutsystems%2Ffederated-llm-workshop/lists"}