+
    &jL                     ^    ^ RI t ^ RI Ht ^RIHtHtHt R.tRR ltR	R lt ! R R]4      t	R# )
    N)Tensor)
_to_scalar	OptimizerParamsTLBFGSc                 *   Ve   Vw  rxMW8:  d   W3MW03w  rxW%,           ^W,
          ,          W,
          ,          ,
          p	V	^,          W%,          ,
          p
V
^ 8  d   V
P                  4       pW8:  d@   W3V ,
          W[,           V	,
          WR,
          ^V,          ,           ,          ,          ,
          pM>W V,
          W+,           V	,
          W%,
          ^V,          ,           ,          ,          ,
          p\        \        W4      V4      # Wx,           R,          # )Ng       @)sqrtminmax)x1f1g1x2f2g2bounds
xmin_bound
xmax_boundd1	d2_squared2min_poss   &&&&&&&      i/Users/jameslopez/projects/CWCArchive/cwc-podcast/.venv/lib/python3.14/site-packages/torch/optim/lbfgs.py_cubic_interpolater      s     !'
J-/X"B8
 
1=BG,	,BAIA~^^8G2"'AF:J(KLLGG2"'AF:J(KLLG3w+Z88'3..    c           
      D	   VP                  4       P                  4       pVP                  \        P                  R 7      pV ! WV4      w  r^pVP                  V4      p^ WEV3w  ppppRp^ pVV
8  Ed>   WWr,          V,          ,           8  g   V^8  d7   VV8  d0   VV.pVV.pVVP                  \        P                  R 7      .pVV.pM\        V4      V) V,          8:  d   V.pV.pV.pRpMV^ 8  d0   VV.pVV.pVVP                  \        P                  R 7      .pVV.pMVRVV,
          ,          ,           pV^
,          pTp\        VVVW,VVV3R7      pTpTpVP                  \        P                  R 7      pTpV ! WV4      w  rV^,          pVP                  V4      pV^,          pEKE  VV
8X  d   ^ V.pWL.pW].pRpX^ ,          VR,          8:  d   RMRw  ppV'       Eg   VV
8  Ed   \        X^,          V^ ,          ,
          4      V,          V	8  d   EMe\        V^ ,          V^ ,          X^ ,          V^,          V^,          V^,          4      pR\        V4      \        V4      ,
          ,          p \        \        V4      V,
          V\        V4      ,
          4      V 8  d   V'       g!   V\        V4      8  g   V\        V4      8:  db   \        V\        V4      ,
          4      \        V\        V4      ,
          4      8  d   \        V4      V ,
          pM\        V4      V ,           pRpMRpMRpV ! WV4      w  rV^,          pVP                  V4      pV^,          pWWr,          V,          ,           8  g   VVV,          8  dR   VVV&   VVV&   VP                  \        P                  R 7      XV&   VVV&   V^ ,          V^,          8:  d   RMRw  ppEK  \        V4      V) V,          8:  d   RpMSVVV,          VV,          ,
          ,          ^ 8  d1   VV,          VV&   VV,          VV&   XV,          VV&   VV,          VV&   VVV&   VVV&   VP                  \        P                  R 7      XV&   VVV&   EK  XV,          pVV,          pXV,          pWW.3# )	memory_formatFTg{Gz?)r   g?)r      )r    r   )absr   clonetorchcontiguous_formatdotr   r
   )!obj_funcxtdfggtdc1c2tolerance_changemax_lsd_normf_newg_newls_func_evalsgtd_newt_prevf_prevg_prevgtd_prevdonels_iterbracket	bracket_f	bracket_gbracket_gtdmin_stepmax_steptmpinsuf_progresslow_poshigh_posepss!   &&&&&&&&&&&                      r   _strong_wolferG   (   s    UUW[[]F	e556AA!$LEMiilG ()!|$FFFHDG
F
$%'A+%6/qkGI5;R;R!STI#W-Kw<B39$cGIIDa<qkGI5;R;R!STI#W-K tq6z**r6FHa8@T

 5+B+BCa())A,1 &a&J	J	
 N"+A,)B-"?VGXdw'wqzGAJ&'&03CC AJaLNAJaLN
, S\CL01s7|aS\!12S8 c'l!2a3w<6G q3w<'(3q3w</?+@@Gs*A Gs*A!&!%"N  a())A,1 $%)G2D)D !"GH"'Ih"'++E<S<S+"TIh$+K!*3A,)A,*FFGX7|sSy(GH-0@@AQF %,G$4!&/&8	(#&/&8	(#(3G(<H%  !GG!&Ig!&5;R;R!SIg#*K  	AgEgE))r   c                      a a ] tR t^t oRtRV3R lV 3R llltR tR tV3R lR ltR t	V3R	 lR
 lt
R t]P                  ! 4       R 4       tRtVtV ;t# )r   a:  Implements L-BFGS algorithm.

Heavily inspired by `minFunc
<https://www.cs.ubc.ca/~schmidtm/Software/minFunc.html>`_.

.. warning::
    This optimizer doesn't support per-parameter options and parameter
    groups (there can be only one).

.. warning::
    Right now all parameters have to be on a single device. This will be
    improved in the future.

.. note::
    This is a very memory intensive optimizer (it requires additional
    ``param_bytes * (history_size + 1)`` bytes). If it doesn't fit in memory
    try reducing the history size, or use a different algorithm.

Args:
    params (iterable): iterable of parameters to optimize. Parameters must be real.
    lr (float, optional): learning rate (default: 1)
    max_iter (int, optional): maximal number of iterations per optimization step
        (default: 20)
    max_eval (int, optional): maximal number of function evaluations per optimization
        step (default: max_iter * 1.25).
    tolerance_grad (float, optional): termination tolerance on first order optimality
        (default: 1e-7).
    tolerance_change (float, optional): termination tolerance on function
        value/parameter changes (default: 1e-9).
    history_size (int, optional): update history size (default: 100).
    line_search_fn (str, optional): either 'strong_wolfe' or None (default: None).
c                z   < V ^8  d   QhRS[ RS[S[,          RS[RS[R,          RS[RS[RS[R	S[R,          R
R/	# )   paramslrmax_itermax_evalNtolerance_gradr/   history_sizeline_search_fnreturn)r   floatr   intstr)format__classdict__s   "r   __annotate__LBFGS.__annotate__   sq     "! "!"! FN"! 	"!
 *"! "!  "! "! d
"! 
"!r   c	                  < \        V\        4      '       d!   VP                  4       ^8w  d   \        R4      hRV8:  g   \        RV 24      hVf   V^,          ^,          pRVRVRVRVR	VR
VRV/p	\        S
V `  W4       \        V P                  4      ^8w  d   \        R4      hV P                  ^ ,          R,          V n        RV n	        R# )r    zTensor lr must be 1-elementg        zInvalid learning rate: NrL   rM   rN   rO   r/   rP   rQ   z>LBFGS doesn't support per-parameter options (parameter groups)rK   )

isinstancer   numel
ValueErrorsuper__init__lenparam_groups_params_numel_cache)selfrK   rL   rM   rN   rO   r/   rP   rQ   defaults	__class__s   &&&&&&&&& r   r_   LBFGS.__init__   s     b&!!bhhjAo:;;by6rd;<<!|q(H"n 0Ln
 	*t  !Q&P  ((+H5 r   c                x    V P                   f"   \        R V P                   4       4      V n         V P                   # )Nc              3      "   T FH  p\         P                  ! V4      '       d   ^VP                  4       ,          MVP                  4       x  KJ  	  R# 5i)rJ   N)r#   
is_complexr\   ).0ps   & r   	<genexpr>LBFGS._numel.<locals>.<genexpr>  s<      $%A "'!1!1!!4!4AGGI!'')C%s
    A/A)rc   sumrb   )rd   s   &r   _numelLBFGS._numel  s:    $ # $$ !D
    r   c                8   . pV P                    F  pVP                  f/   VP                  VP                  4       4      P	                  4       pMaVP                  P
                  '       d+   VP                  P                  4       P                  R4      pMVP                  P                  R4      p\        P                  ! V4      '       d&   \        P                  ! V4      P                  R4      pVP                  V4       K  	  \        P                  ! V^ 4      # )Nr   )rb   gradnewr\   zero_	is_sparseto_denseviewr#   rj   view_as_realappendcat)rd   viewsrl   rx   s   &   r   _gather_flat_gradLBFGS._gather_flat_grad  s    Avv~uuQWWY'--/!!!vv(--b1vv{{2%%))$/44R8LL  yy""r   c                   < V ^8  d   QhRR/# rJ   rR   N )rV   rW   s   "r   rX   rY   +  s     
W 
Wd 
Wr   c                ~   ^ pV P                    Fw  p\        P                  ! V4      '       d   \        P                  ! V4      pVP	                  4       pVP                  W#W5,            P                  V4      VR7       W5,          pKy  	  W0P                  4       8w  d    \        RV RV P                  4        24      hR# )r   alphazExpected offset z
 to equal N)	rb   r#   rj   ry   r\   add_view_asrp   AssertionError)rd   	step_sizeupdateoffsetrl   r\   s   &&&   r   	_add_gradLBFGS._add_grad+  s    A""&&q)GGIEFF66>2::1=YFOOF  [[]" #3F8:dkkm_!UVV #r   c                ~    V P                    Uu. uF"  qP                  \        P                  R 7      NK$  	  up# u upi )r   )rb   r"   r#   r$   )rd   rl   s   & r   _clone_paramLBFGS._clone_param7  s-    HLU1e&=&=>UUUs   (:c                   < V ^8  d   QhRR/# r   r   )rV   rW   s   "r   rX   rY   :  s       r   c                j    \        V P                  VR R7       F  w  r#VP                  V4       K  	  R# )T)strictN)ziprb   copy_)rd   params_datarl   pdatas   &&  r   
_set_paramLBFGS._set_param:  s'    DLL+dCHAGGEN Dr   c                    V P                  W44       \        V! 4       4      pV P                  4       pV P                  V4       WV3# N)r   rS   r}   r   )rd   closurer'   r(   r)   loss	flat_grads   &&&&&  r   _directional_evaluateLBFGS._directional_evaluate>  s<    qWY**,	r   c                  a a \        S P                  4      ^8w  d"   \        R\        S P                  4       24      h\        P                  ! 4       ! S4      oS P                  ^ ,          p\        VR,          4      pVR,          pVR,          pVR,          pVR,          pVR,          pVR,          p	S P                  S P                  ^ ,          ,          p
V
P                  R	^ 4       V
P                  R
^ 4       S! 4       p\        V4      p^pV
R	;;,          ^,          uu&   S P                  4       pVP                  4       P                  4       V8*  pV'       d   V# V
P                  R4      pV
P                  R4      pV
P                  R4      pV
P                  R4      pV
P                  R4      pV
P                  R4      pV
P                  R4      pV
P                  R4      p^ pVV8  EdO   V^,          pV
R
;;,          ^,          uu&   V
R
,          ^8X  d   VP                  4       p. p. p. p^pEMVP                  V4      pVP!                  V4      pVP#                  V4      pVR8  d   \        V4      V	8X  d4   VP%                  ^ 4       VP%                  ^ 4       VP%                  ^ 4       VP'                  V4       VP'                  V4       VP'                  RV,          4       VVP#                  V4      ,          p\        V4      pRV
9  d   R.V	,          V
R&   V
R,          pVP                  4       p\)        V^,
          RR4       FN  pVV,          P#                  V4      VV,          ,          VV&   VP+                  VV,          VV,          ) R7       KP  	  \        P                   ! VV4      ;pp \)        V4       FQ  pVV,          P#                  V 4      VV,          ,          p!V P+                  VV,          VV,          V!,
          R7       KS  	  Vf"   VP-                  \        P.                  R7      pMVP1                  V4       TpV
R
,          ^8X  d8   \3        RRVP                  4       P5                  4       ,          4      V,          pMTpVP#                  V4      p"V"V) 8  d   EM^ p#Ve{   VR8w  d   \7        R4      hS P9                  4       p$VV 3R lp%\;        V%V$VVVVV"W],
          R7      w  rpp#S P=                  VV4       VP                  4       P                  4       V8*  pMS P=                  VV4       VV8w  dl   \        P                  ! 4       ;_uu_ 4        S! 4       pRRR4       \        V4      pS P                  4       pVP                  4       P                  4       V8*  p^p#VV#,          pV
R	;;,          V#,          uu&   VV8X  d   M^W8  d   MWV'       d   MNVP!                  V4      P                  4       P                  4       V8:  d   M\        VV,
          4      V8  g   EKU   VV
R&   VV
R&   VV
R&   VV
R&   VV
R&   VV
R&   VV
R&   VV
R&   V#   + '       g   i     L; i)zPerform a single optimization step.

Args:
    closure (Callable): A closure that reevaluates the model
        and returns the loss.
z*Expected exactly one param_group, but got rL   rM   rN   rO   r/   rQ   rP   
func_evalsn_iterr)   r(   old_dirsold_stpsroH_diagprev_flat_grad	prev_lossg|=g      ?alNr   r   strong_wolfez only 'strong_wolfe' is supportedc                 *   < SP                  SWV4      # r   )r   )r'   r(   r)   r   rd   s   &&&r   r&   LBFGS.step.<locals>.obj_func  s    #99'1KKr   )r0   r   )r`   ra   r   r#   enable_gradr   staterb   
setdefaultrS   r}   r!   r   getnegsubmulr%   poprz   ranger   r"   r$   r   r
   ro   RuntimeErrorr   rG   r   )&rd   r   grouprL   rM   rN   rO   r/   rQ   rP   r   	orig_lossr   current_evalsr   opt_condr)   r(   r   r   r   r   r   r   r   ysysnum_oldr   qirbe_ir,   r4   x_initr&   s&   ff                                    r   step
LBFGS.stepE  s    t  !Q& <SARAR=S<TU 
 ##%g.!!!$d$$$/0 !34/0^, 

4<<?+q)1% I	Ylq **,	==?&&(N:  IIcNIIcN99Z(99Z(YYt_8$#34IIk*	xaKF(Oq O
 X!#MMO MM.1EE!HUU1X:8}4 Q Qq	 OOA&OOA&IIcBh'  !%%(]F h-u$#'&<"7E$K4[ MMOw{B3A$QKOOA.A6BqEFF8A;r!ufF5 4 		!V,,AwA#A;??1-15DFF8A;bedlF; ( %!*u?V?V!W$$Y/I X!#S9==?#6#6#889B> --"C &&& M)!^3&'IJJ!..0FL 9F !'7	95DQ q!$$==?..0NB q!$X% **,,&y - ;D $ 6 6 8I(}}224FH$%M ]*M,=0
 !(  uuQx||~!!#'774)#$'77c
c
$j$jd h"0&kQ -,s   .Y**Y:	)rc   rb   )r       NgHz>&.>d   N)__name__
__module____qualname____firstlineno____doc__r_   rp   r}   r   r   r   r   r#   no_gradr   __static_attributes____classdictcell____classcell__)rf   rW   s   @@r   r   r      sc     B"! "!H!#
W 
WV  ]]_L L Lr   r   )g-C6?g?r      )
r#   r   	optimizerr   r   r   __all__r   rG   r   r   r   r   <module>r      s6      5 5 )/8c*LDI Dr   