def METHOD_NAME(param: torch.nn.Parameter) -> None:
    # view_as creates a node in autograd graph that allows us access to the
    # parameter's AccumulateGrad autograd function object. We register a
    # hook on this object to fire the optimizer when the gradient for
    # this parameter is ready (has been accumulated into .grad field)
    # Don't create a new acc_grad if we already have one
    # i.e. for shared parameters or attaching multiple optimizers to a param.
    if param not in param_to_acc_grad_map:
        param_to_acc_grad_map[param] = param.view_as(param).grad_fn.next_functions[0][0]
    optimizer = optimizer_class([param], **optimizer_kwargs)
    if not hasattr(param, "_in_backward_optimizers"):
        param._in_backward_optimizers = []  # type: ignore[attr-defined]
        # TODO: investigate whether we really need these attributes.
        param._optimizer_classes = []  # type: ignore[attr-defined]
        param._optimizer_kwargs = []  # type: ignore[attr-defined]
    param._in_backward_optimizers.append(optimizer)  # type: ignore[attr-defined]
    param._optimizer_classes.append(optimizer_class)  # type: ignore[attr-defined]
    param._optimizer_kwargs.append(optimizer_kwargs)  # type: ignore[attr-defined]
    if not register_hook:
        return
    def optimizer_hook(*_unused) -> None:
        for opt in param._in_backward_optimizers:  # type: ignore[attr-defined]
            opt.step()
        param.grad = None
    handle = param_to_acc_grad_map[param].register_hook(optimizer_hook)  # type: ignore[attr-defined]
    if param not in param_to_optim_hook_handle_map:
        param_to_optim_hook_handle_map[param] = []
    param_to_optim_hook_handle_map[param].append(handle)