-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclient.py
More file actions
50 lines (39 loc) · 1.5 KB
/
client.py
File metadata and controls
50 lines (39 loc) · 1.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import pika
import uuid
import argparse
import yaml
import os
import torch
import src.Log
from src.RpcClient import RpcClient
parser = argparse.ArgumentParser(description="Split learning framework")
parser.add_argument('--layer_id', type=int, required=True, help='ID of layer, start from 1')
parser.add_argument('--device', type=str, required=False, help='Device of client')
args = parser.parse_args()
with open('config.yaml', 'r') as file:
config = yaml.safe_load(file)
client_id = uuid.uuid4()
address = config["rabbit"]["address"]
username = config["rabbit"]["username"]
password = config["rabbit"]["password"]
virtual_host = config["rabbit"]["virtual-host"]
device = None
if args.device is None:
if torch.cuda.is_available():
device = "cuda"
print(f"Using device: {torch.cuda.get_device_name(device)}")
else:
device = "cpu"
print(f"Using device: CPU")
else:
device = args.device
print(f"Using device: {device}")
credentials = pika.PlainCredentials(username, password)
connection = pika.BlockingConnection(pika.ConnectionParameters(address, 5672, f'{virtual_host}', credentials))
channel = connection.channel()
if __name__ == "__main__":
src.Log.print_with_color("[>>>] Client sending registration message to server...", "red")
data = {"action": "REGISTER", "client_id": client_id, "layer_id": args.layer_id,"message": "Hello from Client!"}
client = RpcClient(client_id, args.layer_id, channel, device)
client.send_to_server(data)
client.wait_response()