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.
| Name | Summary |
|---|---|
PROMPT_LEN | The ids a rendered prompt is laid out in where none is asked for (RenderPrompt). |
PROMPT_PAD | The id a rendered prompt is left-padded with where none is asked for. |
PROMPT_LONG | What a prompt longer than its ids becomes where none is asked for: its tail. |
PROMPT_KEY | Batch key the prompts pipeline left-pads [B, max_prompt_len] ids under. |
LENGTH_KEY | Batch key holding each row’s real token count before padding. |
SOURCE_KEY | Batch key holding the reward’s rule name as UTF-8 bytes. |
TRUTH_KEY | Batch key holding the reference answer as UTF-8 bytes. |
INFO_KEY | Batch key holding the reward’s extra context as UTF-8 bytes. |
PromptRecord | What a reward is told about the prompt it scores, read from the prompt’s row. |
FIELDS | The fields prompt encoding reads, leaving the others unchanged. |
encode | 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. |
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). |
PROMPT_LEN
Section titled “PROMPT_LEN”PROMPT_LEN = 256The ids a rendered prompt is laid out in where none is asked for (RenderPrompt).
PROMPT_PAD
Section titled “PROMPT_PAD”PROMPT_PAD = 0The id a rendered prompt is left-padded with where none is asked for.
PROMPT_LONG
Section titled “PROMPT_LONG”PROMPT_LONG: Literal['drop', 'truncate'] = 'truncate'What a prompt longer than its ids becomes where none is asked for: its tail.
PROMPT_KEY
Section titled “PROMPT_KEY”PROMPT_KEY = 'prompt'Batch key the prompts pipeline left-pads [B, max_prompt_len] ids under.
LENGTH_KEY
Section titled “LENGTH_KEY”LENGTH_KEY = 'prompt_length'Batch key holding each row’s real token count before padding.
SOURCE_KEY
Section titled “SOURCE_KEY”SOURCE_KEY = 'data_source'Batch key holding the reward’s rule name as UTF-8 bytes.
TRUTH_KEY
Section titled “TRUTH_KEY”TRUTH_KEY = 'ground_truth'Batch key holding the reference answer as UTF-8 bytes.
INFO_KEY
Section titled “INFO_KEY”INFO_KEY = 'extra_info'Batch key holding the reward’s extra context as UTF-8 bytes.
PromptRecord
Section titled “PromptRecord”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.
PromptRecord.of
Section titled “PromptRecord.of”def of(data_source: JSON, ground_truth: JSON, extra_info: JSON) -> PromptRecordThe 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).
PromptRecord.from_row
Section titled “PromptRecord.from_row”def from_row(row: Mapping[str, object]) -> PromptRecordThe 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.
PromptRecord.columns
Section titled “PromptRecord.columns”def columns() -> Mapping[str, str]Its three values under the batch keys a prompt batch stores them by.
PromptRecord.width
Section titled “PromptRecord.width”def width() -> intThe bytes its widest value takes in UTF-8.
FIELDS
Section titled “FIELDS”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.
encode
Section titled “encode”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,) -> RenderPromptA 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.
RewardWidth
Section titled “RewardWidth”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).