Skip to content

[Feat] Add tuner event pid recovery and fix deadlock - #6895

Merged
yzhou103 merged 7 commits into
ROCm:mainfrom
jamesETsmith:feature/tuner-event-pid-recovery
Nov 10, 2026
Merged

yzhou103 merged 7 commits into
ROCm:mainfrom
jamesETsmith:feature/tuner-event-pid-recovery

Conversation

@jamesETsmith

@jamesETsmith jamesETsmith commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Fix a livelock in mp_tuner when a worker PID is missing from the PID-to-GPU map. Tasks that hit a mapping error now stay pending while the rest of the round is polled. The pool is rebuilt only when every remaining task has a stale mapping, and those candidates are rerun after the rebuild.

Motivation

When a pool worker restarts, its new PID is not in mp_tuner's PID-to-GPU map, and the task fails with a mapping error. On main, that task is appended to dummy_failed_tasks, a list that is never read. The task is also not marked complete and does not trigger a restart. If the only remaining tasks have stale mappings, the polling loop retries them forever. This is the livelock reported in ROCm/aiter#5091.

An earlier revision of this PR restarted the pool as soon as a mapping error appeared. Review on this PR showed that this hides the real failure. A mapping error is a symptom of a worker restart, and breaking out of polling early means a hung or crashed task later in the list is never reached by the timeout path. With --mp 2, one stale mapping, and one hung task, that version restarted repeatedly with the same remaining task set.

Changes

  • aiter/utility/mp_tuner.py
    • Record mapping-error tasks in mapping_error_tasks and keep polling the rest of the round. A mapping error does not break the loop, restart the pool, or drop the candidate.
    • After each round, drop completed tasks from mapping_error_tasks. If every remaining task has a mapping error, set pool_restart_needed.
    • Clear mapping_error_tasks after the pool is rebuilt so that resubmitted tasks start clean.
    • Remove the unused dummy_failed_tasks list.
    • The timeout, worker-exit, and accelerator-error paths are unchanged. They still run first when a real failure is present.
  • op_tests/tuning_tests/test_mp_tuner_logic.py
    • Update the simulate_poll_round simulation to match the new logic.
    • Replace TestKeyErrorHandling with TestMappingErrorRecovery (4 tests, described under Changed op tests below).
  • The AITER_PERFTEST_USE_CUDA_EVENT override from the first revision was removed in response to review: CUDA-event timing measures differently from the profiler path. That work is no longer part of this PR.

Testing

  • Unit tests added or updated
  • Performance benchmarks run
  • Tested on MI250X
  • Tested on MI300X

Documentation

  • Docstrings updated
  • User guide updated
  • Performance guide updated
  • No documentation change is needed, with the reason stated below

This change only affects internal recovery behavior in mp_tuner. No user-facing options or outputs change.

Dependencies

  • No new third-party dependencies added
  • New dependencies are listed and justified below

Breaking Changes

None. Tuning results do not change unless a mapping error happens. If one does, the affected candidates are now rerun after a pool rebuild, where before the tuner looped forever.

PR Self-Review

Reviewed revision

ef00a29

Behavior and intent

Before this PR, a task whose worker PID is missing from the PID-to-GPU map is never completed and never causes a restart. If only such tasks remain, mp_tuner loops forever (ROCm/aiter#5091). After this PR, mapping-error tasks stay pending while the other tasks keep being polled. That way, timeout, worker-exit, or accelerator-error handling can find the actual failure and restart the pool. If every remaining task has a stale mapping, the pool is rebuilt and those candidates are resubmitted. They are not replaced with failed dummy results. Restarting immediately on a mapping error was rejected because it stops polling before a hung task can time out.

Validation and unverified scope

Ran python3 -m unittest op_tests.tuning_tests.test_mp_tuner_logic -v on a clean clone at ef00a29. Python 3.12, CPU-only host, no ROCm build:

  • 10 tests passed. This includes all 4 new TestMappingErrorRecovery tests and the existing consecutive-timeout and AcceleratorError tests.
  • 8 tests errored at import time because import aiter triggers a JIT build of module_aiter_core, which needs ninja and ROCm. These tests are TestTaskExecutionTiming, TestTaskStartTimeReset, TestTaskWorkerExit, and TestWorkerErrorRatio. They come from main, are not changed by this PR, and are expected to run in the gfx942/gfx950 op-test CI.

Unverified:

  • The new tests check the polling loop through the simulate_poll_round copy in the test file, not by running mp_tuner itself.
  • I have not rerun, on this revision, the end-to-end case from review: a real BF16 tune with --mp 2, one stale PID mapping, and one hung task. I have also not rerun a full GPU tuning pass on this revision. The MI355X BF16 (M=64, N=5120, K=5120) tuning run in the first PR description used the earlier immediate-restart design.
  • Not tested on MI250X or MI300X.

PR-specific question

All 4 new TestMappingErrorRecovery tests fail on the main logic. On main, a mapping error is appended to dummy_failed_tasks and never sets pool_restart_needed, so:

  • test_mapping_error_does_not_interrupt_successful_task fails assertEqual(dummy, []) and assertTrue(restart).
  • test_pool_restarts_when_only_mapping_error_tasks_remain fails assertTrue(restart). This is the livelock.
  • test_mapping_error_candidates_are_rerun_after_restart fails because the candidate is put in the dummy list and no restart is requested.
  • test_timeout_is_processed_before_mapping_restart guards against the earlier immediate-restart design. That design would set restart in the first round, before the hung task times out.

No existing canonical test covered this. The old TestKeyErrorHandling tests asserted the livelock behavior, for example "only KeyError tasks remain → no restart". These tests replace them instead of duplicating them.

Changed op tests

op_tests/tuning_tests/test_mp_tuner_logic.py: simulate_poll_round now tracks mapping_error_tasks and sets pool_restart_needed only when every remaining task has a mapping error, matching mp_tuner. TestKeyErrorHandling (3 tests) is replaced by TestMappingErrorRecovery (4 tests). The new tests cover these behaviors:

  1. A mapping error does not stop polling of other tasks.
  2. A pending or hung task is handled by the timeout path before any restart for a mapping error.
  3. The pool restarts when only mapping-error tasks remain.
  4. Mapping-error candidates stay pending and are rerun after the restart.

This is the only test file for mp_tuner polling and recovery logic, and the old tests asserted the behavior that this PR removes, so the change is not redundant. All other test classes in the file are unchanged.

jamesETsmith and others added 3 commits October 23, 2026 16:05
Signed-off-by: jamesETsmith <[email protected]>
Co-authored-by: Cursor <[email protected]>
Signed-off-by: jamesETsmith <[email protected]>
Co-authored-by: Cursor <[email protected]>
Signed-off-by: jamesETsmith <[email protected]>
Co-authored-by: Cursor <[email protected]>
@jamesETsmith
jamesETsmith requested a review from a team October 23, 2026 23:30
@github-actions

Copy link
Copy Markdown
Contributor

🏷️ CI Guide

Runs automatically on every PR:

  • ✅ Pre-checks (submodule verification, code formatting)
  • ✅ Aiter op tests (gfx942 + gfx950)
  • ✅ Triton tests on MI35X (only when aiter/ops/triton/** or related paths are changed)

Extended tests (opt-in via labels):

Label Tests
ci:gfx1250-ffm-triton Run the five-shard gfx1250 FFM Triton test suite
ci:triton-300x Run an additional Triton test job on MI300X in PRs (added automatically when gfx942 configs change); main branch always runs both MI35X and MI300X
ci:triton-355 Run the full Triton test suite on MI35X, not only the tests the change affects
ci:windows Windows JIT op smoke test on the gfx1201 ROCm runner
ci:multi-gpu Aiter multi-GPU tests on the 8-GPU runner
ci:sglang SGLang integration tests: DeepSeek-R1-MXFP4 accuracy, Qwen 3.5 accuracy
ci:atom ATOM benchmark: DeepSeek-R1-0528, GPT-OSS-120B
ci:atom_full ATOM accuracy suite for PR and main models from ATOM models_accuracy.json
ci:vllm vLLM benchmark: DeepSeek-V4-Pro, MiniMax-M3-MXFP4
ci:all All standard extended tests (excludes ci:atom_full)

Only add ci:atom_full for FlyDSL or Triton upgrades.
Add labels via the sidebar or gh pr edit 6895 --add-label <label>

One backend per PR:
A PR changes one kernel backend: [Triton/Gluon] (Triton and Gluon count as one), [HIP], [ASM], [CK], [OPUS] or [FlyDSL]. If the title ends up with two backend tags, split the PR -- as stacked pull requests when one part cannot merge without the other.

PR title tags & labels:
Component tags ([Triton/Gluon], [HIP], [CK], [ASM], ...) are added to the PR title and as PR labels automatically from the changed files and re-synced on every push — change-type tags like [fix]/[Perf], op tags like [MLA], and human labels (ci:*) are left untouched. Add the no-auto-title label to stop the title rewrites; labels stay in sync either way.

Signed-off-by: jamesETsmith <[email protected]>
Co-authored-by: Cursor <[email protected]>
@yzhou103

Copy link
Copy Markdown
Contributor

Thanks for pointing this problem. The mapping error is a symptom of a stale PID map, not the root failure. Restarting immediately can prevent the actual hung/crashed tasks from being processed.

I reproduced this with a real BF16 tune using --mp 2, with one stale PID mapping and one hung task:

Mapping Error Task 0 -> restart, remaining=4
Mapping Error Task 0 -> restart, remaining=4
Mapping Error Task 0 -> restart, remaining=4
Because polling breaks at Task 0, the hung Task 1 is never reached and never handled by the timeout path. The tuner repeatedly restarts without making progress. The default timeout does not help because the mapping error always causes an earlier break.

Mapping-error tasks should remain pending while polling continues, allowing timeout, worker-exit, or accelerator-error handling to identify the root failure:

mapping_error_tasks = set()
if is_mapping_error:
mapping_error_tasks.add(k)
# Do not restart or break here.
To avoid the existing tail livelock when no other task can trigger recovery, restart only when every remaining task has encountered a mapping error:

if remaining_tasks and all(
k in mapping_error_tasks for k, _ in remaining_tasks
):
pool_restart_needed = True
Clear mapping_error_tasks after rebuilding the pool.

With this behavior, the same reproduction reaches the hung task, marks it timed out, and restarts with fewer remaining tasks instead of repeatedly restarting with the same task set.

Please also add tests covering:

A mapping error does not interrupt another running task.
mapping error -> hung/timeout task processes the timeout before restarting.
The pool restarts when only mapping-error tasks remain.
Mapping-error candidates remain pending and are rerun after the restart.

Comment thread aiter/utility/mp_tuner.py Resolved
Comment thread aiter/test_common.py Resolved
Keep mapping-error tasks pending while polling other workers so the underlying timeout or accelerator failure can be observed. Restart once only stale mappings remain, and remove the CUDA-event environment override per review feedback.

Co-authored-by: Cursor <[email protected]>
Signed-off-by: jamesETsmith <[email protected]>
@jamesETsmith
jamesETsmith force-pushed the feature/tuner-event-pid-recovery branch from cbd785c to 502ad57 Compare October 26, 2026 15:52
@jamesETsmith

Copy link
Copy Markdown
Contributor Author

@yzhou103 thanks for the comments!

I've implemented your suggestions to 1) remove the cuda-event timing features I added earlier and 2) switching the behavior to continue runs after a mapping error to prevent the hang.

I've also added new tests to cover the cases you mentioned in your comments. Let me know what you think!

@jamesETsmith

Copy link
Copy Markdown
Contributor Author

@yzhou103 anything else I should do here?

@aiter-bot

aiter-bot commented Nov 6, 2026 •

Copy link
Copy Markdown

WAITING ON AUTHOR

PR Self-Review

Revision 3fd3dd3f5454 · mode shadow

Waiting for the PR author. The readiness report will appear after the self-review answers are complete for this revision.

Questions to answer in the PR description

  1. What behavior does this PR change, and why is the existing behavior insufficient?
  2. What did you validate, and what remains unverified? Include commands, hardware/configuration and results.
  3. What behavior would each changed op test fail on before this PR, and why is that coverage not already provided by an existing canonical test?
  4. For every changed op_tests/ file, what behavior does it cover and why is it not redundant? Write None if no op test changed.

Edit the PR Self-Review section in the PR description. Include the current revision SHA; this comment refreshes automatically.

Missing or invalid answers

  • FAIL — Reviewed revision must contain at least the first 7 characters of the current head SHA

Shadow mode reports what would block but keeps the status successful. Set AITER_PR_SELF_REVIEW_MODE=enforce only after reviewing real false positives.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants