Skip to content

Commit

Permalink
Fix unfixed naming inconsistencies (#531)
Browse files Browse the repository at this point in the history
It turns out my last PR didn't rename all the variables completely,
thereby causing CI failures. This PR fixes it.
  • Loading branch information
XianzheMa authored Jun 20, 2024
1 parent 1c2c4cc commit 55fef7c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 13 deletions.
2 changes: 1 addition & 1 deletion modyn/tests/common/grpc/test_grpc_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ def test_prepare_start_training_request(
assert req.seed == 0
assert req.num_samples_to_pass == (num_samples_to_pass if num_samples_to_pass is not None else 0)
assert req.shuffle
assert req.measure_operation_time
assert req.enable_accurate_gpu_measurements


@patch("modyn.common.grpc.grpc_helpers.grpc_connection_established", return_value=True)
Expand Down
22 changes: 10 additions & 12 deletions modyn/trainer_server/internal/trainer/pytorch_trainer.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ def __init__(
self._device = device
self._device_type = "cuda" if "cuda" in self._device else "cpu"
self._amp = training_info.amp
self._measure_operation_time = training_info.measure_operation_time
self._measure_gpu_ops = training_info.enable_accurate_gpu_measurements
self._checkpoint_path = training_info.checkpoint_path
self._checkpoint_interval = training_info.checkpoint_interval
self._final_checkpoint_path = training_info.final_checkpoint_path
Expand Down Expand Up @@ -241,7 +241,7 @@ def train(self) -> None: # pylint: disable=too-many-locals, too-many-branches

if self._sample_then_batch_this_epoch(epoch):
self.update_queue("TRAINING", batch_number, self._num_samples, training_active=False)
with GPUMeasurement(self._measure_operation_time, "DownsampleSTB", self._device, stopw):
with GPUMeasurement(self._measure_gpu_ops, "DownsampleSTB", self._device, stopw):
self.downsample_trigger_training_set()

stopw.start("IndivFetchBatch", overwrite=True)
Expand All @@ -258,7 +258,7 @@ def train(self) -> None: # pylint: disable=too-many-locals, too-many-branches

self.update_queue("TRAINING", batch_number, self._num_samples, training_active=True)

with GPUMeasurement(self._measure_operation_time, "PreprocessBatch", self._device, stopw, resume=True):
with GPUMeasurement(self._measure_gpu_ops, "PreprocessBatch", self._device, stopw, resume=True):
sample_ids, target, data = self.preprocess_batch(batch, stopw)

if retrieve_weights_from_dataloader:
Expand All @@ -271,9 +271,7 @@ def train(self) -> None: # pylint: disable=too-many-locals, too-many-branches

with torch.autocast(self._device_type, enabled=self._amp):
if self._downsampling_mode == DownsamplingMode.BATCH_THEN_SAMPLE:
with GPUMeasurement(
self._measure_operation_time, "DownsampleBTS", self._device, stopw, resume=True
):
with GPUMeasurement(self._measure_gpu_ops, "DownsampleBTS", self._device, stopw, resume=True):
data, sample_ids, target, weights = self.downsample_batch(data, sample_ids, target)
self._assert_data_size(post_downsampling_size, data, sample_ids, target)
if not batch_accumulator.inform_batch(data, sample_ids, target, weights):
Expand All @@ -285,10 +283,10 @@ def train(self) -> None: # pylint: disable=too-many-locals, too-many-branches
data, sample_ids, target, weights = batch_accumulator.get_accumulated_batch()

self._assert_data_size(self._batch_size, data, sample_ids, target)
with GPUMeasurement(self._measure_operation_time, "Forward", self._device, stopw, resume=True):
with GPUMeasurement(self._measure_gpu_ops, "Forward", self._device, stopw, resume=True):
output = self._model.model(data)

with GPUMeasurement(self._measure_operation_time, "Loss", self._device, stopw, resume=True):
with GPUMeasurement(self._measure_gpu_ops, "Loss", self._device, stopw, resume=True):
if weighted_optimization:
# weighted gradient descent
assert weights is not None
Expand All @@ -303,10 +301,10 @@ def train(self) -> None: # pylint: disable=too-many-locals, too-many-branches
)
stopw.stop()

with GPUMeasurement(self._measure_operation_time, "Backward", self._device, stopw, resume=True):
with GPUMeasurement(self._measure_gpu_ops, "Backward", self._device, stopw, resume=True):
self._scaler.scale(loss).backward()

with GPUMeasurement(self._measure_operation_time, "OptimizerStep", self._device, stopw, resume=True):
with GPUMeasurement(self._measure_gpu_ops, "OptimizerStep", self._device, stopw, resume=True):
for _, optimizer in self._optimizers.items():
self._scaler.step(optimizer)

Expand Down Expand Up @@ -507,10 +505,10 @@ def preprocess_batch(
target = batch[2]
stopw.stop("LabelTransform")

with GPUMeasurement(self._measure_operation_time, "MoveLabelToGPU", self._device, stopw, resume=True):
with GPUMeasurement(self._measure_gpu_ops, "MoveLabelToGPU", self._device, stopw, resume=True):
target = target.to(self._device)

with GPUMeasurement(self._measure_operation_time, "MoveDataToGPU", self._device, stopw, resume=True):
with GPUMeasurement(self._measure_gpu_ops, "MoveDataToGPU", self._device, stopw, resume=True):
data: Union[torch.Tensor, dict]
if isinstance(batch[1], torch.Tensor):
data = batch[1].to(self._device)
Expand Down

0 comments on commit 55fef7c

Please sign in to comment.