Skip to content

Commit 61deed1

Browse files
committed
chore: format activation offload tests
1 parent efbb14b commit 61deed1

2 files changed

Lines changed: 9 additions & 15 deletions

File tree

‎megatron/core/pipeline_parallel/fine_grained_activation_offload.py‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1055,9 +1055,7 @@ def bulk_offload(self, name, forced_released_tensors):
10551055
"""Offload a group of tensors and optionally release their GPU memory."""
10561056
debug_rank("----bulk_offload")
10571057
group_to_offload = self.find_group_with_name(self._groups_to_offload, name)
1058-
assert (
1059-
group_to_offload is not None
1060-
), f"Group {name} not found in {self._groups_to_offload}"
1058+
assert group_to_offload is not None, f"Group {name} not found in {self._groups_to_offload}"
10611059
# Keep every group in the reload queue, including groups that are not
10621060
# actually offloaded. Non-offloaded groups become no-op reload slots,
10631061
# preserving the backward clock when activation_offload_fraction < 1.

‎tests/unit_tests/pipeline_parallel/test_fine_grained_activation_offloading.py‎

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,9 @@ def record_reload_event(self, stream):
4747
self.recorded_reload = True
4848

4949

50-
def test_group_start_backward_consumes_current_noop_slot_before_reloading_next(
51-
monkeypatch,
52-
):
50+
def test_group_start_backward_consumes_current_noop_slot_before_reloading_next(monkeypatch):
5351
"""No-op reload slots should preserve cadence without delaying the next reload."""
54-
from megatron.core.pipeline_parallel.fine_grained_activation_offload import (
55-
ChunkOffloadHandler,
56-
)
52+
from megatron.core.pipeline_parallel.fine_grained_activation_offload import ChunkOffloadHandler
5753

5854
monkeypatch.setattr(torch.cuda, "current_stream", lambda: _FakeCudaStream())
5955
monkeypatch.setattr(torch.cuda, "stream", lambda stream: nullcontext())
@@ -481,18 +477,18 @@ def _run_offload_case(activation_offload_fraction: float, params: Dict[str, torc
481477
return logits, grads, peak, expected_bytes
482478

483479
def _assert_matches_base(label, logits, grads, base_logits, base_grads):
484-
assert torch.allclose(logits, base_logits, rtol=1e-3, atol=1e-3), (
485-
f"{label} logits mismatch: max_diff={torch.max(torch.abs(logits - base_logits))}"
486-
)
480+
assert torch.allclose(
481+
logits, base_logits, rtol=1e-3, atol=1e-3
482+
), f"{label} logits mismatch: max_diff={torch.max(torch.abs(logits - base_logits))}"
487483
assert set(grads.keys()) == set(base_grads.keys())
488484
for name, gb in base_grads.items():
489485
go = grads[name]
490486
if gb is None or go is None:
491487
assert gb is None and go is None, f"{label} grad None mismatch for {name}"
492488
continue
493-
assert torch.allclose(go, gb, rtol=1e-3, atol=1e-3), (
494-
f"{label} grad mismatch for {name}: max_diff={torch.max(torch.abs(go - gb))}"
495-
)
489+
assert torch.allclose(
490+
go, gb, rtol=1e-3, atol=1e-3
491+
), f"{label} grad mismatch for {name}: max_diff={torch.max(torch.abs(go - gb))}"
496492

497493
try:
498494
base_logits, base_grads, base_peak, params = _run_baseline()

0 commit comments

Comments
 (0)