From: Yinghai Lu Date: Wed, 9 Jan 2019 06:24:37 +0000 (-0800) Subject: Initialize tensor with fp32 in Caffe2Backend.prepare() (#15832) X-Git-Tag: accepted/tizen/6.5/unified/20211028.231830~1953 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=5fe26976559490a99cb60a0dd2e457c1fdda65ba;p=platform%2Fupstream%2Fpytorch.git Initialize tensor with fp32 in Caffe2Backend.prepare() (#15832) Summary: Fix https://github.com/pytorch/pytorch/issues/14104 Pull Request resolved: https://github.com/pytorch/pytorch/pull/15832 Reviewed By: bddppq Differential Revision: D13598332 Pulled By: yinghai fbshipit-source-id: 3302ac47928974f49353c5da8af440e5c1716c22 --- diff --git a/caffe2/python/onnx/backend.py b/caffe2/python/onnx/backend.py index d4cc70a..119750c 100644 --- a/caffe2/python/onnx/backend.py +++ b/caffe2/python/onnx/backend.py @@ -644,7 +644,10 @@ class Caffe2Backend(Backend): if value_info.name in initialized: continue shape = list(d.dim_value for d in value_info.type.tensor_type.shape.dim) - ws.FeedBlob(value_info.name, np.ones(shape), device_option) + ws.FeedBlob( + value_info.name, + np.ones(shape, dtype=onnx.mapping.TENSOR_TYPE_TO_NP_TYPE[value_info.type.tensor_type.elem_type]), + device_option) @staticmethod def optimize_onnx(input, init=False, predict=False):