allow usage of multiple GPUs
Browse filesdetails see https://github.com/pimcore-labs/hugging-face-eap/issues/21#issuecomment-2200537717
- handler.py +9 -5
handler.py
CHANGED
@@ -16,11 +16,15 @@ device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
|
16 |
|
17 |
class EndpointHandler:
|
18 |
def __init__(self, path=""):
|
19 |
-
# load the model
|
20 |
self.processor = AutoImageProcessor.from_pretrained("caidas/swin2SR-classical-sr-x2-64")
|
21 |
-
|
22 |
-
|
23 |
-
|
|
|
|
|
|
|
|
|
24 |
|
25 |
def __call__(self, data: Any):
|
26 |
"""
|
@@ -32,7 +36,7 @@ class EndpointHandler:
|
|
32 |
"""
|
33 |
|
34 |
image = data["inputs"]
|
35 |
-
inputs = self.processor(image, return_tensors="pt")
|
36 |
with torch.no_grad():
|
37 |
outputs = self.model(**inputs)
|
38 |
|
|
|
16 |
|
17 |
class EndpointHandler:
|
18 |
def __init__(self, path=""):
|
19 |
+
# load the model
|
20 |
self.processor = AutoImageProcessor.from_pretrained("caidas/swin2SR-classical-sr-x2-64")
|
21 |
+
Swin2SRModel._no_split_modules = ["Swin2SREmbeddings", "Swin2SRStage"]
|
22 |
+
Swin2SRForImageSuperResolution._no_split_modules = ["Swin2SREmbeddings", "Swin2SRStage"]
|
23 |
+
model = Swin2SRForImageSuperResolution.from_pretrained("caidas/swin2SR-classical-sr-x2-64", device_map="auto")
|
24 |
+
logger.info(model.hf_device_map)
|
25 |
+
model.hf_device_map["swin2sr.conv_after_body"] = model.hf_device_map["swin2sr.embeddings"]
|
26 |
+
model.hf_device_map["upsample"] = model.hf_device_map["swin2sr.embeddings"]
|
27 |
+
self.model = Swin2SRForImageSuperResolution.from_pretrained("caidas/swin2SR-classical-sr-x2-64", device_map=model.hf_device_map)
|
28 |
|
29 |
def __call__(self, data: Any):
|
30 |
"""
|
|
|
36 |
"""
|
37 |
|
38 |
image = data["inputs"]
|
39 |
+
inputs = self.processor(image, return_tensors="pt")
|
40 |
with torch.no_grad():
|
41 |
outputs = self.model(**inputs)
|
42 |
|