Skip to content

Commit

Permalink
Add entry to MM benchmark (#15117)
Browse files Browse the repository at this point in the history
  • Loading branch information
yugaoTT authored Nov 15, 2024
1 parent e00aac5 commit 2d9add2
Showing 1 changed file with 2 additions and 58 deletions.
60 changes: 2 additions & 58 deletions tests/ttnn/unit_tests/benchmarks/test_benchmark.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,64 +15,6 @@
import os


@run_for_wormhole_b0()
# fmt: off
@pytest.mark.parametrize("height,width,average_time", [
(1024, 1024, 1),
])
@pytest.mark.parametrize("dtype", [ttnn.bfloat8_b, ttnn.bfloat16])
# fmt: on
def test_benchmark_ttnn_add(device, use_program_cache, height, width, dtype, average_time):
torch.manual_seed(0)

torch_input_tensor_a = torch.rand((height, width))
torch_input_tensor_b = torch.rand((height, width))

input_tensor_a = ttnn.from_torch(torch_input_tensor_a, layout=ttnn.TILE_LAYOUT, device=device, dtype=dtype)
input_tensor_b = ttnn.from_torch(torch_input_tensor_b, layout=ttnn.TILE_LAYOUT, device=device, dtype=dtype)
ttnn.matmul(input_tensor_a, input_tensor_b)
total_time = 0
for i in range(3):
start = time.time()
output = ttnn.add(input_tensor_a, input_tensor_b)
end = time.time()
duration = end - start
total_time = total_time + duration
print(f"ttnn.add: {duration} seconds")
ttnn.to_torch(output)
total_time = total_time / 3
assert total_time <= average_time


@run_for_wormhole_b0()
# fmt: off
@pytest.mark.parametrize("m_size,k_size,n_size,average_time", [
(384, 1024, 1024, 1),
])
@pytest.mark.parametrize("dtype", [ttnn.bfloat8_b, ttnn.bfloat16])
# fmt: on
def test_benchmark_ttnn_matmul(device, use_program_cache, m_size, k_size, n_size, dtype, average_time):
torch.manual_seed(0)

torch_input_tensor_a = torch.rand((m_size, k_size))
torch_input_tensor_b = torch.rand((k_size, n_size))

input_tensor_a = ttnn.from_torch(torch_input_tensor_a, layout=ttnn.TILE_LAYOUT, device=device, dtype=dtype)
input_tensor_b = ttnn.from_torch(torch_input_tensor_b, layout=ttnn.TILE_LAYOUT, device=device, dtype=dtype)
ttnn.matmul(input_tensor_a, input_tensor_b)
total_time = 0
for i in range(3):
start = time.time()
output = ttnn.matmul(input_tensor_a, input_tensor_b)
end = time.time()
duration = end - start
total_time = total_time + duration
print(f"ttnn.matmul: {duration} seconds")
ttnn.to_torch(output)
total_time = total_time / 3
assert total_time <= average_time


SUBBLOCK_HW_CHOICES = [
(4, 2),
(2, 4),
Expand Down Expand Up @@ -197,10 +139,12 @@ def get_device_freq():
matmul_configs = [
(ttnn.bfloat16, ttnn.MathFidelity.HiFi2, False),
(ttnn.bfloat16, ttnn.MathFidelity.HiFi4, False),
(ttnn.bfloat8_b, ttnn.MathFidelity.HiFi2, False),
(ttnn.bfloat8_b, ttnn.MathFidelity.LoFi, False),
(ttnn.bfloat4_b, ttnn.MathFidelity.LoFi, False),
(ttnn.bfloat16, ttnn.MathFidelity.HiFi2, True),
(ttnn.bfloat16, ttnn.MathFidelity.HiFi4, True),
(ttnn.bfloat8_b, ttnn.MathFidelity.HiFi2, True),
(ttnn.bfloat8_b, ttnn.MathFidelity.LoFi, True),
(ttnn.bfloat4_b, ttnn.MathFidelity.LoFi, True),
]
Expand Down

0 comments on commit 2d9add2

Please sign in to comment.