KEMBAR78
Pytorch very slow to convert list of numpy arrays into tensors · Issue #13918 · pytorch/pytorch · GitHub
Skip to content

Pytorch very slow to convert list of numpy arrays into tensors #13918

@lcswillems

Description

@lcswillems

🐛 Bug

I compared the execution time of two codes.

Code 1:

import torch
import numpy as np

a = [np.random.randint(0, 10, size=(7, 7, 3)) for _ in range(100000)]
b = torch.tensor(np.array(a))

And code 2:

import torch
import numpy as np

a = [np.random.randint(0, 10, size=(7, 7, 3)) for _ in range(100000)]
b = torch.tensor(a)

The code 1 takes less than 1 second to execute (used time):

real    0m0,915s
user    0m0,808s
sys     0m0,330s

Whereas the code 2 takes 5 seconds:

real    0m6,057s
user    0m5,979s
sys     0m0,308s

Expected behavior

I would expect code 2 to be as fast as code 1.

Environment

  • PyTorch 0.4.1
  • Linux
  • OS (e.g., Linux):
  • Installed with conda
  • Python version: 3.6

cc @ezyang @gchanan @zou3519 @bdhirsh @jbschlosser @mruberry @rgommers @heitorschueroff @VitalyFedyunin @ngimel

Metadata

Metadata

Assignees

Labels

enhancementNot as big of a feature, but technically not a bug. Should be easy to fixhas workaroundhigh prioritymodule: numpyRelated to numpy support, and also numpy compatibility of our operatorsmodule: 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