Commit 52a8302d authored by wangkaixiong's avatar wangkaixiong 🚴🏼
Browse files

torch_verify

parent 1d16c4e8
**/log
\ No newline at end of file
#!/bin/bash
pip3 config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple
pip3 install onnx-simplifier
pip3 install paddle2onnx
\ No newline at end of file
## 方法一
使用 `onnxsim` 转换;
安装包的步骤
```bash
pip install onnx-simplifier
```
```python
python -m onnxsim ../resnet50.onnx ../resnet50_1x3x224x224.onnx --test-input-shape input:1,3,224,224
# 查看详细帮助内容
python -m onnxsim -h
```
## 方法二
使用 `paddle2onnx` 去进行转换。
```python
pip3 install paddle2onnx
python -m paddle2onnx.optimize --input_model model.onnx \
--output_model new_model.onnx \
--input_shape_dict "{'x':[1,3,224,224]}"
```
\ No newline at end of file
# --fp16:使用半精度
# --onnx:模型路径
# --input-dim:模型输入维度
# @unique_ids_raw_output___9:0 1:标志位无需修改
# @segment_ids:0 256 256:第一个数为batch size,默认256;第二个数为序列长度,默认256
# @input_mask:0 256 256:第一个数为batch size,默认256;第二个数为序列长度,默认256
# @input_ids:0 256 256:第一个数为batch size,默认256;第二个数为序列长度,默认256
data=$(date +"%Y-%m-%d-%H-%M-%S")
logdir=/datasets/logs_comomm_model_infer/bert/${data}
logdir=./log/${data}
if [ ! -f ${logdir} ]; then
mkdir ${logdir} -p
fi
HIP_VISIBLE_DEVICES=0 /opt/dtk-24.04.1/bin/migraphx-driver perf -n 20 --fp16 --gpu --onnx ./weights/bertsquad-10.onnx \
--input-dim @unique_ids_raw_output___9:0 1 @segment_ids:0 256 256 @input_mask:0 256 256 @input_ids:0 256 256 \
2>&1 | tee ${logdir}/pert-bert-bs-256-seqlen-256.log
HIP_VISIBLE_DEVICES=0 \
/opt/dtk-24.04.1/bin/migraphx-driver perf -n 20 --fp16 --gpu \
--onnx ../resnet50.onnx \
--input-dim @input 1 3 224 224 \
2>&1 | tee ${logdir}/resnet.log
data=$(date +"%Y-%m-%d-%H-%M-%S")
logdir=./log/${data}
if [ ! -f ${logdir} ]; then
mkdir ${logdir} -p
fi
onnxruntime_perf_test -m times \
-e rocm \
-r 20 \
-o 1 \
-I \
../resnet50_1x3x224x224.onnx \
2>&1 | tee ${logdir}/resnet.log
\ No newline at end of file
下载地址:
https://cancon.hpccube.com:65024/4/main/migraphx
安装:
chmod +x migraphx.run
./migraphx.run
\ No newline at end of file
File added
......@@ -46,3 +46,24 @@ with open(synset_words_path, 'r') as f:
class_names = [line.strip() for line in synset_words]
predicted_class_name = class_names[predicted_class_idx+1] # 注意索引可能从1开始,所以+1
print(f"Predicted class name: {predicted_class_name}") # 彭布罗克,彭布罗克威尔士柯基犬
with torch.no_grad():
input_tensor = torch.ones((1,3,224,224), dtype=torch.float).to("cuda:0")
save_path = "./resnet50.onnx"
dynamic_shape = {
'input': {0: 'batch_size', 2: 'height', 3: 'width'},
'output': {0: 'batch_size', 1: 'n_class'}
}
torch.onnx.export(
model,
(input_tensor, ),
f=save_path,
verbose=False,
opset_version=17,
input_names=['input'],
output_names=['output'],
dynamic_axes=dynamic_shape,
)
print("export success")
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment