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

Function checkpoint

diff2flow/models/unet/attention.py:341–355  ·  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

339
340
341def checkpoint(func, inputs, params, flag):
342 """
343 Evaluate a function without caching intermediate activations, allowing for
344 reduced memory at the expense of extra compute in the backward pass.
345 :param func: the function to evaluate.
346 :param inputs: the argument sequence to pass to `func`.
347 :param params: a sequence of parameters `func` depends on but does not
348 explicitly take as arguments.
349 :param flag: if False, disable gradient checkpointing.
350 """
351 if flag:
352 args = tuple(inputs) + tuple(params)
353 return CheckpointFunction.apply(func, len(inputs), *args)
354 else:
355 return func(*inputs)
356
357
358class CheckpointFunction(torch.autograd.Function):

Callers 1

forwardMethod · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected