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)[源代码]#
trinity.trainer.verl.monkey_patch.left_right_2_no_padding(data: TensorDict) TensorDict[源代码]#

Convert TensorDict from left-right padding to no-padding format.

参数:

data -- TensorDict with "input_ids", "attention_mask", "response_mask", "position_ids"

返回:

TensorDict with - Tensor includes NestedTensors like "input_ids", "loss_mask", "position_ids" - NonTensorData includes "max_seq_len", "max_response_len", "indices"

返回类型:

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[源代码]#

Save FSDP checkpoint, handling parameter offload as needed.

trinity.trainer.verl.monkey_patch.get_seq_idx(cu_seqlens: Tensor, total_nnz: int) Tensor[源代码]#

Build seq_idx from cu_seqlens, mapping each packed position to its original sequence id.

参数:
  • cu_seqlens -- Shape (batch + 1,). Cumulative sequence lengths.

  • total_nnz -- Total number of packed tokens, i.e. cu_seqlens[-1].

返回:

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)[源代码]#

Rewritten FSDPEngineWithLMHead.prepare_model_inputs that injects seq_idx and cu_seqlens into 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_seqlens is handled inline, right after ulysses_pad_and_slice_inputs returns pad_size.

trinity.trainer.verl.monkey_patch.patch_verl_engine()[源代码]#