-
Notifications
You must be signed in to change notification settings - Fork 26.3k
[jit] Better match behavior of loaded ScriptModules vs. freshly created ones #43298
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
Conversation
…ed ones IR emitter uses `ModuleValue` to represent ScriptModules and emit IR for attribute access, submodule access, etc. `ModuleValue` relies on two pieces of information, the JIT type of the module, and the `ConcreteModuleType`, which encapsulates Python-only information about the module. ScriptModules loaded from a package used to create a dummy ConcreteModuleType without any info in it. This led to divergences in behavior during compilation. This PR makes the two ways of constructing a ConcreteModuleType equivalent, modulo any py-only information (which, by definition, is never present in packaged files anyway). [ghstack-poisoned]
💊 CI failures summary and remediationsAs of commit 42cf2bd (more details on the Dr. CI page):
ci.pytorch.org: 2 failed
This comment was automatically generated by Dr. CI (expand for details).Follow this link to opt-out of these comments for your Pull Requests.Please report bugs/suggestions on the GitHub issue tracker or post in the (internal) Dr. CI Users group. This comment has been revised 43 times. |
…eshly created ones" IR emitter uses `ModuleValue` to represent ScriptModules and emit IR for attribute access, submodule access, etc. `ModuleValue` relies on two pieces of information, the JIT type of the module, and the `ConcreteModuleType`, which encapsulates Python-only information about the module. ScriptModules loaded from a package used to create a dummy ConcreteModuleType without any info in it. This led to divergences in behavior during compilation. This PR makes the two ways of constructing a ConcreteModuleType equivalent, modulo any py-only information (which, by definition, is never present in packaged files anyway). [ghstack-poisoned]
…ed ones IR emitter uses `ModuleValue` to represent ScriptModules and emit IR for attribute access, submodule access, etc. `ModuleValue` relies on two pieces of information, the JIT type of the module, and the `ConcreteModuleType`, which encapsulates Python-only information about the module. ScriptModules loaded from a package used to create a dummy ConcreteModuleType without any info in it. This led to divergences in behavior during compilation. This PR makes the two ways of constructing a ConcreteModuleType equivalent, modulo any py-only information (which, by definition, is never present in packaged files anyway). ghstack-source-id: 5fb8f8a Pull Request resolved: #43298
…eshly created ones" IR emitter uses `ModuleValue` to represent ScriptModules and emit IR for attribute access, submodule access, etc. `ModuleValue` relies on two pieces of information, the JIT type of the module, and the `ConcreteModuleType`, which encapsulates Python-only information about the module. ScriptModules loaded from a package used to create a dummy ConcreteModuleType without any info in it. This led to divergences in behavior during compilation. This PR makes the two ways of constructing a ConcreteModuleType equivalent, modulo any py-only information (which, by definition, is never present in packaged files anyway). Differential Revision: [D23228738](https://our.internmc.facebook.com/intern/diff/D23228738) [ghstack-poisoned]
…ed ones IR emitter uses `ModuleValue` to represent ScriptModules and emit IR for attribute access, submodule access, etc. `ModuleValue` relies on two pieces of information, the JIT type of the module, and the `ConcreteModuleType`, which encapsulates Python-only information about the module. ScriptModules loaded from a package used to create a dummy ConcreteModuleType without any info in it. This led to divergences in behavior during compilation. This PR makes the two ways of constructing a ConcreteModuleType equivalent, modulo any py-only information (which, by definition, is never present in packaged files anyway). ghstack-source-id: 00997e5 Pull Request resolved: #43298
SplitInfinity
left a comment
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.
One additional question: do we need to do anything for function attributes? I see that they are part of the ConcreteModuleType, but not the JIT type.
| // Populate the builder metadata from the JIT type. This is to ensure | ||
| // ConcreteModuleTypes produced from Python and ones produced from a JIT | ||
| // type directly behave the same to the rest of the system. | ||
| for (size_t i = 0; i < classType->numAttributes(); i++) { |
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.
| for (size_t i = 0; i < classType->numAttributes(); i++) { | |
| for (size_t i = 0, e = classType->numAttributes(); i < e, i++) { |
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 think this makes the code a little less readable for no clear benefit, so I'm going to skip this one unless you feel strongly about it.
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 prefer my suggestion to avoid making an extra function call every time the loop exit condition is tested: https://llvm.org/docs/CodingStandards.html#don-t-evaluate-end-every-time-through-a-loop
But numAttributes() is not an expensive call, so I will not lose sleep over this.
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.
yes, I would expect a compiler to inline and then avoid recomputing numAttributes(). I think the suggestion makes more sense if we are computing the iterator of a complicated data structure instead of returning an int. Although if the data structure is that complicated, writing a raw for loop over its iterator is probably bad to begin with…
| } | ||
| } | ||
|
|
||
| for (size_t i = 0; i < classType->numConstants(); i++) { |
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.
| for (size_t i = 0; i < classType->numConstants(); i++) { | |
| for (size_t i = 0, e = classType->numConstants(); i < e, i++) { |
Anything that is not representable on the JIT type can't be captured here. This makes saving/loading a "lossy", since once you save/load all you have is a JIT type, and lose all the other Python-y bits like function attributes, module iterator kind, etc. The way to reduce this lossiness is by making more things representable first-class on the JIT type. |
…eshly created ones" IR emitter uses `ModuleValue` to represent ScriptModules and emit IR for attribute access, submodule access, etc. `ModuleValue` relies on two pieces of information, the JIT type of the module, and the `ConcreteModuleType`, which encapsulates Python-only information about the module. ScriptModules loaded from a package used to create a dummy ConcreteModuleType without any info in it. This led to divergences in behavior during compilation. This PR makes the two ways of constructing a ConcreteModuleType equivalent, modulo any py-only information (which, by definition, is never present in packaged files anyway). Differential Revision: [D23228738](https://our.internmc.facebook.com/intern/diff/D23228738) [ghstack-poisoned]
…ed ones IR emitter uses `ModuleValue` to represent ScriptModules and emit IR for attribute access, submodule access, etc. `ModuleValue` relies on two pieces of information, the JIT type of the module, and the `ConcreteModuleType`, which encapsulates Python-only information about the module. ScriptModules loaded from a package used to create a dummy ConcreteModuleType without any info in it. This led to divergences in behavior during compilation. This PR makes the two ways of constructing a ConcreteModuleType equivalent, modulo any py-only information (which, by definition, is never present in packaged files anyway). ghstack-source-id: 6baa83f Pull Request resolved: #43298
| // Populate the builder metadata from the JIT type. This is to ensure | ||
| // ConcreteModuleTypes produced from Python and ones produced from a JIT | ||
| // type directly behave the same to the rest of the system. | ||
| for (size_t i = 0; i < classType->numAttributes(); i++) { |
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 prefer my suggestion to avoid making an extra function call every time the loop exit condition is tested: https://llvm.org/docs/CodingStandards.html#don-t-evaluate-end-every-time-through-a-loop
But numAttributes() is not an expensive call, so I will not lose sleep over this.
…eshly created ones" IR emitter uses `ModuleValue` to represent ScriptModules and emit IR for attribute access, submodule access, etc. `ModuleValue` relies on two pieces of information, the JIT type of the module, and the `ConcreteModuleType`, which encapsulates Python-only information about the module. ScriptModules loaded from a package used to create a dummy ConcreteModuleType without any info in it. This led to divergences in behavior during compilation. This PR makes the two ways of constructing a ConcreteModuleType equivalent, modulo any py-only information (which, by definition, is never present in packaged files anyway). Differential Revision: [D23228738](https://our.internmc.facebook.com/intern/diff/D23228738) [ghstack-poisoned]
…ed ones IR emitter uses `ModuleValue` to represent ScriptModules and emit IR for attribute access, submodule access, etc. `ModuleValue` relies on two pieces of information, the JIT type of the module, and the `ConcreteModuleType`, which encapsulates Python-only information about the module. ScriptModules loaded from a package used to create a dummy ConcreteModuleType without any info in it. This led to divergences in behavior during compilation. This PR makes the two ways of constructing a ConcreteModuleType equivalent, modulo any py-only information (which, by definition, is never present in packaged files anyway). ghstack-source-id: 40135c8 Pull Request resolved: #43298
SplitInfinity
left a comment
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.
🥇
…eshly created ones" IR emitter uses `ModuleValue` to represent ScriptModules and emit IR for attribute access, submodule access, etc. `ModuleValue` relies on two pieces of information, the JIT type of the module, and the `ConcreteModuleType`, which encapsulates Python-only information about the module. ScriptModules loaded from a package used to create a dummy ConcreteModuleType without any info in it. This led to divergences in behavior during compilation. This PR makes the two ways of constructing a ConcreteModuleType equivalent, modulo any py-only information (which, by definition, is never present in packaged files anyway). Differential Revision: [D23228738](https://our.internmc.facebook.com/intern/diff/D23228738) [ghstack-poisoned]
…ed ones IR emitter uses `ModuleValue` to represent ScriptModules and emit IR for attribute access, submodule access, etc. `ModuleValue` relies on two pieces of information, the JIT type of the module, and the `ConcreteModuleType`, which encapsulates Python-only information about the module. ScriptModules loaded from a package used to create a dummy ConcreteModuleType without any info in it. This led to divergences in behavior during compilation. This PR makes the two ways of constructing a ConcreteModuleType equivalent, modulo any py-only information (which, by definition, is never present in packaged files anyway). ghstack-source-id: 6c20331 Pull Request resolved: #43298
…eshly created ones" IR emitter uses `ModuleValue` to represent ScriptModules and emit IR for attribute access, submodule access, etc. `ModuleValue` relies on two pieces of information, the JIT type of the module, and the `ConcreteModuleType`, which encapsulates Python-only information about the module. ScriptModules loaded from a package used to create a dummy ConcreteModuleType without any info in it. This led to divergences in behavior during compilation. This PR makes the two ways of constructing a ConcreteModuleType equivalent, modulo any py-only information (which, by definition, is never present in packaged files anyway). Differential Revision: [D23228738](https://our.internmc.facebook.com/intern/diff/D23228738) [ghstack-poisoned]
…ed ones IR emitter uses `ModuleValue` to represent ScriptModules and emit IR for attribute access, submodule access, etc. `ModuleValue` relies on two pieces of information, the JIT type of the module, and the `ConcreteModuleType`, which encapsulates Python-only information about the module. ScriptModules loaded from a package used to create a dummy ConcreteModuleType without any info in it. This led to divergences in behavior during compilation. This PR makes the two ways of constructing a ConcreteModuleType equivalent, modulo any py-only information (which, by definition, is never present in packaged files anyway). ghstack-source-id: e0c6e82 Pull Request resolved: #43298
…eshly created ones" IR emitter uses `ModuleValue` to represent ScriptModules and emit IR for attribute access, submodule access, etc. `ModuleValue` relies on two pieces of information, the JIT type of the module, and the `ConcreteModuleType`, which encapsulates Python-only information about the module. ScriptModules loaded from a package used to create a dummy ConcreteModuleType without any info in it. This led to divergences in behavior during compilation. This PR makes the two ways of constructing a ConcreteModuleType equivalent, modulo any py-only information (which, by definition, is never present in packaged files anyway). Differential Revision: [D23228738](https://our.internmc.facebook.com/intern/diff/D23228738) [ghstack-poisoned]
…ed ones IR emitter uses `ModuleValue` to represent ScriptModules and emit IR for attribute access, submodule access, etc. `ModuleValue` relies on two pieces of information, the JIT type of the module, and the `ConcreteModuleType`, which encapsulates Python-only information about the module. ScriptModules loaded from a package used to create a dummy ConcreteModuleType without any info in it. This led to divergences in behavior during compilation. This PR makes the two ways of constructing a ConcreteModuleType equivalent, modulo any py-only information (which, by definition, is never present in packaged files anyway). ghstack-source-id: 9caee09 Pull Request resolved: #43298
Codecov Report
@@ Coverage Diff @@
## gh/suo/345/base #43298 +/- ##
================================================
Coverage 69.27% 69.27%
================================================
Files 381 381
Lines 47265 47265
================================================
+ Hits 32744 32745 +1
+ Misses 14521 14520 -1
Continue to review full report at Codecov.
|
Stack from ghstack:
IR emitter uses
ModuleValueto represent ScriptModules and emit IR forattribute access, submodule access, etc.
ModuleValuerelies on two pieces of information, the JIT type of themodule, and the
ConcreteModuleType, which encapsulates Python-onlyinformation about the module.
ScriptModules loaded from a package used to create a dummy
ConcreteModuleType without any info in it. This led to divergences in
behavior during compilation.
This PR makes the two ways of constructing a ConcreteModuleType equivalent,
modulo any py-only information (which, by definition, is never present in
packaged files anyway).
Differential Revision: D23228738