cinn_setting.py 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  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 os
  15. from ....utils import logging
  16. CINN_WHITELIST = [
  17. # TODO: update models based testing result
  18. "PP-LCNet_x0_25",
  19. ]
  20. # TODO(gaotingquan): paddle v3.0.0 don't support enable CINN easily
  21. def enable_cinn_backend():
  22. import paddle
  23. if not paddle.is_compiled_with_cinn():
  24. logging.debug(
  25. "Your paddle is not compiled with CINN, can not use CINN backend."
  26. )
  27. return
  28. # equivalent to `FLAGS_prim_all=1`
  29. paddle.base.core._set_prim_all_enabled(True)
  30. # equivalent to `FLAGS_prim_enable_dynamic=1`
  31. paddle.base.framework.set_flags({"FLAGS_prim_enable_dynamic": True})
  32. os.environ["FLAGS_prim_enable_dynamic"] = "1"
  33. # equivalent to `FLAGS_use_cinn=1`
  34. paddle.base.framework.set_flags({"FLAGS_use_cinn": True})
  35. os.environ["FLAGS_use_cinn"] = "1"