You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Summary:
Adds simple_gpt + DTensor implemented in pytorch-labs/simple_gpt#7 to torchbench
Tested via `python benchmarks/dynamo/torchbench.py -d cuda --output-directory=benchmark_logs --output=performance.csv --inference --performance --timing --print-memory --multiprocess --nothing --only simple_gpt`. Note: --nothing is used here to disable compile, since DTensor + compile isn't yet supported in main
```
dev,name,batch_size,speedup,abs_latency,compilation_latency,compression_ratio,eager_peak_mem,dynamo_peak_mem,calls_captured,unique_graphs,graph_breaks,unique_graph_breaks
cuda,simple_gpt,1,0.966153,196.819773,-0.059319,1.000000,4.576880,4.576880,0,0,0,0
cuda,simple_gpt,1,0.967389,196.608152,-0.058833,1.000000,4.577404,4.577404,0,0,0,0
cuda,simple_gpt,1,0.973152,196.093583,-0.059316,1.000000,4.593133,4.593133,0,0,0,0
cuda,simple_gpt,1,0.973087,196.124046,-0.075580,1.000000,4.611483,4.611483,0,0,0,0
cuda,simple_gpt,1,0.967908,193.998484,-0.040192,1.000000,4.593133,4.593133,0,0,0,0
cuda,simple_gpt,1,0.968949,193.798088,-0.028878,1.000000,4.593133,4.593133,0,0,0,0
```
2 changes were required to the model:
- decorate torch.no_grad() on the caches, previously this was done outside the model, the entire eval call was wrapped in a torch.no_grad() context. After using torchbench, I notice even with only inference mode, we don't disable gradient calculations
- rank/world size, added support from torchbench side in pytorch/pytorch#108438 and updated model to fetch from the provided extra_args
Pull Request resolved: #1867
Reviewed By: msaroufim
Differential Revision: D49065244
Pulled By: xmfan
fbshipit-source-id: d4709fa3997c6a25c75e87eff7c13492b370b1af
Copy file name to clipboardexpand all lines: torchbenchmark/models/ADDING_MODELS.md
+14-14
Original file line number
Diff line number
Diff line change
@@ -9,16 +9,16 @@
9
9
## Detailed steps
10
10
11
11
### Adding the model code
12
-
The intent is to preserve the original user code as much as possible while
12
+
The intent is to preserve the original user code as much as possible while
13
13
adding support for a standardized interface to the benchmark suite and making sure
14
14
the code can run from any directory and in a process with other models.
15
15
16
16
In many case it is fine to simply copy the entire original repo into a subdirectory
17
-
as a starting point, paying attention to avoid the .git folder, and not to add any
17
+
as a starting point, paying attention to avoid the .git folder, and not to add any
18
18
large unnecessary data files unintentionally. The subdirectory name should be a valid
19
19
Python identifier because it will become a module in Python and needs to be importable.
20
20
21
-
Create a new file 'origin' that contains the url to the git repo you're copying,
21
+
Create a new file 'origin' that contains the url to the git repo you're copying,
22
22
so it's easy to trace the code back to where it came from.
23
23
24
24
#### Wrapping your model in \_\_init\_\_.py
@@ -34,22 +34,22 @@ Take care to set the random seed like [here](https://github.com/pytorch/benchmar
34
34
#### A minimal new model addition
35
35
A bare miminum example you can follow is https://github.com/pytorch/benchmark/tree/main/torchbenchmark/models/phlippe_resnet
36
36
37
-
The functions you specifically need to implement are
37
+
The functions you specifically need to implement are
38
38
1.`__init__()` which is responsible for initalizing your `nn.Module`
39
39
2.`get_module()` which is responsible for returning the initialized `nn.Module` and an example input
40
40
3.`train()` which is a training loop, you can return a `NotImplementedError()` if your example is inference only. If your
41
41
training loop can be encapsulated by a `forward()`, `backward()`, and `optimizer_step()`, you need not redefine `train()`.
42
42
Instead, please make sure your model provides functions `forward()`, `backward()`, and `optimizer_step()` along with an
43
-
attribute `self.optimizer` which will be chained together for testing, see `invoke_staged_train_test()` for details.
43
+
attribute `self.optimizer` which will be chained together for testing, see `invoke_staged_train_test()` for details.
44
44
4.`eval()` which showcases a simple inference
45
45
46
-
Optionally, if you would like to be able to customize different optimizers for your model, feel free
46
+
Optionally, if you would like to be able to customize different optimizers for your model, feel free
47
47
to override the BenchmarkModel's base class' default `get_optimizer()` and `set_optimizer(optimizer)`
48
-
methods.
48
+
methods.
49
49
50
50
### Preparing install.py and dependencies
51
51
Simply put, install.py should be a one stop shop to install all the dependencies
52
-
for your model, __except torch, torchvision, torchaudio__ which should be assumed to
52
+
for your model, __except torch, torchvision, torchaudio__ which should be assumed to
53
53
have been installed by an outsider (the benchmark CI).
54
54
55
55
- Avoid pinning packages to specific versions with == without good reason, as the
@@ -65,7 +65,7 @@ not easy to build, there may be easier models to target.
65
65
[Example install.py](BERT_pytorch/install.py)
66
66
67
67
### Mini-dataset
68
-
By the time install.py script runs, a miniature version of the dataset is expected to be
68
+
By the time install.py script runs, a miniature version of the dataset is expected to be
69
69
staged and ready for use. It's fine to use install.py to download and prepare the data
70
70
if the download is quick. Otherwise, prepare the dataset manually, checking in the required
71
71
artifacts and modifying the \_\_init\_\_.py script as needed to use them.
@@ -95,8 +95,8 @@ This file should define two things:
95
95
-`__main__` function, which exercises the model APIs for local testing
96
96
97
97
Important: be deliberate about support for cpu/gpu and jit/no-jit. In the case that
98
-
your model is instantiated in an unsupported configuration, the convention is to return
99
-
a model object from \_\_init\_\_ but raise NotImplementedError() from all its methods.
98
+
your model is instantiated in an unsupported configuration, the convention is to raise
99
+
NotImplementedError from \_\_init\_\_.
100
100
101
101
See the [BenchmarkModel API](https://github.com/pytorch/benchmark/blob/master/torchbenchmark/util/model.py) to get started. The [BERT_pytorch](BERT_pytorch/__init__.py) benchmark can serve as a good example.
102
102
@@ -109,11 +109,11 @@ version.
109
109
110
110
### Test
111
111
112
-
After you've submitted your new model, suppose it was called `new_model` make sure the tests pass locally. Your model name is equivalent to the new folder you'd have created in `torchbenchmark/models`
112
+
After you've submitted your new model, suppose it was called `<new_model>` make sure the tests pass locally. Your model name is equivalent to the new folder you'd have created in `torchbenchmark/models`
113
113
114
114
1.`cd benchmark`
115
115
2.`python install.py`
116
-
3.`python run.py model -d cuda` and `python run.py model -d cpu`
117
-
3.`python test.py -k "model_"` following the format from here https://github.com/pytorch/benchmark#using-testpy
0 commit comments