Are you sure you want to delete this task? Once this task is deleted, it cannot be recovered.
“sunxiyin” 891160e98f | 1 year ago | |
---|---|---|
.. | ||
__pycache__ | 1 year ago | |
common | 1 year ago | |
pytorch_cases/demo | 1 year ago | |
README.md | 1 year ago | |
__init__.py | 1 year ago | |
conftest.py | 1 year ago | |
env_set.source | 1 year ago | |
pytest.ini | 1 year ago | |
requirements.txt | 1 year ago |
MSAdapter工具配套测试框架
1)安装MSAdapter
参考:https://openi.pcl.ac.cn/OpenI/MSAdapter
2)安装依赖包
cd /msadapterut/solution_test/
pip3 install requirements.txt
注:如需安装MindSpore2.0,请自行安装
3)执行环境变量脚本
cd /msadapterut/solution_test/
source env_set.source
4)编写测试用例yaml文件
详情参考demo目录:test_msadapter_ops_conv2d_demo.yaml
用来设置输入数据、参数、参数约束、对比精度的配置
5)编写测试用例
详情参考demo目录:test_msadapter_ops_conv2d_demo.py、test_msadapter_ops_tensor_add_demo.py
其中包含test_run()、setup()和teardown()三个部分:
test_run()---为用例测试场景执行模块;
setup()---初始化测试框架,用例运行前执行;
teardown()---释放资源,用例运行后执行;
一般情况setup()和teardown()可以不做变动,仅仅改动用例名即可。
6)执行用例
pytest -s test_msadapter_ops_conv2d_demo.py
1)多次执行命令
pytest -s test_msadapter_ops_conv2d_demo.py --count {times}
eg: pytest -s test_msadapter_ops_conv2d_demo.py --count 50
op_name:算子名称
input_shape: 输入shape
input_1:
input_shape: [1, 3, 32, 32]
dtype: float32
#当需要多输入时可以进行依次添加
input_2:
input_shape: 1, 3, 32, 32], [2], [1, 2 #支持多组shape值,随机选取指定shape其中
dtype: float32,float16,int32 #支持不同数据类型,生成的数据在dtype中随机选取
#当输入shape需要在给定范围内随机生成:
参考demo/tensor_add/test_msadapter_ops_tensor_add_demo.yaml
input_3:
support_dim: 1, 2, 3 #表示生成shape的维度
each_dim_range: 5, 10], [10, 256], [1, 10 #表示生成shape的每一维度的取值范围,按维度顺序取值
#1维取值范围[5, 10],2维取值范围[10, 256],2维取值范围[1, 10]
args: 对应各个算子入参
support_type: 支持参数数据类型,list类型
support_value_range: 支持参数范围,list类型
support_value_length: 支持维度,int类型
示例:
kernel_size: #参数名kernel_size
support_type: ["int", "tuple"] #表示支持int、tuple类型
support_value_range: {"int": [1, 10], "tuple": [1, 10]} #表示各个类型取值范围是[1, 10]
support_value_length: {"tuple": {2}} #表示tuple类型只支持2维
支持参数配置指定tensor数据和类型:
args:
weight: #参数名weight
support_type: ["numpy"] #参数weight支持tensor
numpy_shape: 5, 10], [10, 30, 256], [1, 10, 10, 10, 10], [1, 10, 128, 128#参数weight支持tensor的shape
numpy_type: ["float32", "float16"] #表示支持float32、float16类型
具体使用示例可参考用例demo/CrossEntropyLoss/
默认精度为:
"float16": 1e-3,"float32": 1e-4,"float64": 1e-5,
"complex64": 2e-6,"complex128": 2e-10
自定义精度:
atol: 1e-5
rtol: 1e-5
#当参数、输入数据等相互有约束和限制时,可以自定义规则,在上述范围内进行再赋值。
#variation: 约束规则,按照variation序号顺序执行, 执行格式: params[{参数}]={自定义约束}
示例:
#约束1:in_channels值必须为groups的整数倍
#约束2:out_channels必须为in_channels的2倍
#约束3:weight1必须为输入数据shape值的第二维
#约束4:自定义参数数据,指定kernel_size取值为(1, 10), 1, (10, 10)
variation1: params["in_channels"]=params["groups"]*random.randint(1, 10)
variation2: params["out_channels"]=params["in_channels"]*2
variation3: params["weight1"]=params["input_1"]["input_shape"][1]
variation3: params["kernel_size"]=random.choice([(1, 10), 1, (10, 10)]])
在用例中调用perf_data_compare()方法,传入网络和数据,输出对比结果
对比结果:torch_profile_data < {contrast_multiple} * ms_profile_data,{contrast_multiple}默认值为0.9,可在yaml中配置
参考用例:test_msadapter_ops_tensor_add_demo.py
# 对比性能
assert self.perf_data_compare(py_net, ms_net, torch_input_shape_list, ms_input_shape_list)
注意:性能结果依赖profile支持情况,目前MindSpore不支持CPU上profile使用
No Description
Python Shell Text
Dear OpenI User
Thank you for your continuous support to the Openl Qizhi Community AI Collaboration Platform. In order to protect your usage rights and ensure network security, we updated the Openl Qizhi Community AI Collaboration Platform Usage Agreement in January 2024. The updated agreement specifies that users are prohibited from using intranet penetration tools. After you click "Agree and continue", you can continue to use our services. Thank you for your cooperation and understanding.
For more agreement content, please refer to the《Openl Qizhi Community AI Collaboration Platform Usage Agreement》