Skip to content

🐞 fix(model): fix DFM nll fitting crashing on torch.mean(device=...) - #3926

Open
sohailshk wants to merge 2 commits into
open-edge-platform:mainfrom
sohailshk:fix/dfm-nll-fit-v2
Open

sohailshk wants to merge 2 commits into
open-edge-platform:mainfrom
sohailshk:fix/dfm-nll-fit-v2

Conversation

@sohailshk

Copy link
Copy Markdown

📝 Description

DFM with score_type="nll" cannot finish training. At the end of fitting, SingleClassGaussian.fit calls torch.mean(dataset, dim=1, device=dataset.device), and torch.mean has no device argument:

TypeError: mean() received an invalid combination of arguments - got (Tensor, device=torch.device, dim=int)

Reproduced on main with DFMModel(backbone="resnet18", layer="layer3", pre_trained=False, score_type="nll"): forward a few training batches, then fit(). The fix drops the device argument (the mean already lives on the dataset's device).

The tests fit SingleClassGaussian directly and run the DFMModel train, fit(), eval flow with pre_trained=False (no download) on random images; both fail on main with the TypeError.

Note: correct NLL scores also need the PCA centering fix in #3920, which stops PCA.fit centering the memory bank in place before transform subtracts the mean again.

  • 🛠️ Fixes: no open issue

✨ Changes

  • 🐞 Bug fix (non-breaking change which fixes an issue)

✅ Checklist

  • 📚 I have made the necessary updates to the documentation (if applicable). (not applicable)
  • 🧪 I have written tests that support my changes and prove that my fix is effective or my feature works (if applicable).
  • 🏷️ My PR title follows conventional commit format.

Checks run: pytest tests/unit/models/image/dfm (2 passed; both fail on main), ruff check and ruff format --check (0.12.0), mypy (1.16.1) on torch_model.py. Not run: the full suite, MVTec runs.

SingleClassGaussian.fit passed device= to torch.mean, which raises a TypeError, so DFM with score_type=nll could not finish fitting.

Signed-off-by: sohailshk <122166523+sohailshk@users.noreply.github.com>
Signed-off-by: sohailshk <122166523+sohailshk@users.noreply.github.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant