-
Notifications
You must be signed in to change notification settings - Fork 14
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
Reshape only in row major layout #687
Conversation
TTNN supports two kinds of reshapes - row and tile. row reshape works as expected as long as we don't change last dim. On the other hand tile reshape requires that output `W` and `H` dims are tile aligned. For example this `reshape` in tile layout will fail: 1*12*32 -> 12*32 Error that we get is `Unable to reshape a tensor in TILE_LAYOUT to non-tile height and width! Please convert the tensor to ROW_MAJOR_LAYOUT first.` In addition when we managed to do a `reshape` on tile tensor we found that output tensor did not look the way we expected it to look. For example: If we have input row major tensor 4x4 which contains numbers from 0 .. 15 and we reshape it to 2x8 we will get [[0,1 .. 6,7], [8,9 .. 14,15]]. The output is correct. If we take the same input tensor and convert it to tile layout and call reshape to Shape((2, 8), (32, 32)) and convert output tensor to row_major we will get tensor which looks like this: [[0,1,2,3,0,0,0,0],[4,5,6,7,0,0,0,0]].This is different then row major reshape. In order to unblock forge for `reshape` op we will convert all input tensors to row before calling reshape, and then we will convert output tensor back to original layout. Once we have understanding how reshape works for tile we will remove this and implement proper fix.
%1 = "ttir.reshape"(%arg0, %0) <{shape = [4: i32, 32: i32, 2: i32, 32: i32] , operand_constraints = [#any_device_tile, #any_device_tile]}> : (tensor<4x2x32x32xbf16>, tensor<4x32x2x32xbf16>) -> tensor<4x32x2x32xbf16> | ||
return %1 : tensor<4x32x2x32xbf16> | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should these 2 tests belong in Silicon subdir? Otherwise they will not be exercising the runtime in CI
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If thats the case we will have to move bunch of tests from dialect dir to silicon, since we are not testing bunch of ops.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the case :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay :)
This reverts commit 8152560.
* Convert to `row_major` layout before calling `reshape` TTNN supports two kinds of reshapes - row and tile. row reshape works as expected as long as we don't change last dim. On the other hand tile reshape requires that output `W` and `H` dims are tile aligned. For example this `reshape` in tile layout will fail: 1*12*32 -> 12*32 Error that we get is `Unable to reshape a tensor in TILE_LAYOUT to non-tile height and width! Please convert the tensor to ROW_MAJOR_LAYOUT first.` In addition when we managed to do a `reshape` on tile tensor we found that output tensor did not look the way we expected it to look. For example: If we have input row major tensor 4x4 which contains numbers from 0 .. 15 and we reshape it to 2x8 we will get [[0,1 .. 6,7], [8,9 .. 14,15]]. The output is correct. If we take the same input tensor and convert it to tile layout and call reshape to Shape((2, 8), (32, 32)) and convert output tensor to row_major we will get tensor which looks like this: [[0,1,2,3,0,0,0,0],[4,5,6,7,0,0,0,0]].This is different then row major reshape. In order to unblock forge for `reshape` op we will convert all input tensors to row before calling reshape, and then we will convert output tensor back to original layout. Once we have understanding how reshape works for tile we will remove this and implement proper fix. * Adding comment * Moving test to Silicon. Adding negative test for dialect.
Reshape doesn't work for most output shapes in tile layout. As temporary workaround (until we figure out how to do a reshape in tile properly) and to unblock forge we will convert all input tensors to row before calling reshape, and then we will convert output tensor back to original layout.
#686