Skip to content

Commit c226299

Browse files
authored
Merge pull request #685 from alex-liang-kh/dev/v0.7.0
Dev/v0.7.0
2 parents 99ef513 + af71537 commit c226299

9 files changed

+222
-88
lines changed

python/fedml/cli/cli.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -717,6 +717,10 @@ def device():
717717
@click.option(
718718
"--master", "-m", default=None, is_flag=True, help="login as master device in the federated inference cluster.",
719719
)
720+
@click.option(
721+
"--infer_host", "-ih", type=str, default="127.0.0.1",
722+
help="used this ip address or domain name as inference host.",
723+
)
720724
@click.option(
721725
"--version",
722726
"-v",
@@ -751,9 +755,9 @@ def device():
751755
"--docker-rank", "-dr", default="1", help="docker client rank index (from 1 to n).",
752756
)
753757
def login_as_model_device_agent(
754-
userid, cloud, on_premise, master, version, local_server, runner_cmd, device_id, os_name, docker, docker_rank
758+
userid, cloud, on_premise, master, infer_host, version, local_server, runner_cmd, device_id, os_name, docker, docker_rank
755759
):
756-
device_login_entry.login_as_model_device_agent(userid, cloud, on_premise, master, version, local_server, runner_cmd, device_id, os_name, docker, docker_rank)
760+
device_login_entry.login_as_model_device_agent(userid, cloud, on_premise, master, infer_host, version, local_server, runner_cmd, device_id, os_name, docker, docker_rank)
757761

758762

759763
@device.command("logout", help="Logout from the ModelOps platform (model.fedml.ai)")

python/fedml/cli/model_deployment/device_client_constants.py

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,28 @@ def get_local_ip():
148148
s.close()
149149
return ip
150150

151+
@staticmethod
152+
def check_network_port_is_opened(port):
153+
import socket
154+
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
155+
try:
156+
s.connect(('localhost', int(port)))
157+
s.settimeout(1)
158+
s.shutdown(2)
159+
return True
160+
except:
161+
return False
162+
163+
@staticmethod
164+
def check_process_is_running(process_id):
165+
for proc in psutil.process_iter():
166+
try:
167+
if process_id == proc.pid:
168+
return True
169+
except (psutil.NoSuchProcess, psutil.AccessDenied, psutil.ZombieProcess):
170+
pass
171+
return False
172+
151173
@staticmethod
152174
def unzip_file(zip_file, unzip_file_path):
153175
result = False
@@ -310,14 +332,20 @@ def exit_process(process):
310332
pass
311333

312334
@staticmethod
313-
def exec_console_with_script(script_path, should_capture_stdout=False, should_capture_stderr=False):
335+
def exec_console_with_script(script_path, should_capture_stdout=False, should_capture_stderr=False, no_sys_out_err=False):
314336
stdout_flag = subprocess.PIPE if should_capture_stdout else sys.stdout
315337
stderr_flag = subprocess.PIPE if should_capture_stderr else sys.stderr
316338

317339
if platform.system() == 'Windows':
318-
script_process = subprocess.Popen(script_path, stdout=stdout_flag, stderr=stderr_flag)
340+
if no_sys_out_err:
341+
script_process = subprocess.Popen(script_path)
342+
else:
343+
script_process = subprocess.Popen(script_path, stdout=stdout_flag, stderr=stderr_flag)
319344
else:
320-
script_process = subprocess.Popen(['bash', '-c', script_path], stdout=stdout_flag, stderr=stderr_flag)
345+
if no_sys_out_err:
346+
script_process = subprocess.Popen(['bash', '-c', script_path])
347+
else:
348+
script_process = subprocess.Popen(['bash', '-c', script_path], stdout=stdout_flag, stderr=stderr_flag)
321349

322350
return script_process
323351

python/fedml/cli/model_deployment/device_client_daemon.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
parser.add_argument("--role", "-r", type=str, default="client")
1818
parser.add_argument("--device_id", "-id", type=str, default="0")
1919
parser.add_argument("--os_name", "-os", type=str, default="")
20+
parser.add_argument("--infer_host", "-ih", type=str, default="127.0.0.1")
2021
args = parser.parse_args()
2122
args.user = args.user
2223

@@ -40,7 +41,9 @@
4041
"-id",
4142
args.device_id,
4243
"-os",
43-
args.os_name
44+
args.os_name,
45+
"-ih",
46+
args.infer_host
4447
]
4548
)
4649
ret_code, exec_out, exec_err = ClientConstants.get_console_sys_out_pipe_err_results(login_pid)

python/fedml/cli/model_deployment/device_client_login.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ def __login_as_client(args, userid, version):
138138
ClientConstants.save_runner_infos(args.current_device_id + "." + args.os_name, edge_id, run_id=0)
139139

140140
# Setup MQTT connection for communication with the FedML server.
141+
runner.infer_host = args.infer_host
141142
runner.setup_agent_mqtt_connection(service_config)
142143

143144
# Start mqtt looper
@@ -161,6 +162,7 @@ def logout():
161162
parser.add_argument("--role", "-r", type=str, default="md.on_premise_device")
162163
parser.add_argument("--device_id", "-id", type=str, default="0")
163164
parser.add_argument("--os_name", "-os", type=str, default="")
165+
parser.add_argument("--infer_host", "-ih", type=str, default="127.0.0.1")
164166
args = parser.parse_args()
165167
args.user = args.user
166168
if args.type == 'login':

python/fedml/cli/model_deployment/device_client_runner.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ def __init__(self, args, edge_id=0, request_json=None, agent_config=None, run_id
6969

7070
self.mlops_metrics = None
7171
self.client_active_list = dict()
72-
# logging.info("Current directory of client agent: " + self.cur_dir)
72+
self.infer_host = "127.0.0.1"
7373

7474
def unzip_file(self, zip_file, unzip_file_path):
7575
result = False
@@ -178,7 +178,8 @@ def run(self):
178178
ClientConstants.INFERENCE_METRIC_PORT,
179179
use_gpu, memory_size,
180180
ClientConstants.INFERENCE_CONVERTOR_IMAGE,
181-
ClientConstants.INFERENCE_SERVER_IMAGE)
181+
ClientConstants.INFERENCE_SERVER_IMAGE,
182+
self.infer_host)
182183
if inference_output_url == "":
183184
self.setup_client_mqtt_mgr()
184185
self.wait_client_mqtt_connected()
@@ -472,6 +473,7 @@ def callback_start_deployment(self, topic, payload):
472473
client_runner = FedMLClientRunner(
473474
self.args, edge_id=self.edge_id, request_json=request_json, agent_config=self.agent_config, run_id=run_id
474475
)
476+
client_runner.infer_host = self.infer_host
475477
self.process = Process(target=client_runner.run)
476478
#client_runner.run()
477479
self.process.start()

python/fedml/cli/model_deployment/device_login_entry.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323

2424
def login_as_model_device_agent(
25-
userid, cloud, on_premise, master, version, local_server, runner_cmd, device_id, os_name, docker, docker_rank
25+
userid, cloud, on_premise, master, infer_host, version, local_server, runner_cmd, device_id, os_name, docker, docker_rank
2626
):
2727
account_id = userid[0]
2828
platform_url = "open.fedml.ai"
@@ -91,7 +91,9 @@ def login_as_model_device_agent(
9191
"-id",
9292
device_id,
9393
"-os",
94-
os_name
94+
os_name,
95+
"-ih",
96+
infer_host
9597
]
9698
).pid
9799
sys_utils.save_login_process(ClientConstants.LOCAL_HOME_RUNNER_DIR_NAME,

python/fedml/cli/model_deployment/device_model_cards.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,7 @@ def push_model(self, model_name, user_id, no_uploading_modelops=False):
174174
return "", ""
175175

176176
model_storage_url = self.push_model_to_s3(model_name, model_zip_path, user_id)
177+
print("Model storage url: {}".format(model_storage_url))
177178
if not no_uploading_modelops:
178179
if model_storage_url != "":
179180
upload_result = self.upload_model_api(model_name, model_storage_url, user_id)

0 commit comments

Comments
 (0)