fix #303
This commit is contained in:
parent
40996bddb2
commit
da2fe372cc
|
@ -21,7 +21,7 @@ training_args:
|
|||
# settings for logging
|
||||
log_level: info
|
||||
logging_strategy: steps
|
||||
logging_steps: 500
|
||||
logging_steps: 10
|
||||
# settings for evaluation
|
||||
per_device_eval_batch_size: 16
|
||||
evaluation_strategy: steps
|
||||
|
|
|
@ -1,14 +1,10 @@
|
|||
from pathlib import Path
|
||||
from typing import Annotated, Union
|
||||
|
||||
import typer
|
||||
from peft import PeftModelForCausalLM
|
||||
from transformers import (
|
||||
AutoModel,
|
||||
AutoTokenizer,
|
||||
PreTrainedModel,
|
||||
PreTrainedTokenizer,
|
||||
PreTrainedTokenizerFast
|
||||
)
|
||||
from PIL import Image
|
||||
import torch
|
||||
|
@ -21,12 +17,20 @@ def load_model_and_tokenizer(
|
|||
):
|
||||
model_dir = Path(model_dir).expanduser().resolve()
|
||||
if (model_dir / 'adapter_config.json').exists():
|
||||
import json
|
||||
with open(model_dir / 'adapter_config.json', 'r', encoding='utf-8') as file:
|
||||
config = json.load(file)
|
||||
model = AutoModel.from_pretrained(
|
||||
model_dir,
|
||||
config.get('base_model_name_or_path'),
|
||||
trust_remote_code=trust_remote_code,
|
||||
device_map='auto',
|
||||
torch_dtype=torch.bfloat16
|
||||
)
|
||||
model = PeftModelForCausalLM.from_pretrained(
|
||||
model=model,
|
||||
model_id=model_dir,
|
||||
trust_remote_code=trust_remote_code,
|
||||
)
|
||||
tokenizer_dir = model.peft_config['default'].base_model_name_or_path
|
||||
else:
|
||||
model = AutoModel.from_pretrained(
|
||||
|
@ -50,56 +54,56 @@ def main(
|
|||
model_dir: Annotated[str, typer.Argument(help='')],
|
||||
):
|
||||
# For GLM-4 Finetune Without Tools
|
||||
# messages = [
|
||||
# {
|
||||
# "role": "user", "content": "#裙子#夏天",
|
||||
# }
|
||||
# ]
|
||||
|
||||
# For GLM-4 Finetune With Tools
|
||||
messages = [
|
||||
{
|
||||
"role": "system", "content": "",
|
||||
"tools":
|
||||
[
|
||||
{
|
||||
"type": "function",
|
||||
"function": {
|
||||
"name": "create_calendar_event",
|
||||
"description": "Create a new calendar event",
|
||||
"parameters": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"title": {
|
||||
"type": "string",
|
||||
"description": "The title of the event"
|
||||
},
|
||||
"start_time": {
|
||||
"type": "string",
|
||||
"description": "The start time of the event in the format YYYY-MM-DD HH:MM"
|
||||
},
|
||||
"end_time": {
|
||||
"type": "string",
|
||||
"description": "The end time of the event in the format YYYY-MM-DD HH:MM"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"title",
|
||||
"start_time",
|
||||
"end_time"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
|
||||
},
|
||||
{
|
||||
"role": "user",
|
||||
"content": "Can you help me create a calendar event for my meeting tomorrow? The title is \"Team Meeting\". It starts at 10:00 AM and ends at 11:00 AM."
|
||||
},
|
||||
"role": "user", "content": "#裙子#夏天",
|
||||
}
|
||||
]
|
||||
|
||||
# For GLM-4 Finetune With Tools
|
||||
# messages = [
|
||||
# {
|
||||
# "role": "system", "content": "",
|
||||
# "tools":
|
||||
# [
|
||||
# {
|
||||
# "type": "function",
|
||||
# "function": {
|
||||
# "name": "create_calendar_event",
|
||||
# "description": "Create a new calendar event",
|
||||
# "parameters": {
|
||||
# "type": "object",
|
||||
# "properties": {
|
||||
# "title": {
|
||||
# "type": "string",
|
||||
# "description": "The title of the event"
|
||||
# },
|
||||
# "start_time": {
|
||||
# "type": "string",
|
||||
# "description": "The start time of the event in the format YYYY-MM-DD HH:MM"
|
||||
# },
|
||||
# "end_time": {
|
||||
# "type": "string",
|
||||
# "description": "The end time of the event in the format YYYY-MM-DD HH:MM"
|
||||
# }
|
||||
# },
|
||||
# "required": [
|
||||
# "title",
|
||||
# "start_time",
|
||||
# "end_time"
|
||||
# ]
|
||||
# }
|
||||
# }
|
||||
# }
|
||||
# ]
|
||||
#
|
||||
# },
|
||||
# {
|
||||
# "role": "user",
|
||||
# "content": "Can you help me create a calendar event for my meeting tomorrow? The title is \"Team Meeting\". It starts at 10:00 AM and ends at 11:00 AM."
|
||||
# },
|
||||
# ]
|
||||
|
||||
# For GLM-4V Finetune
|
||||
# messages = [
|
||||
# {
|
||||
|
|
Loading…
Reference in New Issue