DoorDash-inspired demand model occasionally produces unusually large gradients that can destabilize a training step. You need to clip the gradient vector to a maximum norm so the optimizer receives a bounded update.
If the L2 norm of the gradient exceeds max_norm, rescale the gradient so its norm equals max_norm; otherwise return it unchanged. The direction is preserved.
Implement solve(g,max_norm).
Returns. Return a float NumPy vector. A zero gradient is returned as is.
Example 1
Input:
solve([3, 4], 2)
Output:
[1.2, 1.6]
Example 2
Input:
solve([0.3, 0.4], 1.0)
Output:
[0.3, 0.4]
No results yet
Run your code to check it against the examples, or submit to run every test.