Registry / ai-ml / autograd

autograd

JSON →
library1.9.1pypypi✓ verified 27d ago

Autograd is a Python library that efficiently computes derivatives of native Python and NumPy code using automatic differentiation. The current version, 1.8.0, supports Python 3.9-3.13 and has a release cadence that includes compatibility updates for new Python and NumPy versions, along with bug fixes and minor features.

pip install autograd
INSTALL
IMPORT
SIG · AUTOGRAD
A
autograd
ai-mlpythonv1.9.1
Install
5.5s avg
Import
322ms
Disk
90MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v1.9.1 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.910 runs
installs and imports cleanly · install 0.0s · import 0.324s · 89.9MB
glibc
py 3.103.910 runs
installs and imports cleanly · install 5.5s · import 0.319s · 86MB
90MB installed
● package 90MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

numpy
import autograd.numpy as np
Use autograd's wrapped NumPy to enable automatic differentiation.
grad
from autograd import grad
The primary function to obtain the gradient of a scalar-valued function.
elementwise_grad
from autograd import elementwise_grad as egrad
For functions that vectorize over inputs and return an array of scalar derivatives.

This example defines a simple tanh function using `autograd.numpy`, then uses `autograd.grad` to obtain its derivative function. The gradient is then evaluated at a specific point.

import autograd.numpy as np from autograd import grad def tanh(x): return (1.0 - np.exp((-2 * x))) / (1.0 + np.exp(-(2 * x))) grad_tanh = grad(tanh) x_val = np.float64(1.0) print(f"tanh({x_val}) = {tanh(x_val)}") print(f"Gradient of tanh at {x_val} = {grad_tanh(x_val)}")
Debug
Known issues
breakingAutograd v1.7.0 (and subsequent versions) dropped support for Python 2.x. Python 3.9 or newer is now required.
fix
Migrate your project to Python 3.9+.
affects: >=1.7.0
breakingWhile Autograd v1.7.0 added compatibility for NumPy 2.0.0, the latest v1.8.0 explicitly pins dependencies to NumPy < 3 to ensure stability. Future NumPy 3.x versions might introduce breaking changes.
fix
Ensure your environment uses a NumPy version compatible with Autograd's constraints (currently <3.0). Check release notes for specific version requirements.
affects: >=1.8.0
gotchaAutograd does not properly handle in-place array operations (e.g., `A[0,0] = x`, `a += b`) or method-style dot products (`A.dot(B)`). Always use non-in-place assignments (`a = a + b`) and function-style operations (`np.dot(A, B)`).
fix
Rewrite code to use non-in-place operations and function-style calls for NumPy array manipulations.
affects: All
gotchaAvoid implicit casting of Python lists to NumPy arrays within functions that require differentiation (e.g., `np.sum([x, y])`). Explicitly convert lists to NumPy arrays: `np.sum(np.array([x, y]))`.
fix
Ensure all array creations and operations explicitly use `autograd.numpy` functions and array types.
affects: All
gotchaThe `grad` function expects the function being differentiated to return a scalar value. If you need to differentiate a vectorized function that returns an array of scalar derivatives, use `autograd.elementwise_grad`.
fix
Ensure the target function for `grad` returns a scalar, or use `elementwise_grad` for vectorized outputs.
affects: All
gotchaPerformance can be significantly impacted by extensive pure Python logic (e.g., complex loops, conditional statements) within the function being differentiated, as Python overheads are amplified during automatic differentiation.
fix
Vectorize operations as much as possible using `autograd.numpy` primitives to minimize Python-level computation. Re-evaluate algorithm design if performance remains an issue.
affects: All
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'autograd.numpy'; 'autograd' is not a package
This error occurs when the script is named 'autograd.py', causing a naming conflict with the autograd library.
fix
Rename your script to avoid the naming conflict, e.g., 'my_script.py'.
TypeError: loop of ufunc does not support argument 0 of type ArrayBox which has no callable sin method
This error occurs when using NumPy functions that are not compatible with autograd's automatic differentiation.
fix
Import NumPy from autograd to ensure compatibility: 'import autograd.numpy as np'.
TypeError: ufunc 'isnan' not supported for the input types, and the inputs could not be safely coerced to any supported types according to the casting rule 'safe'
This error occurs when using functions from libraries like SciPy that are not compatible with autograd's automatic differentiation.
fix
Use autograd-compatible functions or implement the function manually using autograd's NumPy.
TypeError: 'float' object cannot be interpreted as an integer
This general Python error arises in `autograd` contexts when a floating-point number (often from an `autograd.numpy` array) is used in an operation that strictly requires an integer, such as indexing a list or array with a float, or using a float in Python's `range()` function.
fix
Explicitly cast the float to an integer using `int()` before using it in operations that require integer arguments (e.g., `my_list[int(float_val)]`). Ensure that array dimensions or indices passed to NumPy functions are integers where required.
TypeError: Can't differentiate wrt numpy arrays of dtype int64
`autograd` can only differentiate functions with respect to floating-point numbers. This error indicates that you are trying to compute a gradient with respect to a NumPy array whose elements have an integer data type (e.g., `int64`).
fix
Ensure that all NumPy arrays passed to `autograd`'s differentiation functions (e.g., `grad`) have a floating-point data type. You can explicitly specify the dtype when creating arrays (e.g., `np.array([0.0, 0.0])` or `np.array([0, 0], dtype=float)` or `arr.astype(float)`).
Upgrade
Version history
1.9.1latest on PyPI · released Jul 2, 2026
Audit
Dependencies
numpyrequiredCore functionality relies on NumPy for array operations.
scipyoptionalRequired for certain advanced features.
pythonrequiredRequires Python 3.9 or newer.
Agent activity
34 hits · last 30 days
node
28
OpenAI (training)
1
Resources
autograd — pip install autograd · libregistry