Skip to content

Commit

Permalink
Merge pull request #902 from HALIS-sh/tool-finetune
Browse files Browse the repository at this point in the history
Fix load from LoRA weight & empty tools and system
  • Loading branch information
research4pan authored Sep 27, 2024
2 parents 859ba26 + 0ebbdb1 commit 94021d3
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
11 changes: 10 additions & 1 deletion src/lmflow/models/hf_model_mixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,16 @@ def __prepare_model_for_training(

if model_args.use_lora:
model.enable_input_require_grads()
model = get_peft_model(model, self.peft_config)
if model_args.lora_model_path is not None:
# Load model from LoRA weights
model = PeftModel.from_pretrained(
model,
model_args.lora_model_path,
is_trainable=True,
)
else:
# New LoRA Finetuning
model = get_peft_model(model, self.peft_config)
model.print_trainable_parameters()

# We resize the embeddings only when necessary to avoid index errors.
Expand Down
12 changes: 7 additions & 5 deletions src/lmflow/utils/conversation_template/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -430,19 +430,21 @@ def encode_conversation(
'''
assert isinstance(messages, list), "Messages must be a list."

if tools is not None:
if tools is None:
tools = ''
else:
tools = ','.join(tools)
# logger.warning("Tools are not supported yet. Please include tools in the system message manually.")
else:
tools = ''

if system:
if system is None:
system = ""
else:
if system.replace(" ",""):
if not self.system_formatter:
raise ValueError("Your dataset contains system message but no system formatter is provided. "
"Consider either providing a system formatter or removing system prompt from your dataset.")
else:
system = None
system = ""
encoded_pairs = self._encode(tokenizer, messages, system, tools, **kwargs)

if self.separator and remove_last_sep:
Expand Down

0 comments on commit 94021d3

Please sign in to comment.