Skip to main content

Generative Models using Jax

Project description

generax

generax provides implementations of flow based generative models. The library is built on top of Equinox which removes the need to worry about keeping track of model parameters.

key = random.PRNGKey(0) # JAX random key
x = ... # some data

# Create a flow model
model = NeuralSpline(input_shape=x.shape[1:],
                     n_flow_layers=3,
                     n_blocks=4,
                     hidden_size=32,
                     working_size=16,
                     n_spline_knots=8,
                     key=key)

# Data dependent initialization
model = model.data_dependent_init(x, key=key)

# Take multiple samples using vmap
keys = random.split(key, 1000)
samples = eqx.filter_vmap(model.sample)(keys)

# Compute the log probability of data
log_prob = eqx.filter_vmap(model.log_prob)(x)

There is also support for probability paths (time-dependent probability distributions) which can be used to train continuous normalizing flows with flow matching. See the examples on flow matching and multi-sample flow matching for more details.

Samples

Installation

generax is available on pip:

pip install generax

Training

Generax provides an easy interface to train these models:

trainer = Trainer(checkpoint_path='tmp/model_path')

model = trainer.train(model=model,              # Generax model
                      objective=my_objective,   # Objective function
                      evaluate_model=tester,    # Testing function
                      optimizer=optimizer,      # Optax optimizer
                      num_steps=10000,          # Number of training steps
                      data_iterator=train_ds,   # Training data iterator
                      double_batch=1000,        # Train these many batches in a scan loop
                      checkpoint_every=1000,    # Checkpoint interval
                      test_every=1000,          # Test interval
                      retrain=True)             # Retrain from checkpoint

See the examples folder for more details.

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

generax-0.0.4.tar.gz (44.5 kB view details)

Uploaded Source

Built Distribution

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

generax-0.0.4-py3-none-any.whl (73.6 kB view details)

Uploaded Python 3

File details

Details for the file generax-0.0.4.tar.gz.

File metadata

  • Download URL: generax-0.0.4.tar.gz
  • Upload date:
  • Size: 44.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.13

File hashes

Hashes for generax-0.0.4.tar.gz
Algorithm Hash digest
SHA256 f046fdd9afc9cc809d3d163452e83ec913f873165bd8ec823a64353df3296c5f
MD5 4076173ab7c4178049c1da9aae6e7cb1
BLAKE2b-256 6242316a95439e4dbf98df173341564dc88e180ea5d6bd338ffeb9789ae77292

See more details on using hashes here.

File details

Details for the file generax-0.0.4-py3-none-any.whl.

File metadata

  • Download URL: generax-0.0.4-py3-none-any.whl
  • Upload date:
  • Size: 73.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.13

File hashes

Hashes for generax-0.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 079435eb1ef2bda1f0f43dfe661d5d4414cc7ffd1f3a207e55c18ab4d03fb43b
MD5 588c95a7d50df58708e3c6b664fa69a5
BLAKE2b-256 8fb9fc2e173f27666f9ff45f9bb9eec9737d9a2fa717f2b7ec5fc3b69799270a

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