-
Notifications
You must be signed in to change notification settings - Fork 19
Implement batch bounds to even out resource usage during training #990
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
Open
frostedoyster
wants to merge
17
commits into
metatensor:main
Choose a base branch
from
frostedoyster:batch-bounds
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+484
−7
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- Add min_atoms_per_batch and max_atoms_per_batch to BaseHypers schema - Create CollateFnWithBatchBounds wrapper for batch validation - Add batch bounds to DatasetInfo class - Update train.py to pass batch bounds to DatasetInfo - Update SOAP-BPNN trainer to use batch bounds when creating dataloaders - Add comprehensive tests for batch bounds functionality - Create example demonstrating batch bounds usage Co-authored-by: frostedoyster <[email protected]>
- Update LLPR trainer to use batch bounds - Update PET trainer to use batch bounds - Update MACE trainer to use batch bounds - Update FlashMD trainer to use batch bounds - Update deprecated NanoPET trainer to use batch bounds All trainers now support min_atoms_per_batch and max_atoms_per_batch configuration options Co-authored-by: frostedoyster <[email protected]>
- Move import to module level in test_batch_bounds.py - Clarify docstring on how RuntimeError integrates with PyTorch DataLoader - Make it clear that batches are not automatically skipped but training is interrupted Co-authored-by: frostedoyster <[email protected]>
- Remove batch bounds from global BaseHypers - Add batch_atom_bounds to TrainerHypers for all architectures (SOAP-BPNN, LLPR, PET, MACE, FlashMD, NanoPET) - Change API to use list format: batch_atom_bounds: [min, max] - Return None for invalid batches instead of raising errors - Update all trainers to skip None batches in training/validation loops - Update tests to reflect new API and behavior - Update example documentation Co-authored-by: frostedoyster <[email protected]>
- Synchronize batch rejection across all processes in distributed mode - Use all_reduce with MIN operation to ensure all processes agree on batch validity - If any process has None batch, all processes skip that batch - Applied to all trainers: SOAP-BPNN, LLPR, PET, MACE, FlashMD, NanoPET Co-authored-by: frostedoyster <[email protected]>
- Add validation for batch_atom_bounds format (must be list of 2 elements) - Create should_skip_batch_distributed utility function - Apply utility to SOAP-BPNN and LLPR trainers - Note: Remaining trainers (PET, MACE, FlashMD, NanoPET) still use inline code but are functional Co-authored-by: frostedoyster <[email protected]>
- Remove CollateFnWithBatchBounds wrapper class - Add batch_atom_bounds parameter directly to CollateFn.__init__ - CollateFn now returns None for batches outside bounds - Update all trainers to pass batch_atom_bounds to CollateFn directly - Use should_skip_batch_distributed helper in all training/validation loops - Update tests to work with new API - Minimal code changes per trainer (3-4 lines for collate_fn, 1-2 lines per loop) Co-authored-by: frostedoyster <[email protected]>
…ers[] instead of get()
- Renamed should_skip_batch_distributed to should_skip_batch (simpler name)
- Fixed SOAP-BPNN training loop to use helper function instead of manual code
- Changed all hypers.get("batch_atom_bounds", [None, None]) to hypers["batch_atom_bounds"]
- Defaults are now handled in documentation.py files as intended
- All trainers now consistently use the helper function everywhere
Co-authored-by: frostedoyster <[email protected]>
Contributor
|
Hey, I have some questions:
|
Collaborator
Author
|
Contributor
If this is the way to go, could we at least keep track of how many batches were skipped and print it somewhere in the log file (e.g. as a percentage of the full dataset)? |
Contributor
|
If we can synchronize the skipping at the beggining of the collate function, apart from the code (this is just an opinion) being nicer, we would save a lot of wasted computation. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR implements even load management between different batches, based on the total number of atoms in a batch. This is implemented by letting the user specify a lower and upper bound of atoms in a batch. In practice, training is done as normal but, if a batch has too few or too many atoms, it is skipped.
This is useful for two main reasons:
For PET, this complements the adaptive cutoff strategies to fully even out memory and computation usage across batches
📚 Documentation preview 📚: https://metatrain--990.org.readthedocs.build/en/990/