Skip to content

Commit

Permalink
Add environment parse function that supports default value (pytorch#8…
Browse files Browse the repository at this point in the history
…5563)

We use "-2" to represent an unset environment variable.
Now adding a util function to attach default value if environment variable is unset.
Pull Request resolved: pytorch#85563
Approved by: https://github.com/rohan-varma, https://github.com/H-Huang
  • Loading branch information
kwen2501 authored and pytorchmergebot committed Sep 28, 2022
1 parent f80ef73 commit 3276b51
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
4 changes: 2 additions & 2 deletions torch/csrc/distributed/c10d/ProcessGroupNCCL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -623,8 +623,8 @@ ProcessGroupNCCL::ProcessGroupNCCL(
at::cuda::getNumGPUs() != 0,
"ProcessGroupNCCL is only supported with GPUs, no GPUs found!");
blockingWait_ = parseEnvVarFlag(NCCL_BLOCKING_WAIT);
asyncErrorHandling_ =
static_cast<ErrorHandlingMode>(parseEnvVarInt(NCCL_ASYNC_ERROR_HANDLING));
asyncErrorHandling_ = static_cast<ErrorHandlingMode>(
parseEnvVarIntDefault(NCCL_ASYNC_ERROR_HANDLING, 0));
desyncDebug_ = parseEnvVarFlag(NCCL_DESYNC_DEBUG) ||
(dist_debug_level_ >= DebugLevel::Detail);

Expand Down
7 changes: 7 additions & 0 deletions torch/csrc/distributed/c10d/Utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,13 @@ inline int parseEnvVarInt(const char* envVarName) {
return C10D_ENV_NOT_SET;
}

inline int parseEnvVarIntDefault(const char* envVarName, int defaultVal) {
int val = parseEnvVarInt(envVarName);
if (val == C10D_ENV_NOT_SET)
return defaultVal;
return val;
}

inline bool parseEnvVarFlag(const char* envVarName) {
int val = parseEnvVarInt(envVarName);
if (val == 1) {
Expand Down

0 comments on commit 3276b51

Please sign in to comment.