From 33f2c0d4f89cf76671c0fdfbcee79d732b6a020e Mon Sep 17 00:00:00 2001 From: hiyouga Date: Thu, 4 Jan 2024 23:19:08 +0800 Subject: [PATCH] fix #2081 --- src/llmtuner/model/adapter.py | 5 +++++ src/llmtuner/model/patcher.py | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/llmtuner/model/adapter.py b/src/llmtuner/model/adapter.py index e3e4da15..261650b7 100644 --- a/src/llmtuner/model/adapter.py +++ b/src/llmtuner/model/adapter.py @@ -1,5 +1,6 @@ import torch from typing import TYPE_CHECKING +from transformers.integrations import is_deepspeed_zero3_enabled from peft import PeftModel, TaskType, LoraConfig, get_peft_model from llmtuner.extras.logging import get_logger @@ -71,6 +72,10 @@ def init_adapter( assert len(model_args.adapter_name_or_path) == 1, "Quantized model only accepts a single adapter." is_mergeable = False + if is_deepspeed_zero3_enabled(): + assert len(model_args.adapter_name_or_path) == 1, "Cannot use multiple adapters in DeepSpeed ZeRO-3." + is_mergeable = False + if (is_trainable and not finetuning_args.create_new_adapter) or (not is_mergeable): adapter_to_merge = model_args.adapter_name_or_path[:-1] adapter_to_resume = model_args.adapter_name_or_path[-1] diff --git a/src/llmtuner/model/patcher.py b/src/llmtuner/model/patcher.py index 5b91cb47..426372ee 100644 --- a/src/llmtuner/model/patcher.py +++ b/src/llmtuner/model/patcher.py @@ -3,7 +3,7 @@ import math import torch import random from types import MethodType -from typing import TYPE_CHECKING, Any, Dict, List, Optional, Set, Tuple +from typing import TYPE_CHECKING, Any, Dict, List, Optional, Tuple from datasets import load_dataset from transformers import BitsAndBytesConfig, GPTQConfig, PreTrainedModel, PreTrainedTokenizerBase