Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Messages and message transforms docs #1574

Merged
merged 7 commits into from
Sep 21, 2024
Merged

Conversation

RdoubleA
Copy link
Contributor

@RdoubleA RdoubleA commented Sep 13, 2024

Context

What is the purpose of this PR? Is it to

  • add a new feature
  • fix a bug
  • update tests and/or documentation
  • other (please add here)

Describe a fundamental component, Message, and how to create, format, and tokenize messages. and the concept of message transforms

Test plan

doc build

Copy link

pytorch-bot bot commented Sep 13, 2024

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/torchtune/1574

Note: Links to docs will display an error until the docs builds have been completed.

✅ No Failures

As of commit 5be46fc with merge base 9a863c8 (image):
💚 Looks good so far! There are no failures yet. 💚

This comment was automatically generated by Dr. CI and updates every 15 minutes.

@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Sep 13, 2024
@codecov-commenter
Copy link

codecov-commenter commented Sep 13, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 26.23%. Comparing base (9a863c8) to head (5be46fc).
Report is 2 commits behind head on main.

Additional details and impacted files
@@             Coverage Diff             @@
##             main    #1574       +/-   ##
===========================================
- Coverage   70.96%   26.23%   -44.73%     
===========================================
  Files         295      295               
  Lines       15080    15080               
===========================================
- Hits        10701     3956     -6745     
- Misses       4379    11124     +6745     
Flag Coverage Δ
26.23% <ø> (-44.73%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@RdoubleA RdoubleA marked this pull request as ready for review September 13, 2024 20:39
Copy link
Contributor

@felipemello1 felipemello1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, Rafi! It is well written, but like in the other PR review, i think the user can benefit from seeing more code, end2end, and less paragraphs.

The end2end, IMO, is important, showing the creation of a dummy dataset, etc. I think that an image with a mental model would be super helpful too

docs/source/basics/message_transforms.rst Outdated Show resolved Hide resolved
docs/source/basics/message_transforms.rst Outdated Show resolved Hide resolved
docs/source/basics/message_transforms.rst Outdated Show resolved Hide resolved
docs/source/basics/message_transforms.rst Show resolved Hide resolved

Messages are a core component in torchtune that govern how text and multimodal content is tokenized. It serves as the common interface
for all tokenizer and datasets APIs to operate on. Messages contain information about the text content, which role is sending the text
content, and other information relevant for special tokens in model tokenizers. For more information about the individual parameters
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same comments as before. IMO this should be 1 or 2 lines + maybe image with pipeline + code

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I personally think this is pretty concise as is. Will add a TODO to add an image. Planning to make an image for the whole data pipeline and I'll place parts of that where relevant in a follow up


.. code-block:: python

from torchtune.data import Message
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is great. Maybe giving a bit of context in the code, showing which class creates or receives a message, i think it would make it easier for the user to understand how things connect end2end.

Content is formatted as a list of dictionaries. This is because Messages can also contain multimodal content, such as images.

Images in Messages
^^^^^^^^^^^^^^^^^^
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code is great, but i think we need a bit of end2end, showing how to create the dataset and where messages are used.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

was actually thinking of a section "Tokenizing Messages" or similar to show how they are consumed

Message transforms
^^^^^^^^^^^^^^^^^^
Message transforms are convenient utilities to format raw data into a list of torchtune :class:`~torchtune.data.Message`
objects. See :ref:`message_transform_usage_label` for more discussion.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Message transforms and "Formatting messages with prompt templates" feels a bit out of place. Maybe it should be part of the previous sections

- :class:`~torchtune.data.ShareGPTToMessages`
- :class:`~torchtune.data.JSONToMessages`
- Preference
- :class:`~torchtune.data.ChosenRejectedToMessages`
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you also add the stack exchange paired transform?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

actually I didn't expose that class since it's specific to stack exchange paired. I think in the future it might be nice to generalize that class

@SalmanMohammadi
Copy link
Collaborator

We should TODO to write something about custom preference dataset transforms.

@RdoubleA RdoubleA merged commit d684a2d into pytorch:main Sep 21, 2024
17 checks passed
@RdoubleA RdoubleA deleted the messages_docs branch September 21, 2024 19:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants