-
Notifications
You must be signed in to change notification settings - Fork 81
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#10754: Add data-parallel support for UNet Shallow on N300
- Loading branch information
Showing
9 changed files
with
388 additions
and
95 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 |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# SPDX-FileCopyrightText: © 2024 Tenstorrent Inc. | ||
|
||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
import ttnn | ||
from tests.ttnn.utils_for_testing import assert_with_pcc | ||
|
||
|
||
def is_n300_with_eth_dispatch_cores(device_mesh) -> bool: | ||
all_devices_using_full_grid = all( | ||
[(8 == device.core_grid.x and 8 == device.core_grid.y) for device in device_mesh.get_devices()] | ||
) | ||
return all_devices_using_full_grid and (len(device_mesh.get_devices()) == 2) | ||
|
||
|
||
def check_pcc_conv(torch_tensor, ttnn_tensor, pcc=0.999, mesh_composer=None): | ||
B, C, H, W = torch_tensor.shape | ||
ttnn_tensor = ttnn.to_torch(ttnn_tensor, mesh_composer=mesh_composer).reshape(B, H, W, C).permute(0, 3, 1, 2) | ||
assert_with_pcc(torch_tensor, ttnn_tensor, pcc) | ||
|
||
|
||
def check_pcc_pool(torch_tensor, ttnn_tensor, pcc=0.999, mesh_composer=None): | ||
B, C, H, W = torch_tensor.shape | ||
ttnn_tensor = ( | ||
ttnn.to_torch(ttnn_tensor, mesh_composer=mesh_composer).reshape(B, H, W, -1).permute(0, 3, 1, 2)[:, :C, :, :] | ||
) | ||
assert_with_pcc(torch_tensor, ttnn_tensor, pcc) |
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
51 changes: 51 additions & 0 deletions
51
models/experimental/functional_unet/tests/test_unet_multi_device.py
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,51 @@ | ||
# SPDX-FileCopyrightText: © 2024 Tenstorrent Inc. | ||
|
||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
import pytest | ||
import ttnn | ||
|
||
from loguru import logger | ||
|
||
from models.experimental.functional_unet.tt.model_preprocessing import ( | ||
create_unet_input_tensors, | ||
create_unet_model_parameters, | ||
) | ||
from models.experimental.functional_unet.tt import unet_shallow_torch | ||
from models.experimental.functional_unet.tt import unet_shallow_ttnn | ||
from models.experimental.functional_unet.tests.common import ( | ||
check_pcc_conv, | ||
is_n300_with_eth_dispatch_cores, | ||
) | ||
|
||
|
||
@pytest.mark.parametrize("batch", [2]) | ||
@pytest.mark.parametrize("groups", [1]) | ||
@pytest.mark.parametrize("device_params", [{"l1_small_size": 64768}], indirect=True) | ||
def test_unet_multi_device_model(batch, groups, device_mesh, use_program_cache, reset_seeds): | ||
if not is_n300_with_eth_dispatch_cores(device_mesh): | ||
pytest.skip("Test is only valid for N300") | ||
|
||
inputs_mesh_mapper = ttnn.ShardTensorToMesh(device_mesh, dim=0) | ||
weights_mesh_mapper = ttnn.ReplicateTensorToMesh(device_mesh) | ||
output_mesh_composer = ttnn.ConcatMeshToTensor(device_mesh, dim=0) | ||
|
||
torch_input, ttnn_input = create_unet_input_tensors(device_mesh, batch, groups, pad_input=True) | ||
model = unet_shallow_torch.UNet.from_random_weights(groups=groups) | ||
|
||
parameters = create_unet_model_parameters(model, torch_input, groups=groups, device=device_mesh) | ||
ttnn_model = unet_shallow_ttnn.UNet(parameters, device=device_mesh, mesh_mapper=weights_mesh_mapper) | ||
|
||
num_devices = len(device_mesh.get_device_ids()) | ||
torch_input, ttnn_input = create_unet_input_tensors( | ||
device_mesh, num_devices * batch, groups, pad_input=True, mesh_mapper=inputs_mesh_mapper | ||
) | ||
logger.info(f"Created reference input tensors: {list(torch_input.shape)}") | ||
logger.info( | ||
f"Created multi-device input tensors: shape={list(ttnn_input.shape)} on devices={device_mesh.get_device_ids()}" | ||
) | ||
|
||
torch_output_tensor = model(torch_input) | ||
output_tensor = ttnn_model(ttnn_input, list(torch_input.shape)) | ||
|
||
check_pcc_conv(torch_output_tensor, output_tensor, mesh_composer=output_mesh_composer, pcc=0.99) |
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.