Repository navigation
Add native support for Dask - #4473
Conversation
mrocklin
left a comment
There was a problem hiding this comment.
Thanks for doing this @RAMitchell . I've added some small comments below. In particular I'm curious about your thoughts on the .partitions[...].compute() bits. I think it would be useful if xgboost didn't have to think about concatenation (this gets messy with cudf).
| if isinstance(data[0], (pd.DataFrame, pd.Series)): | ||
| return pd.concat(data, axis=0) | ||
| if isinstance(data[0], (DataFrame, pandas.Series)): | ||
| return pandas.concat(data, axis=0) |
There was a problem hiding this comment.
When using libraries like cudf, which are pandas-like, we've found that explicit type checks can be difficult to work around. For functions like concat we've started using dispatchable functions, which downstream libraries can implement on their own to add support for their library without us having to explicitly whitelist them.
There was a problem hiding this comment.
Also, Python style nit. For private functions I've more often seen a single underscore prefix rather than double-underscore.
I'm not that engaged with the xgboost codebase though. This may be how you all do things and I suspect that there is good reason for it. Just thought I'd mention it.
There was a problem hiding this comment.
Agree. We should avoid isinstance checks. These patterns are difficult to maintain.
To provide an example from Dask where a concat method is registered against dask.dataframe.methods:
from dask.dataframe.methods import concat_dispatch
@concat_dispatch.register((MyDataFrame, MySeries, MyIndex))
def concat_pandas(dfs, axis=0, join='outer', uniform=False, filter_warning=True):
...
There was a problem hiding this comment.
Expanding on my note below. I think that ideally xgboost wouldn't need to have a concat function at all. I would hope that all of this code would go away.
| raise ValueError("Dask data must have the same partitions") | ||
| # Get local partitions | ||
| partitions = [dd.partitions[i].compute() for i in | ||
| range(begin_partition, end_partition)] |
There was a problem hiding this comment.
Calling .compute() multiple times in sequence is somewhat inefficient. It would be better to do something like ...
dask.compute([dd.partitions[i] for i in range(...)])Or even better yet just slice into dd.partitions
dd.partitions[begin_partition:end_partition].compute()There was a problem hiding this comment.
This second approach would also remove the need to think about concatenation, which would remove a coordiantion point for libraries like cudf, which would now need to contend with how xgboost does things.
There was a problem hiding this comment.
@mrocklin can you provide more detail into what you mean, here? What coordination point are we removing by adopting this pattern, for example?
There was a problem hiding this comment.
I mean that in the second code snippet in my comment above xgboost is handed a pre-concatenated dataframe. So while Dask still has to think about this, XGBoost doesn't have to. It's one less thing for cudf and xgboost devs to have to talk about. (or any other library author who wants to work with dask and xgboost together)
There was a problem hiding this comment.
Thank you for clarifying. I certainly missed your point about avoiding an explicit call to concat.
| range(begin_partition, end_partition)] | ||
| if not partitions: | ||
| raise ValueError("Worker " + str( | ||
| rabit.get_rank()) + " has no data. Try using smaller partitions") |
There was a problem hiding this comment.
Should we err here, or just warn?
There was a problem hiding this comment.
A warning seems more appropriate to me.
There was a problem hiding this comment.
If one of the xgboost.train() calls has no data I believe it will just fail. I prefer to explicitly enforce all workers have data for now.
|
No objection on this PR for now (considering where xgboost is ) But one thing to think about is what is the criterion to determine if we have native support to some data processing framework Do we want to support in https://github.com/modin-project/modin in future? Why we choose dask instead of modin? (I am not a fan of modin, never used...) Just something we have to be clear as the maintainer of the project @hcho3, @trivialfis |
Not quite understand what's the advantage of using pandas: https://h2oai.github.io/db-benchmark/ |
mtjrider
left a comment
There was a problem hiding this comment.
My primary concern is ensuring that concatenate should be dispatched with Dask. This will make it much easier to support other data formats from other libraries.
| if isinstance(data[0], (pd.DataFrame, pd.Series)): | ||
| return pd.concat(data, axis=0) | ||
| if isinstance(data[0], (DataFrame, pandas.Series)): | ||
| return pandas.concat(data, axis=0) |
There was a problem hiding this comment.
Agree. We should avoid isinstance checks. These patterns are difficult to maintain.
To provide an example from Dask where a concat method is registered against dask.dataframe.methods:
from dask.dataframe.methods import concat_dispatch
@concat_dispatch.register((MyDataFrame, MySeries, MyIndex))
def concat_pandas(dfs, axis=0, join='outer', uniform=False, filter_warning=True):
...
| raise ValueError("Dask data must have the same partitions") | ||
| # Get local partitions | ||
| partitions = [dd.partitions[i].compute() for i in | ||
| range(begin_partition, end_partition)] |
There was a problem hiding this comment.
@mrocklin can you provide more detail into what you mean, here? What coordination point are we removing by adopting this pattern, for example?
| range(begin_partition, end_partition)] | ||
| if not partitions: | ||
| raise ValueError("Worker " + str( | ||
| rabit.get_rank()) + " has no data. Try using smaller partitions") |
There was a problem hiding this comment.
A warning seems more appropriate to me.
one of the biggest selling points of dask is it can scale pandas-styled analytics to distributed nodes, integrate Dask with XGB is also beneficial because we can have a seamless data preparation and distributed model training in python now my point is just based on the links you posted, what's the criterion to judge we should make native support of Dask, instead of any other one of them? or in future, ClickHouse's person come and say they have a ClickHouse-ML library to work with XGBoost, do we want to integrate to XGB code base? I think we should be clear about it instead of integrating for showing friend-ness. Otherwise, XGBoost is becoming a downstream library of many other projects (big burden for syncing versions, and most of projects without a company support are just going to die, at that point, do we want to clean code base by deleting code?) |
I think there are perhaps two feasible options:
In either case, the onus for developing and maintaining the interoperability (contractual) interface should fall to the native framework contributor.
Regardless of what is done, I think code rot is inevitable. Deleting old code, and redesigning components regularly seems natural. I'm not sure if I've missed your point, though(?) If you're suggesting that XGBoost remove all interface-related code in favor of a single standard, I think that's a great idea. Such an interface should be capable of dispatching types. For example, if you chose to integrate with Dask, you could design a conversion dispatcher for XGBoost, and people that wanted to design an interoperability layer with another layer could simply (with some care) register a source-to-target converter much like concatenation is done. Like (1), I think this requires XGBoost specify more formally an internal data structure so that the process of building these methods in other frameworks is simpler. |
let's imagine that we integrated with Hadoop's MapReduce years ago, at this time point, shall we still support that considering the current status of MapReduce project? most of users are moving to Spark, but some users are happily using XGBoost-MapReduce....or a living example is XGBoost-Flink, I am seriously considering if we want to bring it to XGBoost 1.0, AFAIK, Flink-Batch has a small but existing group of users, XGBoost-Flink itself is lack of maintenance for a while... and Flink's father company is bought by Alibaba now which makes many guesses to the future of project..... support => continuous burden not support => some users left XGBoost community |
|
I see. Is the proposition for 1.0 to simply drop all such code and avoid the maintenance burden? Or is this being weighed against lost communities? |
|
1.0 is more about a milestone of XGBoost's functionality and performance, but it's also a good chance to drop burdens if necessary... |
Agree. So, correct me if I’m wrong, but your original question was more about how to define a burden. Yes? |
|
@CodingCat very good points. I guess my justification for including dask is that it gives us a vehicle to launch distributed GPU algorithms, given that spark is not currently ready for this. As an active maintainer I am prepared to deal with this, especially given the relatively low overhead. Maybe we need a more well defined criteria for deprecating support for other frameworks. |
hmmmmm...........not exactly....burden comes from any integration, XGBoost-Spark also brings burden, we waited for more than 1 week for 2.4.3 release to mark XGBoost 0.9 is ready to go. But obviously, the original idea to bring XGBoost4J-Spark to XGBoost is a right one as it pushes XGBoost to production environment significantly. I think my question is about the criterion for tradeoff between burden and benefits to XGBoost. |
agree, I think distributed GPU makes efforts on Dask more valuable instead of just bringing Dask here....
also agree, I am drafting several documents for the community and I will ensure this is covered and bring it to discussion (and we should also discuss when to bring a support on a new framework) |
For what it's worth I totally understand the concerns around building connections to an external library inside of a core codebase. In maintaining Dask we've been pretty conservative about what is allowed in core, what gets imported by default, and so on. As a maintainer it's a hard decision to make. I don't maintain XGBoost, and I'm obviously biased towards Dask, so please don't trust anything I say here, but here are my thoughts.
However
|
|
Another question here is should we be able to return the predictions as a distributed object? If we know the return type for the train function is always some local data collection (numpy/pandas) we can package it into a distributed dataframe. Not sure how this works if the user wants to return other types of objects. |
|
If you do something like the following: result = df.map_partitions(local_predict_function) # dataframe
result = x.map_blocks(local_predict_function) # arrayThen Dask will figure out the correct parallel type regardless of what the user's predict function returns. Would that solve things? |
|
Tests are currently failing on CI but passing on my local machine. Maybe something to do with the permissions of the docker environment and the need for dask to read/write temporary files. I have decided not to try to return dask objects from the run function at this time. Users may want to return multiple objects or objects of different types and it is not obvious to me how to cleanly handle this, so I will leave it to the user to concatenate their results back together. This is ready for another review @mrocklin @mt-jones . |
This seems to be an import error? Perhaps this line isn't imported? |
That error is a bit odd. It's also coming through as text rather than as a proper traceback meaning that Python wasn't able to serialize the exception (perhaps because it had a file handle?) Can you try a test that just starts a Dask client and then does a trivial amount of work with it so that we can isolate this between Dask-on-this-CI and Dask+XGBoost-on-this-CI? Maybe something like this: def test_dask(client):
assert client.submit(lambda x: x + 1, 10).result() == 11 |
This error message actually goes away if we don't import datatable. @st-pasha can you comment on this? |
|
It appears the error is coming from the following line in module I presume that somehow on your environment the This is something that we could trivially fix in we already test for the case when |
|
Thanks @st-pasha for the quick response. I'm not much of a Python expert but wouldn't setting |
|
The standard stdin channel for python is Of course, changing something at the |
|
I am getting socket errors with rabit on Windows so will not support this platform at the moment. |
|
@cq ^^ |
|
@hcho3 So I have learned that setuptools packages xgboost in a completely different way on Windows - none of the source files get included. This means it does not contain the dmlc tracker scripts. The only solution I have that seems to make any sense is to add the tracker scripts as a package so they get included consistently in the right place. |
trivialfis
left a comment
There was a problem hiding this comment.
Since Windows is not supported, we might want to document it and add an error message: https://stackoverflow.com/questions/1387222/reliably-detect-windows-in-python
|
@RAMitchell This is because symlinks are not supported in Windows. All source files are included in |
There has been some discussion about integrating dask-xgboost into the main xgboost repository (dask/dask-xgboost#39). This will make maintenance/packaging easier and ensure the documentation lives in the same place.
I have taken a different approach to the integration than the original dask-xgboost, which completely wraps everything into a new API. I have instead provided helper functions for launching dask workers. Workers launched in this way are automatically connected via rabit and may perform distributed training.
I believe this approach is very flexible as we do not need to modify the existing xgboost python API in any way, we just call these functions using the dask launcher. This approach was also extremely lightweight in terms of code.
See the demo for a worked example.
TODO:
@mrocklin @mt-jones @TomAugspurger