Skip to content

Commit 4f3ef4b

Browse files
committed
More suggestions
1 parent 79b2087 commit 4f3ef4b

File tree

2 files changed

+27
-5
lines changed

2 files changed

+27
-5
lines changed

recipes_source/compiling_optimizer.py

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,16 @@
33
==========================================================================================
44
55
6-
**Author:** `Michale Lazos <https://github.com/mlazos>`_
6+
**Author:** `Michael Lazos <https://github.com/mlazos>`_
77
"""
88

99
######################################################################
1010
#
11-
# In this recipe, we will apply ``torch.compile`` to the optimizer to observe
12-
# the GPU performance improvement.
11+
# The optimizer is a key algorithm for training any deep learning model.
12+
# Since it is responsible for updating every model parameter, it can often
13+
# become the bottleneck in training performance for large models. In this recipe,
14+
# we will apply ``torch.compile`` to the optimizer to observe the GPU performance
15+
# improvement.
1316
#
1417
# .. note::
1518
#
@@ -65,5 +68,14 @@ def benchmark_torch_function_in_microseconds(f, *args, **kwargs):
6568
for _ in range(5):
6669
fn()
6770

68-
print(f"eager runtime: {benchmark_torch_function_in_microseconds(opt.step)}us")
69-
print(f"compiled runtime: {benchmark_torch_function_in_microseconds(fn)}us")
71+
eager_runtime = benchmark_torch_function_in_microseconds(opt.step)
72+
compiled_runtime = benchmark_torch_function_in_microseconds(fn)
73+
74+
assert eager_runtime > compiled_runtime
75+
76+
print(f"eager runtime: {eager_runtime}us")
77+
print(f"compiled runtime: {compiled_runtime}us")
78+
79+
# Sample Results:
80+
# eager runtime: 747.2437149845064us
81+
# compiled runtime: 392.07384741178us

recipes_source/recipes_index.rst

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,15 @@ Recipes are bite-sized, actionable examples of how to use specific PyTorch featu
276276
:link: ../recipes/amx.html
277277
:tags: Model-Optimization
278278

279+
.. (beta) Compiling the Optimizer with torch.compile
280+
281+
.. customcarditem::
282+
:header: (beta) Compiling the Optimizer with torch.compile
283+
:card_description: Speed up the optimizer using torch.compile
284+
:image: ../_static/img/thumbnails/cropped/generic-pytorch-logo.png
285+
:link: ../recipes/compiling_optimizer.html
286+
:tags: Model-Optimization
287+
279288
.. Intel(R) Extension for PyTorch*
280289
281290
.. customcarditem::
@@ -368,6 +377,7 @@ Recipes are bite-sized, actionable examples of how to use specific PyTorch featu
368377
/recipes/recipes/amp_recipe
369378
/recipes/recipes/tuning_guide
370379
/recipes/recipes/intel_extension_for_pytorch
380+
/recipes/compiling_optimizer
371381
/recipes/torch_compile_backend_ipex
372382
/recipes/torchscript_inference
373383
/recipes/deployment_with_flask

0 commit comments

Comments
 (0)