
    hB                     &   S SK r S SKrS SKJr  S SKJr  S SKJrJrJ	r	  S SK
r
S SKrS SKJr  S SKJr  SSKJr  SS	KJr  SS
KJr  SSKJr  SSKJrJrJrJrJr  \R:                  " SSSS.S9\" SSS9\" SSSS9\" SSSSSS9\" SSSS9\" SSS S!S9\" S"S#S$S%S&9\" S'S(S)S S*S9\" SS+S,S-S94S.\R<                  S/\S0\S1\	\    S2\!S3\ S4\ S5\ S6\	\   4S7 jj5       r" " S8 S95      r# " S: S;5      r$S<\S=\\   S1\	\    S>\
RJ                  4S? jr&S<\S=\\   S4\ S1\ S@\!S>\
RJ                  4SA jr'\
RP                  SB4S>\
RJ                  4SC jjr)S=\\   S>\ 4SD jr*SE\
RJ                  4SF jr+SE\
RJ                  4SG jr,S<\S=\\   S5\ S1\	\    S>\
RJ                  4
SH jr-g)I    N)islice)Path)IterableListOptional)tqdm)msg   )util)Language)Doc)Corpus   )ArgOptbenchmark_cliimport_code	setup_gpuspeedT)allow_extra_argsignore_unknown_options)context_settings.zModel name or path)helpz3Location of binary evaluation data in .spacy format)r   existsz--batch-sizez-bz Override the pipeline batch size)minr   Fz--no-shufflezDo not shuffle benchmark dataz--gpu-idz-gzGPU ID or -1 for CPU2   z	--batchesz&Minimum number of batches to benchmark   )r   r      z--warmupz-wz-Number of iterations over the data for warmupz--codez-czNPath to Python file with additional code (registered functions) to be importedctxmodel	data_path
batch_size
no_shuffleuse_gpu	n_batcheswarmup_epochs	code_pathc	                    [        U5        [        USS9  [        R                  " U5      n	Ub  UOU	R                  n[        U5      n
U
" U	5       Vs/ s H  oR                  PM     nn[        U5      S:X  a  [        R                  " SSS9  [        SU S	35        [        XXs5        [        5         [        S
U S35        [        XXcU(       + 5      n[        5         [        U5        [        U5        gs  snf )zi
Benchmark a pipeline. Expects a loadable spaCy pipeline and benchmark
data in the binary .spacy format.
F)r%   silentNr   z-Cannot benchmark speed using an empty corpus.r   )exitszWarming up for z
 epochs...zBenchmarking z batches...)r   r   r   
load_modelr#   r   	predictedlenr	   failprintwarmup	benchmarkprint_outliersprint_mean_with_ci)r    r!   r"   r#   r$   r%   r&   r'   r(   nlpcorpusegdocswpss                 S/home/james-whalen/.local/lib/python3.13/site-packages/spacy/cli/benchmark_speed.pybenchmark_speed_clir;      s    * 	ge,
//%
 C)53>>JIF#)#;/;RLL;D/
4yA~@J	OM?*
56
3m0	G	M)K
01
Cy*n
EC	G3s 0s   C4c                   $    \ rS rSrSrS rS rSrg)time_context@   z'Register the running time of a context.c                 :    [         R                  " 5       U l        U $ N)timeperf_counterstart)selfs    r:   	__enter__time_context.__enter__C   s    &&(
    c                 R    [         R                  " 5       U R                  -
  U l        g r@   )rA   rB   rC   elapsed)rD   typevalue	tracebacks       r:   __exit__time_context.__exit__G   s    ((*TZZ7rG   )rI   rC   N)__name__
__module____qualname____firstlineno____doc__rE   rM   __static_attributes__ rG   r:   r=   r=   @   s    18rG   r=   c                   h    \ rS rSr% Sr\\S'   \\S'   \\S'   \\S'   S\R                  SS	4S
 jr	Sr
g	)	QuartilesK   zRCalculate the q1, q2, q3 quartiles and the inter-quartile range (iqr)
of a sample.q1q2q3iqrsamplereturnNc                     [         R                  " US5      U l        [         R                  " US5      U l        [         R                  " US5      U l        U R                  U R                  -
  U l        g )Ng      ?g      ?g      ?)numpyquantilerY   rZ   r[   r\   )rD   r]   s     r:   __init__Quartiles.__init__T   sL    .....-...77TWW$rG   )r\   rY   rZ   r[   )rO   rP   rQ   rR   rS   float__annotations__r`   ndarrayrb   rT   rU   rG   r:   rW   rW   K   s4     	III	J%u}} % %rG   rW   r5   r8   r^   c                 r   U R                  [        USS S9US9n/ n [        5        n[        [	        X(       a  UOU R
                  5      5      nS S S 5        [        W5      S:X  a  O+[        U5      nUR                  UWR                  -  5        Mu  [        R                  " U5      $ ! , (       d  f       N_= f)Ndoc)unitdisable)r#   r   )piper   r=   listr   r#   r.   count_tokensappendrI   r`   array)r5   r8   r#   r9   rI   
batch_docsn_tokenss          r:   annotaterr   [   s     88DE48Z8PD
C
^wt:Z3>>JJ  z?a
+

8goo-.  ;;s ^s   (B((
B6shufflec           
      Z   U(       aK  [        X#-  5       Vs/ s H2  nU R                  [        R                  " U5      R                  5      PM4     nnOD[        X#-  5       Vs/ s H,  nU R                  X[        U5      -     R                  5      PM.     nn[        XU5      $ s  snf s  snf r@   )rangemake_docrandomchoicetextr.   rr   )r5   r8   r&   r#   rs   _
bench_docsis           r:   r2   r2   m   s      912
2 LLt,1122 	 

 912
2 LL#d)m,1122 	 

 CZ00


s   9B#"3B(i'  c                 x   ^ ^ [         R                  " UU 4S j[        U5       5       [         R                  5      $ )z9Apply a statistic to repeated random samples of an array.c           	   3      >#    U  H3  nT" [         R                  R                  T[        T5      S S95      v   M5     g7f)T)replaceN)r`   rw   rx   r.   ).0rz   	statisticxs     r:   	<genexpr>bootstrap.<locals>.<genexpr>   s:      	
& ell))!SVT)BCC&s   ;>)r`   fromiterru   float64)r   r   
iterationss   `` r:   	bootstrapr      s/    >>	
:&	
 	 rG   c                 &    [        S U  5       5      $ )Nc              3   8   #    U  H  n[        U5      v   M     g 7fr@   )r.   )r   rh   s     r:   r   count_tokens.<locals>.<genexpr>   s     (4Cs3xx4s   )sum)r8   s    r:   rm   rm      s    (4(((rG   r]   c           	         [         R                  " U 5      n[        U 5      nUR                  5         U[	        [        U5      S-  5         nU[	        [        U5      S-  5         n[        SUS SX1-
  S SXA-
  S S35        g )Ng?g333333?zMean: .1fz words/s (95% CI: z +))r`   meanr   sortintr.   r0   )r]   r   bootstrap_meanslowhighs        r:   r4   r4      s    ::fD'O #c/2U:;
<C3s?3e;<=D	F4*.sxnBtyoQ
OPrG   c           	         [        U 5      n[        R                  " XR                  SUR                  -  -
  :  XR
                  SUR                  -  -   :  -  5      n[        R                  " XR                  SUR                  -  -
  :  XR
                  SUR                  -  -   :  -  5      n[        SSU-  [        U 5      -  S SSU-  [        U 5      -   S35        g )Ng      ?g      @z
Outliers: d   r   z%, extreme outliers: %)rW   r`   r   rY   r\   r[   r0   r.   )r]   	quartiles
n_outliersn_extreme_outlierss       r:   r3   r3      s    &!I	<<#	"55	6\\C)--$778	:J 	<<#	"55	6\\C)--$778	: 

cJ&#f+5c::OQTWiQimpqwmxPxOyyz{rG   c                 f    X-   Vs/ s H  oDR                  5       PM     nn[        XU5      $ s  snf r@   )copyrr   )r5   r8   r'   r#   rh   s        r:   r1   r1      s3     #'"67"63HHJ"6D7Cz** 8s   .).rw   rA   	itertoolsr   pathlibr   typingr   r   r   r`   typerr   wasabir	    r   languager   tokensr   trainingr   _utilr   r   r   r   r   commandContextstrr   boolr;   r=   rW   rf   rr   r2   r   r   rm   r4   r3   r1   rU   rG   r:   <module>r      sZ       + +         B B *.$O S34#$Ybfg #D.$ALn o5.7VWr:t2HI[/W]_aQ
Da>mn #D(D  @P  !Q%	% % 	%
 % % % % % ~%	%R8 8% % 	c08
]]$1	1
s)1 1 	1
 1 ]]1* !::% EMM )x} ) )	Qu}} 	Q5==  +	+c+36+DLSM+
]]+rG   