Skip to content

[JIT] Exclude staticmethods from TS class compilation#42611

Closed
SplitInfinity wants to merge 4 commits intogh/splitinfinity/31/basefrom
gh/splitinfinity/31/head
Closed

[JIT] Exclude staticmethods from TS class compilation#42611
SplitInfinity wants to merge 4 commits intogh/splitinfinity/31/basefrom
gh/splitinfinity/31/head

Conversation

@SplitInfinity
Copy link
Copy Markdown

@SplitInfinity SplitInfinity commented Aug 5, 2020

Stack from ghstack:

Summary
This commit modifies the Python frontend to ignore static functions on
Torchscript classes when compiling them. They are currently included
along with methods, which causes the first argument of the
staticfunction to be unconditionally inferred to be of the type of the
class it belongs to (regardless of how it is annotated or whether it is
annotated at all). This can lead to compilation errors depending on
how that argument is used in the body of the function.

Static functions are instead imported and scripted as if they were
standalone functions.

Test Plan
This commit augments the unit test for static methods in test_class_types.py
to test that static functions can call each other and the class
constructor.

Fixes
This commit fixes #39308.

Differential Revision: D22958163

**Summary**
This commit adds JIT support for static methods of TorchScript class
types. This is a feature request from Detectron2 for scripting that
library.

**Test Plan**
This commit adds a unit test to `test_class_types.py` that tests
static methods of TorchScript classes.

[ghstack-poisoned]
@SplitInfinity SplitInfinity requested a review from apaszke as a code owner August 5, 2020 18:23
SplitInfinity pushed a commit that referenced this pull request Aug 5, 2020
**Summary**
This commit adds JIT support for static methods of TorchScript class
types. This is a feature request from Detectron2 for scripting that
library.

**Test Plan**
This commit adds a unit test to `test_class_types.py` that tests
static methods of TorchScript classes.

ghstack-source-id: 46c1a07
Pull Request resolved: #42611
@facebook-github-bot facebook-github-bot added the oncall: jit Add this issue/PR to JIT oncall triage queue label Aug 5, 2020
@SplitInfinity
Copy link
Copy Markdown
Author

cc: @ppwwyyxx

@dr-ci
Copy link
Copy Markdown

dr-ci Bot commented Aug 5, 2020

💊 CI failures summary and remediations

As of commit 22214f1 (more details on the Dr. CI page):


  • 1/1 failures possibly* introduced in this PR
    • 1/1 non-CircleCI failure(s)

ci.pytorch.org: 1 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.

See how this bot performed.

This comment has been revised 15 times.

@SplitInfinity SplitInfinity changed the title [JIT] Add support for static methods of class types [JIT] Exclude staticmethods from TS class compilation Aug 5, 2020
**Summary**
This commit modifies the Python frontend to ignore static functions on
Torchscript classes when compiling them. They are currently included
along with methods, which causes the first argument of the
staticfunction to be unconditionally inferred to be of the type of the
class it belongs to, which can lead to compilation errors depending on
how that argument is used in the body of the function.

Static functions are instead imported and scripted as if they were
standalone functions.

**Test Plan**
This commit augments the unit test for static methods in `test_class_types.py`
to test that static functions can call each other and the class
constructor.

**Fixes**
This commit fixes #39308.

[ghstack-poisoned]
SplitInfinity pushed a commit that referenced this pull request Aug 5, 2020
**Summary**
This commit modifies the Python frontend to ignore static functions on
Torchscript classes when compiling them. They are currently included
along with methods, which causes the first argument of the
staticfunction to be unconditionally inferred to be of the type of the
class it belongs to, which can lead to compilation errors depending on
how that argument is used in the body of the function.

Static functions are instead imported and scripted as if they were
standalone functions.

**Test Plan**
This commit augments the unit test for static methods in `test_class_types.py`
to test that static functions can call each other and the class
constructor.

**Fixes**
This commit fixes #39308.

ghstack-source-id: 90786b6
Pull Request resolved: #42611
**Summary**
This commit modifies the Python frontend to ignore static functions on
Torchscript classes when compiling them. They are currently included
along with methods, which causes the first argument of the
staticfunction to be unconditionally inferred to be of the type of the
class it belongs to (regardless of how it is annotated or whether it is
annotated at all). This can lead to compilation errors depending on
how that argument is used in the body of the function.

Static functions are instead imported and scripted as if they were
standalone functions.

**Test Plan**
This commit augments the unit test for static methods in `test_class_types.py`
to test that static functions can call each other and the class
constructor.

**Fixes**
This commit fixes #39308.

Differential Revision: [D22958163](https://our.internmc.facebook.com/intern/diff/D22958163)

[ghstack-poisoned]
SplitInfinity pushed a commit that referenced this pull request Aug 6, 2020
**Summary**
This commit modifies the Python frontend to ignore static functions on
Torchscript classes when compiling them. They are currently included
along with methods, which causes the first argument of the
staticfunction to be unconditionally inferred to be of the type of the
class it belongs to, which can lead to compilation errors depending on
how that argument is used in the body of the function.

Static functions are instead imported and scripted as if they were
standalone functions.

**Test Plan**
This commit augments the unit test for static methods in `test_class_types.py`
to test that static functions can call each other and the class
constructor.

**Fixes**
This commit fixes #39308.

ghstack-source-id: 7ec855c
Pull Request resolved: #42611
**Summary**
This commit modifies the Python frontend to ignore static functions on
Torchscript classes when compiling them. They are currently included
along with methods, which causes the first argument of the
staticfunction to be unconditionally inferred to be of the type of the
class it belongs to (regardless of how it is annotated or whether it is
annotated at all). This can lead to compilation errors depending on
how that argument is used in the body of the function.

Static functions are instead imported and scripted as if they were
standalone functions.

**Test Plan**
This commit augments the unit test for static methods in `test_class_types.py`
to test that static functions can call each other and the class
constructor.

**Fixes**
This commit fixes #39308.

Differential Revision: [D22958163](https://our.internmc.facebook.com/intern/diff/D22958163)

[ghstack-poisoned]
SplitInfinity pushed a commit that referenced this pull request Aug 6, 2020
**Summary**
This commit modifies the Python frontend to ignore static functions on
Torchscript classes when compiling them. They are currently included
along with methods, which causes the first argument of the
staticfunction to be unconditionally inferred to be of the type of the
class it belongs to, which can lead to compilation errors depending on
how that argument is used in the body of the function.

Static functions are instead imported and scripted as if they were
standalone functions.

**Test Plan**
This commit augments the unit test for static methods in `test_class_types.py`
to test that static functions can call each other and the class
constructor.

**Fixes**
This commit fixes #39308.

ghstack-source-id: 8290cdf
Pull Request resolved: #42611
@facebook-github-bot
Copy link
Copy Markdown
Contributor

@SplitInfinity merged this pull request in eba3502.

@facebook-github-bot facebook-github-bot deleted the gh/splitinfinity/31/head branch August 11, 2020 14:16
laurentdupin pushed a commit to laurentdupin/pytorch that referenced this pull request Apr 24, 2026
Summary:
Pull Request resolved: pytorch#42611

**Summary**
This commit modifies the Python frontend to ignore static functions on
Torchscript classes when compiling them. They are currently included
along with methods, which causes the first argument of the
staticfunction to be unconditionally inferred to be of the type of the
class it belongs to (regardless of how it is annotated or whether it is
annotated at all). This can lead to compilation errors depending on
how that argument is used in the body of the function.

Static functions are instead imported and scripted as if they were
standalone functions.

**Test Plan**
This commit augments the unit test for static methods in `test_class_types.py`
to test that static functions can call each other and the class
constructor.

**Fixes**
This commit fixes pytorch#39308.

Test Plan: Imported from OSS

Reviewed By: ZolotukhinM

Differential Revision: D22958163

Pulled By: SplitInfinity

fbshipit-source-id: 45c3c372792299e6e5288e1dbb727291e977a2af
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Merged oncall: jit Add this issue/PR to JIT oncall triage queue

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants