Skip to content
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
8 changes: 6 additions & 2 deletions colossalai/nn/optimizer/cpu_adam.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,17 +190,21 @@ def step(self, closure=None, div_scale: float = -1):
)
self._post_update(p, "exp_avg", "exp_avg_sq")
elif target_device.type == "cuda":
assert div_scale == -1, "div_scale should remain default"
assert state["exp_avg"].device.type == "cuda", "exp_avg should stay on cuda"
assert state["exp_avg_sq"].device.type == "cuda", "exp_avg should stay on cuda"

bias_correction1 = 1 - beta1 ** state["step"]
bias_correction2 = 1 - beta2 ** state["step"]

# scale gradient if div_scale is provided
grad = p.grad.data
if div_scale != -1:
grad = grad / div_scale

# adam on cuda
self.torch_adam_update(
p.data,
p.grad.data,
grad,
state["exp_avg"],
state["exp_avg_sq"],
group["lr"],
Expand Down