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

[BUG]: Linux cuda version detection could be incorrect #724

Open
AsakusaRinne opened this issue May 8, 2024 · 2 comments
Open

[BUG]: Linux cuda version detection could be incorrect #724

AsakusaRinne opened this issue May 8, 2024 · 2 comments
Assignees
Labels
backend bug Something isn't working

Comments

@AsakusaRinne
Copy link
Collaborator

Description

Sometimes the cuda version detection in linux is not correct.

Reproduction Steps

  1. pull and run the docker nvidia/cuda:11.7.1-devel-ubuntu22.04.
  2. Run the LLamaSharp examples

Environment & Configuration

  • Operating system: Ubuntu
  • .NET runtime version: 8.0
  • LLamaSharp version: master
  • CUDA version (if you are using cuda backend): 11.7
  • CPU & GPU device: 2080Ti

Known Workarounds

SkipCheck or WithLibrary is a quick fix but not good.

The main reason is that the version.json or version.txt does not exist. A possible solution is to create a repo about calling nvml APIs but that will cost a lot of time.

@AsakusaRinne AsakusaRinne added bug Something isn't working backend labels May 8, 2024
@AsakusaRinne AsakusaRinne self-assigned this May 8, 2024
@Hyp3rSoniX
Copy link

Not sure if this is an okay solution for you but for my usage, I just added an additional environment-var check for the cuda major version:
https://gitlab.um-a.one/ai/LLamaSharp/-/blob/3baffe56e49bb823b01c9dff9c463a2c21ab000e/LLama/Native/NativeApi.Load.cs#L121

            else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
            {
                var manualVersionSet = Environment.GetEnvironmentVariable("CUDA_MAJOR_VERSION");
                if(!string.IsNullOrEmpty(manualVersionSet)){
                    return int.Parse(manualVersionSet);
                }
                // Try the default first
                cudaPath = "/usr/local/bin/cuda";
                version = GetCudaVersionFromPath(cudaPath);
                if (string.IsNullOrEmpty(version))
                {
                    cudaPath = Environment.GetEnvironmentVariable("LD_LIBRARY_PATH");
                    if (cudaPath is null)
                    {
                        return -1;
                    }
                    foreach (var path in cudaPath.Split(':'))
                    {
                        version = GetCudaVersionFromPath(Path.Combine(path, ".."));
                        if (string.IsNullOrEmpty(version))
                        {
                            break;
                        }
                    }
                }
            }

I just set the same environment variable in the dockerfile, and the check always works. One can also set it via the docker run -e command, or export it in the shell.

I don't think you need to implement something super complex just to parse some nvidia tool result. You can expect an environment variable or maybe even a config set within the project, that simply tells you what cuda version is installed. Mention it in the docu and you're done.

Just my two cents.

@AsakusaRinne
Copy link
Collaborator Author

Yeah makes sense, that's a good solution. Thank you a lot for your suggestions!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backend bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants