#2226·garak

hf_args keys are silently dropped on transformers 5.x: `torch_dtype` has no effect and `quantization_config` cannot be passed

Author: enqiduCreated Sep 22, 2026Updated Sep 29, 2026
Labelsbug

Summary

On the transformers range garak pins (transformers>=5.14.1,<6.0), _gather_hf_params silently discards every hf_args key that is not an explicit parameter of the constructor's signature. In transformers v5, PreTrainedModel.from_pretrained has the signature (*model_args, **kwargs) — nothing is explicit — so the filter drops almost everything.

Two concrete consequences:

  1. hf_args.torch_dtype has no effect at all. It was renamed to dtype in transformers v5, so it is not in any constructor signature and never survives the filter. Every torch_dtype setting in the codebase is inert, including the "float16" defaults for Pipeline/Model/LLaVA and the explicit "float32" requests in probes/atkgen.py and buffs/paraphrase.py. Models load at whatever dtype their config.json specifies.
  2. A quantized checkpoint cannot be loaded through the HF generators. quantization_config is likewise absent from the signature, so setting it in hf_args is silently ignored. There is no other path to AWQ/GPTQ/bitsandbytes loading in the generator.

Neither failure warns or errors.

Reproduction

No model download or GPU required — this exercises garak's own _gather_hf_params against the real transformers signatures.

python
import inspect
from transformers import AutoModelForCausalLM, pipeline
from garak.resources.api.huggingface import HFCompatible

class Stub(HFCompatible):
    name, device = "Qwen/Qwen3-8B", "cpu"
    def __init__(self, hf_args): self.hf_args = dict(hf_args)

# garak's own DEFAULT_PARAMS for Pipeline/Model (generators/huggingface.py:50-54)
defaults = {"torch_dtype": "float16", "do_sample": True, "device": None}

print(Stub(defaults)._gather_hf_params(hf_constructor=pipeline))
print(Stub(defaults)._gather_hf_params(hf_constructor=AutoModelForCausalLM.from_pretrained))

q = dict(defaults, quantization_config={"bits": 4, "quant_method": "awq"})
print(Stub(q)._gather_hf_params(hf_constructor=AutoModelForCausalLM.from_pretrained))

Output on transformers 5.17.0 / torch 2.14.0 / Python 3.12:

{'model': 'Qwen/Qwen3-8B', 'do_sample': True, 'device_map': 'cpu', 'trust_remote_code': False}
{'device_map': 'cpu', 'trust_remote_code': False}
{'device_map': 'cpu', 'trust_remote_code': False}

torch_dtype is absent from all three. quantization_config is absent from the third.

Root cause

garak/resources/api/huggingface.py, _gather_hf_params:

python
params_to_process = inspect.signature(hf_constructor).parameters
...
for k in params_to_process:
    if k in params:
        ...

inspect.signature(AutoModelForCausalLM.from_pretrained).parameters is ['model_args', 'kwargs'] on transformers 5.17.0. The union with inspect.signature(pipeline).parameters rescues device, device_map and dtype, but torch_dtype is not a v5 parameter name and quantization_config is not in either signature.

The method's own comment anticipates exactly this:

this may be a bit too naive as it will pass any parameter valid for the hf_constructor signature / this falls over when passed some from_pretrained methods as the callable model params are not always explicit

A side effect: the if k == "torch_dtype" and hasattr(torch, val) branch a few lines below is now unreachable, because torch_dtype never passes the k in params_to_process gate.

Impact

  • generators/huggingface.py:51 (Pipeline, inherited by Model at :367) and :523 (LLaVA) — the float16 defaults never apply.
  • probes/atkgen.py:77 — requests {"device": "cpu", "torch_dtype": "float32"}; the float32 request is dropped, so the attack-generation model loads at its config dtype on CPU.
  • buffs/paraphrase.py:105 — same, "torch_dtype": "float32".
  • Quantized guards and deployed int4/int8 models cannot be scanned at all.
  • The report records neither the resolved dtype nor any quantization config, so none of this is visible after a run.

Suggested direction

  1. Map torch_dtype → dtype for transformers ≥5 (or accept both and normalise), keeping the existing string→torch.dtype conversion.
  2. Stop relying on signature introspection alone when the constructor is **kwargs-only — either allow an explicit passthrough set (dtype, quantization_config, low_cpu_mem_usage, …) or warn when an hf_args key is discarded, so a dropped key is never silent.
  3. Record the resolved dtype and any quantization config in the run report.

I'm happy to open a PR for this if the direction looks right — I'd start with (1) and the "warn on discarded hf_args key" half of (2), since those are small and independently testable.

Environment

garak main; transformers 5.17.0; torch 2.14.0; Python 3.12; macOS arm64. The signature behaviour holds for the whole pinned range, since the from_pretrained **kwargs shape and the torch_dtype→dtype rename both landed before 5.14.1.