PabsCanCode commited on
Commit
2aa2ea0
·
1 Parent(s): 2dc9a35

Avoid CUDA discovery before ZeroGPU worker initialization

Browse files
Files changed (2) hide show
  1. app.py +4 -0
  2. main.py +2 -1
app.py CHANGED
@@ -1,6 +1,10 @@
1
  """Gradio entry point for the free ZeroGPU Space (upload as app.py)."""
2
 
3
  import io
 
 
 
 
4
 
5
  # Import spaces before torch/transformers so ZeroGPU can enable CUDA emulation.
6
  import spaces
 
1
  """Gradio entry point for the free ZeroGPU Space (upload as app.py)."""
2
 
3
  import io
4
+ import os
5
+
6
+ # Availability checks must not initialize the CUDA runtime in the parent process.
7
+ os.environ.setdefault("PYTORCH_NVML_BASED_CUDA_CHECK", "1")
8
 
9
  # Import spaces before torch/transformers so ZeroGPU can enable CUDA emulation.
10
  import spaces
main.py CHANGED
@@ -73,7 +73,8 @@ CONFIDENT_MIN = 0.7
73
  CLOSE_UP_NAMES = {"rice leaves", "a diseased rice leaf"}
74
  MAX_BYTES = 10 * 1024 * 1024
75
 
76
- disease_clf = pipeline("image-classification", model=DISEASE_MODEL)
 
77
  gate_model = CLIPModel.from_pretrained(GATE_MODEL).eval()
78
  gate_processor = CLIPProcessor.from_pretrained(GATE_MODEL)
79
 
 
73
  CLOSE_UP_NAMES = {"rice leaves", "a diseased rice leaf"}
74
  MAX_BYTES = 10 * 1024 * 1024
75
 
76
+ # Load on CPU without automatic accelerator discovery before ZeroGPU forks a worker.
77
+ disease_clf = pipeline("image-classification", model=DISEASE_MODEL, device="cpu")
78
  gate_model = CLIPModel.from_pretrained(GATE_MODEL).eval()
79
  gate_processor = CLIPProcessor.from_pretrained(GATE_MODEL)
80