torchtitan icon indicating copy to clipboard operation
torchtitan copied to clipboard

[Feature] Pythonify next_batch

Open CarlosGomes98 opened this issue 8 months ago • 1 comments

Hey Folks!

I've had a really good time playing with torchtitan so far :)

Looking into the code, as it stands, the way the data loader is wrapped by next_batch is not very pythonic. It makes it very awkward to iterate through the data loader in a pythonic way with for or while.

This is a PoC of my suggestion to make this more pythonic.

I think this will especially bear fruit in situations where we might want to iterate through a dataset from beginning to end, e.g., for a validation dataset.

To note, this current change might break a few of the models under experimental, which would need to mirror this change in their train.py

CarlosGomes98 avatar Apr 23 '25 15:04 CarlosGomes98

Hi @CarlosGomes98!

Thank you for your pull request and welcome to our community.

Action Required

In order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you.

Process

In order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA.

Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with CLA signed. The tagging process may take up to 1 hour after signing. Please give it that time before contacting us about it.

If you have received this in error or have any questions, please contact us at [email protected]. Thanks!

facebook-github-bot avatar Apr 23 '25 15:04 facebook-github-bot

LGTM! Could you please fix linting before we could merge?

Should be good now :)

CarlosGomes98 avatar May 20 '25 07:05 CarlosGomes98

@CarlosGomes98 oops it seems lint test still fails. In case it's helpful, the command to lint all files is pre-commit run --all-files

tianyu-l avatar May 20 '25 08:05 tianyu-l

Thanks @tianyu-l , thats really helpful. The files it complains about now arent from this PR, so hopefully this should pass for the PR now.

CarlosGomes98 avatar May 20 '25 13:05 CarlosGomes98