Model object
The Model object comes with three sets of methods: CRUD methods, I/O methods and kind specific methods.
CRUD methods
Crud methods are used to interact with the entity object in the backend or locally.
save(): Save or update the entity into the backend.export(): Export the entity locally as yaml file.refresh(): Refresh (read) the entity from the backend.
save
Save entity into backend.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
update
|
bool
|
Flag to indicate update. |
False
|
Returns:
| Type | Description |
|---|---|
Model
|
Entity saved. |
export
Export object as a YAML file in the context folder.
Returns:
| Type | Description |
|---|---|
str
|
Exported filepath. |
refresh
Refresh object from backend.
Returns:
| Type | Description |
|---|---|
ContextEntity
|
Entity refreshed. |
I/O methods
I/O methods are used to handle objects as files.
as_file(): Dowloads the model into a local temporary destinationdownload(): Downloads the model into a specified pathupload(): Uploads the model to model spec path
as_file
Get object as file(s). It downloads the object from storage in a temporary folder and returns the list of downloaded files paths.
Returns:
| Type | Description |
|---|---|
list[str]
|
List of file paths. |
download
This function downloads one or more file from storage on local
machine from spec.path.
The files are downloaded into a destination folder. If the destination
is not specified, it will set by default under the context path
as '
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
destination
|
str
|
Destination path as filename or directory. |
None
|
overwrite
|
bool
|
Specify if overwrite existing file(s). If file(s) already exist and overwrite is False, it will raise an error. |
False
|
Returns:
| Type | Description |
|---|---|
str
|
Download path. |
Examples:
Download a single file:
upload
Upload object from given local path to spec path destination. Source must be a local path. If the path is a folder, destination path (object's spec path) must be a folder or a partition ending with '/' (s3).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source
|
str | list[str]
|
Local filepath, directory or list of filepaths. |
required |
Examples:
Upload a single file:
Upload a folder:
Model specific methods
There are several generic model methods on the Model object.
log_metric: Log a metric in the model.log_metrics: Log multiple metrics in the model.
log_metric
Log metric into entity status. A metric is named by a key and value (single number or list of numbers). The metric by default is put in a list or appended to an existing list. If single_value is True, the value will be a single number.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
str
|
Key of the metric. |
required |
value
|
MetricType
|
Value of the metric. |
required |
overwrite
|
bool
|
If True, overwrite existing metric. |
False
|
single_value
|
bool
|
If True, value is a single value. |
False
|
Examples:
Log a new value in a list
Append a new value in a list
Log a list of values and append them to existing metric:
Log a single value (not represented as list):
Log a list of values and overwrite existing metric:
log_metrics
Log metrics into entity status. If a metric is a list, it will be logged as a list. Otherwise, it will be logged as a single value.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
metrics
|
dict[str, MetricType]
|
Dict of metrics to log. |
required |
overwrite
|
bool
|
If True, overwrite existing metrics. |
False
|
Examples:
Log multiple metrics at once
Log metrics with lists and single values
Append to existing metrics (default behavior)
>>> entity.log_metrics(
... {
... "loss": 0.001,
... "accuracy": 0.96,
... }
... ) # Appends to existing
Overwrite existing metrics
>>> entity.log_metrics(
... {
... "loss": 0.0005,
... "accuracy": 0.98,
... },
... overwrite=True,
... )
See also
log_metric
Kind specific methods
Kind specific methods are used to express potential behaviors of different object kinds. See the kinds section for more information.