-
Notifications
You must be signed in to change notification settings - Fork 25.6k
[JIT] Add mutability checks in FunctionSchema and create SchemaInfo subclass #80734
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
…ubclass [ghstack-poisoned]
🔗 Helpful links
✅ No Failures (0 Pending)As of commit 6033932 (more details on the Dr. CI page): Expand to see more💚 💚 Looks good so far! There are no failures yet. 💚 💚 This comment was automatically generated by Dr. CI (expand for details).Please report bugs/suggestions to the (internal) Dr. CI Users group. |
…chemaInfo subclass" [ghstack-poisoned]
…chemaInfo subclass" [ghstack-poisoned]
@goldenxuett has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator. |
…chemaInfo subclass" - Added overloads to is_mutable method in FunctionSchema to tell whether an argument at index is mutable or an argument with name is mutable. - Created SchemaInfo subclass of FunctionSchema with constructors from FunctionSchema and from const char* signature. - Tested is_mutable method overloads in new test_schema_info.cpp file. **Note that this pr is used to set up SchemaInfo. Implementation for SchemaInfo will be addressed in later commits** Differential Revision: [D37651384](https://our.internmc.facebook.com/intern/diff/D37651384) [ghstack-poisoned]
@goldenxuett has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator. |
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.
LGTM!
test/cpp/jit/test_schema_info.cpp
Outdated
|
||
namespace torch { | ||
namespace utils { | ||
namespace { |
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.
very minor nit / my personal preference: I think this doesn't need to be in an anonymous namespace. AFAIK we typically put utility functions and functions that are only used within a given cpp file into an anonymous namespace, but tests are sort of user-facing (and also most of the other jit test files don't put the tests in anonymous namespaces)
…chemaInfo subclass" - Added overloads to is_mutable method in FunctionSchema to tell whether an argument at index is mutable or an argument with name is mutable. - Created SchemaInfo subclass of FunctionSchema with constructors from FunctionSchema and from const char* signature. - Tested is_mutable method overloads in new test_schema_info.cpp file. **Note that this pr is used to set up SchemaInfo. Implementation for SchemaInfo will be addressed in later commits** Differential Revision: [D37651384](https://our.internmc.facebook.com/intern/diff/D37651384) [ghstack-poisoned]
…chemaInfo subclass" - Added overloads to is_mutable method in FunctionSchema to tell whether an argument at index is mutable or an argument with name is mutable. - Created SchemaInfo subclass of FunctionSchema with constructors from FunctionSchema and from const char* signature. - Tested is_mutable method overloads in new test_schema_info.cpp file. **Note that this pr is used to set up SchemaInfo. Implementation for SchemaInfo will be addressed in later commits** Differential Revision: [D37651384](https://our.internmc.facebook.com/intern/diff/D37651384) [ghstack-poisoned]
@goldenxuett has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator. |
* Subclass of FunctionSchema that publicizes argument value specific operator | ||
* behavior (mutation, aliasing, special cases, etc...) | ||
*/ | ||
|
||
struct TORCH_API SchemaInfo : c10::FunctionSchema { | ||
public: | ||
explicit SchemaInfo(c10::FunctionSchema schema) : FunctionSchema(schema) {} | ||
explicit SchemaInfo(const char* signature) | ||
: FunctionSchema(torch::jit::getOperatorForLiteral(signature)->schema()) { | ||
} | ||
}; |
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.
@davidberard98 Should we be concerned about performance impacts from virtualizing FunctionSchema? FunctionSchema is used in Core.
A way to avoid this is by using composition instead of inheritance.
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.
Are any methods on FunctionSchema
actually getting virtualized in this PR? It looks like SchemaInfo inherits from
FunctionSchema` (but without virtualizing any methods). I think that should be fine.
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.
@bdhirsh but in future PRs there would presumably be some virtualized methods (i.e. is_mutable, which on FunctionSchema will return static results but on SchemaInfo will return data-dependent results)
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.
@bdhirsh Look at https://github.com/pytorch/pytorch/pull/80972/files for functions in SchemaInfo
that we would be virtualizing. (They are currently not marked as virtual, but I expect that we would need them to be virtual
in order for things to work as intended).
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.
Ah ok, in agreement with John then on composition over inheritance. FunctionSchema
is probably hot-path enough that we want to avoid virtualizing some of its common methods.
…chemaInfo subclass" - Added overloads to is_mutable method in FunctionSchema to tell whether an argument at index is mutable or an argument with name is mutable. - Created SchemaInfo subclass of FunctionSchema with constructors from FunctionSchema and from const char* signature. - Tested is_mutable method overloads in new test_schema_info.cpp file. **Note that this pr is used to set up SchemaInfo. Implementation for SchemaInfo will be addressed in later commits** Differential Revision: [D37651384](https://our.internmc.facebook.com/intern/diff/D37651384) [ghstack-poisoned]
@goldenxuett has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator. |
…chemaInfo subclass" - Added overloads to is_mutable method in FunctionSchema to tell whether an argument at index is mutable or an argument with name is mutable. - Created SchemaInfo subclass of FunctionSchema with constructors from FunctionSchema and from const char* signature. - Tested is_mutable method overloads in new test_schema_info.cpp file. **Note that this pr is used to set up SchemaInfo. Implementation for SchemaInfo will be addressed in later commits** Differential Revision: [D37651384](https://our.internmc.facebook.com/intern/diff/D37651384) [ghstack-poisoned]
@goldenxuett has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator. |
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.
looks good!
@pytorchbot merge (Initiating merge automatically since Phabricator Diff has merged) |
@pytorchbot successfully started a merge job. Check the current status here |
Hey @goldenxuett. |
…ubclass (#80734) Summary: Pull Request resolved: #80734 - Added overloads to is_mutable method in FunctionSchema to tell whether an argument at index is mutable or an argument with name is mutable. - Created SchemaInfo subclass of FunctionSchema with constructors from FunctionSchema and from const char* signature. - Tested is_mutable method overloads in new test_schema_info.cpp file. **Note that this pr is used to set up SchemaInfo. Implementation for SchemaInfo will be addressed in later commits** Test Plan: Imported from OSS Reviewed By: davidberard98 Differential Revision: D37651384 Pulled By: goldenxuett fbshipit-source-id: 5e3f618758590ad518cfbd14f0ab50f010049e09
Stack from ghstack (oldest at bottom):
Note that this pr is used to set up SchemaInfo. Implementation for SchemaInfo will be addressed in later commits
Differential Revision: D37651384