__init__.py 2.1 KB

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