Skip to content

Conversation

ringohoffman
Copy link

@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
Author

@shimizust @lancerts @ByronHsu

How does this look?

@lancerts lancerts requested a review from ByronHsu October 14, 2024 20:31
@ByronHsu
Copy link
Contributor

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