NumPy allowed · plain Python earns 10 bonus points
θ ← θ − 0.14 · ∂L/∂θ
Mitigate exploding gradients in deep neural networks and recurrent models by scaling down gradients when their L2 norm exceeds a threshold.
Implement grad_clip_by_norm(grads, max_norm): compute the global L2 norm norm = sqrt(sum(g_i^2)). If norm > max_norm, scale each gradient element by max_norm / norm; otherwise leave gradients unchanged. Return {'clipped_grads': [...], 'global_norm': norm} with all numbers rounded to 6 decimal places.
grad_clip_by_norm(grads: list[float], max_norm: float) -> dict