The [Redacted Person] model architecture decouples visual encoding for unified multimodal understanding and generation. It uses separate visual encoders for understanding and generation tasks within a single transformer architecture. JanusFlow builds upon Janus by integrating rectified flow for improved image generation.
[Redacted Person] Architecture:
-
Vision Understanding Encoder: Processes images for understanding tasks. Uses models like CLIPVisionTower (often based on SigLIP-ViT or other ViTs) or ShallowUViTEncoder to extract image features. These features are then projected to the language model's embedding space using a linear layer (vision_und_enc_aligner). A learned embedding signifying the beginning of an understanding image sequence is prepended to the image embeddings.
-
Vision Generation Encoder: Processes the image during generation. This component is absent in the initial Janus model and is introduced in JanusFlow. It uses a ShallowUViTEncoder along with a linear projection layer (vision_gen_enc_aligner). In Janus (without the flow component), image generation relies directly on the language model and a generation head.
-
Vision Generation Decoder: Used during generation in JanusFlow. A ShallowUViTDecoder takes the output of the vision generation encoder and refines it, ultimately producing an image. This decoder is employed in the rectified flow process.
-
Language Model: A causal language model (like [Redacted Person]) forms the core of the architecture, handling text processing and generation. It receives both text and image embeddings as input.
-
Vision Generation Head (Janus): In the generation mode of the original Janus (without flow), a linear projection head (vision_head) maps the language model's output to image token embeddings. These embeddings are then used by a separate image generation model (e.g., a VQ-GAN or diffusion model) to produce the image.
-
Vision Embedding Alignment: Linear layers (aligners) project the outputs of the vision encoders to the language model's embedding space, enabling seamless integration of visual and textual information. Specific examples include the vision_und_enc_aligner, vision_gen_enc_aligner, and vision_gen_dec_aligner within the JanusFlow model.
-
Rectified Flow (JanusFlow): This component in JanusFlow facilitates image generation by iteratively refining a random image representation (z). In each step, z is encoded, combined with the text embedding, and passed through the language model. The output is then used to predict a change (v) in z. The process repeats, effectively guiding z towards a representation that corresponds to the text prompt. Finally, a VAE decodes the refined z to produce the final image.
Loss Function:
The loss function aims to optimize both understanding and generation capabilities.
-
Understanding Loss: Standard cross-entropy loss is used for language modeling tasks, applied to the language model's output on understanding tasks.
-
Generation Loss: In Janus (without flow), the loss is based on the difference between predicted image tokens and the actual tokens from a separate image generation model. In JanusFlow, the loss focuses on training the rectified flow component. It aims to minimize the difference between the predicted change (v) in the latent representation z and the "true" change derived from the input text embeddings.
-
VQ Loss and Commit Loss (if applicable): If a Vector Quantized (VQ) model is used for image generation (like in the original Janus), the loss also includes VQ loss (to ensure accurate quantization) and commit loss (to prevent codebook collapse). JanusFlow uses a diffusion-based VAE, so these losses are not relevant in its context.
The code provides functionalities to prepare inputs for both understanding and generation tasks, handling the appropriate formatting and embedding of text and images for the model. The VLChatProcessor class specifically addresses these pre- and post-processing steps, incorporating special tokens for image placeholders and sequence beginnings/ends.