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’ or ‘PW_ENCRYPT’. 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. Default: ‘NOT_ENCRYPT’.

  • 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: true.

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

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

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")