Skip to content
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

AtenStackOp does not see tensors appended after list construction #3044

Open
renxida opened this issue Mar 21, 2024 · 0 comments
Open

AtenStackOp does not see tensors appended after list construction #3044

renxida opened this issue Mar 21, 2024 · 0 comments

Comments

@renxida
Copy link
Collaborator

renxida commented Mar 21, 2024

Found this issue while working on #2969

Using AtenStackOp on list constructed using ListConstruct with a ValueRange does NOT fail:

module {
  func.func @test_stack() -> !torch.vtensor<[3,2,3],f32> {
    %int0 = torch.constant.int 0
    %int2 = torch.constant.int 2
    %int3 = torch.constant.int 3
    %int6 = torch.constant.int 6
    %float0 = torch.constant.float 0.0
    %none = torch.constant.none
    %shape = torch.prim.ListConstruct %int2, %int3 : (!torch.int, !torch.int) -> !torch.list<int>

    %1 = torch.aten.full %shape, %float0, %int6, %none, %none, %none : !torch.list<int>, !torch.float, !torch.int, !torch.none, !torch.none, !torch.none -> !torch.vtensor<[2,3],f32>
    %2 = torch.aten.full %shape, %float0, %int6, %none, %none, %none : !torch.list<int>, !torch.float, !torch.int, !torch.none, !torch.none, !torch.none -> !torch.vtensor<[2,3],f32>
    %3 = torch.aten.full %shape, %float0, %int6, %none, %none, %none : !torch.list<int>, !torch.float, !torch.int, !torch.none, !torch.none, !torch.none -> !torch.vtensor<[2,3],f32>
    %4 = torch.prim.ListConstruct %1, %2, %3 : (!torch.vtensor<[2,3],f32>, !torch.vtensor<[2,3],f32>, !torch.vtensor<[2,3],f32>) -> !torch.list<vtensor<[2,3],f32>>
    %5 = torch.aten.stack %4, %int0 : !torch.list<vtensor<[2,3],f32>>, !torch.int -> !torch.vtensor<[3,2,3],f32>
    return %5 : !torch.vtensor<[3,2,3],f32>
  }
}

Minimal replicating example:

module {
  func.func @test_stack() -> !torch.vtensor<[3,2,3],f32> {
    %int0 = torch.constant.int 0
    %int2 = torch.constant.int 2
    %int3 = torch.constant.int 3
    %int6 = torch.constant.int 6
    %float0 = torch.constant.float 0.0
    %none = torch.constant.none
    %shape = torch.prim.ListConstruct %int2, %int3 : (!torch.int, !torch.int) -> !torch.list<int>

    %1 = torch.aten.full %shape, %float0, %int6, %none, %none, %none : !torch.list<int>, !torch.float, !torch.int, !torch.none, !torch.none, !torch.none -> !torch.vtensor<[2,3],f32>
    %2 = torch.aten.full %shape, %float0, %int6, %none, %none, %none : !torch.list<int>, !torch.float, !torch.int, !torch.none, !torch.none, !torch.none -> !torch.vtensor<[2,3],f32>
    %3 = torch.aten.full %shape, %float0, %int6, %none, %none, %none : !torch.list<int>, !torch.float, !torch.int, !torch.none, !torch.none, !torch.none -> !torch.vtensor<[2,3],f32>

    %list_of_tensors = torch.prim.ListConstruct  : () -> !torch.list<vtensor<[2,3],f32>>

    torch.aten.append.t %list_of_tensors, %1 : !torch.list<vtensor<[2,3],f32>>, !torch.vtensor<[2,3],f32> -> !torch.list<vtensor<[2,3],f32>>
    torch.aten.append.t %list_of_tensors, %2 : !torch.list<vtensor<[2,3],f32>>, !torch.vtensor<[2,3],f32> -> !torch.list<vtensor<[2,3],f32>>
    torch.aten.append.t %list_of_tensors, %3 : !torch.list<vtensor<[2,3],f32>>, !torch.vtensor<[2,3],f32> -> !torch.list<vtensor<[2,3],f32>>

    %5 = torch.aten.stack %list_of_tensors, %int0 : !torch.list<vtensor<[2,3],f32>>, !torch.int -> !torch.vtensor<[3,2,3],f32>
    return %5 : !torch.vtensor<[3,2,3],f32>
  }
}

Replicating example with loop:

module {
  func.func @test_stack() -> !torch.vtensor<[3,2,3],f32> {
    %int0 = torch.constant.int 0
    %int2 = torch.constant.int 2
    %int3 = torch.constant.int 3
    %int6 = torch.constant.int 6
    %float0 = torch.constant.float 0.0
    %none = torch.constant.none
    %shape = torch.prim.ListConstruct %int2, %int3 : (!torch.int, !torch.int) -> !torch.list<int>
    %true = torch.constant.bool true

    %list_of_tensors = torch.prim.ListConstruct  : () -> !torch.list<vtensor<[2,3],f32>>
    
    %loop_iters_max = torch.constant.int 3

    torch.prim.Loop %loop_iters_max, %true, init() {
      ^bb0(%iter_index: !torch.int):
      %tensor = torch.aten.full %shape, %float0, %int6, %none, %none, %none : !torch.list<int>, !torch.float, !torch.int, !torch.none, !torch.none, !torch.none -> !torch.vtensor<[2,3],f32>
      %discard_append_result = torch.aten.append.t %list_of_tensors, %tensor : !torch.list<vtensor<[2,3],f32>>, !torch.vtensor<[2,3],f32> -> !torch.list<vtensor<[2,3],f32>>
      %continue = torch.constant.bool true
      torch.prim.Loop.condition %true, iter()
    } : (!torch.int, !torch.bool) -> ()

    %5 = torch.aten.stack %list_of_tensors, %int0 : !torch.list<vtensor<[2,3],f32>>, !torch.int -> !torch.vtensor<[3,2,3],f32>
    return %5 : !torch.vtensor<[3,2,3],f32>
  }
}
@renxida renxida changed the title AtenStackOp on list of tensors constructed in for loop AtenStackOp does not see tensors appended after list construction Mar 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant