Spaces:
Running
on
Zero
Running
on
Zero
cutechicken
commited on
Commit
โข
44a7786
1
Parent(s):
e5e0be0
Update app.py
Browse files
app.py
CHANGED
@@ -7,21 +7,31 @@ import json
|
|
7 |
from datetime import datetime
|
8 |
import torch
|
9 |
from transformers import AutoModelForCausalLM, AutoTokenizer
|
10 |
-
import tempfile
|
11 |
|
12 |
# ํ๊ฒฝ ๋ณ์ ์ค์
|
13 |
HF_TOKEN = os.getenv("HF_TOKEN")
|
14 |
MODEL_ID = "CohereForAI/c4ai-command-r-plus-08-2024"
|
15 |
|
16 |
-
#
|
17 |
-
|
18 |
-
os.
|
19 |
-
|
20 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
21 |
|
22 |
class ModelManager:
|
23 |
def __init__(self):
|
24 |
-
self.cache_dir = os.path.join(
|
25 |
os.makedirs(self.cache_dir, exist_ok=True)
|
26 |
self.model = None
|
27 |
self.tokenizer = None
|
@@ -29,6 +39,7 @@ class ModelManager:
|
|
29 |
|
30 |
def setup_model(self):
|
31 |
try:
|
|
|
32 |
print("ํ ํฌ๋์ด์ ๋ก๋ฉ ์์...")
|
33 |
self.tokenizer = AutoTokenizer.from_pretrained(
|
34 |
MODEL_ID,
|
@@ -51,18 +62,7 @@ class ModelManager:
|
|
51 |
print("๋ชจ๋ธ ๋ก๋ฉ ์๋ฃ")
|
52 |
except Exception as e:
|
53 |
print(f"๋ชจ๋ธ ๋ก๋ฉ ์ค ์ค๋ฅ ๋ฐ์: {e}")
|
54 |
-
|
55 |
-
print("๊ธฐ๋ณธ ์ค์ ์ผ๋ก ๋ค์ ์๋...")
|
56 |
-
self.model = AutoModelForCausalLM.from_pretrained(
|
57 |
-
MODEL_ID,
|
58 |
-
token=HF_TOKEN,
|
59 |
-
torch_dtype=torch.float16,
|
60 |
-
trust_remote_code=True,
|
61 |
-
cache_dir=self.cache_dir
|
62 |
-
)
|
63 |
-
print("๊ธฐ๋ณธ ์ค์ ์ผ๋ก ๋ชจ๋ธ ๋ก๋ฉ ์๋ฃ")
|
64 |
-
except Exception as e2:
|
65 |
-
raise Exception(f"๋ชจ๋ธ ๋ก๋ฉ ์์ ํ ์คํจ: {e2}")
|
66 |
|
67 |
class ChatHistory:
|
68 |
def __init__(self):
|
|
|
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 |
+
PERSISTENT_DIR = "/persistent/model_cache"
|
17 |
+
os.makedirs(PERSISTENT_DIR, exist_ok=True)
|
18 |
+
|
19 |
+
# ํ๊ฒฝ ๋ณ์ ์ค์
|
20 |
+
os.environ["TRANSFORMERS_CACHE"] = os.path.join(PERSISTENT_DIR, "transformers_cache")
|
21 |
+
os.environ["TORCH_HOME"] = os.path.join(PERSISTENT_DIR, "torch_cache")
|
22 |
+
os.environ["HF_HOME"] = os.path.join(PERSISTENT_DIR, "huggingface")
|
23 |
+
|
24 |
+
# ๊ฐ ์บ์ ๋๋ ํ ๋ฆฌ ์์ฑ
|
25 |
+
for cache_dir in [
|
26 |
+
os.environ["TRANSFORMERS_CACHE"],
|
27 |
+
os.environ["TORCH_HOME"],
|
28 |
+
os.environ["HF_HOME"]
|
29 |
+
]:
|
30 |
+
os.makedirs(cache_dir, exist_ok=True)
|
31 |
|
32 |
class ModelManager:
|
33 |
def __init__(self):
|
34 |
+
self.cache_dir = os.path.join(PERSISTENT_DIR, "model_files")
|
35 |
os.makedirs(self.cache_dir, exist_ok=True)
|
36 |
self.model = None
|
37 |
self.tokenizer = None
|
|
|
39 |
|
40 |
def setup_model(self):
|
41 |
try:
|
42 |
+
print(f"์บ์ ๋๋ ํ ๋ฆฌ ๊ฒฝ๋ก: {self.cache_dir}")
|
43 |
print("ํ ํฌ๋์ด์ ๋ก๋ฉ ์์...")
|
44 |
self.tokenizer = AutoTokenizer.from_pretrained(
|
45 |
MODEL_ID,
|
|
|
62 |
print("๋ชจ๋ธ ๋ก๋ฉ ์๋ฃ")
|
63 |
except Exception as e:
|
64 |
print(f"๋ชจ๋ธ ๋ก๋ฉ ์ค ์ค๋ฅ ๋ฐ์: {e}")
|
65 |
+
raise Exception(f"๋ชจ๋ธ ๋ก๋ฉ ์คํจ: {e}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
66 |
|
67 |
class ChatHistory:
|
68 |
def __init__(self):
|