8000 CUDA not available when calling ` backwards` before using CUDA · Issue #1198 · dotnet/TorchSharp · GitHub
[go: up one dir, main page]

Skip to content
CUDA not available when calling backwards before using CUDA #1198
@shaltielshmid

Description

@shaltielshmid

When I use TorchSharp and I perform a gradient calculation before loading in the CUDA binaries, then TorchSharp no longer recognizes that CUDA is available.

For example:

var lin = torch.nn.Linear(10, 1, false);
lin.forward(torch.rand(10)).backward();
Console.WriteLine(torch.cuda.is_available()); // False

On the other hand, if I call a CUDA function before the backward() call, it will work:

Console.WriteLine(torch.cuda.is_available()); // True
var lin = torch.nn.Linear(10, 1, false);
lin.forward(torch.rand(10)).backward();
Console.WriteLine(torch.cuda.is_available()); // True

I've traced this issue back to LibTorch, over here. The exact quote is:

// NB: The once_flag here implies that if you try to call any CUDA
// functionality before libATen_cuda.so is loaded, CUDA is permanently
// disabled for that copy of ATen.

@NiklasGustafsson How do you think this should be handled?

In PyTorch I'm pretty sure that they load in the CUDA binaries with the first import torch call. This would be easy to add to TorchSharp, but is that the desired behavior?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0