From f8de8bb4f25f8b225db13949919da484d371a39e Mon Sep 17 00:00:00 2001 From: NanoCode012 Date: Fri, 21 Mar 2025 21:18:01 +0700 Subject: [PATCH] chore(doc): add instructions on adding custom integrations (#2422) [skip ci] * chore(doc): add instructions on adding custom integrations * chore: add warning help * feat: add note about integration path * fix: adjust text per suggestion --- docs/config.qmd | 6 +++++ docs/custom_integrations.qmd | 44 ++++++++++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+) diff --git a/docs/config.qmd b/docs/config.qmd index 38ec368a1..ea7ea2293 100644 --- a/docs/config.qmd +++ b/docs/config.qmd @@ -85,6 +85,12 @@ gpu_memory_limit: 20GiB # Do the LoRA/PEFT loading on CPU -- this is required if the base model is so large it takes up most or all of the available GPU VRAM, e.g. during a model and LoRA merge lora_on_cpu: true +# List[str]. Add plugins to extend the pipeline. +# See `src/axolotl/integrations` for the available plugins or doc below for more details. +# https://axolotl-ai-cloud.github.io/axolotl/docs/custom_integrations.html +plugins: + # - axolotl.integrations.cut_cross_entropy.CutCrossEntropyPlugin + # A list of one or more datasets to finetune the model with datasets: # HuggingFace dataset repo | s3://,gs:// path | "json" for local dataset, make sure to fill data_files diff --git a/docs/custom_integrations.qmd b/docs/custom_integrations.qmd index 8d0498298..cb4aef9ca 100644 --- a/docs/custom_integrations.qmd +++ b/docs/custom_integrations.qmd @@ -55,3 +55,47 @@ sections = [ for section_name, folder_name in sections: print(print_section(section_name, folder_name)) ``` + +## Adding a new integration + +Plugins can be used to customize the behavior of the training pipeline through [hooks](https://en.wikipedia.org/wiki/Hooking). See [`axolotl.integrations.BasePlugin`](https://github.com/axolotl-ai-cloud/axolotl/blob/main/src/axolotl/integrations/base.py) for the possible hooks. + +To add a new integration, please follow these steps: + +1. Create a new folder in the `src/axolotl/integrations` directory. +2. Add any relevant files (`LICENSE`, `README.md`, `ACKNOWLEDGEMENTS.md`, etc.) to the new folder. +3. Add `__init__.py` and `args.py` files to the new folder. + - `__init__.py` should import the integration and hook into the appropriate functions. + - `args.py` should define the arguments for the integration. +4. (If applicable) Add CPU tests under `tests/integrations` or GPU tests under `tests/e2e/integrations`. + +::: {.callout-tip} + +See [src/axolotl/integrations/cut_cross_entropy](https://github.com/axolotl-ai-cloud/axolotl/tree/main/src/axolotl/integrations/cut_cross_entropy) for a minimal integration example. + +::: + +::: {.callout-warning} + +If you could not load your integration, please ensure you are pip installing in editable mode. + +```bash +pip install -e . +``` + +and correctly spelled the integration name in the config file. + +```yaml +plugins: + - axolotl.integrations.your_integration_name.YourIntegrationPlugin +``` + +::: + +::: {.callout-note} + +It is not necessary to place your integration in the `integrations` folder. It can be in any location, so long as it's installed in a package in your python env. + +See this repo for an example: [https://github.com/axolotl-ai-cloud/diff-transformer](https://github.com/axolotl-ai-cloud/diff-transformer) + +:::