L i,ddlZddlZddlmZddlZddlZddlmZmZm Z m Z m Z ddl m Z mZmZmZmZmZdgZeddGddZd Zy) N) deprecated)_disable_profiler_legacy_enable_profiler_legacy DeviceTypeProfilerConfig ProfilerState) _filter_name_filter_stack_entry _rewrite_name EventList FunctionEventMEMORY_EVENT_NAMEprofilez`torch.autograd.profiler_legacy.profile` is deprecated and will be removed in a future release. Please use `torch.profiler` instead.)categorycxeZdZdZ dddddddddZdZdZdZdZd Z d Z d Z dd Z e jje _dZe jje_ddedefdZddZe j"je_dZe j$je_edZy )rz'DEPRECATED: use torch.profiler instead.F)use_cuda record_shapes with_flopsprofile_memory with_stack with_modulesc||_|jsy||_d|_d|_||_||_|xj|j zc_||_||_||_|jr)rreprr/s r'__repr__zprofile.__repr__qs"    '9D(())r)cF|jyt|jS)Nz,)rstrr/s r'__str__zprofile.__str__vs"    'A4''((r)c2|j tdy)NzProfiler didn't finish running)rr2r/s r' _check_finishzprofile._check_finish{s    '?@ @ (r)Nc |j|jJ|jj|||||||S)N)sort_by row_limitmax_src_column_widthmax_name_column_widthmax_shapes_column_widthheadertop_level_events_only)rHrtable)r&rJrKrLrMrNrOrPs r'rQz profile.tablesU ##///##))!5"7$;"7*  r)ct|j|jJ|jj|Sr+)rHrexport_chrome_trace)r&paths r'rSzprofile.export_chrome_traces7 ##///##77==r)rTmetricc|j|jJd|jsJd|jj||S)NExpected profiling resultsz(export_stacks() requires with_stack=True)rHrr export_stacks)r&rTrUs r'rXzprofile.export_stackssQ ##/M1MM/J JJ##11$??r)c|j|jJd|jj||SNrW)rHr key_averages)r&group_by_input_shapegroup_by_stack_ns r'r[zprofile.key_averagessA ##/M1MM/##001EGWXXr)c||j|jJd|jjSrZ)rHr total_averager/s r'r_zprofile.total_averages; ##/M1MM/##1133r)cj|j|jJ|jjS)z;Return CPU time as the sum of self times across all events.)rHrself_cpu_time_totalr/s r'razprofile.self_cpu_time_totals4 ##///##777r))T)NdK7PNF)ra)Fr)__name__ __module__ __qualname____doc__r(r0r4r3r@rCrFrHrQr rSrErXr[r_propertyrar)r'rrs 2"3"3H  /"* ) A  "# ,OO++EM> #,"?"?"G"G@#@s@ Y %1199L4 &33;;M 88r)c d}d}g}tjj|D]}|j}||dk(s|}||j rJ|D] }i}i}i} t } d} |D]}||} t |js| | vr| j| ;|jdk(r| {| j|jk(xrD| j|jk(xr!| j|jk(} | r| j| || | <d|| <d|| <n|jdk(r"| | vs Jd| d| | }|| }|| }|jxs!|j|jk7}|j }|j}td$id|jd |jd t|jd d t|jd d|jd|j!|d|j!|d|j#d|j%d|j'Dcgc]}t)|s|c}d|j+d|j-rdndd|d|d|d|d|j/dt0j2dd d|}|sU|j-rE|j5|}|dkDr/|j7|j|j9||j;|| | =|| =|| =n|jd k(rt=|}t=|}||k(sJ|j?D]}||xx|jAz cc<|j?D]}||xx|jCz cc<|dk(rFtdtDddddg|jA|jCd ! }|j;||}  |jGd"#|Scc}w)%NcB|j|jfS)zPReturn a tuple for correlating start and end records in `_parse_legacy_records`.)handlenode_id)records r'_get_record_keyz._parse_legacy_records.._get_record_keys !122r)__start_profilepushrpopzExpected record with key zo to exist in range_starts. This means that the pop event did not have a corresponding push.idronameT)rv with_wildcard trace_nameFthreadstart_usend_us fwd_thread input_shapesstackscoper7rcpu_memory_usagedevice_memory_usageis_async is_remote sequence_nr device_type is_legacyflops memory_alloc) rurvrxryrzr{r~rrrc\|jj|jj gSr+) time_rangestartend)evts r'z'_parse_legacy_records..7s"CNN$8$83>>;M;M:M#Nr))keyrk)$ itertoolschain from_iterablervrsetr addkindror thread_idrr rnr cpu_elapsed_us fwd_thread_idshapesr~r rhas_cudarrr%cuda_elapsed_us append_kerneldeviceappendlenkeysrcuda_memory_usagersort)thread_recordsrq start_record functionsrprvthread_record_listcpu_memory_allocscuda_memory_allocs range_startsfiltered_handles prev_record record_key duplicaterrrris_remote_event start_flopsentryfedurationnum_open_handles_cpunum_open_handles_cudarns r'r9r9s3LI////?"{{}  D,=$=!L"  #L,B,B,DD D,e! 5 (\ !F(0JFKKM*j>+X0AVEUEUEW0W"("2"2"4#kkm "}}"NN,'EJJLM -%**,eT  !??,  *88? (66v> %224"',1;;="'(?%+/DDDD/446KF%f-1H1H1JJ-K0557MF&v.&2J2J2LL.M'1,&.#' !"  )/)@)@)B,2,D,D,F"& B$$R( Ky\ !e!ZNNNNO os !Q?2Q?)rr!typing_extensionsrr torch.cudatorch.autogradrrrrrtorch.autograd.profiler_utilr r r r r r__all__rr9rkr)r'rsa(  + +  V8V8  V8r~r)