-
Notifications
You must be signed in to change notification settings - Fork 24.8k
[dynamo] Initial support for nonstrict_trace
#146367
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
Closed
Closed
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
a389c1a
Update
StrongerXi 3225172
Update
StrongerXi 44ad899
Update
StrongerXi 4fc9b4d
Update
StrongerXi ceff0c9
Update
StrongerXi 904196b
Update
StrongerXi 021ddb6
Update
StrongerXi 2236b90
Update
StrongerXi c7f08cb
Update
StrongerXi 68a71b5
Update
StrongerXi 5dd522f
Update
StrongerXi 290dd13
Update
StrongerXi dcb8643
Update
StrongerXi 523df2c
Update
StrongerXi 7f34954
Update
StrongerXi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -115,6 +115,7 @@ | |
get_instruction_source_311, | ||
get_locals_to_steal, | ||
get_static_address_type, | ||
get_unique_name_wrt, | ||
graph_break_reasons, | ||
increment_op_count, | ||
lazy_format_graph_code, | ||
|
@@ -748,6 +749,17 @@ def module_key_name(*names): | |
|
||
return name | ||
|
||
def register_static_attr_and_return_proxy( | ||
self, attr_prefix: str, attr_value: Any | ||
) -> fx.Proxy: | ||
attr_name = get_unique_name_wrt(attr_prefix, self.nn_modules) | ||
# TODO `nn_modules` has been historically overloaded to store a lot more | ||
# than just nn module objects, fix that. | ||
self.nn_modules[attr_name] = attr_value | ||
proxy = self.create_proxy("get_attr", attr_name, (), {}) | ||
set_example_value(proxy.node, attr_value) | ||
return proxy | ||
|
||
def register_attr_or_module( | ||
self, | ||
target: Union[torch.nn.Module, torch.Tensor, Any], | ||
|
@@ -859,36 +871,30 @@ def wrap_name(module_key): | |
return wrap_name(k) | ||
|
||
name = OutputGraph.module_key_name(*names) | ||
name = get_unique_name_wrt(name, self.nn_modules, self.global_scope) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This chunk is just refactoring name generation into this call. |
||
self.nn_modules[name] = target | ||
if isinstance(target, torch.nn.Module): | ||
|
||
base = name | ||
for i in itertools.count(): | ||
if name not in self.nn_modules and name not in self.global_scope: | ||
self.nn_modules[name] = target | ||
if isinstance(target, torch.nn.Module): | ||
|
||
def register_leaf_name(leaf_name): | ||
assert self.param_name_to_source is not None | ||
new_source = ParamBufferSource(source, leaf_name) | ||
new_name = f"{name}.{leaf_name}" | ||
self.param_name_to_source[new_name] = new_source | ||
if isinstance(source, LocalSource): | ||
self.dynamo_flat_name_to_original_fqn[ | ||
OutputGraph.module_key_name(new_source.name()) | ||
] = leaf_name | ||
|
||
# annoying, but there are cases when we do not have parameters | ||
# see test_nn_moduledict_contains | ||
if hasattr(target, "_parameters"): | ||
for leaf_name, _ in target.named_parameters(): | ||
register_leaf_name(leaf_name) | ||
if hasattr(target, "_buffers"): | ||
for leaf_name, _ in target.named_buffers(): | ||
register_leaf_name(leaf_name) | ||
|
||
return wrap_name(name) | ||
name = f"{base}_{i}" | ||
|
||
raise AssertionError("unreachable") | ||
def register_leaf_name(leaf_name): | ||
assert self.param_name_to_source is not None | ||
new_source = ParamBufferSource(source, leaf_name) | ||
new_name = f"{name}.{leaf_name}" | ||
self.param_name_to_source[new_name] = new_source | ||
if isinstance(source, LocalSource): | ||
self.dynamo_flat_name_to_original_fqn[ | ||
OutputGraph.module_key_name(new_source.name()) | ||
] = leaf_name | ||
|
||
# annoying, but there are cases when we do not have parameters | ||
# see test_nn_moduledict_contains | ||
if hasattr(target, "_parameters"): | ||
for leaf_name, _ in target.named_parameters(): | ||
register_leaf_name(leaf_name) | ||
if hasattr(target, "_buffers"): | ||
for leaf_name, _ in target.named_buffers(): | ||
register_leaf_name(leaf_name) | ||
|
||
return wrap_name(name) | ||
|
||
def handle_aliases_for_stolen_lists(self, tx): | ||
# If list inputs are stolen, but still needed after the function call, create aliases to keep them alive | ||
|
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
Oops, something went wrong.
Oops, something went wrong.
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.
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.
id(obj)
can be reused ifobj
is deleted. We can still do this, but need to install a weakref callback to remove the ID ifobj
is deleted.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.
Yep created #147777 to track this, I'll try fixing it for all the relevant decorators in a subsequent patch.