Skip to content

Commit

Permalink
fix performance (PaddlePaddle#9772)
Browse files Browse the repository at this point in the history
  • Loading branch information
zhangting2020 committed Apr 20, 2023
1 parent 43abe2f commit d496c8e
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 3 deletions.
1 change: 1 addition & 0 deletions configs/kie/vi_layoutxlm/ser_vi_layoutxlm_xfund_zh.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ Global:
save_res_path: ./output/ser/xfund_zh/res
kie_rec_model_dir:
kie_det_model_dir:
amp_custom_white_list: ['scale', 'concat', 'elementwise_add']

Architecture:
model_type: kie
Expand Down
1 change: 1 addition & 0 deletions configs/table/SLANet.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ Global:
use_sync_bn: True
save_res_path: 'output/infer'
d2s_train_image_shape: [3, -1, -1]
amp_custom_white_list: ['concat', 'elementwise_sub', 'set_value']

Optimizer:
name: Adam
Expand Down
1 change: 1 addition & 0 deletions test_tipc/configs/slanet/SLANet.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ Global:
use_sync_bn: True
save_res_path: 'output/infer'
d2s_train_image_shape: [3, -1, -1]
amp_custom_white_list: ['concat', 'elementwise_sub', 'set_value']

Optimizer:
name: Adam
Expand Down
6 changes: 4 additions & 2 deletions tools/program.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,8 @@ def train(config,
log_writer=None,
scaler=None,
amp_level='O2',
amp_custom_black_list=[]):
amp_custom_black_list=[],
amp_custom_white_list=[]):
cal_metric_during_train = config['Global'].get('cal_metric_during_train',
False)
calc_epoch_interval = config['Global'].get('calc_epoch_interval', 1)
Expand Down Expand Up @@ -277,7 +278,8 @@ def train(config,
if scaler:
with paddle.amp.auto_cast(
level=amp_level,
custom_black_list=amp_custom_black_list):
custom_black_list=amp_custom_black_list,
custom_white_list=amp_custom_white_list):
if model_type == 'table' or extra_input:
preds = model(images, data=batch[1:])
elif model_type in ["kie"]:
Expand Down
3 changes: 2 additions & 1 deletion tools/train.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ def main(config, device, logger, vdl_writer):
use_amp = config["Global"].get("use_amp", False)
amp_level = config["Global"].get("amp_level", 'O2')
amp_custom_black_list = config['Global'].get('amp_custom_black_list', [])
amp_custom_white_list = config['Global'].get('amp_custom_white_list', [])
if use_amp:
AMP_RELATED_FLAGS_SETTING = {'FLAGS_max_inplace_grad_add': 8, }
if paddle.is_compiled_with_cuda():
Expand Down Expand Up @@ -194,7 +195,7 @@ def main(config, device, logger, vdl_writer):
program.train(config, train_dataloader, valid_dataloader, device, model,
loss_class, optimizer, lr_scheduler, post_process_class,
eval_class, pre_best_model_dict, logger, vdl_writer, scaler,
amp_level, amp_custom_black_list)
amp_level, amp_custom_black_list, amp_custom_white_list)


def test_reader(config, device, logger):
Expand Down

0 comments on commit d496c8e

Please sign in to comment.