Skip to content

Commit 7dbb6e9

Browse files
committed
modify get fully fusible subgraph
1 parent e70b44b commit 7dbb6e9

File tree

2 files changed

+13
-38
lines changed

2 files changed

+13
-38
lines changed

graph_net/test/new_graph_decompose_and_look_for_fully_fusible_subgraph_test.sh

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -31,36 +31,3 @@ CONFIG=$(echo $config_json_str | base64 -w 0)
3131

3232
# python3 -m graph_net.model_path_handler --model-path $GRAPH_NET_ROOT/../samples/$MODEL_PATH_IN_SAMPLES --handler-config=$CONFIG
3333
python3 -m graph_net.model_path_handler --model-path-list $INPUT_MODEL_LIST --handler-config=$CONFIG
34-
35-
36-
# 1. 读取总输入数量 (通过计算输入模型列表文件中的行数)
37-
if [ ! -f "$INPUT_MODEL_LIST" ]; then
38-
echo "input dir $INPUT_MODEL_LIST not exist."
39-
TOTAL_INPUT_COUNT=0
40-
else
41-
# wc -l 计算行数, awk '{print $1}' 移除文件名
42-
TOTAL_INPUT_COUNT=$(wc -l < "$INPUT_MODEL_LIST")
43-
fi
44-
45-
# 2. 统计已产出文件夹数量
46-
if [ ! -d "$OUTPUT_DIR" ]; then
47-
echo "output dir $OUTPUT_DIR not exist."
48-
PRODUCED_COUNT=0
49-
else
50-
# 查找 OUTPUT_DIR 下的一级子目录数量
51-
# -mindepth 1: 忽略父目录本身
52-
# -maxdepth 1: 只查找一级目录
53-
# -type d: 只查找目录 (文件夹)
54-
PRODUCED_COUNT=$(find "$OUTPUT_DIR" -mindepth 1 -maxdepth 1 -type d | wc -l)
55-
fi
56-
57-
58-
echo "Total Input = $TOTAL_INPUT_COUNT"
59-
echo "Total Output = $PRODUCED_COUNT"
60-
61-
# 3. 计算产出率 (使用 bc 进行浮点数运算)
62-
if [ "$TOTAL_INPUT_COUNT" -gt 0 ]; then
63-
# scale=2 设置小数点后两位精度
64-
PRODUCTION_RATE=$(echo "scale=2; ($PRODUCED_COUNT * 100) / $TOTAL_INPUT_COUNT" | bc)
65-
echo "Production Rate = ${PRODUCTION_RATE}%"
66-
fi

graph_net/torch/fully_fusible_subgraph_extractor.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,14 +60,20 @@ def _get_sub_ranges(self):
6060
), f"Invalid range generated: start={start_pos}, end={end_pos}, max={self.config['max_nodes']}"
6161
yield start_pos, end_pos
6262

63-
def _handle_success(self, temp_dir: str, start_pos: int, end_pos: int) -> str:
64-
target_name = f"_start{start_pos}_end{end_pos}"
63+
def _handle_success(
64+
self, temp_dir: str, start_pos: int, end_pos: int, model_name
65+
) -> str:
66+
target_name = f"{model_name}_start{start_pos}_end{end_pos}"
6567
target_path = os.path.join(
6668
self.config["output_dir"],
6769
target_name,
6870
)
6971
os.makedirs(target_path, exist_ok=True)
70-
shutil.move(temp_dir, target_path)
72+
# shutil.move(temp_dir, target_path)
73+
for item in os.listdir(temp_dir):
74+
source = os.path.join(temp_dir, item)
75+
destination = os.path.join(target_path, item)
76+
shutil.move(source, destination)
7177
return target_path
7278

7379
def _build_decompose_config(
@@ -76,7 +82,7 @@ def _build_decompose_config(
7682
graph_net_root = os.path.dirname(graph_net.__file__)
7783

7884
check_fusible_config = {
79-
"handler_path": f"{graph_net_root}/torch/naive_graph_decomposer.py",
85+
"handler_path": f"{graph_net_root}/torch/graph_decomposer.py",
8086
"handler_class_name": "NaiveDecomposerExtractor",
8187
"handler_config": {
8288
"model_path_prefix": model_path_prefix,
@@ -105,7 +111,9 @@ def __call__(self, rel_model_path):
105111
)
106112
success = predicator(model_path)
107113
if success:
108-
target_path = self._handle_success(temp_dir, start_pos, end_pos)
114+
target_path = self._handle_success(
115+
temp_dir, start_pos, end_pos, os.path.basename(model_path)
116+
)
109117
print(
110118
f"SUCCESS in finding the biggest fully fusible subgraph. Result saved to: {target_path}"
111119
)

0 commit comments

Comments
 (0)