Skip to content

Commit

Permalink
Send Perf Data to Explorer Frontend (#1608)
Browse files Browse the repository at this point in the history
- A few small changes to explorer to send perf data to the frontend.
- Changed `to_adapter_format` to allow for multiple objects
- Added `add_to_dataclass` to append perf_data to Graph dataclass.
  • Loading branch information
vprajapati-tt authored Dec 17, 2024
1 parent 05a831e commit 8c37b9d
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 6 deletions.
6 changes: 4 additions & 2 deletions tools/explorer/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ include(ExternalProject)
set(TT_EXPLORER_SCRIPT ${CMAKE_CURRENT_SOURCE_DIR}/run.py)
set(TTMLIR_BUILD_BIN_DIR ${TTMLIR_BINARY_DIR}/bin)

set(MODEL_EXPLORER_VERSION "d0b53c3b7049fd41ea1caff193706272c399fac9")
set(MODEL_EXPLORER_VERSION "ca884d5eb3291507e7f4e76776957e231b2d9b6d")
ExternalProject_Add(
model-explorer
PREFIX ${CMAKE_CURRENT_SOURCE_DIR}/model-explorer
Expand All @@ -18,7 +18,9 @@ ExternalProject_Add(
add_custom_target(explorer
COMMENT "Building tt-explorer... ${TTMLIR_BIN_DIR}"
COMMAND pip install $<$<CONFIG:Debug>:-e> ${CMAKE_CURRENT_SOURCE_DIR}/tt_adapter
COMMAND pip install ${CMAKE_CURRENT_SOURCE_DIR}/model-explorer/src/model-explorer/src/server/package
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

DEPENDS TTMLIRPythonModules model-explorer ttrt ttmlir-opt ttmlir-translate
)
Expand Down
4 changes: 3 additions & 1 deletion tools/explorer/tt_adapter/src/tt_adapter/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,9 @@ def convert(

# Convert TTIR to Model Explorer Graphs and Display/Return
graph, perf_data = mlir.build_graph(module, perf_trace)
return {"graphs": [graph], "perf_data": perf_data}
if perf_data:
graph = utils.add_to_dataclass(graph, "perf_data", perf_data.graphsData)
return {"graphs": [graph]}

def execute(
self, model_path: str, settings: Dict
Expand Down
16 changes: 13 additions & 3 deletions tools/explorer/tt_adapter/src/tt_adapter/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#
# SPDX-License-Identifier: Apache-2.0
import ttmlir
from dataclasses import make_dataclass
from dataclasses import make_dataclass, is_dataclass, asdict


def parse_mlir_file(model_path):
Expand All @@ -18,5 +18,15 @@ def to_dataclass(obj: dict, dc_name: str = "tempClass"):
return make_dataclass(dc_name, ((k, type(v)) for k, v in obj.items()))(**obj)


def to_adapter_format(obj: dict):
return {"graphs": [to_dataclass(obj)]}
def add_to_dataclass(dataclass, new_attr_name: str, new_attr_value):
if not is_dataclass(dataclass):
return None
classname = dataclass.__class__.__name__
dataclass = asdict(dataclass)
dataclass[new_attr_name] = new_attr_value
return to_dataclass(dataclass, dc_name=classname)


def to_adapter_format(*objs):
res = [x if is_dataclass(x) else to_dataclass(x) for x in objs]
return {"graphs": res}

0 comments on commit 8c37b9d

Please sign in to comment.