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

Support conversation_style of openai format (OpenAI API style) #890

Merged
merged 13 commits into from
Apr 28, 2024

Conversation

xingyaoww
Copy link
Contributor

@xingyaoww xingyaoww commented Apr 28, 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)

Please link to any issues this PR addresses.

This adds a conversation_style of openai, similar to the openai one by @musabgultekin in #824 (comment).

Changelog

What are the changes made in this PR?

  • Add conversion function of openai_to_llama2_messages

It now supports converting sample like (following OpenAI API) the following directly to internal llama2_messages.

{
    # key could be "messages" OR "conversations"
    "messages": [
        {
            "role": <system|user|assistant>,
            "content": <message>,
        },
        ...
    ]
}

Example usage in config:

# Dataset
dataset:
  _component_: torchtune.datasets.chat_dataset
  source: json
  data_files: data/datasets/codeact-mixture.jsonl
  split: train
  conversation_style: standard_chat
  chat_format: ChatMLFormat
  max_seq_len: 16384
seed: 42
shuffle: True

Test plan

Please make sure to do each of the following if applicable to your PR. (If you're not sure about any one of these just ask and we will happily help.)

  • run pre-commit hooks and linters (make sure you've first installed via pre-commit install)
  • add unit tests for any new functionality
  • update docstrings for any new or updated methods or classes
  • run unit tests via pytest tests
  • run recipe tests via pytest tests -m integration_test
  • manually run any new or modified recipes with sufficient proof of correctness
    • include relevant commands and any other artifacts in this summary (pastes of loss curves, eval results, etc.)

Copy link

pytorch-bot bot commented Apr 28, 2024

🔗 Helpful Links

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

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

✅ No Failures

As of commit 95f2386 with merge base ea3d4ea (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 Apr 28, 2024
Copy link
Contributor

@RdoubleA RdoubleA left a comment

Choose a reason for hiding this comment

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

Thanks @xingyaoww for this addition! Overall looks great, just some minor comments.

Would be great if you can add a unit test for this as well. I also realized the sharegpt converter is missing a unit test also (I know, how could we) but both of these should be tested. Upto you if you also want to cover that :)

torchtune/data/_converters.py Show resolved Hide resolved
torchtune/data/_converters.py Show resolved Hide resolved
torchtune/data/_converters.py Outdated Show resolved Hide resolved
torchtune/data/_converters.py Outdated Show resolved Hide resolved
tests/torchtune/data/test_converters.py Show resolved Hide resolved
tests/torchtune/data/test_converters.py Show resolved Hide resolved
tests/torchtune/data/test_converters.py Outdated Show resolved Hide resolved
tests/torchtune/data/test_converters.py Outdated Show resolved Hide resolved
tests/torchtune/data/test_converters.py Outdated Show resolved Hide resolved
torchtune/data/_converters.py Outdated Show resolved Hide resolved
xingyaoww and others added 5 commits April 28, 2024 14:30
Co-authored-by: Rafi Ayub <33648637+RdoubleA@users.noreply.github.com>
Co-authored-by: Rafi Ayub <33648637+RdoubleA@users.noreply.github.com>
Co-authored-by: Rafi Ayub <33648637+RdoubleA@users.noreply.github.com>
@xingyaoww xingyaoww changed the title Support conversation_style of standard_chat format (OpenAI API style) Support conversation_style of openai format (OpenAI API style) Apr 28, 2024
@xingyaoww
Copy link
Contributor Author

@RdoubleA Thanks a ton for the review!!! I should fixed all the test issues in the latest commit and can confirm all tests passed!

image

Copy link
Contributor

@RdoubleA RdoubleA left a comment

Choose a reason for hiding this comment

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

this looks good to go! and thanks for the additional test! let me start the github CI and see what it thinks

Convert a chat sample adhering to the OpenAI API standard chat format to the Llama2 chat format.

OpenAI API `standard chat format <https://platform.openai.com/docs/guides/text-generation/chat-completions-api>`_ follows::
Check https://platform.openai.com/docs/guides/text-generation/chat-completions-api for more details
Copy link
Contributor

Choose a reason for hiding this comment

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

remove this line?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done!

@RdoubleA
Copy link
Contributor

@xingyaoww Looks like just a lint error which you should be able to fix with pre-commit

@xingyaoww
Copy link
Contributor Author

@RdoubleA should be fixed!

@RdoubleA RdoubleA merged commit a94803f into pytorch:main Apr 28, 2024
27 checks passed
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.

3 participants