MCPcopy Create free account
hub / github.com/BeastyZ/ConvSearch-R1 / make_iterator

Method make_iterator

verl/verl/protocol.py:450–487  ·  view source on GitHub ↗

r"""Make an iterator from the DataProto. This is built upon that TensorDict can be used as a normal Pytorch dataset. See https://pytorch.org/tensordict/tutorials/data_fashion for more details. Args: mini_batch_size (int): mini-batch size when iterating the dataset. We r

(self, mini_batch_size, epochs, seed=None, dataloader_kwargs=None)

Source from the content-addressed store, hash-verified

448 return self
449
450 def make_iterator(self, mini_batch_size, epochs, seed=None, dataloader_kwargs=None):
451 r"""Make an iterator from the DataProto. This is built upon that TensorDict can be used as a normal Pytorch
452 dataset. See https://pytorch.org/tensordict/tutorials/data_fashion for more details.
453
454
455 Args:
456 mini_batch_size (int): mini-batch size when iterating the dataset. We require that ``batch.batch_size[0] % mini_batch_size == 0``.
457 epochs (int): number of epochs when iterating the dataset.
458 dataloader_kwargs (Any): internally, it returns a DataLoader over the batch. The dataloader_kwargs is the kwargs passed to the DataLoader.
459
460 Returns:
461 Iterator: an iterator that yields a mini-batch data at a time. The total number of iteration steps is ``self.batch.batch_size * epochs // mini_batch_size``
462 """
463 assert self.batch.batch_size[0] % mini_batch_size == 0, f"{self.batch.batch_size[0]} % {mini_batch_size} != 0"
464 # we can directly create a dataloader from TensorDict
465 if dataloader_kwargs is None:
466 dataloader_kwargs = {}
467
468 if seed is not None:
469 generator = torch.Generator()
470 generator.manual_seed(seed)
471 else:
472 generator = None
473
474 assert isinstance(dataloader_kwargs, Dict)
475 train_dataloader = DataLoader(dataset=self,
476 batch_size=mini_batch_size,
477 collate_fn=collate_fn,
478 generator=generator,
479 **dataloader_kwargs)
480
481 def get_data():
482 for _ in range(epochs):
483 for d in train_dataloader:
484 d.meta_info = self.meta_info
485 yield d
486
487 return iter(get_data())
488
489 def chunk(self, chunks: int) -> List['DataProto']:
490 """Split the batch among dim=0 into chunks. The meta_info is passed to each DataProto after split.

Callers 3

Calls

no outgoing calls

Tested by 1