Spaces:
Runtime error
Runtime error
pseudotensor
commited on
Commit
•
82934e3
1
Parent(s):
5a3fd3e
Update with h2oGPT hash 6e04392f877303e49bab527df50aac557f4b9d14
Browse files- client_test.py +1 -1
- gen.py +6 -49
- gpt_langchain.py +1 -1
- gradio_runner.py +9 -5
- gradio_utils/__pycache__/grclient.cpython-310.pyc +0 -0
- gradio_utils/__pycache__/prompt_form.cpython-310.pyc +0 -0
- gradio_utils/prompt_form.py +1 -3
client_test.py
CHANGED
@@ -100,7 +100,7 @@ def get_args(prompt, prompt_type, chat=False, stream_output=False,
|
|
100 |
chunk_size=512,
|
101 |
document_choice=[DocumentChoices.All_Relevant.name],
|
102 |
)
|
103 |
-
from
|
104 |
assert len(set(eval_func_param_names).difference(set(list(kwargs.keys())))) == 0
|
105 |
if chat:
|
106 |
# add chatbot output on end. Assumes serialize=False
|
|
|
100 |
chunk_size=512,
|
101 |
document_choice=[DocumentChoices.All_Relevant.name],
|
102 |
)
|
103 |
+
from evaluate_params import eval_func_param_names
|
104 |
assert len(set(eval_func_param_names).difference(set(list(kwargs.keys())))) == 0
|
105 |
if chat:
|
106 |
# add chatbot output on end. Assumes serialize=False
|
gen.py
CHANGED
@@ -20,6 +20,8 @@ from urllib3.exceptions import ConnectTimeoutError, MaxRetryError, ConnectionErr
|
|
20 |
from requests.exceptions import ConnectionError as ConnectionError2
|
21 |
from requests.exceptions import ReadTimeout as ReadTimeout2
|
22 |
|
|
|
|
|
23 |
if os.path.dirname(os.path.abspath(__file__)) not in sys.path:
|
24 |
sys.path.append(os.path.dirname(os.path.abspath(__file__)))
|
25 |
|
@@ -48,8 +50,6 @@ from transformers import GenerationConfig, AutoModel, TextIteratorStreamer
|
|
48 |
from prompter import Prompter, inv_prompt_type_to_model_lower, non_hf_types, PromptType, get_prompt, generate_prompt
|
49 |
from stopping import get_stopping
|
50 |
|
51 |
-
eval_extra_columns = ['prompt', 'response', 'score']
|
52 |
-
|
53 |
langchain_modes = [x.value for x in list(LangChainMode)]
|
54 |
|
55 |
langchain_actions = [x.value for x in list(LangChainAction)]
|
@@ -144,7 +144,7 @@ def main(
|
|
144 |
force_langchain_evaluate: bool = False,
|
145 |
visible_langchain_modes: list = ['UserData', 'MyData'],
|
146 |
# WIP:
|
147 |
-
#visible_langchain_actions: list = langchain_actions.copy(),
|
148 |
visible_langchain_actions: list = [LangChainAction.QUERY.value, LangChainAction.SUMMARIZE_MAP.value],
|
149 |
document_choice: list = [DocumentChoices.All_Relevant.name],
|
150 |
user_path: str = None,
|
@@ -354,6 +354,7 @@ def main(
|
|
354 |
# assert not prompt_type, "Don't specify model_lock and prompt_type"
|
355 |
# assert not prompt_dict, "Don't specify model_lock and prompt_dict"
|
356 |
|
|
|
357 |
is_hf = bool(int(os.getenv("HUGGINGFACE_SPACES", '0')))
|
358 |
is_gpth2oai = bool(int(os.getenv("GPT_H2O_AI", '0')))
|
359 |
is_public = is_hf or is_gpth2oai # multi-user case with fixed model and disclaimer
|
@@ -361,6 +362,8 @@ def main(
|
|
361 |
memory_restriction_level = 2 if is_hf else 0 # 2 assumes run on 24GB consumer GPU
|
362 |
else:
|
363 |
assert 0 <= memory_restriction_level <= 3, "Bad memory_restriction_level=%s" % memory_restriction_level
|
|
|
|
|
364 |
admin_pass = os.getenv("ADMIN_PASS")
|
365 |
# will sometimes appear in UI or sometimes actual generation, but maybe better than empty result
|
366 |
# but becomes unrecoverable sometimes if raise, so just be silent for now
|
@@ -1188,52 +1191,6 @@ def get_score_model(score_model: str = None,
|
|
1188 |
return smodel, stokenizer, sdevice
|
1189 |
|
1190 |
|
1191 |
-
no_default_param_names = [
|
1192 |
-
'instruction',
|
1193 |
-
'iinput',
|
1194 |
-
'context',
|
1195 |
-
'instruction_nochat',
|
1196 |
-
'iinput_nochat',
|
1197 |
-
]
|
1198 |
-
|
1199 |
-
gen_hyper = ['temperature',
|
1200 |
-
'top_p',
|
1201 |
-
'top_k',
|
1202 |
-
'num_beams',
|
1203 |
-
'max_new_tokens',
|
1204 |
-
'min_new_tokens',
|
1205 |
-
'early_stopping',
|
1206 |
-
'max_time',
|
1207 |
-
'repetition_penalty',
|
1208 |
-
'num_return_sequences',
|
1209 |
-
'do_sample',
|
1210 |
-
]
|
1211 |
-
|
1212 |
-
eval_func_param_names = ['instruction',
|
1213 |
-
'iinput',
|
1214 |
-
'context',
|
1215 |
-
'stream_output',
|
1216 |
-
'prompt_type',
|
1217 |
-
'prompt_dict'] + \
|
1218 |
-
gen_hyper + \
|
1219 |
-
['chat',
|
1220 |
-
'instruction_nochat',
|
1221 |
-
'iinput_nochat',
|
1222 |
-
'langchain_mode',
|
1223 |
-
'langchain_action',
|
1224 |
-
'top_k_docs',
|
1225 |
-
'chunk',
|
1226 |
-
'chunk_size',
|
1227 |
-
'document_choice',
|
1228 |
-
]
|
1229 |
-
|
1230 |
-
# form evaluate defaults for submit_nochat_api
|
1231 |
-
eval_func_param_names_defaults = eval_func_param_names.copy()
|
1232 |
-
for k in no_default_param_names:
|
1233 |
-
if k in eval_func_param_names_defaults:
|
1234 |
-
eval_func_param_names_defaults.remove(k)
|
1235 |
-
|
1236 |
-
|
1237 |
def evaluate(
|
1238 |
model_state,
|
1239 |
my_db_state,
|
|
|
20 |
from requests.exceptions import ConnectionError as ConnectionError2
|
21 |
from requests.exceptions import ReadTimeout as ReadTimeout2
|
22 |
|
23 |
+
from evaluate_params import eval_func_param_names, no_default_param_names
|
24 |
+
|
25 |
if os.path.dirname(os.path.abspath(__file__)) not in sys.path:
|
26 |
sys.path.append(os.path.dirname(os.path.abspath(__file__)))
|
27 |
|
|
|
50 |
from prompter import Prompter, inv_prompt_type_to_model_lower, non_hf_types, PromptType, get_prompt, generate_prompt
|
51 |
from stopping import get_stopping
|
52 |
|
|
|
|
|
53 |
langchain_modes = [x.value for x in list(LangChainMode)]
|
54 |
|
55 |
langchain_actions = [x.value for x in list(LangChainAction)]
|
|
|
144 |
force_langchain_evaluate: bool = False,
|
145 |
visible_langchain_modes: list = ['UserData', 'MyData'],
|
146 |
# WIP:
|
147 |
+
# visible_langchain_actions: list = langchain_actions.copy(),
|
148 |
visible_langchain_actions: list = [LangChainAction.QUERY.value, LangChainAction.SUMMARIZE_MAP.value],
|
149 |
document_choice: list = [DocumentChoices.All_Relevant.name],
|
150 |
user_path: str = None,
|
|
|
354 |
# assert not prompt_type, "Don't specify model_lock and prompt_type"
|
355 |
# assert not prompt_dict, "Don't specify model_lock and prompt_dict"
|
356 |
|
357 |
+
n_jobs = int(os.getenv('n_jobs', str(n_jobs)))
|
358 |
is_hf = bool(int(os.getenv("HUGGINGFACE_SPACES", '0')))
|
359 |
is_gpth2oai = bool(int(os.getenv("GPT_H2O_AI", '0')))
|
360 |
is_public = is_hf or is_gpth2oai # multi-user case with fixed model and disclaimer
|
|
|
362 |
memory_restriction_level = 2 if is_hf else 0 # 2 assumes run on 24GB consumer GPU
|
363 |
else:
|
364 |
assert 0 <= memory_restriction_level <= 3, "Bad memory_restriction_level=%s" % memory_restriction_level
|
365 |
+
if is_public and os.getenv('n_jobs') is None:
|
366 |
+
n_jobs = max(1, min(os.cpu_count() // 2, 8))
|
367 |
admin_pass = os.getenv("ADMIN_PASS")
|
368 |
# will sometimes appear in UI or sometimes actual generation, but maybe better than empty result
|
369 |
# but becomes unrecoverable sometimes if raise, so just be silent for now
|
|
|
1191 |
return smodel, stokenizer, sdevice
|
1192 |
|
1193 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1194 |
def evaluate(
|
1195 |
model_state,
|
1196 |
my_db_state,
|
gpt_langchain.py
CHANGED
@@ -1182,7 +1182,7 @@ def file_to_doc(file, base_path=None, verbose=False, fail_any_exception=False,
|
|
1182 |
# so just extract in path where
|
1183 |
zip_ref.extractall(base_path)
|
1184 |
# recurse
|
1185 |
-
doc1 = path_to_docs(base_path, verbose=verbose, fail_any_exception=fail_any_exception)
|
1186 |
else:
|
1187 |
raise RuntimeError("No file handler for %s" % os.path.basename(file))
|
1188 |
|
|
|
1182 |
# so just extract in path where
|
1183 |
zip_ref.extractall(base_path)
|
1184 |
# recurse
|
1185 |
+
doc1 = path_to_docs(base_path, verbose=verbose, fail_any_exception=fail_any_exception, n_jobs=n_jobs)
|
1186 |
else:
|
1187 |
raise RuntimeError("No file handler for %s" % os.path.basename(file))
|
1188 |
|
gradio_runner.py
CHANGED
@@ -57,9 +57,9 @@ from prompter import prompt_type_to_model_name, prompt_types_strings, inv_prompt
|
|
57 |
get_prompt
|
58 |
from utils import get_githash, flatten_list, zip_data, s3up, clear_torch_cache, get_torch_allocated, system_info_print, \
|
59 |
ping, get_short_name, get_url, makedirs, get_kwargs, remove, system_info, ping_gpu
|
60 |
-
from gen import get_model, languages_covered, evaluate,
|
61 |
-
|
62 |
-
|
63 |
|
64 |
from apscheduler.schedulers.background import BackgroundScheduler
|
65 |
|
@@ -307,7 +307,7 @@ def go_gradio(**kwargs):
|
|
307 |
|
308 |
col_chat = gr.Column(visible=kwargs['chat'])
|
309 |
with col_chat:
|
310 |
-
instruction, submit, stop_btn = make_prompt_form(kwargs)
|
311 |
text_output, text_output2, text_outputs = make_chatbots(output_label0, output_label0_model2,
|
312 |
**kwargs)
|
313 |
|
@@ -756,6 +756,7 @@ def go_gradio(**kwargs):
|
|
756 |
caption_loader=caption_loader,
|
757 |
verbose=kwargs['verbose'],
|
758 |
user_path=kwargs['user_path'],
|
|
|
759 |
)
|
760 |
add_file_outputs = [fileup_output, langchain_mode, add_to_shared_db_btn, add_to_my_db_btn]
|
761 |
add_file_kwargs = dict(fn=update_user_db_func,
|
@@ -834,6 +835,7 @@ def go_gradio(**kwargs):
|
|
834 |
caption_loader=caption_loader,
|
835 |
verbose=kwargs['verbose'],
|
836 |
user_path=kwargs['user_path'],
|
|
|
837 |
)
|
838 |
|
839 |
add_my_file_outputs = [fileup_output, langchain_mode, my_db_state, add_to_shared_db_btn, add_to_my_db_btn]
|
@@ -2269,7 +2271,8 @@ def _update_user_db(file, db1, x, y, chunk, chunk_size, dbs=None, db_type=None,
|
|
2269 |
captions_model=None,
|
2270 |
enable_ocr=None,
|
2271 |
verbose=None,
|
2272 |
-
is_url=None, is_txt=None
|
|
|
2273 |
assert use_openai_embedding is not None
|
2274 |
assert hf_embedding_model is not None
|
2275 |
assert caption_loader is not None
|
@@ -2310,6 +2313,7 @@ def _update_user_db(file, db1, x, y, chunk, chunk_size, dbs=None, db_type=None,
|
|
2310 |
print("Adding %s" % file, flush=True)
|
2311 |
sources = path_to_docs(file if not is_url and not is_txt else None,
|
2312 |
verbose=verbose,
|
|
|
2313 |
chunk=chunk, chunk_size=chunk_size,
|
2314 |
url=file if is_url else None,
|
2315 |
text=file if is_txt else None,
|
|
|
57 |
get_prompt
|
58 |
from utils import get_githash, flatten_list, zip_data, s3up, clear_torch_cache, get_torch_allocated, system_info_print, \
|
59 |
ping, get_short_name, get_url, makedirs, get_kwargs, remove, system_info, ping_gpu
|
60 |
+
from gen import get_model, languages_covered, evaluate, score_qa, langchain_modes, inputs_kwargs_list, scratch_base_dir, \
|
61 |
+
get_max_max_new_tokens, get_minmax_top_k_docs, history_to_context, langchain_actions
|
62 |
+
from evaluate_params import eval_func_param_names, no_default_param_names, eval_func_param_names_defaults
|
63 |
|
64 |
from apscheduler.schedulers.background import BackgroundScheduler
|
65 |
|
|
|
307 |
|
308 |
col_chat = gr.Column(visible=kwargs['chat'])
|
309 |
with col_chat:
|
310 |
+
instruction, submit, stop_btn = make_prompt_form(kwargs, LangChainMode)
|
311 |
text_output, text_output2, text_outputs = make_chatbots(output_label0, output_label0_model2,
|
312 |
**kwargs)
|
313 |
|
|
|
756 |
caption_loader=caption_loader,
|
757 |
verbose=kwargs['verbose'],
|
758 |
user_path=kwargs['user_path'],
|
759 |
+
n_jobs=kwargs['n_jobs'],
|
760 |
)
|
761 |
add_file_outputs = [fileup_output, langchain_mode, add_to_shared_db_btn, add_to_my_db_btn]
|
762 |
add_file_kwargs = dict(fn=update_user_db_func,
|
|
|
835 |
caption_loader=caption_loader,
|
836 |
verbose=kwargs['verbose'],
|
837 |
user_path=kwargs['user_path'],
|
838 |
+
n_jobs=kwargs['n_jobs'],
|
839 |
)
|
840 |
|
841 |
add_my_file_outputs = [fileup_output, langchain_mode, my_db_state, add_to_shared_db_btn, add_to_my_db_btn]
|
|
|
2271 |
captions_model=None,
|
2272 |
enable_ocr=None,
|
2273 |
verbose=None,
|
2274 |
+
is_url=None, is_txt=None,
|
2275 |
+
n_jobs=-1):
|
2276 |
assert use_openai_embedding is not None
|
2277 |
assert hf_embedding_model is not None
|
2278 |
assert caption_loader is not None
|
|
|
2313 |
print("Adding %s" % file, flush=True)
|
2314 |
sources = path_to_docs(file if not is_url and not is_txt else None,
|
2315 |
verbose=verbose,
|
2316 |
+
n_jobs=n_jobs,
|
2317 |
chunk=chunk, chunk_size=chunk_size,
|
2318 |
url=file if is_url else None,
|
2319 |
text=file if is_txt else None,
|
gradio_utils/__pycache__/grclient.cpython-310.pyc
CHANGED
Binary files a/gradio_utils/__pycache__/grclient.cpython-310.pyc and b/gradio_utils/__pycache__/grclient.cpython-310.pyc differ
|
|
gradio_utils/__pycache__/prompt_form.cpython-310.pyc
CHANGED
Binary files a/gradio_utils/__pycache__/prompt_form.cpython-310.pyc and b/gradio_utils/__pycache__/prompt_form.cpython-310.pyc differ
|
|
gradio_utils/prompt_form.py
CHANGED
@@ -3,8 +3,6 @@ import math
|
|
3 |
|
4 |
import gradio as gr
|
5 |
|
6 |
-
from enums import LangChainMode
|
7 |
-
|
8 |
|
9 |
def make_chatbots(output_label0, output_label0_model2, **kwargs):
|
10 |
text_outputs = []
|
@@ -97,7 +95,7 @@ def make_chatbots(output_label0, output_label0_model2, **kwargs):
|
|
97 |
return text_output, text_output2, text_outputs
|
98 |
|
99 |
|
100 |
-
def make_prompt_form(kwargs):
|
101 |
if kwargs['langchain_mode'] != LangChainMode.DISABLED.value:
|
102 |
extra_prompt_form = ". For summarization, empty submission uses first top_k_docs documents."
|
103 |
else:
|
|
|
3 |
|
4 |
import gradio as gr
|
5 |
|
|
|
|
|
6 |
|
7 |
def make_chatbots(output_label0, output_label0_model2, **kwargs):
|
8 |
text_outputs = []
|
|
|
95 |
return text_output, text_output2, text_outputs
|
96 |
|
97 |
|
98 |
+
def make_prompt_form(kwargs, LangChainMode):
|
99 |
if kwargs['langchain_mode'] != LangChainMode.DISABLED.value:
|
100 |
extra_prompt_form = ". For summarization, empty submission uses first top_k_docs documents."
|
101 |
else:
|