Skip to content

Commit 91c7ace

Browse files
add completion to prompt function for phi3 (#2299)
1 parent cb99c7b commit 91c7ace

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

notebooks/llm-rag-llamaindex/llm-rag-llamaindex.ipynb

+4-2
Original file line numberDiff line numberDiff line change
@@ -1245,6 +1245,9 @@
12451245
"\n",
12461246
"ov_config = {\"PERFORMANCE_HINT\": \"LATENCY\", \"NUM_STREAMS\": \"1\", \"CACHE_DIR\": \"\"}\n",
12471247
"\n",
1248+
"stop_tokens = llm_model_configuration.get(\"stop_tokens\")\n",
1249+
"completion_to_prompt = llm_model_configuration.get(\"completion_to_prompt\")\n",
1250+
"\n",
12481251
"if \"GPU\" in llm_device.value and \"qwen2-7b-instruct\" in llm_model_id.value:\n",
12491252
" ov_config[\"GPU_ENABLE_SDPA_OPTIMIZATION\"] = \"NO\"\n",
12501253
"\n",
@@ -1259,6 +1262,7 @@
12591262
" max_new_tokens=2,\n",
12601263
" model_kwargs={\"ov_config\": ov_config, \"trust_remote_code\": True},\n",
12611264
" generate_kwargs={\"temperature\": 0.7, \"top_k\": 50, \"top_p\": 0.95},\n",
1265+
" completion_to_prompt=completion_to_prompt,\n",
12621266
" device_map=llm_device.value,\n",
12631267
")\n",
12641268
"\n",
@@ -1314,8 +1318,6 @@
13141318
"else:\n",
13151319
" text_example_path = \"text_example_cn.pdf\"\n",
13161320
"\n",
1317-
"stop_tokens = llm_model_configuration.get(\"stop_tokens\")\n",
1318-
"\n",
13191321
"\n",
13201322
"class StopOnTokens(StoppingCriteria):\n",
13211323
" def __init__(self, token_ids):\n",

utils/llm_config.py

+5
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,10 @@ def internlm_partial_text_processor(partial_text, new_text):
5454
return partial_text.split("<|im_end|>")[0]
5555

5656

57+
def phi_completion_to_prompt(completion):
58+
return f"<|system|><|end|><|user|>{completion}<|end|><|assistant|>\n"
59+
60+
5761
SUPPORTED_LLM_MODELS = {
5862
"English": {
5963
"qwen2-0.5b-instruct": {
@@ -252,6 +256,7 @@ def internlm_partial_text_processor(partial_text, new_text):
252256
Context: {context}
253257
Answer: <|end|>
254258
<|assistant|>""",
259+
"completion_to_prompt": phi_completion_to_prompt,
255260
},
256261
},
257262
"Chinese": {

0 commit comments

Comments
 (0)