__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. paddle = LazyLoader("lazy_paddle", globals(), "paddle")
  17. sys.modules["lazy_paddle"] = paddle
  18. import os
  19. from . import version
  20. from .modules import (
  21. build_dataset_checker,
  22. build_trainer,
  23. build_evaluater,
  24. )
  25. from .model import create_model
  26. from .inference import create_predictor, create_pipeline
  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. supported_versions = ["3.0", "0.0"]
  42. device_type = paddle.device.get_device().split(":")[0]
  43. if device_type.lower() == "xpu":
  44. supported_versions.append("2.6")
  45. version = paddle.__version__
  46. # Recognizable version number: major.minor.patch
  47. major, minor, patch = version.split(".")
  48. # Ignore patch
  49. version = f"{major}.{minor}"
  50. if version not in supported_versions:
  51. raise RuntimeError(
  52. f"The {version} version of PaddlePaddle is not supported. "
  53. f"Please install one of the following versions of PaddlePaddle: {supported_versions}."
  54. )
  55. _initialize()
  56. __version__ = version.get_pdx_version()