Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:Deepseek ai Janus Apply Sft Template

From Leeroopedia


Knowledge Sources
Domains NLP, Image_Generation
Last Updated 2026-02-10 09:30 GMT

Overview

Concrete tool for formatting conversation messages into the SFT prompt template provided by the Janus VLChatProcessor, used for autoregressive image generation.

Description

The VLChatProcessor.apply_sft_template_for_multi_turn_prompts method formats a list of conversation message dicts into a single prompt string using the registered conversation template. For image generation, the image_start_tag property ("<begin_of_image>") is appended after the formatted prompt to trigger the generation mode.

Usage

Call this method when preparing a text prompt for autoregressive image generation. The returned string (with appended image start tag) is then tokenized and used for the CFG input preparation step.

Code Reference

Source Location

  • Repository: Janus
  • File: janus/models/processing_vlm.py
  • Lines: L137-177 (apply_sft_template_for_multi_turn_prompts), L198-200 (image_start_tag property)

Signature

class VLChatProcessor(ProcessorMixin):
    def apply_sft_template_for_multi_turn_prompts(
        self,
        conversations: List[Dict[str, str]],
        sft_format: str = "deepseek",
        system_prompt: str = "",
    ) -> str:
        """
        Format conversations into SFT prompt string.

        Args:
            conversations: Message dicts with "role" and "content" keys
            sft_format: Template name (default "deepseek")
            system_prompt: Optional system message (default "")

        Returns:
            str: Formatted prompt string
        """

    @property
    def image_start_tag(self) -> str:
        """Returns '<begin_of_image>' token string."""

Import

from janus.models import VLChatProcessor

I/O Contract

Inputs

Name Type Required Description
conversations List[Dict[str, str]] Yes Message dicts with "role" and "content"
sft_format str No Template name (default "deepseek")
system_prompt str No System message (default "" for generation)

Outputs

Name Type Description
sft_prompt str Formatted prompt string (before image_start_tag append)
prompt (with tag) str sft_prompt + image_start_tag — ready for tokenization

Usage Examples

Autoregressive Image Generation Prompt

conversation = [
    {"role": "User", "content": "A photo of a sunset over the ocean."},
    {"role": "Assistant", "content": ""},
]

sft_format = vl_chat_processor.apply_sft_template_for_multi_turn_prompts(
    conversations=conversation,
    sft_format=vl_chat_processor.sft_format,
    system_prompt="",
)
prompt = sft_format + vl_chat_processor.image_start_tag
# Result: "<|User|>: A photo of a sunset over the ocean.\n\n<|Assistant|>:<begin_of_image>"

Related Pages

Implements Principle

Uses Heuristic

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment