Skip to content

fix: add None guard for regex in load() and update addmm_() for PyTorch >= 2.0 compatibility#551

Open
SahilKumar75 wants to merge 1 commit into
kubeedge:mainfrom
SahilKumar75:fix/m3l-pytorch-compat
Open

fix: add None guard for regex in load() and update addmm_() for PyTorch >= 2.0 compatibility#551
SahilKumar75 wants to merge 1 commit into
kubeedge:mainfrom
SahilKumar75:fix/m3l-pytorch-compat

Conversation

@SahilKumar75

Copy link
Copy Markdown

Problem

Two bugs in examples/MOT17/multiedge_inference_bench/pedestrian_tracking/testalgorithms/reid/m3l/basemodel.py that cause runtime failures:

  1. load()re.compile(...).search(model_url).group(1) raises AttributeError: 'NoneType' object has no attribute 'group' when the filename doesn't match the expected _<arch>.pth pattern.
  2. _pairwise_distance()dist_m.addmm_(1, -2, x, y.t()) uses the deprecated positional-float signature removed in PyTorch ≥ 2.0, raising TypeError.

Fix

  • load(): capture the re.search() result and raise a descriptive ValueError if it's None, before calling .group(1).
  • _pairwise_distance(): replace addmm_(1, -2, x, y.t()) with addmm_(x, y.t(), beta=1, alpha=-2), which is the correct keyword-argument form supported from PyTorch 1.5+ through 2.x.

Testing

Changes are logic-level; the regex fix is trivially verifiable and the addmm_ signature change matches the PyTorch ≥ 2.0 migration guide.

Fixes #445

@kubeedge-bot kubeedge-bot added the do-not-merge/invalid-commit-message Indicates that a PR should not merge because it has an invalid commit message. label Jun 15, 2026
@kubeedge-bot

Copy link
Copy Markdown
Collaborator

Welcome @SahilKumar75! It looks like this is your first PR to kubeedge/ianvs 🎉

@kubeedge-bot

Copy link
Copy Markdown
Collaborator

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: SahilKumar75
To complete the pull request process, please assign jaypume after the PR has been reviewed.
You can assign the PR to them by writing /assign @jaypume in a comment when ready.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@kubeedge-bot kubeedge-bot added the size/S Denotes a PR that changes 10-29 lines, ignoring generated files. label Jun 15, 2026

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request improves robustness in basemodel.py by escaping the dot in the regular expression and adding a safety check with a descriptive ValueError when parsing the model architecture from model_url. Additionally, it updates the addmm_ call to use keyword arguments for beta and alpha. The reviewer recommended converting model_url to a string before performing the regex search to prevent a potential TypeError if a pathlib.Path object is passed, and suggested using re.search directly instead of compiling.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment on lines +56 to +62
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 format: '<name>_<arch>.pth'"
)
arch = match.group(1)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

If model_url is passed as a pathlib.Path object (which is highly possible given that Path(model_url) is used on line 70), re.search will raise a TypeError: expected string or bytes-like object. Converting model_url to a string first ensures robustness. Additionally, using re.search directly is more idiomatic than compiling a regex that is only used once.

Suggested change
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 format: '<name>_<arch>.pth'"
)
arch = match.group(1)
model_url_str = str(model_url)
match = re.search(r"_([a-zA-Z]+)\.pth", model_url_str)
if match is None:
raise ValueError(
f"Cannot infer model architecture from filename: '{model_url_str}'. "
"Expected format: '<name>_<arch>.pth'"
)
arch = match.group(1)

@SahilKumar75 SahilKumar75 force-pushed the fix/m3l-pytorch-compat branch from f312f23 to dd844e1 Compare June 15, 2026 07:27
@kubeedge-bot kubeedge-bot removed the do-not-merge/invalid-commit-message Indicates that a PR should not merge because it has an invalid commit message. label Jun 15, 2026
@SahilKumar75

Copy link
Copy Markdown
Author

/assign @jaypume

…ch >= 2.0 compatibility

- Add None check on regex match result in load() to prevent AttributeError
  when model filename does not match expected '_<arch>.pth' pattern
- Replace deprecated 3-positional-float addmm_() signature with keyword
  args (beta=1, alpha=-2) compatible with PyTorch >= 2.0

Signed-off-by: Sahil Kumar Singh <sahilkumargreat12@gmail.com>
@SahilKumar75 SahilKumar75 force-pushed the fix/m3l-pytorch-compat branch from dd844e1 to 53ba8c2 Compare June 15, 2026 07:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/S Denotes a PR that changes 10-29 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

3 participants