Skip to content

Commit 7b51a15

Browse files
add internlm2 in LLM notebook (openvinotoolkit#1788)
including: 1. add internLM2-1.8b, qwen1.5-1.8b, qwen1.5-4b support 2. add language filter when selecting the models 3. update MiniCPM's config files with Chinese prompt template 4. Fix Baichuan2 tokenization issue 5. rebase QWEN support for further marketing collaboration
1 parent f935d5c commit 7b51a15

File tree

7 files changed

+770
-405
lines changed

7 files changed

+770
-405
lines changed

.ci/spellcheck/.pyspelling.wordlist.txt

+2
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,8 @@ instantiation
297297
InstructGPT
298298
InstructPix
299299
intel
300+
InternLM
301+
internlm
300302
invertible
301303
intervaling
302304
im

notebooks/254-llm-chatbot/254-llm-chatbot.ipynb

+228-48
Large diffs are not rendered by default.

notebooks/254-llm-chatbot/254-rag-chatbot.ipynb

+70-32
Original file line numberDiff line numberDiff line change
@@ -156,14 +156,17 @@
156156
" except OSError:\n",
157157
" notebook_login()\n",
158158
"```\n",
159-
"* **qwen1.5-7b-chat** - Qwen1.5 is the beta version of Qwen2, a transformer-based decoder-only language model pretrained on a large amount of data. Qwen1.5 is a language model series including decoder language models of different model sizes. It is based on the Transformer architecture with SwiGLU activation, attention QKV bias, group query attention, mixture of sliding window attention and full attention. You can find more details about model in the [model card](https://huggingface.co/Qwen/Qwen1.5-7B-Chat).\n",
159+
"* **qwen1.5-0.5b-chat/qwen1.5-1.8b-chat/qwen1.5-7b-chat** - Qwen1.5 is the beta version of Qwen2, a transformer-based decoder-only language model pretrained on a large amount of data. Qwen1.5 is a language model series including decoder language models of different model sizes. It is based on the Transformer architecture with SwiGLU activation, attention QKV bias, group query attention, mixture of sliding window attention and full attention. You can find more details about model in the [model repository](https://huggingface.co/Qwen).\n",
160+
"* **qwen-7b-chat** - Qwen-7B is the 7B-parameter version of the large language model series, Qwen (abbr. Tongyi Qianwen), proposed by Alibaba Cloud. Qwen-7B is a Transformer-based large language model, which is pretrained on a large volume of data, including web texts, books, codes, etc. For more details about Qwen, please refer to the [GitHub](https://github.com/QwenLM/Qwen) code repository.\n",
160161
"* **mpt-7b-chat** - MPT-7B is part of the family of MosaicPretrainedTransformer (MPT) models, which use a modified transformer architecture optimized for efficient training and inference. These architectural changes include performance-optimized layer implementations and the elimination of context length limits by replacing positional embeddings with Attention with Linear Biases ([ALiBi](https://arxiv.org/abs/2108.12409)). Thanks to these modifications, MPT models can be trained with high throughput efficiency and stable convergence. MPT-7B-chat is a chatbot-like model for dialogue generation. It was built by finetuning MPT-7B on the [ShareGPT-Vicuna](https://huggingface.co/datasets/jeffwan/sharegpt_vicuna), [HC3](https://huggingface.co/datasets/Hello-SimpleAI/HC3), [Alpaca](https://huggingface.co/datasets/tatsu-lab/alpaca), [HH-RLHF](https://huggingface.co/datasets/Anthropic/hh-rlhf), and [Evol-Instruct](https://huggingface.co/datasets/victor123/evol_instruct_70k) datasets. More details about the model can be found in [blog post](https://www.mosaicml.com/blog/mpt-7b), [repository](https://github.com/mosaicml/llm-foundry/) and [HuggingFace model card](https://huggingface.co/mosaicml/mpt-7b-chat).\n",
161162
"* **chatglm3-6b** - ChatGLM3-6B is the latest open-source model in the ChatGLM series. While retaining many excellent features such as smooth dialogue and low deployment threshold from the previous two generations, ChatGLM3-6B employs a more diverse training dataset, more sufficient training steps, and a more reasonable training strategy. ChatGLM3-6B adopts a newly designed [Prompt format](https://github.com/THUDM/ChatGLM3/blob/main/PROMPT_en.md), in addition to the normal multi-turn dialogue. You can find more details about model in the [model card](https://huggingface.co/THUDM/chatglm3-6b)\n",
162163
"* **mistral-7b** - The Mistral-7B-v0.1 Large Language Model (LLM) is a pretrained generative text model with 7 billion parameters. You can find more details about model in the [model card](https://huggingface.co/mistralai/Mistral-7B-v0.1), [paper](https://arxiv.org/abs/2310.06825) and [release blog post](https://mistral.ai/news/announcing-mistral-7b/).\n",
163164
"* **zephyr-7b-beta** - Zephyr is a series of language models that are trained to act as helpful assistants. Zephyr-7B-beta is the second model in the series, and is a fine-tuned version of [mistralai/Mistral-7B-v0.1](https://huggingface.co/mistralai/Mistral-7B-v0.1) that was trained on on a mix of publicly available, synthetic datasets using [Direct Preference Optimization (DPO)](https://arxiv.org/abs/2305.18290). You can find more details about model in [technical report](https://arxiv.org/abs/2310.16944) and [HuggingFace model card](https://huggingface.co/HuggingFaceH4/zephyr-7b-beta).\n",
164165
"* **neural-chat-7b-v3-1** - Mistral-7b model fine-tuned using Intel Gaudi. The model fine-tuned on the open source dataset [Open-Orca/SlimOrca](https://huggingface.co/datasets/Open-Orca/SlimOrca) and aligned with [Direct Preference Optimization (DPO) algorithm](https://arxiv.org/abs/2305.18290). More details can be found in [model card](https://huggingface.co/Intel/neural-chat-7b-v3-1) and [blog post](https://medium.com/@NeuralCompressor/the-practice-of-supervised-finetuning-and-direct-preference-optimization-on-habana-gaudi2-a1197d8a3cd3).\n",
165166
"* **notus-7b-v1** - Notus is a collection of fine-tuned models using [Direct Preference Optimization (DPO)](https://arxiv.org/abs/2305.18290). and related [RLHF](https://huggingface.co/blog/rlhf) techniques. This model is the first version, fine-tuned with DPO over zephyr-7b-sft. Following a data-first approach, the only difference between Notus-7B-v1 and Zephyr-7B-beta is the preference dataset used for dDPO. Proposed approach for dataset creation helps to effectively fine-tune Notus-7b that surpasses Zephyr-7B-beta and Claude 2 on [AlpacaEval](https://tatsu-lab.github.io/alpaca_eval/). More details about model can be found in [model card](https://huggingface.co/argilla/notus-7b-v1).\n",
166-
"* **baichuan2-7b-chat** - Baichuan 2 is the new generation of large-scale open-source language models launched by [Baichuan Intelligence inc](https://www.baichuan-ai.com/home). It is trained on a high-quality corpus with 2.6 trillion tokens and has achieved the best performance in authoritative Chinese and English benchmarks of the same size."
167+
"* **youri-7b-chat** - Youri-7b-chat is a Llama2 based model. [Rinna Co., Ltd.](https://rinna.co.jp/) conducted further pre-training for the Llama2 model with a mixture of English and Japanese datasets to improve Japanese task capability. The model is publicly released on Hugging Face hub. You can find detailed information at the [rinna/youri-7b-chat project page](https://huggingface.co/rinna/youri-7b). \n",
168+
"* **baichuan2-7b-chat** - Baichuan 2 is the new generation of large-scale open-source language models launched by [Baichuan Intelligence inc](https://www.baichuan-ai.com/home). It is trained on a high-quality corpus with 2.6 trillion tokens and has achieved the best performance in authoritative Chinese and English benchmarks of the same size.\n",
169+
"* **internlm2-chat-1.8b** - InternLM2 is the second generation InternLM series. Compared to the previous generation model, it shows significant improvements in various capabilities, including reasoning, mathematics, and coding. More details about model can be found in [model repository](https://huggingface.co/internlm)."
167170
]
168171
},
169172
{
@@ -183,15 +186,15 @@
183186
"name": "stderr",
184187
"output_type": "stream",
185188
"text": [
186-
"2024-03-03 05:37:41.176057: I tensorflow/core/util/port.cc:111] oneDNN custom operations are on. You may see slightly different numerical results due to floating-point round-off errors from different computation orders. To turn them off, set the environment variable `TF_ENABLE_ONEDNN_OPTS=0`.\n",
187-
"2024-03-03 05:37:41.179549: I tensorflow/tsl/cuda/cudart_stub.cc:28] Could not find cuda drivers on your machine, GPU will not be used.\n",
188-
"2024-03-03 05:37:41.221693: E tensorflow/compiler/xla/stream_executor/cuda/cuda_dnn.cc:9342] Unable to register cuDNN factory: Attempting to register factory for plugin cuDNN when one has already been registered\n",
189-
"2024-03-03 05:37:41.221725: E tensorflow/compiler/xla/stream_executor/cuda/cuda_fft.cc:609] Unable to register cuFFT factory: Attempting to register factory for plugin cuFFT when one has already been registered\n",
190-
"2024-03-03 05:37:41.221757: E tensorflow/compiler/xla/stream_executor/cuda/cuda_blas.cc:1518] Unable to register cuBLAS factory: Attempting to register factory for plugin cuBLAS when one has already been registered\n",
191-
"2024-03-03 05:37:41.231708: I tensorflow/tsl/cuda/cudart_stub.cc:28] Could not find cuda drivers on your machine, GPU will not be used.\n",
192-
"2024-03-03 05:37:41.233781: I tensorflow/core/platform/cpu_feature_guard.cc:182] This TensorFlow binary is optimized to use available CPU instructions in performance-critical operations.\n",
189+
"2024-03-06 07:05:19.617312: I tensorflow/core/util/port.cc:111] oneDNN custom operations are on. You may see slightly different numerical results due to floating-point round-off errors from different computation orders. To turn them off, set the environment variable `TF_ENABLE_ONEDNN_OPTS=0`.\n",
190+
"2024-03-06 07:05:19.620814: I tensorflow/tsl/cuda/cudart_stub.cc:28] Could not find cuda drivers on your machine, GPU will not be used.\n",
191+
"2024-03-06 07:05:19.663621: E tensorflow/compiler/xla/stream_executor/cuda/cuda_dnn.cc:9342] Unable to register cuDNN factory: Attempting to register factory for plugin cuDNN when one has already been registered\n",
192+
"2024-03-06 07:05:19.663653: E tensorflow/compiler/xla/stream_executor/cuda/cuda_fft.cc:609] Unable to register cuFFT factory: Attempting to register factory for plugin cuFFT when one has already been registered\n",
193+
"2024-03-06 07:05:19.663683: E tensorflow/compiler/xla/stream_executor/cuda/cuda_blas.cc:1518] Unable to register cuBLAS factory: Attempting to register factory for plugin cuBLAS when one has already been registered\n",
194+
"2024-03-06 07:05:19.671963: I tensorflow/tsl/cuda/cudart_stub.cc:28] Could not find cuda drivers on your machine, GPU will not be used.\n",
195+
"2024-03-06 07:05:19.673938: I tensorflow/core/platform/cpu_feature_guard.cc:182] This TensorFlow binary is optimized to use available CPU instructions in performance-critical operations.\n",
193196
"To enable the following instructions: AVX2 AVX512F AVX512_VNNI FMA, in other operations, rebuild TensorFlow with the appropriate compiler flags.\n",
194-
"2024-03-03 05:37:42.211339: W tensorflow/compiler/tf2tensorrt/utils/py_utils.cc:38] TF-TRT Warning: Could not find TensorRT\n"
197+
"2024-03-06 07:05:20.726709: W tensorflow/compiler/tf2tensorrt/utils/py_utils.cc:38] TF-TRT Warning: Could not find TensorRT\n"
195198
]
196199
}
197200
],
@@ -239,12 +242,12 @@
239242
{
240243
"data": {
241244
"application/vnd.jupyter.widget-view+json": {
242-
"model_id": "cdf2125cd615457790e51e1e48272035",
245+
"model_id": "5875d10008c442c38ff1d90da874b8dc",
243246
"version_major": 2,
244247
"version_minor": 0
245248
},
246249
"text/plain": [
247-
"Dropdown(description='LLM Model:', options=('tiny-llama-1b-chat', 'minicpm-2b-dpo', 'gemma-2b-it', 'red-pajama…"
250+
"Dropdown(description='Model Language:', options=('English', 'Chinese', 'Japanese'), value='English')"
248251
]
249252
},
250253
"execution_count": 2,
@@ -255,12 +258,47 @@
255258
"source": [
256259
"from config import SUPPORTED_EMBEDDING_MODELS, SUPPORTED_LLM_MODELS\n",
257260
"\n",
258-
"llm_model_id = list(SUPPORTED_LLM_MODELS)\n",
261+
"model_languages = list(SUPPORTED_LLM_MODELS)\n",
262+
"\n",
263+
"model_language = widgets.Dropdown(\n",
264+
" options=model_languages,\n",
265+
" value=model_languages[0],\n",
266+
" description=\"Model Language:\",\n",
267+
" disabled=False,\n",
268+
")\n",
269+
"\n",
270+
"model_language"
271+
]
272+
},
273+
{
274+
"cell_type": "code",
275+
"execution_count": 15,
276+
"id": "184d1678-0e73-4f35-8af5-1a7d291c2e6e",
277+
"metadata": {},
278+
"outputs": [
279+
{
280+
"data": {
281+
"application/vnd.jupyter.widget-view+json": {
282+
"model_id": "c8d393ddf227409d84313cde097d9896",
283+
"version_major": 2,
284+
"version_minor": 0
285+
},
286+
"text/plain": [
287+
"Dropdown(description='Model:', options=('tiny-llama-1b-chat', 'gemma-2b-it', 'red-pajama-3b-chat', 'gemma-7b-i…"
288+
]
289+
},
290+
"execution_count": 15,
291+
"metadata": {},
292+
"output_type": "execute_result"
293+
}
294+
],
295+
"source": [
296+
"llm_model_ids = list(SUPPORTED_LLM_MODELS[model_language.value])\n",
259297
"\n",
260298
"llm_model_id = widgets.Dropdown(\n",
261-
" options=llm_model_id,\n",
262-
" value=llm_model_id[0],\n",
263-
" description=\"LLM Model:\",\n",
299+
" options=llm_model_ids,\n",
300+
" value=llm_model_ids[0],\n",
301+
" description=\"Model:\",\n",
264302
" disabled=False,\n",
265303
")\n",
266304
"\n",
@@ -269,20 +307,20 @@
269307
},
270308
{
271309
"cell_type": "code",
272-
"execution_count": 3,
310+
"execution_count": 16,
273311
"id": "49ea95f8",
274312
"metadata": {},
275313
"outputs": [
276314
{
277315
"name": "stdout",
278316
"output_type": "stream",
279317
"text": [
280-
"Selected LLM model chatglm3-6b\n"
318+
"Selected LLM model tiny-llama-1b-chat\n"
281319
]
282320
}
283321
],
284322
"source": [
285-
"llm_model_configuration = SUPPORTED_LLM_MODELS[llm_model_id.value]\n",
323+
"llm_model_configuration = SUPPORTED_LLM_MODELS[model_language.value][llm_model_id.value]\n",
286324
"print(f\"Selected LLM model {llm_model_id.value}\")"
287325
]
288326
},
@@ -344,14 +382,14 @@
344382
},
345383
{
346384
"cell_type": "code",
347-
"execution_count": 4,
385+
"execution_count": 10,
348386
"id": "c6a38153",
349387
"metadata": {},
350388
"outputs": [
351389
{
352390
"data": {
353391
"application/vnd.jupyter.widget-view+json": {
354-
"model_id": "a75a56b8dcf14fcd83ac08e298311b1a",
392+
"model_id": "10a3596a41864effbe8fb9d81723f3ed",
355393
"version_major": 2,
356394
"version_minor": 0
357395
},
@@ -365,7 +403,7 @@
365403
{
366404
"data": {
367405
"application/vnd.jupyter.widget-view+json": {
368-
"model_id": "50d1d22c3d104f71aa7a8b323d829ea4",
406+
"model_id": "da04e6b87e41474194e2de8219da7303",
369407
"version_major": 2,
370408
"version_minor": 0
371409
},
@@ -379,7 +417,7 @@
379417
{
380418
"data": {
381419
"application/vnd.jupyter.widget-view+json": {
382-
"model_id": "9e44deed771a4bc0b1ee5fb96e5bc274",
420+
"model_id": "0532ba4230d440aeb3f10cd7becf9156",
383421
"version_major": 2,
384422
"version_minor": 0
385423
},
@@ -417,7 +455,7 @@
417455
},
418456
{
419457
"cell_type": "code",
420-
"execution_count": 6,
458+
"execution_count": 11,
421459
"id": "2020d522",
422460
"metadata": {},
423461
"outputs": [],
@@ -616,15 +654,15 @@
616654
},
617655
{
618656
"cell_type": "code",
619-
"execution_count": 7,
657+
"execution_count": 12,
620658
"id": "8e127215",
621659
"metadata": {},
622660
"outputs": [
623661
{
624662
"name": "stdout",
625663
"output_type": "stream",
626664
"text": [
627-
"Size of FP16 model is 11909.69 MB\n"
665+
"Size of model with INT4 compressed weights is 1837.58 MB\n"
628666
]
629667
}
630668
],
@@ -660,30 +698,30 @@
660698
},
661699
{
662700
"cell_type": "code",
663-
"execution_count": 8,
701+
"execution_count": 17,
664702
"id": "ff80e6eb-7923-40ef-93d8-5e6c56e50667",
665703
"metadata": {},
666704
"outputs": [
667705
{
668706
"data": {
669707
"application/vnd.jupyter.widget-view+json": {
670-
"model_id": "a1bef0be382747a68399e898afc00112",
708+
"model_id": "d7e6f5925ad0446ca94e882a8c6503fc",
671709
"version_major": 2,
672710
"version_minor": 0
673711
},
674712
"text/plain": [
675-
"Dropdown(description='Embedding Model:', options=('all-mpnet-base-v2', 'text2vec-large-chinese'), value='all-m…"
713+
"Dropdown(description='Embedding Model:', options=('all-mpnet-base-v2',), value='all-mpnet-base-v2')"
676714
]
677715
},
678-
"execution_count": 8,
716+
"execution_count": 17,
679717
"metadata": {},
680718
"output_type": "execute_result"
681719
}
682720
],
683721
"source": [
684722
"embedding_model_id = list(SUPPORTED_EMBEDDING_MODELS)\n",
685723
"\n",
686-
"if \"qwen\" not in llm_model_id.value and \"chatglm\" not in llm_model_id.value:\n",
724+
"if model_language.value != \"Chinese\":\n",
687725
" embedding_model_id = [x for x in embedding_model_id if \"chinese\" not in x]\n",
688726
"\n",
689727
"embedding_model_id = widgets.Dropdown(\n",
@@ -922,7 +960,7 @@
922960
"id": "e2610f4b",
923961
"metadata": {},
924962
"source": [
925-
"The cell below create `OVMPTModel`, `OVQWENModel` and `OVCHATGLM2Model` wrapper based on `OVModelForCausalLM` model."
963+
"The cell below create `OVMPTModel` and `OVCHATGLM2Model` wrapper based on `OVModelForCausalLM` model."
926964
]
927965
},
928966
{

0 commit comments

Comments
 (0)