Skip to content

[Datasets] Refactor iter_rows() for DatasetIterator classes - #33257

Merged
ericl merged 3 commits into
ray-project:masterfrom
c21:fix-iter-row
Mar 14, 2023
Merged

[Datasets] Refactor iter_rows() for DatasetIterator classes#33257
ericl merged 3 commits into
ray-project:masterfrom
c21:fix-iter-row

Conversation

@c21

@c21 c21 commented Mar 13, 2023

Copy link
Copy Markdown
Contributor

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.

Screen Shot 2023-03-13 at 11 24 05 AM

Related issue number

Closes #33263

Checks

  • I've signed off every commit(by using the -s flag, i.e., git commit -s) in this PR.
  • I've run scripts/format.sh to lint the changes in this PR.
  • I've included any doc changes needed for https://docs.ray.io/en/master/.
  • I've made sure the tests are passing. Note that there might be a few flaky tests, see the recent failures at https://flakey-tests.ray.io/
  • Testing Strategy
    • Unit tests
    • Release tests
    • This PR is not tested :(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is basically the same as the other impl. Could we make this not an abstract method, and delete the impl in this file?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(move the common impl to dataset_iterator.py, and then delete the methods in stream_split_dataset_iterator.py and dataset_iterator_impl.py)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that one can also use the same impl...

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(We could make get_batch_format() an abstract method instead, like schema)

@c21 c21 Mar 13, 2023

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ericl - ah got it. Updated.

@ericl ericl added the @author-action-required The PR author is responsible for the next step. Remove tag to send back to the reviewer. label Mar 13, 2023
@c21 c21 changed the title [Datasets] Add iter_rows() for StreamSplitDatasetIterator [Datasets] Refactor iter_rows() for DatasetIterator classes Mar 13, 2023
c21 added 2 commits March 13, 2023 14:54
Signed-off-by: Cheng Su <scnju13@gmail.com>
Signed-off-by: Cheng Su <scnju13@gmail.com>
Comment thread python/ray/data/dataset_iterator.py Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jianoaix - I am open to a better name, do you have a suggestion for naming?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

_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?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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().

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, SG

Comment thread python/ray/data/_internal/util.py Outdated
return splits


def _best_batch_format(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this can be a util, why cannot it be the default impl for DatasetIterator?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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>
@c21 c21 added tests-ok The tagger certifies test failures are unrelated and assumes personal liability. and removed @author-action-required The PR author is responsible for the next step. Remove tag to send back to the reviewer. labels Mar 14, 2023
@ericl
ericl merged commit a3b89f6 into ray-project:master Mar 14, 2023
@c21
c21 deleted the fix-iter-row branch March 14, 2023 02:19
ProjectsByJackHe pushed a commit to ProjectsByJackHe/ray that referenced this pull request Mar 21, 2023
…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>
edoakes pushed a commit to edoakes/ray that referenced this pull request Mar 22, 2023
…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>
peytondmurray pushed a commit to peytondmurray/ray that referenced this pull request Mar 22, 2023
…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">
elliottower pushed a commit to elliottower/ray that referenced this pull request Apr 22, 2023
…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>
ProjectsByJackHe pushed a commit to ProjectsByJackHe/ray that referenced this pull request May 4, 2023
…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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

tests-ok The tagger certifies test failures are unrelated and assumes personal liability.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Datasets] test_streaming_split_e2e is failing

3 participants