cinn_setting.py 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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. "SwinTransformer_base_patch4_window7_224",
  23. "Mask-RT-DETR-L",
  24. "RT-DETR-L",
  25. "Deeplabv3-R50",
  26. "Deeplabv3_Plus-R50",
  27. "PP-LiteSeg-T",
  28. "SLANet",
  29. "PP-OCRv4_mobile_rec",
  30. "PP-OCRv4_server_rec",
  31. "Nonstationary_ad",
  32. "PatchTST_ad",
  33. "TimesNet_ad",
  34. "Nonstationary",
  35. "PatchTST",
  36. "RLinear",
  37. "TiDE",
  38. "TimesNet",
  39. "CLIP_vit_large_patch14_224",
  40. "MobileNetV2_x0_25",
  41. "MobileNetV2_x0_5",
  42. "MobileNetV2_x1_5",
  43. "MobileNetV2_x2_0",
  44. "PP-HGNet_tiny",
  45. "PP-HGNet_base",
  46. "PP-LCNet_x0_25",
  47. "PP-LCNet_x0_35",
  48. "PP-LCNet_x0_5",
  49. "PP-LCNet_x0_75",
  50. "PP-LCNet_x1_5",
  51. "PP-LCNet_x2_5",
  52. "PP-LCNet_x2_0",
  53. "ResNet18",
  54. "ResNet34",
  55. "ResNet101",
  56. "ResNet152",
  57. "ResNet18_vd",
  58. "ResNet34_vd",
  59. "ResNet50_vd",
  60. "ResNet101_vd",
  61. "ResNet152_vd",
  62. "ResNet200_vd",
  63. "SwinTransformer_tiny_patch4_window7_224",
  64. "SwinTransformer_small_patch4_window7_224",
  65. "SwinTransformer_base_patch4_window12_384",
  66. "SwinTransformer_large_patch4_window7_224",
  67. "SwinTransformer_large_patch4_window12_384",
  68. "Mask-RT-DETR-H",
  69. "Mask-RT-DETR-X",
  70. "Mask-RT-DETR-M",
  71. "Mask-RT-DETR-S",
  72. "RT-DETR-H",
  73. "RT-DETR-X",
  74. "RT-DETR-R18",
  75. "RT-DETR-R50",
  76. "Deeplabv3-R101",
  77. "Deeplabv3_Plus-R101",
  78. "PP-LiteSeg-B",
  79. "SLANet_plus",
  80. "PP-OCRv4_server_rec",
  81. "PP-OCRv4_server_rec_doc",
  82. ]
  83. # TODO(gaotingquan): paddle v3.0.0 don't support enable CINN easily
  84. def enable_cinn_backend():
  85. import paddle
  86. if not paddle.is_compiled_with_cinn():
  87. logging.debug(
  88. "Your paddle is not compiled with CINN, can not use CINN backend."
  89. )
  90. return
  91. # equivalent to `FLAGS_prim_all=1`
  92. paddle.base.core._set_prim_all_enabled(True)
  93. # equivalent to `FLAGS_prim_enable_dynamic=1`
  94. paddle.base.framework.set_flags({"FLAGS_prim_enable_dynamic": True})
  95. os.environ["FLAGS_prim_enable_dynamic"] = "1"
  96. # equivalent to `FLAGS_use_cinn=1`
  97. paddle.base.framework.set_flags({"FLAGS_use_cinn": True})
  98. os.environ["FLAGS_use_cinn"] = "1"