--- id: pytorch-revgrad version: "0.2.0" license: unclear license_treatment: permissive maintenance: dormant --- # pytorch_revgrad — A pytorch module (and function) to reverse gradients. License: permissive · Maintenance: dormant · Downloads: 224.3K/mo ## 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 above — 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 pip install pytorch-revgrad uv add pytorch-revgrad poetry add pytorch-revgrad ## Installing 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_current - Install friction: low - Maintenance: dormant - Downloads: 224.3K/month (top 15,000 on PyPI) - Known vulnerabilities: none known ## Tags gradient reversal pytorch, adversarial training layer, reverse gradients neural network, domain adaptation pytorch, gradient flip deep learning, pytorch adversarial layer, revgrad module, adversarial-training, domain-adaptation, gradient-manipulation [View on SkillFed](https://skillfed.io/packages/pytorch-revgrad) · [View on PyPI](https://pypi.org/project/pytorch-revgrad/)