|
| 1 | +# |
| 2 | +# Copyright 2024 Hopsworks AB |
| 3 | +# |
| 4 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | +# you may not use this file except in compliance with the License. |
| 6 | +# You may obtain a copy of the License at |
| 7 | +# |
| 8 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | +# |
| 10 | +# Unless required by applicable law or agreed to in writing, software |
| 11 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | +# See the License for the specific language governing permissions and |
| 14 | +# limitations under the License. |
| 15 | +# |
| 16 | + |
| 17 | +from typing import Optional, Union |
| 18 | + |
| 19 | +import numpy |
| 20 | +import pandas |
| 21 | +from hopsworks_common import usage |
| 22 | +from hsml.model_schema import ModelSchema |
| 23 | +from hsml.llm.model import Model |
| 24 | + |
| 25 | + |
| 26 | +_mr = None |
| 27 | + |
| 28 | + |
| 29 | +@usage.method_logger |
| 30 | +def create_model( |
| 31 | + name: str, |
| 32 | + version: Optional[int] = None, |
| 33 | + metrics: Optional[dict] = None, |
| 34 | + description: Optional[str] = None, |
| 35 | + input_example: Optional[ |
| 36 | + Union[pandas.DataFrame, pandas.Series, numpy.ndarray, list] |
| 37 | + ] = None, |
| 38 | + model_schema: Optional[ModelSchema] = None, |
| 39 | + feature_view=None, |
| 40 | + training_dataset_version: Optional[int] = None, |
| 41 | +): |
| 42 | + """Create an LLM model metadata object. |
| 43 | +
|
| 44 | + !!! note "Lazy" |
| 45 | + This method is lazy and does not persist any metadata or uploads model artifacts in the |
| 46 | + model registry on its own. To save the model object and the model artifacts, call the `save()` method with a |
| 47 | + local file path to the directory containing the model artifacts. |
| 48 | +
|
| 49 | + # Arguments |
| 50 | + name: Name of the model to create. |
| 51 | + version: Optionally version of the model to create, defaults to `None` and |
| 52 | + will create the model with incremented version from the last |
| 53 | + version in the model registry. |
| 54 | + metrics: Optionally a dictionary with model evaluation metrics (e.g., accuracy, MAE) |
| 55 | + description: Optionally a string describing the model, defaults to empty string |
| 56 | + `""`. |
| 57 | + input_example: Optionally an input example that represents a single input for the model, defaults to `None`. |
| 58 | + model_schema: Optionally a model schema for the model inputs and/or outputs. |
| 59 | +
|
| 60 | + # Returns |
| 61 | + `Model`. The model metadata object. |
| 62 | + """ |
| 63 | + model = Model( |
| 64 | + id=None, |
| 65 | + name=name, |
| 66 | + version=version, |
| 67 | + description=description, |
| 68 | + metrics=metrics, |
| 69 | + input_example=input_example, |
| 70 | + model_schema=model_schema, |
| 71 | + feature_view=feature_view, |
| 72 | + training_dataset_version=training_dataset_version, |
| 73 | + ) |
| 74 | + model._shared_registry_project_name = _mr.shared_registry_project_name |
| 75 | + model._model_registry_id = _mr.model_registry_id |
| 76 | + |
| 77 | + return model |
0 commit comments