@@ -98,6 +98,11 @@ def __exit__(self, *args, **kwargs):
9898
9999_REGEX_SHARD = re .compile (r"(.*?)-\d{5}-of-\d{5}" )
100100
101+ # The `user_agent` dict is flattened into a single `user-agent` HTTP header. Serializing an
102+ # unbounded `quantization_config` into it can exceed server header size limits, so we only
103+ # attach the serialized config for telemetry when it stays under this many characters.
104+ _MAX_QUANT_CONFIG_USER_AGENT_CHARS = 2048
105+
101106TORCH_INIT_FUNCTIONS = {
102107 "uniform_" : nn .init .uniform_ ,
103108 "normal_" : nn .init .normal_ ,
@@ -1162,7 +1167,11 @@ def from_pretrained(cls, pretrained_model_name_or_path: str | os.PathLike | None
11621167
11631168 # In order to ensure popular quantization methods are supported. Can be disabled with `disable_telemetry`
11641169 user_agent ["quant" ] = hf_quantizer .quantization_config .quant_method .value
1165- user_agent ["quant_config" ] = json .dumps (hf_quantizer .quantization_config .to_dict (), sort_keys = True )
1170+ # Attach the full serialized config for telemetry, but skip it when it is large enough to
1171+ # risk exceeding HTTP header size limits (see `_MAX_QUANT_CONFIG_USER_AGENT_CHARS`).
1172+ serialized_quant_config = json .dumps (hf_quantizer .quantization_config .to_dict (), sort_keys = True )
1173+ if len (serialized_quant_config ) <= _MAX_QUANT_CONFIG_USER_AGENT_CHARS :
1174+ user_agent ["quant_config" ] = serialized_quant_config
11661175
11671176 # Force-set to `True` for more mem efficiency
11681177 if low_cpu_mem_usage is None :
0 commit comments