def connect_server(self): from paddle import fluid from paddle_fl.paddle_fl.core.trainer.fl_trainer import FLTrainerFactory from paddle_fl.paddle_fl.core.master.fl_job import FLRunTimeJob import numpy as np import sys import logging self.processLabel.setText('connecting') trainer_id = self.id job_path = self.config['path']['job_path'] job = FLRunTimeJob() job.load_trainer_job(job_path, trainer_id) job._scheduler_ep = '{}:{}'.format(self.config['scheduler']['ip'], self.config['scheduler']['port']) # print(job._trainer_send_program) self.trainer = MFLTrainerFactory().create_fl_trainer(job) use_cuda = False place = fluid.CUDAPlace(0) if use_cuda else fluid.CPUPlace() self.trainer._current_ep = '{}:{}'.format( self.config['client']['ip'], int(self.config['client']['port']) + self.id) print('prepared ok') self.trainer.start(place=place) self.trainer._logger.setLevel(logging.DEBUG) print('connected ok') self.processLabel.setText('connected') self.trainThread = threading.Thread(target=self.train) self.processLabel.setText('training') self.trainThread.start() self.trainThread.join() self.processLabel.setText('finished')
import time logging.basicConfig( filename="test.log", filemode="w", format="%(asctime)s %(name)s:%(levelname)s:%(message)s", datefmt="%d-%M-%Y %H:%M:%S", level=logging.DEBUG) trainer_id = int(sys.argv[1]) # trainer id for each guest place = fluid.CPUPlace() train_file_dir = "mid_data/node4/%d/" % trainer_id job_path = "fl_job_config" job = FLRunTimeJob() job.load_trainer_job(job_path, trainer_id) job._scheduler_ep = "127.0.0.1:9091" # Inform the scheduler IP to trainer trainer = FLTrainerFactory().create_fl_trainer(job) trainer._current_ep = "127.0.0.1:{}".format(9000 + trainer_id) place = fluid.CPUPlace() trainer.start(place) r = Gru4rec_Reader() train_reader = r.reader(train_file_dir, place, batch_size=125) output_folder = "model_node4" epoch_i = 0 while not trainer.stop(): epoch_i += 1 train_step = 0 for data in train_reader(): #print(np.array(data['src_wordseq']))
import paddle.fluid as fluid import logging import math import time logging.basicConfig(filename="test.log", filemode="w", format="%(asctime)s %(name)s:%(levelname)s:%(message)s", datefmt="%d-%M-%Y %H:%M:%S", level=logging.DEBUG) trainer_id = int(sys.argv[1]) # trainer id for each guest job_path = "fl_job_config" job = FLRunTimeJob() job.load_trainer_job(job_path, trainer_id) job._scheduler_ep = "127.0.0.1:9091" # Inform scheduler IP address to trainer trainer = FLTrainerFactory().create_fl_trainer(job) trainer._current_ep = "127.0.0.1:{}".format(9000 + trainer_id) place = fluid.CPUPlace() trainer.start(place) test_program = trainer._main_program.clone(for_test=True) train_reader = paddle.batch(paddle.reader.shuffle(paddle.dataset.mnist.train(), buf_size=500), batch_size=64) test_reader = paddle.batch(paddle.dataset.mnist.test(), batch_size=64) img = fluid.layers.data(name='img', shape=[1, 28, 28], dtype='float32') label = fluid.layers.data(name='label', shape=[1], dtype='int64') feeder = fluid.DataFeeder(feed_list=[img, label], place=fluid.CPUPlace())
# Copyright (c) 2019 PaddlePaddle Authors. All Rights Reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. import paddle_fl.paddle_fl as fl import paddle.fluid as fluid from paddle_fl.paddle_fl.core.server.fl_server import FLServer from paddle_fl.paddle_fl.core.master.fl_job import FLRunTimeJob server = FLServer() server_id = 0 job_path = "fl_job_config" job = FLRunTimeJob() job.load_server_job(job_path, server_id) job._scheduler_ep = "127.0.0.1:9091" # IP address for scheduler server.set_server_job(job) server._current_ep = "127.0.0.1:8181" # IP address for server server.start()
os.system("ls") os.system("gzip -d {}.tar.gz".format(message)) print("gzip finish") os.system("tar -xf {}.tar".format(message)) os.system("ls") zmq_socket.close() print("close socket") #program start if 'server' in message: server = FLServer() server_id = 0 job_path = "job_config" job = FLRunTimeJob() job.load_server_job(job_path, server_id) job._scheduler_ep = scheduler_conf["ENDPOINT"] server.set_server_job(job) server._current_ep = endpoint server.start() else: def reader(): for i in range(1000): data_dict = {} for i in range(3): data_dict[str(i)] = np.random.rand(1, 5).astype('float32') data_dict["label"] = np.random.randint(2, size=(1, 1)).astype('int64') yield data_dict trainer_id = message.split("trainer")[1] job_path = "job_config"
######### logging.basicConfig( filename="test.log", filemode="w", format="%(asctime)s %(name)s:%(levelname)s:%(message)s", datefmt="%d-%M-%Y %H:%M:%S", level=logging.DEBUG) # Load configs #################### trainer_id = int(args.id) # trainer id job_path = params["federated"]["job_path"] job = FLRunTimeJob() job.load_trainer_job(job_path, trainer_id) job._scheduler_ep = "127.0.0.1:"+ str(params["federated"]["scheduler_port"]) # Inform scheduler IP address to trainer trainer = FLTrainerFactory().create_fl_trainer(job) trainer._current_ep = "127.0.0.1:{}".format(params["federated"]["seed_of_clients_port"] + trainer_id) place = paddle.fluid.CPUPlace() trainer.start(place) test_program = trainer._main_program.clone(for_test = True) # Load data ############### # dataset = Time_series_loader(distributed = params["federated"]["distributed"], ts_path = params["federated"]["clients_path"], number_of_clients = params["federated"]["number_of_clients"], lookback = params["federated"]["lookback"], lookforward = params["federated"]["lookforward"]) dataset = select_data(params) train_reader = paddle.batch(reader = dataset.train_data(client = trainer_id), batch_size = params["federated"]["batch_size"])
def reader(): for i in range(1000): data_dict = {} for i in range(3): data_dict[str(i)] = np.random.rand(1, 5).astype('float32') data_dict["label"] = np.random.randint(2, size=(1, 1)).astype('int64') yield data_dict trainer_id = int(sys.argv[1]) # trainer id for each guest job_path = "fl_job_config" job = FLRunTimeJob() job.load_trainer_job(job_path, trainer_id) #job._scheduler_ep = "127.0.0.1:9091" # Inform the scheduler IP to trainer job._scheduler_ep = os.environ['FL_SCHEDULER_SERVICE_HOST'] + ":" + os.environ[ 'FL_SCHEDULER_SERVICE_PORT_FL_SCHEDULER'] trainer = FLTrainerFactory().create_fl_trainer(job) #trainer._current_ep = "127.0.0.1:{}".format(9000+trainer_id) trainer._current_ep = os.environ['TRAINER0_SERVICE_HOST'] + ":" + os.environ[ 'TRAINER0_SERVICE_PORT_TRAINER0'] place = fluid.CPUPlace() trainer.start(place) print(trainer._scheduler_ep, trainer._current_ep) output_folder = "fl_model" epoch_id = 0 while not trainer.stop(): print("batch %d start train" % (epoch_id)) train_step = 0 for data in reader(): trainer.run(feed=data, fetch=[]) train_step += 1
from paddle_fl.paddle_fl.core.server.fl_server import FLServer from paddle_fl.paddle_fl.core.master.fl_job import FLRunTimeJob import json import argparse parser = argparse.ArgumentParser() parser.add_argument('--config_path', help="path to the config file") args = parser.parse_args() with open(args.config_path, 'r') as fp: params = json.load(fp) server = FLServer() server_id = 0 job_path = params["federated"]["job_path"] print("job_path: ", job_path) job = FLRunTimeJob() job.load_server_job(job_path, server_id) job._scheduler_ep = "127.0.0.1:" + str(params["federated"]["scheduler_port"]) print("IP address for scheduler: ", job._scheduler_ep) server.set_server_job(job) server._current_ep = "127.0.0.1:" + str(params["federated"]["server_port"]) print("IP address for server: ", server._current_ep) server.start()