<p dir="auto"><code class="notranslate">x.numpy()</code></p>
<p dir="auto">clearly means I want to convert something to numpy, which is always on the CPU. It is redundant to have to say .cpu().numpy(). The conversion should be automatic rather than throwing an exception.</p>
<p dir="auto">In my specific case I have set default tensor type to CUDA because that is what I am using by default - and because it makes it really easy to switch everything to CPU in one line of code without cluttering up the rest of it with passing a device around. However when I call third party software they create a tensor without an explicit type; then try to numpy() it expecting it to be CPU based. I have suggested they add a .cpu() but would be better to fix in pytorch.</p>
<p dir="auto">Both following native tensor factory function entries generate same <code class="notranslate">descriptor</code> (<code class="notranslate">"bernoulli-5"</code>):</p>
<div class="highlight highlight-source-yaml notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="- func: bernoulli(IntList size, Tensor p, *, TensorOptions options={}) -&gt; Tensor
  variants: function

- func: bernoulli(IntList size, double p, *, TensorOptions options={}) -&gt; Tensor
  variants: function"><pre class="notranslate">- <span class="pl-ent">func</span>: <span class="pl-s">bernoulli(IntList size, Tensor p, *, TensorOptions options={}) -&gt; Tensor</span>
  <span class="pl-ent">variants</span>: <span class="pl-s">function</span>

- <span class="pl-ent">func</span>: <span class="pl-s">bernoulli(IntList size, double p, *, TensorOptions options={}) -&gt; Tensor</span>
  <span class="pl-ent">variants</span>: <span class="pl-s">function</span></pre></div>
<p dir="auto">The corresponding <code class="notranslate">decl</code>s are</p>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="{'abstract': False,
 'api_name': 'bernoulli',
 'args': ['size', 'p', 'options'],
 'arguments': [{'dynamic_type': 'IntList',
                'is_nullable': False,
                'name': 'size',
                'simple_type': 'IntList',
                'type': 'IntList'},
               {'dynamic_type': 'Tensor',
                'is_nullable': False,
                'name': 'p',
                'simple_type': 'Tensor',
                'type': 'const Tensor &amp;'},
               {'default': 'static_cast&lt;int64_t&gt;(at::kFloat)',
                'name': 'dtype',
                'simple_type': 'int64_t'},
               {'default': '{static_cast&lt;int64_t&gt;(at::Device::Type::CPU), -1}',
                'name': 'device',
                'simple_type': 'IntList'},
               {'default': 'static_cast&lt;int64_t&gt;(at::kStrided)',
                'name': 'layout',
                'simple_type': 'int64_t'}],
 'base_name': 'bernoulli',
 'deprecated': False,
 'device_guard': True,
 'formals': ['IntList size',
             'const Tensor &amp; p',
             'const TensorOptions &amp; options'],
 'has_tensor_options': True,
 'inplace': False,
 'method_of': ['Type', 'namespace'],
 'method_prefix_derived': '',
 'mode': 'native',
 'name': 'bernoulli',
 'return_type': 'Tensor',
 'returns': [{'dynamic_type': 'Tensor', 'name': 'result', 'type': 'Tensor'}],
 'type_method_args': ['size', 'p', 'options'],
 'type_method_formals': ['IntList size',
                         'const Tensor &amp; p',
                         'const TensorOptions &amp; options'],
 'with_gil': False}"><pre class="notranslate">{<span class="pl-s">'abstract'</span>: <span class="pl-c1">False</span>,
 <span class="pl-s">'api_name'</span>: <span class="pl-s">'bernoulli'</span>,
 <span class="pl-s">'args'</span>: [<span class="pl-s">'size'</span>, <span class="pl-s">'p'</span>, <span class="pl-s">'options'</span>],
 <span class="pl-s">'arguments'</span>: [{<span class="pl-s">'dynamic_type'</span>: <span class="pl-s">'IntList'</span>,
                <span class="pl-s">'is_nullable'</span>: <span class="pl-c1">False</span>,
                <span class="pl-s">'name'</span>: <span class="pl-s">'size'</span>,
                <span class="pl-s">'simple_type'</span>: <span class="pl-s">'IntList'</span>,
                <span class="pl-s">'type'</span>: <span class="pl-s">'IntList'</span>},
               {<span class="pl-s">'dynamic_type'</span>: <span class="pl-s">'Tensor'</span>,
                <span class="pl-s">'is_nullable'</span>: <span class="pl-c1">False</span>,
                <span class="pl-s">'name'</span>: <span class="pl-s">'p'</span>,
                <span class="pl-s">'simple_type'</span>: <span class="pl-s">'Tensor'</span>,
                <span class="pl-s">'type'</span>: <span class="pl-s">'const Tensor &amp;'</span>},
               {<span class="pl-s">'default'</span>: <span class="pl-s">'static_cast&lt;int64_t&gt;(at::kFloat)'</span>,
                <span class="pl-s">'name'</span>: <span class="pl-s">'dtype'</span>,
                <span class="pl-s">'simple_type'</span>: <span class="pl-s">'int64_t'</span>},
               {<span class="pl-s">'default'</span>: <span class="pl-s">'{static_cast&lt;int64_t&gt;(at::Device::Type::CPU), -1}'</span>,
                <span class="pl-s">'name'</span>: <span class="pl-s">'device'</span>,
                <span class="pl-s">'simple_type'</span>: <span class="pl-s">'IntList'</span>},
               {<span class="pl-s">'default'</span>: <span class="pl-s">'static_cast&lt;int64_t&gt;(at::kStrided)'</span>,
                <span class="pl-s">'name'</span>: <span class="pl-s">'layout'</span>,
                <span class="pl-s">'simple_type'</span>: <span class="pl-s">'int64_t'</span>}],
 <span class="pl-s">'base_name'</span>: <span class="pl-s">'bernoulli'</span>,
 <span class="pl-s">'deprecated'</span>: <span class="pl-c1">False</span>,
 <span class="pl-s">'device_guard'</span>: <span class="pl-c1">True</span>,
 <span class="pl-s">'formals'</span>: [<span class="pl-s">'IntList size'</span>,
             <span class="pl-s">'const Tensor &amp; p'</span>,
             <span class="pl-s">'const TensorOptions &amp; options'</span>],
 <span class="pl-s">'has_tensor_options'</span>: <span class="pl-c1">True</span>,
 <span class="pl-s">'inplace'</span>: <span class="pl-c1">False</span>,
 <span class="pl-s">'method_of'</span>: [<span class="pl-s">'Type'</span>, <span class="pl-s">'namespace'</span>],
 <span class="pl-s">'method_prefix_derived'</span>: <span class="pl-s">''</span>,
 <span class="pl-s">'mode'</span>: <span class="pl-s">'native'</span>,
 <span class="pl-s">'name'</span>: <span class="pl-s">'bernoulli'</span>,
 <span class="pl-s">'return_type'</span>: <span class="pl-s">'Tensor'</span>,
 <span class="pl-s">'returns'</span>: [{<span class="pl-s">'dynamic_type'</span>: <span class="pl-s">'Tensor'</span>, <span class="pl-s">'name'</span>: <span class="pl-s">'result'</span>, <span class="pl-s">'type'</span>: <span class="pl-s">'Tensor'</span>}],
 <span class="pl-s">'type_method_args'</span>: [<span class="pl-s">'size'</span>, <span class="pl-s">'p'</span>, <span class="pl-s">'options'</span>],
 <span class="pl-s">'type_method_formals'</span>: [<span class="pl-s">'IntList size'</span>,
                         <span class="pl-s">'const Tensor &amp; p'</span>,
                         <span class="pl-s">'const TensorOptions &amp; options'</span>],
 <span class="pl-s">'with_gil'</span>: <span class="pl-c1">False</span>}</pre></div>
<p dir="auto">and</p>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="{'abstract': False,
 'api_name': 'bernoulli',
 'args': ['size', 'p', 'options'],
 'arguments': [{'dynamic_type': 'IntList',
                'is_nullable': False,
                'name': 'size',
                'simple_type': 'IntList',
                'type': 'IntList'},
               {'dynamic_type': 'double',
                'is_nullable': False,
                'name': 'p',
                'simple_type': 'double',
                'type': 'double'},
               {'default': 'static_cast&lt;int64_t&gt;(at::kFloat)',
                'name': 'dtype',
                'simple_type': 'int64_t'},
               {'default': '{static_cast&lt;int64_t&gt;(at::Device::Type::CPU), -1}',
                'name': 'device',
                'simple_type': 'IntList'},
               {'default': 'static_cast&lt;int64_t&gt;(at::kStrided)',
                'name': 'layout',
                'simple_type': 'int64_t'}],
 'base_name': 'bernoulli',
 'deprecated': False,
 'device_guard': True,
 'formals': ['IntList size', 'double p', 'const TensorOptions &amp; options'],
 'has_tensor_options': True,
 'inplace': False,
 'method_of': ['Type', 'namespace'],
 'method_prefix_derived': '',
 'mode': 'native',
 'name': 'bernoulli',
 'return_type': 'Tensor',
 'returns': [{'dynamic_type': 'Tensor', 'name': 'result', 'type': 'Tensor'}],
 'type_method_args': ['size', 'p', 'options'],
 'type_method_formals': ['IntList size',
                         'double p',
                         'const TensorOptions &amp; options'],
 'with_gil': False}"><pre class="notranslate">{<span class="pl-s">'abstract'</span>: <span class="pl-c1">False</span>,
 <span class="pl-s">'api_name'</span>: <span class="pl-s">'bernoulli'</span>,
 <span class="pl-s">'args'</span>: [<span class="pl-s">'size'</span>, <span class="pl-s">'p'</span>, <span class="pl-s">'options'</span>],
 <span class="pl-s">'arguments'</span>: [{<span class="pl-s">'dynamic_type'</span>: <span class="pl-s">'IntList'</span>,
                <span class="pl-s">'is_nullable'</span>: <span class="pl-c1">False</span>,
                <span class="pl-s">'name'</span>: <span class="pl-s">'size'</span>,
                <span class="pl-s">'simple_type'</span>: <span class="pl-s">'IntList'</span>,
                <span class="pl-s">'type'</span>: <span class="pl-s">'IntList'</span>},
               {<span class="pl-s">'dynamic_type'</span>: <span class="pl-s">'double'</span>,
                <span class="pl-s">'is_nullable'</span>: <span class="pl-c1">False</span>,
                <span class="pl-s">'name'</span>: <span class="pl-s">'p'</span>,
                <span class="pl-s">'simple_type'</span>: <span class="pl-s">'double'</span>,
                <span class="pl-s">'type'</span>: <span class="pl-s">'double'</span>},
               {<span class="pl-s">'default'</span>: <span class="pl-s">'static_cast&lt;int64_t&gt;(at::kFloat)'</span>,
                <span class="pl-s">'name'</span>: <span class="pl-s">'dtype'</span>,
                <span class="pl-s">'simple_type'</span>: <span class="pl-s">'int64_t'</span>},
               {<span class="pl-s">'default'</span>: <span class="pl-s">'{static_cast&lt;int64_t&gt;(at::Device::Type::CPU), -1}'</span>,
                <span class="pl-s">'name'</span>: <span class="pl-s">'device'</span>,
                <span class="pl-s">'simple_type'</span>: <span class="pl-s">'IntList'</span>},
               {<span class="pl-s">'default'</span>: <span class="pl-s">'static_cast&lt;int64_t&gt;(at::kStrided)'</span>,
                <span class="pl-s">'name'</span>: <span class="pl-s">'layout'</span>,
                <span class="pl-s">'simple_type'</span>: <span class="pl-s">'int64_t'</span>}],
 <span class="pl-s">'base_name'</span>: <span class="pl-s">'bernoulli'</span>,
 <span class="pl-s">'deprecated'</span>: <span class="pl-c1">False</span>,
 <span class="pl-s">'device_guard'</span>: <span class="pl-c1">True</span>,
 <span class="pl-s">'formals'</span>: [<span class="pl-s">'IntList size'</span>, <span class="pl-s">'double p'</span>, <span class="pl-s">'const TensorOptions &amp; options'</span>],
 <span class="pl-s">'has_tensor_options'</span>: <span class="pl-c1">True</span>,
 <span class="pl-s">'inplace'</span>: <span class="pl-c1">False</span>,
 <span class="pl-s">'method_of'</span>: [<span class="pl-s">'Type'</span>, <span class="pl-s">'namespace'</span>],
 <span class="pl-s">'method_prefix_derived'</span>: <span class="pl-s">''</span>,
 <span class="pl-s">'mode'</span>: <span class="pl-s">'native'</span>,
 <span class="pl-s">'name'</span>: <span class="pl-s">'bernoulli'</span>,
 <span class="pl-s">'return_type'</span>: <span class="pl-s">'Tensor'</span>,
 <span class="pl-s">'returns'</span>: [{<span class="pl-s">'dynamic_type'</span>: <span class="pl-s">'Tensor'</span>, <span class="pl-s">'name'</span>: <span class="pl-s">'result'</span>, <span class="pl-s">'type'</span>: <span class="pl-s">'Tensor'</span>}],
 <span class="pl-s">'type_method_args'</span>: [<span class="pl-s">'size'</span>, <span class="pl-s">'p'</span>, <span class="pl-s">'options'</span>],
 <span class="pl-s">'type_method_formals'</span>: [<span class="pl-s">'IntList size'</span>,
                         <span class="pl-s">'double p'</span>,
                         <span class="pl-s">'const TensorOptions &amp; options'</span>],
 <span class="pl-s">'with_gil'</span>: <span class="pl-c1">False</span>}</pre></div>