MCPcopy Create free account
hub / github.com/VisionXLab/OF-Diff / checkpoint

Function checkpoint

ldm/modules/diffusionmodules/util.py:102–116  ·  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

100
101
102def checkpoint(func, inputs, params, flag):
103 """
104 Evaluate a function without caching intermediate activations, allowing for
105 reduced memory at the expense of extra compute in the backward pass.
106 :param func: the function to evaluate.
107 :param inputs: the argument sequence to pass to `func`.
108 :param params: a sequence of parameters `func` depends on but does not
109 explicitly take as arguments.
110 :param flag: if False, disable gradient checkpointing.
111 """
112 if flag:
113 args = tuple(inputs) + tuple(params)
114 return CheckpointFunction.apply(func, len(inputs), *args)
115 else:
116 return func(*inputs)
117
118
119class CheckpointFunction(torch.autograd.Function):

Callers 4

forwardMethod · 0.90
forwardMethod · 0.90
forwardMethod · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected