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

Gpu monitoring #237

Merged
merged 22 commits into from
Nov 7, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
13 changes: 13 additions & 0 deletions src/itwinai/torch/distributed.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ class TorchDistributedStrategy(DistributedStrategy):
#: Defaults to False.
is_initialized: bool = False

# Provides the name of the strategy for logging purposes etc.
name: str

@property
def is_main_worker(self) -> bool:
"""Checks if local worker has global rank equal to zero.
Expand Down Expand Up @@ -381,6 +384,7 @@ class TorchDDPStrategy(TorchDistributedStrategy):
def __init__(self, backend: Literal["nccl", "gloo", "mpi"]) -> None:
super().__init__()
self.backend = backend
self.name = "torch-ddp"

def init(self) -> None:
"""Initializes the distributed process group and the distributed
Expand Down Expand Up @@ -595,6 +599,7 @@ class DeepSpeedStrategy(TorchDistributedStrategy):
def __init__(self, backend: Literal["nccl", "gloo", "mpi"]) -> None:
super().__init__()
self.backend = backend
self.name = "deepspeed"

def init(self) -> None:
"""Initializes the distributed process group and the distributed
Expand Down Expand Up @@ -779,6 +784,10 @@ def gather(self, tensor: torch.Tensor, dst_rank: int = 0) -> Optional[List]:
class HorovodStrategy(TorchDistributedStrategy):
"""Horovod distributed strategy class."""

def __init__(self):
super().__init__()
self.name = "horovod"

def init(self) -> None:
"""Initializes the Horovod distributed backend.

Expand Down Expand Up @@ -965,6 +974,10 @@ class NonDistributedStrategy(TorchDistributedStrategy):
is_distributed: bool = True
is_distributed: bool = False

def __init__(self):
super().__init__()
self.name = "non-distributed"

def init(self) -> None:
"""If CUDA is available set CUDA device, and do nothing more.

Expand Down
16 changes: 2 additions & 14 deletions src/itwinai/torch/monitoring/monitoring.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,23 +114,12 @@ def measured_method(self: TorchTrainer, *args, **kwargs) -> Any:
warmup_time = 5

strategy = self.strategy
strategy.init()

if isinstance(strategy, NonDistributedStrategy):
strategy_name = "non-dist"
elif isinstance(strategy, TorchDDPStrategy):
strategy_name = "ddp"
elif isinstance(strategy, DeepSpeedStrategy):
strategy_name = "deepspeed"
elif isinstance(strategy, HorovodStrategy):
strategy_name = "horovod"
else:
strategy_name = "unk"
strategy_name = strategy.name

local_rank = strategy.local_rank()
global_rank = strategy.global_rank()
num_global_gpus = strategy.global_world_size()
num_local_gpus = torch.cuda.device_count()
num_local_gpus = strategy.local_world_size()
node_idx = global_rank // num_local_gpus

output_path = Path(
Expand Down Expand Up @@ -185,7 +174,6 @@ def measured_method(self: TorchTrainer, *args, **kwargs) -> Any:
if strategy.is_main_worker:
write_logs_to_file(global_utilization_log, output_path)

strategy.clean_up()
return result

return measured_method
2 changes: 1 addition & 1 deletion src/itwinai/torch/trainer.py
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ def execute(

if self.logger:
self.logger.destroy_logger_context()
# self.strategy.clean_up()
self.strategy.clean_up()
return train_dataset, validation_dataset, test_dataset, self.model

def _set_epoch_dataloaders(self, epoch: int):
Expand Down
3 changes: 2 additions & 1 deletion use-cases/eurac/trainer.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ def __init__(

@suppress_workers_print
# @profile_torch_trainer
jarlsondre marked this conversation as resolved.
Show resolved Hide resolved
@measure_gpu_utilization
# @measure_gpu_utilization
def execute(
self,
train_dataset: Dataset,
Expand Down Expand Up @@ -148,6 +148,7 @@ def set_epoch(self, epoch: int):
self.train_loader.sampler.set_epoch(epoch)
self.val_loader.sampler.set_epoch(epoch)

@measure_gpu_utilization
jarlsondre marked this conversation as resolved.
Show resolved Hide resolved
def train(self):
"""Override version of hython to support distributed strategy."""
# Tracking epoch times for scaling test
Expand Down