Automatic Differentiation of Optimization Algorithms with Time-Varying Updates