googleapis / googleapis/python-aiplatform

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

Aperta
#5,648 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub
api: vertex-ai
Lingua principale
Python
Stelle
905
Fork
465
Merge medio
1g 13h
PR unite (30g)
44

Descrizione

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!

Guida per i contributori

Apri la guida per i contributori

Valutazione

Questa issue non è ancora stata valutata.

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.