Skip to content

Commit

Permalink
add internlm2 in LLM notebook (#1788)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
openvino-dev-samples authored Mar 7, 2024
1 parent f935d5c commit 7b51a15
Show file tree
Hide file tree
Showing 7 changed files with 770 additions and 405 deletions.
2 changes: 2 additions & 0 deletions .ci/spellcheck/.pyspelling.wordlist.txt
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,8 @@ instantiation
InstructGPT
InstructPix
intel
InternLM
internlm
invertible
intervaling
im
Expand Down
276 changes: 228 additions & 48 deletions notebooks/254-llm-chatbot/254-llm-chatbot.ipynb

Large diffs are not rendered by default.

102 changes: 70 additions & 32 deletions notebooks/254-llm-chatbot/254-rag-chatbot.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -156,14 +156,17 @@
" except OSError:\n",
" notebook_login()\n",
"```\n",
"* **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",
"* **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",
"* **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",
"* **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",
"* **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",
"* **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",
"* **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",
"* **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",
"* **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",
"* **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."
"* **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",
"* **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",
"* **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)."
]
},
{
Expand All @@ -183,15 +186,15 @@
"name": "stderr",
"output_type": "stream",
"text": [
"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",
"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",
"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",
"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",
"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",
"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",
"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",
"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",
"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",
"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",
"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",
"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",
"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",
"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",
"To enable the following instructions: AVX2 AVX512F AVX512_VNNI FMA, in other operations, rebuild TensorFlow with the appropriate compiler flags.\n",
"2024-03-03 05:37:42.211339: W tensorflow/compiler/tf2tensorrt/utils/py_utils.cc:38] TF-TRT Warning: Could not find TensorRT\n"
"2024-03-06 07:05:20.726709: W tensorflow/compiler/tf2tensorrt/utils/py_utils.cc:38] TF-TRT Warning: Could not find TensorRT\n"
]
}
],
Expand Down Expand Up @@ -239,12 +242,12 @@
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "cdf2125cd615457790e51e1e48272035",
"model_id": "5875d10008c442c38ff1d90da874b8dc",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"Dropdown(description='LLM Model:', options=('tiny-llama-1b-chat', 'minicpm-2b-dpo', 'gemma-2b-it', 'red-pajama…"
"Dropdown(description='Model Language:', options=('English', 'Chinese', 'Japanese'), value='English')"
]
},
"execution_count": 2,
Expand All @@ -255,12 +258,47 @@
"source": [
"from config import SUPPORTED_EMBEDDING_MODELS, SUPPORTED_LLM_MODELS\n",
"\n",
"llm_model_id = list(SUPPORTED_LLM_MODELS)\n",
"model_languages = list(SUPPORTED_LLM_MODELS)\n",
"\n",
"model_language = widgets.Dropdown(\n",
" options=model_languages,\n",
" value=model_languages[0],\n",
" description=\"Model Language:\",\n",
" disabled=False,\n",
")\n",
"\n",
"model_language"
]
},
{
"cell_type": "code",
"execution_count": 15,
"id": "184d1678-0e73-4f35-8af5-1a7d291c2e6e",
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "c8d393ddf227409d84313cde097d9896",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"Dropdown(description='Model:', options=('tiny-llama-1b-chat', 'gemma-2b-it', 'red-pajama-3b-chat', 'gemma-7b-i…"
]
},
"execution_count": 15,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"llm_model_ids = list(SUPPORTED_LLM_MODELS[model_language.value])\n",
"\n",
"llm_model_id = widgets.Dropdown(\n",
" options=llm_model_id,\n",
" value=llm_model_id[0],\n",
" description=\"LLM Model:\",\n",
" options=llm_model_ids,\n",
" value=llm_model_ids[0],\n",
" description=\"Model:\",\n",
" disabled=False,\n",
")\n",
"\n",
Expand All @@ -269,20 +307,20 @@
},
{
"cell_type": "code",
"execution_count": 3,
"execution_count": 16,
"id": "49ea95f8",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Selected LLM model chatglm3-6b\n"
"Selected LLM model tiny-llama-1b-chat\n"
]
}
],
"source": [
"llm_model_configuration = SUPPORTED_LLM_MODELS[llm_model_id.value]\n",
"llm_model_configuration = SUPPORTED_LLM_MODELS[model_language.value][llm_model_id.value]\n",
"print(f\"Selected LLM model {llm_model_id.value}\")"
]
},
Expand Down Expand Up @@ -344,14 +382,14 @@
},
{
"cell_type": "code",
"execution_count": 4,
"execution_count": 10,
"id": "c6a38153",
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "a75a56b8dcf14fcd83ac08e298311b1a",
"model_id": "10a3596a41864effbe8fb9d81723f3ed",
"version_major": 2,
"version_minor": 0
},
Expand All @@ -365,7 +403,7 @@
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "50d1d22c3d104f71aa7a8b323d829ea4",
"model_id": "da04e6b87e41474194e2de8219da7303",
"version_major": 2,
"version_minor": 0
},
Expand All @@ -379,7 +417,7 @@
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "9e44deed771a4bc0b1ee5fb96e5bc274",
"model_id": "0532ba4230d440aeb3f10cd7becf9156",
"version_major": 2,
"version_minor": 0
},
Expand Down Expand Up @@ -417,7 +455,7 @@
},
{
"cell_type": "code",
"execution_count": 6,
"execution_count": 11,
"id": "2020d522",
"metadata": {},
"outputs": [],
Expand Down Expand Up @@ -616,15 +654,15 @@
},
{
"cell_type": "code",
"execution_count": 7,
"execution_count": 12,
"id": "8e127215",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Size of FP16 model is 11909.69 MB\n"
"Size of model with INT4 compressed weights is 1837.58 MB\n"
]
}
],
Expand Down Expand Up @@ -660,30 +698,30 @@
},
{
"cell_type": "code",
"execution_count": 8,
"execution_count": 17,
"id": "ff80e6eb-7923-40ef-93d8-5e6c56e50667",
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "a1bef0be382747a68399e898afc00112",
"model_id": "d7e6f5925ad0446ca94e882a8c6503fc",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"Dropdown(description='Embedding Model:', options=('all-mpnet-base-v2', 'text2vec-large-chinese'), value='all-m…"
"Dropdown(description='Embedding Model:', options=('all-mpnet-base-v2',), value='all-mpnet-base-v2')"
]
},
"execution_count": 8,
"execution_count": 17,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"embedding_model_id = list(SUPPORTED_EMBEDDING_MODELS)\n",
"\n",
"if \"qwen\" not in llm_model_id.value and \"chatglm\" not in llm_model_id.value:\n",
"if model_language.value != \"Chinese\":\n",
" embedding_model_id = [x for x in embedding_model_id if \"chinese\" not in x]\n",
"\n",
"embedding_model_id = widgets.Dropdown(\n",
Expand Down Expand Up @@ -922,7 +960,7 @@
"id": "e2610f4b",
"metadata": {},
"source": [
"The cell below create `OVMPTModel`, `OVQWENModel` and `OVCHATGLM2Model` wrapper based on `OVModelForCausalLM` model."
"The cell below create `OVMPTModel` and `OVCHATGLM2Model` wrapper based on `OVModelForCausalLM` model."
]
},
{
Expand Down
Loading

0 comments on commit 7b51a15

Please sign in to comment.