Accumulated squared gradients
Medium TrainingImplement AdaGrad from scratch. AdaGrad gives each weight its own learning rate by accumulating the sum of squared gradients. Frequently & strongly updated weights get progressively smaller steps — great for sparse features, but because the cache only grows, the effective learning rate keeps shrinking and can stall.
Implement the class below. Use only basic PyTorch operations.
Use this code to debug before submitting.
Try solving it yourself first! Click below to reveal the solution.
For interactive practice with auto-grading, run TorchCode locally:pip install torch-judge then use check("adagrad")
Monotonically growing squared-gradient cache → the per-parameter step size only ever decreases. Strong for sparse gradients; the shrinking step is exactly what RMSProp fixes with a decaying average. Covered in DL Module 7 §5.