From edf77fe64ae2f9becfbc1848721b096a14bcd820 Mon Sep 17 00:00:00 2001 From: Dmytro Dzhulgakov Date: Thu, 18 Apr 2019 16:34:20 -0700 Subject: [PATCH] Fix cpp_custom_type_hack variable handling (#19400) Summary: My bad - it might be called in variable and non-variable context. So it's better to just inherit variable-ness from the caller. Pull Request resolved: https://github.com/pytorch/pytorch/pull/19400 Reviewed By: ezyang Differential Revision: D14994781 Pulled By: dzhulgakov fbshipit-source-id: cb9d055b44a2e1d7bbf2e937d558e6bc75037f5b --- aten/src/ATen/cpp_custom_type_hack.h | 6 ++---- aten/src/ATen/native/QuantizedLinear.cpp | 2 +- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/aten/src/ATen/cpp_custom_type_hack.h b/aten/src/ATen/cpp_custom_type_hack.h index 211f1a0..5277d01 100644 --- a/aten/src/ATen/cpp_custom_type_hack.h +++ b/aten/src/ATen/cpp_custom_type_hack.h @@ -25,7 +25,7 @@ T& cast(const Tensor& packed) { } template -Tensor create(std::unique_ptr ptr) { +Tensor create(std::unique_ptr ptr, TensorOptions options) { // We store this instance away in a Tensor and register a deleter function // so that we do not leak memory. On the other side, we pull out the storage's // data_ptr and get the right typed pointer. @@ -38,9 +38,7 @@ Tensor create(std::unique_ptr ptr) { // size doesn't really matter, but we can align it to the actual size // returning variables because one likely want to use this hack from python - auto retval = at::empty( - {sizeof(T)}, - at::device(kCPU).dtype(at::kByte).is_variable(true).requires_grad(false)); + auto retval = at::empty({sizeof(T)}, options.device(kCPU).dtype(at::kByte)); retval.storage().set_data_ptr(std::move(at_ptr)); return retval; } diff --git a/aten/src/ATen/native/QuantizedLinear.cpp b/aten/src/ATen/native/QuantizedLinear.cpp index 0ab3026..98bbefc 100644 --- a/aten/src/ATen/native/QuantizedLinear.cpp +++ b/aten/src/ATen/native/QuantizedLinear.cpp @@ -249,7 +249,7 @@ Tensor fbgemm_pack_quantized_matrix( /*ld=*/K, /*pmat=*/nullptr, // PackBMatrix manages ownership of pmat /*groups=*/1); - return cpp_custom_type_hack::create(std::move(ptr)); + return cpp_custom_type_hack::create(std::move(ptr), weight.options()); } #else // USE_FBGEMM -- 2.7.4