Skip to main content

Torchflows: normalizing flows in PyTorch

Torchflows is a library for generative modeling and density estimation using normalizing flows. It implements many normalizing flow architectures and their building blocks for:

  • Easy use of normalizing flows as trainable distributions.
  • Easy implementation of new normalizing flows.

Example use:

import torch
from torchflows.flows import Flow
from torchflows.architectures import RealNVP

torch.manual_seed(0)

n_data = 1000
n_dim = 3

x = torch.randn(n_data, n_dim)  # Generate some training data
bijection = RealNVP(n_dim)  # Create the bijection
flow = Flow(bijection)  # Create the normalizing flow

flow.fit(x)  # Fit the normalizing flow to training data
log_prob = flow.log_prob(x)  # Compute the log probability of training data
x_new = flow.sample(50)  # Sample 50 new data points

print(log_prob.shape)  # (100,)
print(x_new.shape)  # (50, 3)

Check out examples and the documentation, including the list of supported architectures.

Installing

We support Python versions 3.7 and upwards.

Install Torchflows via pip:

pip install torchflows

Install Torchflows directly from Github:

pip install git+https://github.com/davidnabergoj/torchflows.git

Setup for development:

git clone https://github.com/davidnabergoj/torchflows.git
cd torchflows
pip install -r requirements.txt

Citation

If you use this code in your work, we kindly ask that you cite the accompanying paper:

Nabergoj and Štrumbelj: Empirical evaluation of normalizing flows in Markov Chain Monte Carlo, 2024. arxiv:2412.17136.

BibTex entry:

@misc{nabergoj_nf_mcmc_evaluation_2024,
    author = {Nabergoj, David and \v{S}trumbelj, Erik},
    title = {Empirical evaluation of normalizing flows in {Markov} {Chain} {Monte} {Carlo}},
    publisher = {arXiv},
    month = dec,
    year = {2024},
    note = {arxiv:2412.17136}
}

Contributions

We warmly welcome all contributions and comments. Please do not hesitate to submit issues and pull requests.

Some options to start contributing include:

  • Adding references to the documentation page for architecture presets.
  • Implementing new normalizing flow architectures (see the developer guide).
  • Adding more automated tests for numerical stability and optimization.
  • Adding docstrings to undocumented classes.

Metadata

Release files for torchflows 1.2.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for torchflows 1.2.1
File Size Uploaded Provenance Actions
torchflows-1.2.1.tar.gz 343.0 kB With provenance Details for torchflows-1.2.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for torchflows 1.2.1
File Interpreter ABI Platform Actions
torchflows-1.2.1-py3-none-any.whl Python 3 none any Details for torchflows-1.2.1-py3-none-any.whl

Total release size: 452.5 kB

Release files / torchflows-1.2.1.tar.gz

Download URL torchflows-1.2.1.tar.gz
Size 343.0 kB
Tags Source
SHA-256 checksum
How to use checksums
3338441c52c21d6629d82a7e7e122b5f99d223f9bf51b571b2106439b0a8be15
BLAKE2b-256 checksum
How to use checksums
2965908c1e21296dba9eab086e3ab9348f19b7c65d9884f1162cc573f2638a35
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 26, 2026.

Transparency log

Release files / torchflows-1.2.1-py3-none-any.whl

Download URL torchflows-1.2.1-py3-none-any.whl
Size 109.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
28f4ca61805c82e59ab74eff2a1a51fa2649d66b47f7a0583ff4122809b75ea0
BLAKE2b-256 checksum
How to use checksums
69a8f9a0f5b20a8307c416e13e1d07703d643c30d9445995fb7935532df5cc8b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 26, 2026.

Transparency log

Security for torchflows 1.2.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for torchflows-1.2.1.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 26, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page