Skip to content

torch.eye(d) is slow and hogs cpu for d >= 182 #48251

@akamaus

Description

@akamaus

🐛 Bug

I stumbled upon excessive CPU usage for my training code running on GPU. After some investigations I found the culprit.
It basically was

x = torch.eye(256).to('cuda') 

To Reproduce

This is quick and loads single CPU core.

%%timeit
    torch.eye(181)
6.43 µs ± 218 ns per loop (mean ± std. dev. of 7 runs, 100000 loops each)

This is 3 times slower and hogs 30 cores.

%%timeit
    torch.eye(182)
21.2 µs ± 84.8 ns per loop (mean ± std. dev. of 7 runs, 10000 loops each)

Environment

I tested on server with 72 Intel(R) Xeon(R) Gold 6140 CPU @ 2.30GHz cores (hyper-threading is on)

% python3 collect_env.py

Collecting environment information...
PyTorch version: 1.6.0
Is debug build: False
CUDA used to build PyTorch: 10.2
ROCM used to build PyTorch: N/A

OS: Ubuntu 18.04.3 LTS (x86_64)
GCC version: (Ubuntu 7.5.0-3ubuntu1~18.04) 7.5.0
Clang version: Could not collect
CMake version: version 3.10.2

Python version: 3.6 (64-bit runtime)
Is CUDA available: True
CUDA runtime version: Could not collect
GPU models and configuration:
GPU 0: GeForce RTX 2080 Ti
GPU 1: GeForce RTX 2080 Ti
GPU 2: GeForce RTX 2080 Ti
GPU 3: GeForce RTX 2080 Ti
GPU 4: GeForce RTX 2080 Ti
GPU 5: GeForce RTX 2080 Ti
GPU 6: GeForce RTX 2080 Ti
GPU 7: GeForce RTX 2080 Ti

Nvidia driver version: 440.100
cuDNN version: /usr/lib/x86_64-linux-gnu/libcudnn.so.7.6.5
HIP runtime version: N/A
MIOpen runtime version: N/A

Versions of relevant libraries:
[pip3] numpy==1.18.2
[pip3] pytorch-wavelets==1.2.2
[pip3] torch==1.6.0
[pip3] torchvision==0.4.2
[conda] Could not collect

cc @VitalyFedyunin @ngimel

Metadata

Metadata

Assignees

No one assigned

    Labels

    good first issuemodule: cpuCPU specific problem (e.g., perf, algorithm)module: multithreadingRelated to issues that occur when running on multiple CPU threadsmodule: performanceIssues related to performance, either of kernel code or framework gluetriagedThis issue has been looked at a team member, and triaged and prioritized into an appropriate module

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions