nemo_automodel.components.models.flux3.preprocessing
nemo_automodel.components.models.flux3.preprocessing
FLUX.3 image-edit (img2img) cache encoder.
Encodes generic image-edit manifests (one target image, one context/source
image, one instruction prompt per row) into the cached contract read by
ImageEditDataset:
target_latent: patchified + BN-normalized FLUX.2-VAE latent [128, H/16, W/16]context_latents: single-entry list with the conditioning image latent in the same space (fed to the transformer’simage_condstream with l = -1 position ids and timestep 0)prompt_embeddings/prompt_attention_mask: stacked Qwen3-VL hidden states [sequence, joint_attention_dim] with an all-ones mask — FLUX.3 conditions on every padded position, matching the reference pipeline.
Module Contents
Classes
Functions
Data
API
Encode image-edit manifests into the FLUX.3 img2img cached contract.
Loads only the frozen FLUX.2 image VAE and Qwen3-VL text stack from the modular checkpoint; the trainable transformer is never loaded.
Encode one RGB image into the patchified + BN-normalized latent space.
Parameters:
Dict containing ‘vae’, ‘bn_mean’, ‘bn_std’.
PIL RGB image, already resized to 16-aligned dimensions.
Encoding device.
Returns: torch.Tensor
Latent tensor of shape [128, H/16, W/16], FP32, on CPU.
Encode one worker’s manifest shard on its assigned device.
Encode and persist one image-edit example.
Parameters:
Loaded VAE + text stack from _load_models.
Validated target/context media references and prompt.
Cache root for the emitted tensor payload.
Maximum pixel area without a preset.
Optional fixed square preset.
Runtime device for VAE and text encoding.
Whether to run finite-value checks on the cached latents.
Returns: Flux3EditRecord
Index record with cache path, compound bucket signature, and token
Load the frozen FLUX.2 image VAE and Qwen3-VL text stack.
Resolve the runtime device owned by an encoder worker.
Encode a generic image-edit manifest into cached FLUX.3 tensors.
Parameters:
JSONL manifest whose rows contain an ID, prompt, ordered role-to-file media mappings, and provenance metadata.
Destination for cache tensors and indexes.
Maximum pixel area when no fixed preset is selected.
Optional fixed square preset such as "512p";
target and context images are center-cropped to that shape.
Number of encoder workers (one CUDA device each).
Whether to run finite-value checks on each cached latent.
Returns: Path
Path to metadata.json whose shards index target latents of
Split samples across CUDA workers and merge their index records.
Encode one worker’s shard in a spawned subprocess.
Read and validate every image-edit JSONL row.
Each row must reference exactly one target and exactly one context
image; condition entries (used by VL-conditioned models like
Qwen-Image-Edit) are not part of the FLUX.3 contract and are rejected.
Resize an image for VAE encoding with 16-aligned dimensions.
Parameters:
PIL image (any mode; converted to RGB).
Maximum pixel area when no preset is selected.
Optional fixed square preset key.
Returns: Image
RGB PIL image whose dimensions are multiples of 16. Presets produce an
Write one JSON value through a same-directory temporary file.
Write deterministic cache-index shards and return relative names.
Convert latents to patchified format (2x2 spatial patch -> channel).
Parameters:
Tensor of shape [batch, channels, height, width].
Returns: torch.Tensor
Tensor of shape [batch, channels*4, height//2, width//2].