Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added dependency graph for mlperf-inference runs #573

Merged
merged 6 commits into from
Nov 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,9 @@ jobs:
matrix:
system: [ "GO-spr", "phoenix", "i9" ]
python-version: [ "3.12" ]
model: [ "resnet50", "retinanet", "bert-99", "bert-99.9", "gptj-99.9", "3d-unet-99.9" ]
model: [ "resnet50", "retinanet", "bert-99", "bert-99.9", "gptj-99.9", "3d-unet-99.9", "sdxl" ]
exclude:
- system: i9
model: gptj-99.9
- system: phoenix
model: gptj-99.9
- model: gptj-99.9

steps:
- name: Test MLPerf Inference NVIDIA ${{ matrix.model }}
Expand Down
2 changes: 2 additions & 0 deletions script/app-mlperf-inference-nvidia/_cm.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -455,6 +455,8 @@ variations:
- tags: get,generic-python-lib,_package.diffusers
names:
- diffusers
version_max: "0.30.3"
version_max_usable: "0.30.3"
- tags: get,generic-python-lib,_package.transformers
names:
- transformers
Expand Down
10 changes: 10 additions & 0 deletions script/app-mlperf-inference/_cm.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,16 @@ posthook_deps:
env:
CM_PLATFORM_DETAILS_FILE_PATH: '<<<CM_MLPERF_OUTPUT_DIR>>>/system_info.txt'

post_deps:
- tags: draw,graph,from-json
enable_if_env:
CM_MLPERF_RUN_JSON_VERSION_INFO_FILE:
- on
env:
CM_JSON_INPUT_FILE: <<<CM_MLPERF_RUN_JSON_VERSION_INFO_FILE>>>
CM_OUTPUT_IMAGE_PATH: <<<CM_MLPERF_RUN_DEPS_GRAPH>>>
CM_OUTPUT_MERMAID_PATH: <<<CM_MLPERF_RUN_DEPS_MERMAID>>>

# Order of variations for documentation
variation_groups_order:
- implementation
Expand Down
3 changes: 3 additions & 0 deletions script/app-mlperf-inference/customize.py
Original file line number Diff line number Diff line change
Expand Up @@ -489,6 +489,9 @@ def postprocess(i):
print("\n")

if state.get('mlperf-inference-implementation') and state['mlperf-inference-implementation'].get('version_info'):
env['CM_MLPERF_RUN_JSON_VERSION_INFO_FILE'] = os.path.join(output_dir, "cm-version-info.json")
env['CM_MLPERF_RUN_DEPS_GRAPH'] = os.path.join(output_dir, "cm-deps.png")
env['CM_MLPERF_RUN_DEPS_MERMAID'] = os.path.join(output_dir, "cm-deps.mmd")
with open(os.path.join(output_dir, "cm-version-info.json"), "w") as f:
f.write(json.dumps(state['mlperf-inference-implementation']['version_info'], indent=2))

Expand Down
21 changes: 21 additions & 0 deletions script/draw-graph-from-json-data/_cm.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
alias: draw-graph-from-json-data
automation_alias: script
automation_uid: 5b4e0237da074764
cache: false
tags:
- draw
- graph
- from-json
- from-json-data
uid: 2ed1ebcb6be548fd
input_mapping:
input: CM_JSON_INPUT_FILE
json_input_file: CM_JSON_INPUT_FILE
output_image_path: CM_OUTPUT_IMAGE_PATH
deps:
- tags: get,python3
names:
- python
- python3
- tags: get,generic-python-lib,_package.networkx
- tags: get,generic-python-lib,_package.matplotlib
30 changes: 30 additions & 0 deletions script/draw-graph-from-json-data/customize.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
from cmind import utils
import os

def preprocess(i):

os_info = i['os_info']

env = i['env']

meta = i['meta']

automation = i['automation']

quiet = (env.get('CM_QUIET', False) == 'yes')

env['CM_RUN_CMD'] = f"""{env['CM_PYTHON_BIN_WITH_PATH']} {os.path.join(env['CM_TMP_CURRENT_SCRIPT_PATH'],"process-cm-deps.py")} {env['CM_JSON_INPUT_FILE']}"""

if env.get('CM_OUTPUT_IMAGE_PATH', '') != '':
env['CM_RUN_CMD'] += f""" --output_image {env['CM_OUTPUT_IMAGE_PATH']}"""

if env.get('CM_OUTPUT_MERMAID_PATH', '') != '':
env['CM_RUN_CMD'] += f""" --output_mermaid {env['CM_OUTPUT_MERMAID_PATH']}"""

return {'return':0}

def postprocess(i):

env = i['env']

return {'return':0}
97 changes: 97 additions & 0 deletions script/draw-graph-from-json-data/process-cm-deps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
import argparse
import networkx as nx
import matplotlib.pyplot as plt
import json

# Function to parse the nested JSON structure
def parse_json_to_edges(json_data):
edges = []
for root_key, nodes in json_data.items():
for node in nodes:
for node_key, node_details in node.items():
edges.append((node_details["parent"], node_key))
return edges

def generate_mermaid_output(json_data, mermaid_file="graph.mmd"):
edges = parse_json_to_edges(json_data)

# Start the Mermaid graph definition
mermaid_lines = ["graph TD"] # Use "TD" for top-down; "LR" for left-right

# Add each edge in Mermaid syntax
for parent, child in edges:
mermaid_lines.append(f""" {parent.replace(" ", "_")} --> {child.replace(" ", "_")}""")

# Write to a Mermaid file
with open(mermaid_file, "w") as f:
f.write("\n".join(mermaid_lines))

print(f"Mermaid syntax saved to {mermaid_file}")



# Function to generate and visualize the graph
def generate_graph_from_nested_json(json_data, output_image="graph.png"):
# Parse the JSON to extract edges
edges = parse_json_to_edges(json_data)

# Initialize a directed graph
G = nx.DiGraph()

# Add edges to the graph
G.add_edges_from(edges)

# Draw the graph using a spring layout for better visualization
plt.figure(figsize=(30, 25))
#pos = nx.spectral_layout(G, seed=42) # Seed for consistent layout
pos = nx.shell_layout(G) # Seed for consistent layout
nx.draw(
G,
pos,
with_labels=True,
node_size=7000,
node_color="skyblue",
font_size=9,
font_color="darkblue",
edge_color="gray",
arrowsize=20,
linewidths=1.5
)
plt.title("Parent-Child Graph from Nested JSON", fontsize=16)

# Save the visualization
plt.savefig(output_image, format="png", dpi=300)
print(f"Graph visualization saved as {output_image}")
#plt.show()

return G

# Function to export the graph data
def export_graph_data(graph, filename="graph.graphml"):
nx.write_graphml(graph, filename)
print(f"Graph data saved as {filename}")

# Main function to handle argument parsing and processing
def main():
parser = argparse.ArgumentParser(description="Generate a graph from nested JSON input.")
parser.add_argument("json_file", type=str, help="Path to the JSON input file.")
parser.add_argument("--output_image", type=str, default="graph.png", help="Output image file for the graph visualization.")
parser.add_argument("--output_mermaid", type=str, default="graph.mmd", help="Output mermaid file for the graph data.")
parser.add_argument("--output_graphml", type=str, default="graph.graphml", help="Output GraphML file for the graph data.")

args = parser.parse_args()

# Load the JSON input file
with open(args.json_file, "r") as f:
json_data = json.load(f)

# Generate the graph
G = generate_graph_from_nested_json(json_data, output_image=args.output_image)

generate_mermaid_output(json_data, mermaid_file="graph.mmd")

# Export the graph data
export_graph_data(G, filename=args.output_graphml)

if __name__ == "__main__":
main()
1 change: 1 addition & 0 deletions script/draw-graph-from-json-data/run.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
rem native script
17 changes: 17 additions & 0 deletions script/draw-graph-from-json-data/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/bin/bash

#CM Script location: ${CM_TMP_CURRENT_SCRIPT_PATH}

#To export any variable
#echo "VARIABLE_NAME=VARIABLE_VALUE" >>tmp-run-env.out

#${CM_PYTHON_BIN_WITH_PATH} contains the path to python binary if "get,python" is added as a dependency

echo "Running: "
echo "${CM_RUN_CMD}"
echo ""

if [[ ${CM_FAKE_RUN} != "yes" ]]; then
eval "${CM_RUN_CMD}"
test $? -eq 0 || exit 1
fi
Loading