Skip to main content

Python Documentation Status Coverage Status

Documentation ~ Code ~ Paper

torchgfn

A Python Package for GFlowNets. Please cite this paper if you are using the library for your research!

Installing the package

The codebase requires python >= 3.10. To install the latest stable version with the core dependencies:

pip install torchgfn

torchgfn supports installation with multiple sets of dependencies, under the following tags:

  • dev: dependencies required for development of the core library.
  • scripts: dependencies needed to run examples in tutorials/examples/.
  • all: everything.

and can be called by running

pip install torchgfn[scripts]

Or to install the latest release (from the master branch) with all dependencies in a Conda environment:

git clone https://github.com/GFNOrg/torchgfn.git
conda create -n gfn python=3.10
conda activate gfn
cd torchgfn
pip install -e ".[all]"

About this repo

This repo serves the purpose of fast prototyping GFlowNet (GFN) related algorithms. It decouples the environment definition, the sampling process, and the parametrization of the function approximators used to calculate the GFN loss. It aims to accompany researchers and engineers in learning about GFlowNets, and in developing new algorithms.

The library is shipped with many environments under the gym, including discrete environments (e.g., Discrete Energy Based Model, Hyper Grid, Graph Generation), and continuous environments (e.g., Box). The library is designed to allow users to define their own environments relatively easily. See here for more details.

Getting Started with Example Scripts & Notebooks

Contributing

Please see the Contributing Guidelines.

Components of the Library

  • States, Actions, & Containers: The two core elements of torchgfn are the concepts of states, which are emitted by stateless environments, and actions, which transform states through the environment logic. These are encapsulated with metadata in containers.
  • Modules, Estimators, & Samplers: The components of a GFlowNet policy (those which select actions given a state), are encapsulated in Estimators. If the policy is a neural network, that logic is captured in a Module. This estimator can then be used with a Sampler to produce states (in the form of trajectories or transitions).
  • Losses: Each type of GFlowNet has a specific parameterization related to a specific loss. Covers TB, DB, SubTB, FM, ZVar, and RTB with guidance on when to use each.
  • Off-Policy Training & Replay Buffers: How to train with replay buffers, expert data warm-starting, and mixed on/off-policy batches.
  • Exploration Strategies: Epsilon-greedy, temperature scaling, noisy layers, local search, and variance annealing for mode discovery.
  • Conditional GFlowNets: Learning families of distributions parameterized by external conditions.
  • Recurrent & Non-Autoregressive Policies: LSTM/GRU policies, tree DAG simplifications, and order-invariant generation.
  • Diffusion GFlowNets: Continuous diffusion sampling with Brownian motion estimators and RTB fine-tuning.
  • Defining Environments: For most applications of torchgfn, the main challenge will be to define a stateless environment which will produce a valid sampler.
  • Advanced Usage: Extending torchgfn with Custom GFlowNets: While torchgfn aims to support major usages of GFlowNets, we hope this will also serve as a platform for the community to extend the possible use cases of the technology. This guide details how one can extend the library for new research and applications.
  • Full API Reference: A breakdown of all major components of both the core GFN library, the associated gym, and the included tutorials.

Release files for torchgfn 2.4.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 torchgfn 2.4.1
File Size Uploaded
torchgfn-2.4.1.tar.gz 4.8 MB Details

Built distribution (wheel)

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

Total release size: 9.6 MB

Release files / torchgfn-2.4.1.tar.gz

Download URL torchgfn-2.4.1.tar.gz
Size 4.8 MB
Tags Source
SHA-256 checksum
How to use checksums
ec5113403ea72ef3c082feaf76c4c763f578fb517f2e9a9181eb6301ce0aa0d5
BLAKE2b-256 checksum
How to use checksums
88782247065b4b3c9a56e420c0b88be699d6b25f014050e2ed88a3ed4b12fd03
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.3

Release files / torchgfn-2.4.1-py3-none-any.whl

Download URL torchgfn-2.4.1-py3-none-any.whl
Size 4.9 MB
Tags Python 3
SHA-256 checksum
How to use checksums
00036b98affcb97986d075406a567a60eb4c5dc8ad3ac2d290080096bb240a0f
BLAKE2b-256 checksum
How to use checksums
0825159d45bd139621c530aa7e3efa8c1865231850f1ee9b688674134db71a88
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.3

Release history Release notifications | RSS feed

This release

2.4.1 This release

2 release files

2.4.0

2 release files

2.3.1

2 release files

2.3.0

2 release files

2.2.2

2 release files

2.2.1

2 release files

2.2.0

2 release files

2.1.1

2 release files

2.1.0

2 release files

2.0.1

2 release files

1.2.1

2 release files

1.1.1

2 release files

1.1

2 release files

1.0.0

2 release files

0.2

2 release files

0.1.3

2 release files

0.1.1

2 release files

0.1.0

2 release files

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