[python][torch] Add batch-first streaming datasets - #9365
Draft
XiaoHongbo-Hope wants to merge 1 commit into
Draft
Conversation
XiaoHongbo-Hope
marked this pull request as draft
August 23, 2026 15:53
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Purpose
Avoid per-row Python dictionary conversion in PyPaimon Torch streaming by allowing the dataset to yield PyArrow
RecordBatchobjects or dictionaries of Torch tensors.batch_format="row"remains the compatible default;"pyarrow"and"torch"enable batch streaming.batch_size=Nonepreserves native reader batches; otherwise batches are combined or sliced to the requested size.to_tensor_fn.DataLoader(batch_size=None)to avoid batching the data again.Implementation notes
The queue markers and timeouts (
_SENTINEL,_ITEM,_ERR, and the put/get/join timeouts) already existed in row streaming and are moved to the shared base class._ITEMis the generalized name of the previous_ROWmarker. The only new buffering constant is_PREFETCH_BATCH_QUEUE_MAXSIZE = 16, which bounds each DataLoader worker's Python prefetch queue to 16RecordBatchobjects. Native reader and active producer buffers are additional.This follows the same batch-first pattern as Lance's PyTorch
LanceDataset, which providesbatch_size,to_tensor_fn, Arrow batch buffering, and a defaultbatch_readahead=16. PyIceberg providesto_arrow_batch_reader()for streaming Arrow batches, but does not currently provide a PyTorch dataset or Tensor conversion layer.Tests
PYTHONPATH=paimon-python pytest paimon-python/pypaimon/tests/torch_read_test.py -q(21 passed)py_compile, andgit diff --check