Skip to content

test(moe): realign expert batching with the causal replay pass - #3795

Merged
Qubitium merged 1 commit into
ModelCloud:mainfrom
Lumea-art:test/fix-moe-batching-fixture
Nov 12, 2026
Merged

Qubitium merged 1 commit into
ModelCloud:mainfrom
Lumea-art:test/fix-moe-batching-fixture

Conversation

@Lumea-art

Copy link
Copy Markdown
Contributor

Summary

Eight of the nine tests in tests/test_moe_expert_batching.py fail on main. Two changes since the file was last touched (#3572) moved the ground it stands on.

1. The mocked processor now satisfies a hook that skips the forward pass.

_run_single_subset_pass asks the processor whether a captured forward frontier can be restored:

restore_capture = getattr(processor, "restore_subset_capture_frontier", None)
if (execute_forward and not plan.need_forward_outputs
        and not execution_config.capture_layer_forward_context
        and callable(restore_capture)):
    if bool(restore_capture(...)):
        execute_forward = False

A MagicMock() processor auto-creates that attribute, so callable(...) is true and the mock's return value is truthy - the forward pass every assertion is about is skipped. A real processor without the hook returns None. The fixture now says so explicitly for both restore hooks added in #3600.

2. #3600 added a causal replay pass.

With execution_config.fwd_replay_after_process set (as it is in this fixture's setUp), each chunk runs one capture forward and one replay forward, so _run_forward_batches is called twice per chunk instead of once.

The expectations were doubled and the comments explain why, rather than carrying a different number. The flush counts are unchanged: the replay pass does not call torch_empty_cache.

Result

before:  8 failed, 1 passed
after:   9 passed

Nothing in the product code changes; this only restores the coverage that #3600 silently turned off.

Not covered

tests/test_subset_plan.py and tests/test_stage_modules.py dump core on this machine, before and after this change (verified by stashing it). That looks environmental and is not addressed here.

All but one test in this file fail on main. Two changes since the file was last
touched (ModelCloud#3572) moved the ground it stands on.

The mocked processor auto-creates attributes, so the capture-frontier restore
hook added in ModelCloud#3600 looks callable and returns a truthy mock, which makes
`_run_single_subset_pass` skip the forward pass every assertion is about. A real
processor without that hook returns None, so the fixture now says so explicitly.

ModelCloud#3600 also added a causal replay pass: with
`execution_config.fwd_replay_after_process` set, each chunk runs one capture
forward and one replay forward, so `_run_forward_batches` is called twice per
chunk instead of once. The expectations were doubled and the comments now say
why, instead of just carrying a different number. The flush counts are unchanged:
the replay pass does not call `torch_empty_cache`.

    tests/test_moe_expert_batching.py    9 passed

Before this change the file reported 8 failed, 1 passed on main.

Copy link
Copy Markdown
Collaborator

Review: the fixture now disables both auto-created capture restore hooks on MagicMock, so the intended forward path is exercised. The doubled forward expectations match capture plus causal replay, and the cache flush counts remain unchanged. I found no further issues. Verified with /root/venv/bin/python -m pytest -q tests/test_moe_expert_batching.py (9 passed).

@Qubitium
Qubitium merged commit cff4285 into ModelCloud:main Nov 12, 2026
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.

2 participants