Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove use of local rank in trainers #926

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion src/fairchem/core/_cli_hydra.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ def map_cli_args_to_dist_config(cli_args: argparse.Namespace) -> dict:
"submit": cli_args.submit,
"summit": None,
"cpu": cli_args.cpu,
"use_cuda_visibile_devices": True,
}


Expand Down
12 changes: 2 additions & 10 deletions src/fairchem/core/common/distutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,14 +74,7 @@ def setup(config) -> None:
f"local rank: {config['local_rank']}, visible devices: {os.environ['CUDA_VISIBLE_DEVICES']}"
)

# In the new hydra runners, we setup the device for each rank as either cuda:0 or cpu
# after this point, the local rank should either be using "cpu" or "cuda"
if config.get("use_cuda_visibile_devices"):
assign_device_for_local_rank(config["cpu"], config["local_rank"])
else:
# in the old code, all ranks can see all devices but need to be assigned a device equal to their local rank
# this is dangerous and should be deprecated
torch.cuda.set_device(config["local_rank"])
assign_device_for_local_rank(config["cpu"], config["local_rank"])

dist.init_process_group(
backend="nccl",
Expand Down Expand Up @@ -121,8 +114,7 @@ def setup(config) -> None:
), "Can only setup master address and port at this point for a single rank, otherwise we assume the processes and the comm addr/port have already been setup"
setup_env_local()
config["local_rank"] = int(os.environ.get("LOCAL_RANK"))
if config.get("use_cuda_visibile_devices"):
assign_device_for_local_rank(config["cpu"], config["local_rank"])
assign_device_for_local_rank(config["cpu"], config["local_rank"])
dist.init_process_group(
backend=config["distributed_backend"],
rank=int(os.environ.get("RANK")),
Expand Down
7 changes: 2 additions & 5 deletions src/fairchem/core/trainers/base_trainer.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,7 @@ def __init__(
loss_functions: dict[str, str | float],
evaluation_metrics: dict[str, str],
identifier: str,
# TODO: dealing with local rank is dangerous
# T201111838 remove this and use CUDA_VISIBILE_DEVICES instead so trainers don't need to know about which devie to use
local_rank: int,
local_rank: int, # DEPRECATED, DO NOT USE
timestamp_id: str | None = None,
run_dir: str | None = None,
is_debug: bool = False,
Expand All @@ -104,8 +102,7 @@ def __init__(
self.ema = None

if torch.cuda.is_available() and not self.cpu:
logging.info(f"local rank base: {local_rank}")
self.device = torch.device(f"cuda:{local_rank}")
self.device = torch.device("cuda")
else:
self.device = torch.device("cpu")
self.cpu = True # handle case when `--cpu` isn't specified
Expand Down
4 changes: 1 addition & 3 deletions src/fairchem/core/trainers/ocp_trainer.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,7 @@ def __init__(
loss_functions: dict[str, str | float],
evaluation_metrics: dict[str, str],
identifier: str,
# TODO: dealing with local rank is dangerous
# T201111838 remove this and use CUDA_VISIBILE_DEVICES instead so trainers don't need to know about which devie to use
local_rank: int,
local_rank: int, # DEPRECATED, DO NOT USE
timestamp_id: str | None = None,
run_dir: str | None = None,
is_debug: bool = False,
Expand Down