Browse Source

resolving deprecation warnings

pull/314/head
craigprobus 4 weeks ago
parent
commit
f995fdecc8
  1. 4784
      week8/day1.ipynb
  2. 39
      week8/pricer_service2.py

4784
week8/day1.ipynb

File diff suppressed because it is too large Load Diff

39
week8/pricer_service2.py

@ -5,8 +5,8 @@ from modal import App, Volume, Image
app = modal.App("pricer-service")
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")]
volume = modal.Volume.from_name("pricer-model-cache", create_if_missing=True)
# 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.
RUN_NAME = "2025-04-08_21.52.37"
PROJECT_RUN_NAME = f"{PROJECT_NAME}-{RUN_NAME}"
#DEL: REVISION = "e8d637df551603dc86cd7a1598a8f44af4d7ae36"
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
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?"
PREFIX = "Price is $"
#DEL: @app.cls(image=image, secrets=secrets, gpu=GPU, timeout=1800)
@app.cls(image=image, secrets=secrets, gpu=GPU, timeout=1800, volumes={"/pretrained_models": volume})
#CE: Use the pre-configured hf-hub-cache 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:
#DEL: @modal.build()
#DEL: def download_model_to_folder(self):
def __enter__(self):
from huggingface_hub import snapshot_download
import os
os.makedirs("/pretrained_models/" + MODEL_DIR, exist_ok=True)
snapshot_download(BASE_MODEL, local_dir="/pretrained_models/" + BASE_DIR)
#DEL: snapshot_download(FINETUNED_MODEL, revision=REVISION, local_dir=FINETUNED_DIR)
snapshot_download(FINETUNED_MODEL, local_dir="/pretrained_models/" + FINETUNED_DIR)
#DEL: from huggingface_hub import snapshot_download
#DEL: import os
#DEL: os.makedirs(MODEL_DIR, exist_ok=True)
#DEL: snapshot_download(BASE_MODEL, local_dir=BASE_DIR)
#DEL: snapshot_download(FINETUNED_MODEL, local_dir=FINETUNED_DIR)
@modal.enter()
def setup(self):
@ -64,8 +73,7 @@ class Pricer:
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)
self.fine_tuned_model = PeftModel.from_pretrained(self.base_model, FINETUNED_DIR, revision=REVISION)
@modal.method()
def price(self, description: str) -> float:
@ -89,5 +97,4 @@ class Pricer:
@modal.method()
def wake_up(self) -> str:
return "ok"
return "ok"
Loading…
Cancel
Save