From 5b6f6da18cae1965d3d1da889b7c4a88830e4bde Mon Sep 17 00:00:00 2001 From: Hao Lu Date: Tue, 28 Apr 2020 15:30:02 -0700 Subject: [PATCH] [caffe2] Copy tensor in single tensor input case in UnPackRecordsOp (#37454) Summary: Pull Request resolved: https://github.com/pytorch/pytorch/pull/37454 Fix a bug introduced in D21224497. In the case of having a single unpacked tensor as input, we still need to copy the underline memory because only inputs are guaranteed to be read-only. The output could be overwritten later during inference. If we share the tensor, we could potentially overwrite the input, which in principle should be read only. Test Plan: ``` buck test caffe2/caffe2/python/operator_test:dataset_ops_test ``` AdIndexer canary: https://our.intern.facebook.com/intern/ads/canary/426290361213982683 Reviewed By: yinghai Differential Revision: D21274309 fbshipit-source-id: 71931d4b1afbdc700ba070ea618d1679f1bbe5a7 --- caffe2/operators/dataset_ops.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/caffe2/operators/dataset_ops.cc b/caffe2/operators/dataset_ops.cc index 345a26873e7..ec2e93bc96e 100644 --- a/caffe2/operators/dataset_ops.cc +++ b/caffe2/operators/dataset_ops.cc @@ -399,7 +399,7 @@ class UnPackRecordsOp : public Operator { // input contains a single tensor CAFFE_ENFORCE_EQ(InputSize(), 1); CAFFE_ENFORCE_EQ(OutputSize(), 1); - *Output(0) = Input(0); + Output(0)->CopyFrom(Input(0)); return true; }