mirror of
https://github.com/pytorch/pytorch.git
synced 2025-11-11 22:34:53 +08:00
Set requires grad in TensorMaker::make_tensor() (#148255)
Fixes #146419 Pull Request resolved: https://github.com/pytorch/pytorch/pull/148255 Approved by: https://github.com/soulitzer
This commit is contained in:
committed by
PyTorch MergeBot
parent
b8ef642f04
commit
f3c77b2458
@ -53,7 +53,9 @@ Tensor TensorMaker::make_tensor() {
|
||||
tensor_impl->set_storage_offset(*storage_offset_);
|
||||
}
|
||||
|
||||
return tensor;
|
||||
tensor_impl->set_requires_grad(opts_.requires_grad());
|
||||
|
||||
return tensor;
|
||||
}
|
||||
|
||||
std::size_t TensorMaker::computeStorageSize() const noexcept {
|
||||
|
||||
@ -76,6 +76,14 @@ TEST(TensorTest, ToTensorAndTensorAttributes) {
|
||||
REQUIRE_TENSOR_OPTIONS(at::kCPU, -1, at::kInt, at::kStrided);
|
||||
}
|
||||
|
||||
TEST(TensorTest, TensorAttributes) {
|
||||
std::vector<float> v = {1.0, 2.0, 3.0};
|
||||
auto options = c10::requires_grad(true);
|
||||
auto tensor = at::from_blob(v.data(), {3}, options);
|
||||
REQUIRE_TENSOR_OPTIONS(at::kCPU, -1, at::kFloat, at::kStrided);
|
||||
ASSERT_TRUE(tensor.requires_grad());
|
||||
}
|
||||
|
||||
// Not currently supported.
|
||||
// TEST(TensorTest, ToLayout) {
|
||||
// auto tensor = at::empty({3, 4});
|
||||
|
||||
Reference in New Issue
Block a user