Skip to content

Conversation

@gmagogsfm
Copy link
Contributor

@gmagogsfm gmagogsfm commented Sep 8, 2020

Implements support for Python Slice class (not slice expression, which is already supported)

Slice object can be used in any place that supports slice expression, including multi-dim tensor slicing.

Fixes #43511
Fixes #43125

@dr-ci
Copy link

dr-ci bot commented Sep 8, 2020

💊 CI failures summary and remediations

As of commit dc08fe7 (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 86 times.

@facebook-github-bot facebook-github-bot added the oncall: jit Add this issue/PR to JIT oncall triage queue label Sep 8, 2020
@gmagogsfm gmagogsfm changed the title Enable slice None handling Support Python Slice class in TorchScript Sep 8, 2020
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note to reviewer:

I changed name of this argument from "begin" to "start" to match the schema of aten::slice. I think it worked before because this argument is always used as positional argument. Let me know if there are other things to consider.

@gmagogsfm gmagogsfm marked this pull request as ready for review September 10, 2020 02:10
@gmagogsfm gmagogsfm requested a review from apaszke as a code owner September 10, 2020 02:10
Copy link

@SplitInfinity SplitInfinity left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the motivation for this work? What can slice objects support that slice expressions do not already support?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider adding a comment like the one above which explains that this code handles slice objects.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe SliceValue because this is a regular SugaredValue?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is actually something I want to get advice on. It is a vanilla SugaredValue only because ir_emitter needs it and ir_emitter can't depend on python_sugared_value. In reality, PythonSliceValue does represent a python object, thus the python prefix. Let me know what you think.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, there is a ClassValue class that also extends SugaredValue that represents Python classes. So I think SliceValue would be better here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Copy link
Contributor Author

@gmagogsfm gmagogsfm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As for motivation, this is to fix #43511

The only one case where a slice object is better than slice expression, that is to share slice expression among different objects. Otherwise they are equivalent. So motivation is to fix the issue and enable one more language feature to save users some work-around time.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is actually something I want to get advice on. It is a vanilla SugaredValue only because ir_emitter needs it and ir_emitter can't depend on python_sugared_value. In reality, PythonSliceValue does represent a python object, thus the python prefix. Let me know what you think.

@codecov
Copy link

codecov bot commented Sep 11, 2020

Codecov Report

Merging #44335 into master will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##           master   #44335   +/-   ##
=======================================
  Coverage   68.04%   68.04%           
=======================================
  Files         384      384           
  Lines       49814    49814           
=======================================
  Hits        33897    33897           
  Misses      15917    15917           

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update a5cc151...dc08fe7. Read the comment docs.

Copy link
Contributor

@facebook-github-bot facebook-github-bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gmagogsfm has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

Copy link
Contributor

@facebook-github-bot facebook-github-bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gmagogsfm has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

Copy link
Contributor

@facebook-github-bot facebook-github-bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gmagogsfm has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

Copy link
Contributor

@facebook-github-bot facebook-github-bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gmagogsfm has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

Copy link

@SplitInfinity SplitInfinity left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did so few CI jobs run on this? Please try to get that extra signal before attempting to land this.

@gmagogsfm
Copy link
Contributor Author

Why did so few CI jobs run on this? Please try to get that extra signal before attempting to land this.

Because I rebased this morning to circumvent a Phabricator patch issue. You happened to open this PR when I just rebased, so CIs are just beginning.

Copy link
Contributor

@facebook-github-bot facebook-github-bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gmagogsfm has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

@facebook-github-bot
Copy link
Contributor

@gmagogsfm merged this pull request in 9909327.

xuzhao9 pushed a commit that referenced this pull request Sep 18, 2020
Summary:
Implements support for[ Python Slice class](https://docs.python.org/3/c-api/slice.html) (not slice expression, which is already supported)

Slice object can be used in any place that supports slice expression, including multi-dim tensor slicing.

Fixes #43511
Fixes #43125

Pull Request resolved: #44335

Reviewed By: suo, jamesr66a

Differential Revision: D23682213

Pulled By: gmagogsfm

fbshipit-source-id: f74fe25370e89fbfd2b3727d95ce4e1c4ba8dec4
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.

Non-conforming variable identifiers in JIT code errors / printouts: e.g. "Tensor 0" making slicing from torch.fx scriptable

4 participants