[Datasets] Refactor iter_rows() for DatasetIterator classes - #33257
Conversation
There was a problem hiding this comment.
This is basically the same as the other impl. Could we make this not an abstract method, and delete the impl in this file?
There was a problem hiding this comment.
(move the common impl to dataset_iterator.py, and then delete the methods in stream_split_dataset_iterator.py and dataset_iterator_impl.py)
There was a problem hiding this comment.
Ok, I put it in this way because PipelinedDatasetIterator.iter_rows has its own impl. So technically these 3 subclasses not sharing same iter_rows impl. But I can put it inside DatasetIterator.iter_rows.
There was a problem hiding this comment.
I think that one can also use the same impl...
There was a problem hiding this comment.
(We could make get_batch_format() an abstract method instead, like schema)
There was a problem hiding this comment.
Actually I found PipelinedDatasetIterator.iter_batches() iterate next dataset internally, I don't want to further complicate PipelinedDatasetIterator.iter_batches interface. How about we leave the implenmentation as it is for now? Or @ericl - you have other suggestion to fix the code?
There was a problem hiding this comment.
To be clear, this is my proposal, and I believe we can remove most of the other code after this.
class DatasetIterator:
def iter_rows(...):
target_format = self._best_batch_format()
for batch in self.iter_batches(target_format):
...
yield row
def _best_batch_format():
return "default" # can override to customize in DatasetIteratorImpl
Signed-off-by: Cheng Su <scnju13@gmail.com>
Signed-off-by: Cheng Su <scnju13@gmail.com>
There was a problem hiding this comment.
What does it mean "best"? Matching the dataset format doesn't necessarily has the best perf, e.g. pyarrow-to-pandas conversion can be faster than pandas-to-pandas conversion.
There was a problem hiding this comment.
@jianoaix - I am open to a better name, do you have a suggestion for naming?
There was a problem hiding this comment.
_default_batch_format to align with Dataset (the idea of "best" can be in comment)?
Also since here is a best determined batch format, should it also be used by iter_batches when the batch_format arg is not specified by users?
There was a problem hiding this comment.
I guess I won't touch the batch format behavior for iter_batches, that would trigger more change and dsicussion across Dataset and DatasetIterator. ideally I want this PR should be simple one to unblock CI test failure. I can do the renaming part.
There was a problem hiding this comment.
It should be simple but this invites a question why do we have a class member which determines the best format in the context of iterator, but is not actually used for iter_batches().
There was a problem hiding this comment.
The current behavior for iter_batches is always using the "default" if user does not provide. The iter_rows behavior is different - in bulk execution, it checks Dataset.dataset_format() and uses the returned one, while in streaming execution, it uses "default".
The difference is already happening before this PR, and here we just introduce a private method in DatasetIterator, so it should be easy to change/remove later. Can we defer the behavior change for iter_batches to a future PR?
| return splits | ||
|
|
||
|
|
||
| def _best_batch_format( |
There was a problem hiding this comment.
If this can be a util, why cannot it be the default impl for DatasetIterator?
There was a problem hiding this comment.
So DatasetIterator has no definition of ds: "Dataset. PipelinedDatasetIterator just uses base_dataset_pipeline. And DatasetIteratorImpl and StreamSplitDatasetIterator uses _base_dataset.
Signed-off-by: Cheng Su <scnju13@gmail.com>
…ect#33257) This is to fix CI test failure introduced in ray-project#33180 ([example of buildkite failure](https://buildkite.com/ray-project/oss-ci-build-branch/builds/2690#0186da0a-17c7-40dd-a43c-1de36c4894f4)). We need to add `iter_rows()` method for StreamSplitDatasetIterator as well. <img width="1848" alt="Screen Shot 2023-03-13 at 11 24 05 AM" src="https://user-images.githubusercontent.com/4629931/224795253-ecf4e362-4253-4d60-80ff-f87e138ef773.png"> Signed-off-by: Jack He <jackhe2345@gmail.com>
…ect#33257) This is to fix CI test failure introduced in ray-project#33180 ([example of buildkite failure](https://buildkite.com/ray-project/oss-ci-build-branch/builds/2690#0186da0a-17c7-40dd-a43c-1de36c4894f4)). We need to add `iter_rows()` method for StreamSplitDatasetIterator as well. <img width="1848" alt="Screen Shot 2023-03-13 at 11 24 05 AM" src="https://user-images.githubusercontent.com/4629931/224795253-ecf4e362-4253-4d60-80ff-f87e138ef773.png"> Signed-off-by: Edward Oakes <ed.nmi.oakes@gmail.com>
…ect#33257) This is to fix CI test failure introduced in ray-project#33180 ([example of buildkite failure](https://buildkite.com/ray-project/oss-ci-build-branch/builds/2690#0186da0a-17c7-40dd-a43c-1de36c4894f4)). We need to add `iter_rows()` method for StreamSplitDatasetIterator as well. <img width="1848" alt="Screen Shot 2023-03-13 at 11 24 05 AM" src="https://user-images.githubusercontent.com/4629931/224795253-ecf4e362-4253-4d60-80ff-f87e138ef773.png">
…ect#33257) This is to fix CI test failure introduced in ray-project#33180 ([example of buildkite failure](https://buildkite.com/ray-project/oss-ci-build-branch/builds/2690#0186da0a-17c7-40dd-a43c-1de36c4894f4)). We need to add `iter_rows()` method for StreamSplitDatasetIterator as well. <img width="1848" alt="Screen Shot 2023-03-13 at 11 24 05 AM" src="https://user-images.githubusercontent.com/4629931/224795253-ecf4e362-4253-4d60-80ff-f87e138ef773.png"> Signed-off-by: elliottower <elliot@elliottower.com>
…ect#33257) This is to fix CI test failure introduced in ray-project#33180 ([example of buildkite failure](https://buildkite.com/ray-project/oss-ci-build-branch/builds/2690#0186da0a-17c7-40dd-a43c-1de36c4894f4)). We need to add `iter_rows()` method for StreamSplitDatasetIterator as well. <img width="1848" alt="Screen Shot 2023-03-13 at 11 24 05 AM" src="https://user-images.githubusercontent.com/4629931/224795253-ecf4e362-4253-4d60-80ff-f87e138ef773.png"> Signed-off-by: Jack He <jackhe2345@gmail.com>
Why are these changes needed?
This is to fix CI test failure introduced in #33180 (example of buildkite failure). We need to add
iter_rows()method for StreamSplitDatasetIterator as well.Related issue number
Closes #33263
Checks
git commit -s) in this PR.scripts/format.shto lint the changes in this PR.