MCPcopy Create free account
hub / github.com/OpenDriveLab/ReSim / checkpoint

Function checkpoint

sat/sgm/modules/diffusionmodules/util.py:127–141  ·  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

125
126
127def checkpoint(func, inputs, params, flag):
128 """
129 Evaluate a function without caching intermediate activations, allowing for
130 reduced memory at the expense of extra compute in the backward pass.
131 :param func: the function to evaluate.
132 :param inputs: the argument sequence to pass to `func`.
133 :param params: a sequence of parameters `func` depends on but does not
134 explicitly take as arguments.
135 :param flag: if False, disable gradient checkpointing.
136 """
137 if flag:
138 args = tuple(inputs) + tuple(params)
139 return CheckpointFunction.apply(func, len(inputs), *args)
140 else:
141 return func(*inputs)
142
143
144class CheckpointFunction(torch.autograd.Function):

Callers 5

forwardMethod · 0.70
forwardMethod · 0.70
forwardMethod · 0.50
forwardMethod · 0.50
forwardMethod · 0.50

Calls

no outgoing calls

Tested by

no test coverage detected