Shortcuts

Message

class torchtune.data.Message(role: Literal['system', 'user', 'assistant'], content: str, masked: bool = False, ipython: bool = False, eot: bool = True)[source]

This dataclass represents individual messages in an instruction or chat dataset.

Note that the fields ipython and eot are only relevant when tokenizing with tiktoken, as they inform handling of special tokens in that case.

Variables:
  • role (Role) – role of the message writer. Can be “system”, “user”, “assistant”.

  • content (str) – content of the message.

  • masked (bool) – whether the message is masked in the sample. Default: False

  • ipython (bool) – whether the message is an ipython call. Default: False

  • eot (bool) – whether the message corresponds to the end of a turn. Should be true except in the case of multiple consecutive assistant messages. Default: True

classmethod from_dict(d: dict) Message[source]

Construct a Message from a dictionary.

Parameters:

d (dict) – dictionary containing the fields of the Message.

Returns:

constructed Message.

Return type:

Message

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