Skip to main content

Classical gradient based optimization in PyTorch

Project description

GradOpTorch

Classical gradient based optimization in PyTorch.

What is GradOpTorch?

GradOpTorch is a suite of classical gradient-based optimization tools for PyTorch. The toolkit includes conjugate gradients, BFGS, and some methods for line-search.

Why not torch.optim?

Not every problem is high-dimensional, highly nonconvex, with noisy gradients.
For such problems, classical optimization techniques can be more efficient.

Installation

GradOpTorch can be installed from PyPI:

pip install gradoptorch

Usage

There are two primary interfaces for making use of the library.

  1. The standard PyTorch object oriented interface:
from gradoptorch import optimize_module
from torch import nn

class MyModel(nn.Module):
    ...

model = MyModule()

def loss_fn(model):
    ...

hist = optimize_module(model, loss_fn, opt_method="bfgs", ls_method="back_tracking")
  1. The functional interface:
from gradoptorch import optimizer

def f(x):
    ...

x_guess = ...

x_opt, hist = optimizer(f, x_guess, opt_method="conj_grad_pr", ls_method="quad_search")

Newton's method is only available in the functional interface

Included optimizers:

'grad_exact' : exact gradient optimization
'conj_grad_fr' : conjugate gradient descent using Fletcher-Reeves search direction
'conj_grad_pr' : conjugate gradient descent using Polak-Ribiere search direction
'newton_exact' : exact newton optimization
'bfgs' : approximate newton optimization using bfgs

Included line-search methods:

'back_tracking' : backing tracking based line-search
'quad_search' : quadratic line-search
'constant' : no line search, constant step size used

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

gradoptorch-0.1.1.tar.gz (7.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

gradoptorch-0.1.1-py3-none-any.whl (8.9 kB view details)

Uploaded Python 3

File details

Details for the file gradoptorch-0.1.1.tar.gz.

File metadata

  • Download URL: gradoptorch-0.1.1.tar.gz
  • Upload date:
  • Size: 7.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.6.1 CPython/3.10.10 Darwin/23.0.0

File hashes

Hashes for gradoptorch-0.1.1.tar.gz
Algorithm Hash digest
SHA256 418f729cd031bc0b399412deaf147d1f34cdf9f48a3d3081e8569b70e84a2e12
MD5 fd870fc17e557556c587ed534724ef06
BLAKE2b-256 7970ac47995e737894f41dd08a9e38509de59dcea7b27d137ea994968aa3ce71

See more details on using hashes here.

File details

Details for the file gradoptorch-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: gradoptorch-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 8.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.6.1 CPython/3.10.10 Darwin/23.0.0

File hashes

Hashes for gradoptorch-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 50b8e32d05d3279e150208f297dbcdd7bb4e21b72eef47ae3970aeb89df098a3
MD5 4abdcd576f31a55614e4de865fad3211
BLAKE2b-256 7671879f18f38260dd134d6a7d237900e4356d2e97492819bcdc151b58dc1383

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page