flags.py 1.2 KB

123456789101112131415161718192021222324252627282930313233343536
  1. # copyright (c) 2024 PaddlePaddle Authors. All Rights Reserve.
  2. #
  3. # Licensed under the Apache License, Version 2.0 (the "License");
  4. # you may not use this file except in compliance with the License.
  5. # You may obtain a copy of the License at
  6. #
  7. # http://www.apache.org/licenses/LICENSE-2.0
  8. #
  9. # Unless required by applicable law or agreed to in writing, software
  10. # distributed under the License is distributed on an "AS IS" BASIS,
  11. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. # See the License for the specific language governing permissions and
  13. # limitations under the License.
  14. import os
  15. __all__ = ['DEBUG', 'DRY_RUN', 'CHECK_OPTS', 'EAGER_INITIALIZATION']
  16. def get_flag_from_env_var(name, default):
  17. """ get_flag_from_env_var """
  18. env_var = os.environ.get(name, None)
  19. if env_var in ('True', 'true', 'TRUE', '1'):
  20. return True
  21. elif env_var in ('False', 'false', 'FALSE', '0'):
  22. return False
  23. else:
  24. return default
  25. DEBUG = get_flag_from_env_var('PADDLE_PDX_DEBUG', False)
  26. DRY_RUN = get_flag_from_env_var('PADDLE_PDX_DRY_RUN', False)
  27. CHECK_OPTS = get_flag_from_env_var('PADDLE_PDX_CHECK_OPTS', False)
  28. EAGER_INITIALIZATION = get_flag_from_env_var('PADDLE_PDX_EAGER_INIT', True)