Skip to main content

Efficiently computes derivatives of NumPy code.

Project description

Autograd Checks status Tests status Publish status asv

Autograd can automatically differentiate native Python and Numpy code. It can handle a large subset of Python's features, including loops, ifs, recursion and closures, and it can even take derivatives of derivatives of derivatives. It supports reverse-mode differentiation (a.k.a. backpropagation), which means it can efficiently take gradients of scalar-valued functions with respect to array-valued arguments, as well as forward-mode differentiation, and the two can be composed arbitrarily. The main intended application of Autograd is gradient-based optimization. For more information, check out the tutorial and the examples directory.

Example use:

>>> import autograd.numpy as np  # Thinly-wrapped numpy
>>> from autograd import grad    # The only autograd function you may ever need
>>>
>>> def tanh(x):                 # Define a function
...     return (1.0 - np.exp((-2 * x))) / (1.0 + np.exp(-(2 * x)))
...
>>> grad_tanh = grad(tanh)       # Obtain its gradient function
>>> grad_tanh(1.0)               # Evaluate the gradient at x = 1.0
np.float64(0.419974341614026)
>>> (tanh(1.0001) - tanh(0.9999)) / 0.0002  # Compare to finite differences
np.float64(0.41997434264973155)

We can continue to differentiate as many times as we like, and use numpy's vectorization of scalar-valued functions across many different input values:

>>> from autograd import elementwise_grad as egrad  # for functions that vectorize over inputs
>>> import matplotlib.pyplot as plt
>>> x = np.linspace(-7, 7, 700)
>>> plt.plot(x, tanh(x),
...          x, egrad(tanh)(x),                                     # first  derivative
...          x, egrad(egrad(tanh))(x),                              # second derivative
...          x, egrad(egrad(egrad(tanh)))(x),                       # third  derivative
...          x, egrad(egrad(egrad(egrad(tanh))))(x),)               # fourth derivative
>>> plt.show()

See the tanh example file for the code.

Documentation

You can find a tutorial here.

End-to-end examples

How to install

Install Autograd using Pip:

pip install autograd

Some features require SciPy, which you can install separately or as an optional dependency along with Autograd:

pip install "autograd[scipy]"

Authors and maintainers

Autograd was written by Dougal Maclaurin, David Duvenaud, Matt Johnson, Jamie Townsend and many other contributors. The package is currently being maintained by Agriya Khetarpal, Fabian Joswig and Jamie Townsend. Please feel free to submit any bugs or feature requests. We'd also love to hear about your experiences with Autograd in general. Drop us an email!

We want to thank Jasper Snoek and the rest of the HIPS group (led by Prof. Ryan P. Adams) for helpful contributions and advice; Barak Pearlmutter for foundational work on automatic differentiation and for guidance on our implementation; and Analog Devices Inc. (Lyric Labs) and Samsung Advanced Institute of Technology for their generous support.

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

autograd-1.9.1.tar.gz (2.6 MB view details)

Uploaded Source

Built Distribution

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

autograd-1.9.1-py3-none-any.whl (54.4 kB view details)

Uploaded Python 3

File details

Details for the file autograd-1.9.1.tar.gz.

File metadata

  • Download URL: autograd-1.9.1.tar.gz
  • Upload date:
  • Size: 2.6 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.13

File hashes

Hashes for autograd-1.9.1.tar.gz
Algorithm Hash digest
SHA256 7818c5c69ddf9efb7da74097bd741a4c7920133f41966f68537223a15ef798bc
MD5 a8bf665f9860abcd7164b7d295f807fd
BLAKE2b-256 9dac4a8b58364ba865ab545251edbe475e5a35326814a5d274a2211d33ed8a5d

See more details on using hashes here.

Provenance

The following attestation bundles were made for autograd-1.9.1.tar.gz:

Publisher: publish.yml on HIPS/autograd

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file autograd-1.9.1-py3-none-any.whl.

File metadata

  • Download URL: autograd-1.9.1-py3-none-any.whl
  • Upload date:
  • Size: 54.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.13

File hashes

Hashes for autograd-1.9.1-py3-none-any.whl
Algorithm Hash digest
SHA256 b788bae3fa010cbffb4cfb7b8ba2a3f0daa6072a8506da6164c779fe9cf3e05a
MD5 82b9cf12c31db121eb3402b0c0171225
BLAKE2b-256 6ece8c98e6604bb1ec9d03c8493c328185b69bb7533fe08f3640f0f3641bd9d1

See more details on using hashes here.

Provenance

The following attestation bundles were made for autograd-1.9.1-py3-none-any.whl:

Publisher: publish.yml on HIPS/autograd

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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