Skip to content

Commit

Permalink
[DCP][AC] Add test for apply AC with FSDP1 (pytorch#126935)
Browse files Browse the repository at this point in the history
Adding test for this cherry pick. pytorch#126559

Pull Request resolved: pytorch#126935
Approved by: https://github.com/fegin
  • Loading branch information
wz337 authored and pytorchmergebot committed May 23, 2024
1 parent bbe68a1 commit 264155a
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion test/distributed/checkpoint/test_state_dict.py
Original file line number Diff line number Diff line change
Expand Up @@ -548,7 +548,7 @@ def test_cpu_offload_full_state_dict(self) -> None:

@with_comms
@skip_if_lt_x_gpu(1)
def test_activation_ckpt_fqns(self) -> None:
def test_activation_ckpt_fqns_ddp(self) -> None:
"""Tests that activation checkpointing prefixes are removed from module names"""
model = CompositeParamModel(device=torch.device("cuda"))
original_keys = get_model_state_dict(model).keys()
Expand All @@ -559,6 +559,25 @@ def test_activation_ckpt_fqns(self) -> None:

self.assertEqual(original_keys, new_keys)

@with_comms
@skip_if_lt_x_gpu(1)
def test_activation_ckpt_fqns_fsdp1(self) -> None:
self.run_subtests(
{"use_orig_params": [True, False]},
self._test_activation_ckpt_fqns_fsdp1,
)

def _test_activation_ckpt_fqns_fsdp1(self, use_orig_params: bool) -> None:
"""Tests that activation checkpointing prefixes are removed from module names"""
model = CompositeParamModel(device=torch.device("cuda"))
original_keys = get_model_state_dict(model).keys()

apply_activation_checkpointing(model)
model = FSDP(model, use_orig_params=use_orig_params)
new_keys = get_model_state_dict(model).keys()

self.assertEqual(original_keys, new_keys)

@with_comms
@skip_if_lt_x_gpu(1)
def test_extra_state(self) -> None:
Expand Down

0 comments on commit 264155a

Please sign in to comment.