Skip to content
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

Merged
merged 3 commits into from
Aug 7, 2024
Merged

fix the cpp guard #44

merged 3 commits into from
Aug 7, 2024

Conversation

youkaichao
Copy link
Member

No description provided.

Comment on lines +118 to +147
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())

Copy link
Member Author

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.

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.

@youkaichao youkaichao merged commit f4b1d03 into master Aug 7, 2024
9 checks passed
@youkaichao youkaichao deleted the fix_guard branch August 7, 2024 06:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants