@@ -214,6 +214,39 @@ def stop(self):
214214 self .profile_npu .stop ()
215215 NPUProfiler ._define_count -= 1
216216
217+ def capture_start (self , ** kwargs ):
218+ """Start an on-demand profiling segment."""
219+ if not (self .enable and self .this_step ):
220+ return
221+
222+ role = kwargs .get ("role" , "" )
223+
224+ if self .discrete :
225+ self .capture_profiler_npu = get_npu_profiler (
226+ contents = self .profile_contents ,
227+ profile_level = self .profile_level ,
228+ profile_save_path = self .profile_save_path ,
229+ analysis = self .analysis ,
230+ role = role ,
231+ )
232+ self .capture_profiler_npu .start ()
233+
234+ self ._capture_range_id = mark_start_range (message = role )
235+
236+ def capture_stop (self ):
237+ """Stop the on-demand profiling segment."""
238+ if not (self .enable and self .this_step ):
239+ return
240+
241+ if hasattr (self , "_capture_range_id" ):
242+ mark_end_range (self ._capture_range_id )
243+ del self ._capture_range_id
244+
245+ if self .discrete and getattr (self , "capture_profiler_npu" , None ):
246+ self .capture_profiler_npu .step ()
247+ self .capture_profiler_npu .stop ()
248+ del self .capture_profiler_npu
249+
217250 def annotate (self , message : Optional [str ] = None , role : Optional [str ] = None , ** kwargs_outer ) -> Callable :
218251 """Decorate a Worker member function to profile the current rank in the current training step.
219252
0 commit comments