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

[WIP]add_benchmark #286

Open
wants to merge 10 commits into
base: develop
Choose a base branch
from
Open
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
8 changes: 8 additions & 0 deletions configs/caddn/caddn_deeplabv3p_resnet101_os8_kitti.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@ batch_size: 4
iters: 74240 # 928*80
sync_bn: true

amp_cfg:
use_amp: False
# only enable backbone and fpn
enable: False
level: O1
scaler:
init_loss_scaling: 32.0

train_dataset:
type: KittiDepthDataset
dataset_root: data/kitti
Expand Down
23 changes: 18 additions & 5 deletions paddle3d/models/detection/caddn/caddn.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
from paddle3d.models.layers import ConvBNReLU
from paddle3d.utils import checkpoint
from paddle3d.utils.logger import logger
from paddle3d.utils import dtype2float32

from .bev import BEV
from .f2v import FrustumToVoxel
Expand Down Expand Up @@ -71,9 +72,16 @@ def train_forward(self, data):
data["batch_size"] = b

# ffe
image_features = self.backbone_3d(images)
if hasattr(self, 'amp_cfg_'):
with paddle.amp.auto_cast(**self.amp_cfg_):
image_features = self.backbone_3d(images)
depth_logits = self.class_head(image_features, data["image_shape"])
image_features = dtype2float32(image_features)
depth_logits = dtype2float32(depth_logits)
else:
image_features = self.backbone_3d(images)
depth_logits = self.class_head(image_features, data["image_shape"])

depth_logits = self.class_head(image_features, data["image_shape"])
data = self.ffe(image_features[0], depth_logits, data)

# frustum_to_voxel
Expand All @@ -91,9 +99,14 @@ def train_forward(self, data):
data["spatial_features"] = bev_features

# backbone_2d
data = self.backbone_2d(data)
predictions = self.dense_head(data)

if hasattr(self, 'amp_cfg_'):
with paddle.amp.auto_cast(**self.amp_cfg_):
data = self.backbone_2d(data)
predictions = self.dense_head(data)
predictions = dtype2float32(predictions)
else:
data = self.backbone_2d(data)
predictions = self.dense_head(data)
loss = self.get_loss(predictions)
return loss

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,9 @@ def forward(self,

# sampling_locations.stop_gradient = True
# attention_weights.stop_gradient = True
value = value.cast(paddle.float32)
sampling_locations = sampling_locations.cast(paddle.float32)
attention_weights = attention_weights.cast(paddle.float32)
output = ms_deform_attn.ms_deform_attn(
value, sampling_locations, attention_weights, spatial_shapes,
level_start_index, self.im2col_step)
Expand Down Expand Up @@ -627,6 +630,7 @@ def forward(self,

value = value.cast(paddle.float32)
sampling_locations = sampling_locations.cast(paddle.float32)
attention_weights = attention_weights.cast(paddle.float32)
output = ms_deform_attn.ms_deform_attn(
value, sampling_locations, attention_weights, spatial_shapes,
level_start_index, self.im2col_step)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,7 @@ def forward(self,
# attention_weights.stop_gradient = True
value = value.cast(paddle.float32)
sampling_locations = sampling_locations.cast(paddle.float32)
attention_weights = attention_weights.cast(paddle.float32)
output = ms_deform_attn.ms_deform_attn(
value, sampling_locations, attention_weights, spatial_shapes,
level_start_index, self.im2col_step)
Expand Down
1 change: 1 addition & 0 deletions paddle3d/models/transformers/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,7 @@ def nan_to_num(x, nan=0.0, posinf=None, neginf=None, name=None):
posinf_value = paddle.full_like(x, float("+inf"))
neginf_value = paddle.full_like(x, float("-inf"))
nan = paddle.full_like(x, nan)
x = x.astype("float32")
assert x.dtype in [paddle.float32, paddle.float64]
is_float32 = x.dtype == paddle.float32
if posinf is None:
Expand Down
58 changes: 58 additions & 0 deletions test_tipc/configs/bevformer/train_infer_python.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
===========================train_params===========================
model_name:bevformer
python:python3.7
gpu_list:0
##
auto_cast:null
--iters:lite_train_lite_infer=100
--save_dir:./output/
--batch_size:lite_train_lite_infer=4
pretrained_model:null
train_model_name:iter_100/model.pdparams
train_infer_img_dir:./datasets/nuscenes
null:null
##
trainer:norm_train
norm_train:tools/train.py --config configs/bevformer/bevformer_tiny_r50_fpn_fp16_nuscenes.yml --num_workers 20 --log_interval 1 --seed 123 --save_interval 100
pact_train:null
fpgm_train:null
distill_train:null
null:null
null:null
##
===========================eval_params===========================
eval:null
null:null
##
===========================infer_params===========================
--output_dir:./output/
load:null
norm_export:null
quant_export:null
fpgm_export:null
distill_export:null
export1:null
export2:null
inference_dir:null
infer_model:null
infer_export:null
infer_quant:False
inference:null
null:null
null:null
null:null
null:null
null:null
--model_path:
null:null
null:null
--benchmark:True
null:null
===========================to_static_train_benchmark_params===========================
to_static_train:--to_static True
===========================train_benchmark_params==========================
batch_size:2
fp_items:fp32|fp16
iters:100
--profiler_options:batch_range=[10,20];state=GPU;tracer_option=Default;profile_path=model.profile
flags:FLAGS_cudnn_exhaustive_search=0
58 changes: 58 additions & 0 deletions test_tipc/configs/caddn/train_infer_python.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
===========================train_params===========================
model_name:caddn
python:python3.7
gpu_list:0
##
auto_cast:null
--iters:lite_train_lite_infer=100
--save_dir:./output/
--batch_size:lite_train_lite_infer=4
pretrained_model:null
train_model_name:iter_100/model.pdparams
train_infer_img_dir:./datasets/nuscenes
null:null
##
trainer:norm_train
norm_train:tools/train.py --config configs/caddn/caddn_deeplabv3p_resnet101_os8_kitti.yml --num_workers 4 --log_interval 1 --seed 123 --save_interval 100
pact_train:null
fpgm_train:null
distill_train:null
null:null
null:null
##
===========================eval_params===========================
eval:null
null:null
##
===========================infer_params===========================
--output_dir:./output/
load:null
norm_export:null
quant_export:null
fpgm_export:null
distill_export:null
export1:null
export2:null
inference_dir:null
infer_model:null
infer_export:null
infer_quant:False
inference:null
null:null
null:null
null:null
null:null
null:null
--model_path:
null:null
null:null
--benchmark:True
null:null
===========================to_static_train_benchmark_params===========================
to_static_train:--to_static True
===========================train_benchmark_params==========================
batch_size:4
fp_items:fp32|fp16
iters:100
--profiler_options:batch_range=[10,20];state=GPU;tracer_option=Default;profile_path=model.profile
flags:FLAGS_cudnn_exhaustive_search=0
30 changes: 27 additions & 3 deletions test_tipc/prepare.sh
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ trainer_list=$(func_parser_value "${lines[14]}")

if [ ${MODE} = "benchmark_train" ];then
pip install -r requirements.txt
pip install -e .
MODE="lite_train_lite_infer"
fi

Expand All @@ -39,13 +40,36 @@ if [ ${MODE} = "lite_train_lite_infer" ];then
mkdir -p ./test_tipc/data/mini_modelnet40
cd ./test_tipc/data/mini_modelnet40 && tar xf ../mini_modelnet40.tar.gz && cd ../../
elif [ ${model_name} = "petrv2" ]; then
rm -rf ./data/nuscenes

wget -nc -P ./ https://paddle3d.bj.bcebos.com/pretrained/fcos3d_vovnet_imgbackbone-remapped.pdparams --no-check-certificate
cd ./data/ && unzip nuscenes.zip && cd ../
rm -rf ./data
# download data
# cd Paddle3D
mkdir data && cd data
python ${BENCHMARK_ROOT}/paddlecloud/file_upload_download.py \
--remote-path /user/userdata/benchmark/data/Paddle3D/petrv2/ \
--local-path ./ \
--mode download
unzip nuscenes.zip && cd ../
elif [ ${model_name} = "centerpoint" ]; then
rm -rf ./datasets/KITTI
wget -nc -P ./datasets/ https://paddle3d.bj.bcebos.com/TIPC/dataset/kitti_mini_centerpoint.tar.gz --no-check-certificate
cd ./datasets/ && tar -xzf kitti_mini_centerpoint.tar.gz && cd ../ ;;
cd ./datasets/ && tar -xzf kitti_mini_centerpoint.tar.gz && cd ../
elif [ ${model_name} = "bevformer" ]; then
rm -rf datasets && mkdir datasets && cd datasets
python ${BENCHMARK_ROOT}/paddlecloud/file_upload_download.py \
--remote-path /user/userdata/benchmark/data/Paddle3D/bevformer/ \
--local-path ./ \
--mode download
tar xf nuscenes.tar && cd ../
elif [ ${model_name} = "caddn" ]; then
rm -rf data && mkdir data && cd data
python ${BENCHMARK_ROOT}/paddlecloud/file_upload_download.py \
--remote-path /user/userdata/benchmark/data/Paddle3D/caddn/ \
--local-path ./ \
--mode download
tar xf KITTI.tar && mv KITTI kitti
cd ../;
else
echo "Not added into TIPC yet."
fi
Expand Down
6 changes: 3 additions & 3 deletions test_tipc/test_train_inference_python.sh
Original file line number Diff line number Diff line change
Expand Up @@ -256,11 +256,11 @@ else
fi
set_save_model=$(func_set_params "${save_model_key}" "${save_log}")
if [ ${#gpu} -le 2 ];then # train with cpu or single gpu
cmd="${python} ${run_train} ${set_use_gpu} ${set_save_model} ${set_train_params1} ${set_epoch} ${set_pretrain} ${set_batchsize} ${set_amp_config} ${set_amp_level}"
cmd="${python} ${run_train} ${set_use_gpu} ${set_save_model} ${set_epoch} ${set_pretrain} ${set_batchsize} ${set_amp_config} ${set_amp_level} ${set_train_params1}"
elif [ ${#ips} -le 26 ];then # train with multi-gpu
cmd="${python} -m paddle.distributed.launch --gpus=${gpu} ${run_train} ${set_use_gpu} ${set_save_model} ${set_train_params1} ${set_epoch} ${set_pretrain} ${set_batchsize} ${set_amp_config} ${set_amp_level}"
cmd="${python} -m paddle.distributed.launch --gpus=${gpu} ${run_train} ${set_use_gpu} ${set_train_params1} ${set_epoch} ${set_pretrain} ${set_batchsize} ${set_amp_config} ${set_amp_level} ${set_train_params1}"
else # train with multi-machine
cmd="${python} -m paddle.distributed.launch --ips=${ips} --gpus=${gpu} ${run_train} ${set_use_gpu} ${set_save_model} ${set_train_params1} ${set_pretrain} ${set_epoch} ${set_batchsize} ${set_amp_config} ${set_amp_level}"
cmd="${python} -m paddle.distributed.launch --ips=${ips} --gpus=${gpu} ${run_train} ${set_use_gpu} ${set_save_model} ${set_pretrain} ${set_epoch} ${set_batchsize} ${set_amp_config} ${set_amp_level} ${set_train_params1}"
fi
# run train
export FLAGS_cudnn_deterministic=True
Expand Down