ps_dnn_trainer.py 21.4 KB
Newer Older
Z
ziyoujiyi 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14
# Copyright (c) 2022 PaddlePaddle Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

15 16 17 18 19 20 21 22 23 24 25 26
import argparse
import ast
import copy
import os
import struct
import sys

import numpy as np
import yaml

import paddle
import paddle.distributed.fleet as fleet
Z
ziyoujiyi 已提交
27
import paddle.distributed.fleet.base.role_maker as role_maker
28 29 30 31 32 33
from paddle.distributed.ps.utils.ps_program_builder import (
    debug_program,
    logger,
    new_pass,
    ps_log_root_dir,
)
34

Z
ziyoujiyi 已提交
35 36 37 38 39 40 41 42 43
sys.path.append("..")
from ps_dnn_model import StaticModel

__dir__ = os.path.dirname(os.path.abspath(__file__))
sys.path.append(os.path.abspath(os.path.join(__dir__, '..')))


def is_distributed_env():
    node_role = os.getenv("TRAINING_ROLE")
44
    print("-- Role: {} --".format(node_role))
Z
ziyoujiyi 已提交
45 46 47 48 49 50
    if node_role is None:
        return False
    else:
        return True


51
class YamlHelper:
Z
ziyoujiyi 已提交
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
    def load_yaml(self, yaml_file, other_part=None):
        part_list = ["runner", "hyper_parameters"]
        if other_part:
            part_list += other_part
        running_config = self.get_all_inters_from_yaml(yaml_file, part_list)
        running_config = self.workspace_adapter(running_config)
        return running_config

    def print_yaml(self, config):
        print(self.pretty_print_envs(config))

    def parse_yaml(self, config):
        vs = [int(i) for i in yaml.__version__.split(".")]
        if vs[0] < 5:
            use_full_loader = False
        elif vs[0] > 5:
            use_full_loader = True
        else:
            if vs[1] >= 1:
                use_full_loader = True
            else:
                use_full_loader = False

        if os.path.isfile(config):
76 77 78 79 80 81
            with open(config, 'r', encoding="utf-8") as rb:
                if use_full_loader:
                    _config = yaml.load(rb.read(), Loader=yaml.FullLoader)
                else:
                    _config = yaml.load(rb.read())
                return _config
Z
ziyoujiyi 已提交
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121
        else:
            raise ValueError("config {} can not be supported".format(config))

    def get_all_inters_from_yaml(self, file, filters):
        _envs = self.parse_yaml(file)
        all_flattens = {}

        def fatten_env_namespace(namespace_nests, local_envs):
            for k, v in local_envs.items():
                if isinstance(v, dict):
                    nests = copy.deepcopy(namespace_nests)
                    nests.append(k)
                    fatten_env_namespace(nests, v)
                else:
                    global_k = ".".join(namespace_nests + [k])
                    all_flattens[global_k] = v

        fatten_env_namespace([], _envs)
        ret = {}
        for k, v in all_flattens.items():
            for f in filters:
                if k.startswith(f):
                    ret[k] = v
        return ret

    def workspace_adapter(self, config):
        workspace = config.get("workspace")
        for k, v in config.items():
            if isinstance(v, str) and "{workspace}" in v:
                config[k] = v.replace("{workspace}", workspace)
        return config

    def pretty_print_envs(self, envs, header=None):
        spacing = 2
        max_k = 40
        max_v = 45

        for k, v in envs.items():
            max_k = max(max_k, len(k))

122
        h_format = "    " + "|{{:>{}s}}{}{{:^{}s}}|\n".format(
123 124
            max_k, " " * spacing, max_v
        )
Z
ziyoujiyi 已提交
125 126 127 128 129 130 131 132 133 134 135 136
        l_format = "    " + "|{{:>{}s}}{{}}{{:^{}s}}|\n".format(max_k, max_v)
        length = max_k + max_v + spacing

        border = "    +" + "".join(["="] * length) + "+"
        line = "    +" + "".join(["-"] * length) + "+"

        draws = ""
        draws += border + "\n"

        if header:
            draws += h_format.format(header[0], header[1])
        else:
Z
ziyoujiyi 已提交
137
            draws += h_format.format("Ps Benchmark Envs", "Value")
Z
ziyoujiyi 已提交
138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159

        draws += line + "\n"

        for k, v in sorted(envs.items()):
            if isinstance(v, str) and len(v) >= max_v:
                str_v = "... " + v[-41:]
            else:
                str_v = v

            draws += l_format.format(k, " " * spacing, str(str_v))

        draws += border

        _str = "\n{}\n".format(draws)
        return _str


def get_user_defined_strategy(config):
    if not is_distributed_env():
        logger.warn(
            "Not Find Distributed env, Change To local train mode. If you want train with fleet, please use [fleetrun] command."
        )
160
        # return None
Z
ziyoujiyi 已提交
161 162 163 164 165 166 167 168
    sync_mode = config.get("runner.sync_mode")
    assert sync_mode in ["async", "sync", "geo", "heter", "gpubox"]
    if sync_mode == "sync":
        strategy = paddle.distributed.fleet.DistributedStrategy()
        strategy.a_sync = False
    elif sync_mode == "async":
        strategy = paddle.distributed.fleet.DistributedStrategy()
        strategy.a_sync = True
169 170 171
        strategy.is_fl_ps_mode = (
            True if config.get("runner.is_fl_ps_mode") == 1 else False
        )
172
        if strategy.is_fl_ps_mode:
173 174 175 176
            strategy.pipeline = False
            micro_num = 1
            strategy.pipeline_configs = {
                "accumulate_steps": micro_num
177
            }  # num_microbatches
Z
ziyoujiyi 已提交
178 179 180 181 182 183 184 185
    elif sync_mode == "geo":
        strategy = paddle.distributed.fleet.DistributedStrategy()
        strategy.a_sync = True
        strategy.a_sync_configs = {"k_steps": config.get("runner.geo_step")}
    elif sync_mode == "heter":
        strategy = paddle.distributed.fleet.DistributedStrategy()
        strategy.a_sync = True
        strategy.a_sync_configs = {"heter_worker_device_guard": "gpu"}
186 187 188 189
        strategy.pipeline = True
        strategy.pipeline_configs = {
            "accumulate_steps": config.get('runner.micro_num')
        }
Z
ziyoujiyi 已提交
190 191 192 193 194 195 196 197 198 199
    elif sync_mode == "gpubox":
        print("sync_mode = {}".format(sync_mode))
        strategy = paddle.distributed.fleet.DistributedStrategy()
        strategy.a_sync = True
        strategy.a_sync_configs = {"use_ps_gpu": 1}

    strategy.trainer_desc_configs = {
        "dump_fields_path": config.get("runner.dump_fields_path", ""),
        "dump_fields": config.get("runner.dump_fields", []),
        "dump_param": config.get("runner.dump_param", []),
200 201
        "stat_var_names": config.get("stat_var_names", []),
        "local_sparse": config.get("runner.local_sparse", []),
202
        "remote_sparse": config.get("runner.remote_sparse", []),
Z
ziyoujiyi 已提交
203 204 205 206 207 208 209 210
    }
    print("strategy:", strategy.trainer_desc_configs)

    if config.get("runner.fs_client.uri") is not None:
        strategy.fs_client_param = {
            "uri": config.get("runner.fs_client.uri", ""),
            "user": config.get("runner.fs_client.user", ""),
            "passwd": config.get("runner.fs_client.passwd", ""),
211
            "hadoop_bin": config.get("runner.fs_client.hadoop_bin", "hadoop"),
Z
ziyoujiyi 已提交
212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227
        }
    print("strategy:", strategy.fs_client_param)

    strategy.adam_d2sum = config.get("hyper_parameters.adam_d2sum", True)
    table_config = {}
    for x in config:
        if x.startswith("table_parameters"):
            table_name = x.split('.')[1]
            if table_name not in table_config:
                table_config[table_name] = {}
            table_config[table_name][x] = config[x]
    print("table_config:", table_config)
    strategy.sparse_table_configs = table_config
    print("strategy table config:", strategy.sparse_table_configs)
    a_sync_configs = strategy.a_sync_configs
    a_sync_configs["launch_barrier"] = False
228
    # a_sync_configs["launch_barrier"] = True
Z
ziyoujiyi 已提交
229 230 231 232 233 234
    strategy.a_sync_configs = a_sync_configs
    print("launch_barrier: ", strategy.a_sync_configs["launch_barrier"])

    return strategy


235
def get_distributed_strategy(user_defined_strategy):  # pslib
W
wangzhen38 已提交
236
    from paddle.incubate.fleet.parameter_server.distribute_transpiler.distributed_strategy import (
237 238
        StrategyFactory,
    )
Z
ziyoujiyi 已提交
239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266

    k_steps = user_defined_strategy.a_sync_configs["k_steps"]
    strategy = None

    if not user_defined_strategy.a_sync and k_steps == 0:
        strategy = StrategyFactory.create_sync_strategy()

    if user_defined_strategy.a_sync and k_steps == 0:
        strategy = StrategyFactory.create_async_strategy()

    if user_defined_strategy.a_sync and k_steps > 0:
        strategy = StrategyFactory.create_geo_strategy(k_steps)

    if not strategy:
        raise ValueError("k_steps must be invalid value, please check")

    return strategy


def get_model(config):
    abs_dir = config['config_abs_dir']
    sys.path.append(abs_dir)
    static_model = StaticModel(config)
    return static_model


def parse_args():
    parser = argparse.ArgumentParser("PsTest train script")
267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298
    parser.add_argument(
        '-m', '--config_yaml', type=str, required=True, help='config file path'
    )
    parser.add_argument(
        '-bf16',
        '--pure_bf16',
        type=ast.literal_eval,
        default=False,
        help="whether use bf16",
    )

    parser.add_argument(
        '--run_minimize', type=int, default=0, help="test single pass"
    )
    parser.add_argument(
        '--run_single_pass', type=int, default=0, help="test single pass"
    )
    parser.add_argument(
        '--run_the_one_ps', type=int, default=0, help="test the_one_ps"
    )
    parser.add_argument(
        '--debug_new_minimize', type=int, default=0, help="test single pass"
    )
    parser.add_argument(
        '--debug_new_pass', type=int, default=0, help="test single pass"
    )
    parser.add_argument(
        '--applied_pass_name', type=str, default="", help="test single pass"
    )
    parser.add_argument(
        '--debug_the_one_ps', type=int, default=0, help="test the_one_ps"
    )
Z
ziyoujiyi 已提交
299 300 301 302 303 304 305 306 307 308

    args = parser.parse_args()
    args.abs_dir = os.path.dirname(os.path.abspath(args.config_yaml))
    yaml_helper = YamlHelper()
    config = yaml_helper.load_yaml(args.config_yaml)
    config["yaml_path"] = args.config_yaml
    config["config_abs_dir"] = args.abs_dir
    config["pure_bf16"] = args.pure_bf16
    config['run_minimize'] = args.run_minimize
    config['run_single_pass'] = args.run_single_pass
Z
ziyoujiyi 已提交
309
    config['run_the_one_ps'] = args.run_the_one_ps
Z
ziyoujiyi 已提交
310 311 312
    config['debug_new_minimize'] = args.debug_new_minimize
    config['debug_new_pass'] = args.debug_new_pass
    config['applied_pass_name'] = args.applied_pass_name
Z
ziyoujiyi 已提交
313
    config['debug_the_one_ps'] = args.debug_the_one_ps
Z
ziyoujiyi 已提交
314 315 316 317 318 319 320 321
    yaml_helper.print_yaml(config)
    return config


def bf16_to_fp32(val):
    return np.float32(struct.unpack('<f', struct.pack('<I', val << 16))[0])


322
class DnnTrainer:
Z
ziyoujiyi 已提交
323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342
    def __init__(self, config):
        self.metrics = {}
        self.config = config
        self.input_data = None
        self.reader = None
        self.exe = None
        self.train_result_dict = {}
        self.train_result_dict["speed"] = []
        self.model = None
        self.pure_bf16 = self.config['pure_bf16']
        self.role_maker = role_maker.PaddleCloudRoleMaker()

    def init_fleet_with_gloo(self, use_gloo=False):
        if use_gloo:
            os.environ["PADDLE_WITH_GLOO"] = "1"
            fleet.init(self.role_maker)
        else:
            fleet.init()

        if fleet.is_server():
343
            print("server: {} started".format(fleet.server_index()))
Z
ziyoujiyi 已提交
344
        else:
345
            print("worker: {} started".format(fleet.worker_index()))
Z
ziyoujiyi 已提交
346 347 348 349

    def run_minimize(self):
        self.init_fleet_with_gloo()
        self.model = get_model(self.config)
350
        print("cpu_num: {}".format(os.getenv("CPU_NUM")))
Z
ziyoujiyi 已提交
351 352 353 354 355
        self.input_data = self.model.create_feeds()
        self.metrics = self.model.net(self.input_data)
        loss = self.model._cost
        user_defined_strategy = get_user_defined_strategy(self.config)
        learning_rate = self.config.get(
356 357
            "hyper_parameters.optimizer.learning_rate"
        )
Z
ziyoujiyi 已提交
358
        sync_mode = self.config.get("runner.sync_mode")
Z
ziyoujiyi 已提交
359 360
        inner_optimizer = paddle.optimizer.Adam(learning_rate, lazy_mode=True)

361
        self.role_maker._generate_role()  # 必要
Z
ziyoujiyi 已提交
362
        if self.config['debug_new_minimize'] == 1:
363
            print("entering run_minimize -- new")
364 365 366 367
            from paddle.distributed.fleet.meta_optimizers.ps_optimizer import (
                ParameterServerOptimizer,
            )

Z
ziyoujiyi 已提交
368
            ps_optimizer = ParameterServerOptimizer(inner_optimizer)
369 370 371
            ps_optimizer._set_basic_info(
                loss, self.role_maker, inner_optimizer, user_defined_strategy
            )
Z
ziyoujiyi 已提交
372 373
            ps_optimizer.minimize_impl(loss)
        else:
374
            print("entering run_minimize -- old")
Z
ziyoujiyi 已提交
375
            fleet_obj = fleet.distributed_optimizer(
376
                inner_optimizer, user_defined_strategy
377
            )  # Fleet object
Z
ziyoujiyi 已提交
378 379 380
            fleet_obj.minimize(loss)

        if fleet.is_server():
381 382 383 384 385 386 387 388
            _main_file = (
                ps_log_root_dir
                + sync_mode
                + '_run_minimize'
                + '_debug:_'
                + str(self.config['debug_new_minimize'])
                + '_server_main.prototxt'
            )
389
            debug_program(_main_file, loss.block.program)
Z
ziyoujiyi 已提交
390
        elif fleet.is_worker():
391 392 393 394 395 396 397 398
            _main_file = (
                ps_log_root_dir
                + sync_mode
                + '_run_minimize'
                + '_debug:_'
                + str(self.config['debug_new_minimize'])
                + '_worker_main.prototxt'
            )
399 400
            debug_program(_main_file, loss.block.program)
        elif self.role_maker._is_heter_worker():
401 402 403 404 405 406 407 408
            _main_file = (
                ps_log_root_dir
                + sync_mode
                + '_run_minimize'
                + '_debug:_'
                + str(self.config['debug_new_minimize'])
                + '_heter_worker_main.prototxt'
            )
409
            debug_program(_main_file, loss.block.program)
Z
ziyoujiyi 已提交
410 411 412 413 414 415 416 417 418

    def run_single_pass(self):
        self.init_fleet_with_gloo()
        self.model = get_model(config)
        input_data = self.model.create_feeds()
        metrics = self.model.net(input_data)
        loss = self.model._cost
        user_defined_strategy = get_user_defined_strategy(config)
        learning_rate = config.get("hyper_parameters.optimizer.learning_rate")
Z
ziyoujiyi 已提交
419
        sync_mode = self.config.get("runner.sync_mode")
Z
ziyoujiyi 已提交
420 421 422 423
        inner_optimizer = paddle.optimizer.Adam(learning_rate, lazy_mode=True)
        startup_program = paddle.static.default_startup_program()
        inner_optimizer.minimize(loss, startup_program)
        if self.config['debug_new_pass'] == 1:
424 425 426 427 428 429 430
            print(
                "entering run {} - new".format(str(config["applied_pass_name"]))
            )
            from paddle.distributed.fleet.meta_optimizers.ps_optimizer import (
                ParameterServerOptimizer,
            )

Z
ziyoujiyi 已提交
431
            ps_optimizer = ParameterServerOptimizer(inner_optimizer)
432 433 434
            ps_optimizer._set_basic_info(
                loss, self.role_maker, inner_optimizer, user_defined_strategy
            )
435
            ps_optimizer._set_origin_programs([loss])
Z
ziyoujiyi 已提交
436
            ps_optimizer._init_ps_pass_context(loss, startup_program)
Z
ziyoujiyi 已提交
437
            _main = ps_optimizer.pass_ctx._attrs['cloned_main']
Z
ziyoujiyi 已提交
438

439 440 441
            append_send_ops_pass = new_pass(
                config["applied_pass_name"], ps_optimizer.pass_ctx._attrs
            )
Z
ziyoujiyi 已提交
442 443
            append_send_ops_pass.apply([_main], [None], ps_optimizer.pass_ctx)
        else:
444 445 446 447 448 449 450
            print(
                "entering run {} - old".format(str(config["applied_pass_name"]))
            )
            from paddle.fluid.incubate.fleet.parameter_server.ir import (
                public as public,
            )

Z
ziyoujiyi 已提交
451 452
            dist_strategy = get_distributed_strategy(user_defined_strategy)
            compiled_config = public.CompileTimeStrategy(
453 454 455 456 457
                loss.block.program,
                startup_program,
                dist_strategy,
                self.role_maker,
            )
Z
ziyoujiyi 已提交
458 459 460

            _main = compiled_config.origin_main_program.clone()
            _startup = compiled_config.origin_startup_program.clone()
461 462 463 464
            from paddle.fluid.incubate.fleet.parameter_server.ir import (
                trainer_pass as worker,
            )

Z
ziyoujiyi 已提交
465 466 467
            _main = worker.append_send_ops_pass(_main, compiled_config)

        if fleet.is_server():
468 469 470 471 472 473 474 475 476
            _main_file = (
                ps_log_root_dir
                + sync_mode
                + "_"
                + str(config["applied_pass_name"])
                + '_debug:_'
                + str(self.config['debug_new_pass'])
                + '_server_main.prototxt'
            )
477
            debug_program(_main_file, _main)
Z
ziyoujiyi 已提交
478
        elif fleet.is_worker():
479 480 481 482 483 484 485 486 487
            _main_file = (
                ps_log_root_dir
                + sync_mode
                + "_"
                + str(config["applied_pass_name"])
                + '_debug:_'
                + str(self.config['debug_new_pass'])
                + '_worker_main.prototxt'
            )
488
            debug_program(_main_file, _main)
Z
ziyoujiyi 已提交
489

Z
ziyoujiyi 已提交
490 491 492 493 494 495 496 497
    def run_the_one_ps(self):
        self.init_fleet_with_gloo()
        self.model = get_model(self.config)
        self.input_data = self.model.create_feeds()
        self.metrics = self.model.net(self.input_data)
        loss = self.model._cost
        user_defined_strategy = get_user_defined_strategy(self.config)
        learning_rate = self.config.get(
498 499
            "hyper_parameters.optimizer.learning_rate"
        )
Z
ziyoujiyi 已提交
500 501 502 503 504
        sync_mode = self.config.get("runner.sync_mode")
        inner_optimizer = paddle.optimizer.Adam(learning_rate, lazy_mode=True)

        self.role_maker._generate_role()  # 必要
        if self.config['debug_the_one_ps'] == 1:
505
            print("entering run_the_one_ps -- new")
Z
ziyoujiyi 已提交
506

507 508 509 510
            from paddle.distributed.fleet.meta_optimizers.ps_optimizer import (
                ParameterServerOptimizer,
            )

Z
ziyoujiyi 已提交
511
            ps_optimizer = ParameterServerOptimizer(inner_optimizer)
512 513 514
            ps_optimizer._set_basic_info(
                loss, self.role_maker, inner_optimizer, user_defined_strategy
            )
Z
ziyoujiyi 已提交
515 516 517
            ps_optimizer.minimize_impl(loss)

            from paddle.distributed.ps.the_one_ps import TheOnePSRuntime
518

Z
ziyoujiyi 已提交
519 520 521
            _runtime_handle = TheOnePSRuntime()  # ps 目录下重构版的 TheOnePSRuntime
            _runtime_handle._set_basic_info(ps_optimizer.pass_ctx._attrs)
            if fleet.is_worker():
522 523
                worker_desc = (
                    _runtime_handle.ps_desc_builder.build_worker_desc()
Z
ziyoujiyi 已提交
524
                )
525
                with open(
526 527 528
                    ps_log_root_dir + sync_mode + '_' + 'new_worker_ps_desc',
                    'w',
                ) as f:
Z
ziyoujiyi 已提交
529 530
                    f.write(worker_desc)
            if fleet.is_server():
531 532
                server_desc = (
                    _runtime_handle.ps_desc_builder.build_server_desc()
Z
ziyoujiyi 已提交
533
                )
534
                with open(
535 536 537
                    ps_log_root_dir + sync_mode + '_' + 'new_server_ps_desc',
                    'w',
                ) as f:
Z
ziyoujiyi 已提交
538 539 540 541
                    f.write(server_desc)

        else:
            pass
542
        '''
543
            print("entering run_the_one_ps -- old")
Z
ziyoujiyi 已提交
544
            fleet_obj = fleet.distributed_optimizer(
545 546
                inner_optimizer, user_defined_strategy)
            fleet_obj.minimize(loss)
Z
ziyoujiyi 已提交
547 548 549 550 551 552 553 554 555 556 557
            if fleet.is_worker():
                worker_desc = fleet_obj._runtime_handle._get_fleet_proto(is_server=False, is_sync=False)
                server_desc = fleet_obj._runtime_handle._get_fleet_proto(is_server=True, is_sync=False)
                with open(ps_log_root_dir + sync_mode + '_' + 'worker_ps_desc', 'w') as f:
                    f.write(str(worker_desc) + str(server_desc))
            if fleet.is_server():
                server_desc = fleet_obj._runtime_handle._get_fleet_proto(is_server=True, is_sync=False)
                with open(ps_log_root_dir + sync_mode + '_' + 'server_ps_desc', 'w') as f:
                    f.write(str(server_desc) + str(fleet_obj._runtime_handle._get_fs_client_desc().to_string()))
        '''
        if fleet.is_server():
558 559 560 561 562 563 564 565
            _main_file = (
                ps_log_root_dir
                + sync_mode
                + '_run_the_one_ps'
                + '_debug:_'
                + str(self.config['debug_the_one_ps'])
                + '_server_main.prototxt'
            )
Z
ziyoujiyi 已提交
566 567
            debug_program(_main_file, loss.block.program)
        elif fleet.is_worker():
568 569 570 571 572 573 574 575
            _main_file = (
                ps_log_root_dir
                + sync_mode
                + '_run_the_one_ps'
                + '_debug:_'
                + str(self.config['debug_the_one_ps'])
                + '_worker_main.prototxt'
            )
Z
ziyoujiyi 已提交
576 577
            debug_program(_main_file, loss.block.program)
        elif self.role_maker._is_heter_worker():
578 579 580 581 582 583 584 585
            _main_file = (
                ps_log_root_dir
                + sync_mode
                + '_run_the_one_ps'
                + '_debug:_'
                + str(self.config['debug_the_one_ps'])
                + '_heter_worker_main.prototxt'
            )
Z
ziyoujiyi 已提交
586 587
            debug_program(_main_file, loss.block.program)

Z
ziyoujiyi 已提交
588 589 590 591

if __name__ == "__main__":
    paddle.enable_static()
    config = parse_args()
592
    print(">>>>>>>>>> python process started")
Z
ziyoujiyi 已提交
593 594 595 596 597 598
    os.environ["CPU_NUM"] = str(config.get("runner.thread_num"))
    benchmark_main = DnnTrainer(config)
    if config['run_single_pass'] == 1:
        benchmark_main.run_single_pass()
    elif config['run_minimize'] == 1:
        benchmark_main.run_minimize()
Z
ziyoujiyi 已提交
599 600
    elif config['run_the_one_ps'] == 1:
        benchmark_main.run_the_one_ps()