Closed yuvals1 closed 9 months ago
Hey @yuvals1.
Thanks for trying Lightning App.
Here are some explications.
torch.cuda.is_available()
, this creates a cuda context and can't be passed into forked process. Remove all your prints ;)Could you try this:
class VideoServeGradio(ServeGradio):
inputs = gr.Video()
outputs = "playable_video"
def run(self):
super().run()
def predict(self, video):
# Move the model to cuda in the predict method.
model = self.model.cuda()
video = video.cuda()
output = model(video)
return output.cpu().item()
def build_model(self):
return MyPipeline(face_geometry_path=None)
class Flow(L.LightningFlow):
def __init__(self):
super().__init__()
self.serve_work = VideoServeGradio()
def run(self):
self.serve_work.run()
def configure_layout(self):
tab_2 = {"name": "Interactive demo", "content": self.serve_work}
return [tab_2]
app = L.LightningApp(Flow(), debug=True)
Hey @tchaton,
Thanks for the response.
So I tried your suggestion and unfortunately now the process can't find Cuda for some reason:
CUDA driver initialization failed, you might not have a CUDA gpu.
Any ideas why?
Hey @yuvals1. Some progress, different errors.
Mind trying this?
def predict(self, video):
# Move the model to cuda in the predict method.
torch.set_device(torch.device('cuda:0'))
model = self.model.cuda()
video = video.cuda()
output = model(video)
return output.cpu().item()
cc @awaelchli
Hi @yuvals1 Is PyTorch working fine on that system otherwise? Please check that this works:
python -c "import torch; torch.rand(2).to('cuda:0')"
Because the error
CUDA driver initialization failed, you might not have a CUDA gpu.
would suggest that your system/display driver is perhaps outdated?
As @tchaton said, the error
Cannot re-initialize CUDA in forked subprocess.
Is from torch and it seems that gradio.Interface().launch()
that we use under the hood uses the forking method to create a subprocess. This is a limitation with torch, and thus all cuda operations should be performed inside that predict function. Hmm, I'm not sure what we could do here.
This issue has been automatically marked as stale because it hasn't had any recent activity. This issue will be closed in 7 days if no further activity occurs. Thank you for your contributions - the Lightning Team!
First check
Bug description
I am trying to run an app with
LightningWork
of typeServeGradio
which should run on my local GPU. I am passing theLightningWork
L.CloudCompute("gpu")
(also tried "cuda") but It does not seem to move my model to the the GPU. When I am trying to move my model explicitly to the GPU I am getting the following error:Cannot re-initialize CUDA in forked subprocess. To use CUDA with multiprocessing, you must use the 'spawn' start method
. when I am not trying to move my model to the GPU the process runs.How to reproduce the bug
Error messages and logs
Important info
More info
No response