File tree Expand file tree Collapse file tree 1 file changed +9
-1
lines changed Expand file tree Collapse file tree 1 file changed +9
-1
lines changed Original file line number Diff line number Diff line change
1
+ import os
1
2
import uuid
2
3
import time
3
4
import multiprocessing
@@ -35,6 +36,9 @@ def __init__(
35
36
36
37
self .tokens = (llama_cpp .llama_token * self .params .n_ctx )()
37
38
39
+ if not os .path .exists (model_path ):
40
+ raise ValueError (f"Model path does not exist: { model_path } " )
41
+
38
42
self .ctx = llama_cpp .llama_init_from_file (
39
43
self .model_path .encode ("utf-8" ), self .params
40
44
)
@@ -66,6 +70,8 @@ def __call__(
66
70
llama_cpp .llama_n_ctx (self .ctx ),
67
71
True ,
68
72
)
73
+ if prompt_tokens < 0 :
74
+ raise RuntimeError (f"Failed to tokenize prompt: { prompt_tokens } " )
69
75
70
76
if prompt_tokens + max_tokens > self .params .n_ctx :
71
77
raise ValueError (
@@ -115,13 +121,15 @@ def __call__(
115
121
finish_reason = "stop"
116
122
break
117
123
118
- llama_cpp .llama_eval (
124
+ rc = llama_cpp .llama_eval (
119
125
self .ctx ,
120
126
(llama_cpp .llama_token * 1 )(self .tokens [prompt_tokens + i ]),
121
127
1 ,
122
128
prompt_tokens + completion_tokens ,
123
129
self .n_threads ,
124
130
)
131
+ if rc != 0 :
132
+ raise RuntimeError (f"Failed to evaluate next token: { rc } " )
125
133
126
134
text = text .decode ("utf-8" )
127
135
You can’t perform that action at this time.
0 commit comments