trinity.trainer.verl.monkey_patch module#
- trinity.trainer.verl.monkey_patch.load_valuehead_model(local_path, torch_dtype, model_config, trust_remote_code, use_meta=False)[source]#
- trinity.trainer.verl.monkey_patch.left_right_2_no_padding(data: TensorDict) TensorDict[source]#
Convert TensorDict from left-right padding to no-padding format.
- Parameters:
data ā TensorDict with āinput_idsā, āattention_maskā, āresponse_maskā, āposition_idsā
- Returns:
TensorDict with - Tensor includes NestedTensors like āinput_idsā, āloss_maskā, āposition_idsā - NonTensorData includes āmax_seq_lenā, āmax_response_lenā, āindicesā
- Return type:
data
Note: 1. the return input_ids/position_ids/loss_mask are nested tensor. 2. we will remove āattention_maskā, āresponseā in the return data, but āresponse_maskā is kept.
- trinity.trainer.verl.monkey_patch.save_checkpoint(self, local_path: str, hdfs_path: str | None = None, global_step: int = 0, max_ckpt_to_keep: int | None = None, **kwargs) None[source]#
Save FSDP checkpoint, handling parameter offload as needed.
- trinity.trainer.verl.monkey_patch.get_seq_idx(cu_seqlens: Tensor, total_nnz: int) Tensor[source]#
Build
seq_idxfromcu_seqlens, mapping each packed position to its original sequence id.- Parameters:
cu_seqlens ā Shape
(batch + 1,). Cumulative sequence lengths.total_nnz ā Total number of packed tokens, i.e.
cu_seqlens[-1].
- Returns:
Shape
(total_nnz,), where each position is the original sequence id (0-indexed). For example, cu_seqlens=[0,3,7,10] -> [0,0,0,1,1,1,1,2,2,2].
- trinity.trainer.verl.monkey_patch.prepare_model_inputs(self, micro_batch: TensorDict)[source]#
Rewritten
FSDPEngineWithLMHead.prepare_model_inputsthat injectsseq_idxandcu_seqlensinto model_inputs for packed-sequence models (e.g. Qwen3.5 GateDeltaNet).This is a full rewrite (not a wrapper) so that the Ulysses SP pad_size adjustment on
seq_idx/cu_seqlensis handled inline, right afterulysses_pad_and_slice_inputsreturnspad_size.