Skip to main content

A torch implementation of GFlowNets

Project description

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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

torchgfn-2.4.1.tar.gz (4.8 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

torchgfn-2.4.1-py3-none-any.whl (4.9 MB view details)

Uploaded Python 3

File details

Details for the file torchgfn-2.4.1.tar.gz.

File metadata

  • Download URL: torchgfn-2.4.1.tar.gz
  • Upload date:
  • Size: 4.8 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.3

File hashes

Hashes for torchgfn-2.4.1.tar.gz
Algorithm Hash digest
SHA256 ec5113403ea72ef3c082feaf76c4c763f578fb517f2e9a9181eb6301ce0aa0d5
MD5 dc3b5ed197c027940f23fb141bd53c08
BLAKE2b-256 88782247065b4b3c9a56e420c0b88be699d6b25f014050e2ed88a3ed4b12fd03

See more details on using hashes here.

File details

Details for the file torchgfn-2.4.1-py3-none-any.whl.

File metadata

  • Download URL: torchgfn-2.4.1-py3-none-any.whl
  • Upload date:
  • Size: 4.9 MB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.3

File hashes

Hashes for torchgfn-2.4.1-py3-none-any.whl
Algorithm Hash digest
SHA256 00036b98affcb97986d075406a567a60eb4c5dc8ad3ac2d290080096bb240a0f
MD5 fa108907cc2aa5566aa5e59aa72496d8
BLAKE2b-256 0825159d45bd139621c530aa7e3efa8c1865231850f1ee9b688674134db71a88

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page