jolly-florist-66728
09/26/2024, 1:59 PMtorch.cuda.is_available() returns False
⢠However, if I kubectl exec /bin/bash into the same pod, torch.cuda.is_available() would return True
What could be possible reasons as to why that could be the case?
I am using a custom docker image for registering tasks/workflows, image is based on python:3.10-slim and has flytekit-1.13.5 installed into it
# Answer
The issue you're experiencing could be due to several factors, including the configuration of GPU resources in your Flyte task, the Docker image setup, or the Kubernetes environment. Here are some potential reasons and solutions:
1. GPU Resource Requests and Limits: Ensure that your Flyte task correctly requests and limits GPU resources. The Resources object should specify the GPU resource.
2. Docker Image Configuration: Verify that your custom Docker image includes all necessary dependencies for GPU support, such as CUDA and cuDNN. Ensure that flytekit and torch are installed in the image.
3. Kubernetes Node Configuration: Ensure that the Kubernetes nodes are correctly configured to expose GPU resources. The nodes should have the NVIDIA device plugin installed and configured.
4. Flyte Task Configuration: Ensure that the Flyte task is correctly configured to use the GPU. The ImageSpec should include the necessary CUDA and cuDNN versions.
Here is an example of how to configure a Flyte task to request GPU resources:
from flytekit import ImageSpec, Resources, task
image = ImageSpec(
base_image="python:3.10-slim",
name="custom_image",
python_version="3.10",
packages=["flytekit==1.13.5", "torch"],
registry="<YOUR_CONTAINER_REGISTRY>",
)
@task(
container_image=image,
requests=Resources(cpu="1", mem="1Gi", gpu="1"),
limits=Resources(cpu="1", mem="1Gi", gpu="1")
)
def run_gpu_task():
import torch
cuda_available = torch.cuda.is_available()
print(f"Is cuda available? {cuda_available}")
return cuda_available
If the issue persists, you may need to check the Kubernetes node configuration and ensure that the NVIDIA device plugin is correctly installed and configured.
Would you like more details on any specific part of this process?
Sources:
- Configuring access to GPUs
- Added GPU enabled sandbox image
Slack Link
https://.slack.com/archives/CP2HDHKE1/p1727359165.903949 š 0 button š 0 button š” Hint: Mention @runllm in the thread for followups.