Skip to content

[JIT][Reland] add list() support#42382

Closed
eellison wants to merge 5 commits intopytorch:masterfrom
eellison:ci-all/list_comp
Closed

[JIT][Reland] add list() support#42382
eellison wants to merge 5 commits intopytorch:masterfrom
eellison:ci-all/list_comp

Conversation

@eellison
Copy link
Copy Markdown
Contributor

@eellison eellison commented Jul 31, 2020

Fixes #40869

Resubmit of #33818.

Adds support for list() by desugaring it to a list comprehension.

Last time I landed this it made one of the tests slow, and got unlanded. I think that's bc the previous PR changed the emission of list() on a list input or a str input to a list comprehension, which is the more general way of emitting list(), but also a little bit slower. I updated this version to emit to the builtin operators for these two case. Hopefully it can land without being reverted this time...

@eellison eellison requested a review from apaszke as a code owner July 31, 2020 19:45
@facebook-github-bot facebook-github-bot added the oncall: jit Add this issue/PR to JIT oncall triage queue label Jul 31, 2020
@dr-ci
Copy link
Copy Markdown

dr-ci Bot commented Jul 31, 2020

💊 CI failures summary and remediations

As of commit 213fcc5 (more details on the Dr. CI page):


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

Extra GitHub checks: 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 17 times.

@eellison eellison requested review from SplitInfinity, ansley and gmagogsfm and removed request for SplitInfinity, ansley and gmagogsfm November 4, 2020 23:16
}
case prim::list: {
if (apply.inputs().size() == 0) {
TypePtr type = type_hint ? type_hint : ListType::ofTensors();
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

ListTypePtr ListType::ofTensors() {
  static auto value = ListType::create(TensorType::get());
  return value;
}

Maybe ListType::create(TensorType::getInferred()) should be used (or a function that returns this) in this case since the type is being inferred.

Copy link
Copy Markdown
Contributor Author

@eellison eellison Nov 5, 2020

Choose a reason for hiding this comment

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

Agreed this would be nice, but imo it's a little awkward to have List[Inferred Tensor]. We're inferring the list itself. We do this other places like x = [] or x = {}, and would be nice to add as a follow up, but we dont have any inferred types on non-Tensor rn.


def test_list_keyword(self):
def foo():
return list([1, 2, 3]), list(("a", "b")), list(range(5)), list("abcdefg") # noqa: C410
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

For my own curiosity, how does the type for this expression get set correctly in the absence of an explicit annotation? The IR generation code that was added in this PR for list uses a given type_hint and assume List[Tensor] if there is none:

TypePtr type = type_hint ? type_hint : ListType::ofTensors();

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

It's inferred from the input iterable when we emit the list comprehension

}
}
const std::string& iter_name = createTempName("$_iter");
environment_stack->setSugaredVar(
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Should this be removed from the environment stack after emitting the list comprehension?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

It's not really necessary, createTempName creates a unique identifier which won't ever be used again, and $_iter is not user-valid variable name. In the other instances of createTempName we do not subsequently remove the temporary variable binding

Copy link
Copy Markdown
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.

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

@codecov
Copy link
Copy Markdown

codecov Bot commented Nov 6, 2020

Codecov Report

Merging #42382 into master will increase coverage by 0.20%.
The diff coverage is 88.46%.

@@            Coverage Diff             @@
##           master   #42382      +/-   ##
==========================================
+ Coverage   81.26%   81.46%   +0.20%     
==========================================
  Files        1792     1792              
  Lines      186194   186216      +22     
==========================================
+ Hits       151303   151695     +392     
+ Misses      34891    34521     -370     

@facebook-github-bot
Copy link
Copy Markdown
Contributor

@eellison merged this pull request in f3ad7b2.

laurentdupin pushed a commit to laurentdupin/pytorch that referenced this pull request Apr 24, 2026
Summary:
Fixes pytorch#40869

Resubmit of pytorch#33818.

Adds support for `list()` by desugaring  it to a list comprehension.

Last time I landed this it made one of the tests slow, and got unlanded. I think that's bc the previous PR changed the emission of `list()` on a list input or a str input to a list comprehension, which is the more general way of emitting `list()`, but also a little bit slower. I updated this version to emit to the builtin operators for these two case. Hopefully it can land without being reverted this time...

Pull Request resolved: pytorch#42382

Reviewed By: navahgar

Differential Revision: D24767674

Pulled By: eellison

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

Labels

cla signed 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.

[JIT] list() builtin doesn't work on tensors

3 participants