Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
@@ -28,13 +28,15 @@ device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu") # ๋ช
|
|
28 |
|
29 |
###--------------ZERO GPU ํ์/ ๋ฉ๋ชจ๋ฆฌ ๊ด๋ฆฌ ๊ณตํต --------------------###
|
30 |
def clear_memory():
|
|
|
31 |
gc.collect()
|
32 |
if torch.cuda.is_available():
|
33 |
try:
|
34 |
-
torch.cuda.
|
35 |
-
|
36 |
-
|
37 |
-
|
|
|
38 |
|
39 |
###---------------------------------------------------------------
|
40 |
|
@@ -92,21 +94,33 @@ gd_model = GroundingDinoForObjectDetection.from_pretrained(gd_model_path, torch_
|
|
92 |
gd_model = gd_model.to(device=device)
|
93 |
assert isinstance(gd_model, GroundingDinoForObjectDetection)
|
94 |
|
95 |
-
# ํ์ดํ๋ผ์ธ ์ด๊ธฐํ
|
96 |
pipe = FluxPipeline.from_pretrained(
|
97 |
"black-forest-labs/FLUX.1-dev",
|
98 |
torch_dtype=torch.float16,
|
99 |
use_auth_token=HF_TOKEN
|
100 |
)
|
101 |
|
102 |
-
# ๋ฉ๋ชจ๋ฆฌ
|
103 |
-
pipe.enable_attention_slicing()
|
104 |
-
|
105 |
-
|
|
|
|
|
|
|
|
|
|
|
106 |
|
|
|
107 |
if torch.cuda.is_available():
|
108 |
-
|
109 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
110 |
|
111 |
|
112 |
# LoRA ๊ฐ์ค์น ๋ก๋
|
|
|
28 |
|
29 |
###--------------ZERO GPU ํ์/ ๋ฉ๋ชจ๋ฆฌ ๊ด๋ฆฌ ๊ณตํต --------------------###
|
30 |
def clear_memory():
|
31 |
+
"""๋ฉ๋ชจ๋ฆฌ ์ ๋ฆฌ ํจ์"""
|
32 |
gc.collect()
|
33 |
if torch.cuda.is_available():
|
34 |
try:
|
35 |
+
with torch.cuda.device('cuda:0'):
|
36 |
+
torch.cuda.empty_cache()
|
37 |
+
torch.cuda.synchronize()
|
38 |
+
except Exception as e:
|
39 |
+
print(f"Warning: Could not clear CUDA memory: {e}")
|
40 |
|
41 |
###---------------------------------------------------------------
|
42 |
|
|
|
94 |
gd_model = gd_model.to(device=device)
|
95 |
assert isinstance(gd_model, GroundingDinoForObjectDetection)
|
96 |
|
97 |
+
# ํ์ดํ๋ผ์ธ ์ด๊ธฐํ ๋ฐ ์ต์ ํ ์ค์
|
98 |
pipe = FluxPipeline.from_pretrained(
|
99 |
"black-forest-labs/FLUX.1-dev",
|
100 |
torch_dtype=torch.float16,
|
101 |
use_auth_token=HF_TOKEN
|
102 |
)
|
103 |
|
104 |
+
# ๋ฉ๋ชจ๋ฆฌ ์ต์ ํ ์ค์ - FluxPipeline์์ ์ง์ํ๋ ๋ฉ์๋๋ง ์ฌ์ฉ
|
105 |
+
pipe.enable_attention_slicing(slice_size="auto")
|
106 |
+
|
107 |
+
# xformers ์ต์ ํ (์ค์น๋์ด ์๋ ๊ฒฝ์ฐ์๋ง)
|
108 |
+
try:
|
109 |
+
import xformers
|
110 |
+
pipe.enable_xformers_memory_efficient_attention()
|
111 |
+
except ImportError:
|
112 |
+
print("xformers is not installed. Skipping memory efficient attention.")
|
113 |
|
114 |
+
# GPU ์ค์
|
115 |
if torch.cuda.is_available():
|
116 |
+
try:
|
117 |
+
pipe = pipe.to("cuda:0")
|
118 |
+
# CPU ์คํ๋ก๋ฉ์ด ์ง์๋๋ ๊ฒฝ์ฐ์๋ง ํ์ฑํ
|
119 |
+
if hasattr(pipe, 'enable_model_cpu_offload'):
|
120 |
+
pipe.enable_model_cpu_offload()
|
121 |
+
except Exception as e:
|
122 |
+
print(f"Warning: Could not move pipeline to CUDA: {str(e)}")
|
123 |
+
|
124 |
|
125 |
|
126 |
# LoRA ๊ฐ์ค์น ๋ก๋
|