Parskatt / RoMa

[CVPR 2024] RoMa: Robust Dense Feature Matching; RoMa is the robust dense feature matcher capable of estimating pixel-dense warps and reliable certainties for almost any image pair.
https://parskatt.github.io/RoMa/
MIT License
434 stars 33 forks source link

Unexpected floating ScalarType in at::autocast::prioritize #2

Closed urbste closed 11 months ago

urbste commented 1 year ago

I was just trying out the demo_fundamental.py demo and ran into the following error:

Unexpected floating ScalarType in at::autocast::prioritize

It occurs in the grid_sampler here (local_correlation.py, line 40)

local_window_coords = (coords[_,:,:,None]+local_window[:,None,None]).reshape(1,h,w*(2*r+1)**2,2).half()
window_feature = F.grid_sample(
                feature1[_:_+1], local_window_coords, padding_mode=padding_mode, align_corners=False, mode = sample_mode,)

It can be solved by removing the half precision of local_window_coords and converting feature1 to float(). However, I am not sure about any implications that might have.

local_window_coords = (coords[_,:,:,None]+local_window[:,None,None]).reshape(1,h,w*(2*r+1)**2,2)
window_feature = F.grid_sample(
                feature1[_:_+1].float(), local_window_coords, padding_mode=padding_mode, align_corners=False, mode = sample_mode,)

System/Env:

Parskatt commented 1 year ago

I think its due to autocast not wanting to mix bfloat16 and float16, the .half() call I think I only used to try to save memory. If you dont have any memory issues then float should be fine, its probably also fine to not cast at all as I guess linspace is automatically float32.

Parskatt commented 1 year ago

Btw reason for bfloat16 is that its more stable during training, but I think I should make it optional as I think float16 can be faster at inference.

urbste commented 1 year ago

I will close this issue. Brought it up, if someone else has this problem. Thanks for the response :)

Parskatt commented 1 year ago

Thanks for bringing it up! I'll keep it in mind when cleaning up the code :)

LooperzZ commented 12 months ago

Hello, I have the same problem, it still does not work after modifying it according to your method, how to proceed? Unexpected floating ScalarType in at::autocast::prioritize

Parskatt commented 12 months ago

You could try explicitly casting everything to float32? Whats your pytorch/cuda version?

LooperzZ commented 12 months ago

python==3.7 pytorch==1.10.2 cuda==11.3

mpizenberg commented 11 months ago

Thanks @urbste this saved me from searching for hours what the issue is ^^.

Parskatt commented 11 months ago

As many people seem to be having this issue Ill try to fix it.

Parskatt commented 11 months ago

@mpizenberg @LooperzZ , are your issues resolved with https://github.com/Parskatt/RoMa/pull/3 ?

mpizenberg commented 11 months ago

This is my diff

image

mpizenberg commented 11 months ago

ah sorry I missinterpreted the question. I can check #3 and let you know.

mpizenberg commented 11 months ago

@mpizenberg @LooperzZ , are your issues resolved with #3 ?

Indeed, I don’t have this issue anymore in that branch so I’d say it’s solved.

direct-up commented 11 months ago

Thanks very much! By removing the half precision from local_window_coords and converting feature1 to float using float(), the issue of 'Unexpected floating ScalarType in at::autocast::prioritize' is resolved. System/Env:

PS:I have already tried version #3, and the issue does not occur again.