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

Consistent type checks for prepend and append tags. #1824

Merged
merged 4 commits into from
Oct 14, 2024

Conversation

krammnic
Copy link
Contributor

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.
#1565

Changelog

What are the changes made in this PR?

  • isinstance checks for prepend and append tags.

Test plan

Please make sure to do each of the following if applicable to your PR. If you're unsure about any one of these just ask and we will happily help. We also have a contributing page for some guidance on contributing.

  • 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.)

UX

If your function changed a public API, please add a dummy example of what the user experience will look like when calling it.
Here is a docstring example
and a tutorial example

  • I did not change any public API
  • I have added an example to docs or docstrings

Add checks that prepend and append tags are actually valid. Did not make None <=> empty string. Pretty minor fix(written in perfomance most efficient way)

Copy link

pytorch-bot bot commented Oct 13, 2024

🔗 Helpful Links

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

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

✅ No Failures

As of commit 4c77153 with merge base 7744608 (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 Oct 13, 2024
@codecov-commenter
Copy link

codecov-commenter commented Oct 13, 2024

Codecov Report

Attention: Patch coverage is 35.29412% with 11 lines in your changes missing coverage. Please review.

Project coverage is 69.09%. Comparing base (54673b7) to head (f3ac997).
Report is 14 commits behind head on main.

Files with missing lines Patch % Lines
torchtune/data/_prompt_templates.py 35.29% 11 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1824      +/-   ##
==========================================
+ Coverage   67.05%   69.09%   +2.03%     
==========================================
  Files         305      304       -1     
  Lines       15937    16014      +77     
==========================================
+ Hits        10687    11065     +378     
+ Misses       5250     4949     -301     

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

@krammnic
Copy link
Contributor Author

@RdoubleA Require some review

@krammnic
Copy link
Contributor Author

Pretty minor, so waiting for merge.

+ message.content
+ [{"type": "text", "content": append_tag}]
)
if isinstance(prepend_tag, str) and isinstance(append_tag, str):
Copy link
Contributor

Choose a reason for hiding this comment

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

maybe we should structure this slightly different to avoid the cascade of ifs:

content = message.content
if message.role in self.template:
    prepend_tag = self.template[message.role][0]
    append_tag = self.template[message.role][1]
    if prepend_tag is not None and len(prepend_tag) > 0:
        # add prepend tag
    if append_tag is not None and len(append_tag) > 0:
        # add append tag
formatted_dialogue.append(Message(...))

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It depends on if can something "bad" except None can come there

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah, I see now how do you want to do it. Ok, let me fix it like this. But I would like to save isinstance there

+ message.content
+ [{"type": "text", "content": append_tag}]
)
if isinstance(prepend_tag, str) and isinstance(append_tag, str):
Copy link
Contributor

Choose a reason for hiding this comment

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

similar comment above

+ message.content
+ [{"type": "text", "content": append_tag}]
)
content = {message.content}
Copy link
Contributor

Choose a reason for hiding this comment

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

the {} should be removed here, otherwise we cannot concatenate lists below. otherwise the rest looks good

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed in both cases

@krammnic
Copy link
Contributor Author

@RdoubleA Probably now all issues are fixed(CI might be reruned) We will save isinstance + len > 0 to handle anything that is not good as prepend/append in this case

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.

Excellent work, will wait for CI

content = [{"type": "text", "content": prepend_tag}] + content

if isinstance(append_tag, str) and len(append_tag) > 0:
content = content + [{"type": "text", "content": append_tag}]
else:
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: you could move content = message.content above the if statement and remove this else entirely

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed

{"type": "text", "content": prepend_tag}
] + message.content
else:
content = message.content
Copy link
Contributor

Choose a reason for hiding this comment

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

Similar comment here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed

@joecummings joecummings merged commit 19cacbe into pytorch:main Oct 14, 2024
17 checks passed
mori360 pushed a commit to mori360/torchtune that referenced this pull request Oct 14, 2024
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