forked from nod-ai/SHARK-Studio
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
-Introduce SharkBenchmark that bench models on regular torch, shark-py, and shark-c. -Integrate iree-benchmark-module into Shark.
- Loading branch information
1 parent
18a4423
commit 91867e1
Showing
4 changed files
with
231 additions
and
17 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 |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import torch | ||
from transformers import AutoTokenizer, AutoModelForSequenceClassification | ||
from shark.shark_inference import SharkInference | ||
|
||
torch.manual_seed(0) | ||
tokenizer = AutoTokenizer.from_pretrained("microsoft/MiniLM-L12-H384-uncased") | ||
|
||
|
||
class MiniLMSequenceClassification(torch.nn.Module): | ||
|
||
def __init__(self): | ||
super().__init__() | ||
self.model = AutoModelForSequenceClassification.from_pretrained( | ||
"microsoft/MiniLM-L12-H384-uncased", # The pretrained model. | ||
num_labels= | ||
2, # The number of output labels--2 for binary classification. | ||
output_attentions= | ||
False, # Whether the model returns attentions weights. | ||
output_hidden_states= | ||
False, # Whether the model returns all hidden-states. | ||
torchscript=True, | ||
) | ||
|
||
def forward(self, tokens): | ||
return self.model.forward(tokens)[0] | ||
|
||
|
||
test_input = torch.randint(2, (1, 128)) | ||
|
||
shark_module = SharkInference(MiniLMSequenceClassification(), (test_input,), | ||
jit_trace=True, benchmark_mode=True) | ||
|
||
shark_module.compile() | ||
shark_module.forward((test_input,)) | ||
shark_module.benchmark_all((test_input,)) |
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