ffreemt commited on
Commit
0161136
1 Parent(s): bd3b1f7

Update multiple attempts of downloading

Browse files
Files changed (1) hide show
  1. app.py +32 -13
app.py CHANGED
@@ -24,14 +24,24 @@ except AttributeError:
24
  repo_id = "TheBloke/openbuddy-mistral-7B-v13-GGUF"
25
  filename = "openbuddy-mistral-7b-v13.Q4_K_S.gguf" # 4.17G
26
 
 
27
  logger.debug("Start dl")
28
- try:
29
- model_path = hf_hub_download(repo_id=repo_id, filename=filename, revision="main")
30
- except Exception as exc:
31
- logger.error(f"failed to download {filename}: {exc}")
32
- raise gr.Error("hf acting up, can't donwload the model, exiting")
33
- # raise SystemExit("hf acting up, can't donwload the model, exiting")
34
- logger.debug("Done dl")
 
 
 
 
 
 
 
 
 
35
 
36
  # Set gpu_layers to the number of layers to offload to GPU. Set to 0 if no GPU acceleration is available on your system.
37
  # model = AutoModelForCausalLM.from_pretrained("TheBloke/openbuddy-mistral-7B-v13-GGUF", model_file="openbuddy-mistral-7b-v13.Q4_K_S.gguf", model_type="mistral", gpu_layers=0)
@@ -51,13 +61,19 @@ else:
51
  gpu_layers = 0
52
 
53
  logger.debug("Start loading the model")
54
- model = AutoModelForCausalLM.from_pretrained(
55
- model_path, model_type="mistral", gpu_layers=gpu_layers
56
- )
57
- logger.debug("Done loading the model")
 
 
 
 
 
 
58
 
59
  ins = """[INST] <<FRIDAY>>
60
- Remember that your English name is "Shi-Ci" and your name in Chinese is "兮辞". You are a helpful, respectful and honest assistant. Always answer as helpfully as possible, while being safe. Your answers should not include any harmful, unethical, racist, sexist, toxic, dangerous, or illegal content. Please ensure that your responses are socially unbiased and positive in nature.
61
  If a question does not make any sense, or is not factually coherent, explain why instead of answering something not correct. If you don't know the answer to a question, please don't share false information.
62
  <</FRIDAY>>
63
  {} [/INST]
@@ -78,7 +94,10 @@ theme = gr.themes.Monochrome(
78
 
79
 
80
  def response(question):
81
- res = model(ins.format(question))
 
 
 
82
  yield res
83
 
84
 
 
24
  repo_id = "TheBloke/openbuddy-mistral-7B-v13-GGUF"
25
  filename = "openbuddy-mistral-7b-v13.Q4_K_S.gguf" # 4.17G
26
 
27
+ model_ready = True
28
  logger.debug("Start dl")
29
+ # try to download 5 times:
30
+ for idx in range(5):
31
+ logger.debug(f"attempt {idx + 1}")
32
+ try:
33
+ model_path = hf_hub_download(repo_id=repo_id, filename=filename, revision="main")
34
+ break
35
+ except Exception as exc:
36
+ logger.error(f"failed to download {filename}: {exc}")
37
+ # raise SystemExit("hf acting up, can't donwload the model {filename=}, exiting")
38
+ else:
39
+ logger.warning("Tried 5 times to no vain")
40
+ raise gr.Error(f"hf acting up, can't donwload the model {filename=}, exiting")
41
+ # raise SystemExit("hf acting up, can't donwload the model {filename=}, exiting")
42
+ model_ready = False
43
+
44
+ logger.debug(f"Done dl, {model_ready=}")
45
 
46
  # Set gpu_layers to the number of layers to offload to GPU. Set to 0 if no GPU acceleration is available on your system.
47
  # model = AutoModelForCausalLM.from_pretrained("TheBloke/openbuddy-mistral-7B-v13-GGUF", model_file="openbuddy-mistral-7b-v13.Q4_K_S.gguf", model_type="mistral", gpu_layers=0)
 
61
  gpu_layers = 0
62
 
63
  logger.debug("Start loading the model")
64
+ try:
65
+ model = AutoModelForCausalLM.from_pretrained(
66
+ model_path, model_type="mistral", gpu_layers=gpu_layers
67
+ )
68
+ except Exception as exc:
69
+ logger.error(exc)
70
+ model_ready = False
71
+ model = None
72
+
73
+ logger.debug(f"Done loading the model, {model_ready=}")
74
 
75
  ins = """[INST] <<FRIDAY>>
76
+ Remember that your English name is "openbuddy" and your name in Chinese is "开友". You are a helpful, respectful and honest assistant. Always answer as helpfully as possible, while being safe. Your answers should not include any harmful, unethical, racist, sexist, toxic, dangerous, or illegal content. Please ensure that your responses are socially unbiased and positive in nature.
77
  If a question does not make any sense, or is not factually coherent, explain why instead of answering something not correct. If you don't know the answer to a question, please don't share false information.
78
  <</FRIDAY>>
79
  {} [/INST]
 
94
 
95
 
96
  def response(question):
97
+ if model is None:
98
+ res = "model not ready (got a problem with downloading the file {filename=} from hf.co)"
99
+ else:
100
+ res = model(ins.format(question))
101
  yield res
102
 
103