Skip to content
Open
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
63 changes: 63 additions & 0 deletions graph_net/test/level5_subgraph_dataset_test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
#!/bin/bash

GRAPH_NET_ROOT=$(python3 -c "import graph_net; import os; print(os.path.dirname(os.path.dirname(graph_net.__file__)))")
DECOMPOSE_PATH=$GRAPH_NET_ROOT/decompose_level5_100

mkdir -p "$DECOMPOSE_PATH"

model_list="$GRAPH_NET_ROOT/graph_net/config/torch_samples_list.txt"
# model_list="$GRAPH_NET_ROOT/graph_net/test/dev_model_list/tmp_torch_samples_list.txt"

# Split models into sequences
python3 -m graph_net.torch.typical_sequence_split_points \
--model-list "$model_list" \
--device "cuda" \
--window-size 10 \
--fold-policy default \
--fold-times 10 \
--output-json "$DECOMPOSE_PATH/split_results.json"

# Decompose models
decompose_config_json_str=$(cat <<EOF
{
"handler_path": "$GRAPH_NET_ROOT/graph_net/torch/graph_decomposer.py",
"handler_class_name": "RangeDecomposerExtractor",
"handler_config": {
"model_path_prefix": "$GRAPH_NET_ROOT",
"output_dir": "$DECOMPOSE_PATH",
"split_results_path": "$DECOMPOSE_PATH/split_results.json",
"group_head_and_tail": true,
"chain_style": false
}
}
EOF
)
DECOMPOSE_CONFIG=$(echo $decompose_config_json_str | base64 -w 0)

python3 -m graph_net.model_path_handler \
--model-path-list $model_list \
--handler-config=$DECOMPOSE_CONFIG \
--use-subprocess

# Rename graph variable
config_json_str=$(cat <<EOF
{
"handler_path": "$GRAPH_NET_ROOT/graph_net/torch/graph_variable_renamer.py",
"handler_class_name": "GraphVariableRenamer",
"handler_config": {
"model_path_prefix": "",
"data_input_predicator_filepath": "$GRAPH_NET_ROOT/graph_net/torch/constraint_util.py",
"data_input_predicator_class_name": "NaiveDataInputPredicator",
"model_runnable_predicator_filepath": "$GRAPH_NET_ROOT/graph_net/torch/constraint_util.py",
"model_runnable_predicator_class_name": "ModelRunnablePredicator",
"output_dir": "$DECOMPOSE_PATH/graph_variable_rename_workspace"
}
}
EOF
)
CONFIG=$(echo $config_json_str | base64 -w 0)

python3 -m graph_net.model_path_handler \
--model-path $DECOMPOSE_PATH \
--handler-config=$CONFIG \
--use-subprocess
7 changes: 7 additions & 0 deletions graph_net/torch/graph_decomposer.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from pathlib import Path
import torch
import json
import sys
from graph_net.torch.decompose_util import convert_to_submodules_graph
from graph_net.torch.extractor import GraphExtractor as BuiltinGraphExtractor
import graph_net.imp_util as imp_util
Expand Down Expand Up @@ -209,6 +210,12 @@ def __call__(self, rel_model_path):
)
model_path = os.path.join(self.config["model_path_prefix"], rel_model_path)
split_results = load_json(self.config["split_results_path"])
if (
split_results[rel_model_path]["split_positions"] is None
or len(split_results[rel_model_path]["split_positions"]) == 0
):
sys.stderr.write(f"Error: {rel_model_path} has no split positions.\n")
return
split_positions = split_results[rel_model_path]["split_positions"]
if self.config["resume"] and self._is_model_handled(
rel_model_path, split_positions
Expand Down
4 changes: 3 additions & 1 deletion graph_net/torch/typical_sequence_split_points.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,9 @@ def _resolve_token_to_ops(
return [f"Unknown({tid})"]

def _load_op_names_from_file(self, txt_path: Path) -> List[str]:
assert txt_path.exists(), f"{str(txt_path)=}"
if not txt_path.exists():
print(f"File not found: {txt_path}")
return []
return txt_path.read_text().split("\n")

def _calculate_token_lengths(
Expand Down