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

Method _run

python/paddle/hapi/model.py:508–583  ·  view source on GitHub ↗
(self, inputs, labels=None)

Source from the content-addressed store, hash-verified

506 self._set_var(var.name, converted_state[var.name])
507
508 def _run(self, inputs, labels=None):
509 compiled_prog = self._compiled_progs.get(self.mode, None)
510 assert compiled_prog, (
511 "Model is not ready, please call `model.prepare()` first"
512 )
513
514 inputs = to_list(inputs)
515 if labels is not None:
516 labels = to_list(labels)
517 assert len(inputs) == len(self._input_vars[self.mode]), (
518 "number of inputs"
519 + " does not match number of arguments of `forward` method"
520 )
521
522 feed = {}
523 input_names = [v.name for v in self._input_vars[self.mode]]
524 input_dtypes = [v.dtype for v in self._input_vars[self.mode]]
525
526 for idx, n in enumerate(input_names):
527 # train and test may take different arguments
528 if inputs[idx] is not None:
529 feed[n] = inputs[idx]
530 if self._amp_level == 'O2' and input_dtypes[idx] == paddle.float16:
531 if isinstance(feed[n], core.DenseTensor):
532 feed[n] = feed[n]._as_type(paddle.pir.core.DataType.FLOAT16)
533 elif isinstance(feed[n], np.ndarray):
534 feed[n] = feed[n].astype('float16')
535
536 if labels is not None:
537 for idx, v in enumerate(self._label_vars[self.mode]):
538 feed[v.name] = labels[idx]
539
540 endpoints = self._endpoints[self.mode]
541 if self.mode == 'test':
542 fetch_list = endpoints['output']
543 else:
544 metric_list, metric_splits = flatten_list(endpoints['metric'])
545 fetch_list = endpoints['loss'] + metric_list
546 num_loss = len(endpoints['loss'])
547
548 # if fetch Variable is same as input Variable, do not fetch
549 # from program, get it from input directly
550 pruned_fetch_list = []
551 pruned_fetch_idx_name_map = [""] * len(fetch_list)
552 for i, fetch_var in enumerate(fetch_list):
553 if fetch_var in feed.keys():
554 pruned_fetch_idx_name_map[i] = fetch_var
555 else:
556 pruned_fetch_list.append(fetch_var)
557
558 rets = self._executor.run(
559 compiled_prog,
560 feed=feed,
561 fetch_list=pruned_fetch_list,
562 return_numpy=False,
563 )
564
565 # restore pruned fetch_list Variable from feeds

Callers 3

train_batchMethod · 0.95
eval_batchMethod · 0.95
predict_batchMethod · 0.95

Calls 10

flatten_listFunction · 0.85
restore_flatten_listFunction · 0.85
astypeMethod · 0.80
to_listFunction · 0.70
getMethod · 0.45
keysMethod · 0.45
appendMethod · 0.45
runMethod · 0.45
insertMethod · 0.45
updateMethod · 0.45

Tested by

no test coverage detected