Skip to content

Commit da3cb57

Browse files
authored
[core] restrict logging of quant config based on the header size. (#14262)
restrict logging of quant config based on the header size.
1 parent 7081829 commit da3cb57

1 file changed

Lines changed: 10 additions & 1 deletion

File tree

src/diffusers/models/modeling_utils.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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+
101106
TORCH_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

Comments
 (0)