Implementation:Deepseek ai Janus Apply Sft Template JanusFlow
| Knowledge Sources | |
|---|---|
| Domains | NLP, Image_Generation |
| Last Updated | 2026-02-10 09:30 GMT |
Overview
Concrete tool for formatting conversation prompts using the JanusFlow VLChatProcessor's SFT template for rectified flow generation.
Description
The JanusFlow VLChatProcessor.apply_sft_template_for_multi_turn_prompts method formats conversations identically to the standard Janus processor. The image_start_tag ("<begin_of_image>") is appended to trigger generation. The JanusFlow processor also defines image_gen_tag ("<|begin▁of▁generation|>") at processing_vlm.py:L91.
Usage
Call this method before CFG input preparation in the JanusFlow generation pipeline.
Code Reference
Source Location
- Repository: Janus
- File: janus/janusflow/models/processing_vlm.py
- Lines: L159-199 (apply_sft_template_for_multi_turn_prompts), L89 (image_start_tag), L91 (image_gen_tag)
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."""
@property
def image_start_tag(self) -> str:
"""Returns '<begin_of_image>'."""
@property
def image_gen_tag(self) -> str:
"""Returns '<|begin▁of▁generation|>'."""
Import
from janus.janusflow.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 "") |
Outputs
| Name | Type | Description |
|---|---|---|
| prompt | str | SFT-formatted prompt + image_start_tag, ready for tokenization |
Usage Examples
JanusFlow Prompt Formatting
messages = [
{'role': 'User', 'content': 'A beautiful mountain landscape at sunset'},
{'role': 'Assistant', 'content': ''}
]
text = vl_chat_processor.apply_sft_template_for_multi_turn_prompts(
conversations=messages,
sft_format=vl_chat_processor.sft_format,
system_prompt=''
)
text = text + vl_chat_processor.image_start_tag
input_ids = torch.LongTensor(tokenizer.encode(text))