
    oi                         S SK r S SKJr  S SKrS SKrS SKJrJrJrJ	r	J
r
JrJrJr  SSKJrJr  SSKJrJrJrJrJrJrJrJrJrJrJrJrJr  S SKJ r   S SK!r!S r" \RF                  " \"5        g)    N)AnyListOptionalTupleUnionDictSetCallable   )TEMPORARY_PATCHEStorch_compile)patch_functionprocess_output_optionsprocess_returnKWARGS_TYPEraise_error
ImageInputPreTokenizedInput	TextInputCacheStaticCacheHybridCacheUnpack_get_unique_storage_name)dedentc                    ^^  SS K mTR                  R                  R                    TR                  R                  R                  mS[        R                  4UU4S jjn[        TR                  R                  R                  SU5         [        TR                  R                  SU5        g ! [
         a  n [        SU 5      s S n A $ S n A ff = f!    g = f)Nr   zbitsandbytes.Linear4bitxc                   > T" U 5        U R                   (       d  U R                  U5        SU l         UR                  nU R                  b  UR	                  U R                  5      nU R
                  c  S O$U R
                  R	                  U R                  5      nU R                  R                  R                  5       nTR                  XX0R                  R                  S9R	                  U5      $ )NT)biasquant_state)compute_type_is_setset_compute_typedtypecompute_dtypetor   weightdatatmatmul_4bitr    )selfr   	inp_dtyper   r&   bitsandbytes'fix_4bit_weight_quant_state_from_modules        d/home/james-whalen/.local/lib/python3.13/site-packages/unsloth_zoo/temporary_patches/bitsandbytes.pyforward6patch_bitsandbytes_linear4bit_forward.<locals>.forward3   s    /5 ''!!!$'+D$GG	)T''(Ayy(tdiill4;M;M.N
 !!##%''++JaJa'beefopp    r/   )
r,   nnmodules
Linear4bitr-   	Exceptionr   torchTensorr   )er/   r,   r-   s     @@r.   %patch_bitsandbytes_linear4bit_forwardr9   *   s    9**2>//2I2I2q2q/q q q4 <??**55y'J|119gF?  94a889@s*   AB/ !C /
C9C
C
CC)$r6   torch.nnr2   inspect	importlibtypingr   r   r   r   r   r   r	   r
   commonr   r   utilsr   r   r   r   r   r   r   r   r   r   r   r   r   textwrapr   rer9   append r1   r.   <module>rD      sU   "     I I I 4     	'P    > ?r1   