MCPcopy Create free account
hub / github.com/modelscope/modelscope / checkpoint

Function checkpoint

modelscope/models/multi_modal/guided_diffusion/unet.py:76–90  ·  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

74
75
76def checkpoint(func, inputs, params, flag):
77 """
78 Evaluate a function without caching intermediate activations, allowing for
79 reduced memory at the expense of extra compute in the backward pass.
80 :param func: the function to evaluate.
81 :param inputs: the argument sequence to pass to `func`.
82 :param params: a sequence of parameters `func` depends on but does not
83 explicitly take as arguments.
84 :param flag: if False, disable gradient checkpointing.
85 """
86 if flag:
87 args = tuple(inputs) + tuple(params)
88 return CheckpointFunction.apply(func, len(inputs), *args)
89 else:
90 return func(*inputs)
91
92
93class AttentionPool2d(nn.Module):

Callers 11

forwardMethod · 0.70
forwardMethod · 0.70
forwardMethod · 0.50
encodeMethod · 0.50
forward_Method · 0.50
forward_Method · 0.50
forward_Method · 0.50

Calls 2

funcFunction · 0.85
applyMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…