This is a class tending for easy deployments of users' training and evaluation instead of writing their own scripts. Args: engine (:class:`Engine`): Engine responsible for the process function. schedule (:class:`BaseScheduler`, optional): Runtime schedule. Defaults to None.
| 96 | |
| 97 | |
| 98 | class Trainer: |
| 99 | """This is a class tending for easy deployments of users' training and evaluation instead of |
| 100 | writing their own scripts. |
| 101 | |
| 102 | Args: |
| 103 | engine (:class:`Engine`): Engine responsible for the process function. |
| 104 | schedule (:class:`BaseScheduler`, optional): Runtime schedule. Defaults to None. |
| 105 | """ |
| 106 | |
| 107 | def __init__( |
| 108 | self, |
| 109 | engine: Engine, |
| 110 | schedule: Optional[BaseScheduler] = None, |
| 111 | ): |
| 112 | """Initializes the Trainer class. |
| 113 | |
| 114 | Args: |
| 115 | engine (Engine): The engine responsible for the process function. |
| 116 | schedule (Optional[BaseScheduler], optional): The runtime schedule. Defaults to None. |
| 117 | """ |
| 118 | self._engine = engine |
| 119 | |
| 120 | # build schedule |
| 121 | if schedule is None: |
| 122 | self._schedule = NonPipelineScheduler() |
| 123 | else: |
| 124 | assert isinstance( |
| 125 | schedule, BaseScheduler |
| 126 | ), f"expected schedule to be of type BaseSchedule, but got {type(schedule)}" |
| 127 | self._schedule = schedule |
| 128 | |
| 129 | self._schedule.pre_processing(self._engine) |
| 130 | |
| 131 | @property |
| 132 | def engine(self): |
| 133 | return self._engine |
| 134 | |
| 135 | @property |
| 136 | def schedule(self): |
| 137 | return self._schedule |
| 138 | |
| 139 | @property |
| 140 | def uses_pipeline(self): |
| 141 | """Returns whether the pipeline parallel is used or not.""" |
| 142 | return isinstance(self._schedule, (PipelineScheduler, InterleavedPipelineScheduler)) |
| 143 | |
| 144 | def train(self): |
| 145 | self._engine.train() |
| 146 | |
| 147 | def eval(self): |
| 148 | self._engine.eval() |
| 149 | |
| 150 | def zero_grad(self): |
| 151 | self._engine.zero_grad() |
| 152 | |
| 153 | def step(self): |
| 154 | return self._engine.step() |
| 155 |
no outgoing calls
no test coverage detected