Skip to main content

replace_janus_placeholders

Function replace_janus_placeholders 

Source
pub fn replace_janus_placeholders(
    input_ids: &[i64],
    config: &JanusPlaceholderConfig,
    device: Device,
) -> Result<JanusPlaceholderReplacement, Error>
Expand description

Replace Janus image placeholder tokens with proper token sequence

This follows the official Janus design:

  1. Find all <image_placeholder> tokens in input_ids
  2. Replace each with: <begin_of_image> + 576 x <image_token> + <end_of_image>
  3. Create masks for embedding replacement

§Arguments

  • input_ids - Original token IDs [seq_len]
  • config - Placeholder configuration with token IDs
  • device - Target device for tensors

§Returns

JanusPlaceholderReplacement with expanded tokens and masks