Add num_nodes() method to ClusterEnvironment#21638
Closed
crawfordxx wants to merge 1 commit into
Closed
Conversation
Add an abstract num_nodes() method to the ClusterEnvironment base class so users can query the number of nodes directly from the cluster environment. Each concrete implementation derives the value from the appropriate source: - SLURMEnvironment: SLURM_NNODES env var - TorchElasticEnvironment: GROUP_WORLD_SIZE env var - LightningEnvironment: NUM_NODES env var - KubeflowEnvironment: NUM_NODES env var (defaults to world_size) - LSFEnvironment: unique hosts in rank file - MPIEnvironment: unique hostnames via MPI gather - XLAEnvironment: xr.host_count() or HOST_WORLD_SIZE env var Closes #7361
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #21638 +/- ##
=========================================
- Coverage 87% 48% -39%
=========================================
Files 270 267 -3
Lines 23930 23904 -26
=========================================
- Hits 20709 11414 -9295
- Misses 3221 12490 +9269 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
num_nodes()method to theClusterEnvironmentbase class so the number of nodes can be queried directly from the cluster environmentnum_nodes()in all seven concrete subclasses (SLURM, TorchElastic, Lightning, Kubeflow, LSF, MPI, XLA), each deriving the value from the appropriate environment-specific sourceMotivation
Closes #7361. Currently
num_nodesmust be specified manually by the user, but in most cluster environments this information is already available (e.g.,SLURM_NNODES,GROUP_WORLD_SIZE). This change allows the cluster environment to provide it automatically.Implementation Details
SLURMEnvironmentSLURM_NNODESenv var (default: 1)TorchElasticEnvironmentGROUP_WORLD_SIZEenv var (default: 1)LightningEnvironmentNUM_NODESenv var (default: 1)KubeflowEnvironmentNUM_NODESenv var (default:world_size)LSFEnvironmentLSB_DJOB_RANKFILEMPIEnvironmentMPI.COMM_WORLD.gatherXLAEnvironmentxr.host_count()(XLA >= 2.1) orHOST_WORLD_SIZEenv varTest plan
test_num_nodesandtest_num_nodes_defaulttests for SLURM, TorchElastic, Lightning, and Kubeflow environmentstest_attributes_from_environment_variablesfor SLURM and TorchElastic📚 Documentation preview 📚: https://pytorch-lightning--21638.org.readthedocs.build/en/21638/