__init__.py 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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. from . import version
  16. from .modules import (
  17. build_dataset_checker,
  18. build_trainer,
  19. build_evaluater,
  20. build_predictor,
  21. )
  22. from .modules import create_model, PaddleInferenceOption
  23. from .pipelines import *
  24. def _initialize():
  25. from .utils.logging import setup_logging
  26. from .utils import flags
  27. from . import repo_manager
  28. from . import repo_apis
  29. __DIR__ = os.path.abspath(os.path.dirname(os.path.abspath(__file__)))
  30. repo_manager.set_parent_dirs(
  31. os.path.join(__DIR__, "repo_manager", "repos"), repo_apis
  32. )
  33. setup_logging()
  34. if flags.EAGER_INITIALIZATION:
  35. repo_manager.initialize()
  36. def _check_paddle_version():
  37. """check paddle version"""
  38. import paddle
  39. supported_versions = ["3.0", "0.0"]
  40. device_type = paddle.device.get_device().split(":")[0]
  41. if device_type.lower() == "xpu":
  42. supported_versions.append("2.6")
  43. version = paddle.__version__
  44. # Recognizable version number: major.minor.patch
  45. major, minor, patch = version.split(".")
  46. # Ignore patch
  47. version = f"{major}.{minor}"
  48. if version not in supported_versions:
  49. raise RuntimeError(
  50. f"The {version} version of PaddlePaddle is not supported. "
  51. f"Please install one of the following versions of PaddlePaddle: {supported_versions}."
  52. )
  53. _initialize()
  54. _check_paddle_version()
  55. __version__ = version.get_pdx_version()