load
#
Evaluating or stress testing a model requires Efemarai to load it first in order to pass data through it.
Example
The following definition
load:
entrypoint: inference:get_model
inputs:
- name: config_url
value: cfg/yolor_p6.cfg
- name: params_url
value: ${model.files.params.url}
output:
name: model
describes a Python function in inference.py
(expected to be in the base of the model repo)
which for example could look like
def get_model(config_url, params_url, device):
""" Loads the model.
Args:
config_url (str): Configuration file name.
params_url (str): Trained weights file name.
device (str): Device name passed in by default.
Returns:
An initialized and loaded CarDetector model.
"""
model = CarDetector(config_url)
model.load_state_dict(torch.load(params_url))
model.to(device).eval()
return model
In this case config_url="cfg/yolor_pt.cfg"
is just a string value,
params_url
is set to a path where the specified model file is located
within the model runtime. See Variables for more details.
Properties
entrypoint
: specifies where the user function is in the formatuser_module:user_function
. The module must be importable from the root of the model repository and it must contain the specified function. Sub-modules are also supported with the standard import syntax using dots e.g.module.submodule:function
inputs
: specifies a list of name-value pairs that will be passed as input arguments to the user function. Names must be valid Python variable names. Values are parsed from the YAML file and directly passed to the user function unless they refer to runtimes variable in which case they are substituted with the correct values first (see Variables). The runtime device is passed by default to the user function so it must not be explicitly specified as an input (seeruntime
).output
: specifies the output of the user function. It should contain aname
field that can be used to refer to the output as a runtime variable.