Fix DefaultBoxGenerator CUDA device mismatch in _grid_default_boxes (#9414)#9514
Fix DefaultBoxGenerator CUDA device mismatch in _grid_default_boxes (#9414)#9514Nueramarcos wants to merge 2 commits into
Conversation
Covers CPU shape/device/dtype/NaN/clip/TorchScript and CUDA regression tests including the core torch.cat device-mismatch fix, CPU==CUDA value equality, batch, and _wh_pairs device verification.
Thread the feature-map device into _grid_default_boxes so that shifts_x/shifts_y and _wh_pairs[k] are all created/moved to the same device before torch.cat. Removes the now-redundant .to(device) in forward(). Fixes pytorch#9414
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/vision/9514
Note: Links to docs will display an error until the docs builds have been completed. ❗ 1 Active SEVsThere are 1 currently active SEVs. If your PR is affected, please view them below: This comment was automatically generated by Dr. CI and updates every 15 minutes. |
|
Hi @Nueramarcos! Thank you for your pull request and welcome to our community. Action RequiredIn order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you. ProcessIn order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA. Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks! |
Summary
Fixes #9414
DefaultBoxGenerator._grid_default_boxescreatedshifts_x/shifts_yviatorch.arangewith nodevice=argument, and accessedself._wh_pairs[k](always CPU from__init__), causing a CPU vs CUDA mismatch attorch.catwhen the model runs on GPU.Changes
deviceparameter to_grid_default_boxes(defaults tocpufor backwards compatibility)device=devicetotorch.arangefor the shift tensors.to(dtype=dtype, device=device)on_wh_pairs[k]before useforward()to passdevicethrough and removed the now-redundantdefault_boxes.to(device)callTesting
Added
test/test_default_box_generator.pycovering:clip=True/False, batch size > 1, TorchScript traceabilitytorch.catno longer raises, CPU→CUDA value equality, batch,clip=False, TorchScript on CUDA,_wh_pairsdevice verificationVerified CPU path produces 8732 default boxes for SSD-300 with no NaNs.