mirror of
https://github.com/acon96/home-llm.git
synced 2026-01-08 21:28:05 -05:00
351 lines
16 KiB
YAML
351 lines
16 KiB
YAML
base_model: google/functiongemma-270m-it
|
|
model_type: Gemma3ForCausalLM
|
|
|
|
# gemma3 doesn't seem to play nice with ddp
|
|
ddp_find_unused_parameters: true
|
|
|
|
chat_template: jinja
|
|
chat_template_jinja: |
|
|
{%- macro format_parameters(properties, required) -%}
|
|
{%- set standard_keys = ['description', 'type', 'properties', 'required', 'nullable'] -%}
|
|
{%- set ns = namespace(found_first=false) -%}
|
|
{%- for key, value in properties | dictsort -%}
|
|
{%- if key not in standard_keys -%}
|
|
{%- if ns.found_first %},{% endif -%}
|
|
{%- set ns.found_first = true -%}
|
|
{{- key }}:{description:<escape>{{ value['description'] }}<escape>
|
|
{%- if value['type'] | upper == 'STRING' -%}
|
|
{%- if value['enum'] -%}
|
|
,enum:{{ format_argument(value['enum']) }}
|
|
{%- endif -%}
|
|
{%- elif value['type'] | upper == 'OBJECT' -%}
|
|
,properties:{
|
|
{%- if value['properties'] is defined and value['properties'] is mapping -%}
|
|
{{- format_parameters(value['properties'], value['required'] | default([])) -}}
|
|
{%- elif value is mapping -%}
|
|
{{- format_parameters(value, value['required'] | default([])) -}}
|
|
{%- endif -%}
|
|
}
|
|
{%- if value['required'] -%}
|
|
,required:[
|
|
{%- for item in value['required'] | default([]) -%}
|
|
<escape>{{- item -}}<escape>
|
|
{%- if not loop.last %},{% endif -%}
|
|
{%- endfor -%}
|
|
]
|
|
{%- endif -%}
|
|
{%- elif value['type'] | upper == 'ARRAY' -%}
|
|
{%- if value['items'] is mapping and value['items'] -%}
|
|
,items:{
|
|
{%- set ns_items = namespace(found_first=false) -%}
|
|
{%- for item_key, item_value in value['items'].items() -%}
|
|
{%- if item_value is not none -%}
|
|
{%- if ns_items.found_first %},{% endif -%}
|
|
{%- set ns_items.found_first = true -%}
|
|
{%- if item_key == 'properties' -%}
|
|
properties:{
|
|
{%- if item_value is mapping -%}
|
|
{{- format_parameters(item_value, value['items']['required'] | default([])) -}}
|
|
{%- endif -%}
|
|
}
|
|
{%- elif item_key == 'required' -%}
|
|
required:[
|
|
{%- for req_item in item_value -%}
|
|
<escape>{{- req_item -}}<escape>
|
|
{%- if not loop.last %},{% endif -%}
|
|
{%- endfor -%}
|
|
]
|
|
{%- elif item_key == 'type' -%}
|
|
{%- if item_value is string -%}
|
|
type:{{ format_argument(item_value | upper) }}
|
|
{%- else -%}
|
|
type:{{ format_argument(item_value | map('upper') | list) }}
|
|
{%- endif -%}
|
|
{%- else -%}
|
|
{{ item_key }}:{{ format_argument(item_value) }}
|
|
{%- endif -%}
|
|
{%- endif -%}
|
|
{%- endfor -%}
|
|
}
|
|
{%- endif -%}
|
|
{%- endif -%}
|
|
,type:<escape>{{ value['type'] | upper }}<escape>}
|
|
{%- endif -%}
|
|
{%- endfor -%}
|
|
{%- endmacro -%}
|
|
{% macro format_function_declaration(tool_data) -%}
|
|
declaration:{{- tool_data['function']['name'] -}}
|
|
{description:<escape>{{- tool_data['function']['description'] -}}<escape>
|
|
{%- set params = tool_data['function']['parameters'] -%}
|
|
{%- if params -%}
|
|
,parameters:{
|
|
{%- if params['properties'] -%}
|
|
properties:{ {{- format_parameters(params['properties'], params['required']) -}} },
|
|
{%- endif -%}
|
|
{%- if params['required'] -%}
|
|
required:[
|
|
{%- for item in params['required'] -%}
|
|
<escape>{{- item -}}<escape>
|
|
{{- ',' if not loop.last -}}
|
|
{%- endfor -%}
|
|
],
|
|
{%- endif -%}
|
|
{%- if params['type'] -%}
|
|
type:<escape>{{- params['type'] | upper -}}<escape>}
|
|
{%- endif -%}
|
|
{%- endif -%}
|
|
}
|
|
{%- endmacro -%}
|
|
{% macro format_argument(argument, escape_keys=True) -%}
|
|
{%- if argument is string -%}
|
|
{{- '<escape>' + argument + '<escape>' -}}
|
|
{%- elif argument is boolean -%}
|
|
{%- if argument -%}
|
|
{{- 'true' -}}
|
|
{%- else -%}
|
|
{{- 'false' -}}
|
|
{%- endif -%}
|
|
{%- elif argument is mapping -%}
|
|
{{- '{' -}}
|
|
{%- set ns = namespace(found_first=false) -%}
|
|
{%- for key, value in argument.items() -%}
|
|
{%- if ns.found_first %},{% endif -%}
|
|
{%- set ns.found_first = true -%}
|
|
{%- if escape_keys -%}
|
|
{{- '<escape>' + key + '<escape>' -}}
|
|
{%- else -%}
|
|
{{- key -}}
|
|
{%- endif -%}
|
|
:{{- format_argument(value, escape_keys=escape_keys) -}}
|
|
{%- endfor -%}
|
|
{{- '}' -}}
|
|
{%- elif argument is iterable -%}
|
|
{{- '[' -}}
|
|
{%- for item in argument -%}
|
|
{{- format_argument(item, escape_keys=escape_keys) -}}
|
|
{%- if not loop.last %},{% endif -%}
|
|
{%- endfor -%}
|
|
{{- ']' -}}
|
|
{%- else -%}
|
|
{{- argument -}}
|
|
{%- endif -%}
|
|
{%- endmacro -%}
|
|
{{ bos_token }}
|
|
{%- set ns = namespace(prev_message_type=None) -%}
|
|
{#- extract system prompt for merging with user role -#}
|
|
{%- set loop_messages = messages -%}
|
|
{%- set system_message_content = '' %}
|
|
{%- if messages[0]['role'] == 'system' or messages[0]['role'] == 'developer' -%}
|
|
{%- set system_message_content = messages[0]['content'] -%}
|
|
{%- set loop_messages = messages[1:] -%}
|
|
{%- endif -%}
|
|
{#- 'static' system prompt. -#}
|
|
{%- if tools -%}
|
|
{{- '<start_of_turn>developer\nYou are a model that can do function calling with the following functions' -}}
|
|
{%- for tool in tools %}
|
|
{{- '<start_function_declaration>' -}}
|
|
{{- format_function_declaration(tool) | trim }}
|
|
{{- '<end_function_declaration>' -}}
|
|
{%- endfor %}
|
|
{{- '<end_of_turn>\n' -}}
|
|
{%- else -%}
|
|
{{- '<start_of_turn>developer\nNo tools have been provided. Only respond with answers that do not require tool usage.<end_of_turn>\n' -}}
|
|
{%- endif -%}
|
|
{#- Loop through messages. -#}
|
|
{%- for message in loop_messages -%}
|
|
{%- if (message['role'] == 'assistant') -%}
|
|
{#- Rename "assistant" to "model". -#}
|
|
{%- set role = "model" -%}
|
|
{%- else -%}
|
|
{%- set role = message['role'] -%}
|
|
{%- endif -%}
|
|
{%- if role != 'tool' -%}
|
|
{%- if ns.prev_message_type != 'tool_response' -%}
|
|
{{- '<start_of_turn>' + role + '\n' }}
|
|
{%- endif -%}
|
|
{%- set ns.prev_message_type = None -%}
|
|
{%- if loop.first and system_message_content -%}
|
|
{%- if system_message_content is string -%}
|
|
{{ system_message_content | trim }}
|
|
{%- elif system_message_content is iterable -%}
|
|
{%- for item in system_message_content -%}
|
|
{%- if item['type'] == 'image' -%}
|
|
{{ raise_exception("Invalid content type 'image' in system message") }}
|
|
{%- elif item['type'] == 'text' -%}
|
|
{{ item['text'] | trim }}
|
|
{%- endif -%}
|
|
{%- endfor -%}
|
|
{%- else -%}
|
|
{{ raise_exception("Invalid content type in system message") }}
|
|
{%- endif -%}
|
|
{{- '\n' -}}
|
|
{%- endif -%}
|
|
{#- User/Assistant Messages -#}
|
|
{%- if 'content' in message and message['content'] is not none -%}
|
|
{%- if message['content'] is string -%}
|
|
{{ message['content'] | trim }}
|
|
{%- elif message['content'] is iterable -%}
|
|
{%- for item in message['content'] -%}
|
|
{%- if item['type'] == 'image' -%}
|
|
{{ '<start_of_image>' }}
|
|
{%- elif item['type'] == 'text' -%}
|
|
{{ item['text'] | trim }}
|
|
{%- endif -%}
|
|
{%- endfor -%}
|
|
{%- else -%}
|
|
{{ raise_exception("Invalid content type in user/assistant message") }}
|
|
{%- endif -%}
|
|
{%- set ns.prev_message_type = 'content' -%}
|
|
{%- endif -%}
|
|
{%- if 'tool_calls' in message and message['tool_calls'] and message['tool_calls'] is iterable -%}
|
|
{#- Tool Calls -#}
|
|
{%- for tool_call in message['tool_calls'] -%}
|
|
{% set function = tool_call['function'] %}
|
|
{{- '<start_function_call>call:' + function['name'] + '{' -}}
|
|
{%- if 'arguments' in function -%}
|
|
{%- if function['arguments'] is mapping -%}
|
|
{%- set ns = namespace(found_first=false) -%}
|
|
{%- for key, value in function['arguments'] | dictsort -%}
|
|
{%- if ns.found_first %},{% endif -%}
|
|
{%- set ns.found_first = true -%}
|
|
{{- key -}}:{{- format_argument(value, escape_keys=False) -}}
|
|
{%- endfor -%}
|
|
{%- elif function['arguments'] is string -%}
|
|
{# This handles string-JSON, just in case #}
|
|
{{ function['arguments'] }}
|
|
{%- endif %}
|
|
{%- endif -%}
|
|
{{- '}<end_function_call>' -}}
|
|
{%- endfor -%}
|
|
{%- if loop.last -%}
|
|
{{ '<start_function_response>' }}
|
|
{%- endif -%}
|
|
{%- set ns.prev_message_type = 'tool_call' -%}
|
|
{%- endif -%}
|
|
{%- else -%}
|
|
{#- Tool Responses -#}
|
|
{%- if 'content' in message and message['content'] -%}
|
|
{%- if message['content'] is mapping -%}
|
|
{%- if 'name' in message['content'] and 'response' in message['content'] -%}
|
|
{{ '<start_function_response>response:' + message['content']['name'] | trim + '{' }}
|
|
{%- set response_ns = namespace(found_first=false) -%}
|
|
{%- for key, value in message['content']['response'] | dictsort -%}
|
|
{%- if response_ns.found_first %},{% endif -%}
|
|
{%- set response_ns.found_first = true -%}
|
|
{{- key -}}:{{- format_argument(value, escape_keys=False) -}}
|
|
{%- endfor -%}
|
|
{{- '}<end_function_response>' -}}
|
|
{%- elif 'name' in message -%}
|
|
{{ '<start_function_response>response:' + message['name'] | trim + '{' }}
|
|
{%- set response_ns = namespace(found_first=false) -%}
|
|
{%- for key, value in message['content'].items() -%}
|
|
{%- if response_ns.found_first %},{% endif -%}
|
|
{%- set response_ns.found_first = true -%}
|
|
{{- key -}}:{{- format_argument(value, escape_keys=False) -}}
|
|
{%- endfor -%}
|
|
{{- '}<end_function_response>' -}}
|
|
{%- else -%}
|
|
{{ raise_exception("Invalid tool response mapping: must contain 'name' and 'response' keys, or 'name' must be in the message.") }}
|
|
{%- endif -%}
|
|
{%- elif message['content'] is string -%}
|
|
{%- if 'name' in message -%}
|
|
{{ '<start_function_response>response:' + message['name'] | trim + '{value:' + format_argument(message['content'], escape_keys=False) + '}<end_function_response>' }}
|
|
{%- else -%}
|
|
{{ raise_exception("Invalid tool response: 'name' must be provided.") }}
|
|
{%- endif -%}
|
|
{%- elif message['content'] is iterable -%}
|
|
{%- for item in message['content'] -%}
|
|
{%- if item is mapping -%}
|
|
{%- if 'name' in item and 'response' in item -%}
|
|
{{ '<start_function_response>response:' + item['name'] | trim + '{' }}
|
|
{%- set response_ns = namespace(found_first=false) -%}
|
|
{%- for key, value in item['response'].items() -%}
|
|
{%- if response_ns.found_first %},{% endif -%}
|
|
{%- set response_ns.found_first = true -%}
|
|
{{- key -}}:{{- format_argument(value, escape_keys=False) -}}
|
|
{%- endfor -%}
|
|
{{- '}<end_function_response>' -}}
|
|
{%- elif 'name' in message -%}
|
|
{{ '<start_function_response>response:' + message['name'] | trim + '{' }}
|
|
{%- set response_ns = namespace(found_first=false) -%}
|
|
{%- for key, value in item.items() -%}
|
|
{%- if response_ns.found_first %},{% endif -%}
|
|
{%- set response_ns.found_first = true -%}
|
|
{{- key -}}:{{- format_argument(value, escape_keys=False) -}}
|
|
{%- endfor -%}
|
|
{{- '}<end_function_response>' -}}
|
|
{%- else -%}
|
|
{{ raise_exception("Invalid tool response mapping: must contain 'name' and 'response' keys, or 'name' must be in the message.") }}
|
|
{%- endif -%}
|
|
{%- else -%}
|
|
{{ raise_exception("Invalid tool response message: multiple responses must all be mappings") }}
|
|
{%- endif -%}
|
|
{%- endfor -%}
|
|
{%- else -%}
|
|
{{ raise_exception("Invalid content type in tool message: must be mapping, iterable of mappings, or string.") }}
|
|
{%- endif -%}
|
|
{%- endif -%}
|
|
{%- set ns.prev_message_type = 'tool_response' -%}
|
|
{%- endif -%}
|
|
{%- if ns.prev_message_type not in ['tool_call', 'tool_response'] -%}
|
|
{{ '<end_of_turn>\n' }}
|
|
{%- endif -%}
|
|
{%- endfor -%}
|
|
{%- if add_generation_prompt -%}
|
|
{%- if ns.prev_message_type != 'tool_response' -%}
|
|
{{- '<start_of_turn>model\n' -}}
|
|
{%- endif -%}
|
|
{%- endif -%}
|
|
|
|
|
|
special_tokens:
|
|
eot_tokens:
|
|
- <end_of_turn>
|
|
- <end_function_call>
|
|
eos_token: <end_of_turn>
|
|
|
|
datasets:
|
|
- path: /workspace/data/datasets/sample.jsonl
|
|
ds_type: json
|
|
type: chat_template
|
|
roles_to_train: []
|
|
message_field_training: train_on_turn
|
|
|
|
dataset_prepared_path: /workspace/data/datasets/prepared/
|
|
|
|
# test_datasets:
|
|
# - path: /workspace/data/datasets/home_assistant_test.jsonl
|
|
# ds_type: json
|
|
# type: chat_template
|
|
val_set_size: 0.0
|
|
|
|
output_dir: /workspace/data/training-runs/Home-FunctionGemma-270m
|
|
|
|
sequence_len: 5130
|
|
sample_packing: false
|
|
eval_sample_packing: false
|
|
|
|
use_tensorboard: true
|
|
|
|
# batch size = 16
|
|
gradient_accumulation_steps: 16
|
|
micro_batch_size: 1
|
|
num_epochs: 1
|
|
optimizer: adamw_bnb_8bit
|
|
lr_scheduler: cosine
|
|
learning_rate: 0.0002
|
|
|
|
bf16: true
|
|
|
|
gradient_checkpointing: true
|
|
gradient_checkpointing_kwargs:
|
|
use_reentrant: false
|
|
resume_from_checkpoint:
|
|
logging_steps: 1
|
|
flash_attention: true
|
|
|
|
warmup_ratio: 0.1
|
|
evals_per_epoch:
|
|
saves_per_epoch: 1
|
|
weight_decay: 0.0
|