diff --git a/.github/actions/build-tt-mlir-action/action.yaml b/.github/actions/build-tt-mlir-action/action.yaml index ed88f6291b..09542b2c0a 100644 --- a/.github/actions/build-tt-mlir-action/action.yaml +++ b/.github/actions/build-tt-mlir-action/action.yaml @@ -123,12 +123,23 @@ runs: working-directory: ${{ inputs.install-output-dir }} run: tar cvf artifact.tar . + - name: Archive Build Directory + shell: bash + working-directory: ${{ inputs.build-output-dir }} + run: tar cvf artifact.tar . + - name: Upload Install Folder uses: actions/upload-artifact@v4 with: name: install-artifacts-${{ inputs.build-name }} path: ${{ inputs.install-output-dir }}/artifact.tar + - name: Upload Build Folder + uses: actions/upload-artifact@v4 + with: + name: build-artifacts-${{ inputs.build-name }} + path: ${{ inputs.build-output-dir }}/artifact.tar + - name: Get Latest Tag and Version shell: bash run: | diff --git a/.github/workflows/build-and-test.yml b/.github/workflows/build-and-test.yml index b55fd101e7..bdaa6d3b14 100644 --- a/.github/workflows/build-and-test.yml +++ b/.github/workflows/build-and-test.yml @@ -533,7 +533,9 @@ jobs: pytest -ssv runtime/test/python/ttnn/test_runtime_api.py build-and-test-explorer: - needs: build-image + needs: + - build-image + - build-ttmlir timeout-minutes: 60 strategy: fail-fast: false @@ -601,10 +603,22 @@ jobs: source env/activate cmake --build ${{ steps.strings.outputs.build-output-dir }} -- explorer + - name: Download Tests + uses: actions/download-artifact@v4 + with: + name: build-artifacts-${{ matrix.build.name }} + path: ${{ steps.strings.outputs.build-output-dir }} + + - name: 'Untar build directory' + shell: bash + working-directory: ${{ steps.strings.outputs.build-output-dir }} + run: tar xvf artifact.tar + - name: Run tt-explorer tests shell: bash run: | source env/activate + export TT_EXPLORER_GENERATED_TEST_DIR=${{ steps.strings.outputs.build-output-dir }}/test/ttmlir/Silicon/TTNN pytest tools/explorer/test/run_tests.py # collect results diff --git a/tools/explorer/test/models/forward_and_backward.mlir b/test/ttmlir/Explorer/load/forward_and_backward.mlir similarity index 96% rename from tools/explorer/test/models/forward_and_backward.mlir rename to test/ttmlir/Explorer/load/forward_and_backward.mlir index e205bcf2b8..95e04902fb 100644 --- a/tools/explorer/test/models/forward_and_backward.mlir +++ b/test/ttmlir/Explorer/load/forward_and_backward.mlir @@ -1,3 +1,6 @@ +// RUN: ttmlir-opt --ttir-to-ttnn-backend-pipeline %s +// Need to ensure that model is valid MLIR module + module @SimpleModel attributes {} { func.func @forward(%arg0: tensor<1x784xf32> {ttir.name = "input_1"}, %arg1: tensor<10x784xf32> {ttir.name = "linear.weight"}, %arg2: tensor<10xf32> {ttir.name = "linear.bias"}) -> (tensor<1x10xf32> {ttir.name = "SimpleModel_472.output_softmax_1495"}) { %0 = tensor.empty() : tensor<784x10xf32> diff --git a/tools/explorer/test/models/linear_autoencoder.mlir b/test/ttmlir/Explorer/load/linear_autoencoder.mlir similarity index 98% rename from tools/explorer/test/models/linear_autoencoder.mlir rename to test/ttmlir/Explorer/load/linear_autoencoder.mlir index d8af25bbff..8eee30b3b9 100644 --- a/tools/explorer/test/models/linear_autoencoder.mlir +++ b/test/ttmlir/Explorer/load/linear_autoencoder.mlir @@ -1,3 +1,5 @@ +// RUN: ttmlir-opt --ttir-to-ttnn-backend-pipeline %s + module @LinearAE attributes {} { func.func @forward(%arg0: tensor<1x784xf32> {ttir.name = "input_1"}, %arg1: tensor<784x128xf32> {ttir.name = "encoder_lin1.weight"}, %arg2: tensor<128xf32> {ttir.name = "encoder_lin1.bias"}, %arg3: tensor<128x64xf32> {ttir.name = "encoder_lin2.weight"}, %arg4: tensor<64xf32> {ttir.name = "encoder_lin2.bias"}, %arg5: tensor<64x12xf32> {ttir.name = "encoder_lin3.weight"}, %arg6: tensor<12xf32> {ttir.name = "encoder_lin3.bias"}, %arg7: tensor<12x3xf32> {ttir.name = "encoder_lin4.weight"}, %arg8: tensor<3xf32> {ttir.name = "encoder_lin4.bias"}, %arg9: tensor<3x12xf32> {ttir.name = "decoder_lin1.weight"}, %arg10: tensor<12xf32> {ttir.name = "decoder_lin1.bias"}, %arg11: tensor<12x64xf32> {ttir.name = "decoder_lin2.weight"}, %arg12: tensor<64xf32> {ttir.name = "decoder_lin2.bias"}, %arg13: tensor<64x128xf32> {ttir.name = "decoder_lin3.weight"}, %arg14: tensor<128xf32> {ttir.name = "decoder_lin3.bias"}, %arg15: tensor<128x784xf32> {ttir.name = "decoder_lin4.weight"}, %arg16: tensor<784xf32> {ttir.name = "decoder_lin4.bias"}) -> (tensor<1x784xf32> {ttir.name = "LinearAE.output_add_29"}) { %0 = tensor.empty() : tensor<1x128xf32> diff --git a/tools/explorer/test/models/open_llama_3b_single_layer.mlir b/test/ttmlir/Explorer/load/open_llama_3b_single_layer.mlir similarity index 99% rename from tools/explorer/test/models/open_llama_3b_single_layer.mlir rename to test/ttmlir/Explorer/load/open_llama_3b_single_layer.mlir index 97731870ba..ac97371031 100644 --- a/tools/explorer/test/models/open_llama_3b_single_layer.mlir +++ b/test/ttmlir/Explorer/load/open_llama_3b_single_layer.mlir @@ -1,3 +1,5 @@ +// RUN: ttmlir-opt --ttir-to-ttnn-backend-pipeline %s + #loc = loc("LlamaForCausalLM":0:0) #system_desc = #tt.system_desc<[{role = host, target_triple = "x86_64-pc-linux-gnu"}], [{arch = , grid = 8x8, l1_size = 1499136, num_dram_channels = 12, dram_channel_size = 1073741824, noc_l1_address_align_bytes = 16, pcie_address_align_bytes = 32, noc_dram_address_align_bytes = 32, l1_unreserved_base = 1024, erisc_l1_unreserved_base = 1024, dram_unreserved_base = 1024, dram_unreserved_end = 1073741824, physical_cores = {worker = [ 0x0, 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 1x0, 1x1, 1x2, 1x3, 1x4, 1x5, 1x6, 1x7, 2x0, 2x1, 2x2, 2x3, 2x4, 2x5, 2x6, 2x7, 3x0, 3x1, 3x2, 3x3, 3x4, 3x5, 3x6, 3x7, 4x0, 4x1, 4x2, 4x3, 4x4, 4x5, 4x6, 4x7, 5x0, 5x1, 5x2, 5x3, 5x4, 5x5, 5x6, 5x7, 6x0, 6x1, 6x2, 6x3, 6x4, 6x5, 6x6, 6x7, 7x0, 7x1, 7x2, 7x3, 7x4, 7x5, 7x6, 7x7] dram = [ 8x0, 9x0, 10x0, 8x1, 9x1, 10x1, 8x2, 9x2, 10x2, 8x3, 9x3, 10x3]}, supported_data_types = [, , , , , , , , , , , ], supported_tile_sizes = [ 4x16, 16x16, 32x16, 4x32, 16x32, 32x32], num_cbs = 32}], [0], [3 : i32], [ 0x0x0x0]> module @LlamaForCausalLM attributes {tt.system_desc = #system_desc} { diff --git a/tools/explorer/CMakeLists.txt b/tools/explorer/CMakeLists.txt index 89f7337617..935c8fe09f 100644 --- a/tools/explorer/CMakeLists.txt +++ b/tools/explorer/CMakeLists.txt @@ -15,9 +15,15 @@ ExternalProject_Add( INSTALL_COMMAND "" ) +set(PIP_EDITABLE_FLAG "") + +if (TT_EXPLORER_EDITABLE) + set(PIP_EDITABLE_FLAG "-e") +endif() + add_custom_target(explorer COMMENT "Building tt-explorer... ${TTMLIR_BIN_DIR}" - COMMAND pip install $<$:-e> ${CMAKE_CURRENT_SOURCE_DIR}/tt_adapter + COMMAND pip install ${PIP_EDITABLE_FLAG} ${CMAKE_CURRENT_SOURCE_DIR}/tt_adapter COMMAND pip uninstall -y ai-edge-model-explorer COMMAND ${CMAKE_COMMAND} -E remove_directory ${CMAKE_CURRENT_SOURCE_DIR}/model-explorer/src/model-explorer/src/server/package/build COMMAND pip install --upgrade ${CMAKE_CURRENT_SOURCE_DIR}/model-explorer/src/model-explorer/src/server/package diff --git a/tools/explorer/test/run_tests.py b/tools/explorer/test/run_tests.py index a3684cf72d..9f48ed0988 100644 --- a/tools/explorer/test/run_tests.py +++ b/tools/explorer/test/run_tests.py @@ -8,26 +8,60 @@ import multiprocessing import pytest import glob +import os HOST = "localhost" PORT = 8002 COMMAND_URL = "http://" + HOST + ":" + str(PORT) + "/apipost/v1/send_command" TEST_LOAD_MODEL_PATHS = [ "test/ttmlir/Dialect/TTNN/optimizer/mnist_sharding.mlir", - "tools/explorer/test/models/*.mlir", + "test/ttmlir/Explorer/**/*.mlir", ] MNIST_SHARDING_PATH = "test/ttmlir/Silicon/TTNN/optimizer/mnist_sharding.mlir" TEST_EXECUTE_MODEL_PATHS = [ MNIST_SHARDING_PATH, ] +if "TT_EXPLORER_GENERATED_TEST_DIR" in os.environ: + TEST_LOAD_MODEL_PATHS.append( + os.environ["TT_EXPLORER_GENERATED_TEST_DIR"] + "/**/*.mlir" + ) + + +def get_test_files(paths): + files = [] + for path in paths: + files.extend(glob.glob(path, recursive=True)) + return files + + +def execute_command(model_path, settings): + cmd = { + "extensionId": "tt_adapter", + "cmdId": "execute", + "modelPath": model_path, + "deleteAfterConversion": False, + "settings": settings, + } + + result = requests.post(COMMAND_URL, json=cmd) + assert result.ok + if "error" in result.json(): + print(result.json()) + assert False + @pytest.fixture(scope="function", autouse=True) def start_server(request): """Start the model explorer server before running tests and stop it after.""" server_thread = multiprocessing.Process( - target=model_explorer.visualize, - kwargs={"extensions": ["tt_adapter"], "host": HOST, "port": PORT}, + target=model_explorer.visualize_from_config, + kwargs={ + "extensions": ["tt_adapter"], + "host": HOST, + "port": PORT, + "no_open_in_browser": True, + }, ) server_thread.start()