Repository navigation
Description
Describe the bug
The forward execution path violates the user's compute_device_filter: it chooses input/replay placement and module rehoming on cuda:0 while the sole allowed device is cuda:1. This can make exclusion ineffective for compute/activation placement. The executed evidence proves wrong target selection, not GPU allocation, OOM, numerical error or performance loss. Preserve the sole surviving device when choosing/staging the serial fallback.
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
Two visible CUDA/ROCm runtime devices, current CUDA device left at the usual 0, standard dense calibration with auto_forward_data_parallel=True and default EXCLUSIVE dense strategy without a dense device map or model placement overrides. Public QuantizeConfig(compute_device_filter=lambda ds: [d for d in ds if d.index == 1]) selects cuda:1 while BaseQModel.pre_quantize stages the layer from the family configuration on cuda:0. The public loader device=("cuda:1",) path also builds this filter at pinned HEAD. Force-serial/model placement override paths are not needed.
Introducing change
e499d4f, 2026-11-02T08:17:57Z, feat(rocm): RDNA4 (gfx1200/gfx1201/gfx1250) kernel and quantization support (#3478), specifically its fix(looper): honor compute_device_filter and the assigned pack device subchange. e499d4f ; #3478 . git diff/blame show this merge adds filtering before the existing len(devices)<=1 dispatch without changing the original cur_layer_device argument. git_view_pr confirms merged. Parent 73cda73. The filter callback existed before this commit and the identical parent probe selects cuda:1.
Source evidence
The public callback explicitly documents excluding device 0 at
GPTQModel/gptqmodel/quantization/config.py
Lines 4076 to 4093 in 35987df
| # Callback function to filter devices for compute-intensive stages (quantization and forwarding) | |
| compute_device_filter: Optional[callable] = field( | |
| default=None, | |
| metadata={"help": "Callback function to filter devices for compute-intensive stages. Function signature: fn(devices: List) -> List. " | |
| "Example to exclude device 0: compute_device_filter=lambda devices: [d for d in devices if d.index != 0]"} | |
| ) | |
| # Device for storing calibration data during input capture | |
| calibration_data_device: Optional[Union[str, torch.device]] = field( | |
| default=None, | |
| metadata={"help": "Device for storing calibration data. 'balanced' = round-robin across GPUs, or specify device like 'cuda:1'."} | |
| ) | |
| auto_forward_data_parallel: bool = field( | |
| default=True, | |
| metadata={"help": "When multi-gpu is detected, we may data clone modules to each gpu for data parallelism " | |
| "to speed up quantization forwarding. This causes extra time spent (especially for MoE layers) and vram pressure, " | |
| "leading in some cases to slower forwarding or vram OOM"} |
GPTQModel/gptqmodel/looper/forward_executor.py
Lines 227 to 255 in 35987df
| devices = select_forward_devices_fn(cur_layer_device) | |
| # Apply `compute_device_filter` before staging replicas. Filtering only in | |
| # `run_parallel` leaves a full copy of the module on every excluded GPU, | |
| # which both defeats the caller's device restriction and can OOM the | |
| # device it was meant to avoid. | |
| devices = self._filter_forward_devices(devices) | |
| if len(devices) <= 1: | |
| return self.run_single( | |
| module=module, | |
| processor=processor, | |
| current_subset=current_subset, | |
| ordered_module_names=ordered_module_names, | |
| layer_inputs=layer_inputs, | |
| layer_input_kwargs=layer_input_kwargs, | |
| position_ids=position_ids, | |
| attention_masks=attention_masks, | |
| cur_layer_device=cur_layer_device, | |
| is_lm_head_module=is_lm_head_module, | |
| shared_kv_cache_dict=shared_kv_cache_dict, | |
| layer_index=layer_index, | |
| need_outputs=need_outputs, | |
| reuse_kv=reuse_kv, | |
| progress_pb=progress_pb, | |
| progress_title=progress_title, | |
| progress_stage=progress_stage, | |
| progress_rows_per_batch=progress_rows_per_batch, | |
| progress_total_rows=progress_total_rows, | |
| preserve_module_devices=preserve_module_devices, | |
| apply_moe_config=apply_moe_config, |
GPTQModel/gptqmodel/looper/forward_executor.py
Lines 346 to 365 in 35987df
| processor._set_current_batch_index(batch_idx) | |
| try: | |
| exec_device = cur_layer_device | |
| if preserve_module_devices: | |
| module_target = getattr(module, "target_device", None) | |
| if module_target is not None: | |
| exec_device = module_target | |
| # Capture input device before moving - used for output placement | |
| cached_layer_inputs = layer_inputs[batch_idx] | |
| cached_layer_kwargs = layer_input_kwargs[batch_idx] | |
| input_device = cached_layer_inputs[0].device if cached_layer_inputs else cur_layer_device | |
| layer_input = move_nested_to_device(cached_layer_inputs, device=exec_device) | |
| raw_mask = attention_masks[batch_idx] | |
| attn_tensor = raw_mask if raw_mask is None else move_nested_to_device(raw_mask, device=exec_device) | |
| keep_mask = None | |
| if attn_tensor is not None: |
GPTQModel/gptqmodel/looper/forward_executor.py
Lines 404 to 426 in 35987df
| if not preserve_module_devices: | |
| rehome_module_to_device( | |
| module, | |
| cur_layer_device, | |
| move_parameters=True, | |
| move_buffers=True, | |
| root_module=getattr(self.looper.gptq_model, "model", None), | |
| ) | |
| with self._moe_forward_context( | |
| module=module, | |
| processor=processor, | |
| current_subset=current_subset, | |
| ordered_module_names=ordered_module_names, | |
| apply_moe_config=apply_moe_config, | |
| ): | |
| module_output = None | |
| try: | |
| with torch.no_grad(): | |
| if is_lm_head_module: | |
| module_output = module(*layer_input) | |
| else: | |
| module_output = module(*layer_input, **additional_inputs) |
GPTQModel/gptqmodel/models/loader.py
Lines 1464 to 1480 in 35987df
| with suspend_hf_weight_init(): | |
| # normalize and auto select quantization device is not passed | |
| if quantize_config.device is None: | |
| requested_devices = _explicit_requested_devices(device) | |
| # `quantize_config.device` only carries an accelerator family | |
| # (ordinals are stripped by `normalize_device`), so an explicit | |
| # device list is expressed through the compute filter. | |
| quantize_config.device = auto_select_device(None, None) | |
| if requested_devices is not None and quantize_config.compute_device_filter is None: | |
| wanted = {str(target) for target in requested_devices} | |
| quantize_config.compute_device_filter = ( | |
| lambda devices, _wanted=wanted: [ | |
| target for target in devices if str(target) in _wanted | |
| ] | |
| ) | |
| else: | |
| quantize_config.device = normalize_device(quantize_config.device) |
GPTQModel/gptqmodel/models/base.py
Lines 3191 to 3202 in 35987df
| def pre_quantize(self, module: nn.Module) -> nn.Module: | |
| if get_device(module) == META or _module_has_meta_tensors(module): | |
| if self._materialize_floatx_layer_shell(module, self.quantize_config.device): | |
| return module | |
| return self.shell_module_materialize( | |
| target_submodule=module, | |
| device=self.quantize_config.device, | |
| ) | |
| elif get_device(module) == CPU and self.quantize_config.device != CPU: | |
| return move_to(module, device=self.quantize_config.device) | |
| else: | |
| return module |
GPTQModel/gptqmodel/utils/torch.py
Lines 45 to 60 in 35987df
| def as_torch_device(device_like) -> torch.device: | |
| """Resolve a device-like value without assigning an implicit ordinal. | |
| GPT-QModel's ``DEVICE`` enum names a kernel support family, and its | |
| ``DEVICE.ROCM`` member intentionally has the value ``"rocm"`` even though | |
| PyTorch exposes ROCm through the ``cuda`` namespace. ``torch.device`` | |
| therefore rejects it. Resolve enums through their runtime ``type`` while | |
| keeping families indexless, just like ``torch.device("cuda")``. Calling | |
| ``to_torch_device()`` here would pin family selectors to device 0 instead | |
| of honoring the caller's current CUDA/XPU/NPU device. | |
| """ | |
| if isinstance(device_like, torch.device): | |
| return device_like | |
| resolver = getattr(device_like, "to_torch_device", None) | |
| if callable(resolver): | |
| return torch.device(device_like.type) |
GPTQModel/gptqmodel/looper/stage_layer.py
Line 646 in 35987df
| module = looper.gptq_model.pre_quantize(module) |
GPTQModel/gptqmodel/looper/stage_layer.py
Lines 716 to 721 in 35987df
| materialize_model(module) | |
| cur_layer_device = get_device(module) | |
| if getattr(cur_layer_device, "type", None) == "meta": | |
| # Lazy shell layers can stay meta until a later subset stage materializes them. | |
| cur_layer_device = normalize_device_like(looper.gptq_model.quantize_config.device) or CPU |
GPTQModel/gptqmodel/looper/module_looper.py
Lines 331 to 348 in 35987df
| self._dense_vram_strategy = dense_vram_strategy | |
| self._moe_vram_strategy = moe_vram_strategy | |
| dense_strategy_devices = getattr(self.gptq_model.quantize_config, "dense_vram_strategy_devices", None) | |
| moe_strategy_devices = getattr(self.gptq_model.quantize_config, "moe_vram_strategy_devices", None) | |
| self._dense_quant_devices = _resolve_strategy_device_pool( | |
| dense_strategy_devices, | |
| quant_devices, | |
| label="dense_vram_strategy_devices", | |
| ) | |
| self._moe_quant_devices = _resolve_strategy_device_pool( | |
| moe_strategy_devices, | |
| quant_devices, | |
| label="moe_vram_strategy_devices", | |
| ) | |
| # Keep a cheap flag so the planner can skip split-pool logic entirely | |
| # when the user leaves a pool on the default exclusive behavior. | |
| self._dense_vram_strategy_explicit = bool(dense_strategy_devices) or self._dense_vram_strategy != VramStrategy.EXCLUSIVE | |
| self._moe_vram_strategy_explicit = bool(moe_strategy_devices) or self._moe_vram_strategy != VramStrategy.EXCLUSIVE |
GPTQModel/gptqmodel/looper/stage_subset.py
Lines 424 to 480 in 35987df
| forward = processor.forward | |
| calibration_coverage_policy = _resolve_subset_calibration_coverage_policy( | |
| processor, fallback | |
| ) | |
| moe_groups: Dict[str, List[str]] = {} | |
| forward_device_map: Dict[str, torch.device] = {} | |
| subset_forward_serial = False | |
| restore_forward_device_overrides = True | |
| layer_candidate_names = _collect_layer_candidate_names(subset=subset, full=full) | |
| subset_moe_group_key_by_name: Dict[str, Optional[str]] = { | |
| name: looper._extract_moe_group_key(name) for name in subset | |
| } | |
| layer_moe_group_key_by_name: Dict[str, Optional[str]] = { | |
| name: looper._extract_moe_group_key(name) for name in layer_candidate_names | |
| } | |
| subset_moe_module_names = [ | |
| name | |
| for name, group_key in subset_moe_group_key_by_name.items() | |
| if group_key is not None | |
| ] | |
| layer_moe_module_names = [ | |
| name | |
| for name, group_key in layer_moe_group_key_by_name.items() | |
| if group_key is not None | |
| ] | |
| is_moe_subset = len(subset_moe_module_names) >= looper._moe_subset_threshold | |
| layer_has_moe = len(layer_moe_module_names) >= looper._moe_subset_threshold | |
| moe_modules_set = set(subset_moe_module_names) | |
| if layer_has_moe: | |
| for module_name in layer_candidate_names: | |
| # Group experts across the full MoE family so device placement is | |
| # consistent even when the current subset only contains one slice. | |
| group_key = layer_moe_group_key_by_name[module_name] | |
| if group_key is None: | |
| continue | |
| moe_groups.setdefault(group_key, []).append(module_name) | |
| dense_groups = _collect_dense_groups( | |
| layer_candidate_names, | |
| layer_moe_group_key_by_name, | |
| planning_layer_modules, | |
| ) | |
| for name, named_module in subset.items(): | |
| setattr(named_module, "moe_enabled", name in moe_modules_set) | |
| dense_strategy_active = bool( | |
| getattr(looper, "_dense_vram_strategy_explicit", False) | |
| ) | |
| moe_strategy_active = bool( | |
| getattr(looper, "_moe_vram_strategy_explicit", False) | |
| ) and bool(moe_groups) | |
| if dense_strategy_active or moe_strategy_active: | |
| dense_devices = [ |
GPTQModel/gptqmodel/looper/stage_subset.py
Lines 554 to 586 in 35987df
| if forward_device_map or placement_override_active: | |
| # Start from each leaf's current device so an excluded tensor is never | |
| # moved implicitly with its parent layer. | |
| baseline_devices = _resolve_forward_baseline_devices( | |
| subset=subset, | |
| full=full, | |
| ) | |
| for module_name, baseline_device in baseline_devices.items(): | |
| forward_device_map.setdefault(module_name, baseline_device) | |
| if placement_override_active: | |
| for module_name, planned_device in list(forward_device_map.items()): | |
| module_ref = subset.get(module_name) | |
| if module_ref is None and full is not None: | |
| module_ref = full.get(module_name) | |
| actual_module = module_ref.module if isinstance(module_ref, NamedModule) else module_ref | |
| if actual_module is not None: | |
| forward_device_map[module_name] = placement_override(actual_module, planned_device) | |
| for module_name, named_module in subset.items(): | |
| preferred_device = forward_device_map.get(module_name) | |
| if preferred_device is not None: | |
| named_module.state["preferred_quant_device"] = preferred_device | |
| restore_forward_device_overrides = False | |
| subset_forward_serial = True | |
| auto_forward_data_parallel = getattr( | |
| looper.gptq_model.quantize_config, | |
| "auto_forward_data_parallel", | |
| True, | |
| ) | |
| subset_forward_serial = subset_forward_serial or not auto_forward_data_parallel |
GPTQModel/gptqmodel/looper/stage_subset.py
Lines 1147 to 1170 in 35987df
| with capture_context: | |
| forward_outputs = looper._run_forward_batches( | |
| module=module, | |
| processor=processor, | |
| current_subset=None if disable_moe_hooks else subset, | |
| ordered_module_names=subset_names, | |
| layer_inputs=layer_inputs, | |
| layer_input_kwargs=layer_input_kwargs, | |
| position_ids=position_ids, | |
| attention_masks=attention_masks, | |
| cur_layer_device=cur_layer_device, | |
| is_lm_head_module=is_lm_head_module, | |
| shared_kv_cache_dict=shared_kv_cache_dict, | |
| layer_index=layer_index, | |
| need_outputs=need_outputs, | |
| reuse_kv=reuse_kv, | |
| progress_pb=forward_pb, | |
| progress_title=forward_msg, | |
| progress_stage="Forward", | |
| progress_rows_per_batch=forward_row_counts, | |
| progress_total_rows=plan.forward_total_rows, | |
| force_serial=plan.subset_forward_serial, | |
| preserve_module_devices=preserve_devices, | |
| ) |
GPTQModel/gptqmodel/looper/module_looper.py
Lines 1458 to 1481 in 35987df
| return self._forward_executor.run( | |
| module=module, | |
| processor=processor, | |
| current_subset=current_subset, | |
| ordered_module_names=ordered_module_names, | |
| layer_inputs=layer_inputs, | |
| layer_input_kwargs=layer_input_kwargs, | |
| position_ids=position_ids, | |
| attention_masks=attention_masks, | |
| cur_layer_device=cur_layer_device, | |
| is_lm_head_module=is_lm_head_module, | |
| shared_kv_cache_dict=shared_kv_cache_dict, | |
| layer_index=layer_index, | |
| need_outputs=need_outputs, | |
| reuse_kv=reuse_kv, | |
| progress_pb=progress_pb, | |
| progress_title=progress_title, | |
| progress_stage=progress_stage, | |
| progress_rows_per_batch=progress_rows_per_batch, | |
| progress_total_rows=progress_total_rows, | |
| force_serial=force_serial, | |
| preserve_module_devices=preserve_module_devices, | |
| apply_moe_config=apply_moe_config, | |
| select_forward_devices_fn=select_forward_devices, |
To reproduce / expected behavior
Run from a public checkout with the specified history and Python 3.12+ with torch installed. This is AST-isolated shipped ForwardExecutor execution. Backend moves, replica creation and thread-pool submissions are fake; real run(), run_single() and run_parallel() control flow executes. It measures selected execution/rehome targets and never claims GPU numerics.
Exact command:
python - 35987dfb7433d9b539e5ca9656621473fcd1fbe8 <<'PY'
import ast
import subprocess
import sys
import types
from concurrent.futures import Future
import torch
revision = sys.argv[1]
source = subprocess.check_output(['git', 'show',
f'{revision}:gptqmodel/looper/forward_executor.py'], text=True)
tree = ast.parse(source)
tree.body = [n for n in tree.body if not isinstance(n, ast.ImportFrom) or not n.level]
observed = []
devices = [torch.device('cuda:0'), torch.device('cuda:1')]
def move(value, device):
return value
def rehome(module, device, **kwargs):
observed.append(('single', str(device)))
def clone(module, devices, **kwargs):
return {d: types.SimpleNamespace(target_device=d) for d in devices}
def worker(module, processor, batch_idx, *args, **kwargs):
observed.append(('parallel', str(module.target_device)))
return batch_idx, None, None
class Pool:
def submit(self, device, fn, *args, **kwargs):
future = Future()
future.set_result(fn(*args, **kwargs))
return future
submit_serial = submit
class Module(torch.nn.Module):
def forward(self, value, **kwargs):
return value
namespace = dict(DEVICE_THREAD_POOL=Pool(), StopForward=type('StopForward', (Exception,), {}),
normalize_seq_mask=lambda *a, **k: None, setup_logger=lambda: None,
clone_module_for_devices=clone, forward_batch_worker=worker,
move_nested_to_device=move, rehome_module_to_device=rehome,
select_forward_devices=lambda base: devices, move_to=move,
nested_move_to=move, torch_sync=lambda: None)
exec(compile(tree, '<public forward_executor.py>', 'exec'), namespace)
qcfg = types.SimpleNamespace(compute_device_filter=lambda ds: [d for d in ds if d.index == 1],
auto_forward_data_parallel=True, calibration_data_device='cpu')
model = types.SimpleNamespace(quantize_config=qcfg,
prepare_layer_replay_kwargs=lambda **k: k['additional_inputs'],
prepare_layer_replay_keep_mask=lambda **k: k['keep_mask'])
looper = types.SimpleNamespace(gptq_model=model, support_batch_quantize=False,
moe_routing_override=None, _resolve_batch_total=lambda total, inputs: total,
_collect_row_counts=lambda inputs: [1] * len(inputs),
_set_processor_mask=lambda *a: None)
processor = types.SimpleNamespace(num_batches=1, _set_current_batch_index=lambda idx: None)
executor = namespace['ForwardExecutor'](looper)
executor.run(module=Module(), processor=processor,
layer_inputs=[[torch.zeros(1, 1)]], layer_input_kwargs=[{}],
position_ids=[], attention_masks=[None], cur_layer_device=devices[0],
is_lm_head_module=False, shared_kv_cache_dict={}, layer_index=0,
need_outputs=False, reuse_kv=False)
print(f'{revision[:9]}: allowed=cuda:1 observed={observed}')
PYRepeat the same heredoc with argument e499d4f, 73cda73, and 2ee8cd7 for introducing commit, introducing parent, and baseline. Each run completes in seconds. Inputs are one CPU zeros(1,1) batch, no attention mask/position IDs/KV reuse, original placement cuda:0, candidate devices cuda:0/cuda:1, and filter keeping only cuda:1. Expected selected execution target: cuda:1.
Observed result
Pinned HEAD: 35987dfb7: allowed=cuda:1 observed=[('single', 'cuda:0')]. Introducing commit: e499d4fc0: allowed=cuda:1 observed=[('single', 'cuda:0')]. Introducing parent: 73cda7319: allowed=cuda:1 observed=[('parallel', 'cuda:1')]. Baseline: 2ee8cd7c4: allowed=cuda:1 observed=[('parallel', 'cuda:1')]. The serial label records the argument passed to rehome_module_to_device; parallel records the actual selected replica passed to the worker.
Validation limits
Python 3.12.16 and torch 2.15.0+cu132 with CUDA unavailable. AST removes relative imports; backend movement, cloning, worker and pool are mocked. Proves target-selection control flow and before/after regression; public configuration/caller reachability is static source proof. No actual multi-GPU module/tensor allocation, integration quantization, GPU numerical correctness, OOM, performance or GIL=0 behavior validated.
Duplicate check
Independently searched open and closed public issues with gh issue list --state all --limit 100, including "compute_device_filter", "device filter", "cuda:1" quantization, "single device", "3577", "forward" "filter", "excluded GPU" and "cuda:0" "cuda:1" in:title. No report of this sole-survivor serial-dispatch bug found. Viewed closed #2326 (BALANCED MoE/module restoration; last discussion still said that separate issue was valid), #1610 (older multi-GPU setup), #1977 (cuSOLVER/VRAM), #2116 (uninitialized replay state after skipped subsets), #2220 (multi-GPU quantized inference; historical fix acknowledged), and #2159 (snapshot_download kwargs). These are different contracts/inputs; their closure is not treated as proof their original GPU scenarios remain fixed. Public #3577 is a loader parsing fix, independently checked and not a fix of the surviving ForwardExecutor branch.
Activity
fix(looper): stage serial forward on the surviving filtered device (M…