@@ -117,27 +117,33 @@ def set_compile_configs(
117117 # them to your needs and test the performance
118118 inductor_config .max_fusion_size = 64
119119 inductor_config .max_pointwise_cat_inputs = 8
120- inductor_config .triton .cudagraphs = cuda_graphs
121- inductor_config .triton .use_block_ptr = False
122- inductor_config .triton .codegen_upcast_to_fp32 = True
123-
124- # Copy from https://pytorch.org/blog/accelerating-generative-ai-3/
125- inductor_config .conv_1x1_as_mm = True
126- inductor_config .coordinate_descent_tuning = True
127- inductor_config .coordinate_descent_check_all_directions = True
128- inductor_config .epilogue_fusion = False
129-
130- # Enable epilogue and prologue fusion
131- if ENV .CACHE_DIT_EPILOGUE_PROLOGUE_FUSION or kwargs .get (
132- "epilogue_prologue_fusion" ,
133- False ,
134- ):
135- inductor_config .epilogue_fusion = True
136- inductor_config .prologue_fusion = True
137- inductor_config .epilogue_fusion_first = True
138120
139- # Dead code elimination
140- inductor_config .dce = True # default is False
121+ if current_platform .device_type == "npu" :
122+ # NPU: skip CUDA-specific inductor configs (triton, coordinate_descent, etc)
123+ inductor_config .dce = True # default is False
124+ inductor_config .epilogue_fusion = False
125+ else :
126+ inductor_config .triton .cudagraphs = cuda_graphs
127+ inductor_config .triton .use_block_ptr = False
128+ inductor_config .triton .codegen_upcast_to_fp32 = True
129+
130+ # Copy from https://pytorch.org/blog/accelerating-generative-ai-3/
131+ inductor_config .conv_1x1_as_mm = True
132+ inductor_config .coordinate_descent_tuning = True
133+ inductor_config .coordinate_descent_check_all_directions = True
134+ inductor_config .epilogue_fusion = False
135+
136+ # Enable epilogue and prologue fusion
137+ if ENV .CACHE_DIT_EPILOGUE_PROLOGUE_FUSION or kwargs .get (
138+ "epilogue_prologue_fusion" ,
139+ False ,
140+ ):
141+ inductor_config .epilogue_fusion = True
142+ inductor_config .prologue_fusion = True
143+ inductor_config .epilogue_fusion_first = True
144+
145+ # Dead code elimination
146+ inductor_config .dce = True # default is False
141147
142148 # May need to force disable all cache
143149 if force_disable_compile_caches :
@@ -153,3 +159,19 @@ def set_compile_configs(
153159 inductor_config .cuda .use_fast_math = use_fast_math
154160 except Exception :
155161 pass
162+
163+
164+ def _maybe_apply_mindiesd_compile (module , module_name , module_cls_name ):
165+ # Auto-apply MindieSDBackend compile on NPU when mindiesd is available.
166+ # Returns the compiled module if compiled, None if MindIE-SD not applicable.
167+ try :
168+ import mindiesd # noqa F401
169+
170+ if not hasattr (torch , 'npu' ) or not torch .npu .is_available ():
171+ return None
172+ from mindiesd .compilation import MindieSDBackend
173+
174+ logger .info (f"Compiling { module_name } : { module_cls_name } with MindieSDBackend ..." )
175+ return torch .compile (module , backend = MindieSDBackend (), dynamic = True )
176+ except Exception :
177+ return None
0 commit comments