cinn_setting.py 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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. "CLIP_vit_base_patch16_224",
  18. "MobileNetV2_x1_0",
  19. "PP-HGNet_small",
  20. "PP-LCNet_x1_0",
  21. "ResNet50",
  22. "Deeplabv3-R50",
  23. "Deeplabv3_Plus-R50",
  24. "PP-LiteSeg-T",
  25. "SLANet",
  26. "PP-OCRv4_mobile_rec",
  27. "PP-OCRv4_server_rec",
  28. "Nonstationary_ad",
  29. "PatchTST_ad",
  30. "TimesNet_ad",
  31. "Nonstationary",
  32. "PatchTST",
  33. "RLinear",
  34. "TiDE",
  35. "TimesNet",
  36. "CLIP_vit_large_patch14_224",
  37. "MobileNetV2_x0_25",
  38. "MobileNetV2_x0_5",
  39. "MobileNetV2_x1_5",
  40. "MobileNetV2_x2_0",
  41. "PP-HGNet_tiny",
  42. "PP-HGNet_base",
  43. "PP-LCNet_x0_25",
  44. "PP-LCNet_x0_35",
  45. "PP-LCNet_x0_5",
  46. "PP-LCNet_x0_75",
  47. "PP-LCNet_x1_5",
  48. "PP-LCNet_x2_5",
  49. "PP-LCNet_x2_0",
  50. "ResNet18",
  51. "ResNet34",
  52. "ResNet101",
  53. "ResNet152",
  54. "ResNet18_vd",
  55. "ResNet34_vd",
  56. "ResNet50_vd",
  57. "ResNet101_vd",
  58. "ResNet152_vd",
  59. "ResNet200_vd",
  60. "Deeplabv3-R101",
  61. "Deeplabv3_Plus-R101",
  62. "PP-LiteSeg-B",
  63. "SLANet_plus",
  64. "PP-OCRv4_server_rec",
  65. "PP-OCRv4_server_rec_doc",
  66. ]
  67. # TODO(gaotingquan): paddle v3.0.0 don't support enable CINN easily
  68. def enable_cinn_backend():
  69. import paddle
  70. if not paddle.is_compiled_with_cinn():
  71. logging.debug(
  72. "Your paddle is not compiled with CINN, can not use CINN backend."
  73. )
  74. return
  75. # equivalent to `FLAGS_prim_all=1`
  76. paddle.base.core._set_prim_all_enabled(True)
  77. # equivalent to `FLAGS_prim_enable_dynamic=1`
  78. paddle.base.framework.set_flags({"FLAGS_prim_enable_dynamic": True})
  79. os.environ["FLAGS_prim_enable_dynamic"] = "1"
  80. # equivalent to `FLAGS_use_cinn=1`
  81. paddle.base.framework.set_flags({"FLAGS_use_cinn": True})
  82. os.environ["FLAGS_use_cinn"] = "1"