Repository: incubator-singa Updated Branches: refs/heads/master 74a28dcb4 -> 9ff176c30
SINGA-81 Add Python Helper, which enables users to construct a model (JobProto) and run Singa in Python - Updated model.py . add "device" field in evaluate() to run singa on gpu for only test . modify "fixed" to "fixedstep" for kFixedStep of leaning rate type Project: http://git-wip-us.apache.org/repos/asf/incubator-singa/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-singa/commit/3c127300 Tree: http://git-wip-us.apache.org/repos/asf/incubator-singa/tree/3c127300 Diff: http://git-wip-us.apache.org/repos/asf/incubator-singa/diff/3c127300 Branch: refs/heads/master Commit: 3c12730017ba21b03d2845fe2f9a7c72916d3d19 Parents: 8b69cad Author: chonho <[email protected]> Authored: Tue Dec 29 10:46:37 2015 +0800 Committer: chonho <[email protected]> Committed: Fri Jan 1 15:59:14 2016 +0800 ---------------------------------------------------------------------- tool/python/singa/model.py | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-singa/blob/3c127300/tool/python/singa/model.py ---------------------------------------------------------------------- diff --git a/tool/python/singa/model.py b/tool/python/singa/model.py index 51c4126..d68d143 100644 --- a/tool/python/singa/model.py +++ b/tool/python/singa/model.py @@ -184,13 +184,15 @@ class Model(object): def evaluate(self, data=None, alg='bp', - checkpoint_path=None, execpath='', **fields): + checkpoint_path=None, execpath='', device=None, **fields): ''' required data = (Data) // Data class object for testing data optional - checkpoint_path = (list) // checkpoint path is necessary only for testing - execpaths = (string) // path to user's own executable + alg = (string) // algorithm type, (backpropagation at default) + checkpoint_path = (list) // checkpoint path is necessary only for testing + execpaths = (string) // path to user's own executable + device = (int/list) // a list of gpu ids **fields (KEY=VALUE) batch_size = (int) // batch size for testing data test_freq = (int) // frequency of testing @@ -222,6 +224,11 @@ class Model(object): # set Train_one_batch component, using backprogapation at default setval(self.jobconf, train_one_batch=Algorithm(type=enumAlgType(alg)).proto) + # use of cudnn + if device != None: + setval(self.jobconf, gpu=device) + self.cudnn = True + self.build() # construct Nneuralnet Component #--- generate job.conf file for debug purpose @@ -342,7 +349,13 @@ class Updater(object): def __init__(self, upd_type, lr, lr_type, decay, momentum, step, step_lr, **fields): - + ''' + required + upd_type = (enum) // enum type of updater + lr = (float) // base learning rate + optional + lr_type = (string) // type of the learning rate (Fixed at default) + ''' upd = Message('Updater', type=upd_type, **fields).proto setval(upd.learning_rate, base_lr=lr) if decay > 0: @@ -355,14 +368,16 @@ class Updater(object): elif lr_type == 'step': cp = Message('Step', change_freq=60, gamma=0.997) setval(upd.learning_rate, type=kStep, step_conf=cp.proto) - elif lr_type == 'fixed': + elif lr_type == 'fixedstep': cp = Message('FixedStep', step=step, step_lr=step_lr) setval(upd.learning_rate, type=kFixedStep, fixedstep_conf=cp.proto) elif lr_type == 'linear': cp = Message('Linear', change_freq=10, final_lr=0.1) setval(upd.learning_rate, type=kLinear, linear_conf=cp.proto) + self.proto = upd + class SGD(Updater): def __init__(self, lr=0.01, lr_type=None, decay=0, momentum=0, @@ -377,7 +392,6 @@ class SGD(Updater): step = (int/list) // steps step_lr = (float/list) // learning rate after the steps **fields (KEY=VALUE) - ''' assert lr super(SGD, self).__init__(upd_type=kSGD,
