Alias-Free Torch is a Python library providing a simple PyTorch module implementation of Alias-Free GAN (Generative Adversarial Networks) concepts. It includes Alias-Free GAN style lowpass sinc filters, up/downsampling, and activation modules. The library aims to reduce aliasing artifacts in generated images, which is crucial for deep learning models like diffusion architectures, by integrating signal processing-based alias-free resampling techniques. The current version is 0.0.6, and the project is actively maintained, though it is described as an unofficial implementation and may not perfectly align with official StyleGAN3 implementations.
Install & Compatibility
Where this runs
tested against v0.0.6 · 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
muslpy 3.10–3.920 runs
installs and imports cleanly · install 0.0s · import 0.000s · 17.8MB
glibcpy 3.10–3.920 runs
installs and imports cleanly · install 1.5s · import 0.000s · 18MB
16MB installed
● package 16MB
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
LowPassFilter1d
✓ from alias_free_torch import LowPassFilter1d
✗ from alias_free_torch import LowPassFilter1d
This quickstart demonstrates how to instantiate and use an `Activation1d` module with a standard PyTorch activation like ReLU. It showcases the basic tensor flow through an alias-free processing block, which performs upsampling, applies the activation, and then downsampling to mitigate aliasing effects. The example uses a 1D input tensor, as the library also supports 2D operations.
import torch
import torch.nn as nn
from alias_free_torch.act import Activation1d
# Define a simple 1D activation module with ReLU as the base activation
# This will upsample, apply ReLU, then downsample to combat aliasing
activation_module = Activation1d(
activation=nn.ReLU(),
up_ratio=2,
down_ratio=2,
up_kernel_size=12,
down_kernel_size=12
)
# Create a dummy 1D input tensor (Batch, Channels, Length)
# Current versions often expect channel dimension to be 1 for many operations
input_tensor = torch.randn(1, 1, 64)
# Pass the input through the alias-free activation module
output_tensor = activation_module(input_tensor)
print(f"Input tensor shape: {input_tensor.shape}")
print(f"Output tensor shape: {output_tensor.shape}")
# Expected output shape: (1, 1, 64) if up_ratio and down_ratio cancel out
Debug
Known issues
gotchaThe library explicitly states it is an 'unofficial implementation' and its filters and upsample/downsample behavior 'could be different with official implementation' (e.g., StyleGAN3). This may lead to subtle differences in behavior or results compared to original research papers.fixBe aware that results might not perfectly match official implementations. Conduct thorough validation if replicating specific research outcomes. Consider comparing against official source code if available.
affects: All versions (0.0.1 - 0.0.6)
breakingDue to the `v0.0.x` versioning and rapid development, API changes and behavioral modifications are common. For instance, `v0.0.2` involved a 'Rewrite upsample, jinc applied', and `v0.0.3` included 'Bug fix for torch.special / remove print / split pad from conv_transpose', which can be breaking changes in functionality or required arguments.fixAlways pin the exact version in `requirements.txt`. Review GitHub release notes and commit history carefully when upgrading between minor versions to identify specific changes.
affects: All versions before 0.0.6
gotchaThe library requires PyTorch version `torch>=1.7.0` because it depends on `torch.kaiser_window` and `torch.i0`. Pip's dependency checker may not enforce this for 'custom torch users', leading to runtime errors if an older PyTorch version is installed.fixManually ensure your PyTorch installation is `torch>=1.7.0` before installing `alias-free-torch`. For example: `pip install torch>=1.7.0` then `pip install alias-free-torch`.
affects: All versions (0.0.1 - 0.0.6)
Audit
Dependencies
torchrequiredCore deep learning framework; requires specific functions (kaiser_window, i0) introduced in version 1.7.0 or later.