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

Method _run

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

Source from the content-addressed store, hash-verified

939 t.set(ndarray, place)
940
941 def _run(self, inputs, labels=None):
942 compiled_prog = self._compiled_progs.get(self.mode, None)
943 assert compiled_prog, (
944 "Model is not ready, please call `model.prepare()` first"
945 )
946
947 inputs = to_list(inputs)
948 if labels is not None:
949 labels = to_list(labels)
950 assert len(inputs) == len(self._input_vars[self.mode]), (
951 "number of inputs"
952 + " does not match number of arguments of `forward` method"
953 )
954
955 feed = {}
956 input_names = [v.name for v in self._input_vars[self.mode]]
957 input_dtypes = [v.dtype for v in self._input_vars[self.mode]]
958
959 for idx, n in enumerate(input_names):
960 # train and test may take different arguments
961 if inputs[idx] is not None:
962 feed[n] = inputs[idx]
963 if self._amp_level == 'O2' and input_dtypes[idx] == paddle.float16:
964 if isinstance(feed[n], core.DenseTensor):
965 feed[n] = feed[n]._as_type(core.VarDesc.VarType.FP16)
966 elif isinstance(feed[n], np.array):
967 feed[n] = feed[n].astype('float16')
968
969 if labels is not None:
970 for idx, v in enumerate(self._label_vars[self.mode]):
971 feed[v.name] = labels[idx]
972
973 endpoints = self._endpoints[self.mode]
974 if self.mode == 'test':
975 fetch_list = endpoints['output']
976 else:
977 metric_list, metric_splits = flatten_list(endpoints['metric'])
978 fetch_list = endpoints['loss'] + metric_list
979 num_loss = len(endpoints['loss'])
980
981 # if fetch Variable is same as input Variable, do not fetch
982 # from program, get it from input directly
983 pruned_fetch_list = []
984 pruned_fetch_idx_name_map = [""] * len(fetch_list)
985 for i, fetch_var in enumerate(fetch_list):
986 if fetch_var.name in feed.keys():
987 pruned_fetch_idx_name_map[i] = fetch_var.name
988 else:
989 pruned_fetch_list.append(fetch_var)
990
991 rets = self._executor.run(
992 compiled_prog,
993 feed=feed,
994 fetch_list=pruned_fetch_list,
995 return_numpy=False,
996 )
997
998 # 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