Skip to content

Tests: start every diffusion_segment test with no GPU arbiter resident - #14271

Merged
danielhanchen merged 3 commits into
mainfrom
fix/segment-tests-clean-arbiter
Oct 19, 2026
Merged

danielhanchen merged 3 commits into
mainfrom
fix/segment-tests-clean-arbiter

Conversation

@danielhanchen

Copy link
Copy Markdown
Member

Summary

Two tests in studio/backend/tests/test_diffusion_segment.py fail in the (Python 3.13, a-k) shard on PRs with different bases (#14229, #14245):

test_choose_device_needs_room_on_the_card
test_choose_device_reads_bf16_on_the_chosen_card
E   AssertionError: assert ('cpu', torch.float32) == ('cuda:1', torch.bfloat16)

Both pass when the file runs on its own (64 passed).

Cause

choose_device() (from #14235, SAM 3 masks) puts SAM 3 on the CPU when another GPU arbiter owner holds the card (_other_owner_on -> gpu_arbiter.residents()). The arbiter's _owner / _residents are module globals. These two tests stub torch and the free-memory probe but not the arbiter. So when an earlier test in the same xdist worker leaves a CHAT owner behind, they see the card as taken and pick the CPU. The product is right to refuse a card another owner holds. The tests were order dependent.

Change

Test-only: an autouse fixture in test_diffusion_segment.py clears gpu_arbiter._owner and _residents before each test (with monkeypatch, so they are restored). Tests that exercise ownership already set their own owner, and still do.

Testing

  • test_diffusion_segment.py: 64 passed.
  • Sabotage: I added a throwaway test that sets gpu_arbiter._owner = gpu_arbiter.CHAT and ran it first in the same process:
    • Without the fixture: test_choose_device_needs_room_on_the_card and test_choose_device_reads_bf16_on_the_chosen_card fail. These are the two CI failures.
    • With it: all pass.

choose_device() runs SAM 3 on the CPU when another owner holds the card,
and the arbiter's owner state is module-global. A test elsewhere in the
same xdist worker that leaves a CHAT owner behind turned
test_choose_device_needs_room_on_the_card and
test_choose_device_reads_bf16_on_the_chosen_card into ('cpu', float32) in
the (Python 3.13, a-k) shard. An autouse fixture clears _owner and
_residents; tests that need an owner still set one.
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 19, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-19T15:52:46.620622Z d7cd4c7 Manual request
🔒 Security Review ⚠️ Failed 2026-10-19T15:25:34.455329Z 74bafdb PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Keep it up!

Reviewed commit: 74bafdb993

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: adb5d87f48

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +32 to +33
monkeypatch.setattr(gpu_arbiter, "_owner", None)
monkeypatch.setattr(gpu_arbiter, "_residents", {})

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Restore the arbiter's complete state

When a worker enters this module with an existing arbiter claim, this fixture saves and restores only _owner and _residents, while later tests in this file call the real acquire_for(), which mutates correlated globals such as _owner_account, _prior_account, _owner_epoch, _accounts, and _media_needs. Teardown can therefore reattach the saved owner/residents to mutated account metadata, so subsequent tests in the same xdist worker may observe the wrong owning account and remain order-dependent; isolate all correlated arbiter fields together or clear the state without partially restoring it.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed, fixed in the next commit. The fixture now swaps every correlated arbiter global together: _owner, _owner_account, _prior_account, _residents, _accounts and _media_needs are emptied, and _owner_epoch and _handovers are pinned to their current values, all through monkeypatch. Each test therefore starts unclaimed, and whatever acquire_for() changes is put back as one set afterwards.

Checked with a throwaway test before this file that leaves ("chat", "acct-x") claimed, and one after it that asserts the claim comes back unchanged (owner, account, prior account, residents, accounts, media needs): 66 passed. The file alone: 64 passed.

@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Swish!

Reviewed commit: d7cd4c78b2

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@danielhanchen
danielhanchen merged commit e680e30 into main Oct 19, 2026
@danielhanchen
danielhanchen deleted the fix/segment-tests-clean-arbiter branch October 19, 2026 15:57
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.

1 participant