o
    Ni                     @  s\   d dl mZ d dlmZmZ d dlmZmZ d dlm	Z	 d dl
mZ eG dd de	ZdS )	    )annotations)	dataclassfield)OptionalUnion)
PeftConfig)PeftTypec                      s   e Zd ZU dZedddidZded< edddidZd	ed
< edddidZded< edddidZ	ded< edddidZ
ded< edddidZded<  fddZ  ZS )	OSFConfiga  
    Configuration for Orthogonal Subspace Fine-tuning (OSF).

    Args:
        effective_rank (`int` or `float`, *optional*):
            Preserved SVD rank ("high" subspace). The top-``effective_rank`` singular directions are frozen and
            retained across tasks; the remaining dimensions form the trainable low-rank subspace. If `None`, defaults
            to 50% of the smaller weight dimension per target module. Note: This differs from LoRA's `r` (trainable
            rank). In OSF, the trainable rank is `min(weight.shape) - effective_rank`.
        target_modules (`Union[list[str], str]`, *optional*):
            The names of the modules to apply OSF to. Can be a list of module names or `"all-linear"`.
        rank_pattern (`dict[str, int|float]`, *optional*):
            A dictionary of regex patterns to override `effective_rank` for specific modules. Values can be absolute
            integers or fractions in (0, 1], interpreted as a fraction of the smaller matrix dimension per target.
    Nhelpa  Preserved SVD rank ("high" subspace). The top-`effective_rank` singular directions are frozen and retained across tasks; the remaining dimensions form the trainable low-rank subspace. Trainable rank equals min(weight.shape) - effective_rank. If None, defaults to 50% of the smaller weight dimension per target module. Floats in (0, 1] are interpreted as a fraction of the smaller matrix dimension per target.)defaultmetadatazOptional[Union[int, float]]effective_rankzXThe names of the modules to apply OSF to. Can be a list of module names or 'all-linear'.zOptional[Union[list[str], str]]target_moduleszA dictionary of regex patterns to override effective_rank per module. Values can be absolute integers or fractions in (0, 1], interpreted as a fraction of the smaller matrix dimension.z&Optional[dict[str, Union[int, float]]]rank_patternzIf provided, toggles custom weight initialization behavior for certain methods. OSF ignores this flag but accepts it for config compatibility.zOptional[bool]init_weightszOOptional list of module names to save separately (ignored by OSF but accepted).zOptional[list[str]]modules_to_savezOptional per-parameter SVD target rank mapping (e.g., {'lin0.weight': 8}). OSF currently ignores this field but accepts it for forward compatibility.zOptional[dict[str, int]]target_svd_configc                   s   t    tj| _d S )N)super__post_init__r   OSF	peft_type)self	__class__ J/home/ubuntu/.local/lib/python3.10/site-packages/peft/tuners/osf/config.pyr   N   s   
zOSFConfig.__post_init__)__name__
__module____qualname____doc__r   r   __annotations__r   r   r   r   r   r   __classcell__r   r   r   r   r	   
   sF   
 	
r	   N)
__future__r   dataclassesr   r   typingr   r   peft.configr   
peft.utilsr   r	   r   r   r   r   <module>   s    