1# Copyright 2021 Huawei Technologies Co., Ltd 2# 3# Licensed under the Apache License, Version 2.0 (the "License"); 4# you may not use this file except in compliance with the License. 5# You may obtain a copy of the License at 6# 7# http://www.apache.org/licenses/LICENSE-2.0 8# 9# Unless required by applicable law or agreed to in writing, software 10# distributed under the License is distributed on an "AS IS" BASIS, 11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12# See the License for the specific language governing permissions and 13# limitations under the License. 14# ============================================================================ 15 16import argparse 17import subprocess 18import os 19import ast 20 21parser = argparse.ArgumentParser(description="Run train_cloud.py case") 22parser.add_argument("--device_target", type=str, default="CPU") 23parser.add_argument("--server_mode", type=str, default="FEDERATED_LEARNING") 24parser.add_argument("--worker_num", type=int, default=0) 25parser.add_argument("--server_num", type=int, default=2) 26parser.add_argument("--scheduler_ip", type=str, default="127.0.0.1") 27parser.add_argument("--scheduler_port", type=int, default=8113) 28parser.add_argument("--scheduler_manage_port", type=int, default=11202) 29parser.add_argument("--client_password", type=str, default="") 30parser.add_argument("--server_password", type=str, default="") 31parser.add_argument("--enable_ssl", type=ast.literal_eval, default=False) 32 33args, _ = parser.parse_known_args() 34device_target = args.device_target 35server_mode = args.server_mode 36worker_num = args.worker_num 37server_num = args.server_num 38scheduler_ip = args.scheduler_ip 39scheduler_port = args.scheduler_port 40scheduler_manage_port = args.scheduler_manage_port 41client_password = args.client_password 42server_password = args.server_password 43enable_ssl = args.enable_ssl 44 45os.environ['MS_NODE_ID'] = "20" 46cmd_sched = "execute_path=$(pwd) && self_path=$(dirname \"${script_self}\") && rm -rf ${execute_path}/scheduler/ &&" 47cmd_sched += "mkdir ${execute_path}/scheduler/ &&" 48cmd_sched += "cd ${execute_path}/scheduler/ || exit && export GLOG_v=1 &&" 49cmd_sched += "python ${self_path}/../cloud_train.py" 50cmd_sched += " --device_target=" + device_target 51cmd_sched += " --server_mode=" + server_mode 52cmd_sched += " --ms_role=MS_SCHED" 53cmd_sched += " --worker_num=" + str(worker_num) 54cmd_sched += " --server_num=" + str(server_num) 55cmd_sched += " --scheduler_ip=" + scheduler_ip 56cmd_sched += " --scheduler_port=" + str(scheduler_port) 57cmd_sched += " --client_password=" + str(client_password) 58cmd_sched += " --server_password=" + str(server_password) 59cmd_sched += " --enable_ssl=" + str(enable_ssl) 60cmd_sched += " --scheduler_manage_port=" + str(scheduler_manage_port) 61cmd_sched += " > scheduler.log 2>&1 &" 62 63subprocess.call(['bash', '-c', cmd_sched]) 64