-
Notifications
You must be signed in to change notification settings - Fork 42
【Hackathon 9th Sprint No.86】feat: implement AgentUnittestGenerator for both paddle/torch run_model.py -part #422
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
Conversation
|
Thanks for your contribution! |
|
收到您的PR,感谢您的贡献。 |
|
整体还是很清晰的,PR说明很详细(赞),有几个小改进点:
|
graph_net/paddle/run_model.py
Outdated
| import unittest | ||
| import paddle | ||
| from graph_net.paddle import utils |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这是不可以的。单测脚本应该能脱离graph_net单独工作。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
已经按照建议进行修改,最新的提交中,生成的单侧脚本不再依赖graph_net
| encode_cfg() { | ||
| MODEL_PATH="$1" python - <<'PY' | ||
| import base64, json, os | ||
| cfg = { | ||
| "decorator_class_name": "AgentUnittestGenerator", | ||
| "decorator_config": { | ||
| "model_path": os.environ["MODEL_PATH"], | ||
| "force_device": "auto", | ||
| "output_path": None, | ||
| "use_dummy_inputs": False, | ||
| }, | ||
| } | ||
| print(base64.b64encode(json.dumps(cfg).encode()).decode()) | ||
| PY | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
已经按照建议进行修改了
… AgentUnittestGenerator, adopt jinja2 as render engine
|
使用precommit检查并修复了代码风格问题 |
| if not decorator_config: | ||
| return lambda model: model | ||
|
|
||
| class_name = decorator_config.get("decorator_class_name", "RunModelDecorator") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
run_model机制要求固定类型名RunModelDecorator和GraphModule,model_path_handler可以指定类型名,建议使用model_path_handler来运行,不要这么修改run_model。
| import torch | ||
| def _get_classes(file_path: str): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
实际上我们需要将样本model.py、xxx_meta.py的内容直接写到这个生成的单测文件里面,最后达到的效果是,你把这个单测文件给我我就直接能跑。
Summary
AgentUnittestGeneratorto both run_model entrypoints (run_model.py, run_model.py) to generate standalone unittest scripts frommodel.py+ meta files.jinja2.Templatefor codegen templating (placeholders: target device and dummy/numpy flags);<sample>_test.pybeside each sample.How to Use
python -m graph_net.torch.run_model --model-path /abs/path/to/sample --decorator-config <base64>python -m graph_net.paddle.run_model --model-path /abs/path/to/sample --decorator-config <base64>python <sample_name>_test.py.Validation (manual)
Notes
_get_decoratorstill accepts both argparse.Namespace and dict configs.Sample Artifact
resnet18_test.py
albert-base-v2_test.py