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

[benchmarks] Run some models with smaller batch sizes. #6542

Merged
merged 3 commits into from
Feb 27, 2024

Conversation

ysiraichi
Copy link
Collaborator

This PR adapts the code in PyTorch main repo, so that a few models are executed with smaller batch sizes. This is an effort towards making the benchmarking scripts behavior closer.

In summary, 3 new sets are introduced:

  • USE_SMALL_BATCH_SIZE: batch sizes for training
  • INFERENCE_SMALL_BATCH_SIZE: batch sizes for inference
  • DONT_CHANGE_BATCH_SIZE: models whose batch size can't be changed in the command line

cc @miladm

@ysiraichi
Copy link
Collaborator Author

This PR should only be merged after: #6518

@@ -144,6 +144,48 @@
"hf_T5_generate",
}

# This list was extracted from PyTorch's repository: benchmarks/dynamo/torchbench.py
FORCE_AMP_FOR_FP16_BF16_MODELS = {
Copy link
Collaborator

Choose a reason for hiding this comment

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

These lists feel prone to divergence. Is this how PyTorch does it, too?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yukio: can you extract these lists from where they are so that we can import them? That will eliminate any maintenance burden from us (i.e. I don't want us to have to manually keep these lists in sync with the ones in Pytorch.)
IIRC you did something similar with the deny list being extracted into a YAML file.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes. There is a YAML file for skipped models. These models aren't included in that. I guess I could make the change to include these in the PyTorch repo.

@golechwierowicz
Copy link
Collaborator

This is an effort towards making the benchmarking scripts behavior closer.

What is the point of this? Is this to just get numbers for Inductor as close to the HUD as possible?

@ysiraichi
Copy link
Collaborator Author

That too. But another thing is that this may also prevent OOMs that we are getting even on inductor.

@ysiraichi
Copy link
Collaborator Author

@frgossen @golechwierowicz do you think we can merge this PR?

FORCE_FP16_FOR_BF16_MODELS = {"vision_maskrcnn"}

# Some models have large dataset that doesn't fit in memory. Lower the batch
# size to test the accuracy.
# This list was extracted from PyTorch's repository: benchmarks/dynamo/torchbench.py
Copy link
Collaborator

Choose a reason for hiding this comment

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

Do you think we can factor these lists out there and reuse them? That way we would be more robust against divergence.

@frgossen
Copy link
Collaborator

What worries me a little about PRs like this is that we will almost certainly diverge over time.
Until we can also operate on Cuda tensors, we likely have to work with our forked benchmarking script but we should try to reuse as much as we can from upstream PyTorch.

Do you think we can import and reuse the lists from PyTorch?

@ysiraichi
Copy link
Collaborator Author

Right. I will try to move those lists to a YAML file and, then, update this PR.

@ysiraichi
Copy link
Collaborator Author

Waiting for pytorch/pytorch#120299

@frgossen
Copy link
Collaborator

Sounds good. Ty!

@ysiraichi
Copy link
Collaborator Author

@frgossen @golechwierowicz I think this PR is ready for review. Could you review it when you have some time?

Here's a summary of the changes:

  • Deleted the introduced lists, since we already have the YAML file
  • Read and parse the YAML file once in the torchbench_model.py file
    • Used by both TorchBenchModelLoader (skips) and TorchBenchModel (batch size)
  • Move find_near_file from torchbench_model.py to utils.py

Copy link
Collaborator

@frgossen frgossen 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.
Thanks you!

its lists of models into sets of models.
"""

benchmarks_dynamo_dir = find_near_file(
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think we can make the assumtion that the xla root is at pytorch/xla. Allowing this flexibility with find_near_file feels like it will be hard to debug eventually

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I think @zpcore had a setup where pytorch and xla were sibling folders.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Would it make sense to agree on one setup so keep things simpler?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Sure. I don't mind.
@zpcore Thoughts?

Copy link
Collaborator

Choose a reason for hiding this comment

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

If we decide to make the assumption, we should specify it in https://github.com/pytorch/xla/blob/master/benchmarks/README.md

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I will merge this PR, and open another one for this change.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe the better solution is to add the file location in setup.py in the future. We can use import pkg_resources to find the file location.

@ysiraichi ysiraichi merged commit cd47390 into master Feb 27, 2024
17 of 18 checks passed
amithrm pushed a commit to amithrm/xla that referenced this pull request Mar 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants