Repository navigation
Description
Describe the bug
A supported explicitly configured P2P policy is silently lost when its QuantizeConfig is saved and reloaded. mode='off' becomes p2p=None, so reusing the loaded configuration for quantization installs default mode='auto' rather than preserving the requested policy. Probe settings and thresholds are also lost; serializing the restored object replaces the stored meta.p2p dictionary with null. This is configuration persistence/policy-selection breakage, not a demonstrated GPU crash, numerical error or performance regression.
Priority: P2 — a supported configuration produces incorrect behavior. Specific triggers and validation boundaries are below.
Reviewed at 35987dfb7, within the merged-change window 2026-09-25 07:00 UTC–2026-11-13 07:00 UTC. The changes through 8ea76c395 were checked before filing; these causes remain.
GPU / software / model information
These are focused correctness reproductions using small generic fixtures and public model classes; no external model or dataset download is required. Each case states its execution environment and any hardware or mocking limitation. Accelerator execution is not claimed from a CPU dispatch test.
Trigger
Construct QuantizeConfig(p2p={'mode': 'off'}) or use the equivalent P2PConfig instance, serialize through to_dict()/save_pretrained(), reload through from_quant_config()/from_pretrained(), and reuse that loaded configuration without explicitly supplying p2p again.
Introducing change
Public merged PR #3489 ('feat(multi-gpu): GIL-safe P2P copies across the quantization lifecycle'), merge commit 9dd28c8 , GitHub merged_at=2026-11-09T13:35:32Z. Independently verified public PR metadata and git diff against its parent: this merge adds the p2p field, normalizer, normalization calls and meta.p2p write, but no corresponding metadata deserialization mapping. git blame attributes pinned config.py:4793 to this merge. It is after baseline and before pinned HEAD, and the defect is reproduced at pinned HEAD rather than inferred solely from the introducing patch.
Source evidence
All implementation links are immutable at the requested public HEAD. Supported field/default:
GPTQModel/gptqmodel/quantization/config.py
Lines 4096 to 4105 in 35987df
| # Peer-to-peer policy for multi-GPU quantization and inference. Replaces the | |
| # former GPTQMODEL_P2P* environment variables: `mode` ("auto"/"on"/"off"), | |
| # `probe`, `probe_mib`, `min_gbps`, `min_ratio`, `use_torch_replicate`. | |
| # `None` uses the P2PConfig defaults. | |
| p2p: Optional[Union[P2PConfig, Dict[str, Any]]] = field( | |
| default=None, | |
| metadata={"help": "Peer-to-peer policy for multi-GPU quantization/inference. " | |
| "Pass P2PConfig(mode='auto'|'on'|'off', probe=..., min_gbps=..., min_ratio=..., " | |
| "use_torch_replicate=...) or an equivalent dict. None uses the defaults."}, | |
| ) |
GPTQModel/gptqmodel/quantization/config.py
Lines 4791 to 4795 in 35987df
| meta_payload["offload_to_disk"] = self.offload_to_disk | |
| meta_payload["telemetry"] = asdict(self.telemetry) | |
| meta_payload["p2p"] = self.p2p.to_dict() if self.p2p is not None else None | |
| meta_payload["offload_to_disk_path"] = self.offload_to_disk_path | |
| meta_payload["pack_impl"] = self.pack_impl |
GPTQModel/gptqmodel/quantization/config.py
Lines 4813 to 4828 in 35987df
| out = { | |
| "bits": serialize_quant_bits(self.bits), | |
| "dynamic": self.dynamic, | |
| "group_size": self.group_size, | |
| "desc_act": self.desc_act, | |
| "lm_head": self.lm_head, | |
| "activation": self.activation, | |
| METHOD_FIELD_CODE: self.method, | |
| QUANT_METHOD_FIELD: self.method, | |
| FORMAT_FIELD_CODE: self.format, | |
| FORMAT_FIELD_CHECKPOINT: self.format, | |
| PACK_DTYPE_FIELD: str(self.pack_dtype).split(".")[-1], | |
| "rotation": self.rotation, | |
| META_FIELD: meta_payload, | |
| } | |
| self._update_output_payload(out) |
GPTQModel/gptqmodel/quantization/config.py
Lines 4611 to 4614 in 35987df
| elif key in field_names: | |
| normalized[key] = val | |
| else: | |
| log.info(f"QuantizeConfig: Ignoring unknown parameter in the quantization configuration: {key}.") |
GPTQModel/gptqmodel/quantization/config.py
Lines 4625 to 4686 in 35987df
| meta_payload = normalized.get(META_FIELD) | |
| meta_field_map = { | |
| "telemetry": "telemetry", | |
| "fallback": "fallback", | |
| "hessian": "hessian", | |
| "gptaq": "gptaq", | |
| "foem": "foem", | |
| "weight_only": "weight_only", | |
| "preprocessors": "preprocessors", | |
| "gc_mode": "gc_mode", | |
| "wait_for_submodule_finalizers": "wait_for_submodule_finalizers", | |
| "auto_forward_data_parallel": "auto_forward_data_parallel", | |
| "dense_vram_strategy": "dense_vram_strategy", | |
| "dense_vram_strategy_devices": "dense_vram_strategy_devices", | |
| "moe_vram_strategy": "moe_vram_strategy", | |
| "moe_vram_strategy_devices": "moe_vram_strategy_devices", | |
| "moe": "moe", | |
| "offload_to_disk": "offload_to_disk", | |
| "offload_to_disk_path": "offload_to_disk_path", | |
| "pack_impl": "pack_impl", | |
| "mse": "mse", | |
| "mock_quantization": "mock_quantization", | |
| "act_group_aware": "act_group_aware", | |
| "true_sequential": "true_sequential", | |
| "damp_percent": "damp_percent", | |
| "damp_auto_increment": "damp_auto_increment", | |
| "opt_rotation_epochs": "opt_rotation_epochs", | |
| "opt_finetune_epochs": "opt_finetune_epochs", | |
| "opt_train_samples": "opt_train_samples", | |
| "opt_validation_samples": "opt_validation_samples", | |
| "opt_batch_size": "opt_batch_size", | |
| "opt_rotation_lr": "opt_rotation_lr", | |
| "opt_weight_lr": "opt_weight_lr", | |
| "opt_quantizer_lr": "opt_quantizer_lr", | |
| "opt_pair_ratio": "opt_pair_ratio", | |
| "opt_seed": "opt_seed", | |
| "opt_optimizer": "opt_optimizer", | |
| "opt_weight_decay": "opt_weight_decay", | |
| "opt_betas": "opt_betas", | |
| "opt_eps": "opt_eps", | |
| "opt_amsgrad": "opt_amsgrad", | |
| "opt_sgd_momentum": "opt_sgd_momentum", | |
| "opt_sgd_dampening": "opt_sgd_dampening", | |
| "opt_sgd_nesterov": "opt_sgd_nesterov", | |
| "opt_fused_rotation": "opt_fused_rotation", | |
| "opt_gradient_checkpointing": "opt_gradient_checkpointing", | |
| "opt_stage_cudagraph": "opt_stage_cudagraph", | |
| "opt_amp": "opt_amp", | |
| "opt_best_state_dtype": "opt_best_state_dtype", | |
| "opt_train_on_noisy_inputs": "opt_train_on_noisy_inputs", | |
| "opt_scope": "opt_scope", | |
| "opt_stage_impl": "opt_stage_impl", | |
| "opt_pair_impl": "opt_pair_impl", | |
| "opt_quantizer_impl": "opt_quantizer_impl", | |
| "opt_channel_scale_clamp_min": "opt_channel_scale_clamp_min", | |
| "opt_channel_scale_clamp_max": "opt_channel_scale_clamp_max", | |
| "scale_search_chunked_activations": "scale_search_chunked_activations", | |
| } | |
| if isinstance(meta_payload, dict): | |
| for normalized_key, meta_key in meta_field_map.items(): | |
| if normalized_key not in normalized and meta_key in meta_payload: | |
| normalized[normalized_key] = meta_payload.get(meta_key) |
GPTQModel/gptqmodel/quantization/config.py
Lines 3609 to 3618 in 35987df
| def _normalize_p2p_config( | |
| value: Optional[Union[P2PConfig, Dict[str, Any]]], | |
| ) -> Optional[P2PConfig]: | |
| if value is None: | |
| return None | |
| if isinstance(value, P2PConfig): | |
| return value | |
| if not isinstance(value, dict): | |
| raise ValueError("QuantizeConfig: `p2p` must be a P2PConfig, dict, or None.") | |
| return P2PConfig(**value) |
GPTQModel/gptqmodel/quantization/config.py
Lines 4419 to 4421 in 35987df
| self.gc_mode = _normalize_gc_mode(self.gc_mode) | |
| self.moe = _normalize_moe_config(self.moe) | |
| self.p2p = _normalize_p2p_config(self.p2p) |
GPTQModel/gptqmodel/quantization/config.py
Lines 4510 to 4515 in 35987df
| def save_pretrained(self, save_dir: str, **kwargs): | |
| with open(join(save_dir, QUANT_CONFIG_FILENAME), "w", encoding="utf-8") as f: | |
| payload = self.to_dict() | |
| json_str = json.dumps(payload, indent=2) | |
| log.info(f"Saved Quantize Config: \n{json_str}") | |
| f.write(json_str) |
GPTQModel/gptqmodel/quantization/config.py
Lines 4754 to 4763 in 35987df
| with open(resolved_config_file, "r", encoding="utf-8") as f: | |
| args_from_json = json.load(f) | |
| if transformers_config: | |
| args_from_json = args_from_json["quantization_config"] | |
| config = cls.from_quant_config(args_from_json, format) | |
| if config.adapter is not None and config.adapter.path not in (None, ""): | |
| config.adapter._gptqmodel_checkpoint_source = ( | |
| os.path.abspath(save_dir), config.adapter.path, | |
| ) | |
| return config |
GPTQModel/gptqmodel/models/auto.py
Lines 766 to 775 in 35987df
| # normalize config to cfg instance | |
| if isinstance(quantize_config, Dict): | |
| quantize_config = QuantizeConfig(**quantize_config) | |
| # The P2P policy lives on the quantize config for quantization; allow the | |
| # same object here so a post-quantized load can control it without env vars. | |
| if p2p is not None: | |
| if quantize_config is not None: | |
| quantize_config.p2p = P2PConfig(**p2p) if isinstance(p2p, dict) else p2p | |
| elif quantize_config is not None: | |
| p2p = quantize_config.p2p |
GPTQModel/gptqmodel/models/loader.py
Lines 1252 to 1268 in 35987df
| def from_pretrained( | |
| cls, | |
| pretrained_model_id_or_path: str, | |
| quantize_config: BaseQuantizeConfig, | |
| backend: Union[str, BACKEND] = BACKEND.AUTO, | |
| profile: Union[str, int, PROFILE] = PROFILE.AUTO, | |
| trust_remote_code: bool = False, | |
| dtype: [str | torch.dtype] = "auto", | |
| device_map: Optional[Union[str, Dict[str, Union[int, str]]]] = None, | |
| device: Optional[Union[str, int, torch.device, Sequence[Union[str, int, torch.device]]]] = None, | |
| fuse: bool = False, | |
| p2p: Optional[Union[P2PConfig, Dict]] = None, | |
| **model_init_kwargs, | |
| ): | |
| if p2p is not None and quantize_config is not None: | |
| # The loopers read this field and install it before enabling peers. | |
| quantize_config.p2p = P2PConfig(**p2p) if isinstance(p2p, dict) else p2p |
GPTQModel/gptqmodel/looper/module_looper.py
Lines 350 to 360 in 35987df
| # Best-effort peer enablement once the dense/MoE pools are known. The | |
| # pools can span devices that ``quant_devices`` does not contain (for | |
| # example ``device="cuda:0"`` with | |
| # ``dense_vram_strategy_devices=["cuda:0", "cuda:1"]``), and module | |
| # replicas still move tensors across that union. ``enable_for_devices`` | |
| # caches, logs a single summary line, and never raises in best-effort | |
| # mode, so a failed probe never blocks quantization. | |
| cross_device_pool = self._cross_device_pool() | |
| configure_p2p(getattr(self.gptq_model.quantize_config, "p2p", None)) | |
| if len(cross_device_pool) > 1: | |
| enable_for_devices(cross_device_pool) |
GPTQModel/gptqmodel/utils/p2p.py
Lines 165 to 195 in 35987df
| def _coerce_p2p_config(config: P2PConfig | Mapping[str, Any] | None) -> P2PConfig: | |
| if config is None: | |
| return P2PConfig() | |
| if isinstance(config, P2PConfig): | |
| return config | |
| if isinstance(config, Mapping): | |
| return P2PConfig(**dict(config)) | |
| raise TypeError( | |
| "p2p config must be a P2PConfig, a mapping of its fields, or None; " | |
| f"got {type(config).__name__}" | |
| ) | |
| _CONFIG_LOCK = threading.Lock() | |
| _ACTIVE_CONFIG: P2PConfig = P2PConfig() | |
| def configure_p2p(config: P2PConfig | Mapping[str, Any] | None) -> P2PConfig: | |
| """Install the process-wide P2P policy used by every helper in this module. | |
| Quantization calls this from the loopers with ``BaseQuantizeConfig.p2p``; | |
| inference calls it with the ``p2p=`` argument of ``GPTQModel.load``. Calling | |
| it again replaces the policy and drops cached probe results. ``None`` | |
| restores the defaults, so callers never need environment variables. The | |
| policy has no effect on CPU-only runs: CPU<->CPU transfers never use peer | |
| access. | |
| """ | |
| global _ACTIVE_CONFIG, _WARNED_DEGRADED | |
| resolved = _coerce_p2p_config(config) |
GPTQModel/gptqmodel/utils/p2p.py
Lines 91 to 131 in 35987df
| @dataclass | |
| class P2PConfig: | |
| """Peer-to-peer policy for multi-GPU quantization and inference. | |
| Pass an instance as ``BaseQuantizeConfig(p2p=P2PConfig(...))``, or as | |
| ``GPTQModel.load(..., p2p=P2PConfig(...))`` when loading an already | |
| quantized model. A plain ``dict`` with the same keys is also accepted. | |
| ``mode`` | |
| ``"auto"`` enables peer access when the runtime reports a peer link, | |
| ``"on"`` additionally attempts pairs whose capability bit is false, and | |
| ``"off"`` skips GPT-QModel's pre-enablement (PyTorch still enables | |
| peers lazily inside its own copy path). | |
| ``probe`` | |
| Measure every directed pair and classify a link ``degraded`` when it is | |
| slower than ordered pinned-host staging. Diagnostic only; peer access | |
| stays enabled and no caller inserts a host relay because of it. | |
| ``probe_mib`` | |
| Preferred probe payload size in MiB; the probe steps down under | |
| memory pressure. | |
| ``min_gbps`` / ``min_ratio`` | |
| Diagnostic gates: absolute floor in GB/s, and the fraction of the | |
| ordered host-staging rate a direct copy must reach. | |
| ``use_torch_replicate`` | |
| Allow ``torch.nn.parallel.replicate`` when the GIL is enabled. It is | |
| off by default and skipped on free-threaded builds regardless because | |
| it funnels into ``torch.cuda.comm.broadcast_coalesced``, which is not | |
| thread-safe. | |
| Peer access is an accelerator concept: this config only affects CUDA/HIP | |
| device-to-device copies. It is a no-op for CPU-only runs and for | |
| CPU<->CPU transfers, which never take the peer path (no warning is | |
| emitted, and the CPU move helpers fall back to their regular copy). | |
| """ | |
| mode: str = _MODE_AUTO | |
| probe: bool = False | |
| probe_mib: int = 64 | |
| min_gbps: float = DEFAULT_MIN_GBPS | |
| min_ratio: float = DEFAULT_MIN_RATIO | |
| use_torch_replicate: bool = False |
To reproduce / expected behavior
Run from the public checkout pinned to 35987df with its dependencies installed and Python 3.12 environment active. This exact Python body was executed with real shipped code, not AST extraction or mocks; no GPU/model/download is needed.
python - <<'PY'
import tempfile
from gptqmodel.quantization import QuantizeConfig
from gptqmodel.utils.p2p import configure_p2p
q = QuantizeConfig(p2p={'mode': 'off'}, offload_to_disk=False)
payload = q.to_dict()
r = QuantizeConfig.from_quant_config(payload)
print('saved mode:', payload['meta']['p2p']['mode'])
print('restored p2p:', r.p2p)
print('installed mode:', configure_p2p(r.p2p).mode)
print('next saved p2p:', r.to_dict()['meta']['p2p'])
with tempfile.TemporaryDirectory() as folder:
q.save_pretrained(folder)
loaded = QuantizeConfig.from_pretrained(folder)
print('disk restored p2p:', loaded.p2p)
control = QuantizeConfig.from_quant_config({**payload, 'p2p': payload['meta']['p2p']})
print('top-level control mode:', control.p2p.mode)
configure_p2p(None)
PYExpected: r.p2p and loaded.p2p equal q.p2p, the installed mode remains 'off', and the next saved p2p remains the policy dictionary rather than None. The positive control should also report 'off'. A focused fix would restore p2p through the existing meta_field_map and add JSON/disk round-trip regression tests.
Observed result
Actual output, omitting package informational logs and save_pretrained's JSON log:
saved mode: off
restored p2p: None
installed mode: auto
next saved p2p: None
disk restored p2p: None
top-level control mode: off
A separate broader real-code probe used mode='off', probe=True, probe_mib=7, min_gbps=12.0, min_ratio=2.0 and verified the entire policy is saved but not restored for both dict and P2PConfig inputs. The saved policy remains in loaded.meta['p2p'] but is inert; to_dict then overwrites it from loaded.p2p=None.
Validation limits
Persistence and configure_p2p(None) policy resolution were executed with actual shipped methods on CPU. ModuleLooper's consumption of the loaded field was established by source tracing, not a full model quantization run. No real CUDA/ROCm P2P transfer, bandwidth, numerical correctness or free-threaded concurrency was tested. Runtime mocks in existing P2P unit tests do not establish hardware correctness. mode='off' skips GPT-QModel's pre-enablement; it does not promise that PyTorch itself never enables peers.
Duplicate check
Independently searched public open AND closed issues using gh issue list --repo ModelCloud/GPTQModel --state all --limit 100 with queries including 'p2p in:title,body', '"P2PConfig"', 'quantization config serialization', '"peer" "config"', '"p2p" "serialization"', 'config roundtrip', 'config save load', 'p2p in:title', '"peer"', '"to_dict"', '"p2p" "config"', '"peer-to-peer"', '"meta.p2p"', and 'config persistence'. No matching report found. Inspected public closed #1977 (older VRAM/cuSOLVER problem) and #1568 (older Windows build/header problem); neither concerns persistence of this newly introduced field. Inspected #3440 and independently ran its dynamic-adapter mutation reproduction: rank patterns remain {'model.layers.0.self_attn.q_proj': 16} after to_dict, confirming that separate closed report remains fixed. Search cannot exclude an unindexed or differently worded duplicate.
Activity
fix(config): restore P2P policy from saved quantization metadata (#3850)