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

Class TrainerFactory

python/paddle/base/trainer_factory.py:44–162  ·  view source on GitHub ↗

Create trainer and device worker. If opt_info is not None, it will get configs from opt_info, otherwise create MultiTrainer and Hogwild.

Source from the content-addressed store, hash-verified

42
43
44class TrainerFactory:
45 """
46 Create trainer and device worker.
47 If opt_info is not None, it will get configs from opt_info,
48 otherwise create MultiTrainer and Hogwild.
49 """
50
51 def __init__(self):
52 pass
53
54 def _create_trainer(self, opt_info=None):
55 trainer = None
56 device_worker = None
57 if not opt_info:
58 # default is MultiTrainer + Hogwild
59 trainer = MultiTrainer()
60 device_worker = Hogwild()
61 trainer._set_device_worker(device_worker)
62 else:
63 trainer_class = opt_info.get("trainer", "MultiTrainer")
64 device_worker_class = opt_info.get("device_worker", "Hogwild")
65 trainer = globals()[trainer_class]()
66 device_worker = globals()[device_worker_class]()
67
68 # for debug tools
69 if opt_info is not None:
70 if opt_info.get("trainers") is not None:
71 trainer._set_trainers(opt_info["trainers"])
72 if opt_info.get("trainer_id") is not None:
73 trainer._set_trainer_id(opt_info["trainer_id"])
74 if opt_info.get("dump_slot") is not None:
75 trainer._set_dump_slot(opt_info["dump_slot"])
76 if opt_info.get("mpi_rank") is not None:
77 trainer._set_mpi_rank(opt_info["mpi_rank"])
78 if opt_info.get("mpi_size") is not None:
79 trainer._set_mpi_size(opt_info["mpi_size"])
80 if (
81 opt_info.get("dump_fields") is not None
82 and len(opt_info.get("dump_fields")) != 0
83 ):
84 trainer._set_dump_fields(opt_info["dump_fields"])
85 if (
86 opt_info.get("dump_fields_path") is not None
87 and len(opt_info.get("dump_fields_path")) != 0
88 ):
89 trainer._set_dump_fields_path(opt_info["dump_fields_path"])
90 if opt_info.get("dump_fields_mode") is not None:
91 trainer._set_dump_fields_mode(opt_info["dump_fields_mode"])
92 if (
93 opt_info.get("user_define_dump_filename") is not None
94 and len(opt_info.get("user_define_dump_filename")) != 0
95 ):
96 trainer._set_user_define_dump_filename(
97 opt_info["user_define_dump_filename"]
98 )
99 if opt_info.get("dump_file_num") is not None:
100 trainer._set_dump_file_num(opt_info["dump_file_num"])
101 if opt_info.get("dump_converter") is not None:

Callers 1

_prepare_trainerMethod · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected