Skip to content

[jit][script] Make empty list literals construct empty Tensor[]#10705

Closed
suo wants to merge 4 commits intomasterfrom
suo/tensor_empty
Closed

[jit][script] Make empty list literals construct empty Tensor[]#10705
suo wants to merge 4 commits intomasterfrom
suo/tensor_empty

Conversation

@suo
Copy link
Member

@suo suo commented Aug 20, 2018

This will make the common case more natural (no need to do _construct_empty_tensor_list())

@suo suo added the oncall: jit Add this issue/PR to JIT oncall triage queue label Aug 20, 2018
@suo
Copy link
Member Author

suo commented Aug 20, 2018

I'm concerned that the error msg is confusing:

variable 'x' previously has type Tensor[] but is now being assigned to a value of type int[]:
def reassign_from_empty_literal():
    x = []
    if True:
        x = [1, 2, 3]
        ~ <--- HERE
    return

Should I add special casing for reporting this error? (e.g. if we're trying to assign to a tensor list and get a type error, mention that empty lists are constructed as tensor lists).

Copy link
Contributor

@zdevito zdevito left a comment

Choose a reason for hiding this comment

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

Looks good. Custom error is useful until we get this working better.

throw ErrorReport(tree) << "Empty list literals not allowed. "
<< "Use _construct_empty_foo_list() instead. "
<< "`foo` can be `int`, `float` or `tensor`";
// If this is an empty list literal `[]`, construct an empty Tensor[]

This comment was marked as off-topic.

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.

michaelsuo is landing this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

petrex pushed a commit to petrex/pytorch that referenced this pull request Aug 21, 2018
* upstream/master: (147 commits)
  Support Loading to GPU (pytorch#10710)
  More changes for hidden visibility (pytorch#10692)
  Add arguments __repr__ in Distribution base class
  Add util function from core type to dtype (pytorch#10716)
  Make ONNX_ATEN_FALLBACK as internal default option
  Set the BUILD_ENVIRONMENT variable before installing sccache. (pytorch#10640)
  Avoid shadowing i, j vars in GeneralProposals test (pytorch#10721)
  Move THNN Reduction to ATen/core. (pytorch#10703)
  Completely remove build_aten and use_aten (pytorch#10469)
  Make empty list literals construct empty Tensor[] (pytorch#10705)
  Soumith's last few patches to v0.4.1
  Fix issues link in Caffe2 readme (pytorch#10711)
  Update the onnx Gemm op to FC/FCTransposed logic in caffe2 onnx backend (pytorch#10108)
  Adding ATEN_NO_TEST option to root level cmake for propogation to aten
  Allow method-style casts on tensors (pytorch#10641)
  Fix pytorch#10698 build failure (pytorch#10704)
  Add support for Log()
  Add a bisect percentile operator (pytorch#10563)
  Fix EnsureCPUOutputOp (pytorch#10651)
  Nomnigraph - rename some APIs that invole Subtree to Subgraph (pytorch#10551)
  ...
as_simple_value->type()->kind() == TypeKind::ListType) {
errMsg << "\n. (Note: empty lists are constructed as Tensor[]; "
<< "if you want an empty list of a different type, "
<< "use `_construct_empty_foo_list`, "

This comment was marked as off-topic.

PenghuiCheng pushed a commit to PenghuiCheng/pytorch that referenced this pull request Sep 11, 2018
Summary:
This will make the common case more natural (no need to do `_construct_empty_tensor_list()`)
Pull Request resolved: pytorch#10705

Differential Revision: D9411622

Pulled By: michaelsuo

fbshipit-source-id: 2d91fbc5787426748d6e1c8e7bbeee737544dc96
@soumith soumith deleted the suo/tensor_empty branch September 27, 2018 03:35
@ezyang ezyang added the merged label Jun 26, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants