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

动转静单测时间统计和优化专项 #59339

Closed
ooooo-create opened this issue Nov 24, 2023 · 1 comment
Closed

动转静单测时间统计和优化专项 #59339

ooooo-create opened this issue Nov 24, 2023 · 1 comment
Assignees
Labels
HappyOpenSource 快乐开源活动issue与PR PFCC Paddle Framework Contributor Club,https://github.com/PaddlePaddle/community/tree/master/pfcc status/close 已关闭

Comments

@ooooo-create
Copy link
Contributor

ooooo-create commented Nov 24, 2023

背景

#58356 所述,动转静单测是现有静态图子图级别验证的主要入口,因此我们在动转静单测上开启了「AST」、「SOT」 2 种动转静模式 +「LEGACY_IR」、「PT 中间态」、「PIR 理想态」 3 种 IR 模式共 2x3=6 种组合的单测。而且在 #59191 添加了「SOT MIN_GRAPH_SIZE=10 + LEGACY_IR」一种 case,也就是单测组合达到了 7 种。

虽然目前大多数单测还没有开启所有组合,但是预期未来会达到最高 7 种组合的,这会导致单测时间大幅增加,因此我们需要前置考虑单测时间上的优化方案。

为了方便表示,这里我们将动转静模式系数表示为 $t_{d2s}$,将 IR 模式系数表示为 $t_{ir}$,我们预期最大的时间为 $t_{d2s} = 2$$t_{ir} = 3$$t_{extra} = 1$,总时间为 $t_{d2s} \times t_{ir} + t_{extra} = 7$

这里是一些关键单测时间发生变化的时间节点:

所以短短几个月过去动转静单测已经从 1 倍变成了接近 6 倍的时间,而且接下来我们还会继续增加到 7 倍……

本任务为 #58633 子项

任务细节

学习和了解动转静单测机制,分析动转静单测时间

首先可以通过 #57824#58356 了解单测生成机制,学习了解整个单测机制。

之后修改单测机制,让单测恢复到 1x1+0 的状态以统计单测时间(注意本 PR 只用来测试 CI 时间,不会合入),这里可以考虑直接修改生成 case 部分完成:

for to_static_mode, ir_mode in to_static_with_ir_modes:
if (
to_static_mode == ToStaticMode.SOT_MGS10
and ir_mode != IrMode.LEGACY_IR
):
# SOT_MGS10 only test with LEGACY_IR
continue
new_attrs[
Dy2StTestMeta.test_case_name(
fn_name, to_static_mode, ir_mode
)
] = Dy2StTestMeta.convert_test_case(fn, to_static_mode, ir_mode)

提交 PR 后触发 CI,使用脚本统计 Download 下来的 PR-CI-Py3 log 中的单测时间(仅动转静目录)。

统计后在本 issue 中产出一份单测时间统计表格。

根据统计的单测时间设计和调整单测策略

根据单测时间来设计对单测时长的优化策略(同 @SigureMo 一起),细节待数据产出后再说

任务进展

test in dygraph_to_static 是否有单测(每次 ci 中是否都有) 1x1(sec) time2(sec) 倍数 last_time last_倍数
test_assert 3.77 3.28 0.87 5.60 1.49
test_ast_util 2.40 2.46 1.03 2.53 1.05
test_backward_without_params 2.93 3.50 1.19 3.57 1.22
test_basic_api_transformation 30.12 104.18 3.46 16.53 0.55
test_bert
test_bmn
test_break_continue 9.63 23.00 2.39 21.99 2.28
test_build_strategy 65.57 106.53 1.62
test_cache_program
test_cast 2.50 2.55 1.02 2.67 1.07
test_cinn 2.60 3.26 1.25 2.76 1.06
test_cinn_prim 2.47 3.59 1.45 3.66 1.48
test_cinn_prim_gelu 2.51 2.90 1.16 2.85 1.14
test_cinn_prim_layer_norm 2.48 2.08 0.84 2.29 0.92
test_cinn_prim_mean 2.70 3.17 1.17 3.37 1.25
test_closure_analysis 2.93 4.87 1.66 4.77 1.63
test_container 4.04 7.39 1.83 7.52 1.86
test_convert_call 2.90 3.27 1.13 3.71 1.28
test_convert_call_generator 2.83 2.90 1.02 3.38 1.19
test_convert_operators 4.00 5.83 1.46 6.76 1.69
test_cpu_cuda_to_tensor 2.60 2.66 1.02 2.58 0.99
test_cycle_gan
test_declarative 3.32 3.21 0.97 3.57 1.08
test_decorator_transform 7.54 20.88 2.77 20.46 2.71
test_deepcopy 2.51 2.60 1.04 3.13 1.25
test_dict 7.85 23.25 2.96 13.27 1.69
test_drop_path 2.60 3.06 1.18 2.61 1.00
test_duplicate_output 2.64 2.80 1.06 2.61 0.99
test_error 2.92 2.43 0.83 2.71 0.93
test_eval_frame 2.01 2.09 1.04 2.19 1.09
test_fallback 5.55 9.02 1.63 8.61 1.55
test_fetch_feed 2.71 2.89 1.07 3.18 1.17
test_for_enumerate 14.56 30.75 2.11 53.97 3.71
test_full_name_usage 2.46 2.00 0.81 2.44 0.99
test_function_spec 2.13 1.68 0.79 1.76 0.83
test_grad
test_gradient_aggregation 2.33 2.24 0.96 2.62 1.12
test_gradname_parse 2.65 2.64 1.00 2.42 0.91
test_grid_generator 2.66 2.61 0.98 2.43 0.91
test_ifelse 11.88 26.11 2.20 34.90 2.94
test_ignore_module 2.53 1.85 0.73 1.70 0.67
test_inplace_assign 2.76 2.54 0.92 2.38 0.86
test_isinstance 3.71 5.03 1.36 4.82 1.30
test_jit_property_save 2.83 2.38 0.84 1.89 0.67
test_jit_setitem 6.60 9.51 1.44 13.24 2.01
test_lac
test_lambda 4.26 8.25 1.94 8.36 1.96
test_layer_hook 3.36 5.59 1.66 5.01 1.49
test_len 2.97 3.46 1.16
test_list 9.69 14.48 1.49 20.11 2.08
test_load_transformer 2.43 3.10 1.28
test_local_cast 2.20 2.39 1.09
test_logging_utils 2.28 2.19 0.96 2.48 1.09
test_logical 4.97 8.83 1.78 9.45 1.90
test_loop 29.66 67.01 2.26 71.17 2.40
test_lstm 4.25 4.22 0.99 4.92 1.16
test_mnist 27.81 18.84 0.68 40.11 1.44
test_mnist_amp 12.98 42.34 3.26 47.87 3.69
test_mnist_pure_fp16 2.20 1.92 0.87 1.82 0.83
test_mobile_net
test_multi_forward 2.62 2.38 0.91 2.81 1.07
test_no_gradient 2.47 2.01 0.81 2.39 0.97
test_op_attr 2.24 1.76 0.79 2.57 1.15
test_origin_info 2.78 1.94 0.70 1.91 0.69
test_params_no_grad 2.94 1.96 0.67 1.73 0.59
test_param_guard 3.70 4.33 1.17 5.33 1.44
test_partial_program 3.18 2.41 0.76 3.03 0.95
test_partial_program_hook 3.35 1.86 0.56 2.12 0.63
test_pir_selectedrows 4.81 8.66 1.80 5.32 1.11
test_place 2.65 2.02 0.76 2.02 0.76
test_print 4.47 8.34 1.87 8.45 1.89
test_program_translator
test_ptb_lm 6.36 17.52 2.75 12.33 1.94
test_ptb_lm_v2 4.93 10.91 2.21 12.68 2.57
test_pylayer 3.95 3.45 0.87 3.41 0.86
test_reinforcement_learning 3.46 7.40 2.14 8.86 2.56
test_resnet
test_resnet_amp
test_resnet_pure_fp16 1.96 1.62 0.83 2.02 1.03
test_resnet_v2
test_return 3.69 3.21 0.87 4.43 1.20
test_rollback 2.72 2.09 0.77 2.64 0.97
test_save_inference_model 3.76 2.48 0.66 2.69 0.72
test_save_load 3.23 3.07 0.95 3.12 0.97
test_sentiment
test_seq2seq 175.53 242.77 1.38 152.55 0.87
test_setter_helper 2.18 1.87 0.86 2.16 0.99
test_set_dynamic_shape 2.22 2.17 0.98 2.29 1.03
test_se_resnet 347.43 652.07 1.88 160.95 0.46
test_simnet 2.76 3.20 1.16 4.49 1.63
test_simnet_v2 2.78 3.02 1.09 4.40 1.58
test_slice 6.53 11.60 1.78 19.29 2.95
test_spec_names 2.38 2.05 0.86 2.25 0.95
test_static_analysis 2.19 1.88 0.86 1.84 0.84
test_tensor_hook 3.19 3.76 1.18 3.91 1.23
test_tensor_memcpy_on_cpu 2.39 2.38 1.00 2.68 1.12
test_tensor_memcpy_on_gpu 1.96 1.82 0.93 1.81 0.92
test_tensor_methods 2.83 3.42 1.21 4.40 1.55
test_tensor_shape 9.62 18.08 1.88 21.96 2.28
test_to_tensor 3.63 7.07 1.95 8.47 2.33
test_train_step
test_train_step_resnet18_adam
test_train_step_resnet18_sgd
test_transformer
test_tsm 105.61 495.14 4.69 90.82 0.86
test_typehint 2.15 1.97 0.92 2.10 0.98
test_typing 2.45 2.19 0.89 2.79 1.14
test_unuseful_inputs 2.13 1.83 0.86 2.30 1.08
test_utils 2.21 1.62 0.73 1.92 0.87
test_variable_trans_func 2.34 1.65 0.71 1.90 0.81
test_warning 2.48 2.09 0.84 2.10 0.85
test_word2vec 4.12 7.16 1.74 12.58 3.05
test_write_python_container 4.03 6.13 1.52 7.25 1.80
test_yolov3 106.65 475.92 4.46 85.14 0.80
sum 94/114 1152.68 2558.41 2.22 1186.96 1.03

说明

对要优化的文件进行搜索 def test_.*: 并且定义在 Dy2StTestBase 的子类中

  • 特殊单测文件
    • 对于禁用检查的单测,在表格备注,暂时先不优化
    • 如图的表格可能也需要备注

ebe509ba9655b9599e079a3c016f3e36

  • 对于没有跑 pir 的单测,默认使用 sot + pt 的模式
    • 仅 ast 模式时,添加仅 pt 模式
    • 其余,使用 default 模式
  • 对于支持 pir 的单测,默认使用 sot + pt and sot +pir 的模式
    • 仅 ast 模式时,保留原有装饰器(test_pir_only, test_legacy_and_pt_and_pir)
    • 其余使用 test_default_and_pir 来装饰
@SigureMo
Copy link
Member

SigureMo commented Dec 5, 2023

以只跑 1 次为基线时间,本 PR 从 2.22 倍时间(42 min)优化到了 1.03 倍时间(20 min),大幅缩短了 CI 时间,节省了 CI 资源~

感谢 @ooooo-create

@SigureMo SigureMo closed this as completed Dec 5, 2023
@github-project-automation github-project-automation bot moved this from In Progress to Done in Call for Contributions Dec 5, 2023
@paddle-bot paddle-bot bot added the status/close 已关闭 label Dec 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
HappyOpenSource 快乐开源活动issue与PR PFCC Paddle Framework Contributor Club,https://github.com/PaddlePaddle/community/tree/master/pfcc status/close 已关闭
Projects
Development

No branches or pull requests

3 participants