Improve mismatched storage error message. (#19068)
authorGregory Chanan <gchanan@fb.com>
Wed, 10 Apr 2019 18:46:35 +0000 (11:46 -0700)
committerFacebook Github Bot <facebook-github-bot@users.noreply.github.com>
Wed, 10 Apr 2019 18:51:33 +0000 (11:51 -0700)
Summary:
Previously the error message would look like:
```
Attempted to set the storage of a tensor on device cuda:0 to a storage on different device cuda. This is no longer allowed; the devices must match.
```

Now it looks like:
```
Attempted to set the storage of a tensor on device "cuda:0" to a storage on different device "cuda". This is no longer allowed; the devices must match.
```
Pull Request resolved: https://github.com/pytorch/pytorch/pull/19068

Reviewed By: dzhulgakov

Differential Revision: D14854257

Pulled By: gchanan

fbshipit-source-id: deb1ef73c2fcbf9338e7d67f2856282db2befac8

aten/src/TH/THTensor.cpp

index 2be5ce7..06b02d8 100644 (file)
@@ -168,8 +168,8 @@ void THTensor_stealAndSetStoragePtr(THTensor* tensor, THStorage* storage) {
   // see Note [We regret making Variable hold a Tensor]
   // Let's put an actual error message for this one.
   AT_CHECK(tensor->storage().device() == storage->device(),
-            "Attempted to set the storage of a tensor on device ", tensor->storage().device(),
-             " to a storage on different device ", storage->device(),
-            ".  This is no longer allowed; the devices must match.");
+            "Attempted to set the storage of a tensor on device \"", tensor->storage().device(),
+             "\" to a storage on different device \"", storage->device(),
+            "\".  This is no longer allowed; the devices must match.");
   tensor->set_storage(at::Storage(c10::intrusive_ptr<THStorage>::reclaim(storage)));
 }