opacus/grad_sample/utils.py [13:32]:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
):
    """
    Registers the decorated function as the ``grad_sampler`` of ``target_class_or_classes``, which is
    the function that will be invoked every time you want to compute a per-sample gradient
    of ``target_class_or_classes``. The signature of every grad_sampler is always the same:

    >>> @register_grad_sampler(MyCustomModel)
    ... def compute_grad_sample(module, activations, backprops):
    ...    pass

    It may help you to take a look at the existing grad_samplers inside Opacus, under ``opacus.grad_sample.``
    """

    def decorator(f):
        target_classes = (
            target_class_or_classes
            if isinstance(target_class_or_classes, Sequence)
            else [target_class_or_classes]
        )
        for target_class in target_classes:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -



opacus/validators/utils.py [15:36]:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
):
    """
    Registers the decorated function as the ``validator`` of ``target_class_or_classes``, which is
    the function that will be invoked every time you want to validate that a module is compatible
    for training with Opacus.
    You may supply your own validator_class that holds the registry of VALIDATORS.
    The signature of every validator is always the same:

    >>> @register_module_validator(MyCustomModel)
    ... def validate(module: nn.Module, **kwargs) -> List[opacus.validators.errors.UnsupportedError]:
    ...    pass

    It may help you to take a look at the existing validator inside Opacus, under ``opacus.validators.``
    """

    def decorator(f):
        target_classes = (
            target_class_or_classes
            if isinstance(target_class_or_classes, Sequence)
            else [target_class_or_classes]
        )
        for target_class in target_classes:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -



