Spaces:
Running
on
Zero
Running
on
Zero
cutechicken
commited on
Commit
β’
b0b6eba
1
Parent(s):
44a7786
Update app.py
Browse files
app.py
CHANGED
@@ -7,14 +7,37 @@ import json
|
|
7 |
from datetime import datetime
|
8 |
import torch
|
9 |
from transformers import AutoModelForCausalLM, AutoTokenizer
|
|
|
10 |
|
11 |
# νκ²½ λ³μ μ€μ
|
12 |
HF_TOKEN = os.getenv("HF_TOKEN")
|
13 |
MODEL_ID = "CohereForAI/c4ai-command-r-plus-08-2024"
|
14 |
|
15 |
-
#
|
16 |
-
|
17 |
-
os.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
18 |
|
19 |
# νκ²½ λ³μ μ€μ
|
20 |
os.environ["TRANSFORMERS_CACHE"] = os.path.join(PERSISTENT_DIR, "transformers_cache")
|
@@ -27,7 +50,15 @@ for cache_dir in [
|
|
27 |
os.environ["TORCH_HOME"],
|
28 |
os.environ["HF_HOME"]
|
29 |
]:
|
30 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
31 |
|
32 |
class ModelManager:
|
33 |
def __init__(self):
|
|
|
7 |
from datetime import datetime
|
8 |
import torch
|
9 |
from transformers import AutoModelForCausalLM, AutoTokenizer
|
10 |
+
import shutil
|
11 |
|
12 |
# νκ²½ λ³μ μ€μ
|
13 |
HF_TOKEN = os.getenv("HF_TOKEN")
|
14 |
MODEL_ID = "CohereForAI/c4ai-command-r-plus-08-2024"
|
15 |
|
16 |
+
# μ¬μ©μ ν λλ ν 리 κΈ°λ° κ²½λ‘ μ€μ
|
17 |
+
USER_HOME = os.path.expanduser("~")
|
18 |
+
PERSISTENT_DIR = os.path.join(USER_HOME, "persistent_storage", "model_cache")
|
19 |
+
|
20 |
+
# μ€ν λ¦¬μ§ μν νμΈ
|
21 |
+
def check_storage():
|
22 |
+
try:
|
23 |
+
total, used, free = shutil.disk_usage(USER_HOME)
|
24 |
+
print(f"μ€ν λ¦¬μ§ μν:")
|
25 |
+
print(f"μ΄ μ©λ: {total // (2**30)}GB")
|
26 |
+
print(f"μ¬μ© μ€: {used // (2**30)}GB")
|
27 |
+
print(f"λ¨μ μ©λ: {free // (2**30)}GB")
|
28 |
+
except Exception as e:
|
29 |
+
print(f"μ€ν λ¦¬μ§ νμΈ μ€ν¨: {e}")
|
30 |
+
|
31 |
+
# λλ ν 리 μμ±
|
32 |
+
try:
|
33 |
+
os.makedirs(PERSISTENT_DIR, exist_ok=True)
|
34 |
+
print(f"μΊμ λλ ν 리 μμ± μλ£: {PERSISTENT_DIR}")
|
35 |
+
except Exception as e:
|
36 |
+
print(f"μΊμ λλ ν 리 μμ± μ€ν¨: {e}")
|
37 |
+
# μμ λλ ν λ¦¬λ‘ ν΄λ°±
|
38 |
+
PERSISTENT_DIR = os.path.join("/tmp", "model_cache")
|
39 |
+
os.makedirs(PERSISTENT_DIR, exist_ok=True)
|
40 |
+
print(f"μμ μΊμ λλ ν 리 μ¬μ©: {PERSISTENT_DIR}")
|
41 |
|
42 |
# νκ²½ λ³μ μ€μ
|
43 |
os.environ["TRANSFORMERS_CACHE"] = os.path.join(PERSISTENT_DIR, "transformers_cache")
|
|
|
50 |
os.environ["TORCH_HOME"],
|
51 |
os.environ["HF_HOME"]
|
52 |
]:
|
53 |
+
try:
|
54 |
+
os.makedirs(cache_dir, exist_ok=True)
|
55 |
+
print(f"μμ±λ μΊμ λλ ν 리: {cache_dir}")
|
56 |
+
except Exception as e:
|
57 |
+
print(f"μΊμ λλ ν 리 μμ± μ€ν¨: {cache_dir} - {e}")
|
58 |
+
|
59 |
+
# μμ μ μ€ν λ¦¬μ§ μν νμΈ
|
60 |
+
check_storage()
|
61 |
+
|
62 |
|
63 |
class ModelManager:
|
64 |
def __init__(self):
|