MCPcopy Index your code
hub / github.com/apple/ml-sharp / checkpoint_wrapper

Function checkpoint_wrapper

src/sharp/utils/training.py:10–24  ·  view source on GitHub ↗

Helper function that applies checkpointing. If enabled applies grad checkpointing, otherwise just executes the function normally.

(self, fn, *args)

Source from the content-addressed store, hash-verified

8
9
10def checkpoint_wrapper(self, fn, *args):
11 """Helper function that applies checkpointing.
12
13 If enabled applies grad checkpointing, otherwise just executes the function normally.
14 """
15 if not hasattr(self, "grad_checkpointing"):
16 raise AttributeError(
17 "Trying to apply grad checkpointing on a model that does not have a grad_checkpointing "
18 "attribute."
19 )
20
21 if self.grad_checkpointing:
22 return checkpoint(fn, *args, use_reentrant=False)
23 else:
24 return fn(*args)

Callers 2

forwardMethod · 0.90
forwardMethod · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected