From 30b39c7115964859c7b1429335bed6d65ca792fe Mon Sep 17 00:00:00 2001 From: madroid Date: Fri, 20 Sep 2024 11:34:27 +0800 Subject: [PATCH] LoRA: add tools format to lora docs --- llms/mlx_lm/LORA.md | 62 ++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 58 insertions(+), 4 deletions(-) diff --git a/llms/mlx_lm/LORA.md b/llms/mlx_lm/LORA.md index 2d9a2553..a58905ac 100644 --- a/llms/mlx_lm/LORA.md +++ b/llms/mlx_lm/LORA.md @@ -160,8 +160,8 @@ For fine-tuning (`--train`), the data loader expects a `train.jsonl` and a `valid.jsonl` to be in the data directory. For evaluation (`--test`), the data loader expects a `test.jsonl` in the data directory. -Currently, `*.jsonl` files support three data formats: `chat`, -`completions`, and `text`. Here are three examples of these formats: +Currently, `*.jsonl` files support `chat`, `tools`, +`completions`, and `text` data formats. Here are three examples of these formats: `chat`: @@ -169,6 +169,60 @@ Currently, `*.jsonl` files support three data formats: `chat`, {"messages": [{"role": "system", "content": "You are a helpful assistant."}, {"role": "user", "content": "Hello."}, {"role": "assistant", "content": "How can I assistant you today."}]} ``` +`tools`: + +```json lines +{"messages":[{"role":"user","content":"What is the weather in San Francisco?"},{"role":"assistant","tool_calls":[{"id":"call_id","type":"function","function":{"name":"get_current_weather","arguments":"{\"location\": \"San Francisco, USA\", \"format\": \"celsius\"}"}}]}],"tools":[{"type":"function","function":{"name":"get_current_weather","description":"Get the current weather","parameters":{"type":"object","properties":{"location":{"type":"string","description":"The city and country, eg. San Francisco, USA"},"format":{"type":"string","enum":["celsius","fahrenheit"]}},"required":["location","format"]}}}]} +``` + +
+Click to view the single data format of tools + +Tokenize the dataset using [chat_templating](https://huggingface.co/docs/transformers/main/en/chat_templating#advanced-tool-use--function-calling) format. + +```jsonl +{ + "messages": [ + { "role": "user", "content": "What is the weather in San Francisco?" }, + { + "role": "assistant", + "tool_calls": [ + { + "id": "call_id", + "type": "function", + "function": { + "name": "get_current_weather", + "arguments": "{\"location\": \"San Francisco, USA\", \"format\": \"celsius\"}" + } + } + ] + } + ], + "tools": [ + { + "type": "function", + "function": { + "name": "get_current_weather", + "description": "Get the current weather", + "parameters": { + "type": "object", + "properties": { + "location": { + "type": "string", + "description": "The city and country, eg. San Francisco, USA" + }, + "format": { "type": "string", "enum": ["celsius", "fahrenheit"] } + }, + "required": ["location", "format"] + } + } + } + ] +} +``` + +
+ `completions`: ```jsonl @@ -215,8 +269,8 @@ hf_dataset: - Arguments specified in `config` will be passed as keyword arguments to [`datasets.load_dataset`](https://huggingface.co/docs/datasets/v2.20.0/en/package_reference/loading_methods#datasets.load_dataset). -In general, for the `chat` and `completions` formats, Hugging Face [chat -templates](https://huggingface.co/blog/chat-templates) are used. This applies +In general, for the `chat`, `tools` and `completions` formats, Hugging Face [chat +templates](https://huggingface.co/docs/transformers/main/en/chat_templating) are used. This applies the model's chat template by default. If the model does not have a chat template, then Hugging Face will use a default. For example, the final text in the `chat` example above with Hugging Face's default template becomes: