Force float32 precision on CPU/MPS instead of bf16-mixed - #258
Open
fnachon wants to merge 9 commits into
Open
Conversation
Changes made to run without errors on the Mac MPS device: torch.autocast, number of devices and workers to use on M1-5 chips, workaround for CUDA-specific code, handling of float64 incompatibilities for MPS.
Replace hardcoded torch.autocast("cuda") with device-agnostic
device_type=tensor.device.type in confidence_utils, inverse_fold,
and writer modules introduced in the upstream merge.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Python pickle does not preserve RDKit atom-level SetProp values. When PyTorch DataLoader spawns worker processes (default num_workers=1 on macOS), self.canonicals is pickled and all atom 'name' properties are lost, causing KeyError in process_atom_features. Fix: load all required molecules directly from the moldir zip inside each get_sample() / get_feat() call instead of using the pickled self.canonicals. The moldir zip handle is cached per-process by _get_zipfile(), so there is no repeated I/O overhead. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…ders - Disable pin_memory on MPS (unsupported, causes UserWarning) - Enable persistent_workers when num_workers > 0 (avoids repeated worker init overhead and the PL suggestion warning) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
design.yaml, fold.yaml, and affinity.yaml all hardcode trainer.precision: bf16-mixed with no accelerator-conditional override anywhere in the CLI. On CPUs with AVX-512 BF16 support, Lightning's bf16-mixed silently runs ops in bfloat16 rather than falling back, producing structures with wrong bond lengths and atom clashes instead of an error. MPS has the same reliability problem. boltz hit and fixed the identical bug (jwohlwend/boltz#653); this port forces precision=32 whenever trainer.accelerator is explicitly "cpu" or "mps". Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
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.
design.yaml,fold.yaml, andaffinity.yamlall hardcodetrainer.precision: bf16-mixed, and nothing in the CLI overrides it based on accelerator. On CPUs with AVX-512 BF16 support, PyTorch Lightning'sbf16-mixedsilently runs ops in actual bfloat16 rather than falling back to float32, which produces structures with wrong bond lengths and atom clashes instead of erroring. MPS has the same reliability problem.boltz hit and fixed the identical bug: jwohlwend/boltz#653. This ports that fix: in
Predict.run(), forceprecision=32whenevertrainer.acceleratoris explicitly"cpu"or"mps"(e.g. via--config <step> trainer.accelerator=mps), regardless of what the step config requested.Given the existing MPS work in #145, this seemed worth prioritizing separately since it's a silent correctness bug, not just a crash.