joaogante HF staff commited on
Commit
7cd710e
1 Parent(s): 6f5b463

init commit

Browse files
Files changed (2) hide show
  1. app.py +282 -0
  2. requirements.txt +1 -0
app.py ADDED
@@ -0,0 +1,282 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import matplotlib
2
+ matplotlib.use('Agg')
3
+
4
+ import functools
5
+
6
+ import gradio as gr
7
+ import matplotlib.pyplot as plt
8
+ import seaborn as sns
9
+ import pandas as pd
10
+
11
+
12
+ # benchmark order: pytorch, tf eager, tf xla; units = ms
13
+ BENCHMARK_DATA = {
14
+ "Greedy Decoding": {
15
+ "DistilGPT2": {
16
+ "T4": [336.22, 3976.23, 115.84],
17
+ "3090": [158.38, 1835.82, 46.56],
18
+ "A100": [371.49, 4073.84, 60.94],
19
+ },
20
+ "GPT2": {
21
+ "T4": [607.31, 7140.23, 185.12],
22
+ "3090": [297.03, 3308.31, 76.68],
23
+ "A100": [691.75, 7323.60, 110.72],
24
+ },
25
+ "OPT-1.3B": {
26
+ "T4": [1303.41, 15939.07, 1488.15],
27
+ "3090": [428.33, 7259.43, 468.37],
28
+ "A100": [1125.00, 16713.63, 384.52],
29
+ },
30
+ "GPTJ-6B": {
31
+ "T4": [0, 0, 0],
32
+ "3090": [0, 0, 0],
33
+ "A100": [2664.28, 32783.09, 1440.06],
34
+ },
35
+ "T5 Small": {
36
+ "T4": [99.88, 1527.73, 18.78],
37
+ "3090": [55.09, 665.70, 9.25],
38
+ "A100": [124.91, 1642.07, 13.72],
39
+ },
40
+ "T5 Base": {
41
+ "T4": [416.56, 6095.05, 106.12],
42
+ "3090": [223.00, 2503.28, 46.67],
43
+ "A100": [550.76, 6504.11, 64.57],
44
+ },
45
+ "T5 Large": {
46
+ "T4": [645.05, 9587.67, 225.17],
47
+ "3090": [377.74, 4216.41, 97.92],
48
+ "A100": [944.17, 10572.43, 116.52],
49
+ },
50
+ "T5 3B": {
51
+ "T4": [1493.61, 13629.80, 1494.80],
52
+ "3090": [694.75, 6316.79, 489.33],
53
+ "A100": [1801.68, 16707.71, 411.93],
54
+ },
55
+ },
56
+ "Sampling": {
57
+ "DistilGPT2": {
58
+ "T4": [617.40, 6078.81, 221.65],
59
+ "3090": [310.37, 2843.73, 85.44],
60
+ "A100": [729.05, 7140.05, 121.83],
61
+ },
62
+ "GPT2": {
63
+ "T4": [1205.34, 12256.98, 378.69],
64
+ "3090": [577.12, 5637.11, 160.02],
65
+ "A100": [1377.68, 15605.72, 234.47],
66
+ },
67
+ "OPT-1.3B": {
68
+ "T4": [2166.72, 19126.25, 2341.32],
69
+ "3090": [706.50, 9616.97, 731.58],
70
+ "A100": [2019.70, 28621.09, 690.36],
71
+ },
72
+ "GPTJ-6B": {
73
+ "T4": [0, 0, 0],
74
+ "3090": [0, 0, 0],
75
+ "A100": [5150.35, 70554.07, 2744.49],
76
+ },
77
+ "T5 Small": {
78
+ "T4": [235.93, 3599.47, 41.07],
79
+ "3090": [100.41, 1093.33, 23.24],
80
+ "A100": [267.42, 3366.73, 28.53],
81
+ },
82
+ "T5 Base": {
83
+ "T4": [812.59, 7966.73, 196.85],
84
+ "3090": [407.81, 4904.54, 97.56],
85
+ "A100": [1033.05, 11521.97, 123.93],
86
+ },
87
+ "T5 Large": {
88
+ "T4": [1114.22, 16433.31, 424.91],
89
+ "3090": [647.61, 7184.71, 160.97],
90
+ "A100": [1668.73, 19962.78, 200.75],
91
+ },
92
+ "T5 3B": {
93
+ "T4": [2282.56, 20891.22, 2196.02],
94
+ "3090": [1011.32, 9735.97, 734.40],
95
+ "A100": [2769.64, 26440.65, 612.98],
96
+ },
97
+ },
98
+ "Beam Search": {
99
+ "DistilGPT2": {
100
+ "T4": [2407.89, 19442.60, 3313.92],
101
+ "3090": [998.52, 8286.03, 900.28],
102
+ "A100": [2237.41, 21771.40, 760.47],
103
+ },
104
+ "GPT2": {
105
+ "T4": [3767.43, 34813.93, 5559.42],
106
+ "3090": [1633.04, 14606.93, 1533.55],
107
+ "A100": [3705.43, 34586.23, 1295.87],
108
+ },
109
+ "OPT-1.3B": {
110
+ "T4": [16649.82, 78500.33, 21894.31],
111
+ "3090": [508518, 32822.81, 5762.46],
112
+ "A100": [5967.32, 78334.56, 4096.38],
113
+ },
114
+ "GPTJ-6B": {
115
+ "T4": [0, 0, 0],
116
+ "3090": [0, 0, 0],
117
+ "A100": [15119.10, 134000.40, 10214.17],
118
+ },
119
+ "T5 Small": {
120
+ "T4": [283.64, 25089.12, 1391.66],
121
+ "3090": [137.38, 10680.28, 486.96],
122
+ "A100": [329.28, 24747.38, 513.99],
123
+ },
124
+ "T5 Base": {
125
+ "T4": [1383.21, 44809.14, 3920.40],
126
+ "3090": [723.11, 18657.48, 1258.60],
127
+ "A100": [2360.85, 45085.07, 1107.58],
128
+ },
129
+ "T5 Large": {
130
+ "T4": [1663.50, 81902.41, 9551.29],
131
+ "3090": [922.53, 35524.30, 2838.86],
132
+ "A100": [2168.22, 86890.00, 2373.04],
133
+ },
134
+ "T5 3B": {
135
+ "T4": [0, 0, 0],
136
+ "3090": [1521.05, 35337.30, 8282.09],
137
+ "A100": [3162.54, 88453.65, 5585.20],
138
+ },
139
+ },
140
+ }
141
+ FIGURE_PATH = "plt.png"
142
+ FIG_DPI = 300
143
+
144
+
145
+ def get_plot(model_name, plot_eager, generate_type):
146
+ df = pd.DataFrame(BENCHMARK_DATA[generate_type][model_name])
147
+ df["framework"] = ["PyTorch", "TF (Eager Execution)", "TF (XLA)"]
148
+ df = pd.melt(df, id_vars=["framework"], value_vars=["T4", "3090", "A100"])
149
+ if plot_eager == "No":
150
+ df = df[df["framework"] != "TF (Eager Execution)"]
151
+
152
+ g = sns.catplot(
153
+ data=df,
154
+ kind="bar",
155
+ x="variable",
156
+ y="value",
157
+ hue="framework",
158
+ palette={"PyTorch": "blue", "TF (Eager Execution)": "orange", "TF (XLA)": "red"},
159
+ alpha=.9,
160
+ )
161
+ g.despine(left=True)
162
+ g.set_axis_labels("GPU", "Generation time (ms)")
163
+ g.legend.set_title("Framework")
164
+
165
+ # Add the number to the top of each bar
166
+ ax = g.facet_axis(0, 0)
167
+ for i in ax.containers:
168
+ ax.bar_label(i,)
169
+
170
+ plt.savefig(FIGURE_PATH, dpi=FIG_DPI)
171
+ return FIGURE_PATH
172
+
173
+ demo = gr.Blocks()
174
+
175
+ with demo:
176
+ gr.Markdown(
177
+ """
178
+ # TensorFlow XLA Text Generation Benchmark
179
+ Instructions:
180
+ 1. Pick a tab for the type of generation (or for benchmark information);
181
+ 2. Select a model from the dropdown menu;
182
+ 3. Optionally omit results from TensorFlow Eager Execution, if you wish to better compare the performance of
183
+ PyTorch to TensorFlow with XLA.
184
+ """
185
+ )
186
+ with gr.Tabs():
187
+ with gr.TabItem("Greedy Decoding"):
188
+ plot_fn = functools.partial(get_plot, generate_type="Greedy Decoding")
189
+ with gr.Row():
190
+ with gr.Column():
191
+ model_selector = gr.Dropdown(
192
+ choices=["DistilGPT2", "GPT2", "OPT-1.3B", "GPTJ-6B", "T5 Small", "T5 Base", "T5 Large", "T5 3B"],
193
+ value="T5 Small",
194
+ label="Model",
195
+ interactive=True,
196
+ )
197
+ eager_enabler = gr.Radio(
198
+ ["Yes", "No"],
199
+ value="Yes",
200
+ label="Plot TF Eager Execution?",
201
+ interactive=True
202
+ )
203
+ gr.Markdown(
204
+ """
205
+ ### Greedy Decoding benchmark parameters
206
+ - `max_new_tokens = 64`;
207
+ - `pad_to_multiple_of = 64` for Tensorflow XLA models. Others do not pad (input prompts between 2 and 33 tokens).
208
+ """
209
+ )
210
+ plot = gr.Image(value=plot_fn("T5 Small", "Yes")) # Show plot when the gradio app is initialized
211
+ model_selector.change(fn=plot_fn, inputs=[model_selector, eager_enabler], outputs=plot)
212
+ eager_enabler.change(fn=plot_fn, inputs=[model_selector, eager_enabler], outputs=plot)
213
+ with gr.TabItem("Sampling"):
214
+ plot_fn = functools.partial(get_plot, generate_type="Sampling")
215
+ with gr.Row():
216
+ with gr.Column():
217
+ model_selector = gr.Dropdown(
218
+ choices=["DistilGPT2", "GPT2", "OPT-1.3B", "GPTJ-6B", "T5 Small", "T5 Base", "T5 Large", "T5 3B"],
219
+ value="T5 Small",
220
+ label="Model",
221
+ interactive=True,
222
+ )
223
+ eager_enabler = gr.Radio(
224
+ ["Yes", "No"],
225
+ value="Yes",
226
+ label="Plot TF Eager Execution?",
227
+ interactive=True
228
+ )
229
+ gr.Markdown(
230
+ """
231
+ ### Sampling benchmark parameters
232
+ - `max_new_tokens = 128`;
233
+ - `temperature = 2.0`;
234
+ - `top_k = 50`;
235
+ - `pad_to_multiple_of = 64` for Tensorflow XLA models. Others do not pad (input prompts between 2 and 33 tokens).
236
+ """
237
+ )
238
+ plot = gr.Image(value=plot_fn("T5 Small", "Yes")) # Show plot when the gradio app is initialized
239
+ model_selector.change(fn=plot_fn, inputs=[model_selector, eager_enabler], outputs=plot)
240
+ eager_enabler.change(fn=plot_fn, inputs=[model_selector, eager_enabler], outputs=plot)
241
+ with gr.TabItem("Beam Search"):
242
+ plot_fn = functools.partial(get_plot, generate_type="Beam Search")
243
+ with gr.Row():
244
+ with gr.Column():
245
+ model_selector = gr.Dropdown(
246
+ choices=["DistilGPT2", "GPT2", "OPT-1.3B", "GPTJ-6B", "T5 Small", "T5 Base", "T5 Large", "T5 3B"],
247
+ value="T5 Small",
248
+ label="Model",
249
+ interactive=True,
250
+ )
251
+ eager_enabler = gr.Radio(
252
+ ["Yes", "No"],
253
+ value="Yes",
254
+ label="Plot TF Eager Execution?",
255
+ interactive=True
256
+ )
257
+ gr.Markdown(
258
+ """
259
+ ### Beam Search benchmark parameters
260
+ - `max_new_tokens = 256`;
261
+ - `num_beams = 16`;
262
+ - `pad_to_multiple_of = 64` for Tensorflow XLA models. Others do not pad (input prompts between 2 and 33 tokens).
263
+ """
264
+ )
265
+ plot = gr.Image(value=plot_fn("T5 Small", "Yes")) # Show plot when the gradio app is initialized
266
+ model_selector.change(fn=plot_fn, inputs=[model_selector, eager_enabler], outputs=plot)
267
+ eager_enabler.change(fn=plot_fn, inputs=[model_selector, eager_enabler], outputs=plot)
268
+ with gr.TabItem("Benchmark Information"):
269
+ gr.Dataframe(
270
+ headers=["Parameter", "Value"],
271
+ value=[
272
+ ["Transformers Version", "4.21"],
273
+ ["TensorFlow Version", "2.9.1"],
274
+ ["Pytorch Version", "1.11.0"],
275
+ ["OS", "22.04 LTS (3090) / Debian 10 (other GPUs)"],
276
+ ["CUDA", "11.6 (3090) / 11.3 (others GPUs)"],
277
+ ["Number of Runs", "100 (the first run was discarded to ignore compilation time)"],
278
+ ["Is there code to reproduce?", "Yes -- https://gist.github.com/gante/f0017e3f13ac11b0c02e4e4db351f52f"],
279
+ ],
280
+ )
281
+
282
+ demo.launch()
requirements.txt ADDED
@@ -0,0 +1 @@
 
 
1
+ seaborn