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

Use master weights for bfloat16 FusedAdam when master_weights=True #1731

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
10 changes: 7 additions & 3 deletions apex/optimizers/fused_adam.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ def step(self, closure=None, grads=None, output_params=None, scale=None, grad_no
g_bf, p_bf, m_bf, v_bf = [], [], [], []
g_32, p_32, m_32, v_32 = [], [], [], []
p_16_master = []
p_bf_master = []
p_32_master = []

for p, p_master in zip(group['params'], group_master['params']):
Expand All @@ -182,6 +183,8 @@ def step(self, closure=None, grads=None, output_params=None, scale=None, grad_no
m_16.append(state['exp_avg'])
v_16.append(state['exp_avg_sq'])
elif p.dtype == torch.bfloat16:
if self.master_weights:
p_bf_master.append(p_master.data)
g_bf.append(p.grad)
p_bf.append(p)
m_bf.append(state['exp_avg'])
Expand Down Expand Up @@ -232,10 +235,11 @@ def step(self, closure=None, grads=None, output_params=None, scale=None, grad_no
inv_scale)

if len(g_bf) > 0:
multi_tensor_applier(
self.multi_tensor_adam_capturable,
multi_tensor_applier(self.multi_tensor_adam_capturable_master if self.master_weights
else self.multi_tensor_adam_capturable,
self._dummy_overflow_buf,
[g_bf, p_bf, m_bf, v_bf],
[g_bf, p_bf, m_bf, v_bf, p_bf_master] if self.master_weights
else [g_bf, p_bf, m_bf, v_bf],
group['lr'],
beta1,
beta2,
Expand Down