print('Waiting for PS\'s command...')
sys.stdout.flush()
client_socket.settimeout(600)
while True:
    signal = client_socket.recv(10)
    if signal == SRC.purpose:
        print('Sending init purpose...')
        sys.stdout.flush()
        client_socket.send(SRC.init)
        break
    else:
        client_socket.close()
        print('Server Error! Exit!')
        exit(-1)

hyperparameters = communication.get_np_array(client_socket)
communication_rounds = hyperparameters['communication_rounds']
local_epoch_num = hyperparameters['local_epoch_num']
train_batch_size = hyperparameters['train_batch_size']
embedding_dim = hyperparameters['embedding_dim']
opt_alg = hyperparameters['opt_alg']
clip_bound = hyperparameters['clip_bound']
init_user_id_set = hyperparameters['init_user_id_set']

# Some global parameters
machine_index = FLAGS.machine_index
random_user_index = init_user_id_set[machine_index -
                                     1]  #To save next Taobao user file index

# Probability parameters customized by a client for double randomized response
# prob2 and prob6 are not needed here for testing model accuracy
Beispiel #2
0
################################################################
with open('../taobao_data_process/taobao_user_item_cate_count.pkl', 'rb') as f:
    user_count, item_count, cate_count = pickle.load(f)

for round_num in range(1, communication_rounds + 1):
    print('Round %d starts!' % round_num)
    sys.stdout.flush()

    global_start_time = time.time()
    ######################################################
    # Phase 0: Initialization and prepare some parameters
    ######################################################
    print('Phase 0: Initialization begins...')
    sys.stdout.flush()
    client_socket = communication.start_socket_client()
    received_message = communication.get_np_array(client_socket)
    # It is the client's file index, but in fact contains the data of Taobao user with 'userID'
    client_index = received_message['client_index']
    hyperparameters = received_message['hyperparameters']
    union_security_para_dict = received_message['union_security_para_dict']
    fedsubavg_security_para_dict = received_message[
        'fedsubavg_security_para_dict']
    # reply to checking "online" state
    cl_pl_fn.response_to_check_connection(client_socket)

    local_epoch_num = hyperparameters['local_epoch_num']
    train_batch_size = hyperparameters['train_batch_size']
    learning_rate = hyperparameters[
        'learning_rate']  # please pay attention to its update (already update by ps)
    embedding_dim = hyperparameters['embedding_dim']
    opt_alg = hyperparameters['opt_alg']