Skip to content

Improve error message for mixed strategy namespaces - #22017

Open
Subodh-17 wants to merge 4 commits into
Lightning-AI:masterfrom
Subodh-17:fix/strategy-namespace-collision
Open

Subodh-17 wants to merge 4 commits into
Lightning-AI:masterfrom
Subodh-17:fix/strategy-namespace-collision

Conversation

@Subodh-17

Copy link
Copy Markdown

Fixes #20526

Summary

Detect strategy instances imported from the other PyTorch Lightning namespace.
Raise a descriptive error explaining that the Trainer and Strategy must come from the same package.
Add regression coverage for the namespace-specific error and generic rejection of unrelated/Fabric strategies.

Testing

\git diff --check\ passes.
The focused pytest suite could not be run because \lightning_utilities\ is missing from the current environment. End-to-end behavior has not been verified locally.

@anishpentyala

Copy link
Copy Markdown

AI-assisted acceptance checks for e8494bf: I generated an isolated pytorch_lightning / lightning_fabric mirror from this head using the repository's import-rewrite helper, rather than only spoofing class names. This also checks that the concatenated modern namespace prefix survives package generation.

Twenty CPU cases pass: actual SingleDeviceStrategy, DDPStrategy, and custom subclasses from the opposite namespace get the descriptive error in both directions; same-namespace instances are accepted in both directions; Fabric strategies, unrelated objects and an invalid string keep the generic error. A real two-step fit with a same-namespace SingleDeviceStrategy succeeds from each namespace.

With only the accelerator connector reverted to 84df182 in both the source and mirror, the fourteen acceptance/generic-error/fit controls still pass, while the six opposite-namespace cases fail the message assertion because they receive the old generic error. Both versions correctly reject the mixed instances; this validates diagnosis, not new cross-package interoperability.

The same final accelerator-connector suite has 165 passed / 31 skipped on head and 164 passed / 31 skipped / 1 expected message-test failure on base. Python 3.10 / PyTorch 2.14.1, Linux CPU. DDP strategy construction was checked, not a distributed launch. The isolated mirror needed the usual version metadata copied beside it before importing; that setup failure was not counted as a product failure.

This branch has not been deployed

No deployments
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.

"ValueError: You selected an invalid strategy name" When DDPStrategy(process_group_backend="gloo") is passed

2 participants