-
Notifications
You must be signed in to change notification settings - Fork 14
[debug]debug with profiler #80
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -141,37 +141,39 @@ def run_benchmark(model, args): | |
| train_reader = paddle.batch( | ||
| paddle.dataset.mnist.train(), batch_size=args.batch_size) | ||
|
|
||
| for pass_id in range(args.pass_num): | ||
| accuracy.reset(exe) | ||
| pass_start = time.time() | ||
| for batch_id, data in enumerate(train_reader()): | ||
| img_data = np.array( | ||
| map(lambda x: x[0].reshape([1, 28, 28]), data)).astype(DTYPE) | ||
| y_data = np.array(map(lambda x: x[1], data)).astype("int64") | ||
| y_data = y_data.reshape([len(y_data), 1]) | ||
|
|
||
| start = time.time() | ||
| outs = exe.run( | ||
| fluid.default_main_program(), | ||
| feed={"pixel": img_data, | ||
| "label": y_data}, | ||
| fetch_list=[avg_cost] + accuracy.metrics | ||
| ) # The accuracy is the accumulation of batches, but not the current batch. | ||
|
|
||
| end = time.time() | ||
| loss = np.array(outs[0]) | ||
| acc = np.array(outs[1]) | ||
| print("pass=%d, batch=%d, loss=%f, error=%f, elapse=%f" % | ||
| (pass_id, batch_id, loss, 1 - acc, (end - start) / 1000)) | ||
|
|
||
| pass_end = time.time() | ||
|
|
||
| train_avg_acc = accuracy.eval(exe) | ||
| test_avg_acc = eval_test(exe, accuracy, inference_program) | ||
|
|
||
| print("pass=%d, train_avg_acc=%f, test_avg_acc=%f, elapse=%f" % | ||
| (pass_id, train_avg_acc, test_avg_acc, | ||
| (pass_end - pass_start) / 1000)) | ||
| with profiler.profiler(args.device, 'total') as prof: | ||
| for pass_id in range(args.pass_num): | ||
| accuracy.reset(exe) | ||
| pass_start = time.time() | ||
| for batch_id, data in enumerate(train_reader()): | ||
| img_data = np.array( | ||
| map(lambda x: x[0].reshape([1, 28, 28]), data)).astype( | ||
| DTYPE) | ||
| y_data = np.array(map(lambda x: x[1], data)).astype("int64") | ||
| y_data = y_data.reshape([len(y_data), 1]) | ||
|
|
||
| start = time.time() | ||
| outs = exe.run( | ||
| fluid.default_main_program(), | ||
| feed={"pixel": img_data, | ||
| "label": y_data}, | ||
| fetch_list=[avg_cost] + accuracy.metrics | ||
| ) # The accuracy is the accumulation of batches, but not the current batch. | ||
|
|
||
| end = time.time() | ||
| loss = np.array(outs[0]) | ||
| acc = np.array(outs[1]) | ||
| print("pass=%d, batch=%d, loss=%f, error=%f, elapse=%f" % | ||
| (pass_id, batch_id, loss, 1 - acc, (end - start) / 1000)) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 计时建议带上单位,以及 这里是要以 ks 为单位吗? |
||
|
|
||
| pass_end = time.time() | ||
|
|
||
| train_avg_acc = accuracy.eval(exe) | ||
| test_avg_acc = eval_test(exe, accuracy, inference_program) | ||
|
|
||
| print("pass=%d, train_avg_acc=%f, test_avg_acc=%f, elapse=%f" % | ||
| (pass_id, train_avg_acc, test_avg_acc, | ||
| (pass_end - pass_start) / 1000)) | ||
|
|
||
|
|
||
| if __name__ == '__main__': | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -190,7 +190,7 @@ def run_benchmark(model, args): | |
| opts = optimizer.minimize(avg_cost) | ||
| accuracy = fluid.evaluator.Accuracy(input=predict, label=label) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fluid.evaluator 下无 Accuracy,请针对本文件所有相应地方做相应修改。 |
||
|
|
||
| fluid.memory_optimize(fluid.default_main_program()) | ||
| # fluid.memory_optimize(fluid.default_main_program()) | ||
|
|
||
| train_reader = paddle.batch( | ||
| paddle.reader.shuffle( | ||
|
|
@@ -230,10 +230,11 @@ def run_benchmark(model, args): | |
| data)).astype('float32') | ||
| label = np.array(map(lambda x: x[1], data)).astype('int64') | ||
| label = label.reshape([-1, 1]) | ||
| loss, acc = exe.run(fluid.default_main_program(), | ||
| feed={'data': image, | ||
| 'label': label}, | ||
| fetch_list=[avg_cost] + accuracy.metrics) | ||
| with profiler.profiler(args.device, 'total') as prof: | ||
| loss, acc = exe.run(fluid.default_main_program(), | ||
| feed={'data': image, | ||
| 'label': label}, | ||
| fetch_list=[avg_cost] + accuracy.metrics) | ||
| every_pass_acc.append(acc) | ||
| every_pass_loss.append(loss) | ||
| pass_acc = accuracy.eval(exe) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,6 +10,8 @@ | |
| import argparse | ||
| import functools | ||
|
|
||
| import paddle.v2.fluid.profiler as profiler | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. paddle.fluid ,前几行也须进行相应修改。 |
||
|
|
||
| parser = argparse.ArgumentParser(description=__doc__) | ||
| parser.add_argument( | ||
| '--batch_size', type=int, default=128, help="Batch size for training.") | ||
|
|
@@ -18,7 +20,7 @@ | |
| type=float, | ||
| default=1e-3, | ||
| help="Learning rate for training.") | ||
| parser.add_argument('--num_passes', type=int, default=50, help="No. of passes.") | ||
| parser.add_argument('--pass_num', type=int, default=50, help="No. of passes.") | ||
| parser.add_argument( | ||
| '--device', | ||
| type=str, | ||
|
|
@@ -52,6 +54,7 @@ def conv_block(input, num_filter, groups, dropouts): | |
| conv_with_batchnorm=True, | ||
| conv_batchnorm_drop_rate=dropouts, | ||
| pool_type='max') | ||
| # use_cudnn=False) | ||
|
|
||
| conv1 = conv_block(input, 64, 2, [0.3, 0]) | ||
| conv2 = conv_block(conv1, 128, 2, [0.4, 0]) | ||
|
|
@@ -94,23 +97,24 @@ def main(): | |
| # Evaluator | ||
| accuracy = fluid.evaluator.Accuracy(input=predict, label=label) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fluid.evaluator 下无 Accuracy,请针对本文件所有相应地方做相应修改。 |
||
|
|
||
| # inference program | ||
| inference_program = fluid.default_main_program().clone() | ||
| with fluid.program_guard(inference_program): | ||
| test_target = accuracy.metrics + accuracy.states | ||
| inference_program = fluid.io.get_inference_program(test_target) | ||
| # # inference program | ||
| # inference_program = fluid.default_main_program().clone() | ||
| # with fluid.program_guard(inference_program): | ||
| # test_target = accuracy.metrics + accuracy.states | ||
| # inference_program = fluid.io.get_inference_program(test_target) | ||
|
|
||
| # Optimization | ||
| optimizer = fluid.optimizer.Adam(learning_rate=args.learning_rate) | ||
| opts = optimizer.minimize(avg_cost) | ||
|
|
||
| fluid.memory_optimize(fluid.default_main_program()) | ||
| # fluid.memory_optimize(fluid.default_main_program()) | ||
|
|
||
| # Initialize executor | ||
| place = core.CPUPlace() if args.device == 'CPU' else core.CUDAPlace(0) | ||
| exe = fluid.Executor(place) | ||
|
|
||
| # Parameter initialization | ||
| # with profiler.profiler(args.device, 'total') as prof: | ||
| exe.run(fluid.default_startup_program()) | ||
|
|
||
| # data reader | ||
|
|
@@ -141,7 +145,7 @@ def test(exe): | |
| return accuracy.eval(exe) | ||
|
|
||
| iters = 0 | ||
| for pass_id in range(args.num_passes): | ||
| for pass_id in range(args.pass_num): | ||
| # train | ||
| start_time = time.time() | ||
| num_samples = 0 | ||
|
|
@@ -152,10 +156,11 @@ def test(exe): | |
| y_data = np.array(map(lambda x: x[1], data)).astype("int64") | ||
| y_data = y_data.reshape([-1, 1]) | ||
|
|
||
| loss, acc = exe.run(fluid.default_main_program(), | ||
| feed={"pixel": img_data, | ||
| "label": y_data}, | ||
| fetch_list=[avg_cost] + accuracy.metrics) | ||
| with profiler.profiler(args.device, 'total') as prof: | ||
| loss, acc = exe.run(fluid.default_main_program(), | ||
| feed={"pixel": img_data, | ||
| "label": y_data}, | ||
| fetch_list=[avg_cost] + accuracy.metrics) | ||
| iters += 1 | ||
| num_samples += len(data) | ||
| print( | ||
|
|
@@ -165,11 +170,11 @@ def test(exe): | |
|
|
||
| pass_elapsed = time.time() - start_time | ||
| pass_train_acc = accuracy.eval(exe) | ||
| pass_test_acc = test(exe) | ||
| print( | ||
| "Pass = %d, Training performance = %f imgs/s, Train accuracy = %f, Test accuracy = %f\n" | ||
| % (pass_id, num_samples / pass_elapsed, pass_train_acc, | ||
| pass_test_acc)) | ||
| # pass_test_acc = test(exe) | ||
| # print( | ||
| # "Pass = %d, Training performance = %f imgs/s, Train accuracy = %f, Test accuracy = %f\n" | ||
| # % (pass_id, num_samples / pass_elapsed, pass_train_acc, | ||
| # pass_test_acc)) | ||
|
|
||
|
|
||
| def print_arguments(): | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fluid.evaluator 下无 Accuracy,请针对本文件所有相应地方做相应修改。
以及前面的 paddle.v2.fluid -> paddle.fluid