Skip to Content
MS-SWIFT × TWINKLE
数据格式
COMPONENTSMS-SWIFT × TWINKLE

模型输入

InputFeature 是 Template 编码后的输出、模型的输入,也是一个 TypedDict;Trajectory 继承它。

InputType = Union[List[List[int]], List[int], np.ndarray, torch.Tensor]

class InputFeature(TypedDict, total=False):
    input_ids: InputType
    attention_mask: InputType
    position_ids: InputType
    labels: InputType
    completion_mask: InputType
    loss_scale: InputType
    channel: Any
    length: int
    routed_experts: InputType
字段含义
input_idsmessages 按模板渲染后的 token 序列
attention_mask注意力掩码
position_ids位置编码;packing 或 padding-free 时用来区分拼在一条序列里的不同样本,每个样本从 0 重新计数
labels训练标签,已做左移(labels[i] 是位置 i 要预测的 token),不参与 loss 的位置为 -100
completion_mask布尔掩码,标出需要计算 loss 的 token(RL 中是策略生成的响应段)
loss_scale可选的逐 token 损失权重,见 LossScale
channel可选的样本分组,用于按通道统计损失
lengthinput_ids 长度
routed_expertsMoE 模型各 token 路由到的专家

多模态模型另带模型特定的数值字段(pixel_values、input_features 等),打包后的输入沿序列维拼接。字段名清单见 twinkle.data_format.tq_fields:TRANSFORMERS_INPUT_FIELDS 是 transformers 前向读取的字段,ROLLOUT_TRAIN_FIELDS 是 rollout 后附带的训练字段。