-
Notifications
You must be signed in to change notification settings - Fork 25.7k
[dynamo] Remove mutable_local.source and index on VariableTracker rather than MutableLocalBase
#137905
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
[dynamo] Remove mutable_local.source and index on VariableTracker rather than MutableLocalBase
#137905
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -51,6 +51,7 @@ def __init__( | |
| root: Optional[torch.nn.Module] = None, | ||
| graph_output_var: Optional[str] = None, | ||
| tempvars=None, | ||
| overridden_sources=None, | ||
| ) -> None: | ||
| self.root = root | ||
| self.top_of_stack: Optional[VariableTracker] = None | ||
|
|
@@ -65,6 +66,10 @@ def __init__( | |
| self.new_var = self.tx.output.new_var | ||
| self.mutable_side_effects_from_source = False | ||
| self.value_from_source: bool = True | ||
| # This serves as a way for codegen to use a different source; we need | ||
| # this because sometimes we can't easily modify the original source | ||
| # without affecting other components, e.g., guards. | ||
| self.overridden_sources: Dict[Source, Source] = overridden_sources or {} | ||
|
|
||
| def restore_stack(self, stack_values, *, value_from_source=True): | ||
| prior = self.mutable_side_effects_from_source | ||
|
|
@@ -116,7 +121,9 @@ def add_push_null(self, gen_fn, call_function_ex=False): | |
| def __call__(self, value, allow_cache=True): | ||
| """Generate code such that top-of-stack (TOS) is set to value""" | ||
| if isinstance(value, Source): | ||
| self.call_reconstruct(value) | ||
| # If the source needs to be overridden, use the new one. | ||
| source = self.overridden_sources.get(value, value) | ||
|
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. Need some comments explaining this. 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. Updated. |
||
| self.call_reconstruct(source) | ||
| self.clear_tos() | ||
| return | ||
|
|
||
|
|
@@ -130,27 +137,25 @@ def __call__(self, value, allow_cache=True): | |
|
|
||
| if self.mutable_side_effects_from_source: | ||
| # this is needed to get aliasing relationships right | ||
| # value.mutable_local.source will get mutated to hold `value` | ||
| # value.source will get mutated to hold `value` | ||
| # mutable_side_effects_from_source=False is used to codegen the mutation | ||
| # mutable_side_effects_from_source=True is used to codegen a reference | ||
| from .side_effects import MutableSideEffects | ||
|
|
||
| if isinstance(value.mutable_local, MutableSideEffects): | ||
| self(value.mutable_local.source) | ||
| self(value.source) | ||
| return | ||
|
|
||
| if allow_cache: | ||
| if value.mutable_local and value.mutable_local in self.tempvars: | ||
|
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 one feels like a separate change from this PR. Though perhaps it is ok because VariableTrackers are now mutable. 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. Yeah this is me trying to remove indexing on |
||
| output.append(self.create_load(self.tempvars[value.mutable_local])) | ||
| self.top_of_stack = value | ||
| return | ||
| if self.tempvars.get(value) is not None: | ||
| output.append(self.create_load(self.tempvars[value])) | ||
| self.top_of_stack = value | ||
| return | ||
|
|
||
| if value.source is not None and allow_cache and self.value_from_source: | ||
| self.call_reconstruct(value.source) | ||
| # If the source needs to be overridden, use the new one. | ||
| source = self.overridden_sources.get(value.source, value.source) | ||
| self.call_reconstruct(source) | ||
| elif value.is_python_constant() and is_safe_constant( | ||
| value.as_python_constant() | ||
| ): | ||
|
|
@@ -254,8 +259,6 @@ def load_graph_output(self, index): | |
| def add_cache(self, value): | ||
| var = self.new_var() | ||
| self.tempvars[value] = var | ||
| if value.mutable_local: | ||
| self.tempvars[value.mutable_local] = var | ||
| self._output.append(self.create_store(var)) | ||
|
|
||
| def foreach(self, items): | ||
|
|
||
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.
Add type annotations
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.
Updated.