nemo_automodel.components.models.qwen_image_edit.preprocessing
nemo_automodel.components.models.qwen_image_edit.preprocessing
Offline cache encoder for Qwen/Qwen-Image-Edit-2511.
Module Contents
Classes
Functions
Data
API
Encode generic image-edit manifests into the cached contract.
The encoder loads only the upstream Diffusers VAE and Qwen2.5-VL conditioning stack. The trainable transformer is explicitly omitted.
Encode one worker’s deterministic manifest shard.
Parameters:
Validated manifest rows referencing local RGB images.
Cache root shared by workers; sample filenames are derived from globally unique row indices.
Maximum target/context pixel area without a preset.
Optional fixed square spatial preset.
CUDA device index owned by this worker.
Whether to decode and validate each target latent tensor of shape [channels, target_height, target_width].
Returns: list[_CacheRecord]
Metadata records describing every emitted target/context tensor
Encode and persist one instruction-based editing example.
Parameters:
Upstream pipeline holding the frozen VAE and Qwen2.5-VL conditioning stack.
Validated target/context/condition media references.
Cache root for the emitted tensor payload.
Maximum target/context pixel area without a preset.
Optional fixed square target/context preset.
Runtime device for VAE and text encoding.
Whether to decode the target latent tensor of shape [channels, target_height, target_width].
Returns: _CacheRecord
Index record containing the target/context tensor layouts and
Load only upstream VAE and Qwen2.5-VL conditioning components.
Resolve the runtime device owned by an encoder worker.
Encode a generic manifest into cached target/context/text 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. It may contain
the materialized source tree that owns manifest_path but no
prior cache artifacts.
Maximum target/context pixel area when no fixed preset is selected.
Optional fixed square benchmark preset such as
"1024p". When set, target and context images are center-
cropped to that exact spatial shape.
Number of independent encoder workers. Each worker owns one CUDA device and a private VAE/text encoder.
Whether to decode each target latent and validate its finite RGB tensor output.
Returns: Path
Path to metadata.json, whose shards index target tensors of
Bases: typing.TypedDict
Bases: typing.TypedDict
Encode round-robin manifest shards in spawned GPU workers.
Construct a private encoder and run one spawned GPU shard.
Encode one deterministic Qwen VAE latent.
Parameters:
Upstream Qwen VAE. Its input layout is [batch, 3, frames, height, width], and its latent layout is [batch, channels, frames, latent_height, latent_width].
RGB image in channels-last layout [height, width, channels].
VAE execution device.
Floating-point dtype for the returned cache tensor.
Returns: torch.Tensor
Normalized latent mode tensor of shape [channels, latent_height,
Convert an RGB image to a normalized channels-first tensor.
Parameters:
RGB image in channels-last layout [height, width, channels].
Output tensor device.
Output floating-point dtype.
Returns: torch.Tensor
Tensor of shape [1, 3, height, width] in the range [-1, 1].
Load each manifest-relative media file once as an RGB image.
Read and validate every generic image-edit JSONL row.
Match the upstream Qwen edit vision-conditioning resize.
Diffusers derives an aspect-preserving shape at the fixed 384-squared area and rounds both axes to the nearest multiple of 32. Matching that policy is required because the Qwen2.5-VL image grid changes the prompt embeddings.
Parameters:
RGB image in channels-last pixel layout [height, width, channels].
Returns: Image.Image
RGB image with the upstream 32-aligned conditioning dimensions.
Resize an RGB image to an aspect-preserving, 32-aligned pixel area.
Parameters:
RGB image in channels-last pixel layout [height, width, channels].
Approximate output pixel count.
Returns: Image.Image
RGB image in channels-last layout [target_height, target_width,
Resize an RGB image for a cached Qwen VAE latent.
Parameters:
RGB image in channels-last pixel layout [height, width, channels].
Maximum output pixel area without a preset.
Optional fixed square output preset.
Returns: Image.Image
RGB image in channels-last layout [target_height, target_width,
Return an optional provenance string shared by all manifest rows.
Return a required provenance string shared by all manifest rows.
Require a fresh cache while allowing CLI-owned materialized input.
The image-edit CLI may place its materialized source manifest inside the requested output directory before invoking the configured encoder. That source tree is intentionally retained for provenance. Cache-owned paths must not exist so encoding never overwrites prior outputs.
Decode a cached latent and require a finite RGB result.
Parameters:
Upstream Qwen VAE whose decoded tensor layout is [batch, 3, frames, height, width].
Normalized cache tensor of shape [channels, latent_height, latent_width].
VAE execution device.
Write one JSON value through a same-directory temporary file.
Write deterministic cache-index shards and return relative names.