|
|
@ -5,8 +5,8 @@ from modal import App, Volume, Image |
|
|
|
|
|
|
|
|
|
|
|
app = modal.App("pricer-service") |
|
|
|
app = modal.App("pricer-service") |
|
|
|
image = Image.debian_slim().pip_install("huggingface", "torch", "transformers", "bitsandbytes", "accelerate", "peft") |
|
|
|
image = Image.debian_slim().pip_install("huggingface", "torch", "transformers", "bitsandbytes", "accelerate", "peft") |
|
|
|
|
|
|
|
image.add_local_python_source("hello", "llama") #CE: adding here based on Deprecation warnings... |
|
|
|
secrets = [modal.Secret.from_name("hf-secret")] |
|
|
|
secrets = [modal.Secret.from_name("hf-secret")] |
|
|
|
volume = modal.Volume.from_name("pricer-model-cache", create_if_missing=True) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Constants |
|
|
|
# Constants |
|
|
|
|
|
|
|
|
|
|
@ -16,26 +16,35 @@ PROJECT_NAME = "pricer" |
|
|
|
HF_USER = "cproSD" # your HF name here! Or use mine if you just want to reproduce my results. |
|
|
|
HF_USER = "cproSD" # your HF name here! Or use mine if you just want to reproduce my results. |
|
|
|
RUN_NAME = "2025-04-08_21.52.37" |
|
|
|
RUN_NAME = "2025-04-08_21.52.37" |
|
|
|
PROJECT_RUN_NAME = f"{PROJECT_NAME}-{RUN_NAME}" |
|
|
|
PROJECT_RUN_NAME = f"{PROJECT_NAME}-{RUN_NAME}" |
|
|
|
#DEL: REVISION = "e8d637df551603dc86cd7a1598a8f44af4d7ae36" |
|
|
|
|
|
|
|
FINETUNED_MODEL = f"{HF_USER}/{PROJECT_RUN_NAME}" |
|
|
|
FINETUNED_MODEL = f"{HF_USER}/{PROJECT_RUN_NAME}" |
|
|
|
MODEL_DIR = "hf-cache/" |
|
|
|
#DEL: MODEL_DIR = "hf-cache/" |
|
|
|
|
|
|
|
MODEL_DIR = "/models/" |
|
|
|
BASE_DIR = MODEL_DIR + BASE_MODEL |
|
|
|
BASE_DIR = MODEL_DIR + BASE_MODEL |
|
|
|
FINETUNED_DIR = MODEL_DIR + FINETUNED_MODEL |
|
|
|
FINETUNED_DIR = MODEL_DIR + FINETUNED_MODEL |
|
|
|
|
|
|
|
CACHE_DIR = "/cache" #CE: Use the standard /cache path for hf-hub-cache |
|
|
|
|
|
|
|
|
|
|
|
QUESTION = "How much does this cost to the nearest dollar?" |
|
|
|
QUESTION = "How much does this cost to the nearest dollar?" |
|
|
|
PREFIX = "Price is $" |
|
|
|
PREFIX = "Price is $" |
|
|
|
|
|
|
|
|
|
|
|
#DEL: @app.cls(image=image, secrets=secrets, gpu=GPU, timeout=1800) |
|
|
|
#CE: Use the pre-configured hf-hub-cache Volume... |
|
|
|
@app.cls(image=image, secrets=secrets, gpu=GPU, timeout=1800, volumes={"/pretrained_models": volume}) |
|
|
|
hf_cache_volume = Volume.from_name("hf-hub-cache") |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@app.cls( |
|
|
|
|
|
|
|
#image=image, |
|
|
|
|
|
|
|
image=image.env({"HF_HUB_CACHE": CACHE_DIR}), |
|
|
|
|
|
|
|
secrets=secrets, |
|
|
|
|
|
|
|
gpu=GPU, |
|
|
|
|
|
|
|
timeout=1800, |
|
|
|
|
|
|
|
volumes={CACHE_DIR: hf_cache_volume} |
|
|
|
|
|
|
|
) |
|
|
|
class Pricer: |
|
|
|
class Pricer: |
|
|
|
|
|
|
|
#DEL: @modal.build() |
|
|
|
#DEL: def download_model_to_folder(self): |
|
|
|
#DEL: def download_model_to_folder(self): |
|
|
|
def __enter__(self): |
|
|
|
#DEL: from huggingface_hub import snapshot_download |
|
|
|
from huggingface_hub import snapshot_download |
|
|
|
#DEL: import os |
|
|
|
import os |
|
|
|
#DEL: os.makedirs(MODEL_DIR, exist_ok=True) |
|
|
|
os.makedirs("/pretrained_models/" + MODEL_DIR, exist_ok=True) |
|
|
|
#DEL: snapshot_download(BASE_MODEL, local_dir=BASE_DIR) |
|
|
|
snapshot_download(BASE_MODEL, local_dir="/pretrained_models/" + BASE_DIR) |
|
|
|
#DEL: snapshot_download(FINETUNED_MODEL, local_dir=FINETUNED_DIR) |
|
|
|
#DEL: snapshot_download(FINETUNED_MODEL, revision=REVISION, local_dir=FINETUNED_DIR) |
|
|
|
|
|
|
|
snapshot_download(FINETUNED_MODEL, local_dir="/pretrained_models/" + FINETUNED_DIR) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@modal.enter() |
|
|
|
@modal.enter() |
|
|
|
def setup(self): |
|
|
|
def setup(self): |
|
|
@ -64,8 +73,7 @@ class Pricer: |
|
|
|
device_map="auto" |
|
|
|
device_map="auto" |
|
|
|
) |
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
#DEL: self.fine_tuned_model = PeftModel.from_pretrained(self.base_model, FINETUNED_DIR, revision=REVISION) |
|
|
|
self.fine_tuned_model = PeftModel.from_pretrained(self.base_model, FINETUNED_DIR, revision=REVISION) |
|
|
|
self.fine_tuned_model = PeftModel.from_pretrained(self.base_model, FINETUNED_DIR) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@modal.method() |
|
|
|
@modal.method() |
|
|
|
def price(self, description: str) -> float: |
|
|
|
def price(self, description: str) -> float: |
|
|
@ -90,4 +98,3 @@ class Pricer: |
|
|
|
@modal.method() |
|
|
|
@modal.method() |
|
|
|
def wake_up(self) -> str: |
|
|
|
def wake_up(self) -> str: |
|
|
|
return "ok" |
|
|
|
return "ok" |
|
|
|
|
|
|
|
|
|
|
|