installModel

First introduced in version: 3.00.6.5

Syntax

installModel(modelName, [modelVersion], [downloadDir], [options])

Details

Downloads the specified model package locally. After validation and extraction, the model is registered with the ModelInference plugin by default for subsequent management. If registration is disabled, only the model files are saved. Registration and loading must then be completed separately before use.

No inference instance is created by default. Before inference is performed, ModelInference::loadModel must be called to load the model and create an inference instance. Alternatively, the load option can be set when calling this function to create an inference instance after registration.

The ModelInference plugin must be installed and loaded before installModel is called. Administrator privileges are required. For instructions on using the plugin, see ModelInference.

Parameters

modelName is a STRING scalar specifying the model name. The name can be obtained from the ModelName column returned by listRemoteModels.

modelVersion is an optional STRING scalar specifying the model package release version. If omitted, the latest version returned by listRemoteModels for the specified model is used.

downloadDir is an optional STRING scalar specifying the destination directory for downloading and extracting the model package. An absolute path on the machine hosting the current execution node must be specified. If omitted, the default directory <getHomeDir()>/models is used.

options is an optional dictionary of type dict(STRING, ANY) specifying model installation options. The following keys are supported:

Key

Description

modelServerAddr A STRING scalar specifying the HTTP or HTTPS address of the model repository. This option is unspecified by default.
register A BOOL scalar indicating whether the model is registered with the ModelInference plugin after extraction for subsequent management. The registered name follows the format <modelName>-v<modelVersion>, for example, "bge-m3-int8-v1.0.0". The default value is true.
load A BOOL scalar indicating whether an inference instance is created after registration. If true, the model is loaded on the CPU with the float32 compute type. The default value is false.

Note:

  • When load=true, register must be true. An existing inference instance of the model is preferentially reused. To specify the device, compute type, or thread count, call ModelInference::loadModel separately.

  • The model package is downloaded to the directory specified by downloadDir. The ZIP file is saved at <downloadDir>/<modelName>-<modelVersion>.zip, and the extracted model directory is <downloadDir>/<modelName>/<modelVersion>/.

  • Valid model files and existing registrations are not processed again during repeated installation.

  • Existing model registrations are not overwritten. If a registration with the same name has different content, the original registration is retained.

  • An exception is raised if execution fails. Valid model files and completed registrations are retained. When the function is called again, execution resumes from the steps that have not been completed.

Returns

A dictionary is returned, containing the following fields:

Field Type Description
modelName STRING Model name.
modelVersion STRING Model package version actually installed.
modelPath STRING Absolute path to the extracted model directory on the current execution node.
instanceName STRING Name of the inference instance loaded or reused by this call, which can be used for subsequent inference. An empty string is returned when load=false.

Examples

The ModelInference and zip plugins must be loaded before installModel is used:

loadPlugin("ModelInference")
loadPlugin("zip")

Example 1. Download and register the latest version of an embedding model.

installModel("bge-m3-int8")

Example 2. Download and register a specified model version with a custom download directory.

installModel("chronos-2", "1.0.0", "/data/models")

Example 3. Install a model and load an inference instance with default settings.

options = dict(STRING, ANY)
options["load"] = true
installModel("chronos-2", "1.0.0", "/data/models", options)

Example 4. Only download, validate, and extract the model package.

options = dict(STRING, ANY)
options["register"] = false
installModel("chronos-2", "1.0.0", "/data/models", options)

Example 5. Install a model from the specified official model repository.

options = dict(STRING, ANY)
options["modelServerAddr"] = "https://dolphindb-modelmarket.oss-cn-hangzhou.aliyuncs.com/models/"
installModel("bge-m3-int8", options=options)

Related Functions:listRemoteModels