Spaces:
Running
Running
last modal version required some syntax changes
Browse files- backend.py +12 -11
backend.py
CHANGED
@@ -1,4 +1,4 @@
|
|
1 |
-
import
|
2 |
|
3 |
from typing import List, Dict, Tuple, Union, Callable
|
4 |
# from preprocessing import FileIO
|
@@ -9,18 +9,19 @@ from typing import List, Dict, Tuple, Union, Callable
|
|
9 |
# remote_path="./data",
|
10 |
# )
|
11 |
|
12 |
-
|
13 |
-
vector_search =
|
14 |
"sentence_transformers==2.2.2", "llama_index==0.9.6.post1", "angle_emb==0.1.5"
|
15 |
)
|
16 |
|
17 |
-
|
|
|
18 |
|
19 |
|
20 |
-
@
|
21 |
gpu="A100",
|
22 |
timeout=600,
|
23 |
-
volumes={"/root/models":
|
24 |
# secrets are available in the environment with os.environ["SECRET_NAME"]
|
25 |
# secret=modal.Secret.from_name("my-huggingface-secret")
|
26 |
)
|
@@ -91,11 +92,11 @@ def encode_content_splits(content_splits,
|
|
91 |
return emb
|
92 |
|
93 |
|
94 |
-
@
|
95 |
-
mounts=[
|
96 |
remote_path="/root/data",
|
97 |
condition=lambda pth: ".json" in pth)],
|
98 |
-
volumes={"/root/models":
|
99 |
)
|
100 |
def finetune(training_path='./data/training_data_300.json',
|
101 |
valid_path='./data/validation_data_100.json',
|
@@ -149,7 +150,7 @@ def finetune(training_path='./data/training_data_300.json',
|
|
149 |
print(f"GPU processing lasted {end:.2f} seconds")
|
150 |
|
151 |
print(os.listdir('/root/models'))
|
152 |
-
|
153 |
|
154 |
# TODO SHARE THE MODEL ON HUGGINGFACE
|
155 |
# https://huggingface.co/docs/transformers/v4.15.0/model_sharing
|
@@ -174,7 +175,7 @@ def finetune(training_path='./data/training_data_300.json',
|
|
174 |
return "Finetuning failed"
|
175 |
|
176 |
|
177 |
-
@
|
178 |
def test_method(content_splits=[["a"]]):
|
179 |
output = encode_content_splits.remote(content_splits)
|
180 |
return output
|
|
|
1 |
+
from modal import App, Volume, Image, Mount
|
2 |
|
3 |
from typing import List, Dict, Tuple, Union, Callable
|
4 |
# from preprocessing import FileIO
|
|
|
9 |
# remote_path="./data",
|
10 |
# )
|
11 |
|
12 |
+
app = App("vector-search-project")
|
13 |
+
vector_search = Image.debian_slim().pip_install(
|
14 |
"sentence_transformers==2.2.2", "llama_index==0.9.6.post1", "angle_emb==0.1.5"
|
15 |
)
|
16 |
|
17 |
+
vol = Volume.from_name("vector-search-volume")
|
18 |
+
# ^ volume must be created manually with CLI: modal volume create vector-search-volume
|
19 |
|
20 |
|
21 |
+
@app.function(image=vector_search,
|
22 |
gpu="A100",
|
23 |
timeout=600,
|
24 |
+
volumes={"/root/models": vol}
|
25 |
# secrets are available in the environment with os.environ["SECRET_NAME"]
|
26 |
# secret=modal.Secret.from_name("my-huggingface-secret")
|
27 |
)
|
|
|
92 |
return emb
|
93 |
|
94 |
|
95 |
+
@app.function(image=vector_search, gpu="A100", timeout=240,
|
96 |
+
mounts=[Mount.from_local_dir("./data",
|
97 |
remote_path="/root/data",
|
98 |
condition=lambda pth: ".json" in pth)],
|
99 |
+
volumes={"/root/models": vol}
|
100 |
)
|
101 |
def finetune(training_path='./data/training_data_300.json',
|
102 |
valid_path='./data/validation_data_100.json',
|
|
|
150 |
print(f"GPU processing lasted {end:.2f} seconds")
|
151 |
|
152 |
print(os.listdir('/root/models'))
|
153 |
+
app.volume.commit() # Persist changes, ie the finetumed model
|
154 |
|
155 |
# TODO SHARE THE MODEL ON HUGGINGFACE
|
156 |
# https://huggingface.co/docs/transformers/v4.15.0/model_sharing
|
|
|
175 |
return "Finetuning failed"
|
176 |
|
177 |
|
178 |
+
@app.local_entrypoint()
|
179 |
def test_method(content_splits=[["a"]]):
|
180 |
output = encode_content_splits.remote(content_splits)
|
181 |
return output
|