should pytest --forked be supported for GPU unit test runs?
メンテナーはふだん 2 日以内に返信
まだ誰も着手していません。
評価
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 初心者へのやさしさ
- 18/100
調査の方向性
Start by running pytest --forked tests/unit/ on a GPU host to reproduce the Cannot re-initialize CUDA in forked subprocess error, then check which modules touch the device at import, beginning with tests/unit/simple_model.py and tests/unit/v1/half_precision/test_keep_in_fp32_modules.py. Done means maintainers choose between supporting --forked on GPU (with a collection-time CUDA check in tests/conftest.py) or updating CONTRIBUTING.md, so docs and tests agree. The decision has to come before implementation.
索引モデルが issue の本文から書いたものです。
説明
CONTRIBUTING.md tells contributors to run pytest --forked tests/unit/. It says --forked is required to test
CUDA functionality in distributed tests, and that it is safe because import deepspeed no longer initializes CUDA
(#8078, which followed #7918). On a GPU host, that command does not work on master (3fe2d9508):
- Collecting
tests/unitinitializes CUDA in the pytest process; 77 test modules do it.- Most go through
tests/unit/simple_model.py, whosedtype=preferred_dtype()default argument (#5206) queries
the device at import. - The others are boolean skip conditions such as
@pytest.mark.skipif(not get_accelerator().is_fp16_supported(), ...), module-levelpytest.skip()checks, and
qtorch's JIT build whentest_fp_quant.pyis imported (whenTORCH_CUDA_ARCH_LISTis unset).
- Most go through
- After that, any test that pytest-forked runs in a forked child and that uses CUDA fails with
RuntimeError: Cannot re-initialize CUDA in forked subprocess.DistributedTests are not affected, because their
ranks start from a forkserver (#2141). - CI cannot notice. GPU CI (
aws-torch-latest,aws-torch-latest-full,modal-torch-latest) runs without
--forked. CPU CI runs with--forked, but it cannot initialize CUDA. - New cases keep arriving: #8843 recently added 7 more import-time skip conditions to
tests/unit/v1/half_precision/test_keep_in_fp32_modules.py. - A check limited to one module does not protect the session.
test_chunked_cross_entropy.py::test_collection_leaves_cuda_initialization_fork_safe(#8653) checks that importing
its own module leaves CUDA fork-safe. In the failing run below it passes, while 18 other tests in the same file fail
because a different module initialized CUDA.
So the documented command is broken on GPU, and the question in #7918 ("It seems the opposite is true: the flag must not be used") is still open in practice.
Describe the solution you'd like
A decision between these two options, so the docs and the tests agree:
-
Support
--forkedon GPU hosts. Keep test collection free of device queries, and enforce it.- Write device-dependent skip conditions as strings, which pytest evaluates when each test runs, for example
@pytest.mark.skipif("not get_accelerator().is_fp16_supported()", ...). Apytest_markeval_namespacehook in
tests/conftest.pyprovidesget_accelerator. - Resolve device-dependent defaults and configs inside the tests, and import modules that build kernels at import
(qtorch) when they are first used. - Add a check in
tests/conftest.pythat fails tests when CUDA was initialized during collection.
aws-torch-latestrunstests/unit/v1on GPU for every PR, so it would catch new cases there; the nightly full
run covers the rest oftests/unit.
I have a branch that does the first two points.
- Write device-dependent skip conditions as strings, which pytest evaluates when each test runs, for example
-
Do not support
--forkedon GPU hosts. UpdateCONTRIBUTING.mdinstead:--forkedis not needed for distributed tests, because their ranks start from a forkserver.- GPU runs use plain
pytest, optionally with-n. --forkedstays for CPU runs.
No test changes are needed.
Describe alternatives you've considered
- Keeping the current state: the docs promise a command that fails on GPU, and nothing in CI checks it.
- Fixing individual tests without a check: it does not last, as #8843 shows.
Additional context
Trade-offs for option 1:
- Benefit: each test runs in its own process. State such as globals, torch settings, compile caches or an initialized
CUDA context cannot leak between tests or make results depend on test order. - Cost:
--forkedis slower. On 4x H200 (-n 4), about 920 tests took 58m52s with--forkedand 47m36s without.
Triton-heavy files are hit hardest:test_autoep_expert_activation.pytook 342 s with--forkedand 25 s without. - Contributor burden: skip conditions that query the device must be strings, and nothing may touch the device at
import time. Theconftest.pycheck would make violations fail with a message that names the cause.
This analysis was done with AI assistance.
- 主要言語
- Python
- スター
- 43.3k
- フォーク
- 5.1k
- 平均マージ
- 5日 10時間
- マージ済み PR(30日)
- 85
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートなし
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
deepspeedai/DeepSpeed のほかの issue
-
[Bug] DeepSpeedEngine.step leaves _running_engine_step=True permanently on exception, corrupting is_gradient_accumulation_boundary()対応中かも @its-amann が今日担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 85/100
deepspeedai/DeepSpeed#9190 · コメント 1 件 ·
メンテナーはふだん 2 日以内に返信
-
[Bug] PipelineEngine._exec_reduce_grads and _exec_optimizer_step leave _force_grad_boundary=True permanently after any exception対応中かも @bantianyue が今日担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
deepspeedai/DeepSpeed#9183 ·
メンテナーはふだん 2 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 84/100
deepspeedai/DeepSpeed#9019 · コメント 2 件 ·
メンテナーはふだん 2 日以内に返信
-
fp16 `hysteresis: 0` (or negative) makes DynamicLossScaler never lower the loss scale, so every overflowing step is skipped forever対応中かも @damienen が 26 日前に担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
deepspeedai/DeepSpeed#8982 ·
メンテナーはふだん 2 日以内に返信
-
[BUG] OneCycle applies the minimum momentum to the first Adam update対応中かも @ai-yang が 30 日前に担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
deepspeedai/DeepSpeed#8951 ·
メンテナーはふだん 2 日以内に返信
deepspeedai/DeepSpeed の issue をすべて見る
似ている issue
-
area/auth comp/agent P3 type/bug
難易度 2/5 1〜3時間 初心者へのやさしさ 88/100
NousResearch/hermes-agent#161417 ·
メンテナーはふだん 1 日以内に返信
-
難易度 1/5 1〜3時間 初心者へのやさしさ 75/100
メンテナーはふだん 2 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 88/100
Dao-AILab/flash-attention#3251 ·
メンテナーはふだん 2 日以内に返信
-
[New Check]: sqlserver_public_network_access_disabled対応中かも @pouria-l が今日担当しました。 オープンfeature-request status/needs-triage
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
prowler-cloud/prowler#13607 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
external langchain
難易度 1/5 1時間未満 初心者へのやさしさ 90/100
langchain-ai/docs#8184 ·
メンテナーはふだん 1 日以内に返信