MCPcopy Create free account
hub / github.com/Vchitect/Latte / checkpoint

Function checkpoint

models/utils.py:25–39  ·  view source on GitHub ↗

Evaluate a function without caching intermediate activations, allowing for reduced memory at the expense of extra compute in the backward pass. :param func: the function to evaluate. :param inputs: the argument sequence to pass to `func`. :param params: a sequence of parame

(func, inputs, params, flag)

Source from the content-addressed store, hash-verified

23#################################################################################
24
25def checkpoint(func, inputs, params, flag):
26 """
27 Evaluate a function without caching intermediate activations, allowing for
28 reduced memory at the expense of extra compute in the backward pass.
29 :param func: the function to evaluate.
30 :param inputs: the argument sequence to pass to `func`.
31 :param params: a sequence of parameters `func` depends on but does not
32 explicitly take as arguments.
33 :param flag: if False, disable gradient checkpointing.
34 """
35 if flag:
36 args = tuple(inputs) + tuple(params)
37 return CheckpointFunction.apply(func, len(inputs), *args)
38 else:
39 return func(*inputs)
40
41
42class CheckpointFunction(torch.autograd.Function):

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected