ó
    I½hjÿU  ã                   óö  • 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rS SKJr   S SKrS SKJr  S	S
KJrJr  S	SKJrJrJr  S	SKJr  S\SS4S jrS\SS4S jrS$S\S\SS4S jjrS\S\4S jr \S 5       r!\S%S\RD                  S\4S jj5       r# " S S5      r$ " S S5      r% " S S5      r&    S&S\RD                  S\'S\(S \
\)\S!4      S"\S\*\\
\+\      4   4S# jjr,g! \ a    Sr NÅf = f)'é    N)Úcontextmanager)Údeepcopy)Úupdate_wrapper)Ú
MethodType)ÚOptional)Únn)Útqdmé   )Ú
PeftConfigÚ	PeftModel)Ú	LoraLayerÚ	LoraModelÚdora)ÚBaseTunerLayerÚmodelÚreturnc                 ór  • [         R                  " U R                  5      n[        UR                  5      S:X  a~  SUR                  ;   am  SUR                  ;   a\  [        U R                  R                  5      n[        U[        U R                  5       5      R                  SS9  [        X 5      U l        gggg)ap  
Updates the forward signature of the PeftModel to include parents class signature
    model (`PeftModel`): Peft model to update the forward signature

Example:

```python
>>> from transformers import WhisperForConditionalGeneration
>>> from peft import get_peft_model, LoraConfig
>>> from peft.helpers import update_forward_signature

>>> model = WhisperForConditionalGeneration.from_pretrained("openai/whisper-tiny.en")
>>> peft_config = LoraConfig(r=8, lora_alpha=32, lora_dropout=0.1, target_modules=["q_proj", "v_proj"])

>>> peft_model = get_peft_model(model, peft_config)
>>> update_forward_signature(peft_model)
```
é   ÚargsÚkwargs©Ú__doc__Ú__name__Ú__annotations__©ÚassignedN)ÚinspectÚ	signatureÚforwardÚlenÚ
parametersr   Ú__func__r   ÚtypeÚget_base_modelr   )r   Úcurrent_signaturer   s      ÚšC:\Users\johnn\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.13_qbz5n2kfra8p0\LocalCache\local-packages\Python313\site-packages\peft/helpers.pyÚupdate_forward_signaturer'   &   s    € ô*  ×)Ò)¨%¯-©-Ó8ÐäÐ×(Ñ(Ó)¨QÓ.ØÐ'×2Ñ2Ó2ØÐ)×4Ñ4Ó4ä˜5Ÿ=™=×1Ñ1Ó2ˆÜØ”T˜%×.Ñ.Ó0Ó1×9Ñ9ÐDnò	
ô # 7Ó2ˆ�ð 5ð 3ð 	/ó    c                 óæ  • [        U S5      (       d  g[        R                  " U R                  5      n[	        UR
                  5      S:X  a   SUR
                  ;   a  SUR
                  ;   d)  [	        UR
                  5      S:X  am  SUR
                  ;   a\  [        U R                  R                  5      n[        U[        U R                  5       5      R                  SS9  [        X 5      U l        ggg)	a:  
Updates the generate signature of a PeftModel with overriding generate to include parents class signature
    model (`PeftModel`): Peft model to update the generate signature

Example:

```python
>>> from transformers import AutoModelForSeq2SeqLM, AutoTokenizer
>>> from peft import get_peft_model, LoraConfig, TaskType
>>> from peft.helpers import update_generate_signature

>>> model_name_or_path = "bigscience/mt0-large"
>>> tokenizer = AutoTokenizer.from_pretrained(model_name_or_path)
>>> model = AutoModelForSeq2SeqLM.from_pretrained(model_name_or_path)

>>> peft_config = LoraConfig(
...     task_type=TaskType.SEQ_2_SEQ_LM, inference_mode=False, r=8, lora_alpha=32, lora_dropout=0.1
... )
>>> peft_model = get_peft_model(model, peft_config)
>>> update_generate_signature(peft_model)
>>> help(peft_model.generate)
```
ÚgenerateNr   r   r   r
   r   r   )Úhasattrr   r   r*   r    r!   r   r"   r   r#   r$   r   )r   r%   r*   s      r&   Úupdate_generate_signaturer,   H   sÍ   € ô0 �5˜*×%Ñ%ØÜ×)Ò)¨%¯.©.Ó9ÐäÐ×(Ñ(Ó)¨QÓ.ØÐ'×2Ñ2Ó2ØÐ)×4Ñ4Ó4Ü
Ð×*Ñ*Ó
+¨qÓ
0°XÐAR×A]ÑA]Ó5]Ü˜EŸN™N×3Ñ3Ó4ˆÜØÜ�×%Ñ%Ó'Ó(×1Ñ1Ø?ò	
ô
 $ HÓ4ˆ�ð 6^Ð
0r(   Úmethodc                 ó¢   • US:X  a  [        U 5        gUS:X  a  [        U 5        gUS:X  a  [        U 5        [        U 5        g[        SU S35      e)a‚  
Updates the signature of a PeftModel include parents class signature for forward or generate method
    model (`PeftModel`): Peft model to update generate or forward signature method (`str`): method to update
    signature choose one of "forward", "generate", "all"

Example:
```python
>>> from transformers import AutoModelForSeq2SeqLM, AutoTokenizer
>>> from peft import get_peft_model, LoraConfig, TaskType
>>> from peft.helpers import update_signature

>>> model_name_or_path = "bigscience/mt0-large"
>>> tokenizer = AutoTokenizer.from_pretrained(model_name_or_path)
>>> model = AutoModelForSeq2SeqLM.from_pretrained(model_name_or_path)

>>> peft_config = LoraConfig(
...     task_type=TaskType.SEQ_2_SEQ_LM, inference_mode=False, r=8, lora_alpha=32, lora_dropout=0.1
... )
>>> peft_model = get_peft_model(model, peft_config)
>>> update_signature(peft_model)
>>> help(peft_model.generate)
```
r   r*   Úallzmethod zE is not supported please choose one of ['forward', 'generate', 'all']N)r'   r,   Ú
ValueError)r   r-   s     r&   Úupdate_signaturer1   q   sP   € ð0 �ÓÜ  Õ'Ø	�:Ó	Ü! %Õ(Ø	�5‹Ü  Ô'Ü! %Õ(ä˜7 6 (Ð*oÐpÓqÐqr(   Úmodel_name_or_pathc                 ó^   • Sn [         R                  " U 5        U$ ! [         a    Sn U$ f = f)zÚ
Check if the model is a PEFT model.

Args:
    model_name_or_path (`str`):
        Model id to check, can be local or on the Hugging Face Hub.

Returns:
    `bool`: True if the model is a PEFT model, False otherwise.
TF)r   Úfrom_pretrainedÚ	Exception)r2   Úis_peft_models     r&   Úcheck_if_peft_modelr7   ”   sA   € ð €MðÜ×"Ò"Ð#5Ô6ð
 Ðøô	 ó à‰àÐð	ús   „ œ,«,c              #   ó6  #   • [        U[        [        45      (       d  [        S[	        U5       35      e0 nU R                  5        Hm  n[        U[        5      (       d  M  UR                  R                  5       X#'   UR                  R                  5        VVs0 s H
  u  pEXEU-  _M     snnUl        Mo     U(       d  [        S5      e Sv •  UR                  5        H  u  p6Xcl        M     gs  snnf ! UR                  5        H  u  p6Xcl        M     f = f7f)aÛ  
Context manager to temporarily rescale the scaling of the LoRA adapter in a model.

The original scaling values are restored when the context manager exits. This context manager works with the
transformers and diffusers models that have directly loaded LoRA adapters.

For LoRA, applying this context manager with multiplier in [0, 1] is strictly equivalent to applying
[wise-ft](https://huggingface.co/papers/2109.01903) (see [#1940](https://github.com/huggingface/peft/issues/1940)
for details). It can improve the performances of the model if there is a distribution shiftbetween the training
data used for fine-tuning, and the test data used during inference.

Warning: It has been reported that when using Apple's MPS backend for PyTorch, it is necessary to add a short sleep
    time after exiting the context before the scales are fully restored.

Args:
    model: The model containing `LoraLayer` modules whose scaling is to be adjusted.
    multiplier (float or int):
        The multiplier that rescales the `scaling` attribute. Must be of type float or int.

Raises:
    ValueError: If the model does not contain any `LoraLayer`
        instances, indicating that the model does not support scaling.

Example:

```python
>>> model = ModelWithLoraLayer()
>>> multiplier = 0.5
>>> with rescale_adapter_scale(model, multiplier):
...     outputs = model(**inputs)  # Perform operations with the scaled model
>>> outputs = model(**inputs)  # The original scaling values are restored here
```
z1Argument multiplier should be of type float, got z6scaling is only supported for models with `LoraLayer`sN)Ú
isinstanceÚfloatÚintÚ	TypeErrorr#   Úmodulesr   ÚscalingÚcopyÚitemsr0   )r   Ú
multiplierÚoriginal_scalingÚmoduleÚkÚvr>   s          r&   Úrescale_adapter_scalerF   ©   sô   é € ôH �j¤5¬# ,×/Ñ/ÜÐKÌDÐQ[ÓL\ÐK]Ð^Ó_Ð_ð ÐØ—-‘-–/ˆÜ�fœi×(Ó(Ø'-§~¡~×':Ñ':Ó'<ÐÑ$Ø<B¿N¹N×<PÑ<PÔ<RÔSÒ<R±D°A˜a Z¡Ò/Ñ<RÒSˆFŽNñ "ö ÜÐQÓRÐRð%Ûð  0×5Ñ5Ö7‰OˆFØ$ŽNò  8ùó Tøð  0×5Ñ5Ö7‰OˆFØ$ŽNò  8üs0   ‚ADÁ!9DÂC/Â+DÃC5 Ã&DÃ5!DÄDÚactivec              #   óÆ  #   • U(       d  Sv •  g0 nU R                  5        H1  u  p4[        U[        5      (       d  M  UR                  X#'   SUl        M3      Sv •  U R                  5        H,  u  p4[        U[        5      (       d  M  X2;   d  M#  X#   Ul        M.     g! U R                  5        H,  u  p4[        U[        5      (       d  M  X2;   d  M#  X#   Ul        M.     f = f7f)a  
Context manager disables input dtype casting to the dtype of the weight.

Parameters:
    model (nn.Module):
        The model containing PEFT modules whose input dtype casting is to be adjusted.
    active (bool):
        Whether the context manager is active (default) or inactive.

NF)Únamed_modulesr9   r   Úcast_input_dtype_enabled)r   rG   Úoriginal_valuesÚnamerC   s        r&   Údisable_input_dtype_castingrM   æ   sÅ   é € ö  ÛØà€OØ×+Ñ+Ö-‰ˆÜ˜&¤.×1Ñ1ÙØ &× ?Ñ ?ˆÑØ*/ˆÖ'ñ	 .ðHÛà!×/Ñ/Ö1‰LˆDÜ˜f¤n×5Ñ5ÙØÕ&Ø2AÑ2G�Ö/ò	 2ø˜E×/Ñ/Ö1‰LˆDÜ˜f¤n×5Ñ5ÙØÕ&Ø2AÑ2G�Ö/ò	 2üs*   ‚AC!ÁB Á/C!ÂC!Â0CÃCÃC!c                   ó0   ^ • \ rS rSrSrSU 4S jjrSrU =r$ )ÚMontecloraTrainerMixini  a  
Mixin class for adding Monteclora variational loss to the Trainer's compute_loss method.

This mixin can be used with any Trainer class (e.g., Trainer, SFTTrainer) to add support for Monteclora's
variational regularization during training.

Example:
    ```python
    from transformers import Trainer
    from peft import get_peft_model, LoraConfig
    from peft.helpers import MontecloraTrainerMixin


    # custom trainer that supports Monteclora
    class MontecloraTrainer(MontecloraTrainerMixin, Trainer):
        pass


    # Configure LoRA with Monteclora
    monteclora_config = MontecloraConfig(
        num_samples=8,
        sample_scaler=1e-4,
        kl_loss_weight=1e-5,
    )
    lora_config = LoraConfig(
        r=16,
        lora_alpha=32,
        target_modules=["q_proj", "v_proj"],
        monteclora_config=monteclora_config,
    )

    # Get PEFT model and train
    model = get_peft_model(base_model, lora_config)
    trainer = MontecloraTrainer(model=model, args=training_args)
    trainer.train()
    ```
c                 ó.  >• U(       a  [         TU ]  " X4SS0UD6u  pVO[         TU ]  " X4SS0UD6nSnSnSnUR                  5        H1  n	[        U	[        5      (       d  M  XyR                  5       -   nUS-  nM3     US:”  a  Xx-  nXW-   n
U(       a  X¦4$ U
$ )a¸  
Compute loss with Monteclora variational regularization.

This method extends the standard compute_loss by adding the variational loss (KL divergence + entropy) from
Monteclora samplers to the task loss.

Args:
    model: The model being trained
    inputs: Input batch
    return_outputs: Whether to return model outputs along with loss
    **kwargs: Additional arguments

Returns:
    loss or (loss, outputs) depending on return_outputs
Úreturn_outputsTFNg        r   r
   )ÚsuperÚcompute_lossr=   r9   r   Ú_get_monteclora_loss)Úselfr   ÚinputsrQ   r   Ú	task_lossÚoutputsÚmonteclora_lossÚnum_lora_modelsrC   Ú
total_lossÚ	__class__s              €r&   rS   Ú#MontecloraTrainerMixin.compute_loss2  sµ   ø€ ö  Ü!&¡Ò!5°eÑ!cÐTXÐ!cÐ\bÑ!cÑˆI�wä™Ò,¨UÑ[È5Ð[ÐTZÑ[ˆIØˆGð ˆØˆØ—m‘m–oˆFÜ˜&¤)×,Ó,Ø"1×4OÑ4OÓ4QÑ"Q�Ø 1Ñ$’ñ &ð ˜QÓØ-Ñ?ˆOàÑ0ˆ
æ(6�
Ð$ÐF¸JÐFr(   © )F)r   Ú
__module__Ú__qualname__Ú__firstlineno__r   rS   Ú__static_attributes__Ú__classcell__)r\   s   @r&   rO   rO     s   ø† ñ$÷L'Gõ 'Gr(   rO   c                   óL   • \ rS rSrSrSS\SS4S jjrS rS rSS\4S	 jjr	S
r
g)ÚDoraCachingi\  aL  Context manager to enable DoRA caching, which improves speed of DoRA inference at the expense of memory.

With active caching, the materialized LoRA weight (B @ A) and the weight norm (base weight + LoRA weight) are
cached.

Even within the caching context, if the model is in training mode, caching is disabled. When the model switches to
training mode, the cache will be cleared.

Example:

    ```py
    >>> from peft.helpers import DoraCaching

    >>> model.eval()  # put in eval model for caching to work

    >>> with DoraCaching():  # use as a context manager
    ...     output = model(inputs)

    >>> dora_caching = DoraCaching()
    >>> dora_caching(enabled=True)  # permanently enable caching
    >>> output = model(inputs)
    >>> dora_caching(enabled=False)  # permanently disable caching
    >>> output = model(inputs)
    ```

Úenabledr   Nc                 ó   • Xl         S U l        g ©N©rf   Ú
prev_value©rU   rf   s     r&   Ú__init__ÚDoraCaching.__init__x  s   € ØŒØˆ�r(   c                 óX   • [         R                  U l        U R                  [         l        g rh   )r   ÚENABLE_DORA_CACHINGrj   rf   )rU   s    r&   Ú	__enter__ÚDoraCaching.__enter__|  s   € Ü×2Ñ2ˆŒØ#'§<¡<ŒÕ r(   c                 ó<   • U R                   [        l        S U l         g rh   )rj   r   ro   )rU   r#   ÚvalueÚ	tracebacks       r&   Ú__exit__ÚDoraCaching.__exit__€  s   € Ø#'§?¡?ŒÔ Øˆ�r(   c                 ó   • U[         l        g rh   )r   ro   rk   s     r&   Ú__call__ÚDoraCaching.__call__„  s
   € Ø#*ŒÕ r(   ri   ©T)r   r_   r`   ra   r   Úboolrl   rp   ru   rx   rb   r^   r(   r&   re   re   \  s5   † ññ6 ð °õ ò0òñ+ ÷ +ð +r(   re   c            
       óÚ   • \ rS rSrSr   SS\R                  S\S\\	\
S4      S\4S	 jjrSS jr SS\\   S\\   S\\   S
\\
   4S jjr SS\\   S\\   S\\   S
\\
   4S jjrSrg)ÚKappaTuneSelectoriˆ  a@  
Lightweight utility to compute per-module / per-parameter condition numbers and return the best LoRA targets.

Supports:
- Classic nn.Linear modules (target_modules in LoraConfig)
- Modern fused MoE weights stored as 3D nn.Parameter (gate_up_proj / down_proj, gate_proj / up_proj, etc.) used in
  Llama-4, Qwen2_MoE, Qwen3_MoE, Mixtral, OLMoE and similar models. These are returned via target_parameters.

Notes:
- Condition-number computation requires running SVD and can take several minutes on very large models. A progress
bar can be shown/disabled via `show_progress`.

Nr   Úmax_dim_size_to_analyzeÚmoe_param_suffixes.Úshow_progressc                 ód   • Xl         X l        X@l        U=(       d    SU l        S U l        S U l        g )N)z.gate_up_projz
.down_projz
.gate_projz.up_proj)r   r~   r€   r   Ú_condition_numbersÚ_parameter_condition_numbers)rU   r   r~   r   r€   s        r&   rl   ÚKappaTuneSelector.__init__—  s:   € ð Œ
Ø'>Ô$Ø*ÔØ"4÷ #
ð 9
ˆÔð ?CˆÔØHLˆÕ)r(   r   c                 ó¬  ^ ^• T R                   b  g 0 nT R                  R                  5        VVs/ s H)  u  p#[        U[        R
                  5      (       d  M&  X#4PM+     nnnT R                  (       a  [        USSS9OUnU GHÇ  u  p#UR                  n[        Gb   [        US5      (       aC  [        R                  R                  UR                  UR                  5      R                  5       nOÔ[        US5      (       ar  [        UR                   S5      (       aW  [        R                  R#                  UR                   R$                  UR                   R&                  5      R                  5       nOQUR                  R)                  5       R                  5       nO(UR                  R)                  5       R                  5       n[+        U 4S jUR,                   5       5      (       a  GMi  [.        R0                  R3                  UR5                  UR7                  S5      S	5      5      nUS   US	   S
-   -  R9                  5       n	X‘U'   GMÊ     UT l         0 n
T R                  R;                  5        V^Vs/ s HF  u  mn[+        U4S jT R<                   5       5      (       d  M,  UR?                  5       S:X  d  MB  TU4PMH     nnnT R                  (       a  [        USSS9OUnU HØ  u  mnUR                  R)                  5       R                  5       nUR,                  tnn[+        U 4S jU 5       5      (       a  MX  / n[A        U5       HT  nUU   n[.        R0                  R3                  U5      nUS   US	   S
-   -  R9                  5       n	URC                  U	5        MV     [E        U5      [G        U5      -  n	XšT'   MÚ     U
T l$        g s  snnf s  snnf )NzComputing SVD (linear layers)Úlayer)ÚdescÚunitÚquant_stateÚstateÚCBc              3   ó@   >#   • U  H  oTR                   :„  v •  M     g 7frh   ©r~   ©Ú.0ÚdimrU   s     €r&   Ú	<genexpr>Ú4KappaTuneSelector._compute_kappas.<locals>.<genexpr>Æ  s   øé € ÐIÂ¸#˜×5Ñ5Ö5Âùó   ƒr   éÿÿÿÿg:Œ0âŽyE>c              3   óF   >#   • U  H  nTR                  U5      v •  M     g 7frh   )Úendswith)r�   ÚsÚ
param_names     €r&   r‘   r’   Ô  s!   øé € ÐKÒ3J¨a�:×&Ñ& q×)Ð)Ò3Jùs   ƒ!é   zComputing SVD (MoE parameters)Úparamc              3   ó@   >#   • U  H  oTR                   :„  v •  M     g 7frh   r�   rŽ   s     €r&   r‘   r’   Ý  s   øé € ÐNÂ¸#˜×5Ñ5Ö5Âùr“   )%r‚   r   rI   r9   r   ÚLinearr€   r	   ÚweightÚbnbr+   Ú
functionalÚdequantize_4bitÚdatar‰   r:   rŠ   Úint8_vectorwise_dequantr‹   ÚSCBÚdetachÚanyÚshapeÚtorchÚlinalgÚsvdvalsÚviewÚsizeÚitemÚnamed_parametersr   r�   ÚrangeÚappendÚsumr    rƒ   )rU   Úcondition_numbersÚmodule_namerC   Úlinear_modulesÚlinear_iterr�   ÚwÚSÚkappaÚparameter_condition_numbersr˜   rš   Ú
moe_paramsÚmoe_iterÚnum_expertsÚexpert_shapeÚkappasÚ
expert_idxÚexpert_ws   `          `        r&   Ú_compute_kappasÚ!KappaTuneSelector._compute_kappasª  s7  ù€ Ø×"Ñ"Ñ.Øð /1Ðð (,§z¡z×'?Ñ'?Ô'Aô
â'AÑ#�Ü˜&¤"§)¡)×,ó "ˆ[Ó!Ù'Að 	ñ 
ð ×!×!ô �Ð&EÈGÒTàð 	ô
 $/ÑˆKØ—]‘]ˆFÜŠÜ˜6 =×1Ñ1ÜŸ™×6Ñ6°v·{±{ÀF×DVÑDVÓW×]Ñ]Ó_‘AÜ˜V W×-Ñ-´'¸&¿,¹,È×2MÑ2MÜŸ™×>Ñ>¸v¿|¹|¿¹ÐPV×P\ÑP\×P`ÑP`Óa×gÑgÓi‘AàŸ™×*Ñ*Ó,×2Ñ2Ó4‘Aà—K‘K×&Ñ&Ó(×.Ñ.Ó0�äÔIÀÇÂÓI×IÑIÚä—‘×$Ñ$ Q§V¡V¨A¯F©F°1«I°rÓ%:Ó;ˆAØ�q‘T˜Q˜r™U T™\Ñ*×0Ñ0Ó2ˆEØ-2˜kÔ*ñ# $/ð& #4ˆÔð 9;Ð#ð &*§Z¡Z×%@Ñ%@Ô%Bõ
â%BÑ!�
˜EÜÔK°4×3JÒ3JÓK×Kó  àPU×PYÑPYÓP[Ð_`ÑP`ó  ˆZ˜ÓÙ%Bð 	ñ 
ð VZ×Ug×UgŒD�Ð"BÈÒQÐmwð 	ó "*ÑˆJ˜Ø—
‘
×!Ñ!Ó#×)Ñ)Ó+ˆAØ)*¯©Ð&ˆK˜,äÔNÁÓN×NÑNÙàˆFÜ# KÖ0�
Ø˜Z™=�Ü—L‘L×(Ñ(¨Ó2�Ø˜1™  2¡¨¡Ñ.×4Ñ4Ó6�Ø—‘˜eÖ$ñ	 1ô
 ˜“K¤# f£+Ñ-ˆEØ6;¨
Ó3ñ "*ð  -HˆÕ)ùós
ùóB
s   °%O
ÁO
É6+OÊ%OÊ;OÚtop_pÚnum_modulesÚ	thresholdc                 ó  • U R                  5         U R                  (       d  / $ [        U R                  R                  5       S S9nUb/  [	        U[        U5      5      nUS U  VVs/ s H  u  pgUPM	     snn$ Ub;  [        S[        [        U5      U-  5      5      nUS U  VVs/ s H  u  pgUPM	     snn$ Ub  U VVs/ s H  u  phXƒ::  d  M  UPM     snn$ U VVs/ s H  u  pgUPM	     snn$ s  snnf s  snnf s  snnf s  snnf )Nc                 ó   • U S   $ ©Nr
   r^   ©Úxs    r&   Ú<lambda>Ú4KappaTuneSelector.get_best_targets.<locals>.<lambda>ò  s	   € ÈqÐQRÊtr(   ©Úkeyr
   )rÀ   r‚   Úsortedr@   Úminr    Úmaxr;   )	rU   rÂ   rÃ   rÄ   Úsorted_modulesrD   rL   Ú_r·   s	            r&   Úget_best_targetsÚ"KappaTuneSelector.get_best_targetsë  sý   € ð 	×ÑÔØ×&×&ØˆIä × 7Ñ 7× =Ñ =Ó ?Á^ÑTˆàÑ"Ü�K¤ ^Ó!4Ó5ˆAØ(6°r¸Ñ(:Ô;Ò(:™W˜T“DÑ(:Ò;Ð;àÑÜ�A”sœ3˜~Ó.°Ñ6Ó7Ó8ˆAØ(6°r¸Ñ(:Ô;Ò(:™W˜T“DÑ(:Ò;Ð;àÑ Ù,:ÔQªN™[˜T¸eÑ>P—D©NÒQÐQá$2Ô3¢N™˜“¡NÒ3Ð3ùó <ùó <ùó Rùã3ó   Á'C/Â%C5Â?C;ÃC;ÃDc                 ó  • U R                  5         U R                  (       d  / $ [        U R                  R                  5       S S9nUb/  [	        U[        U5      5      nUS U  VVs/ s H  u  pgUPM	     snn$ Ub;  [        S[        [        U5      U-  5      5      nUS U  VVs/ s H  u  pgUPM	     snn$ Ub  U VVs/ s H  u  phXƒ::  d  M  UPM     snn$ U VVs/ s H  u  pgUPM	     snn$ s  snnf s  snnf s  snnf s  snnf )Nc                 ó   • U S   $ rÇ   r^   rÈ   s    r&   rÊ   Ú>KappaTuneSelector.get_best_target_parameters.<locals>.<lambda>  s   € ÐXYÐZ[ÒX\r(   rÌ   r
   )rÀ   rƒ   rÎ   r@   rÏ   r    rÐ   r;   )	rU   rÂ   rÃ   rÄ   Úsorted_paramsrD   rL   rÒ   r·   s	            r&   Úget_best_target_parametersÚ,KappaTuneSelector.get_best_target_parameters  sý   € ð 	×ÑÔØ×0×0ØˆIä˜t×@Ñ@×FÑFÓHÉnÑ]ˆàÑ"Ü�K¤ ]Ó!3Ó4ˆAØ(5°b°qÑ(9Ô:Ò(9™W˜T“DÑ(9Ò:Ð:àÑÜ�A”sœ3˜}Ó-°Ñ5Ó6Ó7ˆAØ(5°b°qÑ(9Ô:Ò(9™W˜T“DÑ(9Ò:Ð:àÑ Ù,9ÔPªM™[˜T¸UÑ=O—D©MÒPÐPá$1Ô2¢M™˜“¡MÒ2Ð2ùó ;ùó ;ùó Qùã2rÕ   )r‚   rƒ   r~   r   r   r€   )é @  NT)r   N)NNN)r   r_   r`   ra   r   r   ÚModuler;   r   ÚtupleÚstrr{   rl   rÀ   r:   ÚlistrÓ   rÚ   rb   r^   r(   r&   r}   r}   ˆ  sÛ   † ñð" (-Ø8<Ø"ñMà�y‰yðMð "%ðMð % U¨3°¨8¡_Ñ5ð	Mð
 õMô&?HðD nrñ4Ø˜e‘_ð4Ø:BÀ3¹-ð4Ø[cÐdiÑ[jð4à	ˆc‰õ4ð. nrñ3Ø˜e‘_ð3Ø:BÀ3¹-ð3Ø[cÐdiÑ[jð3à	ˆc‰÷3ð 3r(   r}   rÂ   r~   r   .r€   c                 ór   • [        U UUUS9nUR                  US9nUR                  US9nU(       d  SnUUS.$ )a¬  
One-liner convenience function for KappaTune target selection. Returns both target_modules and target_parameters.

Args:
    model (nn.Module):
        Base model whose weights will be analyzed for condition numbers.
    top_p (float, optional):
        Select the top fraction of candidate modules/parameters with the lowest condition numbers.
    max_dim_size_to_analyze (int, optional):
        Upper bound on the maximum matrix dimension analyzed via SVD. Defaults to 16384.
    moe_param_suffixes (Optional[tuple[str, ...]], optional):
        Parameter-name suffixes used to identify fused MoE tensors that should be returned via `target_parameters`.
        If None, sensible defaults are used.
    show_progress (bool, optional):
        Whether to display a progress bar while computing condition numbers (SVD-based) across candidate
        tensors/modules. Disable in CI or other non-interactive environments. Defaults to True.
)r~   r   r€   )rÂ   N)Útarget_modulesÚtarget_parameters)r}   rÓ   rÚ   )r   rÂ   r~   r   r€   Úselectorrâ   rã   s           r&   Úfind_kappa_target_modulesrå     s`   € ô0 !ØØ 7Ø-Ø#ñ	€Hð ×.Ñ.°UÐ.Ð;€NØ ×;Ñ;À%Ð;ÐHÐö Ø Ðð )Ø.ñð r(   )r/   rz   )gš™™™™™É?rÜ   NT)-r   Ú
contextlibr   r?   r   Ú	functoolsr   Útypesr   Útypingr   r§   r   Úbitsandbytesrž   ÚImportErrorÚ	tqdm.autor	   Ú
peft_modelr   r   Útuners.lorar   r   r   Útuners.tuners_utilsr   r'   r,   rß   r1   r{   r7   rF   rÝ   rM   rO   re   r}   r:   r;   rÞ   Údictrà   rå   r^   r(   r&   Ú<module>rñ      s  ðó Ý %Ý Ý $Ý Ý ã Ý ðÛõ ç -ß 3Ñ 3Ý /ð3 Ið 3°$ô 3ðD&5 Yð &5°4ô &5ñR r˜Ið  r¨sð  r¸tõ  rðF¨Cð °Dô ð* ñ9%ó ð9%ðx ñ!H r§y¡yð !H¸$ô !Hó ð!H÷HNGñ NG÷b)+ñ )+÷XM3ñ M3ðd Ø#(Ø48Øñ)Ø�9‰9ð)àð)ð !ð)ð !  s¨C x¡Ñ1ð	)ð
 ð)ð 
ˆ#ˆx˜˜S™	Ñ"Ð
"Ñ#ö)øðy ó Ø
‚Cðús   ®C- Ã-C8Ã7C8