nemo_automodel.components.models.flux3.text_encoding
nemo_automodel.components.models.flux3.text_encoding
FLUX.3 Qwen3-VL text-encoding helpers shared by the preprocessing processors.
FLUX.3 conditions on stacked Qwen3-VL hidden states: the prompt goes through the chat template, is right-padded to a multiple of 80 tokens, and evenly spaced hidden layers (derived from the checkpoint geometry) are concatenated per token.
Module Contents
Classes
Functions
Data
API
Bases: typing.TypedDict
Frozen image-small text encoder, processor, and selected hidden layers.
Encode a prompt with FLUX3’s training-time text-conditioning semantics.
Each prompt is right-padded to a multiple of 80 tokens. Explicit Qwen position IDs keep padding tokens at position 1, including with Transformers versions that would otherwise assign them position 0.
Parameters:
Caption used to condition image generation.
Frozen text encoder, processor, and hidden-layer indices.
Device used for text encoding.
Returns: torch.Tensor
FP16 CPU tensor of shape [sequence, joint_attention_dim], where sequence
Load the FLUX.3 Qwen3-VL text stack from a resolved modular snapshot dir.
Parameters:
Resolved local snapshot dir of the FLUX.3 modular checkpoint.
Device to load the text encoder on.
Returns: Flux3TextStack
Dict with ‘text_encoder’ (Qwen3VLForConditionalGeneration), ‘tokenizer’
Derive the text-encoder hidden layers to stack from checkpoint geometry.
FLUX.3 conditions on joint_attention_dim / hidden_size stacked hidden
layers, evenly spaced through the encoder depth. For the released
checkpoint (Qwen3-VL-4B: 36 layers, hidden 2560, joint 20480) this yields
the pipeline default (4, 8, …, 32); for tiny test checkpoints it scales
down consistently.
Parameters:
Transformer’s text-embedding channel width.
Text encoder hidden size.
Text encoder layer count.
Returns: tuple[int, ...]
Tuple of hidden-state indices to stack, in ascending order.
Raises:
ValueError: If the checkpoint geometry is inconsistent (dim not a multiple of hidden size, or more stacked layers than the encoder has).