fix(autobatching): recognise Warp OOM in memory estimation and free cache before the real run#589
Open
niklashoelter wants to merge 1 commit into
Conversation
c05b9d4 to
cb2c240
Compare
…he before real run
The autobatcher estimates a safe batch size by replaying the model forward
on geometrically-growing batches until it OOMs. Two defects on that path made
ORB v3 conservative (autograd forces -> ~2x memory) crash:
1. determine_max_batch_size only recognised the substring "CUDA out of
memory". ORB's neighbor lists run on Warp/nvalchemiops, whose allocator
raises "Failed to allocate <n> bytes", so the OOM was not caught and
propagated during estimation. In addition the re-raise sat inside the
message-matching loop, so a broadened list of signatures never worked:
the first non-matching entry re-raised before later ones were checked.
Fix: add DEFAULT_OOM_ERROR_MESSAGES = ("CUDA out of memory",
"Failed to allocate"), use it as the default across
determine_max_batch_size / InFlightAutoBatcher / BinningAutoBatcher, and
only re-raise after checking all signatures (any(...)).
2. After estimation survives, PyTorch's caching allocator still holds most of
the device memory, starving the separate Warp/cudaMallocAsync pool on the
first real forward pass (fails on a tiny 2556-byte allocation). Release the
cache at the end of estimate_max_memory_scaler (shared by both batchers)
via synchronize() + empty_cache().
Adds regression tests covering both OOM wordings and confirming genuine
non-OOM errors still propagate.
cb2c240 to
b678610
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.
Problem
InFlightAutoBatcher/BinningAutoBatcherestimate a safe batch size by replaying the model forward on geometrically-growing batches until it OOMs, then backing off. Two defects on that path make models whose neighbor lists run on Warp / nvalchemiops (e.g. ORB v3) crash instead of backing off:The Warp OOM isn't recognised.
determine_max_batch_sizeonly matched the substring"CUDA out of memory". Warp's allocator raises"Failed to allocate <n> bytes on device '…'", which doesn't match, so the OOM propagates and kills the run during memory estimation. In addition, the re-raisesat inside thefor msg in oom_error_messageloop, so passing a broadened list of signatures never worked — the first non-matching entry re-raised before later ones were checked.PyTorch's caching allocator starves the external Warp pool after estimation. Once (1) is fixed, estimation survives but the crash simply moves to the first real optimization forward pass, failing on a tiny (~2.5 KB) Warp allocation. The estimation forwards leave PyTorch's caching allocator holding almost all of device memory, and Warp allocates from a separate
cudaMallocAsyncpool that then has nothing left.Concretely, ORB v3 conservative on a 4272-molecule batch reproducibly died with
RuntimeError: Failed to allocate 2556 bytes on device 'cuda:N'.Fix (
torch_sim/autobatching.py)DEFAULT_OOM_ERROR_MESSAGES = ("CUDA out of memory", "Failed to allocate")and use it as the defaultoom_error_messagefordetermine_max_batch_size,InFlightAutoBatcher, andBinningAutoBatcher.if any(msg in exc_str …): return safethenraise), so a multi-signature list actually works.estimate_max_memory_scaler(shared by both batchers) withtorch.cuda.synchronize()+torch.cuda.empty_cache(), guarded bytorch.cuda.is_available(), so the real run isn't starved.Tests
Adds regression tests in
tests/test_autobatching.py: both PyTorch and Warp OOM wordings are recognised, and a genuine non-OOM error still propagates.pytest tests/test_autobatching.py→ 38 passed; ruff clean.Validation
ORB v3 conservative over a 4272-structure library on a dedicated GPU: 4/4 full runs complete
4272/4272with the fix; the same code with the memory release disabled crashes withFailed to allocate 2556 bytes.