From 63fb3eb42653b5a4cdf17290fc21221c59b9031c Mon Sep 17 00:00:00 2001 From: Hamel Husain Date: Thu, 4 Jan 2024 18:14:20 -0800 Subject: [PATCH] set default for merge (#1044) --- README.md | 4 ++-- src/axolotl/cli/merge_lora.py | 9 ++++++++- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 172dd558e..2bf748303 100644 --- a/README.md +++ b/README.md @@ -1036,10 +1036,10 @@ Please use `--sample_packing False` if you have it on and receive the error simi ### Merge LORA to base -Add below flag to train command above +The following command will merge your LORA adapater with your base model. You can optionally pass the argument `--lora_model_dir` to specify the directory where your LORA adapter was saved, otherwhise, this will be inferred from `output_dir` in your axolotl config file. The merged model is saved in the sub-directory `{lora_model_dir}/merged`. ```bash -python3 -m axolotl.cli.merge_lora examples/your_config.yml --lora_model_dir="./completed-model" +python3 -m axolotl.cli.merge_lora your_config.yml --lora_model_dir="./completed-model" ``` If you run out of CUDA memory, you can try to merge in system RAM with diff --git a/src/axolotl/cli/merge_lora.py b/src/axolotl/cli/merge_lora.py index 4c810d572..4124e25b8 100644 --- a/src/axolotl/cli/merge_lora.py +++ b/src/axolotl/cli/merge_lora.py @@ -25,9 +25,16 @@ def do_cli(config: Path = Path("examples/"), **kwargs): load_in_8bit=False, load_in_4bit=False, flash_attention=False, - **kwargs + **kwargs, ) + if not parsed_cfg.lora_model_dir and parsed_cfg.output_dir: + parsed_cfg.lora_model_dir = parsed_cfg.output_dir + if not Path(parsed_cfg.lora_model_dir).exists(): + raise ValueError( + f"Target directory for merge: `{parsed_cfg.lora_model_dir}` does not exist." + ) + do_merge_lora(cfg=parsed_cfg, cli_args=parsed_cli_args)