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

Mixed Precision Training #113

Merged
merged 2 commits into from
Oct 31, 2024
Merged

Mixed Precision Training #113

merged 2 commits into from
Oct 31, 2024

Conversation

JSabadin
Copy link
Contributor

Mixed Precision Training Implementation

This pull request introduces mixed precision training to improve the performance and efficiency of our model training.

Key Changes

  • Mixed precision training has been implemented, leveraging the automatic mixed precision (AMP) feature available in PyTorch.
  • Testing results:
    • Prior to this implementation, the detection model took:
      • 10.5 minutes per epoch on a batch size of 16 (bs16)
      • 10.5 minutes per epoch on a batch size of 32 (bs32) due to high GPU utilization and full VRAM.
    • After implementing mixed precision training, the detection epoch time reduced to:
      • 8.5 minutes per epoch on a batch size of 32 (bs32), providing a significant performance boost.

Limitations

  • This implementation has only been tested on detection models. It is recommended to perform further testing on other models.
  • Some loss functions do not support mixed precision training. In these cases, the following should be applied:
    • Use torch.amp.autocast(..., disable=True) to disable AMP for specific loss functions.

Benefits of Mixed Precision Training

  • Reduced training time: By utilizing half-precision for certain operations, training time has been significantly reduced while maintaining model accuracy.
  • Better hardware utilization: Improved GPU memory usage, allowing for larger batch sizes without running into VRAM issues.

@JSabadin JSabadin requested a review from a team as a code owner October 12, 2024 09:47
@JSabadin JSabadin requested review from kozlov721, klemen1999, tersekmatija and conorsim and removed request for a team October 12, 2024 09:47
@github-actions github-actions bot added fix Fixing a bug release New version release labels Oct 12, 2024
@kozlov721 kozlov721 changed the title Fix/lower vram usage Mixed Precision Training Oct 14, 2024
Copy link
Collaborator

@kozlov721 kozlov721 left a comment

Choose a reason for hiding this comment

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

LGTM

@klemen1999 klemen1999 merged commit 1d83a2c into main Oct 31, 2024
5 of 6 checks passed
@klemen1999 klemen1999 deleted the fix/lower-vram-usage branch October 31, 2024 09:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fix Fixing a bug release New version release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants