Skip to content

Conversation

@zasdfgbnm
Copy link
Collaborator

@zasdfgbnm zasdfgbnm commented Oct 21, 2019

Stack from ghstack:

Using the new type promotion and dynamic casting added to
TensorIterator, the copy kernels could be greatly simplified.

Script:

import torch
import timeit
import pandas
import itertools
from tqdm import tqdm
import math
print(torch.__version__)
print()

_10M = 10 * 1024 ** 2

d = {}

for from_, to in tqdm(itertools.product(torch.testing.get_all_dtypes(),
repeat=2)):
    if from_ not in d:
        d[from_] = {}
    a = torch.zeros(_10M, dtype=from_)
    min_ = math.inf
    for i in range(100):
        start = timeit.default_timer()
        a.to(to)
        end = timeit.default_timer()
        elapsed = end - start
        if elapsed < min_:
            min_ = elapsed
    d[from_][to] = int(elapsed * 1000 * 1000)

pandas.DataFrame(d)

Before:
image

After:
image

zasdfgbnm added a commit that referenced this pull request Oct 21, 2019
Using the new type promotion and dynamic casting added to
`TensorIterator`, the copy kernels could be greatly simplified.

**Script:**
```python
import torch
import timeit
import pandas
import itertools
from tqdm import tqdm
import math
print(torch.__version__)
print()

_10M = 10 * 1024 ** 2

d = {}

for from_, to in tqdm(itertools.product(torch.testing.get_all_dtypes(),
repeat=2)):
    if from_ not in d:
        d[from_] = {}
    a = torch.zeros(_10M, dtype=from_)
    min_ = math.inf
    for i in range(100):
        start = timeit.default_timer()
        a.to(to)
        end = timeit.default_timer()
        elapsed = end - start
        if elapsed < min_:
            min_ = elapsed
    d[from_][to] = int(elapsed * 1000 * 1000)

pandas.DataFrame(d)
```

**Before:**
![image](https://user-images.githubusercontent.com/1032377/67171274-2e93d000-f36b-11e9-8fa0-91edd7dbc8ec.png)

**After:**
![image](https://user-images.githubusercontent.com/1032377/67171200-d361dd80-f36a-11e9-9b22-66292e395a09.png)

ghstack-source-id: 3e43f97
Pull Request resolved: #28352
Using the new type promotion and dynamic casting added to
`TensorIterator`, the copy kernels could be greatly simplified.

**Script:**
```python
import torch
import timeit
import pandas
import itertools
from tqdm import tqdm
import math
print(torch.__version__)
print()

_10M = 10 * 1024 ** 2

d = {}

for from_, to in tqdm(itertools.product(torch.testing.get_all_dtypes(),
repeat=2)):
    if from_ not in d:
        d[from_] = {}
    a = torch.zeros(_10M, dtype=from_)
    min_ = math.inf
    for i in range(100):
        start = timeit.default_timer()
        a.to(to)
        end = timeit.default_timer()
        elapsed = end - start
        if elapsed < min_:
            min_ = elapsed
    d[from_][to] = int(elapsed * 1000 * 1000)

pandas.DataFrame(d)
```

**Before:**
![image](https://user-images.githubusercontent.com/1032377/67171274-2e93d000-f36b-11e9-8fa0-91edd7dbc8ec.png)

**After:**
![image](https://user-images.githubusercontent.com/1032377/67171200-d361dd80-f36a-11e9-9b22-66292e395a09.png)

[ghstack-poisoned]
@zasdfgbnm zasdfgbnm requested a review from colesbury October 21, 2019 03:48
@zasdfgbnm zasdfgbnm added better-engineering Relatively self-contained tasks for better engineering contributors module: operators labels Oct 21, 2019
@zasdfgbnm
Copy link
Collaborator Author

Sorry there is a bug in my benchmark code: I am not reporting the minimum time but reporting the last result instead. Here is the fixed script and result:

script:

import torch
import timeit
import pandas
import itertools
from tqdm.notebook import tqdm
import math
print(torch.__version__)
print()

_10M = 10 * 1024 ** 2

d = {}

for from_, to in tqdm(itertools.product(torch.testing.get_all_dtypes(), repeat=2)):
    if from_ not in d:
        d[from_] = {}
    a = torch.zeros(_10M, dtype=from_)
    min_ = math.inf
    for i in range(100):
        start = timeit.default_timer()
        a.to(to)
        end = timeit.default_timer()
        elapsed = end - start
        if elapsed < min_:
            min_ = elapsed
    d[from_][to] = int(min_ * 1000 * 1000)
    
pandas.DataFrame(d)

before:
image

after:
image

@zasdfgbnm zasdfgbnm merged commit d3cbbca into gh/zasdfgbnm/10/base Oct 22, 2019
zasdfgbnm added a commit that referenced this pull request Oct 22, 2019
Using the new type promotion and dynamic casting added to
`TensorIterator`, the copy kernels could be greatly simplified.

**Script:**
```python
import torch
import timeit
import pandas
import itertools
from tqdm import tqdm
import math
print(torch.__version__)
print()

_10M = 10 * 1024 ** 2

d = {}

for from_, to in tqdm(itertools.product(torch.testing.get_all_dtypes(),
repeat=2)):
    if from_ not in d:
        d[from_] = {}
    a = torch.zeros(_10M, dtype=from_)
    min_ = math.inf
    for i in range(100):
        start = timeit.default_timer()
        a.to(to)
        end = timeit.default_timer()
        elapsed = end - start
        if elapsed < min_:
            min_ = elapsed
    d[from_][to] = int(elapsed * 1000 * 1000)

pandas.DataFrame(d)
```

**Before:**
![image](https://user-images.githubusercontent.com/1032377/67171274-2e93d000-f36b-11e9-8fa0-91edd7dbc8ec.png)

**After:**
![image](https://user-images.githubusercontent.com/1032377/67171200-d361dd80-f36a-11e9-9b22-66292e395a09.png)

ghstack-source-id: d7fc960
Pull Request resolved: #28352
@zasdfgbnm zasdfgbnm mentioned this pull request Oct 22, 2019
zasdfgbnm added a commit that referenced this pull request Oct 22, 2019
Using the new type promotion and dynamic casting added to
`TensorIterator`, the copy kernels could be greatly simplified.

For benchmark, see #28352 (comment)

[ghstack-poisoned]
zasdfgbnm added a commit that referenced this pull request Oct 23, 2019
Using the new type promotion and dynamic casting added to
`TensorIterator`, the copy kernels could be greatly simplified.

For benchmark, see #28352 (comment)

[ghstack-poisoned]
zasdfgbnm added a commit that referenced this pull request Oct 24, 2019
Using the new type promotion and dynamic casting added to
`TensorIterator`, the copy kernels could be greatly simplified.

For benchmark, see #28352 (comment)

[ghstack-poisoned]
zasdfgbnm added a commit that referenced this pull request Oct 24, 2019
Using the new type promotion and dynamic casting added to
`TensorIterator`, the copy kernels could be greatly simplified.

For benchmark, see #28352 (comment)

[ghstack-poisoned]
zasdfgbnm added a commit that referenced this pull request Oct 25, 2019
Using the new type promotion and dynamic casting added to
`TensorIterator`, the copy kernels could be greatly simplified.

For benchmark, see #28352 (comment)

[ghstack-poisoned]
zasdfgbnm added a commit that referenced this pull request Oct 25, 2019
Using the new type promotion and dynamic casting added to
`TensorIterator`, the copy kernels could be greatly simplified.

For benchmark, see #28352 (comment)

[ghstack-poisoned]
zasdfgbnm added a commit that referenced this pull request Oct 26, 2019
Using the new type promotion and dynamic casting added to
`TensorIterator`, the copy kernels could be greatly simplified.

For benchmark, see #28352 (comment)

[ghstack-poisoned]
zasdfgbnm added a commit that referenced this pull request Oct 26, 2019
Using the new type promotion and dynamic casting added to
`TensorIterator`, the copy kernels could be greatly simplified.

For benchmark, see #28352 (comment)

[ghstack-poisoned]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

better-engineering Relatively self-contained tasks for better engineering contributors

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants