def _construct_job(self): def job(): batch = self._cfg.data() return self._model.validation_step(batch) job.__name__ = self._model.__class__.__name__ + "_Model_eval_job" deco = api_oneflow_function(type="predict", function_config=self._cfg.exe_cfg) return deco(job)
def _construct_numpy_job(self, batch: Tuple[np.ndarray, ...] = None): def job(*input_batch): return self._model.validation_step(batch=input_batch) _infer_job_signature(self._cfg.data, batch, 0, job) job.__name__ = self._model.__class__.__name__ + "_Model_eval_numpy_job" deco = api_oneflow_function(type="predict", function_config=self._cfg.exe_cfg) return deco(job)
def _construct_job(self, optimizer_idx: int = 0): def job(): batch = self._cfg.data(0, optimizer_idx) outputs = self._model.training_step(batch=batch, optimizer_idx=optimizer_idx) loss = None if isinstance(outputs, tuple) and len(outputs) > 0: loss = outputs[0] else: loss = outputs self._opts[optimizer_idx].minimize(loss) return outputs job.__name__ = (self._model.__class__.__name__ + "_Model_train_job_" + str(optimizer_idx)) deco = api_oneflow_function(type="train", function_config=self._cfg.exe_cfg) return deco(job)
def _construct_numpy_job(self, batch, optimizer_idx): def job(*input_batch): outputs = self._model.training_step(batch=input_batch, optimizer_idx=optimizer_idx) loss = None if isinstance(outputs, tuple) and len(outputs) > 0: loss = outputs[0] else: loss = outputs self._opts[optimizer_idx].minimize(loss) return outputs _infer_job_signature(self._cfg.data, batch, optimizer_idx, job) job.__name__ = (self._model.__class__.__name__ + "_Model_train_numpy_job_" + str(optimizer_idx)) deco = api_oneflow_function(type="train", function_config=self._cfg.exe_cfg) return deco(job)