gpt4 book ai didi

c++ - 如何使用 ONNXRuntime C API 运行半浮点 ONNX 模型?

转载 作者:行者123 更新时间:2023-12-04 10:07:53 29 4
gpt4 key购买 nike

既然C语言没有半浮点实现,那么如何向ONNXRuntime C API发送数据呢?

最佳答案

可能有一个示例,您可以从此处链接:https://github.com/microsoft/onnxruntime/issues/1173#issuecomment-501088662

您可以使用 CreateTensorAsOrtValue 创建一个缓冲区以将输入数据写入到其中,并使用 GetTensorMutableData 访问 OrtValue 中的缓冲区。

ONNXRuntime 使用 Eigen 将浮点数转换为可以写入该缓冲区的 16 位值。

uint16_t floatToHalf(float f) {
return Eigen::half_impl::float_to_half_rtne(f).x;
}

或者,您可以编辑模型以添加从 float32 到 float16 的 Cast 节点,以便模型将 float32 作为输入。

关于c++ - 如何使用 ONNXRuntime C API 运行半浮点 ONNX 模型?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61478905/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com