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

add enable to scaler #39

Merged
merged 1 commit into from
May 25, 2022
Merged
Show file tree
Hide file tree
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
4 changes: 2 additions & 2 deletions theseus/base/optimizers/scalers/native.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ class NativeScaler:
"""
state_dict_key = "amp_scaler"

def __init__(self):
self._scaler = torch.cuda.amp.GradScaler()
def __init__(self, use_fp16:bool = True):
self._scaler = torch.cuda.amp.GradScaler(enabled=use_fp16)

def __call__(self, loss, optimizer, create_graph=False):
"""
Expand Down
2 changes: 1 addition & 1 deletion theseus/base/trainer/base_trainer.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def __init__(self,

self.num_iterations = num_iterations
self.use_amp = True if use_fp16 else False
self.scaler = NativeScaler() if use_fp16 else False
self.scaler = NativeScaler(use_fp16)
self.clip_grad = clip_grad
self.evaluate_interval = evaluate_interval
self.iters = 0
Expand Down