pytorch
7a3c223b - Migrate `var` & `std` to ATen (#39967)

Commit
5 years ago
Migrate `var` & `std` to ATen (#39967) Summary: Not sure why there are so many issues for std & var, but this PR should close them all: std: Fix https://github.com/pytorch/pytorch/issues/24771, Fix https://github.com/pytorch/pytorch/issues/24676, Fix https://github.com/pytorch/pytorch/issues/24639, Fix https://github.com/pytorch/pytorch/issues/24529 var: Fix https://github.com/pytorch/pytorch/issues/24782, Fix https://github.com/pytorch/pytorch/issues/24677, Fix https://github.com/pytorch/pytorch/issues/24652, Fix https://github.com/pytorch/pytorch/issues/24530 ```py import time import torch def _time(): if torch.cuda.is_available(): torch.cuda.synchronize() return time.time() for device in (torch.device("cpu"), torch.device("cuda")): for size in ( [100000000], [10000, 10000], [1000, 1000, 100], [100, 100, 100, 100], ): t = torch.randn(*size, device=device) total_time = 0 for i in range(10): t1 = _time() t.std() t2 = _time() total_time += t2 - t1 print(f"Tensor of size {size} on {device}: {total_time / 10}") ``` Before: ``` Tensor of size [100000000] on cpu: 0.36041643619537356 Tensor of size [10000, 10000] on cpu: 0.37235140800476074 Tensor of size [1000, 1000, 100] on cpu: 0.386572527885437 Tensor of size [100, 100, 100, 100] on cpu: 0.37404844760894773 Tensor of size [100000000] on cuda: 0.0021645784378051757 Tensor of size [10000, 10000] on cuda: 0.002090191841125488 Tensor of size [1000, 1000, 100] on cuda: 0.00208127498626709 Tensor of size [100, 100, 100, 100] on cuda: 0.0020844221115112306 ``` After: ``` Tensor of size [100000000] on cpu: 0.1339871883392334 Tensor of size [10000, 10000] on cpu: 0.1343991994857788 Tensor of size [1000, 1000, 100] on cpu: 0.1346735954284668 Tensor of size [100, 100, 100, 100] on cpu: 0.11906447410583496 Tensor of size [100000000] on cuda: 0.0013531208038330077 Tensor of size [10000, 10000] on cuda: 0.0012922048568725585 Tensor of size [1000, 1000, 100] on cuda: 0.001285886764526367 Tensor of size [100, 100, 100, 100] on cuda: 0.0012899160385131836 ``` cc: VitalyFedyunin Pull Request resolved: https://github.com/pytorch/pytorch/pull/39967 Differential Revision: D22162469 Pulled By: VitalyFedyunin fbshipit-source-id: 8d901c779767b00f81cd6231bc665e04f297b4c3
Author
Parents
Loading