encode_with_qwen3

Encode prompts with the Qwen3 encoder for FLUX.2

Description

Tokenizes with the chat template, runs the encoder with the padding mask, and concatenates the requested mid-stack hidden states per token, matching Flux2KleinPipeline._get_qwen3_prompt_embeds.

Usage

encode_with_qwen3(prompts, model, tokenizer, max_sequence_length = 512L,
                  out_layers = c(9L, 18L, 27L), device = NULL)

Arguments

  • prompts: Character vector.
  • model: A qwen3_encoder.
  • tokenizer: A qwen_bpe_tokenizer.
  • max_sequence_length: Integer. Fixed token length (klein: 512).
  • out_layers: Integer vector. Hidden-state layers (klein-4B: 9, 18, 27).
  • device: Device for the input ids (defaults to the model’s).

Value

Tensor [length(prompts), max_sequence_length, 3 * hidden_size].