-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
test(scattermoe-lora): skip on CUDA OOM under xdist contention #3689
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
| # Copyright (c) Axolotl AI | ||
| # Licensed under the Apache License, Version 2.0 | ||
|
|
||
| """Treat CUDA OOM as a skip for tests in this directory. | ||
|
|
||
| When the suite runs under ``pytest-xdist``, multiple workers contend for the | ||
| same physical GPU's memory budget. A test that fits comfortably in isolation | ||
| can OOM purely because peer workers are already holding most of VRAM. That's | ||
| an environmental race, not a code defect, so converting it to a skip keeps | ||
| mixed-GPU CI green without masking real regressions (a real correctness bug | ||
| surfaces as an assert/exception, not as ``torch.OutOfMemoryError``). | ||
|
|
||
| We hook ``pytest_runtest_call`` rather than using an autouse fixture because | ||
| pytest captures the test exception before re-entering the fixture's | ||
| generator — the fixture's ``try/except`` around ``yield`` never sees it. | ||
| """ | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| import gc | ||
|
|
||
| import pytest | ||
| import torch | ||
|
|
||
|
|
||
| def _cuda_oom_types() -> tuple[type[BaseException], ...]: | ||
| types: list[type[BaseException]] = [] | ||
| if hasattr(torch, "OutOfMemoryError"): | ||
| types.append(torch.OutOfMemoryError) | ||
| cuda_oom = getattr(torch.cuda, "OutOfMemoryError", None) | ||
| if cuda_oom is not None and cuda_oom not in types: | ||
| types.append(cuda_oom) | ||
| return tuple(types) or (RuntimeError,) | ||
|
|
||
|
|
||
| _OOM = _cuda_oom_types() | ||
|
|
||
|
|
||
| @pytest.hookimpl(hookwrapper=True) | ||
| def pytest_runtest_call(item): | ||
| outcome = yield | ||
| excinfo = outcome.excinfo | ||
| if excinfo is None: | ||
| return | ||
| exc_val = excinfo[1] | ||
| if isinstance(exc_val, _OOM): | ||
| gc.collect() | ||
| if torch.cuda.is_available(): | ||
| torch.cuda.empty_cache() | ||
| outcome.force_exception( | ||
| pytest.skip.Exception( | ||
| f"skipping on CUDA OOM (likely xdist worker contention): {exc_val}", | ||
| _use_item_location=True, | ||
| ) | ||
| ) | ||
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Avoid broad
RuntimeErrorfallback that can hide real failures.At Line 34, defaulting
_OOMto(RuntimeError,)means Line 47 may skip unrelated runtime failures if torch OOM classes are unavailable, masking real regressions.Proposed fix
def _cuda_oom_types() -> tuple[type[BaseException], ...]: types: list[type[BaseException]] = [] if hasattr(torch, "OutOfMemoryError"): types.append(torch.OutOfMemoryError) cuda_oom = getattr(torch.cuda, "OutOfMemoryError", None) if cuda_oom is not None and cuda_oom not in types: types.append(cuda_oom) - return tuple(types) or (RuntimeError,) + return tuple(types)def pytest_runtest_call(item): outcome = yield excinfo = outcome.excinfo if excinfo is None: return + if not _OOM: + return exc_val = excinfo[1] if isinstance(exc_val, _OOM): gc.collect()Also applies to: 47-47
🤖 Prompt for AI Agents