-
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.
Added onnx visualizations for transformer model
- Loading branch information
Showing
10 changed files
with
91 additions
and
2 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
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
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,5 @@ | ||
num_encoder_layers:1 | ||
encoder_number_of_heads:1 | ||
window_size:2048 | ||
num_input_features:100 | ||
batch_size:16 |
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,45 @@ | ||
from model import TransformerVisual | ||
from options import Options | ||
|
||
import torch | ||
from torch.nn import MSELoss, CrossEntropyLoss | ||
from torch.optim import AdamW | ||
from torch.utils.data import DataLoader # random_split | ||
from torch._utils import _accumulate | ||
from torch import randperm | ||
import torch.onnx | ||
|
||
import numpy as np | ||
import matplotlib.pyplot as plt | ||
|
||
import argparse | ||
import os | ||
|
||
def update_options_from_args(options, args): | ||
for arg in vars(args): | ||
setattr(options, arg, getattr(args, arg)) | ||
|
||
def add_options_to_parser(parser): | ||
dummy_options = Options() | ||
for name in dummy_options.get_option_names(): | ||
default_value = getattr(dummy_options, name) | ||
if type(default_value) in [str, int, float]: | ||
parser.add_argument("--" + name, type=type(default_value), default=default_value) | ||
elif type(default_value) == bool: | ||
parser.add_argument("--" + name, action="store_false" if default_value else "store_true") | ||
|
||
def main(args): | ||
options = Options() | ||
update_options_from_args(options, args) | ||
|
||
transformer_model = TransformerVisual(options) | ||
dummy_input = torch.randn(options.window_size, options.batch_size, options.num_input_features) | ||
torch.onnx.export(transformer_model, dummy_input, "transformer_model.onnx") | ||
|
||
if __name__ == "__main__": | ||
parser = argparse.ArgumentParser(description='Transformer on crossbar') | ||
|
||
add_options_to_parser(parser) | ||
|
||
args = parser.parse_args() | ||
main(args) |