This repository has been archived by the owner on Dec 16, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* benchmark transfers * create tensors directl on device when possible * fix
- Loading branch information
Showing
20 changed files
with
89 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,3 +3,6 @@ | |
**/__pycache__ | ||
.gitignore | ||
.git | ||
.coverage | ||
.benchmarks | ||
.mypy_cache |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -44,6 +44,7 @@ __pycache__ | |
|
||
.coverage | ||
.pytest_cache/ | ||
.benchmarks | ||
|
||
# documentation build artifacts | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import torch | ||
|
||
from allennlp.nn import util | ||
from allennlp.common.testing import requires_gpu | ||
|
||
|
||
@requires_gpu | ||
def bench_add_sentence_boundary_token_ids(benchmark): | ||
device = torch.device("cuda") | ||
# shape: (32, 50) | ||
tensor = torch.tensor([[3] * 50] * 32, device=device) | ||
# shape: (32, 50) | ||
mask = torch.tensor([[True] * 50, [True] * 30 + [False] * 20] * 16, device=device) | ||
begin_token = 1 | ||
end_token = 2 | ||
benchmark(util.add_sentence_boundary_token_ids, tensor, mask, begin_token, end_token) | ||
|
||
|
||
@requires_gpu | ||
def bench_remove_sentence_boundaries(benchmark): | ||
device = torch.device("cuda") | ||
# shape: (32, 50, 1) | ||
tensor = torch.tensor([[3] * 50] * 32, device=device).unsqueeze(-1) | ||
# shape: (32, 50) | ||
mask = torch.tensor([[True] * 50, [True] * 30 + [False] * 20] * 16, device=device) | ||
benchmark(util.remove_sentence_boundaries, tensor, mask) | ||
|
||
|
||
@requires_gpu | ||
def bench_create_tensor_then_send_to_device(benchmark): | ||
device = torch.device("cuda:0") | ||
|
||
def create_tensor(): | ||
return torch.rand((32, 50)).to(device) | ||
|
||
benchmark(create_tensor) | ||
|
||
|
||
@requires_gpu | ||
def bench_create_tensor_directly_on_device(benchmark): | ||
device = torch.device("cuda:0") | ||
|
||
def create_tensor(): | ||
return torch.rand((32, 50), device=device) | ||
|
||
benchmark(create_tensor) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters