Skip to content
This repository has been archived by the owner on Nov 17, 2023. It is now read-only.

Commit

Permalink
[MXNET-124] Upgrade examples to use newer profiler API (#10190)
Browse files Browse the repository at this point in the history
* Upgrade examples to use newer profiler API

* Trigger rebuild
  • Loading branch information
cjolivier01 authored and piiswrong committed Mar 22, 2018
1 parent 57534bf commit b51cfbe
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 16 deletions.
6 changes: 3 additions & 3 deletions benchmark/python/sparse/sparse_end2end.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,8 +239,8 @@ def row_sparse_pull(kv, key, data, slices, weight_array, priority):
device = 'gpu' + str(args.num_gpu)
name = 'profile_' + args.dataset + '_' + device + '_nworker' + str(num_worker)\
+ '_batchsize' + str(args.batch_size) + '_outdim' + str(args.output_dim) + '.json'
mx.profiler.profiler_set_config(mode='all', filename=name)
mx.profiler.profiler_set_state('run')
mx.profiler.set_config(profile_all=True, filename=name)
mx.profiler.set_state('run')

logging.debug('start training ...')
start = time.time()
Expand Down Expand Up @@ -301,7 +301,7 @@ def row_sparse_pull(kv, key, data, slices, weight_array, priority):
logging.info('|cpu/{} cores| {} | {} | {} |'.format(str(num_cores), str(num_worker), str(average_cost_epoch), rank))
data_iter.reset()
if profiler:
mx.profiler.profiler_set_state('stop')
mx.profiler.set_state('stop')
end = time.time()
time_cost = end - start
logging.info('num_worker = {}, rank = {}, time cost = {}'.format(str(num_worker), str(rank), str(time_cost)))
6 changes: 3 additions & 3 deletions example/profiler/profiler_executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,15 +128,15 @@ def benchmark(mod, dry_run=10, iterations=10):

t0 = time.clock()

profiler.profiler_set_state('run')
profiler.set_state('run')
# real run
for i in range(iterations):
mod.forward(batch, is_train=True)
mod.backward()
mod.update()
for output in mod.get_outputs(merge_multi_context=False)[0]:
output.wait_to_read()
profiler.profiler_set_state('stop')
profiler.set_state('stop')

t1 = time.clock()
return (t1 - t0)*1000.0 / iterations
Expand All @@ -152,7 +152,7 @@ def executor(num_iteration):
args = parse_args()

if __name__ == '__main__':
mx.profiler.profiler_set_config(mode='symbolic', filename=args.profile_filename)
mx.profiler.set_config(profile_symbolic=True, filename=args.profile_filename)
print('profile file save to {0}'.format(args.profile_filename))
print('executor num_iteration: {0}'.format(args.iter_num))
executor_time = executor(args.iter_num)
Expand Down
6 changes: 3 additions & 3 deletions example/profiler/profiler_imageiter.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def run_imageiter(path_rec, n, batch_size=32):


if __name__ == '__main__':
mx.profiler.profiler_set_config(mode='all', filename='profile_imageiter.json')
mx.profiler.profiler_set_state('run')
mx.profiler.set_config(profile_all=True, filename='profile_imageiter.json')
mx.profiler.set_state('run')
run_imageiter('test.rec', 20) # See http://mxnet.io/tutorials/python/image_io.html for how to create .rec files.
mx.profiler.profiler_set_state('stop')
mx.profiler.set_state('stop')
6 changes: 3 additions & 3 deletions example/profiler/profiler_matmul.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def parse_args():
args = parse_args()

if __name__ == '__main__':
mx.profiler.profiler_set_config(mode='symbolic', filename=args.profile_filename)
mx.profiler.set_config(profile_symbolic=True, filename=args.profile_filename)
print('profile file save to {0}'.format(args.profile_filename))

A = mx.sym.Variable('A')
Expand All @@ -53,10 +53,10 @@ def parse_args():
for i in range(args.iter_num):
if i == args.begin_profiling_iter:
t0 = time.clock()
mx.profiler.profiler_set_state('run')
mx.profiler.set_state('run')
if i == args.end_profiling_iter:
t1 = time.clock()
mx.profiler.profiler_set_state('stop')
mx.profiler.set_state('stop')
executor.forward()
c = executor.outputs[0]
c.wait_to_read()
Expand Down
6 changes: 3 additions & 3 deletions example/profiler/profiler_ndarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -316,8 +316,8 @@ def test_broadcast_to():


if __name__ == '__main__':
mx.profiler.profiler_set_config(mode='all', filename='profile_ndarray.json')
mx.profiler.profiler_set_state('run')
mx.profiler.set_config(profile_all=True, filename='profile_ndarray.json')
mx.profiler.set_state('run')
test_ndarray_slice_along_axis()
test_broadcast()
test_ndarray_elementwise()
Expand All @@ -333,4 +333,4 @@ def test_broadcast_to():
test_ndarray_onehot()
test_ndarray_fill()
test_reduce()
mx.profiler.profiler_set_state('stop')
mx.profiler.set_state('stop')
2 changes: 1 addition & 1 deletion tests/python/unittest/test_profiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def test_profile_create_domain():


def test_profile_create_domain_dept():
profiler.profiler_set_config(mode='symbolic', filename='test_profile_create_domain_dept.json')
profiler.set_config(profile_symbolic=True, filename='test_profile_create_domain_dept.json')
profiler.set_state('run')
domain = profiler.Domain(name='PythonDomain')
print("Domain created: {}".format(str(domain)))
Expand Down

0 comments on commit b51cfbe

Please sign in to comment.