Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CPP extensions Update #10

Open
UsernameN0tAvailable opened this issue Aug 9, 2023 · 2 comments
Open

CPP extensions Update #10

UsernameN0tAvailable opened this issue Aug 9, 2023 · 2 comments

Comments

@UsernameN0tAvailable
Copy link

The cpp extensions do not compile anymore with newer version of torch, I've encountered the following two errors using versions >= 1.13.0

cpp_functions.cpp:85:28: error: ‘struct DLTensor’ has no member named ‘ctx’
   85 |       dlMTensor->dl_tensor.ctx.device_id = device_id;
      |                        
cpp_functions.cpp:24:14: error: ‘cudnn_convolution_backward_weight’ is not a member of ‘at’; did you mean ‘mps_convolution_backward_out’?
   24 |   return at::cudnn_convolution_backward_weight(
      |              ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      |              mps_convolution_backward_out
cpp_functions.cpp:48:14: error: ‘cudnn_convolution_backward_input’ is not a member of ‘at’; did you mean ‘mps_convolution_backward_out’?
   48 |   return at::cudnn_convolution_backward_input(
      |              ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      |              mps_convolution_backward_out

This is very likely due to versions mismatch, is there any fix for this or a newer version of the cpp extensions?

@hanspinckaers
Copy link
Collaborator

hanspinckaers commented Aug 9, 2023

Hi! I don't have time to fix this now, but you can rewrite scnn to use these functions here, these use the CUDA kernels now too, so should be fast: https://github.com/pytorch/pytorch/blob/main/torch/nn/grad.py

it's relatively easy:


replace

StreamingCNN/scnn.py

Lines 128 to 130 in 350df03

grad_in = cpp_functions.backward_input(inpt.shape, grad_output, weight.to(inpt.dtype), padding,
stride, dilation, groups,
torch.backends.cudnn.benchmark, torch.backends.cudnn.deterministic)

with:

grad_in = torch.nn.grad.conv2d_input(inpt.shape, weight, grad_output, stride,  padding, dilation, groups)  

replace

StreamingCNN/scnn.py

Lines 215 to 221 in 350df03

grad_weight = cpp_functions.backward(weight.shape,
relevant_grad.to(weight.dtype),
relevant_input.to(weight.dtype),
(0, 0), # padding
stride[1:3], dilation, groups,
torch.backends.cudnn.benchmark, # benchmark
torch.backends.cudnn.deterministic) # deterministic

with:

grad_weight = torch.nn.grad.conv2d_weight(relevant_input.to(weight.dtype), 
                                      weight.shape, 
                                      relevant_grad.to(weight.dtype), 
                                      stride[1:3], 
                                      (0, 0),  # padding 
                                      dilation, 
                                      groups) 

Good luck!

@UsernameN0tAvailable
Copy link
Author

yes, that is exactly it, I would have opened a PR if I had the permissions, however it's a very quick fix, thanks a lot!

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

No branches or pull requests

2 participants