-
Notifications
You must be signed in to change notification settings - Fork 361
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
docs: Adding words to the refit and engine caching tutorials #3141
Merged
Conversation
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are some changes that do not conform to Python style guidelines:
--- /home/runner/work/TensorRT/TensorRT/examples/dynamo/engine_caching_bert_example.py 2024-09-03 20:07:41.366823+00:00
+++ /home/runner/work/TensorRT/TensorRT/examples/dynamo/engine_caching_bert_example.py 2024-09-03 20:08:00.989606+00:00
@@ -5,10 +5,11 @@
Engine Caching (BERT)
=======================
Small caching example on BERT.
"""
+
import numpy as np
import torch
import torch_tensorrt
from engine_caching_example import remove_timing_cache
from transformers import BertModel
--- /home/runner/work/TensorRT/TensorRT/docsrc/conf.py 2024-09-03 20:07:41.362823+00:00
+++ /home/runner/work/TensorRT/TensorRT/docsrc/conf.py 2024-09-03 20:08:01.014045+00:00
@@ -91,11 +91,11 @@
# sphinx-gallery configuration
sphinx_gallery_conf = {
"examples_dirs": "../examples",
"gallery_dirs": "tutorials/_rendered_examples/",
- "ignore_pattern": "utils.py"
+ "ignore_pattern": "utils.py",
}
# Setup the breathe extension
breathe_projects = {"Torch-TensorRT": "./_tmp/xml"}
breathe_default_project = "Torch-TensorRT"
--- /home/runner/work/TensorRT/TensorRT/examples/dynamo/engine_caching_example.py 2024-09-03 20:07:41.366823+00:00
+++ /home/runner/work/TensorRT/TensorRT/examples/dynamo/engine_caching_example.py 2024-09-03 20:08:01.131264+00:00
@@ -45,10 +45,11 @@
def remove_timing_cache(path=TIMING_CACHE_PATH):
if os.path.exists(path):
os.remove(path)
+
# %%
# Engine Caching for JIT Compilation
# ----------------------------------
#
@@ -61,10 +62,11 @@
# engines are saved to disk tied to a hash of their corresponding PyTorch subgraph. If
# in a subsequent compilation, either as part of this session or a new session, the cache will
# pull the built engine and **refit** the weights which can reduce compilation times by orders of magnitude.
# As such, in order to insert a new engine into the cache (i.e. ``cache_built_engines=True``),
# the engine must be refitable (``make_refittable=True``). See :ref:`refit_engine_example` for more details.
+
def torch_compile(iterations=3):
times = []
start = torch.cuda.Event(enable_timing=True)
end = torch.cuda.Event(enable_timing=True)
@@ -108,18 +110,20 @@
print("----------------torch_compile----------------")
print("disable engine caching, used:", times[0], "ms")
print("enable engine caching to cache engines, used:", times[1], "ms")
print("enable engine caching to reuse engines, used:", times[2], "ms")
+
torch_compile()
# %%
# Engine Caching for AOT Compilation
# ----------------------------------
# Similarly to the JIT workflow, AOT workflows can benefit from engine caching.
# As the same architecture or common subgraphs get recompiled, the cache will pull
# previously built engines and refit the weights.
+
def dynamo_compile(iterations=3):
times = []
start = torch.cuda.Event(enable_timing=True)
end = torch.cuda.Event(enable_timing=True)
@@ -166,10 +170,11 @@
print("----------------dynamo_compile----------------")
print("disable engine caching, used:", times[0], "ms")
print("enable engine caching to cache engines, used:", times[1], "ms")
print("enable engine caching to reuse engines, used:", times[2], "ms")
+
dynamo_compile()
# %%
# Custom Engine Cache
# ----------------------
@@ -185,10 +190,11 @@
#
# The hash provided by the cache systen is a weight agnostic hash of the originating PyTorch subgraph (post lowering).
# The blob contains a serialized engine, calling spec data, and weight map information in the pickle format
#
# Below is an example of a custom engine cache implementation that implents a ``RAMEngineCache``.
+
class RAMEngineCache(BaseEngineCache):
def __init__(
self,
) -> None:
@@ -276,6 +282,7 @@
print("----------------torch_compile----------------")
print("disable engine caching, used:", times[0], "ms")
print("enable engine caching to cache engines, used:", times[1], "ms")
print("enable engine caching to reuse engines, used:", times[2], "ms")
+
torch_compile_my_cache()
--- /home/runner/work/TensorRT/TensorRT/py/torch_tensorrt/dynamo/_engine_cache.py 2024-09-03 20:07:41.378823+00:00
+++ /home/runner/work/TensorRT/TensorRT/py/torch_tensorrt/dynamo/_engine_cache.py 2024-09-03 20:08:01.555967+00:00
@@ -142,11 +142,13 @@
engine_cache_dir
)
if engine_cache_dir not in DiskEngineCache.dir2hash2size_map:
DiskEngineCache.dir2hash2size_map[engine_cache_dir] = {}
- _LOGGER.info(f"Disk engine cache initialized (cache directory:{self.engine_cache_dir}, max size: {self.total_engine_cache_size})")
+ _LOGGER.info(
+ f"Disk engine cache initialized (cache directory:{self.engine_cache_dir}, max size: {self.total_engine_cache_size})"
+ )
def has_available_cache_size(self, needed_size: int) -> bool:
"""Check if the cache has available space for saving object
Args:
Signed-off-by: Naren Dasan <[email protected]>
a4684e3
to
d5e3a77
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are some changes that do not conform to Python style guidelines:
--- /home/runner/work/TensorRT/TensorRT/docsrc/conf.py 2024-09-03 20:34:09.598244+00:00
+++ /home/runner/work/TensorRT/TensorRT/docsrc/conf.py 2024-09-03 20:34:44.738932+00:00
@@ -91,11 +91,11 @@
# sphinx-gallery configuration
sphinx_gallery_conf = {
"examples_dirs": "../examples",
"gallery_dirs": "tutorials/_rendered_examples/",
- "ignore_pattern": "utils.py"
+ "ignore_pattern": "utils.py",
}
# Setup the breathe extension
breathe_projects = {"Torch-TensorRT": "./_tmp/xml"}
breathe_default_project = "Torch-TensorRT"
Signed-off-by: Naren Dasan <[email protected]>
d5e3a77
to
8492c62
Compare
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
cla signed
component: api [Python]
Issues re: Python API
component: build system
Issues re: Build system
component: conversion
Issues re: Conversion stage
component: core
Issues re: The core compiler
component: dynamo
Issues relating to the `torch.compile` or `torch._dynamo.export` paths
component: runtime
component: tests
Issues re: Tests
documentation
Improvements or additions to documentation
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
Adds a bunch of text explaining the two new refit features for 2.5
Fixes # (issue)
Type of change
Please delete options that are not relevant and/or add your own.
Checklist: