Model Loading¶
- substrafl.model_loading.download_algo_files(client: substra.sdk.client.Client, compute_plan_key: str, dest_folder: os.PathLike, round_idx: Optional[int] = None)¶
Download all the files needed to load the model:
hosted on the client organization
being part of the given compute plan
being the result of the associated strategy ofter round_idx steps
into memory.
Those files are:
the algorithm used for this task
the output local state of the task
a metadata.json
Important
This function supports only strategies with one composite traintuple for a given organization and round.
- Parameters
client (substra.Client) – Substra client where to fetch the model from.
compute_plan_key (str) – Compute plan key to fetch the model from.
dest_folder (os.PathLike) – Folder where to download the files.
round_idx (Optional[int], None) – Round of the strategy to fetch the model from. If set to
None
, the last round will be used. (Default to None).
- Raises
NotImplementedError – The given compute plan must have been submitted to Substra through the
execute_experiment()
function.TrainTaskNotFoundError – If no composite matches the given requirements.
MultipleTrainTaskError – The experiment to get the model from can’t have multiple TrainDataNodes hosted on the same organization. In practice this means the presence of multiple composite train tuples with the same round number on the same rank.
UnfinishedTrainTaskError – The task from which the files are trying to be downloaded is not done.
- substrafl.model_loading.load_algo(input_folder: os.PathLike) Any ¶
Loads an algo from a specified folder. This folder should contains:
algo.tar.gz
metadata.json
the file specified in metadata.local_state_file
This kind of folder can be generated with the
download_algo_files()
function.- Parameters
input_folder (os.PathLike) – Path to folder containing the required files.
- Raises
LoadAlgoMetadataError – The metadata file must contains the local_state_file key
LoadAlgoFileNotFoundError – At least one of the required file to load the model is not found
LoadAlgoLocalDependencyError – One of the dependency used by the algo is not installed within the the used environnement
- Returns
The serialized algo within the input_folder
- Return type
Any