Skip to content

Commit

Permalink
Try fix ray
Browse files Browse the repository at this point in the history
  • Loading branch information
wjsi committed Oct 28, 2023
1 parent 624fb5a commit e0e4fed
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 15 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/platform-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ jobs:
fi
if [ -n "$WITH_RAY" ] || [ -n "$WITH_RAY_DAG" ] || [ -n "$WITH_RAY_DEPLOY" ]; then
pip install "ray>=1.8.0,<2.4.0"
pip install "xgboost_ray<0.1.14" "protobuf<4"
pip install xgboost_ray "protobuf<4"
# Ray Datasets need pyarrow>=6.0.1
pip install "pyarrow>=6.0.1"
pip install lightgbm
Expand Down
14 changes: 13 additions & 1 deletion mars/dataframe/contrib/raydataset/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import operator
from functools import reduce

from ....utils import lazy_import
from ....utils import lazy_import, lazy_import_on_load
from .mldataset import _rechunk_if_needed
from typing import Dict, List

Expand All @@ -24,6 +25,17 @@
ray_dataset = lazy_import("ray.data", rename="ray_dataset")


@lazy_import_on_load(ray_dataset, before=True)
def _patch_xgboost():
# _treat_X_doc in xgboost_ray might cause error
try:
from xgboost.sklearn import XGBRanker

Check warning on line 32 in mars/dataframe/contrib/raydataset/dataset.py

View check run for this annotation

Codecov / codecov/patch

mars/dataframe/contrib/raydataset/dataset.py#L31-L32

Added lines #L31 - L32 were not covered by tests

XGBRanker.predict.__doc__ = XGBRanker.predict.__doc__ or ""
except (ImportError, AttributeError):
pass

Check warning on line 36 in mars/dataframe/contrib/raydataset/dataset.py

View check run for this annotation

Codecov / codecov/patch

mars/dataframe/contrib/raydataset/dataset.py#L34-L36

Added lines #L34 - L36 were not covered by tests


def to_ray_dataset(df, num_shards: int = None):
"""Create a Ray Dataset from Mars DataFrame
Expand Down
6 changes: 1 addition & 5 deletions mars/dataframe/contrib/raydataset/tests/test_mldataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,7 @@

ray = lazy_import("ray")
ml_dataset = lazy_import("ray.util.data", rename="ml_dataset")

try:
import xgboost_ray
except ImportError: # pragma: no cover
xgboost_ray = None
xgboost_ray = lazy_import("xgboost_ray")
try:
import sklearn
except ImportError: # pragma: no cover
Expand Down
10 changes: 5 additions & 5 deletions mars/storage/vineyard.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,11 +144,11 @@ async def setup(cls, **kwargs) -> Tuple[Dict, Dict]:
vineyard_store = None
else:
vineyard_store = vineyard.deploy.local.start_vineyardd(
etcd_endpoints,
etcd_prefix,
vineyardd_path,
vineyard_size,
vineyard_socket,
etcd_endpoints=etcd_endpoints,
etcd_prefix=etcd_prefix,
vineyardd_path=vineyardd_path,
size=vineyard_size,
socket=vineyard_socket,
rpc=False,
)
vineyard_socket = (
Expand Down
15 changes: 12 additions & 3 deletions mars/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -368,26 +368,35 @@ def lazy_import(

class LazyModule(object):
def __init__(self):
self._before_loads = []
self._on_loads = []

def __getattr__(self, item):
if item.startswith("_pytest") or item in ("__bases__", "__test__"):
raise AttributeError(item)

for before_load_func in self._before_loads:
before_load_func()

Check warning on line 379 in mars/utils.py

View check run for this annotation

Codecov / codecov/patch

mars/utils.py#L379

Added line #L379 was not covered by tests

real_mod = importlib.import_module(name, package=package)
if rename in globals:
globals[rename] = real_mod
elif locals is not None:
locals[rename] = real_mod
ret = getattr(real_mod, item)

for on_load_func in self._on_loads:
on_load_func()

# make sure on_load hooks only executed once
self._on_loads = []
return ret

def add_load_handler(self, func: Callable):
self._on_loads.append(func)
def add_load_handler(self, func: Callable, before: bool = False):
if before:
self._before_loads.append(func)

Check warning on line 397 in mars/utils.py

View check run for this annotation

Codecov / codecov/patch

mars/utils.py#L397

Added line #L397 was not covered by tests
else:
self._on_loads.append(func)

Check warning on line 399 in mars/utils.py

View check run for this annotation

Codecov / codecov/patch

mars/utils.py#L399

Added line #L399 was not covered by tests
return func

if pkgutil.find_loader(prefix_name) is not None:
Expand All @@ -398,7 +407,7 @@ def add_load_handler(self, func: Callable):
return None


def lazy_import_on_load(lazy_mod):
def lazy_import_on_load(lazy_mod, before: bool = False):
def wrapper(fun):
if lazy_mod is not None and hasattr(lazy_mod, "add_load_handler"):
lazy_mod.add_load_handler(fun)
Expand Down

0 comments on commit e0e4fed

Please sign in to comment.