Downloads · 30 days
7
10% of all-time downloads
jcopo/flux_jax
flux_jax is a text-to-image model from jcopo. Use it when you need an image from a text prompt. It is set up for diffuse. The card lists the license as other.
Downloads · 30 days
7
10% of all-time downloads
All-time downloads
72
Public
Repo size
26.6 GB
Likes
0
Public
Click a slice to open those files.
Other26.6 GB · 100%
From the Hugging Face model README
This repository contains a FLUX.1-dev text-to-image diffusion model stored in Orbax/JAX format, optimized for use with JAX/Flax frameworks.
FLUX.1-dev is a powerful text-to-image generation model that uses a transformer-based architecture with dual text encoders (CLIP and T5) for enhanced text understanding and image generation capabilities.
This model includes the following components:
To use this model, you should use the Diffuse library, which provides an easy-to-use interface for FLUX models.
For a comprehensive tutorial on using FLUX models with Diffuse, please refer to: FLUX Tutorial Documentation
This model is stored in Orbax checkpoint format, optimized for JAX/Flax frameworks. The Diffuse library handles loading and inference automatically.
Install the Diffuse library:
pip install git+https://github.com/jcopo/diffuse.git
import jax
from pathlib import Path
from huggingface_hub import snapshot_download
from diffuse import FluxModelLoader, FluxTimer, Flow, Predictor, Denoiser
from diffuse.integrators import EulerIntegrator
from diffuse.utils import _latent_shapes
# ===========================
# 1. Download Model
# ===========================
HF_REPO_ID = "jcopo/flux_jax"
checkpoint_dir = Path(snapshot_download(repo_id=HF_REPO_ID, repo_type="model"))
# ===========================
# 2. Set Generation Parameters
# ===========================
PROMPT = "A serene landscape with mountains at sunset, highly detailed, photorealistic"
HEIGHT = 512
WIDTH = 512
NUM_STEPS = 20
GUIDANCE_SCALE = 4.0
SEED = 42
# ===========================
# 3. Load Model and Prepare Network
# ===========================
loader = FluxModelLoader(checkpoint_dir=checkpoint_dir, verbose=True)
conditioned = loader.prepare_conditioned_network(
prompt=PROMPT,
negative_prompt=None,
guidance_scale=GUIDANCE_SCALE,
height=HEIGHT,
width=WIDTH,
)
# ===========================
# 4. Setup Diffusion Components
# ===========================
_, transformer_hw = _latent_shapes(HEIGHT, WIDTH)
image_seq_len = transformer_hw[0] * transformer_hw[1]
# Initialize timer with dynamic shift
timer = FluxTimer(num_steps=NUM_STEPS, use_dynamic_shift=True)
timer.set_image_seq_len(image_seq_len)
# Create flow model and predictor
flow = Flow(tf=1.0)
predictor = Predictor(
model=flow,
network=conditioned.network_fn,
prediction_type="velocity",
)
# Create integrator and denoiser
integrator = EulerIntegrator(model=flow, timer=timer)
denoiser = Denoiser(
integrator=integrator,
model=flow,
predictor=predictor,
x0_shape=(transformer_hw[0], transformer_hw[1], conditioned.in_channels),
)
# ===========================
# 5. Generate Image
# ===========================
key = jax.random.PRNGKey(SEED)
state, _ = denoiser.generate(
rng_key=key,
n_steps=NUM_STEPS,
n_particles=1,
keep_history=False,
)
# Get latent from generation
latent = state.integrator_state.position
# ===========================
# 6. Decode to Image
# ===========================
image = loader.decode_latent(latent)
print(f"Generated image shape: {image.shape}")
# Save image (image is a numpy array in [0, 1] range)
from PIL import Image
img = Image.fromarray((image * 255).astype('uint8'))
img.save("output.png")
Please refer to the original FLUX.1-dev license terms for usage restrictions and guidelines.
If you use this model in your research, please cite the original FLUX paper and the Diffuse library.
@software{diffuse2024,
title = {Diffuse: A modular diffusion model library},
author = {Iollo, J., Oudoumanessah G.},
year = {2025},
url = {https://github.com/jcopo/diffuse}
}