Federated-Server

mindspore.context.set_fl_context(**kwargs)[source]

Set federated learning training mode context.

Parameters
  • enable_fl (bool) – Whether to enable federated learning training mode. Default: False.

  • server_mode (str) – Describe the server mode, which must one of ‘FEDERATED_LEARNING’ and ‘HYBRID_TRAINING’. Default: ‘FEDERATED_LEARNING’.

  • ms_role (str) – The process’s role in the federated learning mode, which must be one of ‘MS_SERVER’, ‘MS_WORKER’ and ‘MS_SCHED’. Default: ‘MS_SERVER’.

  • worker_num (int) – The number of workers. For current version, this must be set to 1 or 0.

  • server_num (int) – The number of federated learning servers. Default: 0.

  • scheduler_ip (str) – The scheduler IP. Default: ‘0.0.0.0’.

  • scheduler_port (int) – The scheduler port. Default: 6667.

  • fl_server_port (int) – The http port of the federated learning server. Normally for each server this should be set to the same value. Default: 6668.

  • enable_fl_client (bool) – Whether this process is federated learning client. Default: False.

  • start_fl_job_threshold (int) – The threshold count of startFLJob. Default: 1.

  • start_fl_job_time_window (int) – The time window duration for startFLJob in millisecond. Default: 3000.

  • share_secrets_ratio (float) – The ratio for computing the threshold count of share secrets. Default: 1.0.

  • update_model_ratio (float) – The ratio for computing the threshold count of updateModel. Default: 1.0.

  • cipher_time_window (int) – The time window duration for each cipher round in millisecond. Default: 300000.

  • reconstruct_secrets_threshold (int) – The threshold count of reconstruct threshold. Default: 0.

  • update_model_time_window (int) – The time window duration for updateModel in millisecond. Default: 3000.

  • fl_name (string) – The federated learning job name. Default: ‘’.

  • fl_iteration_num (int) – Iteration number of federated learning, which is the number of interactions between client and server. Default: 20.

  • client_epoch_num (int) – Client training epoch number. Default: 25.

  • client_batch_size (int) – Client training data batch size. Default: 32.

  • client_learning_rate (float) – Client training learning rate. Default: 0.001.

  • worker_step_num_per_iteration (int) – The worker’s standalone training step number before communicating with server. Default: 65.

  • dp_eps (float) – Epsilon budget of differential privacy mechanism. The smaller the dp_eps, the better the privacy protection effect. Default: 50.0.

  • dp_delta (float) – Delta budget of differential privacy mechanism, which is usually equals the reciprocal of client number. The smaller the dp_delta, the better the privacy protection effect. Default: 0.01.

  • dp_norm_clip (float) – A factor used for clipping model’s weights for differential mechanism. Its value is suggested to be 0.5~2. Default: 1.0.

  • encrypt_type (string) – Secure schema for federated learning, which can be ‘NOT_ENCRYPT’, ‘DP_ENCRYPT’, ‘PW_ENCRYPT’, ‘STABLE_PW_ENCRYPT’ or ‘SIGNDS’. If ‘DP_ENCRYPT’, differential privacy schema would be applied for clients and the privacy protection effect would be determined by dp_eps, dp_delta and dp_norm_clip as described above. If ‘PW_ENCRYPT’, pairwise secure aggregation would be applied to protect clients’ model from stealing in cross-device scenario. If ‘STABLE_PW_ENCRYPT’, pairwise secure aggregation would be applied to protect clients’ model from stealing in cross-silo scenario. If ‘SIGNDS’, SignDS schema would be applied for clients. Default: ‘NOT_ENCRYPT’.

  • sign_k (float) – SignDS: Top-k ratio, namely the number of top-k dimensions divided by the total number of dimensions. Default: 0.01.

  • sign_eps (float) – SignDS: Privacy budget. Default: 100.

  • sign_thr_ratio (float) – SignDS: Threshold of the expected topk dimension. Default: 0.6.

  • sign_global_lr (float) – SignDS: The constant value assigned to the selected dimension. Default: 1.

  • sign_dim_out (int) – SignDS: Number of output dimensions. Default: 0.

  • config_file_path (string) – Configuration file path used by recovery. Default: ‘’.

  • scheduler_manage_port (int) – scheduler manage port used to scale out/in. Default: 11202.

  • enable_ssl (bool) – Set PS SSL mode enabled or disabled. Default: False.

  • client_password (str) – Password to decrypt the secret key stored in the client certificate. Default: ‘’.

  • server_password (str) – Password to decrypt the secret key stored in the server certificate. Default: ‘’.

  • pki_verify (bool) – If True, the identity verification between server and clients would be turned on. You should also download Root CA certificate, Root CA G2 certificate and Mobile Equipment CRL certificate from https://pki.consumer.huawei.com/ca/. It should be noted that only when the client is an Android environment with HUKS service, pki_verify can be True. Default: False.

  • root_first_ca_path (str) – The file path of the Root CA certificate. It should be given when pki_verify is True. Default: “”.

  • root_second_ca_path (str) – The file path of the Root CA G2 certificate. It should be given when pki_verify is True. Default: “”.

  • equip_crl_path (str) – The file path of the Mobile Equipment CRL certificate. It should be given when pki_verify is True. Default: “”.

  • replay_attack_time_diff (int) – The maximum tolerable error of certificate timestamp verification (ms). Default: 600000.

  • http_url_prefix (string) – The http url prefix for http server. Default: “”.

  • global_iteration_time_window (unsigned long) – The global iteration time window for one iteration with rounds(ms). Default: 3600000.

  • checkpoint_dir (string) – The Server model checkpoint directory. If no checkpoint dir is set, the startup script directory is used by default. Default: “”.

Raises

ValueError – If input key is not the attribute in federated learning mode context.

Examples

>>> context.set_fl_context(enable_fl=True, server_mode='FEDERATED_LEARNING')
mindspore.context.get_fl_context(attr_key)[source]

Get federated learning mode context attribute value according to the key.

Parameters

attr_key (str) – The key of the attribute. Please refer to set_fl_context’s parameters to decide what key should be passed.

Returns

Returns attribute value according to the key.

Raises

ValueError – If input key is not attribute in federated learning mode context.

Examples

>>> context.get_fl_context("server_mode")