MCPcopy Create free account
hub / github.com/InternLM/InternBootcamp / repeat

Method repeat

verl/verl/protocol.py:982–1024  ·  view source on GitHub ↗

Repeat the batch data a specified number of times. Args: repeat_times (int): Number of times to repeat the data. interleave (bool): Whether to interleave the repeated data. Returns: DataProto: A new DataProto with repeated data.

(self, repeat_times=2, interleave=True)

Source from the content-addressed store, hash-verified

980 self.non_tensor_batch = {key: val[indices_np] for key, val in self.non_tensor_batch.items()}
981
982 def repeat(self, repeat_times=2, interleave=True):
983 """
984 Repeat the batch data a specified number of times.
985
986 Args:
987 repeat_times (int): Number of times to repeat the data.
988 interleave (bool): Whether to interleave the repeated data.
989
990 Returns:
991 DataProto: A new DataProto with repeated data.
992 """
993 if self.batch is not None:
994 if interleave:
995 # Interleave the data
996 repeated_tensors = {
997 key: tensor.repeat_interleave(repeat_times, dim=0) for key, tensor in self.batch.items()
998 }
999 else:
1000 # Stack the data
1001 repeated_tensors = {
1002 key: tensor.unsqueeze(0).expand(repeat_times, *tensor.shape).reshape(-1, *tensor.shape[1:])
1003 for key, tensor in self.batch.items()
1004 }
1005
1006 repeated_batch = TensorDict(
1007 source=repeated_tensors,
1008 batch_size=(self.batch.batch_size[0] * repeat_times,),
1009 )
1010 else:
1011 repeated_batch = None
1012
1013 repeated_non_tensor_batch = {}
1014 for key, val in self.non_tensor_batch.items():
1015 if interleave:
1016 repeated_non_tensor_batch[key] = np.repeat(val, repeat_times, axis=0)
1017 else:
1018 repeated_non_tensor_batch[key] = np.tile(val, (repeat_times,) + (1,) * (val.ndim - 1))
1019
1020 return type(self)(
1021 batch=repeated_batch,
1022 non_tensor_batch=repeated_non_tensor_batch,
1023 meta_info=self.meta_info,
1024 )
1025
1026 def unfold_column_chunks(self, n_split: int, split_keys: Optional[list[str]] = None):
1027 """Split along the second dim into `n_split`, unfold it to the first dim (batch dim)

Callers 15

test_single_turnFunction · 0.95
test_tool_agentFunction · 0.95
to_vectorMethod · 0.80
to_vectorMethod · 0.80
to_vectorMethod · 0.80
test_repeatFunction · 0.80
test_repeatFunction · 0.80

Calls

no outgoing calls

Tested by 10

test_single_turnFunction · 0.76
test_tool_agentFunction · 0.76
test_repeatFunction · 0.64
test_repeatFunction · 0.64