Shortcuts

validate_messages

torchtune.data.validate_messages(messages: List[Message]) None[source]

Given a list of messages, ensure that messages form a valid back-and-forth conversation. An error will be raised if:

  • There is a system message that’s not the first message

  • There are two consecutive user messages

  • An assistant message comes before the first user message

  • The message is empty

  • Messages are shorter than length of 2 (min. one user-assistant turn)

Parameters:

messages (List[Message]) – the messages to validate.

Raises:

ValueError – If the messages are invalid.

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