googleapis / googleapis/python-aiplatform

Loading registred model from a Windows machine failed due to wrong separator

未关闭
#5,648 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看
api: vertex-ai
主要语言
Python
星标
905
派生
465
平均合并
1 天 13 小时
30 天内合并 PR
44

描述

Hello! I've noticed that to load a registered model one construct a path from model uri and the predefined name which is for XGBoost, for example, is `model.bst`. [Like that.](https://github.com/googleapis/python-aiplatform/blob/78c8fddc8fc9a9cc83bf982a572ed3aeaf9b876b/google/cloud/aiplatform/metadata/_models.py#L565)

The problem is when one calls this line from a Windows machine, `os.path.join()` adds a backward slash `\` to the path - but that path is to be utilised in the POSIX file system of GCP. This fails the command with FileNotFound exception. Obviously, it happens only for Windows machine.

Given that by definition load_model() should load a model from GCP servers, would it wise to force a forward slash `/` join on this line?

Like that:
```
# Force forward slash as model will be always loaded from POSIX system of GCP
source_file_uri = model.uri + '/' + model_file
```

#### Environment details

- OS type and version: Windows 11
- Python version: Python 3.12.10
- pip version: pip 25.0.1
- `google-cloud-aiplatform` version: `1.86.0`

#### Steps to reproduce

1. Save (XGBRegressor in my case) model using `aiplatform.save_model()`
2. Using Windows machine, try to load it back using `experiment_model.load_model()`

#### Code example

```python
def save_model(
experiment_name: str,
run_name: str,
project: str,
location: str,
model,
artifact_id: Optional[str] = None,
input_example=None,
display_name: Optional[str] = None,
) -> None:
_, gcs_bucket = get_gcp_bucket_vertex_ai(
project=project,
location=location,
experiment_name=experiment_name,
run_name=run_name,
)
model_uri = f"{gcs_bucket}/models/{display_name}"

aiplatform.init(project=project, location=location)
aiplatform.save_model(
model=model,
artifact_id=artifact_id,
uri=model_uri,
input_example=input_example,
display_name=display_name,
)

def load_experiment_model_sample(
artifact_id: str,
project: str,
location: str,
) -> Union["sklearn.base.BaseEstimator", "xgb.Booster", "tf.Module"]: # noqa: F821:
experiment_model = aiplatform.get_experiment_model(
artifact_id=artifact_id, project=project, location=location
)

return experiment_model.load_model()

a = load_experiment_model_sample('{...redacted...}', config['project'], 'europe-west1')
```

#### Stack trace
```
Cell In[4], [line 15](vscode-notebook-cell:?execution_count=4&line=15)
6 def load_experiment_model_sample(
7 artifact_id: str,
8 project: str,
9 location: str,
10 ) -> Union["sklearn.base.BaseEstimator", "xgb.Booster", "tf.Module"]: # noqa: F821:
11 experiment_model = aiplatform.get_experiment_model(
12 artifact_id=artifact_id, project=project, location=location
13 )
---> [15](vscode-notebook-cell:?execution_count=4&line=15) return experiment_model.load_model()

File {...redacted...}\Lib\site-packages\google\cloud\aiplatform\metadata\schema\google\artifact_schema.py:777, in ExperimentModel.load_model(self)
759 def load_model(
760 self,
761 ) -> Union["sklearn.base.BaseEstimator", "xgb.Booster", "tf.Module"]: # noqa: F821
762 """Retrieves the original ML model from an ExperimentModel.
763
764 Example Usage:
(...) 775 ValueError: if model type is not supported.
776 """
--> [777](file:///{...redacted...}/Lib/site-packages/google/cloud/aiplatform/metadata/schema/google/artifact_schema.py:777) return _models.load_model(self)

File :27, in load_model(model)

File {...redacted...}\Lib\site-packages\google\cloud\aiplatform\utils\gcs_utils.py:301, in download_file_from_gcs(source_file_uri, destination_file_path, project, credentials)
297 source_blob = storage.Blob.from_string(source_file_uri, client=storage_client)
299 _logger.debug(f'Downloading "{source_file_uri}" to "{destination_file_path}"')
--> [301]({...redacted...}/Lib/site-packages/google/cloud/aiplatform/utils/gcs_utils.py:301) source_blob.download_to_filename(filename=destination_file_path)

File ~\python\3.12\Lib\contextlib.py:81, in ContextDecorator.__call__..inner(*args, **kwds)
78 @wraps(func)
79 def inner(*args, **kwds):
80 with self._recreate_cm():
---> [81](https://file+.vscode-resource.vscode-cdn.net/{...redacted...}/model/src/notebooks/~/python/3.12/Lib/contextlib.py:81) return func(*args, **kwds)

....

NotFound: 404 GET https://storage.googleapis.com/download/storage/v1/b/i{...redacted...}5Cmodel.bst?alt=media: No such object: {...redacted...}\model.bst: ('Request failed with status code', 404, 'Expected one of', , )
```

Thanks for considering this!

贡献指南

打开贡献指南

调研方向

从 google/cloud/aiplatform/metadata/_models.py 中第 565 行附近的模型 URI 构造开始,然后检查生成的 URI 如何传递到 gcs_utils.py。重现 issue 中描述的 Windows 加载失败,并验证使用预期的 POSIX 对象路径加载已注册模型能够成功。

由索引模型根据 Issue 内容生成。

评估

技术栈
google-cloud, python
领域
cloud
Issue 类型
缺陷
难度
2/5
预计耗时
1-3 小时
活跃度
停滞
描述清晰度
描述清楚
新手友好度
48/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。