-
Notifications
You must be signed in to change notification settings - Fork 11
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
fix the cpp guard #44
Conversation
cpp_guard = False | ||
|
||
try: | ||
from torch._dynamo.guards import GuardManager | ||
cpp_guard = isinstance(cache.check_fn, GuardManager) | ||
except Exception: | ||
pass | ||
|
||
if not cpp_guard: | ||
guard = cache.check_fn.code_parts | ||
freevar_names = cache.check_fn.__code__.co_freevars | ||
freevar_values = [x.cell_contents for x in cache.check_fn.__closure__] | ||
else: | ||
def visit(root, ans): | ||
for x in root.get_leaf_guards(): | ||
for verbose_str in x.verbose_code_parts(): | ||
verbose_str = verbose_str.split("#")[0].strip() | ||
ans.append(verbose_str) | ||
for child in root.get_child_managers(): | ||
visit(child, ans) | ||
guard = [] | ||
root = cache.check_fn.root | ||
visit(root, guard) | ||
if cache.check_fn.closure_vars is None: | ||
freevar_names = tuple() | ||
freevar_values = [] | ||
else: | ||
freevar_names = tuple(cache.check_fn.closure_vars.keys()) | ||
freevar_values = list(cache.check_fn.closure_vars.values()) | ||
|
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.
@anijain2305 can you help check if these lines are correct for getting all the guards when cpp guards are enabled?
I got thousands of guards from my experiments.
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.
Yes, these lines seem correct to me. We have increased the number of guards by more than order of magnitude since February. This is by enabling two flags
guard_nn_modules = True
and more recently
inline_inbuilt_nn_modules = True
These flags make Dynamo tracing safer than before.
No description provided.