Skip to content

Add isInitialized() API to TorchCommBackend and update TorchCommMCCL::reconfigure initialization state (#2071)#2071

Open
Scusemua wants to merge 1 commit intometa-pytorch:mainfrom
Scusemua:export-D100673963
Open

Add isInitialized() API to TorchCommBackend and update TorchCommMCCL::reconfigure initialization state (#2071)#2071
Scusemua wants to merge 1 commit intometa-pytorch:mainfrom
Scusemua:export-D100673963

Conversation

@Scusemua
Copy link
Copy Markdown
Contributor

@Scusemua Scusemua commented Apr 14, 2026

Summary:

Add isInitialized() virtual method to TorchCommBackend so callers can check whether a backend is ready for collective operations before issuing them. The MCCL implementation now correctly ties initialization state to a successful reconfigure() result rather than unconditionally marking itself initialized, preventing use of a backend whose reconfigure failed.

Specifically, we now set initState_ = UNINITIALIZED before calling mccl_comm_->reconfigure(), then only promote to INITIALIZED inside the existing success block (where result->code == commSuccess) alongside rank_ and commSize_ updates. Previously initState_ = INITIALIZED was set unconditionally after createWork(), which allowed subsequent operations to proceed on a broken communicator after a failed reconfigure.

Differential Revision: D100673963

@meta-cla meta-cla bot added the CLA Signed This label is managed by the Meta Open Source bot. label Apr 14, 2026
@meta-codesync
Copy link
Copy Markdown
Contributor

meta-codesync bot commented Apr 14, 2026

@Scusemua has exported this pull request. If you are a Meta employee, you can view the originating Diff in D100673963.

Scusemua added a commit to Scusemua/torchcomms that referenced this pull request Apr 14, 2026
…:reconfigure initialization state (meta-pytorch#2071)

Summary:

Add `isInitialized()` virtual method to `TorchCommBackend` so callers can check whether a backend is ready for collective operations before issuing them. The MCCL implementation now correctly ties initialization state to a successful `reconfigure()` result rather than unconditionally marking itself initialized, preventing use of a backend whose reconfigure failed.

Specifically, we now set `initState_ = UNINITIALIZED` before calling `mccl_comm_->reconfigure()`, then only promote to `INITIALIZED` inside the existing success block (where `result->code == commSuccess`) alongside `rank_` and `commSize_` updates. Previously `initState_ = INITIALIZED` was set unconditionally after `createWork()`, which allowed subsequent operations to proceed on a broken communicator after a failed reconfigure.

Differential Revision: D100673963
@meta-codesync meta-codesync bot changed the title Add isInitialized() API to TorchCommBackend and update TorchCommMCCL::reconfigure initialization state Add isInitialized() API to TorchCommBackend and update TorchCommMCCL::reconfigure initialization state (#2071) Apr 14, 2026
Scusemua added a commit to Scusemua/torchcomms that referenced this pull request Apr 14, 2026
…:reconfigure initialization state (meta-pytorch#2071)

Summary:

Add `isInitialized()` virtual method to `TorchCommBackend` so callers can check whether a backend is ready for collective operations before issuing them. The MCCL implementation now correctly ties initialization state to a successful `reconfigure()` result rather than unconditionally marking itself initialized, preventing use of a backend whose reconfigure failed.

Specifically, we now set `initState_ = UNINITIALIZED` before calling `mccl_comm_->reconfigure()`, then only promote to `INITIALIZED` inside the existing success block (where `result->code == commSuccess`) alongside `rank_` and `commSize_` updates. Previously `initState_ = INITIALIZED` was set unconditionally after `createWork()`, which allowed subsequent operations to proceed on a broken communicator after a failed reconfigure.

Differential Revision: D100673963
@Scusemua Scusemua force-pushed the export-D100673963 branch from 231c3d6 to 591b242 Compare April 14, 2026 20:28
Scusemua added a commit to Scusemua/torchcomms that referenced this pull request Apr 14, 2026
…:reconfigure initialization state (meta-pytorch#2071)

Summary:

Add `isInitialized()` virtual method to `TorchCommBackend` so callers can check whether a backend is ready for collective operations before issuing them. The MCCL implementation now correctly ties initialization state to a successful `reconfigure()` result rather than unconditionally marking itself initialized, preventing use of a backend whose reconfigure failed.

Specifically, we now set `initState_ = UNINITIALIZED` before calling `mccl_comm_->reconfigure()`, then only promote to `INITIALIZED` inside the existing success block (where `result->code == commSuccess`) alongside `rank_` and `commSize_` updates. Previously `initState_ = INITIALIZED` was set unconditionally after `createWork()`, which allowed subsequent operations to proceed on a broken communicator after a failed reconfigure.

Differential Revision: D100673963
…:reconfigure initialization state (meta-pytorch#2071)

Summary:
Pull Request resolved: meta-pytorch#2071

Add `isInitialized()` virtual method to `TorchCommBackend` so callers can check whether a backend is ready for collective operations before issuing them. The MCCL implementation now correctly ties initialization state to a successful `reconfigure()` result rather than unconditionally marking itself initialized, preventing use of a backend whose reconfigure failed.

Specifically, we now set `initState_ = UNINITIALIZED` before calling `mccl_comm_->reconfigure()`, then only promote to `INITIALIZED` inside the existing success block (where `result->code == commSuccess`) alongside `rank_` and `commSize_` updates. Previously `initState_ = INITIALIZED` was set unconditionally after `createWork()`, which allowed subsequent operations to proceed on a broken communicator after a failed reconfigure.

Differential Revision: D100673963
@Scusemua Scusemua force-pushed the export-D100673963 branch from 591b242 to 8bc6040 Compare April 14, 2026 20:31
Scusemua pushed a commit to Scusemua/torchcomms that referenced this pull request Apr 14, 2026
…:reconfigure initialization state (meta-pytorch#2071)

Summary:
Pull Request resolved: meta-pytorch#2071

Add `isInitialized()` virtual method to `TorchCommBackend` so callers can check whether a backend is ready for collective operations before issuing them. The MCCL implementation now correctly ties initialization state to a successful `reconfigure()` result rather than unconditionally marking itself initialized, preventing use of a backend whose reconfigure failed.

Specifically, we now set `initState_ = UNINITIALIZED` before calling `mccl_comm_->reconfigure()`, then only promote to `INITIALIZED` inside the existing success block (where `result->code == commSuccess`) alongside `rank_` and `commSize_` updates. Previously `initState_ = INITIALIZED` was set unconditionally after `createWork()`, which allowed subsequent operations to proceed on a broken communicator after a failed reconfigure.

Differential Revision: D100673963
Scusemua added a commit to Scusemua/torchcomms that referenced this pull request Apr 14, 2026
…:reconfigure initialization state (meta-pytorch#2071)

Summary:

Add `isInitialized()` virtual method to `TorchCommBackend` so callers can check whether a backend is ready for collective operations before issuing them. The MCCL implementation now correctly ties initialization state to a successful `reconfigure()` result rather than unconditionally marking itself initialized, preventing use of a backend whose reconfigure failed.

Specifically, we now set `initState_ = UNINITIALIZED` before calling `mccl_comm_->reconfigure()`, then only promote to `INITIALIZED` inside the existing success block (where `result->code == commSuccess`) alongside `rank_` and `commSize_` updates. Previously `initState_ = INITIALIZED` was set unconditionally after `createWork()`, which allowed subsequent operations to proceed on a broken communicator after a failed reconfigure.

Differential Revision: D100673963
Scusemua pushed a commit to Scusemua/torchcomms that referenced this pull request Apr 14, 2026
…:reconfigure initialization state (meta-pytorch#2071)

Summary:
Pull Request resolved: meta-pytorch#2071

Add `isInitialized()` virtual method to `TorchCommBackend` so callers can check whether a backend is ready for collective operations before issuing them. The MCCL implementation now correctly ties initialization state to a successful `reconfigure()` result rather than unconditionally marking itself initialized, preventing use of a backend whose reconfigure failed.

Specifically, we now set `initState_ = UNINITIALIZED` before calling `mccl_comm_->reconfigure()`, then only promote to `INITIALIZED` inside the existing success block (where `result->code == commSuccess`) alongside `rank_` and `commSize_` updates. Previously `initState_ = INITIALIZED` was set unconditionally after `createWork()`, which allowed subsequent operations to proceed on a broken communicator after a failed reconfigure.

Differential Revision: D100673963
Scusemua added a commit to Scusemua/torchcomms that referenced this pull request Apr 15, 2026
…:reconfigure initialization state (meta-pytorch#2071)

Summary:

Add `isInitialized()` virtual method to `TorchCommBackend` so callers can check whether a backend is ready for collective operations before issuing them. The MCCL implementation now correctly ties initialization state to a successful `reconfigure()` result rather than unconditionally marking itself initialized, preventing use of a backend whose reconfigure failed.

Specifically, we now set `initState_ = UNINITIALIZED` before calling `mccl_comm_->reconfigure()`, then only promote to `INITIALIZED` inside the existing success block (where `result->code == commSuccess`) alongside `rank_` and `commSize_` updates. Previously `initState_ = INITIALIZED` was set unconditionally after `createWork()`, which allowed subsequent operations to proceed on a broken communicator after a failed reconfigure.

**We also** reset `commSize_` to 0 instead of -1, and we move the reset of `commSize_` and `rank_` to be with the `initState_ = UNITIALIZED`. For one thing, -1 (as an int) silently becomes `SIZE_MAX` when cast to `size_t`, which caused a production SEV once already. And if `commSize_` ever leaks beyond these guards, then 0 is harmless, while -1 is catastrophic (can crash the workload/application). 

**Concession:** 0 is more of a soft sentinel insofar as it is a valid communicator size, and so you cannot distinguish "uninitialized" from "genuinely zero participants" by looking at `commSize_` alone. But you can just look at `initState_` for this.

Differential Revision: D100673963
Scusemua pushed a commit to Scusemua/torchcomms that referenced this pull request Apr 15, 2026
…:reconfigure initialization state (meta-pytorch#2071)

Summary:
Pull Request resolved: meta-pytorch#2071

Add `isInitialized()` virtual method to `TorchCommBackend` so callers can check whether a backend is ready for collective operations before issuing them. The MCCL implementation now correctly ties initialization state to a successful `reconfigure()` result rather than unconditionally marking itself initialized, preventing use of a backend whose reconfigure failed.

Specifically, we now set `initState_ = UNINITIALIZED` before calling `mccl_comm_->reconfigure()`, then only promote to `INITIALIZED` inside the existing success block (where `result->code == commSuccess`) alongside `rank_` and `commSize_` updates. Previously `initState_ = INITIALIZED` was set unconditionally after `createWork()`, which allowed subsequent operations to proceed on a broken communicator after a failed reconfigure.

**We also** reset `commSize_` to 0 instead of -1, and we move the reset of `commSize_` and `rank_` to be with the `initState_ = UNITIALIZED`. For one thing, -1 (as an int) silently becomes `SIZE_MAX` when cast to `size_t`, which caused a production SEV once already. And if `commSize_` ever leaks beyond these guards, then 0 is harmless, while -1 is catastrophic (can crash the workload/application).

**Concession:** 0 is more of a soft sentinel insofar as it is a valid communicator size, and so you cannot distinguish "uninitialized" from "genuinely zero participants" by looking at `commSize_` alone. But you can just look at `initState_` for this.

Differential Revision: D100673963
Scusemua added a commit to Scusemua/torchcomms that referenced this pull request Apr 15, 2026
…:reconfigure initialization state (meta-pytorch#2071)

Summary:

Add `isInitialized()` virtual method to `TorchCommBackend` so callers can check whether a backend is ready for collective operations before issuing them. The MCCL implementation now correctly ties initialization state to a successful `reconfigure()` result rather than unconditionally marking itself initialized, preventing use of a backend whose reconfigure failed.

Specifically, we now set `initState_ = UNINITIALIZED` before calling `mccl_comm_->reconfigure()`, then only promote to `INITIALIZED` inside the existing success block (where `result->code == commSuccess`) alongside `rank_` and `commSize_` updates. Previously `initState_ = INITIALIZED` was set unconditionally after `createWork()`, which allowed subsequent operations to proceed on a broken communicator after a failed reconfigure.

**We also** reset `commSize_` to 0 instead of -1, and we move the reset of `commSize_` and `rank_` to be with the `initState_ = UNITIALIZED`. For one thing, -1 (as an int) silently becomes `SIZE_MAX` when cast to `size_t`, which caused a production SEV once already. And if `commSize_` ever leaks beyond these guards, then 0 is harmless, while -1 is catastrophic (can crash the workload/application). 

**Concession:** 0 is more of a soft sentinel insofar as it is a valid communicator size, and so you cannot distinguish "uninitialized" from "genuinely zero participants" by looking at `commSize_` alone. But you can just look at `initState_` for this.

Differential Revision: D100673963
Scusemua pushed a commit to Scusemua/torchcomms that referenced this pull request Apr 15, 2026
…:reconfigure initialization state (meta-pytorch#2071)

Summary:
Pull Request resolved: meta-pytorch#2071

Add `isInitialized()` virtual method to `TorchCommBackend` so callers can check whether a backend is ready for collective operations before issuing them. The MCCL implementation now correctly ties initialization state to a successful `reconfigure()` result rather than unconditionally marking itself initialized, preventing use of a backend whose reconfigure failed.

Specifically, we now set `initState_ = UNINITIALIZED` before calling `mccl_comm_->reconfigure()`, then only promote to `INITIALIZED` inside the existing success block (where `result->code == commSuccess`) alongside `rank_` and `commSize_` updates. Previously `initState_ = INITIALIZED` was set unconditionally after `createWork()`, which allowed subsequent operations to proceed on a broken communicator after a failed reconfigure.

**We also** reset `commSize_` to 0 instead of -1, and we move the reset of `commSize_` and `rank_` to be with the `initState_ = UNITIALIZED`. For one thing, -1 (as an int) silently becomes `SIZE_MAX` when cast to `size_t`, which caused a production SEV once already. And if `commSize_` ever leaks beyond these guards, then 0 is harmless, while -1 is catastrophic (can crash the workload/application).

**Concession:** 0 is more of a soft sentinel insofar as it is a valid communicator size, and so you cannot distinguish "uninitialized" from "genuinely zero participants" by looking at `commSize_` alone. But you can just look at `initState_` for this.

Differential Revision: D100673963
Scusemua added a commit to Scusemua/torchcomms that referenced this pull request Apr 15, 2026
…:reconfigure initialization state (meta-pytorch#2071)

Summary:

Add `isInitialized()` virtual method to `TorchCommBackend` so callers can check whether a backend is ready for collective operations before issuing them. The MCCL implementation now correctly ties initialization state to a successful `reconfigure()` result rather than unconditionally marking itself initialized, preventing use of a backend whose reconfigure failed.

Specifically, we now set `initState_ = UNINITIALIZED` before calling `mccl_comm_->reconfigure()`, then only promote to `INITIALIZED` inside the existing success block (where `result->code == commSuccess`) alongside `rank_` and `commSize_` updates. Previously `initState_ = INITIALIZED` was set unconditionally after `createWork()`, which allowed subsequent operations to proceed on a broken communicator after a failed reconfigure.

**We also** reset `commSize_` to 0 instead of -1, and we move the reset of `commSize_` and `rank_` to be with the `initState_ = UNITIALIZED`. For one thing, -1 (as an int) silently becomes `SIZE_MAX` when cast to `size_t`, which caused a production SEV once already. And if `commSize_` ever leaks beyond these guards, then 0 is harmless, while -1 is catastrophic (can crash the workload/application). 

**Concession:** 0 is more of a soft sentinel insofar as it is a valid communicator size, and so you cannot distinguish "uninitialized" from "genuinely zero participants" by looking at `commSize_` alone. But you can just look at `initState_` for this.

Differential Revision: D100673963
Scusemua added a commit to Scusemua/torchcomms that referenced this pull request Apr 15, 2026
…:reconfigure initialization state (meta-pytorch#2071)

Summary:

Add `isInitialized()` virtual method to `TorchCommBackend` so callers can check whether a backend is ready for collective operations before issuing them. The MCCL implementation now correctly ties initialization state to a successful `reconfigure()` result rather than unconditionally marking itself initialized, preventing use of a backend whose reconfigure failed.

Specifically, we now set `initState_ = UNINITIALIZED` before calling `mccl_comm_->reconfigure()`, then only promote to `INITIALIZED` inside the existing success block (where `result->code == commSuccess`) alongside `rank_` and `commSize_` updates. Previously `initState_ = INITIALIZED` was set unconditionally after `createWork()`, which allowed subsequent operations to proceed on a broken communicator after a failed reconfigure.

**We also** reset `commSize_` to 0 instead of -1, and we move the reset of `commSize_` and `rank_` to be with the `initState_ = UNITIALIZED`. For one thing, -1 (as an int) silently becomes `SIZE_MAX` when cast to `size_t`, which caused a production SEV once already. And if `commSize_` ever leaks beyond these guards, then 0 is harmless, while -1 is catastrophic (can crash the workload/application). 

**Concession:** 0 is more of a soft sentinel insofar as it is a valid communicator size, and so you cannot distinguish "uninitialized" from "genuinely zero participants" by looking at `commSize_` alone. But you can just look at `initState_` for this.

Differential Revision: D100673963
Scusemua added a commit to Scusemua/torchcomms that referenced this pull request Apr 15, 2026
…:reconfigure initialization state (meta-pytorch#2071)

Summary:

Add `isInitialized()` virtual method to `TorchCommBackend` so callers can check whether a backend is ready for collective operations before issuing them. The MCCL implementation now correctly ties initialization state to a successful `reconfigure()` result rather than unconditionally marking itself initialized, preventing use of a backend whose reconfigure failed.

Specifically, we now set `initState_ = UNINITIALIZED` before calling `mccl_comm_->reconfigure()`, then only promote to `INITIALIZED` inside the existing success block (where `result->code == commSuccess`) alongside `rank_` and `commSize_` updates. Previously `initState_ = INITIALIZED` was set unconditionally after `createWork()`, which allowed subsequent operations to proceed on a broken communicator after a failed reconfigure.

**We also** reset `commSize_` to 0 instead of -1, and we move the reset of `commSize_` and `rank_` to be with the `initState_ = UNITIALIZED`. For one thing, -1 (as an int) silently becomes `SIZE_MAX` when cast to `size_t`, which caused a production SEV once already. And if `commSize_` ever leaks beyond these guards, then 0 is harmless, while -1 is catastrophic (can crash the workload/application). 

**Concession:** 0 is more of a soft sentinel insofar as it is a valid communicator size, and so you cannot distinguish "uninitialized" from "genuinely zero participants" by looking at `commSize_` alone. But you can just look at `initState_` for this.

Differential Revision: D100673963
Scusemua pushed a commit to Scusemua/torchcomms that referenced this pull request Apr 15, 2026
…:reconfigure initialization state (meta-pytorch#2071)

Summary:
Pull Request resolved: meta-pytorch#2071

Add `isInitialized()` virtual method to `TorchCommBackend` so callers can check whether a backend is ready for collective operations before issuing them. The MCCL implementation now correctly ties initialization state to a successful `reconfigure()` result rather than unconditionally marking itself initialized, preventing use of a backend whose reconfigure failed.

Specifically, we now set `initState_ = UNINITIALIZED` before calling `mccl_comm_->reconfigure()`, then only promote to `INITIALIZED` inside the existing success block (where `result->code == commSuccess`) alongside `rank_` and `commSize_` updates. Previously `initState_ = INITIALIZED` was set unconditionally after `createWork()`, which allowed subsequent operations to proceed on a broken communicator after a failed reconfigure.

**We also** reset `commSize_` to 0 instead of -1, and we move the reset of `commSize_` and `rank_` to be with the `initState_ = UNITIALIZED`. For one thing, -1 (as an int) silently becomes `SIZE_MAX` when cast to `size_t`, which caused a production SEV once already. And if `commSize_` ever leaks beyond these guards, then 0 is harmless, while -1 is catastrophic (can crash the workload/application).

**Concession:** 0 is more of a soft sentinel insofar as it is a valid communicator size, and so you cannot distinguish "uninitialized" from "genuinely zero participants" by looking at `commSize_` alone. But you can just look at `initState_` for this.

Differential Revision: D100673963
Scusemua added a commit to Scusemua/torchcomms that referenced this pull request Apr 15, 2026
…:reconfigure initialization state (meta-pytorch#2071)

Summary:

Add `isInitialized()` virtual method to `TorchCommBackend` so callers can check whether a backend is ready for collective operations before issuing them. The MCCL implementation now correctly ties initialization state to a successful `reconfigure()` result rather than unconditionally marking itself initialized, preventing use of a backend whose reconfigure failed.

Specifically, we now set `initState_ = UNINITIALIZED` before calling `mccl_comm_->reconfigure()`, then only promote to `INITIALIZED` inside the existing success block (where `result->code == commSuccess`) alongside `rank_` and `commSize_` updates. Previously `initState_ = INITIALIZED` was set unconditionally after `createWork()`, which allowed subsequent operations to proceed on a broken communicator after a failed reconfigure.

**We also** reset `commSize_` to 0 instead of -1, and we move the reset of `commSize_` and `rank_` to be with the `initState_ = UNITIALIZED`. For one thing, -1 (as an int) silently becomes `SIZE_MAX` when cast to `size_t`, which caused a production SEV once already. And if `commSize_` ever leaks beyond these guards, then 0 is harmless, while -1 is catastrophic (can crash the workload/application). 

**Concession:** 0 is more of a soft sentinel insofar as it is a valid communicator size, and so you cannot distinguish "uninitialized" from "genuinely zero participants" by looking at `commSize_` alone. But you can just look at `initState_` for this.

Differential Revision: D100673963
Scusemua added a commit to Scusemua/torchcomms that referenced this pull request Apr 15, 2026
…:reconfigure initialization state (meta-pytorch#2071)

Summary:

Add `isInitialized()` virtual method to `TorchCommBackend` so callers can check whether a backend is ready for collective operations before issuing them. The MCCL implementation now correctly ties initialization state to a successful `reconfigure()` result rather than unconditionally marking itself initialized, preventing use of a backend whose reconfigure failed.

Specifically, we now set `initState_ = UNINITIALIZED` before calling `mccl_comm_->reconfigure()`, then only promote to `INITIALIZED` inside the existing success block (where `result->code == commSuccess`) alongside `rank_` and `commSize_` updates. Previously `initState_ = INITIALIZED` was set unconditionally after `createWork()`, which allowed subsequent operations to proceed on a broken communicator after a failed reconfigure.

**We also** reset `commSize_` to 0 instead of -1, and we move the reset of `commSize_` and `rank_` to be with the `initState_ = UNITIALIZED`. For one thing, -1 (as an int) silently becomes `SIZE_MAX` when cast to `size_t`, which caused a production SEV once already. And if `commSize_` ever leaks beyond these guards, then 0 is harmless, while -1 is catastrophic (can crash the workload/application). 

**Concession:** 0 is more of a soft sentinel insofar as it is a valid communicator size, and so you cannot distinguish "uninitialized" from "genuinely zero participants" by looking at `commSize_` alone. But you can just look at `initState_` for this.

Differential Revision: D100673963
Scusemua added a commit to Scusemua/torchcomms that referenced this pull request Apr 15, 2026
…:reconfigure initialization state (meta-pytorch#2071)

Summary:

Add `isInitialized()` virtual method to `TorchCommBackend` so callers can check whether a backend is ready for collective operations before issuing them. The MCCL implementation now correctly ties initialization state to a successful `reconfigure()` result rather than unconditionally marking itself initialized, preventing use of a backend whose reconfigure failed.

Specifically, we now set `initState_ = UNINITIALIZED` before calling `mccl_comm_->reconfigure()`, then only promote to `INITIALIZED` inside the existing success block (where `result->code == commSuccess`) alongside `rank_` and `commSize_` updates. Previously `initState_ = INITIALIZED` was set unconditionally after `createWork()`, which allowed subsequent operations to proceed on a broken communicator after a failed reconfigure.

**We also** reset `commSize_` to 0 instead of -1, and we move the reset of `commSize_` and `rank_` to be with the `initState_ = UNITIALIZED`. For one thing, -1 (as an int) silently becomes `SIZE_MAX` when cast to `size_t`, which caused a production SEV once already. And if `commSize_` ever leaks beyond these guards, then 0 is harmless, while -1 is catastrophic (can crash the workload/application). 

**Concession:** 0 is more of a soft sentinel insofar as it is a valid communicator size, and so you cannot distinguish "uninitialized" from "genuinely zero participants" by looking at `commSize_` alone. But you can just look at `initState_` for this.

Differential Revision: D100673963
Scusemua added a commit to Scusemua/torchcomms that referenced this pull request Apr 15, 2026
…:reconfigure initialization state (meta-pytorch#2071)

Summary:

Add `isInitialized()` virtual method to `TorchCommBackend` so callers can check whether a backend is ready for collective operations before issuing them. The MCCL implementation now correctly ties initialization state to a successful `reconfigure()` result rather than unconditionally marking itself initialized, preventing use of a backend whose reconfigure failed.

Specifically, we now set `initState_ = UNINITIALIZED` before calling `mccl_comm_->reconfigure()`, then only promote to `INITIALIZED` inside the existing success block (where `result->code == commSuccess`) alongside `rank_` and `commSize_` updates. Previously `initState_ = INITIALIZED` was set unconditionally after `createWork()`, which allowed subsequent operations to proceed on a broken communicator after a failed reconfigure.

**We also** reset `commSize_` to 0 instead of -1, and we move the reset of `commSize_` and `rank_` to be with the `initState_ = UNITIALIZED`. For one thing, -1 (as an int) silently becomes `SIZE_MAX` when cast to `size_t`, which caused a production SEV once already. And if `commSize_` ever leaks beyond these guards, then 0 is harmless, while -1 is catastrophic (can crash the workload/application). 

**Concession:** 0 is more of a soft sentinel insofar as it is a valid communicator size, and so you cannot distinguish "uninitialized" from "genuinely zero participants" by looking at `commSize_` alone. But you can just look at `initState_` for this.

Differential Revision: D100673963
Scusemua pushed a commit to Scusemua/torchcomms that referenced this pull request Apr 15, 2026
…:reconfigure initialization state (meta-pytorch#2071)

Summary:
Pull Request resolved: meta-pytorch#2071

Add `isInitialized()` virtual method to `TorchCommBackend` so callers can check whether a backend is ready for collective operations before issuing them. The MCCL implementation now correctly ties initialization state to a successful `reconfigure()` result rather than unconditionally marking itself initialized, preventing use of a backend whose reconfigure failed.

Specifically, we now set `initState_ = UNINITIALIZED` before calling `mccl_comm_->reconfigure()`, then only promote to `INITIALIZED` inside the existing success block (where `result->code == commSuccess`) alongside `rank_` and `commSize_` updates. Previously `initState_ = INITIALIZED` was set unconditionally after `createWork()`, which allowed subsequent operations to proceed on a broken communicator after a failed reconfigure.

**We also** reset `commSize_` to 0 instead of -1, and we move the reset of `commSize_` and `rank_` to be with the `initState_ = UNITIALIZED`. For one thing, -1 (as an int) silently becomes `SIZE_MAX` when cast to `size_t`, which caused a production SEV once already. And if `commSize_` ever leaks beyond these guards, then 0 is harmless, while -1 is catastrophic (can crash the workload/application).

**Concession:** 0 is more of a soft sentinel insofar as it is a valid communicator size, and so you cannot distinguish "uninitialized" from "genuinely zero participants" by looking at `commSize_` alone. But you can just look at `initState_` for this.

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

Labels

CLA Signed This label is managed by the Meta Open Source bot. fb-exported meta-exported

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant