torch/distributed/algorithms/_checkpoint/_checkpoint_wrapper.py
def checkpoint_wrapper(
    module: torch.nn.Module,
    checkpoint_impl: CheckpointImpl = CheckpointImpl.REENTRANT
):
    """
    A convenience wrapper for activation checkpointing. If the module is wrapped
    with this function, all subsequent calls to the module will automatically
    perform checkpointing without the user having to explicitly call ``checkpoint``
    function.
    Usage::
        checkpointed_module = checkpoint_wrapper(module)
        outputs = checkpointed_module(inputs)
    Args:
        module (nn.Module):
            The module to be wrapped
        checkpoint_impl (Optional[CheckpointImpl]):
            The checkpointing implementation to use. Currently only
            CheckpointImpl.REENTRANT is supported.
    Returns:
        (nn.Module):
            Wrapped module
    """
    # saved tensor hooks based-checkpoint wrapper is not yet supported.
    if checkpoint_impl == CheckpointImpl.NO_REENTRANT:
        raise ValueError(
            "No support for non-reentrant based checkpoint implementation."
        )
    # Use weakref to avoid creating a refcycle: m -> m.forward -> m. This would
    # leak GPU memory because python won't gc the module when the module is
    # freed.
    module.forward = partial(  # type: ignore[assignment]
        _checkpointed_forward,
        type(module).forward,
        ref(module),
        checkpoint_impl,
    )
    return module

    A convenience wrapper for activation checkpointing. If the module is wrapped
    with this function, all subsequent calls to the module will automatically
    perform checkpointing without the user having to explicitly call ``checkpoint``
    function.
    Usage::
        checkpointed_module = checkpoint_wrapper(module)
        outputs = checkpointed_module(inputs)
    Args:
        module (nn.Module):
            The module to be wrapped
        checkpoint_impl (Optional[CheckpointImpl]):
            The checkpointing implementation to use. Currently only
            CheckpointImpl.REENTRANT is supported.
    Returns:
        (nn.Module):
            Wrapped module
    
A convenience wrapper for activation checkpointing. If the module is wrapped
with this function, all subsequent calls to the module will automatically
perform checkpointing without the user having to explicitly call ``checkpoint``
function.
A convenience wrapper for activation checkpointing . If the module is wrapped with this function all subsequent calls to the module will automatically perform checkpointing without the user having to explicitly call ` ` checkpoint ` ` function .
def checkpoint_wrapper(
    module: torch.nn.Module,
    checkpoint_impl: CheckpointImpl = CheckpointImpl.REENTRANT
):
    if checkpoint_impl == CheckpointImpl.NO_REENTRANT:
        raise ValueError(
            "No support for non-reentrant based checkpoint implementation."
        )
    module.forward = partial(  
        _checkpointed_forward,
        type(module).forward,
        ref(module),
        checkpoint_impl,
    )
    return module
def checkpoint_wrapper ( module : torch . nn . Module , checkpoint_impl : CheckpointImpl = CheckpointImpl . REENTRANT ) : if checkpoint_impl == CheckpointImpl . NO_REENTRANT : raise ValueError ( "No support for non-reentrant based checkpoint implementation." ) module . forward = partial ( _checkpointed_forward , type ( module ) . forward , ref ( module ) , checkpoint_impl , ) return module
A convenience wrapper for activation checkpointing.
A convenience wrapper for activation checkpointing .
"""
    A convenience wrapper for activation checkpointing. If the module is wrapped
    with this function, all subsequent calls to the module will automatically
    perform checkpointing without the user having to explicitly call ``checkpoint``
    function.
    Usage::
        checkpointed_module = checkpoint_wrapper(module)
        outputs = checkpointed_module(inputs)
    Args:
        module (nn.Module):
            The module to be wrapped
        checkpoint_impl (Optional[CheckpointImpl]):
            The checkpointing implementation to use. Currently only
            CheckpointImpl.REENTRANT is supported.
    Returns:
        (nn.Module):
            Wrapped module
    """ # saved tensor hooks based-checkpoint wrapper is not yet supported. # Use weakref to avoid creating a refcycle: m -> m.forward -> m. This would # leak GPU memory because python won't gc the module when the module is # freed. # type: ignore[assignment]
None
(nn.Module)
module
torch.nn.Module
The module to be wrapped
The module to be wrapped
checkpoint_impl
CheckpointImpl
The checkpointing implementation to use. Currently only
CheckpointImpl.REENTRANT is supported.
The checkpointing implementation to use . Currently only CheckpointImpl . REENTRANT is supported .