Skip to content
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

[PaddleV3] 修复部分依赖 paddle.fluid 的 pytorch 模型 #1065

Merged
merged 26 commits into from
Oct 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 4 additions & 11 deletions test_benchmark/PyTorch/AlexNet/pd_infer.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from __future__ import print_function
import paddle.fluid as fluid
import paddle
import sys
import os
Expand All @@ -16,11 +15,8 @@
# trace
paddle.enable_static()
exe = paddle.static.Executor(paddle.CPUPlace())
[prog, inputs, outputs] = fluid.io.load_inference_model(
dirname="pd_model_trace/inference_model/",
executor=exe,
model_filename="model.pdmodel",
params_filename="model.pdiparams")
[prog, inputs, outputs] = paddle.static.load_inference_model(
path_prefix="pd_model_trace/inference_model/model", executor=exe)
result = exe.run(prog, feed={inputs[0]: input_data}, fetch_list=outputs)
df = pytorch_output - result
if numpy.max(numpy.fabs(df)) > 1e-04:
Expand All @@ -31,11 +27,8 @@
# script
paddle.enable_static()
exe = paddle.static.Executor(paddle.CPUPlace())
[prog, inputs, outputs] = fluid.io.load_inference_model(
dirname="pd_model_script/inference_model/",
executor=exe,
model_filename="model.pdmodel",
params_filename="model.pdiparams")
[prog, inputs, outputs] = paddle.static.load_inference_model(
path_prefix="pd_model_script/inference_model/model", executor=exe)
result = exe.run(prog, feed={inputs[0]: input_data}, fetch_list=outputs)
df = pytorch_output - result
if numpy.max(numpy.fabs(df)) > 1e-05:
Expand Down
1 change: 0 additions & 1 deletion test_benchmark/PyTorch/BASNet/deploy_infer.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

import numpy as np
import paddle
import paddle.fluid as fluid
from paddle.inference import Config
from paddle.inference import create_predictor

Expand Down
9 changes: 3 additions & 6 deletions test_benchmark/PyTorch/BASNet/pd_infer.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from __future__ import print_function
import paddle.fluid as fluid

import paddle
import sys
import os
Expand All @@ -16,11 +16,8 @@
# trace
paddle.enable_static()
exe = paddle.static.Executor(paddle.CPUPlace())
[prog, inputs, outputs] = fluid.io.load_inference_model(
dirname="pd_model_trace/inference_model/",
executor=exe,
model_filename="model.pdmodel",
params_filename="model.pdiparams")
[prog, inputs, outputs] = paddle.static.load_inference_model(
path_prefix="pd_model_trace/inference_model/model", executor=exe)
result = exe.run(prog, feed={inputs[0]: input_data}, fetch_list=outputs)
result_string = "Trace Successed"
for i in range(len(result)):
Expand Down
1 change: 0 additions & 1 deletion test_benchmark/PyTorch/DBFace/deploy_infer.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

import numpy as np
import paddle
import paddle.fluid as fluid
from paddle.inference import Config
from paddle.inference import create_predictor

Expand Down
9 changes: 3 additions & 6 deletions test_benchmark/PyTorch/DBFace/pd_infer.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from __future__ import print_function
import paddle.fluid as fluid

import paddle
import common
import numpy as np
Expand All @@ -23,11 +23,8 @@
# trace
paddle.enable_static()
exe = paddle.static.Executor(paddle.CPUPlace())
[prog, inputs, outputs] = fluid.io.load_inference_model(
dirname="pd_model_trace/inference_model/",
executor=exe,
model_filename="model.pdmodel",
params_filename="model.pdiparams")
[prog, inputs, outputs] = paddle.static.load_inference_model(
path_prefix="pd_model_trace/inference_model/model", executor=exe)
result = exe.run(prog, feed={inputs[0]: image}, fetch_list=outputs)

df0 = pytorch_output["hm"] - result[0]
Expand Down
1 change: 0 additions & 1 deletion test_benchmark/PyTorch/EDSR/deploy_infer.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

import numpy as np
import paddle
import paddle.fluid as fluid
from paddle.inference import Config
from paddle.inference import create_predictor

Expand Down
16 changes: 5 additions & 11 deletions test_benchmark/PyTorch/EDSR/pd_infer.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from __future__ import print_function
import paddle.fluid as fluid

import paddle
import sys
import os
Expand All @@ -13,11 +13,8 @@
# trace
paddle.enable_static()
exe = paddle.static.Executor(paddle.CPUPlace())
[prog, inputs, outputs] = fluid.io.load_inference_model(
dirname="pd_model_trace/inference_model/",
executor=exe,
model_filename="model.pdmodel",
params_filename="model.pdiparams")
[prog, inputs, outputs] = paddle.static.load_inference_model(
path_prefix="pd_model_trace/inference_model/model", executor=exe)
result = exe.run(prog, feed={inputs[0]: img}, fetch_list=outputs)
df = pytorch_output - result
if np.max(np.fabs(df)) > 1e-03:
Expand All @@ -28,11 +25,8 @@
# script
paddle.enable_static()
exe = paddle.static.Executor(paddle.CPUPlace())
[prog, inputs, outputs] = fluid.io.load_inference_model(
dirname="pd_model_script/inference_model/",
executor=exe,
model_filename="model.pdmodel",
params_filename="model.pdiparams")
[prog, inputs, outputs] = paddle.static.load_inference_model(
path_prefix="pd_model_script/inference_model/model", executor=exe)
result = exe.run(prog, feed={inputs[0]: img}, fetch_list=outputs)
df = pytorch_output - result
if np.max(np.fabs(df)) > 1e-03:
Expand Down
1 change: 0 additions & 1 deletion test_benchmark/PyTorch/ElectraModel/deploy_infer.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

import numpy as np
import paddle
import paddle.fluid as fluid
from paddle.inference import Config
from paddle.inference import create_predictor

Expand Down
10 changes: 4 additions & 6 deletions test_benchmark/PyTorch/ElectraModel/pd_infer.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from __future__ import print_function
import paddle.fluid as fluid

import paddle
import sys
import os
Expand All @@ -22,11 +22,9 @@ def rel_err(x, y):
try:
paddle.enable_static()
exe = paddle.static.Executor(paddle.CPUPlace())
[prog, inputs, outputs
] = fluid.io.load_inference_model(dirname="pd_model/inference_model/",
executor=exe,
model_filename="model.pdmodel",
params_filename="model.pdiparams")
[prog, inputs, outputs] = paddle.static.load_inference_model(
path_prefix="pd_model/inference_model/model", executor=exe)

result = exe.run(prog,
feed={
inputs[0]: input_data["input_ids"],
Expand Down
1 change: 0 additions & 1 deletion test_benchmark/PyTorch/FlaubertModel/deploy_infer.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

import numpy as np
import paddle
import paddle.fluid as fluid
from paddle.inference import Config
from paddle.inference import create_predictor

Expand Down
10 changes: 4 additions & 6 deletions test_benchmark/PyTorch/FlaubertModel/pd_infer.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from __future__ import print_function
import paddle.fluid as fluid

import paddle
import sys
import os
Expand All @@ -22,11 +22,9 @@ def rel_err(x, y):
try:
paddle.enable_static()
exe = paddle.static.Executor(paddle.CPUPlace())
[prog, inputs, outputs
] = fluid.io.load_inference_model(dirname="pd_model/inference_model/",
executor=exe,
model_filename="model.pdmodel",
params_filename="model.pdiparams")
[prog, inputs, outputs] = paddle.static.load_inference_model(
path_prefix="pd_model/inference_model/model", executor=exe)

result = exe.run(prog,
feed={
inputs[0]: input_data["input_ids"],
Expand Down
1 change: 0 additions & 1 deletion test_benchmark/PyTorch/InceptionV3/deploy_infer.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

import numpy as np
import paddle
import paddle.fluid as fluid
from paddle.inference import Config
from paddle.inference import create_predictor

Expand Down
16 changes: 5 additions & 11 deletions test_benchmark/PyTorch/InceptionV3/pd_infer.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from __future__ import print_function
import paddle.fluid as fluid

import paddle
import sys
import os
Expand All @@ -22,11 +22,8 @@ def rel_err(x, y):
# trace
paddle.enable_static()
exe = paddle.static.Executor(paddle.CPUPlace())
[prog, inputs, outputs] = fluid.io.load_inference_model(
dirname="pd_model_trace/inference_model/",
executor=exe,
model_filename="model.pdmodel",
params_filename="model.pdiparams")
[prog, inputs, outputs] = paddle.static.load_inference_model(
path_prefix="pd_model_trace/inference_model/model", executor=exe)
result = exe.run(prog, feed={inputs[0]: input_data}, fetch_list=outputs)
df = pytorch_output - result[0]
if numpy.max(numpy.fabs(df)) > 1e-04:
Expand All @@ -37,11 +34,8 @@ def rel_err(x, y):
# script
paddle.enable_static()
exe = paddle.static.Executor(paddle.CPUPlace())
[prog, inputs, outputs] = fluid.io.load_inference_model(
dirname="pd_model_script/inference_model/",
executor=exe,
model_filename="model.pdmodel",
params_filename="model.pdiparams")
[prog, inputs, outputs] = paddle.static.load_inference_model(
path_prefix="pd_model_script/inference_model/model", executor=exe)
result = exe.run(prog, feed={inputs[0]: input_data}, fetch_list=outputs)
df = pytorch_output - result[0]
if numpy.max(numpy.fabs(df)) > 1e-04:
Expand Down
1 change: 0 additions & 1 deletion test_benchmark/PyTorch/MNasNet/deploy_infer.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

import numpy as np
import paddle
import paddle.fluid as fluid
from paddle.inference import Config
from paddle.inference import create_predictor

Expand Down
16 changes: 5 additions & 11 deletions test_benchmark/PyTorch/MNasNet/pd_infer.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from __future__ import print_function
import paddle.fluid as fluid

import paddle
import sys
import os
Expand All @@ -22,11 +22,8 @@ def rel_err(x, y):
# trace
paddle.enable_static()
exe = paddle.static.Executor(paddle.CPUPlace())
[prog, inputs, outputs] = fluid.io.load_inference_model(
dirname="pd_model_trace/inference_model/",
executor=exe,
model_filename="model.pdmodel",
params_filename="model.pdiparams")
[prog, inputs, outputs] = paddle.static.load_inference_model(
path_prefix="pd_model_trace/inference_model/model", executor=exe)
result = exe.run(prog, feed={inputs[0]: input_data}, fetch_list=outputs)
df = pytorch_output - result[0]
if numpy.max(numpy.fabs(df)) > 1e-04:
Expand All @@ -37,11 +34,8 @@ def rel_err(x, y):
# script
paddle.enable_static()
exe = paddle.static.Executor(paddle.CPUPlace())
[prog, inputs, outputs] = fluid.io.load_inference_model(
dirname="pd_model_script/inference_model/",
executor=exe,
model_filename="model.pdmodel",
params_filename="model.pdiparams")
[prog, inputs, outputs] = paddle.static.load_inference_model(
path_prefix="pd_model_script/inference_model/model", executor=exe)
result = exe.run(prog, feed={inputs[0]: input_data}, fetch_list=outputs)
df = pytorch_output - result[0]
if numpy.max(numpy.fabs(df)) > 1e-04:
Expand Down
1 change: 0 additions & 1 deletion test_benchmark/PyTorch/MobileNetV2/deploy_infer.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

import numpy as np
import paddle
import paddle.fluid as fluid
from paddle.inference import Config
from paddle.inference import create_predictor

Expand Down
16 changes: 5 additions & 11 deletions test_benchmark/PyTorch/MobileNetV2/pd_infer.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from __future__ import print_function
import paddle.fluid as fluid

import paddle
import sys
import os
Expand All @@ -22,11 +22,8 @@ def rel_err(x, y):
# trace
paddle.enable_static()
exe = paddle.static.Executor(paddle.CPUPlace())
[prog, inputs, outputs] = fluid.io.load_inference_model(
dirname="pd_model_trace/inference_model/",
executor=exe,
model_filename="model.pdmodel",
params_filename="model.pdiparams")
[prog, inputs, outputs] = paddle.static.load_inference_model(
path_prefix="pd_model_trace/inference_model/model", executor=exe)
result = exe.run(prog, feed={inputs[0]: input_data}, fetch_list=outputs)
df = pytorch_output - result[0]
if numpy.max(numpy.fabs(df)) > 1e-04:
Expand All @@ -37,11 +34,8 @@ def rel_err(x, y):
# script
paddle.enable_static()
exe = paddle.static.Executor(paddle.CPUPlace())
[prog, inputs, outputs] = fluid.io.load_inference_model(
dirname="pd_model_script/inference_model/",
executor=exe,
model_filename="model.pdmodel",
params_filename="model.pdiparams")
[prog, inputs, outputs] = paddle.static.load_inference_model(
path_prefix="pd_model_script/inference_model/model", executor=exe)
result = exe.run(prog, feed={inputs[0]: input_data}, fetch_list=outputs)
df = pytorch_output - result[0]
if numpy.max(numpy.fabs(df)) > 1e-04:
Expand Down
1 change: 0 additions & 1 deletion test_benchmark/PyTorch/ResNet18/deploy_infer.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

import numpy as np
import paddle
import paddle.fluid as fluid
from paddle.inference import Config
from paddle.inference import create_predictor

Expand Down
16 changes: 5 additions & 11 deletions test_benchmark/PyTorch/ResNet18/pd_infer.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from __future__ import print_function
import paddle.fluid as fluid

import paddle
import sys
import os
Expand All @@ -22,11 +22,8 @@ def rel_err(x, y):
# trace
paddle.enable_static()
exe = paddle.static.Executor(paddle.CPUPlace())
[prog, inputs, outputs] = fluid.io.load_inference_model(
dirname="pd_model_trace/inference_model/",
executor=exe,
model_filename="model.pdmodel",
params_filename="model.pdiparams")
[prog, inputs, outputs] = paddle.static.load_inference_model(
path_prefix="pd_model_trace/inference_model/model", executor=exe)
result = exe.run(prog, feed={inputs[0]: input_data}, fetch_list=outputs)
df = pytorch_output - result[0]
if numpy.max(numpy.fabs(df)) > 1e-04:
Expand All @@ -37,11 +34,8 @@ def rel_err(x, y):
# script
paddle.enable_static()
exe = paddle.static.Executor(paddle.CPUPlace())
[prog, inputs, outputs] = fluid.io.load_inference_model(
dirname="pd_model_script/inference_model/",
executor=exe,
model_filename="model.pdmodel",
params_filename="model.pdiparams")
[prog, inputs, outputs] = paddle.static.load_inference_model(
path_prefix="pd_model_script/inference_model/model", executor=exe)
result = exe.run(prog, feed={inputs[0]: input_data}, fetch_list=outputs)
df = pytorch_output - result[0]
if numpy.max(numpy.fabs(df)) > 1e-04:
Expand Down
1 change: 0 additions & 1 deletion test_benchmark/PyTorch/ResNet18_2/deploy_infer.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

import numpy as np
import paddle
import paddle.fluid as fluid
from paddle.inference import Config
from paddle.inference import create_predictor

Expand Down
9 changes: 3 additions & 6 deletions test_benchmark/PyTorch/ResNet18_2/pd_infer.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import paddle
import paddle.fluid as fluid

import numpy as np
import pickle
import sys
Expand All @@ -11,11 +11,8 @@
paddle.enable_static()
exe = paddle.static.Executor(paddle.CPUPlace())
# test trace
[prog, inputs, outputs] = fluid.io.load_inference_model(
dirname="pd_model_trace/inference_model/",
executor=exe,
model_filename="model.pdmodel",
params_filename="model.pdiparams")
[prog, inputs, outputs] = paddle.static.load_inference_model(
path_prefix="pd_model_trace/inference_model/model", executor=exe)
data = np.load('../dataset/ResNet18_2/input.npy')
result = exe.run(prog, feed={inputs[0]: data}, fetch_list=outputs)

Expand Down
Loading