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

Move logits.float() call #308

Merged
merged 1 commit into from
Oct 14, 2024

Conversation

ringohoffman
Copy link
Contributor

@ringohoffman ringohoffman commented Oct 13, 2024

Summary

The analogous logits.float() calls were moved in the Hugging Face modeling source code to be inside the if labels is not None block to avoid upcasting logits unless they are being used in a loss calculation; this avoids a memory spike during inference if the model is in lower precision.

Some of your models already have this change:

if labels is not None:
# Upcast to float if we need to compute the loss to avoid potential precision issues
logits = logits.float()

if labels is not None:
# Upcast to float if we need to compute the loss to avoid potential precision issues
logits = logits.float()

See also:

Testing Done

  • Hardware Type:
  • run make test to ensure correctness
  • run make checkstyle to ensure code style
  • run make test-convergence to ensure convergence

@ringohoffman
Copy link
Contributor Author

@shimizust @lancerts @ByronHsu

How does this look?

@ByronHsu
Copy link
Collaborator

Sorry for the delay. This looks great! Thank you for making liger consistent with the latest hf implementation

@ByronHsu ByronHsu merged commit 04d5a0e into linkedin:main Oct 14, 2024
2 checks passed
@ringohoffman ringohoffman deleted the move-logits-float-cast branch October 14, 2024 21:16
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.

2 participants