-
Notifications
You must be signed in to change notification settings - Fork 6
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
Convert aten.sum.dim_IntList
to ttnn.sum
#264
base: main
Are you sure you want to change the base?
Conversation
680876a
to
79ffb55
Compare
I have no idea about the failing test case. |
tests/lowering/reduction/test_sum.py
Outdated
((1024, 640), (0,)), | ||
((14, 2048), (0,)), | ||
((14, 512), (0,)), | ||
((16384, 128), (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.
Found mild PCC error locally for (16384, 128), (0,)
:
expected_pytorch_result = tensor([[ 53.5000, -96.0000, -113.5000, -139.0000, -72.5000, 39.2500,
-159.0000, -13.6875, -87.0000, ...187.0000, -130.0000, -23.7500, -18.7500, -25.2500, -132.0000,
-22.0000, 87.5000]], dtype=torch.bfloat16)
actual_pytorch_result = TorchTensor([[ 63.0000, -111.5000, -129.0000, -142.0000, -74.0000, 59.2500,
-153.0000, -14.1875, -...000, -137.0000, -5.2188, -18.7500, -34.0000, -153.0000,
-15.6250, 102.5000]], dtype=torch.bfloat16)
pcc = 0.999
def assert_with_pcc(expected_pytorch_result, actual_pytorch_result, pcc=0.999):
assert list(expected_pytorch_result.shape) == list(
actual_pytorch_result.shape
), f"list(expected_pytorch_result.shape)={list(expected_pytorch_result.shape)} vs list(actual_pytorch_result.shape)={list(actual_pytorch_result.shape)}"
pcc_passed, pcc_message = comp_pcc(expected_pytorch_result, actual_pytorch_result, pcc)
> assert pcc_passed, construct_pcc_assert_message(pcc_message, expected_pytorch_result, actual_pytorch_result)
E AssertionError: 0.9923741703805607
tests/utils.py:219: AssertionError
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.
PCC accuracy declines as tensors grow in size because of aggregation of differences. Would it make sense to lower the threshold for tensors where a dimension is over 10k?
tests/lowering/reduction/test_sum.py
Outdated
((14, 2048), (0,)), | ||
((14, 512), (0,)), | ||
((16384, 128), (0,)), | ||
((16384, 32), (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.
Found mild PCC error locally for (16384, 32), (0,)
:
expected_pytorch_result = tensor([[-156.0000, -105.0000, -136.0000, 71.0000, -59.5000, -163.0000,
-26.1250, -26.2500, -67.0000, ... 10.8750, -237.0000, -108.0000, -38.2500, -107.5000, 47.2500,
-41.2500, -85.0000]], dtype=torch.bfloat16)
actual_pytorch_result = TorchTensor([[-185.0000, -127.5000, -161.0000, 93.5000, -63.2500, -199.0000,
-40.0000, -44.2500, -...000, -280.0000, -116.5000, -36.0000, -147.0000, 76.0000,
-37.7500, -104.0000]], dtype=torch.bfloat16)
pcc = 0.999
def assert_with_pcc(expected_pytorch_result, actual_pytorch_result, pcc=0.999):
assert list(expected_pytorch_result.shape) == list(
actual_pytorch_result.shape
), f"list(expected_pytorch_result.shape)={list(expected_pytorch_result.shape)} vs list(actual_pytorch_result.shape)={list(actual_pytorch_result.shape)}"
pcc_passed, pcc_message = comp_pcc(expected_pytorch_result, actual_pytorch_result, pcc)
> assert pcc_passed, construct_pcc_assert_message(pcc_message, expected_pytorch_result, actual_pytorch_result)
E AssertionError: 0.993693118840562
tests/utils.py:219: AssertionError
tensor = g.call_function(ttnn.to_layout, (tensor, TtnnRowMajorLayout())) | ||
tensor = g.call_function(ttnn.unsqueeze, (tensor, 0)) | ||
tensor = g.call_function(ttnn.sum, (tensor, 1)) | ||
tensor = g.call_function(ttnn.squeeze, (tensor, 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.
Summing along dimension 0 seems unsupported, so I made this workaround
Our current use cases only reduce at most 2 dimensions, so I'm using this naive algorithm. If the loop becomes a bottleneck, consider the following algorithm producing O(1) ops: 1. Transpose the tensor to group together dimensions to reduce 2. Reshape the tensor to merge dimensions to reduce 3. Reduce the only dimension 4. Unsqueeze/reshape if keepdims=True
…eezing at arbitrary axis is unsupported yet
I doubt if this makes a difference in Python though
Ticket
ttnn.sum
tt-metal#16336Problem description
To support
aten.sum.dim_IntList
, we needttnn.sum
to support a tuple of dims. I'm investigating how to patch the kernel.What's changed