Update handler.py
Browse files- handler.py +5 -5
handler.py
CHANGED
|
@@ -2,11 +2,11 @@ from gliner import GLiNER
|
|
| 2 |
|
| 3 |
class EndpointHandler:
|
| 4 |
def __init__(self, path=""):
|
| 5 |
-
#
|
| 6 |
-
self.model = GLiNER.from_pretrained(
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
)
|
| 10 |
|
| 11 |
def __call__(self, data):
|
| 12 |
# If data is wrapped in 'inputs' (as Hugging Face does), unwrap it
|
|
|
|
| 2 |
|
| 3 |
class EndpointHandler:
|
| 4 |
def __init__(self, path=""):
|
| 5 |
+
# Load without device_map, then move to GPU
|
| 6 |
+
self.model = GLiNER.from_pretrained(path) # Remove device_map="cuda"
|
| 7 |
+
device = "cuda" if torch.cuda.is_available() else "cpu"
|
| 8 |
+
self.model = self.model.to(device)
|
| 9 |
+
self.model.eval() # Lock for inference
|
| 10 |
|
| 11 |
def __call__(self, data):
|
| 12 |
# If data is wrapped in 'inputs' (as Hugging Face does), unwrap it
|