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

[2/n] SFTDataset: refactor slimorca and message converters #1270

Merged
merged 26 commits into from
Aug 6, 2024

Conversation

RdoubleA
Copy link
Contributor

@RdoubleA RdoubleA commented Aug 6, 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)

As discussed in the RFC in #1186, we will merge instruct and chat datasets to the following unified pipeline that can better support multimodal:

  1. message_transform to create List[Message] from dataset with full flexibility on columns, ad-hoc modifications, etc. For multimodal, additionally images are loaded from the path
  2. prompt_template as a optional way to add structured text around specific roles in the list of messages
  3. model_transform that takes the list of messages and tokenizes it. For multimodal, it will additionally apply model-specific image transforms to the images associated with the sample

For ease of review, we will stage this as multiple moderate-sized PRs. This PR updates slimorca_dataset to use SFTDataset and refactors the message converters get_sharegpt_messages and get_openai_messages to their transform analogues: ShareGPTToMessages and JSONToMessages

Also renames _finetune.py to _sft.py

Previous PR: #1234

Test plan

  • update live docs and check rendering
  • unit tests for ShareGPTToMessages, JSONToMessages
  • updated unit test for slimorca_dataset
  • run unit tests via pytest tests
  • run recipe tests via pytest tests -m integration_test
  • compare loss curves of slimorca to original versions on main
image

Copy link

pytorch-bot bot commented Aug 6, 2024

🔗 Helpful Links

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

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

✅ No Failures

As of commit 6d84b31 with merge base 5c7246e (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 Aug 6, 2024
from torchtune.modules.tokenizers import ModelTokenizer
from torchtune.datasets._finetune import SFTDataset
from torchtune.datasets._packed import PackedDataset
from torchtune.modules.transforms import Transform


def slimorca_dataset(
Copy link
Contributor

Choose a reason for hiding this comment

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

This whole thing is so nice.

Returns:
ChatDataset: dataset configured with SlimOrca source data and Llama2 chat template
Union[SFTDataset, PackedDataset]: dataset configured with SlimOrca source data
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we use the | operator yet for this? Or is that only available in Python 3.11?

Copy link
Contributor

Choose a reason for hiding this comment

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

Like SFTDataset | PackedDataset

Copy link
Contributor Author

Choose a reason for hiding this comment

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

3.10 and above, and I think we test 3.9?

Copy link
Contributor

Choose a reason for hiding this comment

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

Grrr okay. Soon, soon.

@codecov-commenter
Copy link

Codecov Report

Attention: Patch coverage is 43.66197% with 40 lines in your changes missing coverage. Please review.

Project coverage is 27.04%. Comparing base (9fd5d01) to head (b58995b).

Files Patch % Lines
torchtune/data/_messages.py 26.08% 17 Missing ⚠️
tests/torchtune/data/test_messages.py 50.00% 12 Missing ⚠️
tests/torchtune/datasets/test_slimorca_dataset.py 46.66% 8 Missing ⚠️
torchtune/datasets/_slimorca.py 62.50% 3 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##             main    #1270       +/-   ##
===========================================
- Coverage   70.49%   27.04%   -43.46%     
===========================================
  Files         251      251               
  Lines       11596    11640       +44     
===========================================
- Hits         8175     3148     -5027     
- Misses       3421     8492     +5071     

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

@SalmanMohammadi
Copy link
Collaborator

Rafi shows me what a 10x engineer looks like, this is fresh clean

InputOutputToMessages
ShareGPTToMessages
JSONToMessages

Helper funcs
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: Helper Functions??

Copy link
Contributor

@ebsmothers ebsmothers left a comment

Choose a reason for hiding this comment

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

One comment, otherwise looks great

This value needs to be at least 4 though it is generally set to max sequence length accepted by the model.
Default is 1024.
model_transform (Transform): model specific transform to convert a list of messages
output by the dataset to tokens. This will always be a :class:`~torchtune.modules.tokenizers.ModelTokenizer`.
Copy link
Contributor

Choose a reason for hiding this comment

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

I commented this on the other PR (after it landed), but can you clarify why this always has to be a ModelTokenizer? And if that's the case, why don't we type it as such?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Discussed offline, keeping this as Transform to maintain consistency across SFTDataset, text dataset builders, multimodal dataset builders

@RdoubleA RdoubleA merged commit 2014dd3 into pytorch:main Aug 6, 2024
29 checks passed
@RdoubleA RdoubleA deleted the merged_dataset_2 branch August 6, 2024 21:36
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.

6 participants