|
| 1 | +# Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved. |
| 2 | +# |
| 3 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +# you may not use this file except in compliance with the License. |
| 5 | +# You may obtain a copy of the License at |
| 6 | +# |
| 7 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +# |
| 9 | +# Unless required by applicable law or agreed to in writing, software |
| 10 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +# See the License for the specific language governing permissions and |
| 13 | +# limitations under the License. |
| 14 | + |
| 15 | +import argparse |
| 16 | + |
| 17 | +__all__ = ['parse_args', ] |
| 18 | + |
| 19 | +BENCHMARK_MODELS = [ |
| 20 | + "machine_translation", "resnet", "vgg", "mnist", "stacked_dynamic_lstm" |
| 21 | +] |
| 22 | + |
| 23 | + |
| 24 | +def parse_args(): |
| 25 | + parser = argparse.ArgumentParser('Fluid model benchmarks.') |
| 26 | + parser.add_argument( |
| 27 | + '--model', |
| 28 | + type=str, |
| 29 | + choices=BENCHMARK_MODELS, |
| 30 | + default='resnet', |
| 31 | + help='The model to run benchmark with.') |
| 32 | + parser.add_argument( |
| 33 | + '--batch_size', type=int, default=32, help='The minibatch size.') |
| 34 | + # args related to learning rate |
| 35 | + parser.add_argument( |
| 36 | + '--learning_rate', type=float, default=0.001, help='The learning rate.') |
| 37 | + # TODO(wuyi): add "--use_fake_data" option back. |
| 38 | + parser.add_argument( |
| 39 | + '--skip_batch_num', |
| 40 | + type=int, |
| 41 | + default=5, |
| 42 | + help='The first num of minibatch num to skip, for better performance test' |
| 43 | + ) |
| 44 | + parser.add_argument( |
| 45 | + '--iterations', type=int, default=80, help='The number of minibatches.') |
| 46 | + parser.add_argument( |
| 47 | + '--pass_num', type=int, default=100, help='The number of passes.') |
| 48 | + parser.add_argument( |
| 49 | + '--data_format', |
| 50 | + type=str, |
| 51 | + default='NCHW', |
| 52 | + choices=['NCHW', 'NHWC'], |
| 53 | + help='The data data_format, now only support NCHW.') |
| 54 | + parser.add_argument( |
| 55 | + '--device', |
| 56 | + type=str, |
| 57 | + default='GPU', |
| 58 | + choices=['CPU', 'GPU'], |
| 59 | + help='The device type.') |
| 60 | + parser.add_argument( |
| 61 | + '--gpus', |
| 62 | + type=int, |
| 63 | + default=1, |
| 64 | + help='If gpus > 1, will use ParallelExecutor to run, else use Executor.') |
| 65 | + # this option is available only for vgg and resnet. |
| 66 | + parser.add_argument( |
| 67 | + '--cpus', |
| 68 | + type=int, |
| 69 | + default=1, |
| 70 | + help='If cpus > 1, will use ParallelDo to run, else use Executor.') |
| 71 | + parser.add_argument( |
| 72 | + '--data_set', |
| 73 | + type=str, |
| 74 | + default='flowers', |
| 75 | + choices=['cifar10', 'flowers'], |
| 76 | + help='Optional dataset for benchmark.') |
| 77 | + parser.add_argument( |
| 78 | + '--infer_only', action='store_true', help='If set, run forward only.') |
| 79 | + parser.add_argument( |
| 80 | + '--use_cprof', action='store_true', help='If set, use cProfile.') |
| 81 | + parser.add_argument( |
| 82 | + '--use_nvprof', |
| 83 | + action='store_true', |
| 84 | + help='If set, use nvprof for CUDA.') |
| 85 | + parser.add_argument( |
| 86 | + '--no_test', |
| 87 | + action='store_true', |
| 88 | + help='If set, do not test the testset during training.') |
| 89 | + parser.add_argument( |
| 90 | + '--memory_optimize', |
| 91 | + action='store_true', |
| 92 | + help='If set, optimize runtime memory before start.') |
| 93 | + parser.add_argument( |
| 94 | + '--use_fake_data', |
| 95 | + action='store_true', |
| 96 | + help='If set ommit the actual read data operators.') |
| 97 | + parser.add_argument( |
| 98 | + '--profile', action='store_true', help='If set, profile a few steps.') |
| 99 | + parser.add_argument( |
| 100 | + '--update_method', |
| 101 | + type=str, |
| 102 | + default='local', |
| 103 | + choices=['local', 'pserver', 'nccl2'], |
| 104 | + help='Choose parameter update method, can be local, pserver, nccl2.') |
| 105 | + parser.add_argument( |
| 106 | + '--no_split_var', |
| 107 | + action='store_true', |
| 108 | + default=False, |
| 109 | + help='Whether split variables into blocks when update_method is pserver') |
| 110 | + parser.add_argument( |
| 111 | + '--async_mode', |
| 112 | + action='store_true', |
| 113 | + default=False, |
| 114 | + help='Whether start pserver in async mode to support ASGD') |
| 115 | + parser.add_argument( |
| 116 | + '--use_reader_op', |
| 117 | + action='store_true', |
| 118 | + help='Whether to use reader op, and must specify the data path if set this to true.' |
| 119 | + ) |
| 120 | + parser.add_argument( |
| 121 | + '--data_path', |
| 122 | + type=str, |
| 123 | + default="", |
| 124 | + help='Directory that contains all the training recordio files.') |
| 125 | + args = parser.parse_args() |
| 126 | + return args |
0 commit comments