Skip to main content

Implementation of Transformer Flows (Apple ML) in JAX and Equinox.

Project description

Transformer flows

Implementation of Apple ML's Transformer Flow (or TARFlow) from Normalising flows are capable generative models in jax and equinox.

Features:

  • jax.vmap & jax.lax.scan construction & forward-pass, for layers respectively for fast compilation and execution,
  • multi-device training, inference and sampling,
  • score-based denoising step (see paper),
  • conditioning via class embedding (for discrete class labels) or adaptive layer-normalisation (for continuous variables, like in DiT),
  • array-typed to-the-teeth for dependable execution with jaxtyping and beartype.

To implement:

  • Guidance
  • Denoising
  • Mixed precision
  • EMA
  • AdaLayerNorm
  • Class embedding
  • Hyperparameter/model saving
  • Uniform and Gaussian noise for dequantisation

Usage

pip install transformer-flows
uv run --all-extras python examples/main.py

#### Samples

I haven't optimised anything here (the authors mention varying the variance of noise used to dequantise the images), nor have I trained for very long. You can see slight artifacts due to the dequantisation noise.

<p align="center">
  <picture>
    <img src="assets/mnist_warp.gif" alt="Your image description">
  </picture>
</p>

<p align="center">
  <picture>
    <img src="assets/cifar10_warp.gif" alt="Your image description">
  </picture>
</p>

#### Citation 

```bibtex
@misc{zhai2024normalizingflowscapablegenerative,
      title={Normalizing Flows are Capable Generative Models}, 
      author={Shuangfei Zhai and Ruixiang Zhang and Preetum Nakkiran and David Berthelot and Jiatao Gu and Huangjie Zheng and Tianrong Chen and Miguel Angel Bautista and Navdeep Jaitly and Josh Susskind},
      year={2024},
      eprint={2412.06329},
      archivePrefix={arXiv},
      primaryClass={cs.CV},
      url={https://arxiv.org/abs/2412.06329}, 
}

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

transformer_flows-0.0.10.tar.gz (15.4 MB view details)

Uploaded Source

Built Distribution

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

transformer_flows-0.0.10-py3-none-any.whl (19.2 kB view details)

Uploaded Python 3

File details

Details for the file transformer_flows-0.0.10.tar.gz.

File metadata

  • Download URL: transformer_flows-0.0.10.tar.gz
  • Upload date:
  • Size: 15.4 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.7.19

File hashes

Hashes for transformer_flows-0.0.10.tar.gz
Algorithm Hash digest
SHA256 e838a06dd3a9162305c95f306f58202b8cab98e82b62051299e4cd73546491fc
MD5 41e54e2c906c3bb74b240f7b16a259c8
BLAKE2b-256 1d0d73c4c146113cc52b4095b175d87631f2d53703de6d13f5de68c5405c15fa

See more details on using hashes here.

File details

Details for the file transformer_flows-0.0.10-py3-none-any.whl.

File metadata

File hashes

Hashes for transformer_flows-0.0.10-py3-none-any.whl
Algorithm Hash digest
SHA256 b767812b380fddc0aee00dbac4ae9a57d680904c35960b6b84b2c9a8039883bd
MD5 e0de399a7b91d56c915ae2b16a5e5bf5
BLAKE2b-256 19f8a9aabb56a5e3433f91ca75ed104dd8ba7543157dfde23254169b47e5e785

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