Instructions to use flax-community/t5-vae-python with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use flax-community/t5-vae-python with Transformers:
# pip install -U transformers accelerate # Load model directly from transformers import T5VaeForAutoencoding model = T5VaeForAutoencoding.from_pretrained("flax-community/t5-vae-python", device_map="auto") - Notebooks
- Google Colab
- Kaggle
Download model/vae.py from flax-community/t5-vae-python: direct link, hf CLI and curl.
- Browser
- Download file 1.09 kB
-
https://huggingface.co/flax-community/t5-vae-python/resolve/2a2a24e12e68b276f3a4cea4e967208172e2cbab/model/vae.py
- Command line
-
hf download hf://flax-community/t5-vae-python@2a2a24e12e68b276f3a4cea4e967208172e2cbab/model/vae.py
-
curl -L -o vae.py https://huggingface.co/flax-community/t5-vae-python/resolve/2a2a24e12e68b276f3a4cea4e967208172e2cbab/model/vae.py
1.09 kB
| import jax.numpy as jnp | |
| import flax.linen as nn | |
| from model.encoders import VAE_ENCODER_MODELS | |
| from model.decoders import VAE_DECODER_MODELS | |
| from model.config import T5VaeConfig | |
| class VAE(nn.Module): | |
| # see https://github.com/google/flax#what-does-flax-look-like | |
| """ | |
| An MMD-VAE used with encoder-decoder models. | |
| Encodes all token encodings into a single latent & spits them back out. | |
| """ | |
| config: T5VaeConfig | |
| dtype: jnp.dtype = jnp.float32 # the dtype of the computation | |
| def setup(self): | |
| self.encoder = VAE_ENCODER_MODELS[self.config.vae_encoder_model](self.config.latent_token_size, self.config.n_latent_tokens) | |
| self.decoder = VAE_DECODER_MODELS[self.config.vae_decoder_model](self.config.t5.d_model, self.config.n_latent_tokens) | |
| def __call__(self, encoding=None, latent_codes=None): | |
| latent_codes = self.encode(encoding) | |
| return self.decode(latent_codes), latent_codes | |
| def encode(self, encoding): | |
| return self.encoder(encoding) | |
| def decode(self, latent): | |
| return self.decoder(latent) | |