Repository navigation
[Compile] Fix capture outputs during compile
#44614
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
Changes from 1 commit
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 |
|---|---|---|
|
|
@@ -64,35 +64,32 @@ class CompileableContextVar: | |
| """ | ||
|
|
||
| def __init__(self, name, default): | ||
| self.context_var = ContextVar(name, default=default) | ||
| self.global_var = default | ||
| self.compiling = False | ||
| self.context_var = ContextVar(name, default=default) # real thread-safe, local var | ||
| self.global_var = default # mirror for compile, global var | ||
| self.default = default | ||
|
|
||
| def get(self): | ||
| # Set was called before and compilation was already detected | ||
| if self.compiling: | ||
| # Always check the current dynamo state dynamically! See the note below | ||
| # | ||
| # NOTE: Local attributes/flags may be interpreted once during tracing | ||
| # and effectively treated as constant across compiled frames. If we | ||
| # cached such a flag, eager frames could incorrectly fall back to the | ||
| # shared global value, breaking visibility between eager wrappers and | ||
| # compiled hooks | ||
| if is_torchdynamo_compiling(): | ||
| return self.global_var | ||
| else: | ||
| # Set was maybe never called, so still check it here | ||
| if is_torchdynamo_compiling(): | ||
| self.is_compiling = True | ||
|
Collaborator
Author
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. Side note: This was even a typo 👀 self.compiling <-> self.is_compiling |
||
| return self.global_var | ||
| else: | ||
| return self.context_var.get() | ||
| return self.context_var.get() | ||
|
|
||
| def set(self, value): | ||
| self.global_var = value | ||
| # Same, check the current state dynamically rather than relying on cached attributes | ||
|
Member
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. Why do we always set the global here? Let's only do when it's compiling!
Collaborator
Author
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 is essentially the core change, it seems somewhere along the way, some small graph break happens and when we do not set it in general the state between compiled regions and non-compiled eager regions is messed up
Member
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 is concerning, it means some modules are fully skipped by dynamo and not compiled?? |
||
| if is_torchdynamo_compiling(): | ||
| self.global_var = value | ||
| self.compiling = True | ||
| return None | ||
| else: | ||
| return self.context_var.set(value) | ||
| return self.context_var.set(value) | ||
|
|
||
| def reset(self, token): | ||
| if self.compiling or token is None: | ||
| self.global_var = None | ||
| self.compiling = False | ||
| else: | ||
| self.global_var = self.default | ||
|
Member
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. Let's just reset to None alway no? Instead of saving the default as internal attr
Collaborator
Author
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. I don't mind, but why do we even provide a default in the init at all 😅
Member
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. Only because
Collaborator
Author
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. Yea changed the init, and forced none in any case |
||
| if token is not None: | ||
| self.context_var.reset(token) | ||
|
|
||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
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.
I don't really understand this comment (the final part), so not helpful IMO haha - let's either entirely remove or rewrite!
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.
Will update in a second