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

Separate grad scaler test out from test_app_state_mixin #425

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all 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
21 changes: 18 additions & 3 deletions tests/framework/test_auto_unit.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,18 +56,33 @@ def test_app_state_mixin(self) -> None:

auto_unit = DummyAutoUnit(
module=my_module,
precision="fp16",
)

self.assertEqual(auto_unit.tracked_modules()["module"], my_module)
for key in ("module", "optimizer", "lr_scheduler"):
self.assertIn(key, auto_unit.app_state())

@unittest.skipUnless(
condition=cuda_available, reason="This test needs a GPU host to run."
)
def test_app_state_mixin_grad_scaler(self) -> None:
"""
Test that grad_scaler is added to the AutoUnit tracked_misc_statefuls when using fp16 precision
"""
my_module = torch.nn.Linear(2, 2)

auto_unit = DummyAutoUnit(
module=my_module,
precision="fp16",
)

self.assertTrue(
isinstance(
auto_unit.tracked_misc_statefuls()["grad_scaler"],
torch.cuda.amp.GradScaler,
)
)
for key in ("module", "optimizer", "lr_scheduler", "grad_scaler"):
self.assertIn(key, auto_unit.app_state())
self.assertIn("grad_scaler", auto_unit.app_state())

def test_lr_scheduler_step(self) -> None:
"""
Expand Down