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