-
Notifications
You must be signed in to change notification settings - Fork 90
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
Add support for unpadded shapes in Matmul1D w/ gather_in0 #16627
base: main
Are you sure you want to change the base?
Conversation
@@ -32,7 +32,7 @@ void DramPrefetcher::validate(const std::vector<Tensor>& input_tensors) const { | |||
|
|||
// Check that all tensors' k is divisible by number of cores in global CB receiver | |||
TT_FATAL( | |||
tensor.get_legacy_shape()[1] % num_receiver_cores == 0, | |||
tensor.get_legacy_shape()[0] % num_receiver_cores == 0, |
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.
why is it changed from 1 to 0 (from K to M)?
@@ -1357,11 +1357,6 @@ void Matmul::validate( | |||
TT_FATAL( | |||
(input_tensor_a.get_layout() == Layout::TILE && input_tensor_b.get_layout() == Layout::TILE), | |||
"Inputs to matmul must be tilized"); | |||
TT_FATAL( |
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.
I assume this is a redundant check and there's other places that check for a_shape[-1] == b_shape[-2] ?
@@ -447,7 +456,7 @@ def test_multi_core_matmul_1d_wh( | |||
"num_iters", | |||
[1, 3], | |||
) | |||
@pytest.mark.parametrize("device_params", [{"dispatch_core_axis": ttnn.DispatchCoreAxis.COL}], indirect=True) | |||
# @pytest.mark.parametrize("device_params", [{"dispatch_core_axis": ttnn.DispatchCoreAxis.COL}], indirect=True) |
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.
commented out?
@@ -1414,6 +1409,27 @@ void Matmul::validate( | |||
|
|||
MatmulProgramConfig chosen_program_config = get_program_config(input_tensor_a, input_tensor_b, this); | |||
|
|||
bool k_n_pad = false; |
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.
is this flag essentially program_config.gather_in0? might be confusing for people without context
Ticket
Problem description
In the current use case of Matmul1D with gather_in0 in the Llama models, the activations and weights need to be padded. This results in significant overhead.
What's changed
To support unpadded shapes, the implementation leverages the implicit padding information that can be stored in the sharding spec. For example, a tensor might be of shape
[1, 1, 32, 2048]
and we want to shard it over 24 cores. SinceK = 2048
doesn't divide with 24 cores, we can pad the shape toK_pad = 2304
, while keeping the actual tensor shape the same. Then, the shapes in the sharding spec can be derived usingK_pad
, instead ofK
.Since the matmul block sizes are derived using the sharding spec, the kernels implicitly process the padding shape, where some pages at the end of the inner dim (for activations) contain garbage data. Note, if the activations are being implicitly padded, to make sure the the output is correct when implicitly padding the inner dim, the inner dim for the weights must be explicitly padded with 0's. This is to ensure that when accumulating partials, the garbage/padded part of the activations get multiplied with 0's before summation.
Example for matmul on 24 cores
Original shapes
[1, 1, 32, 2048]
[1, 1, 2048, 3584]
Actual tensors passed into the op
[1, 1, 32, 2048]
, with shard shape using padding:[32, 2304 / 24]
[1, 1, 2304, 3584]
, with shard shape using padding:[2304, 3840 / 24]
[1, 1, 32, 3584]
, with shard shape using padding:[32, 3840 / 24]
Other changes include moving validation code in matmul to support different K's for the activation vs weights when
gather_in0 = True
.Checklist