Skip to content

refactor(tensor_bus): PairState/BatchState are dataclasses, not Structs#108

Merged
junjzhang merged 2 commits into
mainfrom
refactor/dataclass-runtime-state
May 29, 2026
Merged

refactor(tensor_bus): PairState/BatchState are dataclasses, not Structs#108
junjzhang merged 2 commits into
mainfrom
refactor/dataclass-runtime-state

Conversation

@junjzhang
Copy link
Copy Markdown
Contributor

@junjzhang junjzhang commented May 29, 2026

What did you do

Follow-up to #106. PairState and BatchState subclassed msgspec.Struct, but both hold live ProcessGroup handles, torch.Tensors and Buckets carrying CUDA work. They never cross a process boundary and can never be msgspec-encoded — the Struct base falsely signalled serializability.

Across the codebase, the only genuine serialization boundary is Message (the Host↔Agent command wire format, command_queue.py). Query/status flows transmit only scalars ("matched", bool) the Agent projects out of its in-memory state — never the state objects themselves. The pure-data comm IR (Endpoint/Route/M2MMap) is genuinely serializable and stays msgspec.Struct.

This PR:

  • converts the two runtime-state holders to plain @dataclass(kw_only=True) and fixes their docstrings (kw_only guards the many no-default fields against positional mistakes; all construction sites already pass kwargs; no behavior change). slots deliberately omitted — unlike the hot-path Chunk/Bucket, these are a handful of long-lived instances with no memory payoff.
  • drops the get_or_create_process_group re-export shim from comm.utils; importers now pull it directly from etha.pg_utils.

New test cases

None — pure type/import refactor, no new feature or bug. Covered by the existing 3-layer verification for no behavioral regression.

Test results

  • CPU unit tests: ✅ 55 passed
  • vLLM weight-sync end-to-end: ✅ 3/3 rounds, no agent errors
  • Transfer benchmark (GPU/NCCL): ✅ bucket 319–327 GB/s (baseline ~319, no regression)

Other comments

The msgspec.Struct base is now reserved for things that actually go on the wire.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 29, 2026

Warning

Review limit reached

@junjzhang, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 15 minutes and 16 seconds. Learn how PR review limits work.

Your organization has run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: a6134f99-6435-44fb-8f4f-c280ff7ff88c

📥 Commits

Reviewing files that changed from the base of the PR and between a40ce15 and 653a9d0.

📒 Files selected for processing (5)
  • src/etha/comm/get_chunks.py
  • src/etha/comm/transfer.py
  • src/etha/comm/utils.py
  • src/etha/tensor_bus/batch_state.py
  • src/etha/tensor_bus/pair_state.py
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch refactor/dataclass-runtime-state

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions
Copy link
Copy Markdown

Failed to generate code suggestions for PR

@junjzhang
Copy link
Copy Markdown
Contributor Author

@codex reivew

@chatgpt-codex-connector
Copy link
Copy Markdown

To use Codex here, create an environment for this repo.

junjzhang added 2 commits May 29, 2026 22:43
Both hold live process-group handles, tensors and CUDA work; they never
cross a process boundary and can never be msgspec-encoded. The Struct base
falsely signalled serializability. Only Message (the Host<->Agent command
wire format) and the pure-data comm IR genuinely need msgspec.

Use kw_only=True (all construction sites already pass kwargs) to guard the
many no-default fields against positional mistakes.
comm.utils re-exported it from etha.pg_utils purely for backward compat.
Import it directly where used (transfer.py, get_chunks.py).
@junjzhang junjzhang force-pushed the refactor/dataclass-runtime-state branch from 50df11a to 653a9d0 Compare May 29, 2026 14:44
@junjzhang junjzhang merged commit efed75e into main May 29, 2026
4 checks passed
@junjzhang junjzhang deleted the refactor/dataclass-runtime-state branch May 29, 2026 14:50
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