# Why model.to(device) wouldn't put tensors on a custom layer to the same device?

**URL:** <https://discuss.pytorch.org/t/why-model-to-device-wouldnt-put-tensors-on-a-custom-layer-to-the-same-device/17964>\
**Category:** Uncategorized\
**Created:** [May 12, 2018, 3:02am UTC](https://discuss.pytorch.org/t/why-model-to-device-wouldnt-put-tensors-on-a-custom-layer-to-the-same-device/17964 "2018-05-12T03:02:57Z")\
**Posts on this page:** 1\
**Showing post:** 4

<div class="post-metadata">

**Author:** ![yxchng](https://discuss.pytorch.org/letter_avatar_proxy/v4/letter/y/7bcc69/32.png) [@yxchng](https://discuss.pytorch.org/u/yxchng)\
**Post date:** [May 13, 2018, 5:33am UTC](https://discuss.pytorch.org/t/why-model-to-device-wouldnt-put-tensors-on-a-custom-layer-to-the-same-device/17964/4 "2018-05-13T05:33:18Z")

</div>

Ok this is not a good example because I could just move it to the same tensor as x.

But the problem I face is because I have to define the weights myself

`self.w = Parameter(torch.zeros(out_features, in_features))`

in \_\_init\_\_ function.

At that point, I still do not know the input device. Therefore my self.w is on the cpu but my input is on the gpu.

---

_[View the full topic](https://discuss.pytorch.org/t/why-model-to-device-wouldnt-put-tensors-on-a-custom-layer-to-the-same-device/17964)._
