Models
Models are the main output of a machine learning experiment. In Hectiq Lab, models are stored in a specific directory and can be accessed using the Model object.
Create a model
You can create a model using the create method. This method is available from the functional and model object-oriented approach.
import pyhectiqlab.functional as hl
hl.create_model(name="model_name", path="path/to/model")| Name | Type | Default | Description |
|---|---|---|---|
| name | str | - | Name of the model |
| path | Optional[str] | None | Path to the model. If None, it creates a model without files. |
| run_id | Optional[str] | None | ID of the run |
| version | Optional[str] | None | Version of the model |
| description | Optional[str] | None | Description of the model |
| project | Optional[str] | None | Project of the model |
| upload | Optional[bool] | True | Upload the model to the server |
If the name parameter is not provided, the project or the model is not found, it logs an error and returns None.
Upload files to a model
You can upload files to a model using the upload method. This method is available from the functional and model object-oriented approach. You'll need the model id to upload the files. The model id can be retrieved using the retrieve method or is provided in the web application. The id is unique for a specific model name and version.
import pyhectiqlab.functional as hl
model = hl.retrieve_model(name="model_name", version="0.1.0")
hl.upload_model(id=model["id"], path="path/to/model")Retrieve a model
You can retrieve a model by its name and version using the retrieve method.
import pyhectiqlab.functional as hl
hl.retrieve_model(name="model_name", version="0.1.0")| Name | Type | Default | Description |
|---|---|---|---|
name | str | - | Name of the model |
project | Optional[str] | None | Project of the model |
version | str | - | Version of the model |
fields | Optional[list[str]] | None | Fields to retrieve |
If the project is not found, it logs an error and returns None.
Download a model locally
You can download a model by its name and version using the download method.
import pyhectiqlab.functional as hl
hl.download_model(name="model_name", version="0.1.0")| Name | Type | Default | Description |
|---|---|---|---|
name | str | - | Name of the model |
project | Optional[str] | None | Project of the model |
version | str | - | Version of the model |
path | Optional[str] | None | Path to download the model |
overwrite | bool | False | Whether to overwrite the existing files. |
If the project or the model is not found, it logs an error and returns None.
Delete a model
You can delete a model by its name, version and project using the delete method, or by its id. Depending on the argument you provide, the method will delete the model by its id or by its name and version.
import pyhectiqlab.functional as hl
hl.delete_model(name="model_name", version="0.1.0")If the id parameter, or the name, version and project are not provided, it logs an error and returns None.
| Name | Type | Default | Description |
|---|---|---|---|
id | str | None | ID of the model |
name | Optional[str] | None | Name of the model |
version | Optional[str] | None | Version of the model |
project | Optional[str] | None | Project of the model |
wait_response | bool | False | Wait for the response from the server |
Update a model
You can update the metadata of a model using the update method. For updating the files of a model, you can use the upload method.
The name and version of a model can be updated. The update uses the id to find the model to update.
import pyhectiqlab.functional as hl
hl.update_model(id="12kd9x", version="0.1.0", description="New description")If the id parameter is not provided, it logs an error and returns None.
| Name | Type | Default | Description |
|---|---|---|---|
| id | str | - | ID of the model |
| name | Optional[str] | None | Name of the model |
| description | Optional[str] | None | Description of the model |
| version | Optional[str] | None | Version of the model |
| wait_response | bool | False | Wait for the response from the server |
List models
You can list models using the list method.
import pyhectiqlab.functional as hl
hl.list_models(project="hectiq-ai/demo")| Name | Type | Default | Description |
|---|---|---|---|
project | Optional[str] | None | Project of the model |
search | Optional[str] | None | Search string |
author | Optional[str] | None | Author of the model |
keep_latest_version | bool | False | If True, group by the latest version of model name and return only the latest version of each model name |
fields | Optional[list[str]] | [] | Fields to retrieve |
page | Optional[int] | 1 | Page number |
limit | Optional[int] | 100 | Limit of the models |
order_by | Optional[str] | "created_at" | Order by |
order_direction | Optional[str] | "desc" | Order direction |
wait_response | bool | False | Wait for the response from the server |
Attach / Detach models to a run
A model can be attached or detached from a run. To do so, use the attach and detach method.
import pyhectiqlab.functional as hl
hl.attach_model(name="model-name", version="1.0.0", run_id="9c29ckw0")
hl.detach_model(name="model-name", version="1.0.0", run_id="9c29ckw0")| Name | Type | Default | Description |
|---|---|---|---|
name | str | - | Name of the model. |
version | str | - | Version of the model. |
run_id | str | - | ID of the run. |
project | str | None | Project of the model. |
wait_response | bool | False | Wait for the response from the server. |
If the run_id parameter is not provided or the model is not found, it logs an error and returns None.
Attach / detach tags to the models
Like for runs, tags can be attached / detached to models by using the add_tags and detach_tag method.
import pyhectiqlab.functional as hl
hl.add_tags_to_model(name="model-name", version="1.0.0", tags=["some", "tag"])
hl.detach_tag_from_model(tag="some", model_id="model-id", project="hectiq-ai/demo")If the model is not found, it logs an error and returns None.