Skip to content

Commit

Permalink
Move to experimental
Browse files Browse the repository at this point in the history
  • Loading branch information
krasserm committed Nov 17, 2023
1 parent 8988317 commit 7d1c7d2
Show file tree
Hide file tree
Showing 10 changed files with 148 additions and 86 deletions.
155 changes: 83 additions & 72 deletions docs/docs/integrations/chat/llama2_chat.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@
},
{
"cell_type": "code",
"execution_count": 2,
"execution_count": 1,
"id": "36c03540",
"metadata": {},
"outputs": [],
"source": [
"from langchain.chains import LLMChain\n",
"from langchain.chat_models import Llama2Chat\n",
"from langchain.memory import ConversationBufferMemory"
"from langchain.memory import ConversationBufferMemory\n",
"from langchain_experimental.chat_models import Llama2Chat"
]
},
{
Expand All @@ -34,7 +34,7 @@
},
{
"cell_type": "code",
"execution_count": 3,
"execution_count": 2,
"id": "9bbfaf3a",
"metadata": {},
"outputs": [],
Expand Down Expand Up @@ -154,7 +154,7 @@
"name": "stdout",
"output_type": "stream",
"text": [
" Certainly! Here are a few popular locations to consider visiting in Vienna:\n",
" Sure, I'd be happy to help! Here are a few popular locations to consider visiting in Vienna:\n",
"\n",
"1. Schönbrunn Palace\n",
"2. St. Stephen's Cathedral\n",
Expand All @@ -170,7 +170,11 @@
}
],
"source": [
"print(chain.run(text=\"What can I see in Vienna? Propose a few locations. Names only, no details.\"))"
"print(\n",
" chain.run(\n",
" text=\"What can I see in Vienna? Propose a few locations. Names only, no details.\"\n",
" )\n",
")"
]
},
{
Expand All @@ -183,19 +187,9 @@
"name": "stdout",
"output_type": "stream",
"text": [
" Sure! St. Stephen's Cathedral (Stephansdom) is a stunning Gothic cathedral located in the heart of Vienna. It's one of the city's most recognizable landmarks and a must-visit attraction for anyone interested in history, architecture, and religion.\n",
"\n",
"Here are some interesting facts about St. Stephen's Cathedral:\n",
"\n",
"1. Construction began in 1137 and took over 80 years to complete.\n",
"2. The cathedral features a unique blend of Gothic and Romanesque styles.\n",
"3. The south tower is 136 meters tall and offers breathtaking views of the city.\n",
"4. The cathedral's interior is adorned with intricate stone carvings, colorful stained glass windows, and impressive frescoes.\n",
"5. St. Stephen's Cathedral is the seat of the Archdiocese of Vienna and hosts many important religious events throughout the year.\n",
"6. The cathedral's crypt houses the tombs of many famous Viennese figures, including Mozart's family and several Austrian monarchs.\n",
"7. The cathedral's bell, known as the Pummerin, weighs over 20 tons and is one of the largest in Europe.\n",
" Certainly! St. Stephen's Cathedral (Stephansdom) is one of the most recognizable landmarks in Vienna and a must-see attraction for visitors. This stunning Gothic cathedral is located in the heart of the city and is known for its intricate stone carvings, colorful stained glass windows, and impressive dome.\n",
"\n",
"Visitors can take a guided tour of the cathedral, climb up the south tower for panoramic views, or simply sit in the pews and admire the beauty of the building. Whether you're interested in history, architecture, or religion, St. Stephen's Cathedral is an unmissable attraction in Vienna.\n"
"The cathedral was built in the 12th century and has been the site of many important events throughout history, including the coronation of Holy Roman emperors and the funeral of Mozart. Today, it is still an active place of worship and offers guided tours, concerts, and special events. Visitors can climb up the south tower for panoramic views of the city or attend a service to experience the beautiful music and chanting.\n"
]
}
],
Expand Down Expand Up @@ -231,7 +225,7 @@
"name": "stderr",
"output_type": "stream",
"text": [
"llama_model_loader: loaded meta data with 19 key-value pairs and 291 tensors from /home/martin/Models/llama-2-7b-chat.Q4_0.gguf (version GGUF V2 (latest))\n",
"llama_model_loader: loaded meta data with 19 key-value pairs and 291 tensors from /home/martin/Models/llama-2-7b-chat.Q4_0.gguf (version GGUF V2)\n",
"llama_model_loader: - tensor 0: token_embd.weight q4_0 [ 4096, 32000, 1, 1 ]\n",
"llama_model_loader: - tensor 1: blk.0.attn_norm.weight f32 [ 4096, 1, 1, 1 ]\n",
"llama_model_loader: - tensor 2: blk.0.ffn_down.weight q4_0 [ 11008, 4096, 1, 1 ]\n",
Expand Down Expand Up @@ -545,48 +539,62 @@
"llama_model_loader: - type f32: 65 tensors\n",
"llama_model_loader: - type q4_0: 225 tensors\n",
"llama_model_loader: - type q6_K: 1 tensors\n",
"llm_load_print_meta: format = GGUF V2 (latest)\n",
"llm_load_print_meta: arch = llama\n",
"llm_load_print_meta: vocab type = SPM\n",
"llm_load_print_meta: n_vocab = 32000\n",
"llm_load_print_meta: n_merges = 0\n",
"llm_load_print_meta: n_ctx_train = 4096\n",
"llm_load_print_meta: n_ctx = 512\n",
"llm_load_print_meta: n_embd = 4096\n",
"llm_load_print_meta: n_head = 32\n",
"llm_load_print_meta: n_head_kv = 32\n",
"llm_load_print_meta: n_layer = 32\n",
"llm_load_print_meta: n_rot = 128\n",
"llm_load_print_meta: n_gqa = 1\n",
"llm_load_print_meta: f_norm_eps = 1.0e-05\n",
"llm_load_print_meta: f_norm_rms_eps = 1.0e-06\n",
"llm_load_print_meta: n_ff = 11008\n",
"llm_load_print_meta: freq_base = 10000.0\n",
"llm_load_print_meta: freq_scale = 1\n",
"llm_load_print_meta: model type = 7B\n",
"llm_load_print_meta: model ftype = mostly Q4_0\n",
"llm_load_print_meta: model size = 6.74 B\n",
"llm_load_vocab: special tokens definition check successful ( 259/32000 ).\n",
"llm_load_print_meta: format = GGUF V2\n",
"llm_load_print_meta: arch = llama\n",
"llm_load_print_meta: vocab type = SPM\n",
"llm_load_print_meta: n_vocab = 32000\n",
"llm_load_print_meta: n_merges = 0\n",
"llm_load_print_meta: n_ctx_train = 4096\n",
"llm_load_print_meta: n_embd = 4096\n",
"llm_load_print_meta: n_head = 32\n",
"llm_load_print_meta: n_head_kv = 32\n",
"llm_load_print_meta: n_layer = 32\n",
"llm_load_print_meta: n_rot = 128\n",
"llm_load_print_meta: n_gqa = 1\n",
"llm_load_print_meta: f_norm_eps = 0.0e+00\n",
"llm_load_print_meta: f_norm_rms_eps = 1.0e-06\n",
"llm_load_print_meta: f_clamp_kqv = 0.0e+00\n",
"llm_load_print_meta: f_max_alibi_bias = 0.0e+00\n",
"llm_load_print_meta: n_ff = 11008\n",
"llm_load_print_meta: rope scaling = linear\n",
"llm_load_print_meta: freq_base_train = 10000.0\n",
"llm_load_print_meta: freq_scale_train = 1\n",
"llm_load_print_meta: n_yarn_orig_ctx = 4096\n",
"llm_load_print_meta: rope_finetuned = unknown\n",
"llm_load_print_meta: model type = 7B\n",
"llm_load_print_meta: model ftype = mostly Q4_0\n",
"llm_load_print_meta: model params = 6.74 B\n",
"llm_load_print_meta: model size = 3.56 GiB (4.54 BPW) \n",
"llm_load_print_meta: general.name = LLaMA v2\n",
"llm_load_print_meta: BOS token = 1 '<s>'\n",
"llm_load_print_meta: EOS token = 2 '</s>'\n",
"llm_load_print_meta: UNK token = 0 '<unk>'\n",
"llm_load_print_meta: LF token = 13 '<0x0A>'\n",
"llm_load_tensors: ggml ctx size = 0.09 MB\n",
"llm_load_tensors: mem required = 3647.96 MB (+ 256.00 MB per state)\n",
"llm_load_tensors: ggml ctx size = 0.11 MB\n",
"llm_load_tensors: mem required = 3647.97 MB\n",
"..................................................................................................\n",
"llama_new_context_with_model: n_ctx = 512\n",
"llama_new_context_with_model: freq_base = 10000.0\n",
"llama_new_context_with_model: freq_scale = 1\n",
"llama_new_context_with_model: kv self size = 256.00 MB\n",
"llama_new_context_with_model: compute buffer total size = 71.97 MB\n",
"AVX = 1 | AVX2 = 1 | AVX512 = 0 | AVX512_VBMI = 0 | AVX512_VNNI = 0 | FMA = 1 | NEON = 0 | ARM_FMA = 0 | F16C = 1 | FP16_VA = 0 | WASM_SIMD = 0 | BLAS = 0 | SSE3 = 1 | SSSE3 = 1 | VSX = 0 | \n"
"llama_build_graph: non-view tensors processed: 740/740\n",
"llama_new_context_with_model: compute buffer total size = 2.66 MB\n",
"AVX = 1 | AVX2 = 1 | AVX512 = 1 | AVX512_VBMI = 0 | AVX512_VNNI = 1 | FMA = 1 | NEON = 0 | ARM_FMA = 0 | F16C = 1 | FP16_VA = 0 | WASM_SIMD = 0 | BLAS = 0 | SSE3 = 1 | SSSE3 = 1 | VSX = 0 | \n"
]
}
],
"source": [
"from os.path import expanduser\n",
"\n",
"from langchain.llms import LlamaCpp\n",
"\n",
"model_path = expanduser(\"~/Models/llama-2-7b-chat.Q4_0.gguf\")\n",
"\n",
"llm = LlamaCpp(model_path=model_path, streaming=False,)\n",
"llm = LlamaCpp(\n",
" model_path=model_path,\n",
" streaming=False,\n",
")\n",
"model = Llama2Chat(llm=llm)"
]
},
Expand Down Expand Up @@ -619,34 +627,40 @@
"name": "stdout",
"output_type": "stream",
"text": [
" Of course! Vienna is a beautiful city with a rich history and culture. Here are some must-see locations to consider:\n",
" Of course! Vienna is a beautiful city with a rich history and culture. Here are some of the top tourist attractions you might want to consider visiting:\n",
"1. Schönbrunn Palace\n",
"2. St. Stephen's Cathedral\n",
"3. Hofburg Palace\n",
"4. Belvedere Palace\n",
"5. MuseumsQuartier\n",
"6. Prater Park\n",
"7. Vienna State Opera\n",
"8. Burgtheater\n",
"9. Albertina Museum\n",
"10. Vienna Woods (Nussbaumer Forst)\n"
"5. Prater Park\n",
"6. MuseumsQuartier\n",
"7. Ringstrasse\n",
"8. Vienna State Opera\n",
"9. Kunsthistorisches Museum\n",
"10. Imperial Palace\n",
"\n",
"These are just a few of the many amazing places to see in Vienna. Each one has its own unique history and charm, so I hope you enjoy exploring this beautiful city!\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"\n",
"llama_print_timings: load time = 289.55 ms\n",
"llama_print_timings: sample time = 40.63 ms / 104 runs ( 0.39 ms per token, 2559.50 tokens per second)\n",
"llama_print_timings: prompt eval time = 1587.24 ms / 48 tokens ( 33.07 ms per token, 30.24 tokens per second)\n",
"llama_print_timings: eval time = 6392.08 ms / 103 runs ( 62.06 ms per token, 16.11 tokens per second)\n",
"llama_print_timings: total time = 8245.60 ms\n"
"llama_print_timings: load time = 250.46 ms\n",
"llama_print_timings: sample time = 56.40 ms / 144 runs ( 0.39 ms per token, 2553.37 tokens per second)\n",
"llama_print_timings: prompt eval time = 1444.25 ms / 47 tokens ( 30.73 ms per token, 32.54 tokens per second)\n",
"llama_print_timings: eval time = 8832.02 ms / 143 runs ( 61.76 ms per token, 16.19 tokens per second)\n",
"llama_print_timings: total time = 10645.94 ms\n"
]
}
],
"source": [
"print(chain.run(text=\"What can I see in Vienna? Propose a few locations. Names only, no details.\"))"
"print(\n",
" chain.run(\n",
" text=\"What can I see in Vienna? Propose a few locations. Names only, no details.\"\n",
" )\n",
")"
]
},
{
Expand All @@ -666,26 +680,23 @@
"name": "stdout",
"output_type": "stream",
"text": [
" Of course! St. Stephen's Cathedral, also known as Stephansdom, is a must-see attraction in Vienna. It is a beautiful Gothic church located in the heart of the city, on Stephansplatz. The cathedral was founded in the 12th century and has been a symbol of Vienna ever since.\n",
"Some of the notable features of St. Stephen's Cathedral include:\n",
"* Its impressive height, with a tower that reaches 137 meters (450 feet)\n",
"* The colorful tile roof, which is made up of more than 250,000 tiles and features intricate designs\n",
"* The stunning stained glass windows, which depict scenes from the Bible and Austrian history\n",
"* The marble altars and statues, including a famous statue of Mary Magdalene by sculptor Johann Georg von Hagen\n",
"* The fascinating history, including its role as a place of worship, a symbol of Vienna's power and influence, and a site of important historical events such as coronations and funerals.\n",
"Visitors can take a guided tour of the cathedral, climb to the top of the South Tower for\n"
" Of course! St. Stephen's Cathedral (also known as Stephansdom) is a stunning Gothic-style cathedral located in the heart of Vienna, Austria. It is one of the most recognizable landmarks in the city and is considered a symbol of Vienna.\n",
"Here are some interesting facts about St. Stephen's Cathedral:\n",
"1. History: The construction of St. Stephen's Cathedral began in the 12th century on the site of a former Romanesque church, and it took over 600 years to complete. The cathedral has been renovated and expanded several times throughout its history, with the most significant renovation taking place in the 19th century.\n",
"2. Architecture: St. Stephen's Cathedral is built in the Gothic style, characterized by its tall spires, pointed arches, and intricate stone carvings. The cathedral features a mix of Romanesque, Gothic, and Baroque elements, making it a unique blend of styles.\n",
"3. Design: The cathedral's design is based on the plan of a cross with a long nave and two shorter arms extending from it. The main altar is\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"\n",
"llama_print_timings: load time = 289.55 ms\n",
"llama_print_timings: sample time = 97.02 ms / 256 runs ( 0.38 ms per token, 2638.55 tokens per second)\n",
"llama_print_timings: prompt eval time = 3956.20 ms / 120 tokens ( 32.97 ms per token, 30.33 tokens per second)\n",
"llama_print_timings: eval time = 16141.25 ms / 256 runs ( 63.05 ms per token, 15.86 tokens per second)\n",
"llama_print_timings: total time = 20754.33 ms\n"
"llama_print_timings: load time = 250.46 ms\n",
"llama_print_timings: sample time = 100.60 ms / 256 runs ( 0.39 ms per token, 2544.73 tokens per second)\n",
"llama_print_timings: prompt eval time = 5128.71 ms / 160 tokens ( 32.05 ms per token, 31.20 tokens per second)\n",
"llama_print_timings: eval time = 16193.02 ms / 255 runs ( 63.50 ms per token, 15.75 tokens per second)\n",
"llama_print_timings: total time = 21988.57 ms\n"
]
}
],
Expand All @@ -710,7 +721,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.16"
"version": "3.9.18"
}
},
"nbformat": 4,
Expand Down
26 changes: 26 additions & 0 deletions libs/experimental/langchain_experimental/chat_models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
"""**Chat Models** are a variation on language models.
While Chat Models use language models under the hood, the interface they expose
is a bit different. Rather than expose a "text in, text out" API, they expose
an interface where "chat messages" are the inputs and outputs.
**Class hierarchy:**
.. code-block::
BaseLanguageModel --> BaseChatModel --> <name> # Examples: ChatOpenAI, ChatGooglePalm
**Main helpers:**
.. code-block::
AIMessage, BaseMessage, HumanMessage
""" # noqa: E501

from langchain_experimental.chat_models.llm_wrapper import Llama2Chat, Orca, Vicuna

__all__ = [
"Llama2Chat",
"Orca",
"Vicuna",
]
Loading

0 comments on commit 7d1c7d2

Please sign in to comment.