Skip to content

Commit 07eaab2

Browse files
lixinqiroll-away
andauthored
Check graph module fusible (#433)
* 1119 * 1120 * 1120.2 * model_path * remove unnecessary files and pre-committed * remove unnecessary files and pre-committed * 1121 remove unnecessary files * modify rev version * modify rev version * modify rev version * accuracy issues targeted * test script and modify feature * return set[str] * add logfile for test * filter can get the number of kernels in naive_graph_decomposer * post extract process feature * remove unnecessary code blocks and variables * modify the way of counting kernels used * modify the way of counting kernels used * modify script, rename files and variables * add failure protection and log output when removing directories * add a script to check fusability of a given model * add a script to check if a given model is fully fusable * add a script to check if a given model is fully fusable * a script to check if a given model is fully fusable * add a script to check if a given model is fully fusionable * add a script to find fully fusionable subgraph * find the biggest fully fusionable subgraph * get fusible subgraph test * modify get fully fusible subgraph * improve fully_fusible_subgraph_extractor.py efficiency * backup code * Improve efficiency of test/fully_fusible_subgraph_extractor_test.sh * check_graph_module_parsable --------- Co-authored-by: roll-away <[email protected]>
1 parent 9c02d0a commit 07eaab2

File tree

7 files changed

+224
-0
lines changed

7 files changed

+224
-0
lines changed
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
samples/timm/crossvit_small_240.in1k
2+
samples/timm/poolformerv2_s12.sail_in1k
3+
samples/timm/regnety_080.pycls_in1k
4+
samples/timm/dla46x_c.in1k
5+
samples/timm/mobilenetv1_100.ra4_e3600_r224_in1k
6+
samples/timm/efficientnetv2_rw_s.ra2_in1k
7+
samples/timm/vit_base_patch16_rope_ape_224.naver_in1k
8+
samples/timm/fastvit_t8.apple_dist_in1k
9+
samples/timm/test_byobnet.r160_in1k
10+
samples/timm/mambaout_base.in1k
11+
samples/timm/davit_small
12+
samples/timm/resnet61q.ra2_in1k
13+
samples/timm/coat_tiny
14+
samples/timm/regnetx_004.pycls_in1k
15+
samples/timm/convnextv2_large.fcmae
16+
samples/timm/regnety_640.seer
17+
samples/timm/repvit_m1_1.dist_300e_in1k
18+
samples/timm/tinynet_d.in1k
19+
samples/timm/resnetrs270.tf_in1k
20+
samples/timm/cait_m48_448
21+
samples/timm/legacy_seresnet50.in1k
22+
samples/timm/tinynet_a.in1k
23+
samples/timm/convnext_small.fb_in1k
24+
samples/timm/vit_huge_patch14_clip_quickgelu_224.dfn5b
25+
samples/timm/dpn131.mx_in1k
26+
samples/timm/convnextv2_large.fcmae_ft_in1k
27+
samples/timm/convnextv2_small
28+
samples/timm/repvit_m1.dist_in1k
29+
samples/timm/cs3darknet_s
30+
samples/timm/resnet50d.a1_in1k
31+
samples/timm/dm_nfnet_f6
32+
samples/timm/coatnet_1_rw_224
33+
samples/timm/lcnet_050.ra2_in1k
34+
samples/timm/efficientnet_em.ra2_in1k
35+
samples/timm/dpn48b
36+
samples/timm/semnasnet_075.rmsp_in1k
37+
samples/timm/skresnet34.ra_in1k
38+
samples/timm/crossvit_15_dagger_240.in1k
39+
samples/timm/mnasnet_100.rmsp_in1k
40+
samples/timm/mobilenetv3_rw.rmsp_in1k
41+
samples/timm/xception65p.ra3_in1k
42+
samples/timm/coatnet_0_rw_224
43+
samples/timm/eca_nfnet_l3
44+
samples/timm/deit3_base_patch16_224.fb_in1k
45+
samples/timm/mambaout_base_short_rw.sw_e500_in1k
46+
samples/timm/mobilenetv4_conv_small.e1200_r224_in1k
47+
samples/timm/xception71.tf_in1k
48+
samples/timm/dla60.in1k
49+
samples/timm/repghostnet_130.in1k
50+
samples/timm/mambaout_base_plus_rw.sw_e150_in12k
51+
samples/timm/poolformerv2_s36.sail_in1k
52+
samples/timm/deit3_huge_patch14_224.fb_in1k
53+
samples/timm/vit_base_patch32_clip_224.datacompxl
54+
samples/timm/poolformer_m48.sail_in1k
55+
samples/timm/regnety_006.pycls_in1k
56+
samples/timm/starnet_s4.in1k
57+
samples/timm/poolformer_m36.sail_in1k
58+
samples/timm/vit_huge_patch14_gap_224.in1k_ijepa
59+
samples/timm/efficientnet_b3.ra2_in1k
60+
samples/timm/mobilenetv3_large_150d.ra4_e3600_r256_in1k
61+
samples/timm/hgnetv2_b0.ssld_stage1_in22k_in1k
62+
samples/timm/convnextv2_huge.fcmae
63+
samples/timm/davit_huge
64+
samples/timm/regnetx_004_tv.tv2_in1k
65+
samples/timm/dla34.in1k
66+
samples/timm/convnext_xlarge.fb_in22k
67+
samples/timm/resmlp_12_224.fb_dino
68+
samples/timm/fasternet_t1.in1k
69+
samples/timm/resnetblur50.bt_in1k
70+
samples/timm/res2net50d.in1k
71+
samples/timm/vit_base_patch32_224.augreg_in1k
72+
samples/timm/mambaout_base_wide_rw.sw_e500_in1k
73+
samples/timm/vgg19_bn.tv_in1k
74+
samples/timm/vit_small_patch16_rope_ape_224.naver_in1k
75+
samples/timm/hardcorenas_b.miil_green_in1k
76+
samples/timm/vgg16.tv_in1k
77+
samples/timm/xception41p.ra3_in1k
78+
samples/timm/efficientnet_lite0.ra_in1k
79+
samples/timm/regnetv_064.ra3_in1k
80+
samples/timm/regnety_320.pycls_in1k
81+
samples/timm/convnext_pico.d1_in1k
82+
samples/timm/repvit_m1_0.dist_300e_in1k
83+
samples/timm/resnet50c.gluon_in1k
84+
samples/timm/mobileone_s4.apple_in1k
85+
samples/timm/ghostnet_100.in1k
86+
samples/timm/deit_base_distilled_patch16_384
87+
samples/timm/dpn68b.mx_in1k
88+
samples/timm/dla60_res2next
89+
samples/timm/resnet101d.gluon_in1k
90+
samples/timm/eva02_large_patch14_clip_224.merged2b
91+
samples/timm/fasternet_m.in1k
92+
samples/timm/mobilenetv2_110d.ra_in1k
93+
samples/timm/regnetx_064.pycls_in1k
94+
samples/timm/cspresnet50.ra_in1k
95+
samples/timm/resmlp_24_224.fb_dino
96+
samples/timm/mobileone_s3.apple_in1k
97+
samples/timm/mobileone_s2.apple_in1k
98+
samples/timm/res2net101d
99+
samples/timm/hardcorenas_f.miil_green_in1k
100+
samples/timm/hrnet_w18_ssld.paddle_in1k
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#samples/timm/crossvit_small_240.in1k
2+
#samples/timm/poolformerv2_s12.sail_in1k
3+
#samples/timm/regnety_080.pycls_in1k
4+
#samples/timm/dla46x_c.in1k
5+
#samples/timm/mobilenetv1_100.ra4_e3600_r224_in1k
6+
samples/timm/efficientnetv2_rw_s.ra2_in1k
7+
samples/timm/vit_base_patch16_rope_ape_224.naver_in1k
8+
#samples/timm/fastvit_t8.apple_dist_in1k
9+
#samples/timm/test_byobnet.r160_in1k
10+
#samples/timm/mambaout_base.in1k
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
samples/timm/aimv2_huge_patch14_224.apple_pt
2+
samples/timm/vit_so400m_patch14_siglip_gap_224.pali2_3b_pt
3+
samples/timm/eca_resnet33ts.ra2_in1k
4+
samples/timm/poolformer_s12.sail_in1k
5+
samples/timm/eva_giant_patch14_224.clip_ft_in1k
6+
samples/timm/eva02_base_patch14_224.mim_in22k
7+
samples/timm/eva02_small_patch14_224.mim_in22k
8+
samples/timm/poolformer_m36.sail_in1k
9+
samples/timm/poolformerv2_m36.sail_in1k
10+
samples/timm/resnest50d_1s4x24d.in1k
11+
samples/timm/aimv2_1b_patch14_224.apple_pt
12+
samples/timm/poolformer_m48.sail_in1k
13+
samples/timm/poolformer_s36.sail_in1k
14+
samples/timm/vit_base_patch16_siglip_gap_224.v2_webli
15+
samples/timm/vit_giant_patch16_gap_224.in22k_ijepa
16+
samples/timm/ecaresnet101d.miil_in1k
17+
samples/timm/vit_huge_patch14_gap_224.in1k_ijepa
18+
samples/timm/aimv2_3b_patch14_224.apple_pt
19+
samples/timm/skresnet18.ra_in1k
20+
samples/timm/ecaresnetlight.miil_in1k
21+
samples/timm/eca_resnext26ts.ch_in1k
22+
samples/timm/skresnext50_32x4d.ra_in1k
23+
samples/timm/poolformerv2_m48.sail_in1k
24+
samples/timm/poolformer_s24.sail_in1k
25+
samples/timm/ecaresnet26t.ra2_in1k
26+
samples/timm/eva02_large_patch14_224.mim_in22k
27+
samples/timm/ecaresnet50d.miil_in1k
28+
samples/timm/poolformerv2_s36.sail_in1k
29+
samples/timm/aimv2_large_patch14_224.apple_pt
30+
samples/timm/skresnet34.ra_in1k
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#!/bin/bash
2+
3+
GRAPH_NET_ROOT=$(python3 -c "import graph_net; import os; print(
4+
os.path.dirname(graph_net.__file__))")
5+
6+
# input model path
7+
# model_runnable_predicator=ShapePropagatablePredicator
8+
model_runnable_predicator=ModelRunnablePredicator
9+
config_json_str=$(cat <<EOF
10+
{
11+
"handler_path": "$GRAPH_NET_ROOT/torch/check_graph_module_parsable.py",
12+
"handler_class_name": "CheckGraphModuleParsable",
13+
"handler_config": {
14+
"model_path_prefix": "$GRAPH_NET_ROOT/../",
15+
"resume": true,
16+
"limits_handled_models": 999999,
17+
"output_dir": "/tmp/check_graph_module_parsable"
18+
}
19+
}
20+
EOF
21+
)
22+
CONFIG=$(echo $config_json_str | base64 -w 0)
23+
24+
python3 -m graph_net.model_path_handler --model-path-list $GRAPH_NET_ROOT/test/dev_model_list/graph_module_parse_error_torch_sample_list.txt --handler-config=$CONFIG --use-subprocess
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
from pathlib import Path
2+
from graph_net.torch.fx_graph_cache_util import (
3+
parse_immutable_model_path_into_sole_graph_module,
4+
)
5+
import os
6+
import sys
7+
8+
9+
class CheckGraphModuleParsable:
10+
def __init__(self, config=None):
11+
if config is None:
12+
config = {}
13+
self.config = self._make_config(**config)
14+
self.num_handled_models = 0
15+
16+
def _make_config(
17+
self,
18+
model_path_prefix,
19+
output_dir,
20+
resume=False,
21+
limits_handled_models=None,
22+
):
23+
return {
24+
"model_path_prefix": model_path_prefix,
25+
"output_dir": output_dir,
26+
"resume": resume,
27+
"limits_handled_models": limits_handled_models,
28+
}
29+
30+
def __call__(self, rel_model_path):
31+
model_path = os.path.join(self.config["model_path_prefix"], rel_model_path)
32+
if self.config["resume"] and self._is_model_path_handled(rel_model_path):
33+
return
34+
parse_immutable_model_path_into_sole_graph_module(model_path)
35+
output_dir = Path(self.config["output_dir"]) / rel_model_path
36+
output_dir.mkdir(parents=True, exist_ok=True)
37+
self._inc_num_handled_models()
38+
39+
def _is_model_path_handled(self, rel_model_path):
40+
return (Path(self.config["output_dir"]) / rel_model_path).exists()
41+
42+
def _inc_num_handled_models(self):
43+
self.num_handled_models += 1
44+
limits = self.config["limits_handled_models"]
45+
if limits is not None:
46+
if self.num_handled_models >= limits:
47+
print(
48+
"`num_handled_models` exceeds config `limits_handled_models`",
49+
file=sys.stderr,
50+
)
51+
sys.exit(0)

graph_net/torch/graph_decomposer.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,10 +259,19 @@ def _get_model_path(self):
259259
self.model_name,
260260
)
261261

262+
def _get_model_path(self):
263+
return os.path.join(
264+
self.config["output_dir"],
265+
f"{self.parent_graph_name}_decomposed",
266+
self.model_name,
267+
)
268+
262269
def forward(self, *args):
270+
logger.warning("naive decomposer forwarding")
263271
if not self.extracted:
264272
if self.need_extract(self.submodule, args):
265273
self.builtin_extractor(self.submodule, args)
274+
self._post_extract_process()
266275
self.extracted = True
267276
return self.submodule(*args)
268277

model_100_list.txt

Whitespace-only changes.

0 commit comments

Comments
 (0)