8000 `torch.asarray` does not respect `set_default_device` · Issue #106773 · pytorch/pytorch · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

torch.asarray does not respect set_default_device #106773

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
rgommers opened this issue Aug 8, 2023 · 0 comments
Closed

torch.asarray does not respect set_default_device #106773

rgommers opened this issue Aug 8, 2023 · 0 comments
Assignees
Labels
bug module: numpy Related to numpy support, and also numpy compatibility of our operators triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module

Comments

@rgommers
Copy link
Collaborator
rgommers commented Aug 8, 2023

🐛 Describe the bug

torch.asarray should be respecting set_default_device like all other tensor creation functions, but it doesn't. We ran into this in the process of testing SciPy's in-progress support for PyTorch tensors (see this comment):

>>> import torch
>>> torch.set_default_device('cuda')
>>> torch.arange(3)
tensor([0, 1, 2], device='cuda:0')
>>> torch.tensor(3)
tensor(3, device='cuda:0')
>>> torch.asarray(3, device='cuda')
tensor(3, device='cuda:0')
>>> torch.asarray(3)  # THIS IS ENDING UP ON cpu!
tensor(3)

The asarray function is quite important, because it allows writing library-agnostic code and asarray is one of the most heavily used functions in test suites when doing so.

Versions

This is with pytorch 2.0.0. Full environment details:

$ python collect_env.py 
Collecting environment information...
PyTorch version: 2.0.0.post200
Is debug build: False
CUDA used to build PyTorch: 11.2
ROCM used to build PyTorch: N/A

OS: EndeavourOS Linux (x86_64)
GCC version: (conda-forge gcc 11.3.0-19) 11.3.0
Clang version: Could not collect
CMake version: version 3.26.4
Libc version: glibc-2.37

Python version: 3.10.11 | packaged by conda-forge | (main, May 10 2023, 18:58:44) [GCC 11.3.0] (64-bit runtime)
Python platform: Linux-6.3.2-arch1-1-x86_64-with-glibc2.37
Is CUDA available: True
CUDA runtime version: Could not collect
CUDA_MODULE_LOADING set to: LAZY
GPU models and configuration: GPU 0: NVIDIA GeForce GTX 1080 Ti
Nvidia driver version: 530.41.03
cuDNN version: Could not collect
HIP runtime version: N/A
MIOpen runtime version: N/A
Is XNNPACK available: True

CPU:
Architecture:                    x86_64
CPU op-mode(s):                  32-bit, 64-bit
Address sizes:                   46 bits physical, 48 bits virtual
Byte Order:                      Little Endian
CPU(s):                          24
On-line CPU(s) list:             0-23
Vendor ID:                       GenuineIntel
Model name:                      Intel(R) Core(TM) i9-7920X CPU @ 2.90GHz
CPU family:                      6
Model:                           85
Thread(s) per core:              2
Core(s) per socket:              12
Socket(s):                       1
Stepping:                        4
CPU(s) scaling MHz:              46%
CPU max MHz:                     4400,0000
CPU min MHz:                     1200,0000
BogoMIPS:                        5802,42
Flags:                           fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc art arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc cpuid aperfmperf pni pclmulqdq dtes64 monitor ds_cpl vmx est tm2 ssse3 sdbg fma cx16 xtpr pdcm pcid dca sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm abm 3dnowprefetch cpuid_fault epb cat_l3 cdp_l3 invpcid_single pti ssbd mba ibrs ibpb stibp tpr_shadow vnmi flexpriority ept vpid ept_ad fsgsbase tsc_adjust bmi1 hle avx2 smep bmi2 erms invpcid rtm cqm mpx rdt_a avx512f avx512dq rdseed adx smap clflushopt clwb intel_pt avx512cd avx512bw avx512vl xsaveopt xsavec xgetbv1 xsaves cqm_llc cqm_occup_llc cqm_mbm_total cqm_mbm_local dtherm ida arat pln pts md_clear flush_l1d arch_capabilities
Virtualization:                  VT-x
L1d cache:                       384 KiB (12 instances)
L1i cache:                       384 KiB (12 instances)
L2 cache:                        12 MiB (12 instances)
L3 cache:                        16,5 MiB (1 instance)
NUMA node(s):                    1
NUMA node0 CPU(s):               0-23
Vulnerability Itlb multihit:     KVM: Mitigation: VMX disabled
Vulnerability L1tf:              Mitigation; PTE Inversion; VMX conditional cache flushes, SMT vulnerable
Vulnerability Mds:               Mitigation; Clear CPU buffers; SMT vulnerable
Vulnerability Meltdown:          Mitigation; PTI
Vulnerability Mmio stale data:   Mitigation; Clear CPU buffers; SMT vulnerable
Vulnerability Retbleed:          Mitigation; IBRS
Vulnerability Spec store bypass: Mitigation; Speculative Store Bypass disabled via prctl
Vulnerability Spectre v1:        Mitigation; usercopy/swapgs barriers and __user pointer sanitization
Vulnerability Spectre v2:        Mitigation; IBRS, IBPB conditional, STIBP conditional, RSB filling, PBRSB-eIBRS Not affected
Vulnerability Srbds:             Not affected
Vulnerability Tsx async abort:   Mitigation; Clear CPU buffers; SMT vulnerable

Versions of relevant libraries:
[pip3] mypy==1.3.0
[pip3] mypy-extensions==1.0.0
[pip3] numpy==1.24.3
[pip3] numpydoc==1.5.0
[pip3] torch==2.0.0.post200
[conda] cudatoolkit               11.8.0              h37601d7_11    conda-forge
[conda] libmagma                  2.7.1                hc72dce7_1    conda-forge
[conda] libmagma_sparse           2.7.1                hc72dce7_2    conda-forge
[conda] magma                     2.7.1                ha770c72_2    conda-forge
[conda] mkl                       2022.2.1         h84fe81f_16997    conda-forge
[conda] numpy                     1.24.3          py310ha4c1d20_0    conda-forge
[conda] numpydoc                  1.5.0              pyhd8ed1ab_0    conda-forge
[conda] pytorch                   2.0.0           cuda112py310he33e0d6_200    conda-forge
cc @mruberry

Cc @ysiraichi as the original author (I believe) of torch.asarray.

@rgommers rgommers added module: numpy Related to numpy support, and also numpy compatibility of our operators bug labels Aug 8, 2023
ysiraichi added a commit that referenced this issue Aug 8, 2023
Fix: #106773

This PR makes it so `asarray` takes the default device into consideration when called with
a Python sequence as the data.

[ghstack-poisoned]
ysiraichi added a commit that referenced this issue Aug 8, 2023
…ation."

Fix: #106773

This PR makes it so `asarray` takes the default device into consideration when called with
a Python sequence as the data.

[ghstack-poisoned]
ysiraichi added a commit that referenced this issue Aug 8, 2023
Fix: #106773

This PR makes it so `asarray` takes the default device into consideration when called with
a Python sequence as the data.

[ghstack-poisoned]
ysiraichi added a commit that referenced this issue Aug 8, 2023
…ce into consideration."

Fix: #106773

This PR makes it so `asarray` takes the default device into consideration when called with
a Python sequence as the data.

[ghstack-poisoned]
ysiraichi added a commit that referenced this issue Aug 8, 2023
Fix: #106773

This PR makes it so `asarray` takes the default device into consideration when called with
a Python sequence as the data.

[ghstack-poisoned]
ysiraichi added a commit that referenced this issue Aug 8, 2023
Fix: #106773

This PR makes it so `asarray` takes the default device into consideration when called with
a Python sequence as the data.

ghstack-source-id: 20b11f2
Pull Request resolved: #106779
@drisspg drisspg added the triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module label Aug 9, 2023
ysiraichi added a commit that referenced this issue Aug 9, 2023
…nsideration."

Fix: #106773

This PR makes it so `asarray` takes the default device into consideration when called with
a Python sequence as the data.

[ghstack-poisoned]
ysiraichi added a commit that referenced this issue Aug 9, 2023
Fix: #106773

This PR makes it so `asarray` takes the default device into consideration when called with
a Python sequence as the data.

ghstack-source-id: 0552a22
Pull Request resolved: #106779
ysiraichi added a commit that referenced this issue Aug 9, 2023
…consideration."

Fix: #106773

This PR makes it so `asarray` takes the default device into consideration when called with
a Python sequence as the data.

[ghstack-poisoned]
ysiraichi added a commit that referenced this issue Aug 9, 2023
Fix: #106773

This PR makes it so `asarray` takes the default device into consideration when called with
a Python sequence as the data.

[ghstack-poisoned]
ysiraichi added a commit that referenced this issue Aug 9, 2023
Fix: #106773

This PR makes it so `asarray` takes the default device into consideration when called with
a Python sequence as the data.

ghstack-source-id: b408353
Pull Request resolved: #106779
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug module: numpy Related to numpy support, and also numpy compatibility of our operators triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module
Projects
None yet
Development

No branches or pull requests

3 participants
0