From 0f43f84a673f42d109b62a8aca812630ed82ba11 Mon Sep 17 00:00:00 2001 From: Mike Judge Date: Thu, 1 Feb 2024 15:48:11 -0500 Subject: [PATCH 01/10] @timestamp is required for ES (cherry picked from commit d8cb16db58c63d101bda5137b7a83ca6954d761f) From 89d882f509978591d0953f53ae1fe820a44832fe Mon Sep 17 00:00:00 2001 From: Stefan Djordjevic Date: Fri, 2 Feb 2024 15:10:20 +0000 Subject: [PATCH 02/10] Bumping confidential customer models repo submodule (cherry picked from commit 116dd3b147fd6f31968febc2d24c4c92c0b2a533) From fd14f8df6f4fedd7cd109d6f70a29e92c9187b57 Mon Sep 17 00:00:00 2001 From: Nikola Vukobrat Date: Fri, 2 Feb 2024 14:03:29 +0000 Subject: [PATCH 03/10] Support caching for benchmarking models (customer repo) #2270 (cherry picked from commit 48e64b159e17114ec083102170f39f58a524b9e0) From 9c321fa486d8be1e9de6bbc5a6c5f24b8fe7d5c8 Mon Sep 17 00:00:00 2001 From: mpantic Date: Mon, 5 Feb 2024 10:28:55 +0000 Subject: [PATCH 04/10] Remove allow_failure flag from PyBuda push CI and perf runs (cherry picked from commit 179d7adc3e822056f0a0cc242356963b0cd3ce1c) From 070d946ca45dd57fc529c24e2724414d2a8dc511 Mon Sep 17 00:00:00 2001 From: pchandrasekaran Date: Thu, 8 Feb 2024 08:15:15 +0000 Subject: [PATCH 05/10] Added tri_basic_2 sematic segmentation model in confidential_customer_models and nightly test and configuration file (cherry picked from commit 26fb354ffb75f37e8394f79ff2566e91287d14a5) --- .../high_prio/cnn/pytorch/test_tri_basic_2.py | 66 ++++++++ .../models/tri_basic_2/model/__init__.py | 0 .../models/tri_basic_2/model/semseg.py | 145 ++++++++++++++++++ 3 files changed, 211 insertions(+) create mode 100644 pybuda/test/model_demos/high_prio/cnn/pytorch/test_tri_basic_2.py create mode 100644 pybuda/test/model_demos/models/tri_basic_2/model/__init__.py create mode 100644 pybuda/test/model_demos/models/tri_basic_2/model/semseg.py diff --git a/pybuda/test/model_demos/high_prio/cnn/pytorch/test_tri_basic_2.py b/pybuda/test/model_demos/high_prio/cnn/pytorch/test_tri_basic_2.py new file mode 100644 index 000000000..2a3cf7368 --- /dev/null +++ b/pybuda/test/model_demos/high_prio/cnn/pytorch/test_tri_basic_2.py @@ -0,0 +1,66 @@ +import pybuda +import torch + +from types import SimpleNamespace + +import cv2 +import os + +from test.model_demos.models.tri_basic_2.model.semseg import resnet34_semseg + +from pybuda.verify.backend import verify_module +from pybuda import VerifyConfig + +from pybuda.verify.config import TestKind + + +def test_tri_basic_2_sematic_segmentation_pytorch(test_device): + + # Set PyBuda configuration parameters + compiler_cfg = pybuda.config._get_global_compiler_config() + compiler_cfg.balancer_policy = "Ribbon" + compiler_cfg.enable_t_streaming = True + compiler_cfg.default_dram_parameters = False + compiler_cfg.default_df_override = pybuda.DataFormat.Float16_b + compiler_cfg.enable_auto_fusing = False + + compiler_cfg.balancer_op_override("add_114", "t_stream_shape", (1,1)) #TM error + compiler_cfg.balancer_op_override("add_142", "t_stream_shape", (1,1)) #TM error + compiler_cfg.balancer_op_override("add_156", "t_stream_shape", (1,1)) #TM error + compiler_cfg.balancer_op_override("add_171", "t_stream_shape", (1,1)) #TM error + compiler_cfg.balancer_op_override("add_214", "t_stream_shape", (1,1)) #TM error + + os.environ["PYBUDA_RIBBON2"]="1" + os.environ["PYBUDA_FORCE_EMULATE_HARVESTED"]="1" + os.environ["ARCH_NAME"]="wormhole_b0" + + + # Sample Input + image_w = 800 + image_h = 800 + image = cv2.imread("third_party/confidential_customer_models/cv_demos/tri_basic_2/images/left.png") + image = cv2.resize(image, (image_w, image_h), interpolation = cv2.INTER_LINEAR) + image_tensor = (torch.from_numpy(image).permute(2, 0, 1).unsqueeze(0).to(torch.float32) / 255.0).contiguous() + + # Load the model and weights + hparams = SimpleNamespace(num_classes=24) + model = resnet34_semseg(hparams) + state_dict = torch.load("third_party/confidential_customer_models/cv_demos/tri_basic_2/weights/basic_semseg.ckpt", map_location="cpu") + model.load_state_dict(state_dict) + model.eval() + + # Create PyBuda module from PyTorch model + tt_model = pybuda.PyTorchModule("pt_tri_basic_2_semseg", model) + + # Run inference on Tenstorrent device + verify_module( + tt_model, + input_shapes=[(image_tensor.shape,)], + inputs=[(image_tensor,)], + verify_cfg=VerifyConfig( + arch=test_device.arch, + devtype=test_device.devtype, + devmode=test_device.devmode, + test_kind=TestKind.INFERENCE, + ) + ) \ No newline at end of file diff --git a/pybuda/test/model_demos/models/tri_basic_2/model/__init__.py b/pybuda/test/model_demos/models/tri_basic_2/model/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/pybuda/test/model_demos/models/tri_basic_2/model/semseg.py b/pybuda/test/model_demos/models/tri_basic_2/model/semseg.py new file mode 100644 index 000000000..f575869c4 --- /dev/null +++ b/pybuda/test/model_demos/models/tri_basic_2/model/semseg.py @@ -0,0 +1,145 @@ +# Copyright 2023 Toyota Research Institute. All rights reserved. + +import math +from typing import List + +import torch +import torch.nn as nn +import torch.nn.functional as F + + +class BasicResidualBlock(nn.Module): + + def __init__(self, *, in_channels, out_channels, stride=1, dilation_rate=1): + super().__init__() + if in_channels == out_channels and stride == 1: + self.shortcut = nn.Identity() + else: + self.shortcut = nn.Sequential( + nn.Conv2d(in_channels, out_channels, kernel_size=1, stride=stride, bias=False), + nn.BatchNorm2d(out_channels), + ) + + self.conv1 = nn.Conv2d(in_channels, out_channels, kernel_size=3, stride=stride, padding=dilation_rate, + dilation=dilation_rate, bias=False) + self.norm1 = nn.BatchNorm2d(out_channels) + self.activation = nn.ReLU(inplace=True) + self.conv2 = nn.Conv2d(out_channels, out_channels, kernel_size=3, padding=dilation_rate, dilation=dilation_rate, + bias=False) + self.norm2 = nn.BatchNorm2d(out_channels) + + def forward(self, inputs): + shortcut = self.shortcut(inputs) + + outputs = self.activation(self.norm1(self.conv1(inputs))) + outputs = self.norm2(self.conv2(outputs)) + outputs = outputs + shortcut + outputs = self.activation(outputs) + return outputs + + +def resnet_group(*, block_func, in_channels, out_channels, stride, num_blocks, dilation_rates=[1]): + assert len(dilation_rates) > 0 + + residual_blocks = [ + block_func(in_channels=in_channels, out_channels=out_channels, stride=stride, dilation_rate=dilation_rates[0]) + ] + for idx in range(1, num_blocks): + residual_blocks.append(block_func(in_channels=out_channels, out_channels=out_channels, stride=1, + dilation_rate=dilation_rates[idx % len(dilation_rates)])) + return nn.Sequential(*residual_blocks) + + +class Fpn(nn.Module): + + def __init__(self, *, in_channels, out_channels): + super().__init__() + + idxs = [] + convs = [] + for idx, channels in enumerate(in_channels): + idxs.append(idx) + convs.append(nn.Conv2d(channels, out_channels, kernel_size=1, bias=True)) + self.idxs = idxs[::-1] + self.convs = nn.ModuleList(convs[::-1]) + + self.upsample2 = nn.Upsample(scale_factor=2, mode="bilinear", align_corners=False) + + def forward(self, group_outputs: List[torch.Tensor]): + outputs = None + for idx, module in enumerate(self.convs): + current = module(group_outputs[self.idxs[idx]]) + if outputs is None: + outputs = current + else: + outputs = self.upsample2(outputs) + current + + return outputs + + +class BasicResNet(nn.Module): + + def __init__(self, hparams, *, num_blocks, num_channels, dilation_rates): + super().__init__() + assert len(num_blocks) == 4 + assert len(num_channels) == len(num_blocks) + assert len(dilation_rates) == len(num_blocks) + + self.num_channels = num_channels + + self.conv_in = nn.Conv2d(3, num_channels[0], kernel_size=7, padding=3, stride=2, bias=False) + self.norm_in = nn.BatchNorm2d(num_channels[0]) + self.activation_in = nn.ReLU(inplace=True) + self.pool_in = nn.MaxPool2d(kernel_size=2) + + self.group1 = resnet_group(block_func=BasicResidualBlock, in_channels=num_channels[0], + out_channels=num_channels[0], stride=1, num_blocks=num_blocks[0], + dilation_rates=dilation_rates[0]) + self.group2 = resnet_group(block_func=BasicResidualBlock, in_channels=num_channels[0], + out_channels=num_channels[1], stride=2, num_blocks=num_blocks[1], + dilation_rates=dilation_rates[1]) + self.group3 = resnet_group(block_func=BasicResidualBlock, in_channels=num_channels[1], + out_channels=num_channels[2], stride=2, num_blocks=num_blocks[2], + dilation_rates=dilation_rates[2]) + self.group4 = resnet_group(block_func=BasicResidualBlock, in_channels=num_channels[2], + out_channels=num_channels[3], stride=2, num_blocks=num_blocks[3], + dilation_rates=dilation_rates[3]) + + self.head = Fpn(in_channels=num_channels, out_channels=hparams.num_classes) + + self.upsample = nn.Upsample(scale_factor=4, mode="bilinear", align_corners=False) + + def get_output_channels(self): + return self.num_channels + + def forward(self, inputs): + _, _, h, w = inputs.shape + + vpad = math.ceil(h / 32) * 32 - h + top_pad = vpad // 2 + bottom_pad = vpad - top_pad + hpad = math.ceil(w / 32) * 32 - w + left_pad = hpad // 2 + right_pad = hpad - left_pad + + inputs = F.pad(inputs, (left_pad, right_pad, top_pad, bottom_pad)) + + outputs = self.pool_in(self.activation_in(self.norm_in(self.conv_in(inputs)))) + group1_outputs = self.group1(outputs) + group2_outputs = self.group2(group1_outputs) + group3_outputs = self.group3(group2_outputs) + group4_outputs = self.group4(group3_outputs) + + outputs = [group1_outputs, group2_outputs, group3_outputs, group4_outputs] + logits = self.upsample(self.head(outputs)) + + logits = logits[:, :, top_pad:top_pad + h, left_pad:left_pad + w] + + return logits + + +def resnet34_semseg(hparams): + return BasicResNet(hparams, + num_blocks=[3, 4, 6, 3], + num_channels=[64, 128, 256, 512], + dilation_rates=[[1], [1], [1, 1, 2, 5, 9, 17], [1]]) From e7de84d58e63fb881b553c03a8601ee647600ed2 Mon Sep 17 00:00:00 2001 From: svuckovic Date: Thu, 28 Mar 2024 12:32:18 +0000 Subject: [PATCH 06/10] Rebase with main --- pybuda/test/model_demos/high_prio/cnn/pytorch/test_yolo_v5.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/pybuda/test/model_demos/high_prio/cnn/pytorch/test_yolo_v5.py b/pybuda/test/model_demos/high_prio/cnn/pytorch/test_yolo_v5.py index 2ca404b34..01d457c09 100644 --- a/pybuda/test/model_demos/high_prio/cnn/pytorch/test_yolo_v5.py +++ b/pybuda/test/model_demos/high_prio/cnn/pytorch/test_yolo_v5.py @@ -274,7 +274,11 @@ def generate_model_yoloV5I480_imgcls_torchhub_pytorch(test_device, variant, size def test_yolov5_480x480(test_device, size): if test_device.arch == BackendDevice.Grayskull: os.environ["PYBUDA_FORK_JOIN_SKIP_EXPANDING_BUFFERS"] = "1" +<<<<<<< HEAD if size in ["m", "l"] and test_device.arch == BackendDevice.Wormhole_B0: +======= + if size in ["x", "l", "m"] and test_device.arch == BackendDevice.Wormhole_B0: +>>>>>>> 8b0ffe2 ([nightly] Fix #2441, #2449, #2476) os.environ["PYBUDA_LEGACY_KERNEL_BROADCAST"] = "1" if size in ["s"] and test_device.arch == BackendDevice.Wormhole_B0: os.environ["PYBUDA_TEMP_DISABLE_MODEL_KB_PROLOGUE_BW"] = "1" From ec0e04525f35edb22ee29acd0d6ef0c28d10b366 Mon Sep 17 00:00:00 2001 From: pchandrasekaran Date: Thu, 4 Apr 2024 13:50:23 +0000 Subject: [PATCH 07/10] Add tri_basic_2 semantic segmentation model on gs and nightly (cherry picked from commit 88b29efb09cdf658b9a05ce977f99285bd242205) --- .../high_prio/cnn/pytorch/test_tri_basic_2.py | 63 ++++++++++++++----- 1 file changed, 46 insertions(+), 17 deletions(-) diff --git a/pybuda/test/model_demos/high_prio/cnn/pytorch/test_tri_basic_2.py b/pybuda/test/model_demos/high_prio/cnn/pytorch/test_tri_basic_2.py index 2a3cf7368..19e8dc85b 100644 --- a/pybuda/test/model_demos/high_prio/cnn/pytorch/test_tri_basic_2.py +++ b/pybuda/test/model_demos/high_prio/cnn/pytorch/test_tri_basic_2.py @@ -4,13 +4,12 @@ from types import SimpleNamespace import cv2 -import os +import os from test.model_demos.models.tri_basic_2.model.semseg import resnet34_semseg from pybuda.verify.backend import verify_module from pybuda import VerifyConfig - from pybuda.verify.config import TestKind @@ -24,34 +23,64 @@ def test_tri_basic_2_sematic_segmentation_pytorch(test_device): compiler_cfg.default_df_override = pybuda.DataFormat.Float16_b compiler_cfg.enable_auto_fusing = False - compiler_cfg.balancer_op_override("add_114", "t_stream_shape", (1,1)) #TM error - compiler_cfg.balancer_op_override("add_142", "t_stream_shape", (1,1)) #TM error - compiler_cfg.balancer_op_override("add_156", "t_stream_shape", (1,1)) #TM error - compiler_cfg.balancer_op_override("add_171", "t_stream_shape", (1,1)) #TM error - compiler_cfg.balancer_op_override("add_214", "t_stream_shape", (1,1)) #TM error + compiler_cfg.balancer_op_override("add_114", "t_stream_shape", (1, 1)) # TM error + compiler_cfg.balancer_op_override("add_142", "t_stream_shape", (1, 1)) # TM error + compiler_cfg.balancer_op_override("add_171", "t_stream_shape", (1, 1)) # TM error +<<<<<<< HEAD os.environ["PYBUDA_RIBBON2"]="1" os.environ["PYBUDA_FORCE_EMULATE_HARVESTED"]="1" os.environ["ARCH_NAME"]="wormhole_b0" +======= + if test_device.arch == pybuda.BackendDevice.Wormhole_B0: + compiler_cfg.balancer_op_override( + "add_156", "t_stream_shape", (1, 1) + ) # TM error + compiler_cfg.balancer_op_override( + "add_214", "t_stream_shape", (1, 1) + ) # TM error + + elif test_device.arch == pybuda.BackendDevice.Grayskull: + compiler_cfg.balancer_op_override( + "add_200", "t_stream_shape", (1, 1) + ) # TM error + compiler_cfg.balancer_op_override( + "add_229", "t_stream_shape", (1, 1) + ) # TM error + compiler_cfg.balancer_op_override( + "conv2d_15.dc.conv2d.3.dc.sparse_matmul.9.dc.sparse_matmul.1.lc2", + "t_stream_shape", + (10, 1), + ) + os.environ["PYBUDA_RIBBON2"] = "1" + os.environ["PYBUDA_TEMP_DISABLE_MODEL_KB_PROLOGUE_BW"] = "1" +>>>>>>> e4f2df4 (Add tri_basic_2 semantic segmentation model on gs and nightly) - # Sample Input + # Sample Input image_w = 800 image_h = 800 - image = cv2.imread("third_party/confidential_customer_models/cv_demos/tri_basic_2/images/left.png") - image = cv2.resize(image, (image_w, image_h), interpolation = cv2.INTER_LINEAR) - image_tensor = (torch.from_numpy(image).permute(2, 0, 1).unsqueeze(0).to(torch.float32) / 255.0).contiguous() - + image = cv2.imread( + "third_party/confidential_customer_models/cv_demos/tri_basic_2/images/left.png" + ) + image = cv2.resize(image, (image_w, image_h), interpolation=cv2.INTER_LINEAR) + image_tensor = ( + torch.from_numpy(image).permute(2, 0, 1).unsqueeze(0).to(torch.float32) / 255.0 + ).contiguous() + # Load the model and weights hparams = SimpleNamespace(num_classes=24) model = resnet34_semseg(hparams) - state_dict = torch.load("third_party/confidential_customer_models/cv_demos/tri_basic_2/weights/basic_semseg.ckpt", map_location="cpu") + state_dict = torch.load( + "third_party/confidential_customer_models/cv_demos/tri_basic_2/weights/basic_semseg.ckpt", + map_location="cpu", + ) model.load_state_dict(state_dict) model.eval() - + # Create PyBuda module from PyTorch model tt_model = pybuda.PyTorchModule("pt_tri_basic_2_semseg", model) - + # Run inference on Tenstorrent device verify_module( tt_model, @@ -62,5 +91,5 @@ def test_tri_basic_2_sematic_segmentation_pytorch(test_device): devtype=test_device.devtype, devmode=test_device.devmode, test_kind=TestKind.INFERENCE, - ) - ) \ No newline at end of file + ), + ) From babeb0b8f8c70890a89f2147c1c51d616de96e7e Mon Sep 17 00:00:00 2001 From: jserbedzija Date: Wed, 24 Apr 2024 14:34:27 +0000 Subject: [PATCH 08/10] [Model] Fixup tri_basic_2 (cherry picked from commit 1283b4bd3d5e7ed53f75d20b3b165bafe004beb6) --- .../test/model_demos/high_prio/cnn/pytorch/test_tri_basic_2.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/pybuda/test/model_demos/high_prio/cnn/pytorch/test_tri_basic_2.py b/pybuda/test/model_demos/high_prio/cnn/pytorch/test_tri_basic_2.py index 19e8dc85b..5854cd486 100644 --- a/pybuda/test/model_demos/high_prio/cnn/pytorch/test_tri_basic_2.py +++ b/pybuda/test/model_demos/high_prio/cnn/pytorch/test_tri_basic_2.py @@ -36,6 +36,9 @@ def test_tri_basic_2_sematic_segmentation_pytorch(test_device): compiler_cfg.balancer_op_override( "add_156", "t_stream_shape", (1, 1) ) # TM error + compiler_cfg.balancer_op_override( + "add_200", "t_stream_shape", (1, 1) + ) # TM error compiler_cfg.balancer_op_override( "add_214", "t_stream_shape", (1, 1) ) # TM error From a782031f9f9f9778b2296b98b915ebb3187ae965 Mon Sep 17 00:00:00 2001 From: Milan Topalovic Date: Wed, 31 Jul 2024 06:51:07 +0000 Subject: [PATCH 09/10] [Minor] Downgrading `mypy` from latest 1.11 -> 1.10 Latest `mypy` depends on `typing-extension` >= 4.6 which conflicts with tensorflow which requires < 4.6. Downgrading `1.10` solves this issue. Tested: * Builds tt-forge OK * Run simple test OK * Run make_stups OK - no conflicts and no diff in generated stubs --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index bafab148c..4f8f6ff4c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -51,7 +51,7 @@ add_subdirectory(pybuda) ### Generate stubs for ttforge ### Run `cmake --build build -- make_stubs` to generate stubs add_custom_target(make_stubs - COMMAND pip install mypy + COMMAND pip install mypy==1.10 COMMAND stubgen -m pybuda._C -m pybuda._C.autograd -m pybuda._C.graph -m pybuda._C.torch_device -m pybuda._C.runtime -o pybuda -v COMMENT "Generating stubs for ttforge" USES_TERMINAL From 54e9838ee826b6c7ad17e1296fbddf30a6505713 Mon Sep 17 00:00:00 2001 From: Milan Topalovic Date: Fri, 2 Aug 2024 10:20:55 +0000 Subject: [PATCH 10/10] Fixing rebase --- .../high_prio/cnn/pytorch/test_tri_basic_2.py | 98 ------------ .../high_prio/cnn/pytorch/test_yolo_v5.py | 4 - .../models/tri_basic_2/model/__init__.py | 0 .../models/tri_basic_2/model/semseg.py | 145 ------------------ 4 files changed, 247 deletions(-) delete mode 100644 pybuda/test/model_demos/high_prio/cnn/pytorch/test_tri_basic_2.py delete mode 100644 pybuda/test/model_demos/models/tri_basic_2/model/__init__.py delete mode 100644 pybuda/test/model_demos/models/tri_basic_2/model/semseg.py diff --git a/pybuda/test/model_demos/high_prio/cnn/pytorch/test_tri_basic_2.py b/pybuda/test/model_demos/high_prio/cnn/pytorch/test_tri_basic_2.py deleted file mode 100644 index 5854cd486..000000000 --- a/pybuda/test/model_demos/high_prio/cnn/pytorch/test_tri_basic_2.py +++ /dev/null @@ -1,98 +0,0 @@ -import pybuda -import torch - -from types import SimpleNamespace - -import cv2 -import os - -from test.model_demos.models.tri_basic_2.model.semseg import resnet34_semseg - -from pybuda.verify.backend import verify_module -from pybuda import VerifyConfig -from pybuda.verify.config import TestKind - - -def test_tri_basic_2_sematic_segmentation_pytorch(test_device): - - # Set PyBuda configuration parameters - compiler_cfg = pybuda.config._get_global_compiler_config() - compiler_cfg.balancer_policy = "Ribbon" - compiler_cfg.enable_t_streaming = True - compiler_cfg.default_dram_parameters = False - compiler_cfg.default_df_override = pybuda.DataFormat.Float16_b - compiler_cfg.enable_auto_fusing = False - - compiler_cfg.balancer_op_override("add_114", "t_stream_shape", (1, 1)) # TM error - compiler_cfg.balancer_op_override("add_142", "t_stream_shape", (1, 1)) # TM error - compiler_cfg.balancer_op_override("add_171", "t_stream_shape", (1, 1)) # TM error - -<<<<<<< HEAD - os.environ["PYBUDA_RIBBON2"]="1" - os.environ["PYBUDA_FORCE_EMULATE_HARVESTED"]="1" - os.environ["ARCH_NAME"]="wormhole_b0" -======= - if test_device.arch == pybuda.BackendDevice.Wormhole_B0: - compiler_cfg.balancer_op_override( - "add_156", "t_stream_shape", (1, 1) - ) # TM error - compiler_cfg.balancer_op_override( - "add_200", "t_stream_shape", (1, 1) - ) # TM error - compiler_cfg.balancer_op_override( - "add_214", "t_stream_shape", (1, 1) - ) # TM error - - elif test_device.arch == pybuda.BackendDevice.Grayskull: - compiler_cfg.balancer_op_override( - "add_200", "t_stream_shape", (1, 1) - ) # TM error - compiler_cfg.balancer_op_override( - "add_229", "t_stream_shape", (1, 1) - ) # TM error - compiler_cfg.balancer_op_override( - "conv2d_15.dc.conv2d.3.dc.sparse_matmul.9.dc.sparse_matmul.1.lc2", - "t_stream_shape", - (10, 1), - ) - - os.environ["PYBUDA_RIBBON2"] = "1" - os.environ["PYBUDA_TEMP_DISABLE_MODEL_KB_PROLOGUE_BW"] = "1" ->>>>>>> e4f2df4 (Add tri_basic_2 semantic segmentation model on gs and nightly) - - # Sample Input - image_w = 800 - image_h = 800 - image = cv2.imread( - "third_party/confidential_customer_models/cv_demos/tri_basic_2/images/left.png" - ) - image = cv2.resize(image, (image_w, image_h), interpolation=cv2.INTER_LINEAR) - image_tensor = ( - torch.from_numpy(image).permute(2, 0, 1).unsqueeze(0).to(torch.float32) / 255.0 - ).contiguous() - - # Load the model and weights - hparams = SimpleNamespace(num_classes=24) - model = resnet34_semseg(hparams) - state_dict = torch.load( - "third_party/confidential_customer_models/cv_demos/tri_basic_2/weights/basic_semseg.ckpt", - map_location="cpu", - ) - model.load_state_dict(state_dict) - model.eval() - - # Create PyBuda module from PyTorch model - tt_model = pybuda.PyTorchModule("pt_tri_basic_2_semseg", model) - - # Run inference on Tenstorrent device - verify_module( - tt_model, - input_shapes=[(image_tensor.shape,)], - inputs=[(image_tensor,)], - verify_cfg=VerifyConfig( - arch=test_device.arch, - devtype=test_device.devtype, - devmode=test_device.devmode, - test_kind=TestKind.INFERENCE, - ), - ) diff --git a/pybuda/test/model_demos/high_prio/cnn/pytorch/test_yolo_v5.py b/pybuda/test/model_demos/high_prio/cnn/pytorch/test_yolo_v5.py index 01d457c09..2ca404b34 100644 --- a/pybuda/test/model_demos/high_prio/cnn/pytorch/test_yolo_v5.py +++ b/pybuda/test/model_demos/high_prio/cnn/pytorch/test_yolo_v5.py @@ -274,11 +274,7 @@ def generate_model_yoloV5I480_imgcls_torchhub_pytorch(test_device, variant, size def test_yolov5_480x480(test_device, size): if test_device.arch == BackendDevice.Grayskull: os.environ["PYBUDA_FORK_JOIN_SKIP_EXPANDING_BUFFERS"] = "1" -<<<<<<< HEAD if size in ["m", "l"] and test_device.arch == BackendDevice.Wormhole_B0: -======= - if size in ["x", "l", "m"] and test_device.arch == BackendDevice.Wormhole_B0: ->>>>>>> 8b0ffe2 ([nightly] Fix #2441, #2449, #2476) os.environ["PYBUDA_LEGACY_KERNEL_BROADCAST"] = "1" if size in ["s"] and test_device.arch == BackendDevice.Wormhole_B0: os.environ["PYBUDA_TEMP_DISABLE_MODEL_KB_PROLOGUE_BW"] = "1" diff --git a/pybuda/test/model_demos/models/tri_basic_2/model/__init__.py b/pybuda/test/model_demos/models/tri_basic_2/model/__init__.py deleted file mode 100644 index e69de29bb..000000000 diff --git a/pybuda/test/model_demos/models/tri_basic_2/model/semseg.py b/pybuda/test/model_demos/models/tri_basic_2/model/semseg.py deleted file mode 100644 index f575869c4..000000000 --- a/pybuda/test/model_demos/models/tri_basic_2/model/semseg.py +++ /dev/null @@ -1,145 +0,0 @@ -# Copyright 2023 Toyota Research Institute. All rights reserved. - -import math -from typing import List - -import torch -import torch.nn as nn -import torch.nn.functional as F - - -class BasicResidualBlock(nn.Module): - - def __init__(self, *, in_channels, out_channels, stride=1, dilation_rate=1): - super().__init__() - if in_channels == out_channels and stride == 1: - self.shortcut = nn.Identity() - else: - self.shortcut = nn.Sequential( - nn.Conv2d(in_channels, out_channels, kernel_size=1, stride=stride, bias=False), - nn.BatchNorm2d(out_channels), - ) - - self.conv1 = nn.Conv2d(in_channels, out_channels, kernel_size=3, stride=stride, padding=dilation_rate, - dilation=dilation_rate, bias=False) - self.norm1 = nn.BatchNorm2d(out_channels) - self.activation = nn.ReLU(inplace=True) - self.conv2 = nn.Conv2d(out_channels, out_channels, kernel_size=3, padding=dilation_rate, dilation=dilation_rate, - bias=False) - self.norm2 = nn.BatchNorm2d(out_channels) - - def forward(self, inputs): - shortcut = self.shortcut(inputs) - - outputs = self.activation(self.norm1(self.conv1(inputs))) - outputs = self.norm2(self.conv2(outputs)) - outputs = outputs + shortcut - outputs = self.activation(outputs) - return outputs - - -def resnet_group(*, block_func, in_channels, out_channels, stride, num_blocks, dilation_rates=[1]): - assert len(dilation_rates) > 0 - - residual_blocks = [ - block_func(in_channels=in_channels, out_channels=out_channels, stride=stride, dilation_rate=dilation_rates[0]) - ] - for idx in range(1, num_blocks): - residual_blocks.append(block_func(in_channels=out_channels, out_channels=out_channels, stride=1, - dilation_rate=dilation_rates[idx % len(dilation_rates)])) - return nn.Sequential(*residual_blocks) - - -class Fpn(nn.Module): - - def __init__(self, *, in_channels, out_channels): - super().__init__() - - idxs = [] - convs = [] - for idx, channels in enumerate(in_channels): - idxs.append(idx) - convs.append(nn.Conv2d(channels, out_channels, kernel_size=1, bias=True)) - self.idxs = idxs[::-1] - self.convs = nn.ModuleList(convs[::-1]) - - self.upsample2 = nn.Upsample(scale_factor=2, mode="bilinear", align_corners=False) - - def forward(self, group_outputs: List[torch.Tensor]): - outputs = None - for idx, module in enumerate(self.convs): - current = module(group_outputs[self.idxs[idx]]) - if outputs is None: - outputs = current - else: - outputs = self.upsample2(outputs) + current - - return outputs - - -class BasicResNet(nn.Module): - - def __init__(self, hparams, *, num_blocks, num_channels, dilation_rates): - super().__init__() - assert len(num_blocks) == 4 - assert len(num_channels) == len(num_blocks) - assert len(dilation_rates) == len(num_blocks) - - self.num_channels = num_channels - - self.conv_in = nn.Conv2d(3, num_channels[0], kernel_size=7, padding=3, stride=2, bias=False) - self.norm_in = nn.BatchNorm2d(num_channels[0]) - self.activation_in = nn.ReLU(inplace=True) - self.pool_in = nn.MaxPool2d(kernel_size=2) - - self.group1 = resnet_group(block_func=BasicResidualBlock, in_channels=num_channels[0], - out_channels=num_channels[0], stride=1, num_blocks=num_blocks[0], - dilation_rates=dilation_rates[0]) - self.group2 = resnet_group(block_func=BasicResidualBlock, in_channels=num_channels[0], - out_channels=num_channels[1], stride=2, num_blocks=num_blocks[1], - dilation_rates=dilation_rates[1]) - self.group3 = resnet_group(block_func=BasicResidualBlock, in_channels=num_channels[1], - out_channels=num_channels[2], stride=2, num_blocks=num_blocks[2], - dilation_rates=dilation_rates[2]) - self.group4 = resnet_group(block_func=BasicResidualBlock, in_channels=num_channels[2], - out_channels=num_channels[3], stride=2, num_blocks=num_blocks[3], - dilation_rates=dilation_rates[3]) - - self.head = Fpn(in_channels=num_channels, out_channels=hparams.num_classes) - - self.upsample = nn.Upsample(scale_factor=4, mode="bilinear", align_corners=False) - - def get_output_channels(self): - return self.num_channels - - def forward(self, inputs): - _, _, h, w = inputs.shape - - vpad = math.ceil(h / 32) * 32 - h - top_pad = vpad // 2 - bottom_pad = vpad - top_pad - hpad = math.ceil(w / 32) * 32 - w - left_pad = hpad // 2 - right_pad = hpad - left_pad - - inputs = F.pad(inputs, (left_pad, right_pad, top_pad, bottom_pad)) - - outputs = self.pool_in(self.activation_in(self.norm_in(self.conv_in(inputs)))) - group1_outputs = self.group1(outputs) - group2_outputs = self.group2(group1_outputs) - group3_outputs = self.group3(group2_outputs) - group4_outputs = self.group4(group3_outputs) - - outputs = [group1_outputs, group2_outputs, group3_outputs, group4_outputs] - logits = self.upsample(self.head(outputs)) - - logits = logits[:, :, top_pad:top_pad + h, left_pad:left_pad + w] - - return logits - - -def resnet34_semseg(hparams): - return BasicResNet(hparams, - num_blocks=[3, 4, 6, 3], - num_channels=[64, 128, 256, 512], - dilation_rates=[[1], [1], [1, 1, 2, 5, 9, 17], [1]])