MCPcopy Create free account
hub / github.com/ray-project/ray / _create_iterator

Method _create_iterator

python/ray/data/iterator.py:245–307  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

243 batch_format = _apply_batch_format(batch_format)
244
245 def _create_iterator() -> Iterator[DataBatch]:
246 time_start = time.perf_counter()
247
248 # Iterate through the dataset from the start each time
249 # _iterator_gen is called.
250 # This allows multiple iterations of the dataset without
251 # needing to explicitly call `iter_batches()` multiple times.
252 (
253 ref_bundles_iterator,
254 stats,
255 blocks_owned_by_consumer,
256 executor,
257 ) = self._to_ref_bundle_iterator()
258
259 dataset_tag = self._get_dataset_tag()
260
261 # Create a callback to report prefetched bytes to the executor's
262 # resource manager.
263 def make_prefetch_callback(exec):
264 def callback(num_bytes: int) -> None:
265 exec.set_external_consumer_bytes(num_bytes)
266
267 return callback
268
269 prefetch_bytes_callback = (
270 make_prefetch_callback(executor) if executor is not None else None
271 )
272 if prefetch_bytes_callback is not None:
273 # Register the external consumer with the executor's resource manager.
274 prefetch_bytes_callback(0)
275
276 batch_iterator = self._create_batch_iterator(
277 ref_bundles_iterator,
278 stats=stats,
279 dataset_tag=dataset_tag,
280 clear_block_after_read=blocks_owned_by_consumer,
281 batch_size=batch_size,
282 batch_format=batch_format,
283 drop_last=drop_last,
284 collate_fn=_collate_fn,
285 finalize_fn=_finalize_fn,
286 shuffle_buffer_min_size=local_shuffle_buffer_size,
287 shuffle_seed=local_shuffle_seed,
288 prefetch_batches=prefetch_batches,
289 prefetch_bytes_callback=prefetch_bytes_callback,
290 preserve_order=self.get_context().execution_options.preserve_order,
291 )
292
293 if stats:
294 stats.iter_initialize_s.add(time.perf_counter() - time_start)
295
296 try:
297 yield from batch_iterator
298 if stats:
299 stats.iter_total_s.add(time.perf_counter() - time_start)
300 finally:
301 # On early exit (e.g. ``break`` in the for-loop), the inner
302 # ``_ClosingIterator`` would only shut down the executor via

Callers

nothing calls this directly

Calls 6

_get_dataset_tagMethod · 0.95
get_contextMethod · 0.95
_on_iteration_endMethod · 0.95
addMethod · 0.45

Tested by

no test coverage detected