ó
    >:j©  ã            	       ót   • S r SSKJr  SSKrSSKJr  S	S\R                  S\S\\   S\R                  4S jjr	g)
ad  
This module is intended to store mask functions for use inside SHiRA construction. The mask functions are required to
have a specific signature as shown below.

Required positional arguments:
    base_layer - This is the linear layer where the shira adapter will be attached. r - This parameter is used to
    determine the number of parameters in the
                 shira adapter in a way that is consistent with LoRA sizing. SHiRA is a high rank adapter. Setting this
                 parameter does not restrict the adapter rank.
Keyword arguments can be provided as needed by the particular mask function implementation.

Return:
    mask - this is a torch.tensor of the same shape as base_layer.weight that contains 0s and 1s with the same
           dtype and device as base_layer.weight

If you would like to attach SHiRA adapters to a model using PEFT methods (such as get_peft_model()), using more
arguments than the provided positional arguments, you can create the mask function reference like the following:

```
    def create_mask_function_reference(**my_kwargs):
        def mask_fn(base_layer, r):
            ... your implementation here that might use my_kwargs ...
            return mask
        return mask_fn
```
Then, you can create your peft model with custom SHiRA mask as follows:
```
    model = ...
    my_kwargs = ...
    mask_fn = create_mask_function_reference(**my_kwargs)
    peft_config = ShiraConfig(r=4, mask_type='my_custom_mask')
    peft_config.mask_fn = mask_fn
    peft_model = get_peft_model(model, peft_config)
```

Complete training examples are provided in the examples/shira/ directory.
é    )ÚOptionalNÚ
base_layerÚrÚrandom_seedÚreturnc                 ó–  • U R                   R                  nXS   US   -   -  n[        R                  " 5       nUb  UR	                  U5        [        R
                  " U R                   R                  5       US9S U R                  U R                   R                  5      n[        R                  " UR                  U R                   R                  5      5      n[        R                  " U R                   R                  SS5      5      n	U	R                  SUR                  S5      UR                  S5      5      R                  U5      n	U	$ )Nr   é   )Ú	generatoréÿÿÿÿ)ÚweightÚshapeÚtorchÚ	GeneratorÚmanual_seedÚrandpermÚnumelÚtoÚdeviceÚ	ones_likeÚtypeÚdtypeÚ
zeros_likeÚviewÚscatter_Ú	unsqueeze)
r   r   r   Úkwargsr   Únum_shira_weightsÚrandom_generatorÚidxÚvalÚmasks
             Ú]/home/mande/repo/quber/.venv/lib/python3.13/site-packages/peft/tuners/shira/mask_functions.pyÚrandom_maskr#   ;   s	  € Ø×Ñ×#Ñ#€EØ 1™X¨¨a©Ñ0Ñ1ÐÜ—’Ó(ÐØÑØ×$Ñ$ [Ô1Ü�>Š>˜*×+Ñ+×1Ñ1Ó3Ð?OÑPÐQcÐRcÐd×
hÑ
hØ×Ñ× Ñ ó€Cô �/Š/˜#Ÿ(™( :×#4Ñ#4×#:Ñ#:Ó;Ó
<€CÜ×Ò˜J×-Ñ-×2Ñ2°1°bÓ9Ó:€DØ�=‰=˜˜CŸM™M¨!Ó,¨c¯m©m¸AÓ.>Ó?×DÑDÀUÓK€Dà€Kó    )N)
Ú__doc__Útypingr   r   Útorch.nnÚnnÚModuleÚintÚtensorr#   © r$   r"   Ú<module>r-      sF   ðñ$õL ã Ý ñ˜BŸI™Ið ¨#ð ¸HÀS¹Mð Ð_d×_kÑ_kö r$   