__init__.py 2.0 KB

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