Skip to content

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.

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.

3 participants