MCPcopy Create free account
hub / github.com/CompVis/diff2flow / checkpoint

Function checkpoint

diff2flow/models/unet/util.py:17–31  ·  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 parameters

(func, inputs, params, flag)

Source from the content-addressed store, hash-verified

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

Callers 3

forwardMethod · 0.90
forwardMethod · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected