flags.py 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  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__ = [
  16. "DEBUG",
  17. "DRY_RUN",
  18. "CHECK_OPTS",
  19. "EAGER_INITIALIZATION",
  20. "FLAGS_json_format_model",
  21. ]
  22. def get_flag_from_env_var(name, default):
  23. """get_flag_from_env_var"""
  24. env_var = os.environ.get(name, None)
  25. if env_var in ("True", "true", "TRUE", "1"):
  26. return True
  27. elif env_var in ("False", "false", "FALSE", "0"):
  28. return False
  29. else:
  30. return default
  31. DEBUG = get_flag_from_env_var("PADDLE_PDX_DEBUG", False)
  32. DRY_RUN = get_flag_from_env_var("PADDLE_PDX_DRY_RUN", False)
  33. CHECK_OPTS = get_flag_from_env_var("PADDLE_PDX_CHECK_OPTS", False)
  34. EAGER_INITIALIZATION = get_flag_from_env_var("PADDLE_PDX_EAGER_INIT", True)
  35. FLAGS_json_format_model = get_flag_from_env_var("FLAGS_json_format_model", None)