# Device check will be automatically generated for functions

**URL:** <https://dev-discuss.pytorch.org/t/device-check-will-be-automatically-generated-for-functions/211>\
**Category:** frontend API\
**Created:** [May 7, 2021, 6:09pm UTC](https://dev-discuss.pytorch.org/t/device-check-will-be-automatically-generated-for-functions/211 "2021-05-07T18:09:03Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![wenleix](https://yyz2.discourse-cdn.com/flex036/user_avatar/dev-discuss.pytorch.org/wenleix/32/159_2.png) [@wenleix](https://dev-discuss.pytorch.org/u/wenleix)\
**Post date:** [May 7, 2021, 6:09pm UTC](https://dev-discuss.pytorch.org/t/device-check-will-be-automatically-generated-for-functions/211/1 "2021-05-07T18:09:03Z")

</div>

With [#56872](https://github.com/pytorch/pytorch/pull/56872) landed, now functions registered in `native_functions.yaml` will have automatically generated check about whether tensor parameters are on the same devices by default.

If your function allows tensors on different devices (e.g. using `TensorIterator` ), you can set `device_check: NoCheck` explicitly in `native_functions.yaml` . See also [https://github.com/…/tree/master/aten/src/ATen/native…](https://github.com/pytorch/pytorch/tree/master/aten/src/ATen/native#device_check)

#### Background

Many functions check whether the tensor parameters are on the same device with a few different implementations, which cause code duplications and confusions:

- The Appendix section in [https://github.com/pytorch/pytorch/pull/55241](https://github.com/pytorch/pytorch/pull/55241) summarizes a few existing device check implementation in codebase (there are more in codebase! ![😛](https://canada1.discourse-cdn.com/flex036/uploads/pytorch1/original/1X/13a95352f93110b73ea49f49eac739273e455674.png) ).

- This is also raised by community in [Cleaner mechanism in the source-code to check if multiple tensors are on the same device · Issue #56632 · pytorch/pytorch · GitHub](https://github.com/pytorch/pytorch/issues/56632).

This is a first step towards unifying device check code.
