-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
26 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
from zeroband.models.llama.model import Transformer | ||
|
||
from torch.distributed.algorithms._checkpoint.checkpoint_wrapper import checkpoint_wrapper | ||
|
||
from zeroband.utils.logging import get_logger | ||
|
||
|
||
def apply_ac_ckpt(model: Transformer): | ||
"""Apply activation checkpointing to the model.""" | ||
logger = get_logger() | ||
|
||
for layer_id, transformer_block in model.layers.named_children(): | ||
transformer_block = checkpoint_wrapper(transformer_block, preserve_rng_state=False) | ||
model.layers.register_module(layer_id, transformer_block) | ||
|
||
logger.info("Applied activation checkpointing to the model") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters