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

[Feature] refractor dist came; fix percision error; add low level zero test with bert model zoo; #5676

Merged
merged 7 commits into from
Apr 30, 2024
6 changes: 3 additions & 3 deletions colossalai/nn/optimizer/came.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def step(self, closure=None):
for p in group["params"]:
if p.grad is None:
continue
grad = p.grad.data
grad = p.grad
if grad.is_sparse:
raise RuntimeError("CAME does not support sparse gradients.")

Expand Down Expand Up @@ -104,6 +104,7 @@ def step(self, closure=None):
state["step"] += 1

update = (grad**2) + group["eps"][0]

if factored:
exp_avg_sq_row = state["exp_avg_sq_row"]
exp_avg_sq_col = state["exp_avg_sq_col"]
Expand Down Expand Up @@ -132,15 +133,14 @@ def step(self, closure=None):
if factored:
exp_avg_res_row = state["exp_avg_res_row"]
exp_avg_res_col = state["exp_avg_res_col"]

exp_avg_res_row.mul_(group["betas"][2]).add_(res.mean(dim=-1), alpha=1.0 - group["betas"][2])
exp_avg_res_col.mul_(group["betas"][2]).add_(res.mean(dim=-2), alpha=1.0 - group["betas"][2])

# Approximation of exponential moving average of instability
res_approx = self._approx_sq_grad(exp_avg_res_row, exp_avg_res_col)
update = res_approx.mul_(exp_avg)
else:
update = exp_avg
update = exp_avg.clone()

if group["weight_decay"] != 0:
p.data.add_(p.data, alpha=-group["weight_decay"] * group["lr"])
Expand Down
Loading
Loading