Skip to content

[Runtime][Disco] Fix session attribute storage, NVSHMEM build, and test gating - #19736

Merged
tqchen merged 1 commit into
apache:mainfrom
tlopex:fix-disco-wheel-tests
Jun 12, 2026
Merged

tqchen merged 1 commit into
apache:mainfrom
tlopex:fix-disco-wheel-tests

Conversation

@tlopex

@tlopex tlopex commented Jun 11, 2026 •

Copy link
Copy Markdown
Member

The tvm_ffi Object metaclass now gives every subclass __slots__ = (), so the Disco Python wrappers can no longer store instance attributes and every session construction fails with AttributeError. Declare the attributes each
wrapper actually stores as named slots, fix the NVSHMEM dist_gemm.cu so TVM builds with USE_NVSHMEM = ON, and gate the disco tests on the disco runtime being present so they skip cleanly on builds (e.g. the pip wheel) that report USE_NCCL / USE_NVSHMEM = ON without shipping it.

Session attribute storage

  • DPackedFunc / DModule: __slots__ = ("session",).
  • Session: __slots__ = ("_cache", "_import_python_module")

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request refactors and improves the robustness of the Disco distributed runtime tests. Key changes include adding __slots__ = ("__dict__",) to several Disco classes to allow dynamic Python-side attributes, introducing a centralized SocketSessionTester utility to manage socket sessions and remote nodes, and refactoring NVSHMEM tests to run in fresh processes to prevent undefined behavior from repeated initializations. Feedback on these changes highlights potential hang risks in the new SocketSessionTester implementation, specifically recommending configuring the server thread as a daemon and adding a timeout to thread.join() to prevent indefinite blocking in CI environments.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment thread python/tvm/testing/disco.py Outdated
Comment thread python/tvm/testing/disco.py Outdated
Comment thread python/tvm/runtime/disco/session.py Outdated
Comment thread python/tvm/runtime/disco/session.py Outdated
@tlopex
tlopex force-pushed the fix-disco-wheel-tests branch 4 times, most recently from 147bea9 to ea9a9f6 Compare June 12, 2026 04:50
@tlopex tlopex changed the title [Runtime][Disco] Fix Disco session attribute storage and test gating [Runtime][Disco] Fix session attribute storage and gate tests on runtime Jun 12, 2026
@tlopex
tlopex force-pushed the fix-disco-wheel-tests branch from ea9a9f6 to f54f538 Compare June 12, 2026 05:01
@tlopex tlopex changed the title [Runtime][Disco] Fix session attribute storage and gate tests on runtime [Runtime][Disco] Fix session attribute storage, NVSHMEM build, and test gating Jun 12, 2026
…st gating

The tvm_ffi Object metaclass now gives every subclass `__slots__ = ()`, so
the Disco Python wrappers can no longer store instance attributes and every
session construction fails with AttributeError. Declare the attributes each
wrapper actually stores as named slots, fix the NVSHMEM dist_gemm.cu so TVM
builds with USE_NVSHMEM = ON, and gate the disco tests on the disco runtime
being present so they skip cleanly on builds (e.g. the pip wheel) that report
USE_NCCL / USE_NVSHMEM = ON without shipping it.

Session attribute storage
- DPackedFunc / DModule: `__slots__ = ("session",)`.
- Session: `__slots__ = ("_cache", "_import_python_module")`, and look up
  the cache slot with `hasattr` instead of reading `self.__dict__`.

NVSHMEM build
- src/runtime/extra/contrib/nvshmem/dist_gemm.cu failed to compile under
  USE_NVSHMEM = ON after the tvm-ffi migration: `GetDataSize` now lives in
  namespace tvm::ffi, and the `LOG(FATAL)` macros are no longer in scope.
  Qualify the call as `ffi::GetDataSize` and replace the
  `if (worker == nullptr) LOG(FATAL) << ...` checks with
  `TVM_FFI_ICHECK(worker != nullptr) << ...` (the idiom already used in this
  file; it throws ffi::Error, so the behavior is unchanged). No logic change.

Test gating
- Add a `tvm.testing.requires_nvshmem` feature that probes the
  `runtime.disco.nvshmem.init_nvshmem_uid` runtime function rather than the
  cmake flag (a flag can be ON in a build that does not ship the runtime).
- test_session.py / test_nvshmem.py: skip at module level when the disco
  runtime is absent (`tvm.runtime.disco is None`), so the socket-session
  helpers they define are never reached and the modules skip cleanly instead
  of erroring at collection.
- test_loader.py: skip at module level unless `runtime.disco.compiled_ccl`
  reports "nccl" (the same source of truth as test_ccl.py), and require two
  GPUs via tvm.testing.requires_multi_gpu.
- test_nvshmem.py: gate every test on NVSHMEM support and on the machine
  having one CUDA device per worker; run each body in a freshly spawned
  process with a timeout, because nvshmem_init may run only once per process
  and disco worker-0 lives in the test process (pytest previously ran all
  bodies in one process); replace the hand-rolled __main__ matrix with
  tvm.testing.main().
@tlopex
tlopex force-pushed the fix-disco-wheel-tests branch from f54f538 to 7f5c3bd Compare June 12, 2026 05:05
@tlopex
tlopex requested a review from tqchen June 12, 2026 05:07
@tqchen
tqchen merged commit b57d0b3 into apache:main Jun 12, 2026
9 of 10 checks passed
MasterJH5574 pushed a commit to MasterJH5574/tvm that referenced this pull request Jun 15, 2026
…st gating (apache#19736)

The tvm_ffi Object metaclass now gives every subclass `__slots__ = ()`,
so the Disco Python wrappers can no longer store instance attributes and
every session construction fails with AttributeError. Declare the
attributes each
wrapper actually stores as named slots, fix the NVSHMEM `dist_gemm.cu`
so TVM builds with `USE_NVSHMEM = ON`, and gate the disco tests on the
disco runtime being present so they skip cleanly on builds (e.g. the pip
wheel) that report `USE_NCCL` / `USE_NVSHMEM = ON` without shipping it.

### Session attribute storage
- `DPackedFunc` / `DModule`: `__slots__ = ("session",)`.
- `Session`: `__slots__ = ("_cache", "_import_python_module")`

(cherry picked from commit b57d0b3)
MasterJH5574 pushed a commit to MasterJH5574/tvm that referenced this pull request Jun 15, 2026
…st gating (apache#19736)

The tvm_ffi Object metaclass now gives every subclass `__slots__ = ()`,
so the Disco Python wrappers can no longer store instance attributes and
every session construction fails with AttributeError. Declare the
attributes each
wrapper actually stores as named slots, fix the NVSHMEM `dist_gemm.cu`
so TVM builds with `USE_NVSHMEM = ON`, and gate the disco tests on the
disco runtime being present so they skip cleanly on builds (e.g. the pip
wheel) that report `USE_NCCL` / `USE_NVSHMEM = ON` without shipping it.

### Session attribute storage
- `DPackedFunc` / `DModule`: `__slots__ = ("session",)`.
- `Session`: `__slots__ = ("_cache", "_import_python_module")`

(cherry picked from commit b57d0b3)
tqchen pushed a commit that referenced this pull request Oct 16, 2026
…st gating (#19736)

The tvm_ffi Object metaclass now gives every subclass `__slots__ = ()`,
so the Disco Python wrappers can no longer store instance attributes and
every session construction fails with AttributeError. Declare the
attributes each
wrapper actually stores as named slots, fix the NVSHMEM `dist_gemm.cu`
so TVM builds with `USE_NVSHMEM = ON`, and gate the disco tests on the
disco runtime being present so they skip cleanly on builds (e.g. the pip
wheel) that report `USE_NCCL` / `USE_NVSHMEM = ON` without shipping it.

### Session attribute storage
- `DPackedFunc` / `DModule`: `__slots__ = ("session",)`.
- `Session`: `__slots__ = ("_cache", "_import_python_module")`
tqchen pushed a commit that referenced this pull request Oct 18, 2026
…st gating (#19736)

The tvm_ffi Object metaclass now gives every subclass `__slots__ = ()`,
so the Disco Python wrappers can no longer store instance attributes and
every session construction fails with AttributeError. Declare the
attributes each
wrapper actually stores as named slots, fix the NVSHMEM `dist_gemm.cu`
so TVM builds with `USE_NVSHMEM = ON`, and gate the disco tests on the
disco runtime being present so they skip cleanly on builds (e.g. the pip
wheel) that report `USE_NCCL` / `USE_NVSHMEM = ON` without shipping it.

### Session attribute storage
- `DPackedFunc` / `DModule`: `__slots__ = ("session",)`.
- `Session`: `__slots__ = ("_cache", "_import_python_module")`
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