Commit c6ca671
authored
fix(pt): recognize AOTInductor-wrapped CUDA OOM in AutoBatchSize (#5418)
When running `dp --pt-expt test` (or any path that goes through
`deepmd.pt_expt.infer.deep_eval`) against a `.pt2` AOTInductor package,
`AutoBatchSize` doubles the batch on every success. For models with a
large `sel` the exploration eventually saturates GPU memory, and the
CUDA caching allocator raises the usual ``CUDA out of memory`` from
inside the AOTInductor runtime. AOTInductor then rewraps that error as a
generic
RuntimeError: run_func_(...) API call failed at
.../aoti_runner/model_container_runner.cpp, line 144
The original "CUDA out of memory" text is printed only to stderr, so the
old `is_oom_error` -- which keyed on a short list of substrings in
`e.args[0]` -- never matched. `execute()` therefore did not shrink the
batch; the exception propagated and the run crashed on a GPU that was
otherwise completely idle (as confirmed by monitoring `nvidia-smi
--query-compute-apps`, which showed dp itself as the sole consumer
holding tens of GiB just before the failure). Widen `is_oom_error` to:
* walk the exception chain via `__cause__` / `__context__`, so that a
future PyTorch preserving the original OOM text is handled for free;
* keep matching the four plain CUDA OOM markers on every message in the
chain;
* additionally treat the AOTInductor wrapper signature (`run_func_(`
plus `model_container_runner`) as an OOM candidate. If the AOTInductor
wrapper ever hides a non-OOM failure, the batch shrinker will halve down
to 1 and then raise `OutOfMemoryError`, so the fallback is bounded --
non-OOM bugs still surface with a clear terminal error rather than being
silently retried forever.
<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit
* **Bug Fixes**
* Improved out-of-memory detection to catch more CUDA memory exhaustion
scenarios, including wrapped/instrumented failures; now reliably clears
CUDA cached memory when OOM conditions are identified to reduce
cascading failures.
* **Tests**
* Added unit tests validating OOM detection across varied exception
shapes and confirming CUDA cache clearing is invoked for detected OOMs.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->1 parent d14233e commit c6ca671
2 files changed
Lines changed: 81 additions & 14 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
49 | 49 | | |
50 | 50 | | |
51 | 51 | | |
52 | | - | |
53 | | - | |
54 | | - | |
55 | | - | |
56 | | - | |
57 | | - | |
58 | | - | |
59 | | - | |
60 | | - | |
61 | | - | |
62 | | - | |
63 | | - | |
64 | | - | |
65 | | - | |
| 52 | + | |
66 | 53 | | |
67 | 54 | | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
68 | 102 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
3 | 6 | | |
4 | 7 | | |
5 | 8 | | |
| |||
9 | 12 | | |
10 | 13 | | |
11 | 14 | | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
12 | 45 | | |
13 | 46 | | |
14 | 47 | | |
| |||
0 commit comments