diff --git a/requirements.txt b/requirements.txt index 12e907e5..fb5820ab 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,8 +1,8 @@ torch>=1.13.1 transformers>=4.29.1 datasets>=2.12.0 -accelerate>=0.19.0 -peft>=0.3.0 +accelerate>=0.21.0 +peft>=0.4.0 trl>=0.4.7 sentencepiece jieba diff --git a/src/llmtuner/__init__.py b/src/llmtuner/__init__.py index 46ff63b2..146ad353 100644 --- a/src/llmtuner/__init__.py +++ b/src/llmtuner/__init__.py @@ -1,4 +1,4 @@ from llmtuner.chat import ChatModel -__version__ = "0.1.2" +__version__ = "0.1.3" diff --git a/src/llmtuner/extras/save_and_load.py b/src/llmtuner/extras/save_and_load.py index fd4a8165..781b9bb7 100644 --- a/src/llmtuner/extras/save_and_load.py +++ b/src/llmtuner/extras/save_and_load.py @@ -1,6 +1,6 @@ import os import torch -from typing import Dict +from typing import Dict, Optional from transformers.trainer import WEIGHTS_NAME, WEIGHTS_INDEX_NAME from transformers.modeling_utils import load_sharded_checkpoint @@ -12,12 +12,12 @@ from llmtuner.extras.logging import get_logger logger = get_logger(__name__) -def get_state_dict(model: torch.nn.Module) -> Dict[str, torch.Tensor]: # get state dict containing trainable parameters +def get_state_dict(model: torch.nn.Module, trainable_only: Optional[bool] = True) -> Dict[str, torch.Tensor]: state_dict = model.state_dict() filtered_state_dict = {} for k, v in model.named_parameters(): - if v.requires_grad: + if (not trainable_only) or v.requires_grad: filtered_state_dict[k] = state_dict[k].cpu().clone().detach() return filtered_state_dict diff --git a/src/llmtuner/tuner/core/loader.py b/src/llmtuner/tuner/core/loader.py index 025a37df..a4e2e7ea 100644 --- a/src/llmtuner/tuner/core/loader.py +++ b/src/llmtuner/tuner/core/loader.py @@ -27,8 +27,8 @@ logger = get_logger(__name__) check_min_version("4.29.1") require_version("datasets>=2.12.0", "To fix: pip install datasets>=2.12.0") -require_version("accelerate>=0.19.0", "To fix: pip install accelerate>=0.19.0") -require_version("peft>=0.3.0", "To fix: pip install peft>=0.3.0") +require_version("accelerate>=0.21.0", "To fix: pip install accelerate>=0.21.0") +require_version("peft>=0.4.0", "To fix: pip install peft>=0.4.0") require_version("trl>=0.4.7", "To fix: pip install trl>=0.4.7") @@ -81,9 +81,6 @@ def load_model_and_tokenizer( elif model_args.quantization_bit == 4: require_version("bitsandbytes>=0.39.0", "To fix: pip install bitsandbytes>=0.39.0") - require_version("transformers>=4.30.1", "To fix: pip install transformers>=4.30.1") - require_version("accelerate>=0.20.3", "To fix: pip install accelerate>=0.20.3") - require_version("peft>=0.4.0.dev0", "To fix: pip install git+https://github.com/huggingface/peft.git") config_kwargs["load_in_4bit"] = True config_kwargs["quantization_config"] = BitsAndBytesConfig( load_in_4bit=True, diff --git a/src/llmtuner/tuner/core/trainer.py b/src/llmtuner/tuner/core/trainer.py index 2a025180..c9bb7043 100644 --- a/src/llmtuner/tuner/core/trainer.py +++ b/src/llmtuner/tuner/core/trainer.py @@ -56,7 +56,7 @@ class PeftTrainer(Seq2SeqTrainer): backbone_model.config.use_cache = True backbone_model.save_pretrained( output_dir, - state_dict=get_state_dict(backbone_model), + state_dict=get_state_dict(backbone_model, trainable_only=(self.finetuning_args.finetuning_type != "full")), safe_serialization=self.args.save_safetensors ) backbone_model.config.use_cache = False diff --git a/src/llmtuner/webui/chat.py b/src/llmtuner/webui/chat.py index ad3ebd8a..b721ad40 100644 --- a/src/llmtuner/webui/chat.py +++ b/src/llmtuner/webui/chat.py @@ -84,6 +84,12 @@ class WebChatModel(ChatModel): query, history, prefix, max_new_tokens=max_new_tokens, top_p=top_p, temperature=temperature ): response += new_text + response = self.postprocess(response) new_history = history + [(query, response)] chatbot[-1] = [query, response] yield chatbot, new_history + + def postprocess(self, response: str) -> str: + response = response.replace("<", "<") + response = response.replace(">", ">") + return response