pytorch_revgrad
A pytorch module (and function) to reverse gradients.
What it is and what it does
pytorch-revgrad provides a single-purpose layer that reverses gradients during backpropagation, a technique used in adversarial training and domain adaptation. It wraps PyTorch's autograd mechanism to negate gradients flowing backward through the layer while preserving the forward pass unchanged. The layer integrates directly into torch.nn.Sequential or custom models as a drop-in module.
The package depends only on numpy and torch, making it lightweight to install. It targets a specific algorithmic need rather than a broad framework—if your model requires gradient reversal for adversarial objectives (such as domain-adversarial neural networks), this layer provides that functionality without additional overhead. The dormant maintenance status and age of the codebase mean you should verify compatibility with your PyTorch version before relying on it in production.
Use it for:
- Domain adaptation: reverse gradients in a discriminator to train domain-invariant feature extractors.
- Adversarial training: implement gradient reversal for adversarial loss objectives in multi-task learning.
- Feature learning: use RevGrad to prevent a classifier from learning domain-specific features during transfer learning.
- Research prototyping: quickly add gradient reversal to experimental architectures without custom autograd code.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Implements a gradient reversal layer for PyTorch neural networks, enabling adversarial training by reversing gradients during backpropagation.
Yes, if you need gradient reversal for adversarial training or domain adaptation and your PyTorch version is compatible. The low install friction and permissive license make it a straightforward addition. However, verify that the package works with your specific PyTorch version first, given the dormant maintenance status and last release in 2021. For new projects, consider whether a custom autograd Function might be more maintainable long-term.
Install
pytorch-revgrad on PyPI
pip
pip install pytorch-revgraduv
uv add pytorch-revgradpoetry
poetry add pytorch-revgradInstalling pytorch_revgrad
Before you install
Low friction install with only numpy and torch as dependencies. Dormant maintenance status—last release was 2021-01-09 and no commits since 2024-11-04—but the repository remains active and the package is straightforward enough that infrequent updates are not inherently a risk.
License in practice
MIT license (permissive) means you can use, modify, and distribute this package freely in both open and closed projects with minimal restrictions.
Quickstart
pip install pytorch-revgrad
import torch
from pytorch_revgrad import RevGrad
model = torch.nn.Sequential(
torch.nn.Linear(10, 5),
torch.nn.Linear(5, 2),
RevGrad()
)
Verify before relying
- Whether gradient reversal behavior matches current PyTorch conventions and autograd semantics in modern PyTorch versions.
- Whether the package has been tested against recent PyTorch releases or if compatibility issues exist.
Package facts
| License | not declared (permissive) |
| Python support | supports the current Python release (>=3.5) |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | 2 — numpy, torch |
| Maintenance | dormant — 2,043 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 224,317/month — #9,235 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: pytorch_revgrad-0.2.0-py3-none-any.whl
Tags
More Artificial Intelligence packages
LiteLLM provides a unified Python interface to…
permissive · top 100 on PyPI
huggingface-hubClient library and CLI tool for downloading,…
permissive · top 100 on PyPI
langchainLangChain provides a framework for building…
permissive · top 1,000 on PyPI
hf-xethf-xet provides chunk-based deduplication and…
permissive · top 1,000 on PyPI
tokenizersTokenizers converts raw text into token…
permissive · top 1,000 on PyPI
transformersTransformers provides a unified framework for…
permissive · top 1,000 on PyPI
pytorch_optimizerProvides a collection of modern optimizers,…
permissive · top 15,000 on PyPI
torchPyTorch provides GPU-accelerated tensor…
permissive · top 1,000 on PyPI
torchsdeSolves stochastic differential equations (SDEs)…
permissive · top 5,000 on PyPI
autogradAutograd automatically computes derivatives of…
permissive · top 5,000 on PyPI
torchdiffeqProvides PyTorch-based ODE solvers with…
permissive · top 5,000 on PyPI
pytorchcvProvides a collection of pretrained computer…
unclear · top 15,000 on PyPI
torchsrProvides pretrained neural network models for…
permissive · top 15,000 on PyPI
torch-geometricPyTorch Geometric is a library for building and…
permissive · top 5,000 on PyPI
pytorch-waveletsProvides 2D discrete wavelet and dual-tree…
unclear · top 15,000 on PyPI
NeuralFoilNeuralFoil predicts airfoil aerodynamic…
permissive · top 15,000 on PyPI