Gradient checkpointing forward
Background
Gradient checkpointing (a.k.a. activation recomputation) trades compute for memory. A normal forward pass stores every layer's intermediate activation so the backward pass can reuse them — memory grows linearly with depth. Checkpointing instead discards intermediates during the forward pass and recomputes them on demand during backprop. This problem models the forward half: apply a chain of layer functions in sequence, returning only the final output (no intermediates retained).
Problem statement
Implement checkpoint_forward(funcs, input_arr) that applies each function in funcs to the running array in order and returns the final result as a float array:
No intermediate is kept — only the running value is carried forward.
Input
funcs— a list of callables , each mapping an array to an array.input_arr— annp.ndarrayinput .
Output
An np.ndarray (cast to float) equal to .
Examples
Example 1
Input: f1(x)=x+1, f2(x)=x*2, f3(x)=x-3, input_arr = [1.0, 2.0]
Output: [1.0, 3.0]
Explanation: . Only the final array is returned; the two intermediate arrays are not stored.
Constraints
- Apply the functions strictly left-to-right (function composition order).
- Carry a single running variable; do not accumulate a list of intermediates.
- Return the result cast to
float.
Notes
- The memory win is asymptotic: storing activations instead of at the cost of recomputing the forward pass during backprop (roughly one extra forward).
- In real frameworks, checkpointing wraps segments of layers; the recompute happens lazily inside the backward graph.
This problem ships 4 hidden tests. They run in your browser via Pyodide — no backend, no submission queue. Press ▶ Run tests to execute.
- •Reference example
- •Empty function list returns the input (as float)
- •Output is cast to float
- •Composition order is left-to-right