Skip to content

Commit 3cc751f

Browse files
Add try_run and fix config of dtype_generalizer.py (#629)
* add try_run and fix config of dtype_generalizer.py * rm test.txt * fix default value of try_run * fix value of try_run * True for try_run
1 parent 247c957 commit 3cc751f

2 files changed

Lines changed: 17 additions & 19 deletions

File tree

graph_net/test/dtype_gen_test.sh

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,9 @@ python3 -m graph_net.apply_sample_pass \
3232
"output_dir": "$OUTPUT_DIR",
3333
"model_path_prefix": "$GRAPHNET_ROOT",
3434
"model_runnable_predicator_filepath": "$GRAPH_NET_ROOT/torch/constraint_util.py",
35-
"model_runnable_predicator_class_name": "RunModelPredicator",
36-
"model_runnable_predicator_config": {
37-
"use_dummy_inputs": true
38-
},
3935
"resume": true,
40-
"limits_handled_models": null
36+
"limits_handled_models": null,
37+
"try_run": true
4138
}
4239
EOF
4340
)

graph_net/torch/sample_pass/dtype_generalizer.py

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -236,8 +236,9 @@ class ApplyDataTypeGeneralizationPasses(SamplePass, ResumableSamplePassMixin):
236236
"output_dir": "/path/to/output",
237237
"model_path_prefix": "",
238238
"model_runnable_predicator_filepath": "...",
239-
"model_runnable_predicator_class_name": "...",
240-
"model_runnable_predicator_config": {...},
239+
"resume": ,
240+
"limits_handled_models": ,
241+
"try_run": ,
241242
}
242243
"""
243244

@@ -250,6 +251,9 @@ def __init__(self, config: Dict[str, Any]):
250251
raise ValueError("output_dir is required in config")
251252

252253
self.model_path_prefix = config.get("model_path_prefix", "")
254+
self.model_runnable_predicator_class_name = "RunModelPredicator"
255+
self.model_runnable_predicator_config = {"use_dummy_inputs": True}
256+
self.try_run = config.get("try_run", True)
253257

254258
# model_runnable_predicator is required to ensure generated code is runnable
255259
if "model_runnable_predicator_filepath" not in config:
@@ -264,21 +268,17 @@ def declare_config(
264268
output_dir: str,
265269
model_path_prefix: str,
266270
model_runnable_predicator_filepath: str,
267-
model_runnable_predicator_class_name: str,
268-
model_runnable_predicator_config: dict,
269271
resume: bool = False,
270272
limits_handled_models: int = None,
273+
try_run: bool = True,
271274
):
272275
pass
273276

274277
def _make_model_runnable_predicator(self, config: Dict[str, Any]):
275278
"""Create model runnable predicator from config."""
276279
module = load_module(config["model_runnable_predicator_filepath"])
277-
cls = getattr(
278-
module,
279-
config.get("model_runnable_predicator_class_name", "RunModelPredicator"),
280-
)
281-
predicator_config = config.get("model_runnable_predicator_config", {})
280+
cls = getattr(module, self.model_runnable_predicator_class_name)
281+
predicator_config = self.model_runnable_predicator_config
282282
return cls(predicator_config)
283283

284284
def sample_handled(self, rel_model_path: str) -> bool:
@@ -430,11 +430,12 @@ def _apply_pass_and_generate(
430430
self._update_sample_metadata(output_sample_dir, dtype)
431431

432432
# Validate generated sample (required - generated code must be runnable)
433-
if not self.model_runnable_predicator(str(output_sample_dir)):
434-
raise RuntimeError(
435-
f"Generated sample failed validation: {output_sample_dir}"
436-
)
437-
logging.info(f"Generated sample validated: {output_sample_dir}")
433+
if self.try_run:
434+
if not self.model_runnable_predicator(str(output_sample_dir)):
435+
raise RuntimeError(
436+
f"Generated sample failed validation: {output_sample_dir}"
437+
)
438+
logging.info(f"Generated sample validated: {output_sample_dir}")
438439

439440
return str(output_sample_dir)
440441

0 commit comments

Comments
 (0)