Skip to content

Commit

Permalink
fix plt tools, test=model
Browse files Browse the repository at this point in the history
  • Loading branch information
Zeref996 committed Sep 6, 2024
1 parent d087c91 commit 4472abd
Show file tree
Hide file tree
Showing 25 changed files with 178 additions and 33 deletions.
4 changes: 2 additions & 2 deletions framework/e2e/PaddleLT_new/binary_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
4 changes: 2 additions & 2 deletions framework/e2e/PaddleLT_new/db/layer_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
145 changes: 145 additions & 0 deletions framework/e2e/PaddleLT_new/debug/infer_debug_dropout.py
Original file line number Diff line number Diff line change
@@ -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)
2 changes: 1 addition & 1 deletion framework/e2e/PaddleLT_new/diy/data/single_img_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion framework/e2e/PaddleLT_new/diy/data/struct_img_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
4 changes: 2 additions & 2 deletions framework/e2e/PaddleLT_new/engine/paddle_eval.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
6 changes: 3 additions & 3 deletions framework/e2e/PaddleLT_new/engine/paddle_eval_bm.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion framework/e2e/PaddleLT_new/engine/paddle_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion framework/e2e/PaddleLT_new/engine/paddle_infer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion framework/e2e/PaddleLT_new/engine/paddle_train.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
6 changes: 3 additions & 3 deletions framework/e2e/PaddleLT_new/engine/paddle_train_bm.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
4 changes: 2 additions & 2 deletions framework/e2e/PaddleLT_new/engine/torch_eval_bm.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion framework/e2e/PaddleLT_new/generator/builder_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import torch
import layerTorchcase

import tools.np_tool as tool
import pltools.np_tool as tool


class BuildData(object):
Expand Down
6 changes: 3 additions & 3 deletions framework/e2e/PaddleLT_new/layertest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
File renamed without changes.
File renamed without changes.
16 changes: 8 additions & 8 deletions framework/e2e/PaddleLT_new/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion framework/e2e/PaddleLT_new/strategy/compare.py
Original file line number Diff line number Diff line change
Expand Up @@ -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":
Expand Down

0 comments on commit 4472abd

Please sign in to comment.