
    oi                     d   / S Qr SSKrSSKrSSKrSSKJr  SSKr\R                  R                  SS5      S:H  r	\R                  R                  SS5      S:H  r
SSKrSSKr\R                  " \R                  R                  5      r\R"                  " S	5      S
 5       r             SS jr \" SSSSSS\	SSSSS9rSSKJrJrJr  \" S\S\4   S9rS\S\4S jr \
(       a  \rO\R8                  " \R:                  \S9r\
(       a  \r/ qg\R8                  " \R:                  5      r/ qg))TEMPORARY_PATCHEStorch_compile_optionsUNSLOTH_ENABLE_LOGGINGUNSLOTH_COMPILE_DISABLEget_torch_compile_optionsloggertorch_compile_torch_compile    N   )r   r   01r      c                      [         R                  S:X  a  g[        R                  " 5       n [	        S[        SU 5      5      $ )Nwin32r          )sysplatformos	cpu_countminmax)r   s    ^/home/james-whalen/.local/lib/python3.13/site-packages/unsloth_zoo/temporary_patches/common.pydetermine_compile_threadsr   )   s1     ||wqIr3q)$%%    TFc           	        ^ [         R                  R                  SS5      S:H  n[         R                  R                  SS5      S:H  n[         R                  R                  SS5      S:H  n[        (       a  SnU
(       a  SOSn
 SS KnSS	KJm  U4S
 jnUUR                  R                  l         0 SU _SU_SU_SU=(       d    U_SU_SU=(       d    U_SS_SU	_SU=(       d    U_SU=(       d    U_S[        5       _SU_SU(       + _SU_SU
_SU_SS_SSSSUSSS.En0 nUR                  5        H5  u  nnUR                  S 5      n[        S! U 5       5      (       d  M0  UUU'   M7     U$ !   [        S5         N= f)"NUNSLOTH_COMPILE_DEBUGr   r   UNSLOTH_COMPILE_MAXIMUMUNSLOTH_COMPILE_IGNORE_ERRORSTr   r
   )tqdmc                     > SUS'   T" U 0 UD6$ )NzUnsloth: Compiling kernelsdesc )argskwargsr    s     r   replaced_tqdm0get_torch_compile_options.<locals>.replaced_tqdmM   s    9F6N(((r   z=Unsloth: Failed editing tqdm to replace Inductor Compilation:epilogue_fusionmax_autotuneshape_paddingztrace.enabledztriton.cudagraphsdebugdcememory_planningcoordinate_descent_tuningztrace.graph_diagramcompile_threadsgroup_fusiondisable_progressverbose_progressztriton.multi_kernelztriton.use_block_ptrz#triton.enable_persistent_tma_matmulFz-O2)ztriton.autotune_at_compile_timeztriton.cooperative_reductionszcuda.compile_opt_levelzcuda.enable_cuda_ltocombo_kernelsbenchmark_combo_kernel#combo_kernel_foreach_dynamic_shapes.c              3   2   #    U  H  o[         ;   v   M     g 7fN)inductor_config_source).0ks     r   	<genexpr>,get_torch_compile_options.<locals>.<genexpr>w   s     ;Fq**Fs   )r   environgetr   torch._inductor.async_compile	torch.hubr    	_inductorasync_compileprintr   itemssplitall)r(   r)   r*   r+   
cudagraphsr.   loggingr3   r0   r-   multi_kerneluse_block_ptrr   r   r   torchr&   r   final_torch_compile_optionskeyvaluesplitsr    s                         @r   r   r   2   s
    %'JJNN3JTW$X\_$_$&JJNN3LTW$X\_$_$&JJNN3RTW$X\_$_!w %1!LO,"	) .;%%* 	ol 	m 	&;&Du	
 	j 	&;&Du 	d 	o 	$&?&ZCZ 	&;&Du 	&?&A 	l 	'k 	g  	l!" 	m#$ 	.%& 16050504 1>0404;> #%+113
U3;F;;;/4', 4 '&QOMNs   +E- -E<)r(   r)   r*   r+   rH   r.   rI   r3   r-   rJ   rK   )AnyCallableTypeVarF.)boundr$   r%   c                      U (       a5  [        U S   5      (       a"  [        R                  R                  U S   5      $ S[        S[        4S jnU$ )z
A do-nothing decorator/adapter.

Works as:
  - @noop
  - @noop(...)
  - noop(func, ...)

Returns the original function unchanged in every case.
r
   funcreturnc                 @    [         R                  R                  U 5      $ r8   )rL   compilerdisable)rW   s    r   
_decoratornoop.<locals>._decorator   s    ~~%%d++r   )callablerL   rZ   r[   rT   )r$   r%   r\   s      r   noopr_      sG     a!!~~%%d1g.., ,q ,r   )options)TFTFFFFFTTFF) __all__r   r   rI   logr   	functoolsr>   r?   r   r   inspectrL   	getsourcerB   configr9   	lru_cacher   r   r   typingrQ   rR   rS   rT   r_   r   partialcompiler	   r   r#   r   r   <module>rk      s  "	 
 
   **..)ACHCO **..)BCHCO    **5??+A+AB 
Q& &   %G'P 1 %$  * )CxS)* s ( M%%'M
 N   &&N
  r   