apis.md

January 4, 2023 · View on GitHub

API of federated learning

We provide APIs to access job scheduler and model manager components to manage federated jobs and models, mainly are some CRUD operations. All the interfaces comply with the HTTP protocol.

Table of Contents


Job Management

APIs used to manage federated jobs, the objects definition as follows:

Objects

Job

nametypepropertydescription
idstringrequiredThe id of federated job, is unique in namespace
descriptionstringoptionalThe description of federated job
create_timestring-Create time of this federated job (generated by server)
model_pathstringconditionalThe init model path in the storage
Note: model_path、model_id、checkpoint_id are mutually exclusive. You only need to fill in one. If all fields are filled in, then the priority will be: checkpoint_id > model_id > model_path
model_idstringconditionalThe init model id, you can get the model id through model manager.
Note: model_path、model_id、checkpoint_id are mutually exclusive. You only need to fill in one. If all fields are filled in, then the priority will be: checkpoint_id > model_id > model_path
checkpoint_idstringconditionalThe checkpoint_id, you can get the checkpoint_id through model manager.
Note: model_path、model_id、checkpoint_id are mutually exclusive. You only need to fill in one. If all fields are filled in, then the priority will be: checkpoint_id > model_id > model_path
statusStatus-The current state of federated job, set by the server
runtimestringrequiredThe runtime of model used in the federated job. Currently supporting “pytorch”, “keras”
clientsstringoptionalThe ip:port address of clients to join into the federated training.
seperated by ',' , for example : “192.168.0.1:8080,192.168.0.2:8080”
resourceResourceoptionalThe required client resource to running the federated job
portintoptionalThe port of server service, used to report the job state
hyper_parametersHyperParametersoptionalThe hyper parameters of federated job. If not configured, will be filled with default training parameters
task_entrystringconditionalThe training enterypoint in the client , should correspond to the scripts name already on the client at startup
Note: This is mutually exclusive with scripts configuration
scriptsScriptsConfigconditionalThe training scripts to broadcast to all the clients. This configuration is suitable for the scene that clients has no scripts in local.
Note: This is mutually exclusive with task_entry configuration
sslstringoptionalThe ssl store path, used for secure transfer for grpc
parametersParametersoptionalThe parameters that need to be passed to all training clients, need to be customized by the user
extendersExtendersoptionalThe extender interface configuration, through this interface, the custom extended interface scripts and functions can be injected into the federation process
secure_algorithmSecureAlgorithmoptionalFederal job security algorithm configuration. If configured, the job will protect the intermediate data of the job under the corresponding secure computing method.
compressionCompressionoptionalFederal job compression algorithm configuration. If configured, client will compress updated weights before sending to coordinator.
checkpointsCheckpointsListoptionalThe checkpoints generated during the federated job training process, are convenient for users to select the checkpoint for next running corresponding to the checkpoint_id
datasetsstringoptionalThe dataset to use for the job, when there are multiple datasets, seperated by ',', for example: "dataset1, dataset2"
outputstringrequiredThe output path of the checkpoint and metrics after job finished
random_clientbooloptionalWhether to randomly choose from suitable clients
Default is false
untrained_firstbooloptionalWhen selecting clients for the job, whether those not participating in training is preferred
Default is false
redundancyfloatoptionalRedundancy when selecting devices. For example, 1.5 means selecting at most 1.5 times the number of cleints in each round of configuration; the value ranges from 1.0 to 2.0.
Default 1.0 means that there is no redundancy
optimizerOptimizeroptionalOptimizer cofiguration, currently for non iid datasets, you can use fedprox, scaffold two optimizers

The definition of objects involved above as follows:

Status

nametypepropertydescription
statestring-The status of the federation job, which has the following status: QUEUED,STARTING,RUNNING,FINISHED,FAILED,DELETING
reasonstring-If the federated job is in the FAILED state, this field will give the exception reason
progressint-The progress of the federation job, a value from 0 to 100

HyperParameters

nametypepropertydescription
max_round_numintoptionalThe maximum number of running rounds for federated jobs, default is 10
client_numintoptionalThe number of clients required to run federated jobs, default is 1
threshold_client_numintoptionalThe minimum number of clients that the federated job runs successfully in each round, default is 1
evaluate_intervalintoptionalFederated job evaluation interval, how many rounds to run evaluation once, default is 2
save_intervalintoptionalFederated job model save interval, how many rounds to save the checkpoint, default is 5
round_timeoutintoptionalThe timeout for each round of federated jobs waiting for client results, unit is seconds, default is 3600
learning_ratefloatoptionalLearning rate for federated jobs, default is 1.0

ScriptsConfig

nametypepropertydescription
pathstringrequiredThe relative path where the script is located
config_filestringrequiredThe configuration file required for federated jobs to run tasks on the client side

Resource

nametypepropertydescription
worker_numintoptionalHow many workers are needed for parallel training when the federated job runs on the client, the default is 1
cpufloatoptionalThe number of CPU resources required for each worker participating in training on the client, the default value is 1.0
gpuintoptionalThe number of GPU resources required for each worker participating in training on the client, the default value is 0
memoryintoptionalThe number of memory resources required for each worker participating in the training on the client, unit is MB, the default is 1000MB

Parameters

This parameter is passed to the user training or evaluation scripts, and will be provided as a command line argument. This paramters is dict with key-value.
For example, if you provide this config as follows, then the commad will be with the form:
		python3 srcipt.py –key value1 -k value2 -v
nametypepropertydescription
–keyvalue1optionalparamaeter 1
-kvalue2optionalparameter 2
-vNoneoptionalsingle parameter 3

CheckpointsList

nametypepropertydescription
idCheckPointrequiredDetails of the checkpoint corresponding to the id

CheckPoint

nametypepropertydescription
accuracyfloatrequiredThe accuracy of this checkpoint after joint evaluation on the federated dataset
pathstringrequiredThe relative path of the checkpoint file in the namespace working directory

Extenders

nametypepropertydescription
script_pathstringoptionalThe path to the script file that implements the extension interface. (If this field is empty, other fields are ignored)
broadcaststringoptionalThe function name of the broadcast interface in the script. This function should return two parameters , which are custom file and custom parameters, both in the form of dict. And these files and params will be sent to each client
aggregatestringoptionalThe function name of the aggregate interface in the script. This function's input is the updates uploaded by the client, which can be customized for aggregation calculation
finishstringoptionalThe function name of the finish interface in the script. This function is executed after the current federated round. Users can customize the final aggregated results, such as saving or converting to other format

SecureAlgorithm

nametypepropertyalgorithmdescription
typestringrequired--Type of security algorithm, currently supported: "DP", "SSA"
DP is Differential Privacy
SSA is Secure Aggregate
noise_multiplierfloatrequiredDPAdd the Gaussian noise, which is the variance of the Gaussian distribution
adding_same_noisebooloptionalDPWhen adding noise to the model, whether to add the same noise to all weights
thresholdintoptionalSSAThe minimum threshold for the number of clients participating in secret sharing, the minimum value is 2, the maximum value is threshold_num defined in HyperParameters
modestringoptionalSSAonemask or doublemask mode in ssa。onemask mode is more suitable for cross-slio scenarios and does not support client disconnection;
doublemask is more suitable for cross-device scenarios, supports client disconnection, and is more secure

Compression

nametypepropertyalgorithmdescription
typestringrequired--Type of compression algorithm, currently supported: "quantization", "subsampling", "selective_masking".
quantization_bitsintoptionalquantizationA integer specifying the quantization bitwidth
sampling_ratefloatoptionalsubsamplingSpecify the sampling ratio, how much data needs to be sampled from the original data, which can be simply understood as the compression ratio
top_k_ratiofloatoptionalselective_maskingSpecify the sampling ratio, how much data will be selected from the original data, the selected data is top K largest absolute difference of the original data. This parameter can be simply understood as the compression ratio

Optimizer

nametypepropertydescription
namestringrequiredThe name of the optimizer, currently supported: "fedprox", "scaffold"
paramsdictoptionalOptimizer parameters (see the table of below)
nametypepropertyalgorithmdescription
mufloatoptionalfedproxCorrection term coefficient, to correct the difference between the local model and the server model, the recommended range is 0~1, 0 means no correction;
default is 0.6
learning_ratefloatoptional--Local training learning rate
batch_sizeintoptionalscaffoldThe batch size used when training the local model
sample_numintoptionalscaffoldThe number of samples used in this round when training the local model

Loss

nametypepropertydescription
namestringrequiredThe name of the loss, currently supported: "feddc"

JobList

nametypepropertydescription
jobslist-List of federated jobs, each element of list is Job

HttpResponse

nametypepropertydescription
statestring-Status: "SUCCESSFUL", "FAILED"
reasonstring-If status is "FAILED", giving the error reason

Operations

the operations is defined as follows

create job

Description: create a federated job.

HTTP Request:

POST /api/v1/namespaces/{namespace}/jobs

Parameters :

nametyperequireddescription
namespace(in path)stringyesthe belonging namespace of this job
bodyJobyesthe details of job configuration

Response:

codebodydescription
201HttpResponseSuccessfully created federated job
403HttpResponseFailed to create a job, such as the job already exists, the namespace does not exist, the job parameter verification fails, etc.
500HttpResponseInternal server error
update job

Description: Update a federated job.

HTTP Request:

PUT /api/v1/namespaces/{namespace}/jobs/{job_id}

Parameters :

nametyperequireddescription
namespace(in path)stringyesthe belonging namespace of this job
job_id(in path)stringyesthe unique id of job
bodyJobyesthe details of job configuration

Response:

codebodydescription
200HttpResponseSuccessfully modified federated job
403HttpResponseModifying the job failed, such as the job does not exist, the namespace does not exist, the job parameter verification fails, etc.
500HttpResponseInternal server error
delete job

Description: Delete a federated job

HTTP Request:

DELETE /api/v1/namespaces/{namespace}/jobs/{job_id}

Parameters :

nametyperequireddescription
namespace(in path)stringyesthe belonging namespace of this job
job_id(in path)stringyesthe unique id of job

Response:

codebodydescription
200HttpResponseThe federated job was deleted successfully, or the job does not exist
500HttpResponseInternal server error
start job

Description: Start a federated job to running.

HTTP Request:

PUT /api/v1/namespaces/{namespace}/jobs/{job_id}:start

Parameters :

nametyperequireddescription
namespace(in path)stringyesthe belonging namespace of this job
job_id(in path)stringyesthe unique id of job

Response:

codebodydescription
200HttpResponseFederated job started successfully
403HttpResponseFailed to start the job, such as the job does not exist, the namespace does not exist, etc.
500HttpResponseInternal server error
stop job

Description: Stop a federated job.

HTTP Request:

PUT /api/v1/namespaces/{namespace}/jobs/{job_id}:stop

Parameters :

nametyperequireddescription
namespace(in path)stringyesthe belonging namespace of this job
job_id(in path)stringyesthe unique id of job

Response:

codebodydescription
200HttpResponseSuccessfully stopped federated job
403HttpResponseFailed to stop the job, such as the job does not exist, the namespace does not exist, etc.
500HttpResponseInternal server error
get job

Description: Get the detailed info of a job.

HTTP Request:

GET /api/v1/namespaces/{namespace}/jobs/{job_id}

Parameters :

nametyperequireddescription
namespace(in path)stringyesthe belonging namespace of this job
job_id(in path)stringyesthe unique id of job

Response:

codebodydescription
200JobThe federated job is successfully obtained and the job information is returned
404HttpResponseFailed to get job, such as job does not exist, namespace does not exist, etc.
500HttpResponseInternal server error
get jobs

Description: Get all the jobs info of one namespace.

HTTP Request:

GET /api/v1/namespaces/{namespace}/jobs

Parameters :

nametyperequireddescription
namespace(in path)stringyesthe namespace name

Response:

codebodydescription
200JobListGet all the federated jobs successfully, return job information list
500HttpResponseInternal server error
health check

Description: Health check is used to judge whether the job scheduler componment is working normally.

HTTP Request:

GET /api/v1/health

Parameters :

None

Response:

codebodydescription
200'OK'job scheduler is workinng normally

Model Management

APIs to access the model manager, which is used to manage the model meteadta in user-space in the federated learning system, including the initial model uploaded by the user, the checkpoint generated during the training process, and the final trained model, etc.

Note: Model management only manages the meta information of the model. The upload and download of the model data need to access API according to your backend data storage scheme. If your backend supports s3 standard object storage, then we strongly recommend that you use the 'cli' tool we provide. The 'cli' tool provide a complete model management solution, including the data downlond and upload.
However, if you use other backend storage solutions, you should wrap a script yourself to provide full model management functionality, especially the data upload and download. At the sametime, access our model managers API to maintain your model data metadata.

objects definition as follows:

Objects

Model

nametypepropertydescription
namestringrequiredThe name of created model
versionstringrequiredThe version of created model
runtimestringrequiredThe runtime of created model
descriptionstringoptionalThe description of created model
namespacestringoptionalThe namespace of created model
Default is 'default 'nampspace
progressintoptionalThe current progress of model data. When created model, the model should be uploaded to storege server, and this field means the progress, you can use the update opertion to update the progress. And when the progress is 100, means the model is ready for use.
statestringoptionalThe state of model, support 'unready', 'ready', 'error', 'deleting'. Note: only ready model can be used for federated job
model_pathstringconditionalThe path of model in the storage, use this field means the created model is already in storage server, only need to copy to user path.
Note: the model_path is mutually exclusive with file_name, file_name means user will upload the model to storage server
file_namestringconditionalThe file name of model, if the model still in user local disk, then should upload the model to the storage server.

ModelDetail

nametypepropertydesrcription
namestringrequiredThe name of model
runtimestringrequiredThe runtime of model
namespacestringrequiredThe namespace of model
idstringrequiredThe unique id of model
statestringrequiredThe current state of model, support 'unready', 'ready', 'error', 'deleting'.
version_infoVersionInforequiredThe version info of this model
storage_infotuplerequiredThe storage info of this model, the tuple is format with (namespace, path), the path is releative to the namespace directory
model_pathstringoptionalThe origin model path when created
file_namestringoptionalThe file name of model when created
error_msgstringoptionalThe error reason if model state is error

VersionInfo

nametypepropertydescription
versionstringrequiredThe version name of the model
timestringrequiredThe create time of this version
descriptionstringoptionalThe description of this version

ModelList

nametypepropertydescription
modelslist-The list of model, each element is ModelDetail

HttpResponse

nametypepropertydescription
statestring-Status: "SUCCESSFUL", "FAILED"
reasonstring-If status is "FAILED", giving the error reason

Operations

the operations is defined as follows

create model

Description: Create a model

HTTP Request:

POST /api/v1/namespaces/{namespace}/models

Parameters :

nametyperequireddescription
namespace(in path)stringyesthe belonging namespace of this model
bodyModelyesthe configuration of model

Response:

codebodydescription
201ModelDetailModel created successfully
400HttpResponseFailed to create model, such as configuration error, data type is not equal
404HttpResponseFailed to create model, namespace does not exist
500,503HttpResponseInternal server error
get model

Description: Get a model

Note: A model may have many versions. If version is not specified, then will return all the versions of model, otherwise will return the specified version of model.

HTTP Request:

GET /api/v1/namespaces/{namespace}/models/{model_name}?version=

Parameters :

nametyperequireddescription
namespace(in path)stringyesthe belonging namespace of this model
model_name(in path)stringyesthe name of this model
version(in query)stringnothe version name of this model

Response:

codebodydescription
200ModelListModel obtained successfully
404HttpResponsemodel or namespace not exist
500,503HttpResponseInternal server error
get models

Description: Get all models in one namespace

HTTP Request:

GET /api/v1/namespaces/{namespace}/models

Parameters :

nametyperequireddescription
namespace(in path)stringyesthe namespace of models

Response:

codebodydescription
200ModelListSuccessfully fetched all models in one namesapce
404HttpResponsenamespace not exist
500,503HttpResponseInternal server error
get model by id

Description: Get a model through its model-id

Note: After model created success, each model(version) will be given a unique model id, and you can access the model through this id.

HTTP Request:

GET /api/v1/models?model_id=

Parameters :

nametyperequireddescription
model_id(in query)stringyesthe namespace of models

Response:

codebodydescription
200ModelDetailsucccess, return the model detail in body
404HttpResponsenamespace not exist
500,503HttpResponseservice internal error or unavailable
delete model

Description: Delete a model

Note: A model may have many versions. If version is not specified, then will delete all the versions of model, otherwise will only detele the specified version of model.

HTTP Request:

DELETE /api/v1/namespaces/{namespace}/models/{model_name}?version=

Parameters :

nametyperequireddescription
namespace(in path)stringyesthe belonging namespace of this model
model_name(in path)stringyesthe name of this model
version(in query)stringnothe specific version name of this model

Response:

codebodydescription
200Nonedelete model succcess
404HttpResponsemodel not exist
500,503HttpResponseservice internal error or unavailable
delete model by id

Description: Delete a model through its model-id

Note: After model created success, each model(version) will be given a unique model id, and you can access the model through this id.

HTTP Request:

DELETE /api/v1/models?model_id=

Parameters :

nametyperequireddescription
model_id(in query)stringyesthe unique id of model

Response:

codebodydescription
200Nonedelete succcess
404HttpResponsenamespace not exist
500,503HttpResponseservice internal error or unavailable
update model

Description: Update a model

Note: A model may have many versions. When you update a model, you must set the model version, otherwise the operation will failed.

HTTP Request:

PUT /api/v1/namespaces/{namespace}/models/{model_name}?version=

Parameters :

nametyperequireddescription
namespace(in path)stringyesthe belonging namespace of this model
model_name(in path)stringyesthe name of this model
version(in query)stringyesthe specific version name of this model

Response:

codebodydescription
200ModelDetailupdate model succcess, return the model detail
404HttpResponsemodel not exist
500,503HttpResponseservice internal error or unavailable
update model by id

Description: Update a model through its model-id

Note: After model created success, each model(version) will be given a unique model id, and you can access the model through this id.

HTTP Request:

PUT /api/v1/models?model_id=

Parameters :

nametyperequireddescription
model_id(in query)stringyesthe unique id of model

Response:

codebodydescription
200ModelDetailupdate succcess
404HttpResponsenamespace not exist
500,503HttpResponseservice internal error or unavailable
health check

Description: Health check is used to judge whether the model manager is working normally.

HTTP Request:

GET /api/v1/health

Parameters :

None

Response:

codebodydescription
200'OK'model manager is workinng normally