From 74f38d63f2978b266b469bef1a51f9441ff9293b Mon Sep 17 00:00:00 2001 From: Zeng Jinle <32832641+sneaxiy@users.noreply.github.com> Date: Sat, 18 Sep 2021 15:55:37 +0800 Subject: [PATCH] Change __init__.py to adapt the new FLAGS coding style and update CI to monitor FLAGS changing (#35849) * change __init__.py to adapt new FLAGS * test ci check, ready for revert * split __init__.py and FLAGS approval * Revert "test ci check, ready for revert" This reverts commit bbbd2442fe3e948fef790ec634085a2431474326. --- python/paddle/fluid/__init__.py | 84 +++++------------------------- tools/check_file_diff_approvals.sh | 6 +++ 2 files changed, 18 insertions(+), 72 deletions(-) diff --git a/python/paddle/fluid/__init__.py b/python/paddle/fluid/__init__.py index 30e3f9dec97..8ddac967e7b 100644 --- a/python/paddle/fluid/__init__.py +++ b/python/paddle/fluid/__init__.py @@ -176,83 +176,23 @@ def __bootstrap__(): print('PLEASE USE OMP_NUM_THREADS WISELY.', file=sys.stderr) os.environ['OMP_NUM_THREADS'] = str(num_threads) - sysstr = platform.system() + + flag_prefix = "FLAGS_" read_env_flags = [ - 'check_nan_inf', - 'convert_all_blocks', - 'benchmark', - 'eager_delete_scope', - 'fraction_of_cpu_memory_to_use', - 'initial_cpu_memory_in_mb', - 'init_allocated_mem', - 'paddle_num_threads', - 'dist_threadpool_size', - 'eager_delete_tensor_gb', - 'fast_eager_deletion_mode', - 'memory_fraction_of_eager_deletion', - 'allocator_strategy', - 'reader_queue_speed_test_mode', - 'print_sub_graph_dir', - 'pe_profile_fname', - 'inner_op_parallelism', - 'enable_parallel_graph', - 'fuse_parameter_groups_size', - 'multiple_of_cupti_buffer_size', - 'fuse_parameter_memory_size', - 'tracer_profile_fname', - 'dygraph_debug', - 'use_system_allocator', - 'enable_unused_var_check', - 'free_idle_chunk', - 'free_when_no_cache_hit', - 'call_stack_level', - 'sort_sum_gradient', - 'max_inplace_grad_add', - 'apply_pass_to_program', - 'new_executor_use_inplace', + key[len(flag_prefix):] for key in core.globals().keys() + if key.startswith(flag_prefix) ] - if 'Darwin' not in sysstr: - read_env_flags.append('use_pinned_memory') - if os.name != 'nt': - read_env_flags.append('cpu_deterministic') + def remove_flag_if_exists(name): + if name in read_env_flags: + read_env_flags.remove(name) - if core.is_compiled_with_mkldnn(): - read_env_flags.append('use_mkldnn') - read_env_flags.append('tracer_mkldnn_ops_on') - read_env_flags.append('tracer_mkldnn_ops_off') - - if core.is_compiled_with_cuda(): - read_env_flags += [ - 'fraction_of_gpu_memory_to_use', - 'initial_gpu_memory_in_mb', - 'reallocate_gpu_memory_in_mb', - 'cudnn_deterministic', - 'enable_cublas_tensor_op_math', - 'conv_workspace_size_limit', - 'cudnn_exhaustive_search', - 'selected_gpus', - 'sync_nccl_allreduce', - 'cudnn_batchnorm_spatial_persistent', - 'gpu_allocator_retry_time', - 'local_exe_sub_scope_limit', - 'gpu_memory_limit_mb', - 'conv2d_disable_cudnn', - 'get_host_by_name_time', - ] + sysstr = platform.system() + if 'Darwin' in sysstr: + remove_flag_if_exists('use_pinned_memory') - if core.is_compiled_with_npu(): - read_env_flags += [ - 'selected_npus', - 'fraction_of_gpu_memory_to_use', - 'initial_gpu_memory_in_mb', - 'reallocate_gpu_memory_in_mb', - 'gpu_memory_limit_mb', - 'npu_config_path', - 'get_host_by_name_time', - 'hccl_check_nan', - 'min_loss_scaling', - ] + if os.name == 'nt': + remove_flag_if_exists('cpu_deterministic') core.init_gflags(["--tryfromenv=" + ",".join(read_env_flags)]) # Note(zhouwei25): sys may not have argv in some cases, diff --git a/tools/check_file_diff_approvals.sh b/tools/check_file_diff_approvals.sh index f65a65c8b75..1549cf1f228 100644 --- a/tools/check_file_diff_approvals.sh +++ b/tools/check_file_diff_approvals.sh @@ -88,6 +88,12 @@ function run_tools_test() { cd ${CUR_PWD} } +changed_env_var_count=`git diff -U0 upstream/$BRANCH ${PADDLE_ROOT}/paddle | grep -E 'DEFINE_EXPORTED|DEFINE_bool|DEFINE_int32|DEFINE_int64|DEFINE_uint64|DEFINE_double|DEFINE_string' | wc -l` +if [[ $changed_env_var_count -gt 0 ]]; then + echo_line="You must have one RD (lanxianghit (Recommend), phlrain or luotao1) approval for changing the FLAGS, which manages the environment variables.\n" + check_approval 1 6836917 47554610 43953930 +fi + if [[ $git_files -gt 19 || $git_count -gt 999 ]];then echo_line="You must have Dianhai approval for change 20+ files or add than 1000+ lines of content.\n" check_approval 1 38231817 -- GitLab