Skip to content

[MOT17] M3L basemodel.py: unguarded regex crashes on non-standard checkpoints; deprecated addmm_ API removed in PyTorch ≥ 2.0 #445

Description

@suhaan-24

Summary

Two bugs in the M3L ReID algorithm implementation (testalgorithms/reid/m3l/basemodel.py)
block the ReID benchmark job from completing. First, the architecture-inference regex
in load() has no None guard and will crash with AttributeError on any model
filename that does not match a narrow implicit pattern. Second, the pairwise distance
computation in predict() uses the three-positional-float signature of addmm_(), which
was removed in PyTorch 2.0 and raises TypeError on any modern GPU environment.

Environment

  • Example: MOT17/multiedge_inference_bench
  • Branch: main (as of 2026-05-21)
  • Files affected:
    • examples/MOT17/multiedge_inference_bench/pedestrian_tracking/testalgorithms/reid/m3l/basemodel.py

Findings

Finding 1 — Unguarded regex in load() crashes on non-standard model filenames

File: testalgorithms/reid/m3l/basemodel.py
Line: 56
Code:

arch = re.compile("_([a-zA-Z]+).pth").search(model_url).group(1)

Problem:
The load() method attempts to infer the model architecture name from the checkpoint
filename using a regex. There are two compounding issues:

  1. No None guard: If model_url does not contain a substring matching
    _<letters>.pth, re.search() returns None. Calling .group(1) on None
    raises:

    AttributeError: 'NoneType' object has no attribute 'group'
    

    Any alternative checkpoint — a fine-tuned model, a renamed download, or a path like
    market_best_model.bin — triggers this immediately.

  2. Unescaped dot in regex: The pattern "_([a-zA-Z]+).pth" uses an unescaped .
    which matches any character, not a literal dot. This is a latent correctness issue
    that widens the match unintentionally (e.g., _IBNMeta_pth would match when it
    should not).

The current default filename market_IBNMeta.pth.tar happens to satisfy the pattern,
so the bug is invisible unless users bring their own checkpoints.

Impact:
The error occurs at model load time, before any inference runs. Users who provide
alternative checkpoints receive an AttributeError with no indication of which
filename caused the problem or what naming convention is required.

Proposed Fix:

match = re.compile(r"_([a-zA-Z]+)\.pth").search(model_url)
if match is None:
    raise ValueError(
        f"Cannot infer model architecture from filename: '{model_url}'. "
        "Expected a filename containing '_<arch>.pth' (e.g., 'market_IBNMeta.pth.tar')."
    )
arch = match.group(1)

Finding 2 — Deprecated addmm_() positional-float API removed in PyTorch 2.0

File: testalgorithms/reid/m3l/basemodel.py
Line: 153
Code:

dist_m.addmm_(1, -2, x, y.t())

Problem:
The call uses the legacy three-positional-float signature
addmm_(beta, alpha, mat1, mat2), where beta and alpha are passed as positional
arguments. This signature was deprecated in PyTorch 1.5 and removed in
PyTorch 2.0
. On any current CUDA environment (CUDA 11.8+ ships with PyTorch ≥ 2.0
by default), the call raises:

TypeError: addmm_() received an invalid combination of arguments - got
(int, int, Tensor, Tensor), but expected one of:
 * (Tensor mat1, Tensor mat2, *, Scalar beta, Scalar alpha)

The example was written in 2022 when this signature was still valid. It has been silently
broken on current GPU servers since the PyTorch 2.0 release.

Impact:
The crash occurs inside _pairwise_distance(), which is called from predict(). The
model must complete a full forward pass through the dataset before _pairwise_distance()
is reached, so users waste the full inference compute time before hitting the error.
The entire ReID job becomes non-executable on any modern environment.

Proposed Fix:

# Replace positional beta/alpha with keyword arguments (PyTorch ≥ 1.5 compatible):
dist_m.addmm_(x, y.t(), beta=1, alpha=-2)

Steps to Reproduce

Finding 1 (unguarded regex):

  1. Download any ReID checkpoint with a non-standard filename (e.g., rename
    market_IBNMeta.pth.tar to market_best_model.bin).
  2. Update m3l_algorithm.yamlinitial_model_url to point to the renamed file.
  3. Run the ReID job:
    ianvs -f examples/MOT17/multiedge_inference_bench/pedestrian_tracking/reid_job.yaml
  4. Observe: AttributeError: 'NoneType' object has no attribute 'group' at the
    load() step.

Finding 2 (deprecated addmm_):

  1. Run the ReID job on any machine with PyTorch ≥ 2.0.
  2. Allow inference to complete.
  3. Observe: TypeError: addmm_() received an invalid combination of arguments during
    the _pairwise_distance() call inside predict().

Verify PyTorch version: python -c "import torch; print(torch.__version__)".
Any version ≥ 2.0.0 will trigger Finding 2.


Additional Notes

Both bugs are confined to m3l/basemodel.py and require no changes to the ianvs core.
They can be fixed in a single focused PR.

Finding 2 affects any user on a 2024+ GPU server. CUDA 11.8 and later ship with
PyTorch 2.x as the default. It is unlikely that any current contributor can run the
ReID job without encountering this crash.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions