Update ui/gpu.py
Browse files
ui/gpu.py
CHANGED
|
@@ -20,7 +20,6 @@ Off ZeroGPU (local, or Spaces "CPU basic") @spaces.GPU is a transparent
|
|
| 20 |
passthrough and ON_ZEROGPU is False, so this module quietly degrades to plain
|
| 21 |
CPU work and nothing else in the app changes.
|
| 22 |
"""
|
| 23 |
-
|
| 24 |
import os
|
| 25 |
|
| 26 |
import spaces
|
|
@@ -36,9 +35,8 @@ GPU_DEVICE = "cuda" if ON_ZEROGPU else "cpu"
|
|
| 36 |
# itself. A long paper on a cold cache is the worst case.
|
| 37 |
_VECTORIZE_SECONDS = 120
|
| 38 |
|
|
|
|
| 39 |
@spaces.GPU(duration=_VECTORIZE_SECONDS)
|
| 40 |
-
zero_gpu_flag = os.environ.get("SPACES_ZERO_GPU")
|
| 41 |
-
print("[GPU FN] pid=" + str(os.getpid()) + ", in ZeroGPU ctx: " + str(zero_gpu_flag))
|
| 42 |
def vectorize_on_gpu(pdf_path: str) -> None:
|
| 43 |
"""Build and persist this paper's vectorstore with the embedder on GPU.
|
| 44 |
|
|
@@ -51,5 +49,15 @@ def vectorize_on_gpu(pdf_path: str) -> None:
|
|
| 51 |
The caller then re-opens it on CPU, which costs nothing: build_vectorstore
|
| 52 |
short-circuits to a plain load as soon as the persist dir exists.
|
| 53 |
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 54 |
from vectorizeer import build_vectorstore
|
| 55 |
-
|
|
|
|
|
|
| 20 |
passthrough and ON_ZEROGPU is False, so this module quietly degrades to plain
|
| 21 |
CPU work and nothing else in the app changes.
|
| 22 |
"""
|
|
|
|
| 23 |
import os
|
| 24 |
|
| 25 |
import spaces
|
|
|
|
| 35 |
# itself. A long paper on a cold cache is the worst case.
|
| 36 |
_VECTORIZE_SECONDS = 120
|
| 37 |
|
| 38 |
+
|
| 39 |
@spaces.GPU(duration=_VECTORIZE_SECONDS)
|
|
|
|
|
|
|
| 40 |
def vectorize_on_gpu(pdf_path: str) -> None:
|
| 41 |
"""Build and persist this paper's vectorstore with the embedder on GPU.
|
| 42 |
|
|
|
|
| 49 |
The caller then re-opens it on CPU, which costs nothing: build_vectorstore
|
| 50 |
short-circuits to a plain load as soon as the persist dir exists.
|
| 51 |
"""
|
| 52 |
+
# Runs fresh on every call, inside the GPU worker — unlike a module-level
|
| 53 |
+
# print, this actually tells you what's true for *this* invocation.
|
| 54 |
+
zero_gpu_flag = os.environ.get("SPACES_ZERO_GPU")
|
| 55 |
+
print(
|
| 56 |
+
"[GPU FN] pid=" + str(os.getpid())
|
| 57 |
+
+ ", in ZeroGPU ctx: " + str(zero_gpu_flag)
|
| 58 |
+
+ ", device=" + GPU_DEVICE
|
| 59 |
+
)
|
| 60 |
+
|
| 61 |
from vectorizeer import build_vectorstore
|
| 62 |
+
|
| 63 |
+
build_vectorstore(pdf_path, device=GPU_DEVICE)
|