From 4472abd062ccee5f626cbd96096c958931f67a3e Mon Sep 17 00:00:00 2001 From: Zeref996 <825276847@qq.com> Date: Fri, 6 Sep 2024 11:44:42 +0800 Subject: [PATCH] fix plt tools, test=model --- framework/e2e/PaddleLT_new/binary_search.py | 4 +- framework/e2e/PaddleLT_new/db/layer_db.py | 4 +- .../PaddleLT_new/debug/infer_debug_dropout.py | 145 ++++++++++++++++++ .../diy/data/single_img_dataset.py | 2 +- .../diy/data/struct_img_dataset.py | 2 +- .../e2e/PaddleLT_new/engine/paddle_eval.py | 4 +- .../e2e/PaddleLT_new/engine/paddle_eval_bm.py | 6 +- .../e2e/PaddleLT_new/engine/paddle_export.py | 2 +- .../e2e/PaddleLT_new/engine/paddle_infer.py | 2 +- .../e2e/PaddleLT_new/engine/paddle_train.py | 2 +- .../PaddleLT_new/engine/paddle_train_bm.py | 6 +- .../e2e/PaddleLT_new/engine/torch_eval_bm.py | 4 +- .../PaddleLT_new/generator/builder_data.py | 2 +- framework/e2e/PaddleLT_new/layertest.py | 6 +- .../PaddleLT_new/{tools => pltools}/alarm.py | 0 .../{tools => pltools}/case_select.py | 2 +- .../{tools => pltools}/json_loader.py | 0 .../PaddleLT_new/{tools => pltools}/logger.py | 0 .../{tools => pltools}/np_tool.py | 0 .../{tools => pltools}/res_save.py | 0 .../{tools => pltools}/statistics.py | 0 .../{tools => pltools}/upload_bos.py | 0 .../{tools => pltools}/yaml_loader.py | 0 framework/e2e/PaddleLT_new/run.py | 16 +- .../e2e/PaddleLT_new/strategy/compare.py | 2 +- 25 files changed, 178 insertions(+), 33 deletions(-) create mode 100644 framework/e2e/PaddleLT_new/debug/infer_debug_dropout.py rename framework/e2e/PaddleLT_new/{tools => pltools}/alarm.py (100%) rename framework/e2e/PaddleLT_new/{tools => pltools}/case_select.py (97%) rename framework/e2e/PaddleLT_new/{tools => pltools}/json_loader.py (100%) rename framework/e2e/PaddleLT_new/{tools => pltools}/logger.py (100%) rename framework/e2e/PaddleLT_new/{tools => pltools}/np_tool.py (100%) rename framework/e2e/PaddleLT_new/{tools => pltools}/res_save.py (100%) rename framework/e2e/PaddleLT_new/{tools => pltools}/statistics.py (100%) rename framework/e2e/PaddleLT_new/{tools => pltools}/upload_bos.py (100%) rename framework/e2e/PaddleLT_new/{tools => pltools}/yaml_loader.py (100%) diff --git a/framework/e2e/PaddleLT_new/binary_search.py b/framework/e2e/PaddleLT_new/binary_search.py index f3a2902def..1684ca1fc6 100644 --- a/framework/e2e/PaddleLT_new/binary_search.py +++ b/framework/e2e/PaddleLT_new/binary_search.py @@ -13,8 +13,8 @@ import numpy as np from layertest import LayerTest from strategy.compare import perf_compare -from tools.logger import Logger -from tools.res_save import save_pickle +from pltools.logger import Logger +from pltools.res_save import save_pickle def get_commits(start, end): diff --git a/framework/e2e/PaddleLT_new/db/layer_db.py b/framework/e2e/PaddleLT_new/db/layer_db.py index 9e90f5d219..6976b10686 100644 --- a/framework/e2e/PaddleLT_new/db/layer_db.py +++ b/framework/e2e/PaddleLT_new/db/layer_db.py @@ -15,8 +15,8 @@ from db.snapshot import Snapshot # from strategy.compare import perf_compare -from tools.logger import Logger -from tools.res_save import xlsx_save +from pltools.logger import Logger +from pltools.res_save import xlsx_save class LayerBenchmarkDB(object): diff --git a/framework/e2e/PaddleLT_new/debug/infer_debug_dropout.py b/framework/e2e/PaddleLT_new/debug/infer_debug_dropout.py new file mode 100644 index 0000000000..c473f745d1 --- /dev/null +++ b/framework/e2e/PaddleLT_new/debug/infer_debug_dropout.py @@ -0,0 +1,145 @@ +import os +import numpy as np +import paddle +import paddle.inference as paddle_infer + + +class LayerCase(paddle.nn.Layer): + def __init__(self): + super().__init__() + self.parameter_0 = self.create_parameter( + shape=[2048], + dtype=paddle.float32, + ) + self.parameter_1 = self.create_parameter( + shape=[1024], + dtype=paddle.float32, + ) + self.parameter_2 = self.create_parameter( + shape=[1024], + dtype=paddle.float32, + ) + self.parameter_3 = self.create_parameter( + shape=[1024], + dtype=paddle.float32, + ) + self.parameter_4 = self.create_parameter( + shape=[1024], + dtype=paddle.float32, + ) + self.parameter_5 = self.create_parameter( + shape=[1024], + dtype=paddle.float32, + ) + self.parameter_6 = self.create_parameter( + shape=[2048, 1024], + dtype=paddle.float32, + ) + self.parameter_7 = self.create_parameter( + shape=[1024, 2048], + dtype=paddle.float32, + ) + + def forward( + self, + var_0, # (shape: [1, 169, 1024], dtype: paddle.float32, stop_gradient: False) + var_1, # (shape: [1, 169, 1024], dtype: paddle.float32, stop_gradient: False) + ): + var_2 = paddle.nn.functional.common.dropout( + var_0, p=0.1, axis=None, training=self.training, mode="upscale_in_train", name=None + ) + var_3 = var_1.__add__(var_2) + var_4 = paddle.nn.functional.norm.layer_norm( + var_3, normalized_shape=[1024], weight=self.parameter_5, bias=self.parameter_3, epsilon=1e-05 + ) + var_5 = paddle.nn.functional.common.linear(x=var_4, weight=self.parameter_7, bias=self.parameter_0, name=None) + var_6 = paddle.nn.functional.activation.gelu(var_5) + var_7 = paddle.nn.functional.common.dropout( + var_6, p=0.1, axis=None, training=self.training, mode="upscale_in_train", name=None + ) + var_8 = paddle.nn.functional.common.linear(x=var_7, weight=self.parameter_6, bias=self.parameter_1, name=None) + var_9 = paddle.nn.functional.common.dropout( + var_8, p=0.1, axis=None, training=self.training, mode="upscale_in_train", name=None + ) + var_10 = var_4.__add__(var_9) + var_11 = paddle.nn.functional.norm.layer_norm( + var_10, normalized_shape=[1024], weight=self.parameter_2, bias=self.parameter_4, epsilon=1e-05 + ) + return var_11 + + +seed = 33 + + +def reset(seed): + """ + 重置模型图 + :param seed: 随机种子 + :return: + """ + paddle.enable_static() + paddle.disable_static() + paddle.seed(seed) + np.random.seed(seed) + np.set_printoptions(threshold=5, edgeitems=3) + + +# def _net_input(): +# """get input""" +# reset(seed) +# data = ( +# paddle.to_tensor(np.random.random(size=[1, 169, 1024]).astype('float32')), +# paddle.to_tensor(np.random.random(size=[1, 169, 1024]).astype('float32')), +# ) +# return data + +data = [ + np.random.random(size=[1, 169, 1024]).astype("float32"), + np.random.random(size=[1, 169, 1024]).astype("float32"), +] + +tensor_data = [paddle.to_tensor(data[0]), paddle.to_tensor(data[1])] + + +def _net_instant(): + """get net""" + reset(seed) + net = LayerCase() + return net + + +# 动态图结果 +reset(seed) +net = _net_instant() +net.eval() +logit = net(*tensor_data) + +# export +reset(seed) +st_net = paddle.jit.to_static(_net_instant()) +st_net.eval() +st_net(*tensor_data) +paddle.jit.save(st_net, path=os.path.join("save_path", "jit_save")) + +# infer +reset(seed) +config = paddle_infer.Config("save_path/jit_save" + ".pdmodel", "save_path/jit_save" + ".pdiparams") +config.enable_use_gpu(1000, 0) +predictor = paddle_infer.create_predictor(config) +input_names = predictor.get_input_names() +for i, name in enumerate(input_names): + input_handle = predictor.get_input_handle(name) + input_tmp = data[i] + input_handle.copy_from_cpu(input_tmp) +predictor.run() +output_names = predictor.get_output_names() +if len(output_names) > 1: + infer_res = [] + for i, name in enumerate(output_names): + output_handle = predictor.get_output_handle(output_names[i]) + infer_res.append(output_handle.copy_to_cpu()) +else: + output_handle = predictor.get_output_handle(output_names[0]) + infer_res = output_handle.copy_to_cpu() + +print(logit - infer_res) diff --git a/framework/e2e/PaddleLT_new/diy/data/single_img_dataset.py b/framework/e2e/PaddleLT_new/diy/data/single_img_dataset.py index 12d907829b..64ac15bea1 100644 --- a/framework/e2e/PaddleLT_new/diy/data/single_img_dataset.py +++ b/framework/e2e/PaddleLT_new/diy/data/single_img_dataset.py @@ -9,7 +9,7 @@ import paddle from paddle.io import Dataset, BatchSampler, DataLoader -import tools.np_tool as tool +import pltools.np_tool as tool class SingleImageWithoutLabelDataset(Dataset): diff --git a/framework/e2e/PaddleLT_new/diy/data/struct_img_dataset.py b/framework/e2e/PaddleLT_new/diy/data/struct_img_dataset.py index 7df0b4f358..16cb8daa29 100644 --- a/framework/e2e/PaddleLT_new/diy/data/struct_img_dataset.py +++ b/framework/e2e/PaddleLT_new/diy/data/struct_img_dataset.py @@ -9,7 +9,7 @@ import paddle from paddle.io import Dataset, BatchSampler, DataLoader -import tools.np_tool as tool +import pltools.np_tool as tool # class ListImageWithoutLabelDataset(Dataset): diff --git a/framework/e2e/PaddleLT_new/engine/paddle_eval.py b/framework/e2e/PaddleLT_new/engine/paddle_eval.py index 0c9f3e564a..82bc406b52 100644 --- a/framework/e2e/PaddleLT_new/engine/paddle_eval.py +++ b/framework/e2e/PaddleLT_new/engine/paddle_eval.py @@ -13,9 +13,9 @@ from generator.builder_layer import BuildLayer from generator.builder_data import BuildData -from tools.logger import Logger +from pltools.logger import Logger -from tools.res_save import save_tensor +from pltools.res_save import save_tensor class LayerEval(object): diff --git a/framework/e2e/PaddleLT_new/engine/paddle_eval_bm.py b/framework/e2e/PaddleLT_new/engine/paddle_eval_bm.py index 5bf70b6fe4..b2e32762c0 100644 --- a/framework/e2e/PaddleLT_new/engine/paddle_eval_bm.py +++ b/framework/e2e/PaddleLT_new/engine/paddle_eval_bm.py @@ -13,9 +13,9 @@ from engine.paddle_xtools import reset from generator.builder_layer import BuildLayer from generator.builder_data import BuildData -from tools.res_save import save_pickle -from tools.statistics import trimmean, mean, best, best_top_k, perf_by_step -from tools.logger import Logger +from pltools.res_save import save_pickle +from pltools.statistics import trimmean, mean, best, best_top_k, perf_by_step +from pltools.logger import Logger class LayerEvalBM(object): diff --git a/framework/e2e/PaddleLT_new/engine/paddle_export.py b/framework/e2e/PaddleLT_new/engine/paddle_export.py index 87ba4c566b..37c24af99f 100644 --- a/framework/e2e/PaddleLT_new/engine/paddle_export.py +++ b/framework/e2e/PaddleLT_new/engine/paddle_export.py @@ -12,7 +12,7 @@ from generator.builder_layer import BuildLayer from generator.builder_data import BuildData -from tools.logger import Logger +from pltools.logger import Logger class LayerExport(object): diff --git a/framework/e2e/PaddleLT_new/engine/paddle_infer.py b/framework/e2e/PaddleLT_new/engine/paddle_infer.py index 4ab35e7f1a..7388b651e6 100644 --- a/framework/e2e/PaddleLT_new/engine/paddle_infer.py +++ b/framework/e2e/PaddleLT_new/engine/paddle_infer.py @@ -14,7 +14,7 @@ from generator.builder_layer import BuildLayer from generator.builder_data import BuildData -from tools.logger import Logger +from pltools.logger import Logger class LayerInfer(object): diff --git a/framework/e2e/PaddleLT_new/engine/paddle_train.py b/framework/e2e/PaddleLT_new/engine/paddle_train.py index 52aec07e71..fe42a57572 100644 --- a/framework/e2e/PaddleLT_new/engine/paddle_train.py +++ b/framework/e2e/PaddleLT_new/engine/paddle_train.py @@ -15,7 +15,7 @@ from generator.builder_optimizer import BuildOptimizer from generator.builder_loss import BuildLoss -from tools.logger import Logger +from pltools.logger import Logger class LayerTrain(object): diff --git a/framework/e2e/PaddleLT_new/engine/paddle_train_bm.py b/framework/e2e/PaddleLT_new/engine/paddle_train_bm.py index c17564a189..88119604fa 100644 --- a/framework/e2e/PaddleLT_new/engine/paddle_train_bm.py +++ b/framework/e2e/PaddleLT_new/engine/paddle_train_bm.py @@ -15,9 +15,9 @@ from generator.builder_data import BuildData from generator.builder_optimizer import BuildOptimizer from generator.builder_loss import BuildLoss -from tools.res_save import save_pickle -from tools.statistics import trimmean, mean, best, best_top_k, perf_by_step -from tools.logger import Logger +from pltools.res_save import save_pickle +from pltools.statistics import trimmean, mean, best, best_top_k, perf_by_step +from pltools.logger import Logger class LayerTrainBM(object): diff --git a/framework/e2e/PaddleLT_new/engine/torch_eval_bm.py b/framework/e2e/PaddleLT_new/engine/torch_eval_bm.py index 45092f0256..4c3361cf0e 100644 --- a/framework/e2e/PaddleLT_new/engine/torch_eval_bm.py +++ b/framework/e2e/PaddleLT_new/engine/torch_eval_bm.py @@ -12,8 +12,8 @@ from engine.torch_xtools import reset from generator.builder_layer import BuildLayer from generator.builder_data import BuildData -from tools.res_save import save_pickle -from tools.statistics import trimmean, mean, best, best_top_k, perf_by_step +from pltools.res_save import save_pickle +from pltools.statistics import trimmean, mean, best, best_top_k, perf_by_step class TorchLayerEvalBM(object): diff --git a/framework/e2e/PaddleLT_new/generator/builder_data.py b/framework/e2e/PaddleLT_new/generator/builder_data.py index c33df22112..2b6b07d4d5 100644 --- a/framework/e2e/PaddleLT_new/generator/builder_data.py +++ b/framework/e2e/PaddleLT_new/generator/builder_data.py @@ -18,7 +18,7 @@ import torch import layerTorchcase -import tools.np_tool as tool +import pltools.np_tool as tool class BuildData(object): diff --git a/framework/e2e/PaddleLT_new/layertest.py b/framework/e2e/PaddleLT_new/layertest.py index 1587b543bc..9fa118a3c0 100644 --- a/framework/e2e/PaddleLT_new/layertest.py +++ b/framework/e2e/PaddleLT_new/layertest.py @@ -11,9 +11,9 @@ # from engine.engine_map import engine_map from strategy.compare import base_compare, infer_compare -from tools.yaml_loader import YamlLoader -from tools.logger import Logger -from tools.res_save import save_tensor, load_tensor, save_pickle +from pltools.yaml_loader import YamlLoader +from pltools.logger import Logger +from pltools.res_save import save_tensor, load_tensor, save_pickle class LayerTest(object): diff --git a/framework/e2e/PaddleLT_new/tools/alarm.py b/framework/e2e/PaddleLT_new/pltools/alarm.py similarity index 100% rename from framework/e2e/PaddleLT_new/tools/alarm.py rename to framework/e2e/PaddleLT_new/pltools/alarm.py diff --git a/framework/e2e/PaddleLT_new/tools/case_select.py b/framework/e2e/PaddleLT_new/pltools/case_select.py similarity index 97% rename from framework/e2e/PaddleLT_new/tools/case_select.py rename to framework/e2e/PaddleLT_new/pltools/case_select.py index ee692dd5ba..1ba38e007e 100644 --- a/framework/e2e/PaddleLT_new/tools/case_select.py +++ b/framework/e2e/PaddleLT_new/pltools/case_select.py @@ -12,7 +12,7 @@ # import time # import pytest # import allure -# from tools.yaml_loader import YamlLoader +# from pltools.yaml_loader import YamlLoader class CaseSelect(object): diff --git a/framework/e2e/PaddleLT_new/tools/json_loader.py b/framework/e2e/PaddleLT_new/pltools/json_loader.py similarity index 100% rename from framework/e2e/PaddleLT_new/tools/json_loader.py rename to framework/e2e/PaddleLT_new/pltools/json_loader.py diff --git a/framework/e2e/PaddleLT_new/tools/logger.py b/framework/e2e/PaddleLT_new/pltools/logger.py similarity index 100% rename from framework/e2e/PaddleLT_new/tools/logger.py rename to framework/e2e/PaddleLT_new/pltools/logger.py diff --git a/framework/e2e/PaddleLT_new/tools/np_tool.py b/framework/e2e/PaddleLT_new/pltools/np_tool.py similarity index 100% rename from framework/e2e/PaddleLT_new/tools/np_tool.py rename to framework/e2e/PaddleLT_new/pltools/np_tool.py diff --git a/framework/e2e/PaddleLT_new/tools/res_save.py b/framework/e2e/PaddleLT_new/pltools/res_save.py similarity index 100% rename from framework/e2e/PaddleLT_new/tools/res_save.py rename to framework/e2e/PaddleLT_new/pltools/res_save.py diff --git a/framework/e2e/PaddleLT_new/tools/statistics.py b/framework/e2e/PaddleLT_new/pltools/statistics.py similarity index 100% rename from framework/e2e/PaddleLT_new/tools/statistics.py rename to framework/e2e/PaddleLT_new/pltools/statistics.py diff --git a/framework/e2e/PaddleLT_new/tools/upload_bos.py b/framework/e2e/PaddleLT_new/pltools/upload_bos.py similarity index 100% rename from framework/e2e/PaddleLT_new/tools/upload_bos.py rename to framework/e2e/PaddleLT_new/pltools/upload_bos.py diff --git a/framework/e2e/PaddleLT_new/tools/yaml_loader.py b/framework/e2e/PaddleLT_new/pltools/yaml_loader.py similarity index 100% rename from framework/e2e/PaddleLT_new/tools/yaml_loader.py rename to framework/e2e/PaddleLT_new/pltools/yaml_loader.py diff --git a/framework/e2e/PaddleLT_new/run.py b/framework/e2e/PaddleLT_new/run.py index 2acd438783..930fcc5dd8 100644 --- a/framework/e2e/PaddleLT_new/run.py +++ b/framework/e2e/PaddleLT_new/run.py @@ -17,14 +17,14 @@ import layertest from db.layer_db import LayerBenchmarkDB from strategy.compare import perf_compare_dict, perf_compare_kernel_dict -from tools.case_select import CaseSelect -from tools.logger import Logger -from tools.yaml_loader import YamlLoader -from tools.json_loader import JSONLoader -from tools.res_save import xlsx_save, download_sth, create_tar_gz, extract_tar_gz, load_pickle, save_txt -from tools.upload_bos import UploadBos -from tools.statistics import split_list, sublayer_perf_gsb_gen, kernel_perf_gsb_gen -from tools.alarm import Alarm +from pltools.case_select import CaseSelect +from pltools.logger import Logger +from pltools.yaml_loader import YamlLoader +from pltools.json_loader import JSONLoader +from pltools.res_save import xlsx_save, download_sth, create_tar_gz, extract_tar_gz, load_pickle, save_txt +from pltools.upload_bos import UploadBos +from pltools.statistics import split_list, sublayer_perf_gsb_gen, kernel_perf_gsb_gen +from pltools.alarm import Alarm class Run(object): diff --git a/framework/e2e/PaddleLT_new/strategy/compare.py b/framework/e2e/PaddleLT_new/strategy/compare.py index 7f33174387..0abf243a8d 100644 --- a/framework/e2e/PaddleLT_new/strategy/compare.py +++ b/framework/e2e/PaddleLT_new/strategy/compare.py @@ -13,7 +13,7 @@ import traceback import numpy as np -from tools.logger import Logger +from pltools.logger import Logger framework = "" if os.environ.get("FRAMEWORK") == "paddle":