MCPcopy Create free account
hub / github.com/PaddlePaddle/Paddle / _prepare_trainer

Method _prepare_trainer

python/paddle/base/executor.py:2415–2476  ·  view source on GitHub ↗
(
        self,
        program=None,
        dataset=None,
        scope=None,
        thread=0,
        debug=False,
        fetch_list=None,
        fetch_info=None,
        print_period=100,
    )

Source from the content-addressed store, hash-verified

2413 ]
2414
2415 def _prepare_trainer(
2416 self,
2417 program=None,
2418 dataset=None,
2419 scope=None,
2420 thread=0,
2421 debug=False,
2422 fetch_list=None,
2423 fetch_info=None,
2424 print_period=100,
2425 ):
2426 if scope is None:
2427 scope = global_scope()
2428 if fetch_list is None:
2429 fetch_list = []
2430 if fetch_info is None:
2431 fetch_info = []
2432 assert len(fetch_list) == len(fetch_info)
2433 compiled = isinstance(program, compiler.CompiledProgram)
2434 if not compiled:
2435 # TODO: Need a better way to distinguish and specify different execution mode
2436 if program._pipeline_opt:
2437 trainer = TrainerFactory()._create_trainer(
2438 program._pipeline_opt
2439 )
2440 elif program._heter_pipeline_opt:
2441 trainer = TrainerFactory()._create_trainer(
2442 program._heter_pipeline_opt
2443 )
2444 else:
2445 trainer = TrainerFactory()._create_trainer(program._fleet_opt)
2446 trainer._set_thread_barrier(program._is_distributed)
2447 trainer._set_program(program)
2448 else:
2449 if program._pipeline_opt:
2450 trainer = TrainerFactory()._create_trainer(
2451 program.program._pipeline_opt
2452 )
2453 elif program._heter_pipeline_opt:
2454 trainer = TrainerFactory()._create_trainer(
2455 program.program._heter_pipeline_opt
2456 )
2457 else:
2458 trainer = TrainerFactory()._create_trainer(
2459 program.program._fleet_opt
2460 )
2461 trainer._set_program(program.program)
2462
2463 if thread <= 0:
2464 if dataset.thread_num <= 0:
2465 raise RuntimeError(
2466 "You should set thread num first, either in Dataset"
2467 "or in Executor.train_from_dataset"
2468 )
2469 else:
2470 trainer._set_thread(dataset.thread_num)
2471 else:
2472 trainer._set_thread(thread)

Callers 3

_run_from_datasetMethod · 0.95
_prepare_pipeline_ctxMethod · 0.95
start_heter_trainerMethod · 0.95

Calls 9

global_scopeFunction · 0.85
RuntimeErrorClass · 0.85
_create_trainerMethod · 0.80
_set_thread_barrierMethod · 0.80
_set_debugMethod · 0.80
TrainerFactoryClass · 0.70
_set_programMethod · 0.45
_set_threadMethod · 0.45

Tested by

no test coverage detected