
    ^j
                     F    d Z ddlmZ ddlmZ erddlmZ  G d de      Zy	)
aH  HfQuantizer implementation for pre-quantized Gemma checkpoints.

Handles loading of checkpoints that contain:
  - Packed integer weights (INT2/4/8) with per-channel scales
  - Static Range Quantization (SRQ) activation scales
  - Audio residual quantization (rqv2_muls)
  - Quantized embeddings
  - KV cache quantization scales
    )TYPE_CHECKING   )HfQuantizer   )GemmaQuantizationConfigc                   \    e Zd ZU dZded<   dZd Zed        Zed        Z	ede
fd	       Zy
)GemmaQuantizeraN  HfQuantizer for pre-quantized Gemma checkpoints.

    Replaces `nn.Linear` / `nn.Embedding` modules with their quantized
    counterparts during model loading, and loads quantized weights + SRQ
    scales directly from safetensors. Wrappers and unquantized layers are
    skipped via `quantization_config.modules_to_not_convert`.
    r   quantization_configTc                 "   ddl m} | j                  || j                  j                  |j
                        | _         ||| j                  | j                        }t        t        |dd       xs g       }|j                  ddg       ||_	        y )Nr   )replace_with_quant_layers)r
   modules_to_not_convert"_keys_to_ignore_on_load_unexpectedz.*\.k_cache_scale$z.*\.v_cache_scale$)
integrations.gemma_quantr   get_modules_to_not_convertr
   r   _keep_in_fp32_modulessetgetattrupdater   )selfmodelkwargsr   ignoreds        r/var/www/ramen.bs-engineer-server.com/venv/lib/python3.12/site-packages/transformers/quantizers/quantizer_gemma.py$_process_model_before_weight_loadingz3GemmaQuantizer._process_model_before_weight_loading.   s    H&*&E&E4++BBED_D_'
# * $ 8 8#'#>#>
 ge%I4PVTVW-/DEF3:0    c                      yNT r   s    r   is_serializablezGemmaQuantizer.is_serializableA       r   c                      y)NFr   r   s    r   is_trainablezGemmaQuantizer.is_trainableE   s    r   returnc                      yr   r   r   s    r   is_compileablezGemmaQuantizer.is_compileableI   r!   r   N)__name__
__module____qualname____doc____annotations__requires_calibrationr   propertyr    r#   boolr&   r   r   r   r	   r	   "   s]     32;&       r   r	   N)r*   typingr   baser   utils.quantization_configr   r	   r   r   r   <module>r2      s&    !  C)[ )r   