forked from pytorch/pytorch
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move at::chunk into the graph fuser (pytorch#10178)
Summary: ... to avoid slow at::chunk (it is slow due to tensor initialization). Picking up from pytorch#10026 This is done through the following: 1) Absorb starting chunks into FusionGroup as a part of the graph fuser pass. 2) When compiling a kernel, emit a `std::vector<ConcatDesc>` that describes if an input (of the original graph) will be chunked. 3) When launching a kernel, `use std::vector<ConcatDesc>` to chunk an input tensor on the CPU. This chunk directly takes in an at::Tensor and creates four TensorInfo structs in-place in the argument list, bypassing the creation of intermediate Tensors. - Expect test and correctness test to see if a single chunk is fused by the graph fuser - Correctness test for a variety of chunks (dimension = beginning, middle, end) and tensors (contiguous, non-contiguous, edge case (splitSize = 1) for both CPU/CUDA - Expect test for multiple chunks fused into the same kernel and correctness test. cc zdevito apaszke LSTM forward pass, 1 layer, 512 hidden size and input size, 100 seq length, requires_grad=False on all inputs and weights. After changes: ``` thnn cudnn jit 8.8468 6.5797 9.3470 ``` Before changes: ``` thnn cudnn jit 9.9221 6.6539 11.2550 ``` Pull Request resolved: pytorch#10178 Differential Revision: D9382661 Pulled By: zou3519 fbshipit-source-id: 1f8a749208fbdd45559775ce98cf4eb9558448f8
- Loading branch information
1 parent
d87b4e9
commit f1420ad
Showing
12 changed files
with
517 additions
and
184 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,16 @@ | ||
graph(%0 : Float(4, 4) | ||
%1 : Float(4, 4)) { | ||
%2 : int = prim::Constant[value=1]() | ||
%3 : int = prim::Constant[value=2]() | ||
%4 : Float(4!, 2), %5 : Float(4!, 2) = aten::chunk(%0, %3, %2) | ||
%6 : Float(4!, 2), %7 : Float(4!, 2) = aten::chunk(%1, %3, %2) | ||
%8 : Float(4, 2) = prim::FusionGroup_0[device=0](%4, %6, %5, %7) | ||
return (%8); | ||
%2 : Float(4, 2) = prim::FusionGroup_0[device=0](%0, %1) | ||
return (%2); | ||
} | ||
with prim::FusionGroup_0 = graph(%3 : Float(4!, 2) | ||
%4 : Float(4!, 2) | ||
%7 : Float(4!, 2) | ||
%8 : Float(4!, 2)) { | ||
with prim::FusionGroup_0 = graph(%11 : Float(4, 4) | ||
%14 : Float(4, 4)) { | ||
%15 : Dynamic, %16 : Dynamic = prim::FusedChunk[chunks=2, dim=1](%14) | ||
%12 : Dynamic, %13 : Dynamic = prim::FusedChunk[chunks=2, dim=1](%11) | ||
%9 : int = prim::Constant[value=1]() | ||
%10 : Float(4, 2) = aten::add(%7, %8, %9) | ||
%10 : Float(4, 2) = aten::add(%13, %16, %9) | ||
%5 : int = prim::Constant[value=1]() | ||
%6 : Float(4, 2) = aten::add(%3, %4, %5) | ||
%6 : Float(4, 2) = aten::add(%12, %15, %5) | ||
%2 : Float(4, 2) = aten::mul(%6, %10) | ||
return (%2); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
graph(%x : Float(10, 6)) { | ||
%1 : Float(10, 2) = prim::FusionGroup_0[device=0](%x) | ||
return (%1); | ||
} | ||
with prim::FusionGroup_0 = graph(%7 : Float(10, 6)) { | ||
%8 : Dynamic, %9 : Dynamic, %10 : Dynamic = prim::FusedChunk[chunks=3, dim=1](%7) | ||
%6 : Float(10, 2) = aten::mul(%8, %9) | ||
%2 : int = prim::Constant[value=1]() | ||
%3 : Float(10, 2) = aten::add(%6, %10, %2) | ||
return (%3); | ||
} |
30 changes: 30 additions & 0 deletions
30
test/expect/TestScript.test_chunk_multiple_fusion_cuda.expect
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
graph(%s : Float(5, 2, 3) | ||
%x : Float(5, 6, 3) | ||
%y : Float(10, 2, 3) | ||
%z : Float(5, 2, 6)) { | ||
%4 : Float(5, 2, 3) = prim::FusionGroup_0[device=0](%s, %y, %x, %z) | ||
return (%4); | ||
} | ||
with prim::FusionGroup_0 = graph(%24 : Float(5, 2, 3) | ||
%28 : Float(10, 2, 3) | ||
%31 : Float(5, 6, 3) | ||
%35 : Float(5, 2, 6)) { | ||
%36 : Dynamic, %37 : Dynamic = prim::FusedChunk[chunks=2, dim=2](%35) | ||
%32 : Dynamic, %33 : Dynamic, %34 : Dynamic = prim::FusedChunk[chunks=3, dim=1](%31) | ||
%29 : Dynamic, %30 : Dynamic = prim::FusedChunk[chunks=2, dim=0](%28) | ||
%26 : int = prim::Constant[value=1]() | ||
%27 : Float(5, 2, 3) = aten::add(%24, %32, %26) | ||
%22 : int = prim::Constant[value=1]() | ||
%23 : Float(5, 2, 3) = aten::add(%27, %33, %22) | ||
%18 : int = prim::Constant[value=1]() | ||
%19 : Float(5, 2, 3) = aten::add(%23, %34, %18) | ||
%14 : int = prim::Constant[value=1]() | ||
%15 : Float(5, 2, 3) = aten::add(%19, %29, %14) | ||
%10 : int = prim::Constant[value=1]() | ||
%11 : Float(5, 2, 3) = aten::add(%15, %30, %10) | ||
%6 : int = prim::Constant[value=1]() | ||
%7 : Float(5, 2, 3) = aten::add(%11, %36, %6) | ||
%2 : int = prim::Constant[value=1]() | ||
%3 : Float(5, 2, 3) = aten::add(%7, %37, %2) | ||
return (%3); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.