Skip to content

Commit a68a119

Browse files
author
Andrew Gu
committed
Update on "[FSDP] Add unsafe setattr gated by env var"
This adds the option to use an unsafe `setattr` for `_use_sharded_views()` and `_use_unsharded_views()` gated by the environment variable `FSDP_USE_UNSAFE_SETATTR`, where a value of `1` means to use the unsafe `setattr`. The unsafe option is disabled by default. The unsafe `setattr` may be able to save CPU overhead and may be used to intentionally bypass `setattr` checks. Both `_use_sharded_views()` and `_use_unsharded_views()` must use the unsafe version or use the safe versions atomically. [ghstack-poisoned]
1 parent 4704a52 commit a68a119

1 file changed

Lines changed: 0 additions & 2 deletions

File tree

test/distributed/fsdp/test_fsdp_misc.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -682,7 +682,6 @@ def __setattr__(self, name: str, value: Any) -> None:
682682
os.environ[_FSDP_USE_UNSAFE_SETATTR] = "1"
683683
module = SetattrLinear(5, 5, torch.device("cuda"))
684684
fsdp_module = FSDP(module, use_orig_params=use_orig_params)
685-
inp = torch.randn((8, 5), device=torch.device("cuda"))
686685
called_setattr_override = False
687686
fsdp_module(inp)
688687
self.assertFalse(called_setattr_override)
@@ -691,7 +690,6 @@ def __setattr__(self, name: str, value: Any) -> None:
691690
os.environ[_FSDP_USE_UNSAFE_SETATTR] = "0"
692691
module = SetattrLinear(5, 5, torch.device("cuda"))
693692
fsdp_module = FSDP(module, use_orig_params=use_orig_params)
694-
inp = torch.randn((8, 5), device=torch.device("cuda"))
695693
called_setattr_override = False
696694
fsdp_module(inp)
697695
self.assertTrue(called_setattr_override)

0 commit comments

Comments
 (0)