yonikremer commited on
Commit
e67f273
1 Parent(s): 15842fa

reimplemented model downloading

Browse files
Files changed (1) hide show
  1. on_server_start.py +7 -9
on_server_start.py CHANGED
@@ -1,11 +1,7 @@
1
  """
2
  A script that is run when the server starts.
3
  """
4
- import os
5
-
6
- from transformers import AutoModelForCausalLM
7
-
8
- DOWNLOADED_MODELS_DIR = os.path.join(os.path.dirname(__file__), 'models')
9
 
10
 
11
  def download_model(model_name: str):
@@ -13,9 +9,12 @@ def download_model(model_name: str):
13
  Downloads a model from hugging face hub to the disk but not to the RAM.
14
  :param model_name: The name of the model to download.
15
  """
16
- print(f"Downloading model: {model_name}")
17
- AutoModelForCausalLM.from_pretrained(model_name)
18
- print(f"Downloaded model: {model_name}")
 
 
 
19
 
20
 
21
  def download_useful_models():
@@ -24,7 +23,6 @@ def download_useful_models():
24
  So that the user doesn't have to wait for the models to download when they first use the app.
25
  """
26
  print("Downloading useful models...")
27
- os.makedirs(DOWNLOADED_MODELS_DIR, exist_ok=True)
28
  useful_models = (
29
  "facebook/opt-125m",
30
  )
 
1
  """
2
  A script that is run when the server starts.
3
  """
4
+ from huggingface_hub import snapshot_download
 
 
 
 
5
 
6
 
7
  def download_model(model_name: str):
 
9
  Downloads a model from hugging face hub to the disk but not to the RAM.
10
  :param model_name: The name of the model to download.
11
  """
12
+ number_of_seconds_in_a_day: int = 86_400
13
+ snapshot_download(
14
+ repo_id=model_name,
15
+ etag_timeout=number_of_seconds_in_a_day,
16
+ resume_download=True,
17
+ )
18
 
19
 
20
  def download_useful_models():
 
23
  So that the user doesn't have to wait for the models to download when they first use the app.
24
  """
25
  print("Downloading useful models...")
 
26
  useful_models = (
27
  "facebook/opt-125m",
28
  )