Skip to content

dew.data.prompts

Prompts for online RL: fixed-width rows with their reward context.

A Prompts source reads a parquet file or in-memory JSON rows in the verl layout. Each row becomes a left-padded prompt of max_prompt_len ids with its prompt_length, and the reward columns data_source, ground_truth and extra_info as fixed-width UTF-8 byte arrays, so every leaf survives the device transfer.

A row’s prompt is messages rendered with the tokenizer’s chat template and generation prompt, a string encoded on its own, or token ids used as they are. Chat messages use the SFT parser and carry optional top-level tools schemas into the template. Text parts join in order; nontext parts require a processor and are refused before truncation. Prompts longer than the window keep their tail, and the three reward columns default to the empty string when the row lacks them.

NameSummary
PROMPT_LENThe ids a rendered prompt is laid out in where none is asked for (RenderPrompt).
PROMPT_PADThe id a rendered prompt is left-padded with where none is asked for.
PROMPT_LONGWhat a prompt longer than its ids becomes where none is asked for: its tail.
PROMPT_KEYBatch key the prompts pipeline left-pads [B, max_prompt_len] ids under.
LENGTH_KEYBatch key holding each row’s real token count before padding.
SOURCE_KEYBatch key holding the reward’s rule name as UTF-8 bytes.
TRUTH_KEYBatch key holding the reference answer as UTF-8 bytes.
INFO_KEYBatch key holding the reward’s extra context as UTF-8 bytes.
PromptRecordWhat a reward is told about the prompt it scores, read from the prompt’s row.
FIELDSThe fields prompt encoding reads, leaving the others unchanged.
encodeA record step that renders a prompt row (verl’s columns: “prompt”, “data_source”, “ground_truth”, …) to max_prompt_len left-padded ids, keeping a longer one’s tail, or dropping it (long="drop"), counted as a rejection.
RewardWidthThe bytes the widest reward string of a store’s prompt rows takes, its data source, ground truth and extra info, at least one: the width each row’s reward columns are padded to, so every row fits whole (Configured.measures).

attribute source

PROMPT_LEN = 256

The ids a rendered prompt is laid out in where none is asked for (RenderPrompt).

attribute source

PROMPT_PAD = 0

The id a rendered prompt is left-padded with where none is asked for.

attribute source

PROMPT_LONG: Literal['drop', 'truncate'] = 'truncate'

What a prompt longer than its ids becomes where none is asked for: its tail.

attribute source

PROMPT_KEY = 'prompt'

Batch key the prompts pipeline left-pads [B, max_prompt_len] ids under.

attribute source

LENGTH_KEY = 'prompt_length'

Batch key holding each row’s real token count before padding.

attribute source

SOURCE_KEY = 'data_source'

Batch key holding the reward’s rule name as UTF-8 bytes.

attribute source

TRUTH_KEY = 'ground_truth'

Batch key holding the reference answer as UTF-8 bytes.

attribute source

INFO_KEY = 'extra_info'

Batch key holding the reward’s extra context as UTF-8 bytes.

dataclass source

class PromptRecord(data_source: str = '', ground_truth: str = '', extra_info: str = '')

What a reward is told about the prompt it scores, read from the prompt’s row.

data_source names the row’s dataset or rule, ground_truth is its reference answer as the source normalized it, and extra_info is any other context the row carries, each the empty string where the row lacks it. A reward reads the fields it needs.

def of(data_source: JSON, ground_truth: JSON, extra_info: JSON) -> PromptRecord

The record of a row’s three values as a prompt batch stores them: a string is itself, a missing one is empty, and any other value travels as its JSON (_text).

def from_row(row: Mapping[str, object]) -> PromptRecord

The record of a prompt row (verl’s columns): its data source, its reference answer, top-level or in reward_model, and its extra info with its ability folded in. Measuring the reward width (RewardWidth) and rendering a row (RenderPrompt) read it alike.

def columns() -> Mapping[str, str]

Its three values under the batch keys a prompt batch stores them by.

def width() -> int

The bytes its widest value takes in UTF-8.

attribute source

FIELDS = ('prompt', 'data_source', 'ground_truth', 'extra_info', 'tools', 'reward_model')

The fields prompt encoding reads, leaving the others unchanged.

verl’s RL parquet (rl_dataset.py, reward_loop/reward_manager/naive.py L42-L46 at 12ebe0c) nests the answer as reward_model.ground_truth and keeps tools_kwargs inside extra_info.

function source

def encode(
tokenizer: str | PreTrainedTokenizerBase,
*,
max_prompt_len: int = PROMPT_LEN,
pad_id: int = PROMPT_PAD,
long: Literal['drop', 'truncate'] = PROMPT_LONG,
thinking: bool | None = None,
) -> RenderPrompt

A record step that renders a prompt row (verl’s columns: “prompt”, “data_source”, “ground_truth”, …) to max_prompt_len left-padded ids, keeping a longer one’s tail, or dropping it (long="drop"), counted as a rejection.

dataclass source

class RewardWidth()

The bytes the widest reward string of a store’s prompt rows takes, its data source, ground truth and extra info, at least one: the width each row’s reward columns are padded to, so every row fits whole (Configured.measures).