MCPcopy Create free account
hub / github.com/OpenPPL/ppl.nn / SaveOutputsOneByOne

Function SaveOutputsOneByOne

tools/pplnn.py:531–550  ·  view source on GitHub ↗
(save_data_dir, runtime)

Source from the content-addressed store, hash-verified

529# ---------------------------------------------------------------------------- #
530
531def SaveOutputsOneByOne(save_data_dir, runtime):
532 for i in range(runtime.GetOutputCount()):
533 tensor = runtime.GetOutputTensor(i)
534 out_file_name = save_data_dir + "/pplnn_output-" + tensor.GetName() + ".dat"
535 shape = tensor.GetShape()
536 dims = shape.GetDims()
537 element_count = CalcElementCount(dims)
538 if element_count > 0:
539 dst_data_type = shape.GetDataType()
540 if dst_data_type == pplcommon.DATATYPE_FLOAT16: # convert fp16 to fp32 when saving to file
541 dst_data_type = pplcommon.DATATYPE_FLOAT32
542 tensor_data = tensor.ConvertToHost(dst_data_type)
543 if not tensor_data:
544 logging.error("copy data from tensor[" + tensor.GetName() + "] failed.")
545 sys.exit(-1)
546
547 out_data = np.array(tensor_data, copy=False)
548 out_data.tofile(out_file_name)
549 else:
550 open(out_file_name, 'a').close()
551
552# ---------------------------------------------------------------------------- #
553

Callers 1

pplnn.pyFile · 0.70

Calls 6

CalcElementCountFunction · 0.85
GetOutputTensorMethod · 0.80
GetOutputCountMethod · 0.45
GetNameMethod · 0.45
GetShapeMethod · 0.45
ConvertToHostMethod · 0.45

Tested by

no test coverage detected