@@ -214,6 +214,43 @@ 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+ message = kwargs .get ("message" )
223+ role = kwargs .get ("role" )
224+ profile_name = message or role
225+
226+ if not self .discrete :
227+ self ._capture_range_id = mark_start_range (message = profile_name )
228+ else :
229+ self .capture_profiler_npu = get_npu_profiler (
230+ contents = self .profile_contents ,
231+ profile_level = self .profile_level ,
232+ profile_save_path = self .profile_save_path ,
233+ analysis = self .analysis ,
234+ role = role ,
235+ )
236+ self .capture_profiler_npu .start ()
237+ self ._capture_range_id = mark_start_range (message = profile_name )
238+
239+ def capture_stop (self ):
240+ """Stop the on-demand profiling segment."""
241+ if not (self .enable and self .this_step ):
242+ return
243+
244+ # End manual range
245+ if hasattr (self , "_capture_range_id" ):
246+ mark_end_range (self ._capture_range_id )
247+ del self ._capture_range_id
248+
249+ if self .discrete and getattr (self , "capture_profiler_npu" , None ):
250+ self .capture_profiler_npu .step ()
251+ self .capture_profiler_npu .stop ()
252+ del self .capture_profiler_npu
253+
217254 def annotate (self , message : Optional [str ] = None , role : Optional [str ] = None , ** kwargs_outer ) -> Callable :
218255 """Decorate a Worker member function to profile the current rank in the current training step.
219256
0 commit comments