fix: force float32 precision on CPU to prevent distorted structures#670
Open
joshuasteier wants to merge 1 commit intojwohlwend:mainfrom
Open
fix: force float32 precision on CPU to prevent distorted structures#670joshuasteier wants to merge 1 commit intojwohlwend:mainfrom
joshuasteier wants to merge 1 commit intojwohlwend:mainfrom
Conversation
0820f97 to
83bb04c
Compare
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
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 updates PR #670 from the blanket CPU float32 workaround in
main.pyto the underlying fix described in #662.
On CPU, PyTorch Lightning wraps the forward pass with
torch.autocast("cpu", dtype=torch.bfloat16), sotorch.autocast("cuda", enabled=False)is a no-op there. As a result,the structure and affinity blocks in
boltz2.pystill run under CPU bf16autocast even though they explicitly cast inputs to float32.
This patch:
main.pyCPU precision workaround from this PRautocast_device_type()helper inmodel/modules/utils.pytorch.autocast("cuda", enabled=False)blocks in
src/boltz/model/models/boltz2.pywithtorch.autocast(autocast_device_type(s.device.type), enabled=False)Local validation:
torch.autocast("cpu", dtype=torch.bfloat16), the old path keepsmatmul in
torch.bfloat16autocast_device_type(...)path correctly yieldstorch.float32Credit:
Closes #653
Closes #662