Skip to content

Accept closure argument in NGD optimizer step #2118

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Sep 6, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions gpytorch/optim/ngd.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env python3

from typing import Iterable, Union
from typing import Callable, Iterable, Optional, Union

import torch

Expand Down Expand Up @@ -28,8 +28,13 @@ def __init__(self, params: Iterable[Union[torch.nn.Parameter, dict]], num_data:
super().__init__(params, defaults=dict(lr=lr))

@torch.no_grad()
def step(self) -> None:
"""Performs a single optimization step."""
def step(self, closure: Optional[Callable] = None) -> None:
"""
Performs a single optimization step.

(Note that the :attr:`closure` argument is not used by this optimizer; it is simply included to be
compatible with the PyTorch optimizer API.)
"""
for group in self.param_groups:
for p in group["params"]:
if p.grad is None:
Expand Down