facebookresearch/detectron2 · error · ValueError

Unsupported query remaining: f

Error message

Unsupported query remaining: f{queries}, orginal filename: {parsed_url.geturl()}

What it means

DetectionCheckpointer._load_file supports only the 'matching_heuristics=True' URL query parameter. After popping it, any remaining query string in the checkpoint path causes this ValueError because the loader cannot interpret other options.

Solutions

  1. Remove unsupported query parameters from the path and configure those options in code instead
  2. Pass only ?matching_heuristics=True if you need suffix matching
  3. For options like device mapping, subclass DetectionCheckpointer and override _load_file/_torch_load

Example fix

# before
ckpt.load("model.pth?matching_heuristics=True&strict=False")
# after
ckpt.load("model.pth?matching_heuristics=True")  # strictness handled via model.load_state_dict yourself
Defensive patterns

Strategy: validation

Validate before calling

from urllib.parse import urlparse, parse_qs
q = parse_qs(urlparse(path).query)
assert set(q) <= {"matching_heuristics"}, f"unsupported queries: {set(q) - {'matching_heuristics'}}"

Type guard

def is_supported_ckpt_path(path: str) -> bool:
    return set(parse_qs(urlparse(path).query)) <= {"matching_heuristics"}

Try / catch

try:
    ckpt.load(path)
except ValueError as e:
    if "Unsupported query" in str(e):
        ckpt.load(urlparse(path).path + "?matching_heuristics=True")
    else:
        raise

Prevention

When it happens

Trigger: Loading a checkpoint with a URL like 'model.pth?matching_heuristics=True&strict=False' or any path containing '?' followed by unrecognized key=value pairs.

Common situations: Trying to pass torch.load options (e.g. map_location, strict) through the checkpoint filename; copying example URLs with extra parameters; hand-crafting query strings assuming generic support.

Related errors


AI-assisted analysis of facebookresearch/detectron2@a2f4a8771a (2026-08-27). Data as JSON: /api/errors/d34d0d0e4985e07d. Report an issue: GitHub.

Appendix: source

Thrown at detectron2/checkpoint/detection_checkpoint.py:108

                "model_state" in data
            ), f"Cannot load .pyth file {filename}; pycls checkpoints must contain 'model_state'."
            model_state = {
                k: v
                for k, v in data["model_state"].items()
                if not k.endswith("num_batches_tracked")
            }
            return {"model": model_state, "__author__": "pycls", "matching_heuristics": True}

        loaded = self._torch_load(filename)
        if "model" not in loaded:
            loaded = {"model": loaded}
        assert self._parsed_url_during_load is not None, "`_load_file` must be called inside `load`"
        parsed_url = self._parsed_url_during_load
        queries = parse_qs(parsed_url.query)
        if queries.pop("matching_heuristics", "False") == ["True"]:
            loaded["matching_heuristics"] = True
        if len(queries) > 0:
            raise ValueError(
                f"Unsupported query remaining: f{queries}, orginal filename: {parsed_url.geturl()}"
            )
        return loaded

    def _torch_load(self, f):
        return super()._load_file(f)

    def _load_model(self, checkpoint):
        if checkpoint.get("matching_heuristics", False):
            self._convert_ndarray_to_tensor(checkpoint["model"])
            # convert weights by name-matching heuristics
            checkpoint["model"] = align_and_update_state_dicts(
                self.model.state_dict(),
                checkpoint["model"],
                c2_conversion=checkpoint.get("__author__", None) == "Caffe2",
            )
        # for non-caffe2 models, use standard ways to load it
        incompatible = super()._load_model(checkpoint)

View on GitHub (pinned to a2f4a8771a)