|
|
@ -50,11 +50,12 @@ class Components :
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
#
|
|
|
|
#
|
|
|
|
# @TODO: we need to log something here about the parameters being passed
|
|
|
|
# @TODO: we need to log something here about the parameters being passed
|
|
|
|
pointer = args['reader'] if 'reader' in args else lambda: Components.get(**args)
|
|
|
|
# pointer = args['reader'] if 'reader' in args else lambda: Components.get(**args)
|
|
|
|
df = pointer()
|
|
|
|
df = args['reader']()
|
|
|
|
if df.shape[0] == 0 :
|
|
|
|
|
|
|
|
print ("CAN NOT TRAIN EMPTY DATASET ")
|
|
|
|
# if df.shape[0] == 0 :
|
|
|
|
return
|
|
|
|
# print ("CAN NOT TRAIN EMPTY DATASET ")
|
|
|
|
|
|
|
|
# return
|
|
|
|
#
|
|
|
|
#
|
|
|
|
# Now we can parse the arguments and submit the entire thing to training
|
|
|
|
# Now we can parse the arguments and submit the entire thing to training
|
|
|
|
#
|
|
|
|
#
|
|
|
@ -113,18 +114,29 @@ class Components :
|
|
|
|
|
|
|
|
|
|
|
|
pass
|
|
|
|
pass
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
|
|
|
|
print ('.....')
|
|
|
|
partition = args['partition'] if 'partition' in args else ''
|
|
|
|
partition = args['partition'] if 'partition' in args else ''
|
|
|
|
log_folder = os.sep.join([log_folder,args['context'],partition])
|
|
|
|
log_folder = os.sep.join([log_folder,args['context'],str(partition)])
|
|
|
|
_args = {"batch_size":10000,"logs":log_folder,"context":args['context'],"max_epochs":150,"column":args['columns'],"id":"person_id","logger":logger}
|
|
|
|
_args = {"batch_size":10000,"logs":log_folder,"context":args['context'],"max_epochs":150,"column":args['columns'],"id":"person_id","logger":logger}
|
|
|
|
_args['max_epochs'] = 150 if 'max_epochs' not in args else int(args['max_epochs'])
|
|
|
|
_args['max_epochs'] = 150 if 'max_epochs' not in args else int(args['max_epochs'])
|
|
|
|
_args['num_gpu'] = int(args['num_gpu']) if 'num_gpu' in args else 1
|
|
|
|
|
|
|
|
os.environ['CUDA_VISIBLE_DEVICES'] = str(args['gpu']) if 'gpu' in args else '0'
|
|
|
|
#
|
|
|
|
|
|
|
|
# We ask the process to assume 1 gpu given the system number of GPU and that these tasks can run in parallel
|
|
|
|
|
|
|
|
#
|
|
|
|
|
|
|
|
if int(args['num_gpu']) > 1 :
|
|
|
|
|
|
|
|
_args['gpu'] = int(args['gpu']) if int(args['gpu']) < 8 else np.random.choice(np.arange(8)).astype(int)[0]
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
|
|
|
_args['gpu'] = 0
|
|
|
|
|
|
|
|
_args['num_gpu'] = 1
|
|
|
|
|
|
|
|
os.environ['CUDA_VISIBLE_DEVICES'] = str(args['gpu'])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
_args['data'] = df
|
|
|
|
_args['data'] = df
|
|
|
|
#
|
|
|
|
#
|
|
|
|
# @log :
|
|
|
|
# @log :
|
|
|
|
# Logging information about the training process for this partition (or not)
|
|
|
|
# Logging information about the training process for this partition (or not)
|
|
|
|
#
|
|
|
|
#
|
|
|
|
|
|
|
|
|
|
|
|
info = {"rows":df.shape[0],"cols":df.shape[1], "partition":int(partition),"logs":_args['logs']}
|
|
|
|
info = {"rows":df.shape[0],"cols":df.shape[1], "partition":int(partition),"logs":_args['logs']}
|
|
|
|
|
|
|
|
|
|
|
|
logger.write({"module":"train","action":"train","input":info})
|
|
|
|
logger.write({"module":"train","action":"train","input":info})
|
|
|
@ -291,7 +303,7 @@ if __name__ == '__main__' :
|
|
|
|
if ''.join(content).isnumeric() :
|
|
|
|
if ''.join(content).isnumeric() :
|
|
|
|
#
|
|
|
|
#
|
|
|
|
# we have partitions we are working with
|
|
|
|
# we have partitions we are working with
|
|
|
|
make = lambda _args: (Components()).generate(_args)
|
|
|
|
|
|
|
|
jobs = []
|
|
|
|
jobs = []
|
|
|
|
del args['reader']
|
|
|
|
del args['reader']
|
|
|
|
columns = DATA.columns.tolist()
|
|
|
|
columns = DATA.columns.tolist()
|
|
|
@ -310,13 +322,13 @@ if __name__ == '__main__' :
|
|
|
|
args['gpu'] = id
|
|
|
|
args['gpu'] = id
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
args['gpu']=0
|
|
|
|
args['gpu']=0
|
|
|
|
|
|
|
|
make = lambda _args: (Components()).generate(_args)
|
|
|
|
job = Process(target=make,args=(args,))
|
|
|
|
job = Process(target=make,args=(args,))
|
|
|
|
job.name = 'generator # '+str(id)
|
|
|
|
job.name = 'generator # '+str(id)
|
|
|
|
job.start()
|
|
|
|
job.start()
|
|
|
|
jobs.append(job)
|
|
|
|
jobs.append(job)
|
|
|
|
|
|
|
|
|
|
|
|
print (["Started ",len(jobs),"generator"+"s" if len(jobs)>1 else "" ])
|
|
|
|
print (["Started ",len(jobs),"generators" if len(jobs)>1 else "generator" ])
|
|
|
|
while len(jobs)> 0 :
|
|
|
|
while len(jobs)> 0 :
|
|
|
|
jobs = [job for job in jobs if job.is_alive()]
|
|
|
|
jobs = [job for job in jobs if job.is_alive()]
|
|
|
|
time.sleep(2)
|
|
|
|
time.sleep(2)
|
|
|
@ -358,9 +370,31 @@ if __name__ == '__main__' :
|
|
|
|
# qreader.read(1)
|
|
|
|
# qreader.read(1)
|
|
|
|
pass
|
|
|
|
pass
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
|
|
|
|
PART_SIZE = int(args['jobs']) if 'jobs' in args else 8
|
|
|
|
|
|
|
|
DATA = reader()
|
|
|
|
|
|
|
|
DATA = np.array_split(DATA[args['columns']],PART_SIZE)
|
|
|
|
|
|
|
|
jobs = []
|
|
|
|
|
|
|
|
for index in range(0,int(args['jobs'])) :
|
|
|
|
|
|
|
|
if 'focus' in args and int(args['focus']) != index :
|
|
|
|
|
|
|
|
continue
|
|
|
|
|
|
|
|
args['partition'] = index
|
|
|
|
|
|
|
|
_df = pd.DataFrame(DATA[index],columns=args['columns'])
|
|
|
|
|
|
|
|
args['reader'] = lambda: _df
|
|
|
|
|
|
|
|
make = lambda _args: (Components()).train(**_args)
|
|
|
|
|
|
|
|
job = Process(target=make,args=(args,))
|
|
|
|
|
|
|
|
job.name = 'Trainer # ' + str(index)
|
|
|
|
|
|
|
|
job.start()
|
|
|
|
|
|
|
|
jobs.append(job)
|
|
|
|
|
|
|
|
# args['gpu']
|
|
|
|
|
|
|
|
print (["Started ",len(jobs),"trainers" if len(jobs)>1 else "trainer" ])
|
|
|
|
|
|
|
|
while len(jobs)> 0 :
|
|
|
|
|
|
|
|
jobs = [job for job in jobs if job.is_alive()]
|
|
|
|
|
|
|
|
time.sleep(2)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# trainer = Components()
|
|
|
|
|
|
|
|
# trainer.train(**args)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
trainer = Components()
|
|
|
|
|
|
|
|
trainer.train(**args)
|
|
|
|
|
|
|
|
# Components.train(**args)
|
|
|
|
# Components.train(**args)
|
|
|
|
#for args in PIPELINE :
|
|
|
|
#for args in PIPELINE :
|
|
|
|
#args['dataset'] = 'combined20190510'
|
|
|
|
#args['dataset'] = 'combined20190510'
|
|
|
|