Shortcuts

ShareGPTToMessages

class torchtune.data.ShareGPTToMessages(train_on_input: bool = False, column_map: Optional[Dict[str, str]] = None, new_system_prompt: Optional[str] = None)[source]

Convert a single chat sample adhering to the ShareGPT json structure to torchtune’s Message structure.

A single sample typically consists of a single optional system prompt and one or multiple turns of user and assistant messages.

ShareGPT follows:

{
    "conversations": [
        {
            "from": <system|human|gpt>,
            "value": <message>,
        },
        ...
    ]
}

Message follows:

[
    {
        "role": <system|user|assistant>,
        "content": <message>,
    },
    ...
]
Parameters:
  • train_on_input (bool) – whether the prompt should remain unmasked. Default: False

  • column_map (Optional[Dict[str, str]]) – a mapping from the expected columns (“conversations”) to the new column names in the dataset. Key should be “conversations” and value should be the new column name. If None, keep the default “conversations”. Default is None.

  • new_system_prompt (Optional[str]) – if specified, prepend a system message. This can serve as instructions to guide the model response. Setting this will OVERRIDE any system messages already present in the dataset. Default is None.

Raises:

ValueError – If column_map is provided and conversations not in column_map.

Docs

Access comprehensive developer documentation for PyTorch

View Docs

Tutorials

Get in-depth tutorials for beginners and advanced developers

View Tutorials

Resources

Find development resources and get your questions answered

View Resources