File: leanpass/optim.py
The zero_grad method unconditionally creates a NumPy array for param.grad even when the parameter does not require gradients (requires_grad=False). This breaks the convention that non‑trainable tensors have grad=None and can cause downstream code to treat them as trainable. The method should only zero gradients for parameters that have requires_grad=True.
def zero_grad(self):
for param in self.params:
- param.grad = np.zeros_like(param.data)
+ if param.requires_grad:
+ param.grad = np.zeros_like(param.data)
Filed automatically by ai-issue-scan.
File:
leanpass/optim.pyThe
zero_gradmethod unconditionally creates a NumPy array forparam.gradeven when the parameter does not require gradients (requires_grad=False). This breaks the convention that non‑trainable tensors havegrad=Noneand can cause downstream code to treat them as trainable. The method should only zero gradients for parameters that haverequires_grad=True.Filed automatically by ai-issue-scan.