googleapis / googleapis/python-aiplatform

Google Cloud AIplatform error when saving XGBRegressor model locally

Đang mở
#3,439 2 bình luận 0 reaction 1 người được giao Được giao cho @lakeyk Xem trên GitHub
api: vertex-ai
Ngôn ngữ chính
Python
Star
905
Fork
465
Merge trung bình
1 ngày 13 giờ
Pull request đã merge (30 ngày)
44

Mô tả

**Description**
When using `aiplatform` to manage experiments, there is an option to [log_model](https://cloud.google.com/python/docs/reference/aiplatform/latest/google.cloud.aiplatform.ExperimentRun#google_cloud_aiplatform_ExperimentRun_log_model). When the XGBRegressor parameter `enable_categorical` is enabled, the default `"model_file": "model.bst"` will fail.

The issue should be caused by the configuration of `_FRAMEWORK_SPECS` defined in `.../lib/python3.10/site-packages/google/cloud/aiplatform/metadata/_models.py`

```Python
_FRAMEWORK_SPECS = {
"sklearn": {
"save_method": _save_sklearn_model,
"load_method": _load_sklearn_model,
"model_file": "model.pkl",
},
"xgboost": {
"save_method": _save_xgboost_model,
"load_method": _load_xgboost_model,
"model_file": "model.bst",
},
"tensorflow": {
"save_method": _save_tensorflow_model,
"load_method": _load_tensorflow_model,
"model_file": "saved_model",
},
}
```

#### Environment details

- OS type and version:
> Windows 11 WSL
> Distributor ID: Ubuntu
> Description: Ubuntu 22.04.2 LTS
> Release: 22.04

- Python version: 3.10.13
- pip version: 24.0
- `google-cloud-aiplatform` version: 1.4.3
- xgboost version: 2.0.3

#### Steps to reproduce
1. Train a XGBoost Regressor model using categorical feature
2. Trying to save the model locally using `.bst` format
3. It will success when set the format to `.json` or `.ubj` as described [here](https://xgboost.readthedocs.io/en/stable/tutorials/saving_model.html#introduction-to-model-io)

#### Code example

```Python
# Necessary imports
import numpy as np
import pandas as pd
import xgboost as xg
from sklearn.model_selection import train_test_split
from sklearn.metrics import mean_squared_error as MSE

url = 'https://raw.githubusercontent.com/jbrownlee/Datasets/master/housing.csv'
dataset = pd.read_csv(url, header=None)
# Load the data
X, y = dataset.iloc[:, :-1], dataset.iloc[:, -1]

X[8] = X[8].astype('category')

# Splitting
train_X, test_X, train_y, test_y = train_test_split(X, y,
test_size = 0.3, random_state = 42)

# Instantiation
xgb_r = xg.XGBRegressor(enable_categorical=True)

# Fitting the model
xgb_r.fit(train_X, train_y)

import os
import tempfile

model_file = "model.bst"

with tempfile.TemporaryDirectory() as temp_dir:
path = os.path.join(temp_dir, model_file)
print(path)
xgb_r.get_booster().save_model(path)
```

#### Stack trace
```
Stack trace:
[bt] (0) .../lib/python3.10/site-packages/xgboost/lib/libxgboost.so(+0x397223) [0x7fc9a4597223]
[bt] (1) .../lib/python3.10/site-packages/xgboost/lib/libxgboost.so(+0x3985e2) [0x7fc9a45985e2]
[bt] (2) .../lib/python3.10/site-packages/xgboost/lib/libxgboost.so(+0x2ca66e) [0x7fc9a44ca66e]
[bt] (3) .../lib/python3.10/site-packages/xgboost/lib/libxgboost.so(+0x2e67a7) [0x7fc9a44e67a7]
[bt] (4) .../lib/python3.10/site-packages/xgboost/lib/libxgboost.so(XGBoosterSaveModel+0x163) [0x7fc9a433d1c3]
[bt] (5) .../lib/python3.10/lib-dynload/../../libffi.so.8(+0x6a4a) [0x7fca6ae4ba4a]
[bt] (6) .../lib/python3.10/lib-dynload/../../libffi.so.8(+0x5fea) [0x7fca6ae4afea]
[bt] (7) .../lib/python3.10/lib-dynload/_ctypes.cpython-310-x86_64-linux-gnu.so(+0x12461) [0x7fca6ae63461]
[bt] (8) .../lib/python3.10/lib-dynload/_ctypes.cpython-310-x86_64-linux-gnu.so(+0x86eb) [0x7fca6ae596eb]
```

Thanks!

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.