mirror of
https://github.com/hwchase17/langchain
synced 2024-11-08 07:10:35 +00:00
Add instructions for GGUF (#9874)
llama.cpp migrated to GGUF model format, and new releases (e.g., [here](https://huggingface.co/TheBloke)) now use GGUF.
This commit is contained in:
parent
eb3d1fa93c
commit
8393ba9dab
@ -7,9 +7,20 @@
|
|||||||
"# Llama.cpp\n",
|
"# Llama.cpp\n",
|
||||||
"\n",
|
"\n",
|
||||||
"[llama-cpp-python](https://github.com/abetlen/llama-cpp-python) is a Python binding for [llama.cpp](https://github.com/ggerganov/llama.cpp). \n",
|
"[llama-cpp-python](https://github.com/abetlen/llama-cpp-python) is a Python binding for [llama.cpp](https://github.com/ggerganov/llama.cpp). \n",
|
||||||
"It supports [several LLMs](https://github.com/ggerganov/llama.cpp).\n",
|
|
||||||
"\n",
|
"\n",
|
||||||
"This notebook goes over how to run `llama-cpp-python` within LangChain."
|
"It supports inference for [many LLMs](https://github.com/ggerganov/llama.cpp), which can be accessed on [HuggingFace](https://huggingface.co/TheBloke).\n",
|
||||||
|
"\n",
|
||||||
|
"This notebook goes over how to run `llama-cpp-python` within LangChain.\n",
|
||||||
|
"\n",
|
||||||
|
"**Note: new versions of `llama-cpp-python` use GGUF model files (see [here](https://github.com/abetlen/llama-cpp-python/pull/633)).**\n",
|
||||||
|
"\n",
|
||||||
|
"This is a breaking change.\n",
|
||||||
|
" \n",
|
||||||
|
"To convert existing GGML models to GGUF you can run the following in [llama.cpp](https://github.com/ggerganov/llama.cpp):\n",
|
||||||
|
"\n",
|
||||||
|
"```\n",
|
||||||
|
"python ./convert-llama-ggmlv3-to-gguf.py --eps 1e-5 --input models/openorca-platypus2-13b.ggmlv3.q4_0.bin --output models/openorca-platypus2-13b.gguf.q4_0.bin\n",
|
||||||
|
"```"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -19,7 +30,7 @@
|
|||||||
"## Installation\n",
|
"## Installation\n",
|
||||||
"\n",
|
"\n",
|
||||||
"There are different options on how to install the llama-cpp package: \n",
|
"There are different options on how to install the llama-cpp package: \n",
|
||||||
"- only CPU usage\n",
|
"- CPU usage\n",
|
||||||
"- CPU + GPU (using one of many BLAS backends)\n",
|
"- CPU + GPU (using one of many BLAS backends)\n",
|
||||||
"- Metal GPU (MacOS with Apple Silicon Chip) \n",
|
"- Metal GPU (MacOS with Apple Silicon Chip) \n",
|
||||||
"\n",
|
"\n",
|
||||||
@ -171,7 +182,7 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": 1,
|
"execution_count": 3,
|
||||||
"metadata": {
|
"metadata": {
|
||||||
"tags": []
|
"tags": []
|
||||||
},
|
},
|
||||||
@ -207,15 +218,14 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": 3,
|
"execution_count": 4,
|
||||||
"metadata": {
|
"metadata": {
|
||||||
"tags": []
|
"tags": []
|
||||||
},
|
},
|
||||||
"outputs": [],
|
"outputs": [],
|
||||||
"source": [
|
"source": [
|
||||||
"# Callbacks support token-wise streaming\n",
|
"# Callbacks support token-wise streaming\n",
|
||||||
"callback_manager = CallbackManager([StreamingStdOutCallbackHandler()])\n",
|
"callback_manager = CallbackManager([StreamingStdOutCallbackHandler()])"
|
||||||
"# Verbose is required to pass to the callback manager"
|
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -240,12 +250,12 @@
|
|||||||
"source": [
|
"source": [
|
||||||
"# Make sure the model path is correct for your system!\n",
|
"# Make sure the model path is correct for your system!\n",
|
||||||
"llm = LlamaCpp(\n",
|
"llm = LlamaCpp(\n",
|
||||||
" model_path=\"/Users/rlm/Desktop/Code/llama/llama-2-7b-ggml/llama-2-7b-chat.ggmlv3.q4_0.bin\",\n",
|
" model_path=\"/Users/rlm/Desktop/Code/llama.cpp/models/openorca-platypus2-13b.gguf.q4_0.bin\",\n",
|
||||||
" temperature=0.75,\n",
|
" temperature=0.75,\n",
|
||||||
" max_tokens=2000,\n",
|
" max_tokens=2000,\n",
|
||||||
" top_p=1,\n",
|
" top_p=1,\n",
|
||||||
" callback_manager=callback_manager,\n",
|
" callback_manager=callback_manager, \n",
|
||||||
" verbose=True,\n",
|
" verbose=True, # Verbose is required to pass to the callback manager\n",
|
||||||
")"
|
")"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
@ -375,7 +385,6 @@
|
|||||||
],
|
],
|
||||||
"source": [
|
"source": [
|
||||||
"question = \"What NFL team won the Super Bowl in the year Justin Bieber was born?\"\n",
|
"question = \"What NFL team won the Super Bowl in the year Justin Bieber was born?\"\n",
|
||||||
"\n",
|
|
||||||
"llm_chain.run(question)"
|
"llm_chain.run(question)"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
@ -397,100 +406,20 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": 4,
|
"execution_count": null,
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
"outputs": [
|
"outputs": [],
|
||||||
{
|
|
||||||
"name": "stderr",
|
|
||||||
"output_type": "stream",
|
|
||||||
"text": [
|
|
||||||
"llama.cpp: loading model from /Users/rlm/Desktop/Code/llama.cpp/llama-2-13b-chat.ggmlv3.q4_0.bin\n",
|
|
||||||
"llama_model_load_internal: format = ggjt v3 (latest)\n",
|
|
||||||
"llama_model_load_internal: n_vocab = 32000\n",
|
|
||||||
"llama_model_load_internal: n_ctx = 512\n",
|
|
||||||
"llama_model_load_internal: n_embd = 5120\n",
|
|
||||||
"llama_model_load_internal: n_mult = 256\n",
|
|
||||||
"llama_model_load_internal: n_head = 40\n",
|
|
||||||
"llama_model_load_internal: n_head_kv = 40\n",
|
|
||||||
"llama_model_load_internal: n_layer = 40\n",
|
|
||||||
"llama_model_load_internal: n_rot = 128\n",
|
|
||||||
"llama_model_load_internal: n_gqa = 1\n",
|
|
||||||
"llama_model_load_internal: rnorm_eps = 5.0e-06\n",
|
|
||||||
"llama_model_load_internal: n_ff = 13824\n",
|
|
||||||
"llama_model_load_internal: freq_base = 10000.0\n",
|
|
||||||
"llama_model_load_internal: freq_scale = 1\n",
|
|
||||||
"llama_model_load_internal: ftype = 2 (mostly Q4_0)\n",
|
|
||||||
"llama_model_load_internal: model size = 13B\n",
|
|
||||||
"llama_model_load_internal: ggml ctx size = 0.11 MB\n",
|
|
||||||
"llama_model_load_internal: mem required = 6983.72 MB (+ 400.00 MB per state)\n",
|
|
||||||
"llama_new_context_with_model: kv self size = 400.00 MB\n",
|
|
||||||
"ggml_metal_init: allocating\n",
|
|
||||||
"ggml_metal_init: loading '/Users/rlm/miniforge3/envs/llama2/lib/python3.9/site-packages/llama_cpp/ggml-metal.metal'\n",
|
|
||||||
"ggml_metal_init: loaded kernel_add 0x1405ed6b0\n",
|
|
||||||
"ggml_metal_init: loaded kernel_add_row 0x1405eee00\n",
|
|
||||||
"ggml_metal_init: loaded kernel_mul 0x1405ee650\n",
|
|
||||||
"ggml_metal_init: loaded kernel_mul_row 0x1405eda20\n",
|
|
||||||
"ggml_metal_init: loaded kernel_scale 0x121fc1d80\n",
|
|
||||||
"ggml_metal_init: loaded kernel_silu 0x121fc1fe0\n",
|
|
||||||
"ggml_metal_init: loaded kernel_relu 0x121fc2240\n",
|
|
||||||
"ggml_metal_init: loaded kernel_gelu 0x121fc24e0\n",
|
|
||||||
"ggml_metal_init: loaded kernel_soft_max 0x121fc2950\n",
|
|
||||||
"ggml_metal_init: loaded kernel_diag_mask_inf 0x121fc2d60\n",
|
|
||||||
"ggml_metal_init: loaded kernel_get_rows_f16 0x121fc3160\n",
|
|
||||||
"ggml_metal_init: loaded kernel_get_rows_q4_0 0x121fc3a20\n",
|
|
||||||
"ggml_metal_init: loaded kernel_get_rows_q4_1 0x121fc4170\n",
|
|
||||||
"ggml_metal_init: loaded kernel_get_rows_q2_K 0x121fc4890\n",
|
|
||||||
"ggml_metal_init: loaded kernel_get_rows_q3_K 0x121fc5010\n",
|
|
||||||
"ggml_metal_init: loaded kernel_get_rows_q4_K 0x121fc5750\n",
|
|
||||||
"ggml_metal_init: loaded kernel_get_rows_q5_K 0x121fc5e90\n",
|
|
||||||
"ggml_metal_init: loaded kernel_get_rows_q6_K 0x121fc65d0\n",
|
|
||||||
"ggml_metal_init: loaded kernel_rms_norm 0x121fc6d20\n",
|
|
||||||
"ggml_metal_init: loaded kernel_norm 0x121fc7460\n",
|
|
||||||
"ggml_metal_init: loaded kernel_mul_mat_f16_f32 0x121fc7dd0\n",
|
|
||||||
"ggml_metal_init: loaded kernel_mul_mat_q4_0_f32 0x121fc8610\n",
|
|
||||||
"ggml_metal_init: loaded kernel_mul_mat_q4_1_f32 0x121fc8e50\n",
|
|
||||||
"ggml_metal_init: loaded kernel_mul_mat_q2_K_f32 0x1405edc80\n",
|
|
||||||
"ggml_metal_init: loaded kernel_mul_mat_q3_K_f32 0x1405efdc0\n",
|
|
||||||
"ggml_metal_init: loaded kernel_mul_mat_q4_K_f32 0x140306f30\n",
|
|
||||||
"ggml_metal_init: loaded kernel_mul_mat_q5_K_f32 0x1403073d0\n",
|
|
||||||
"ggml_metal_init: loaded kernel_mul_mat_q6_K_f32 0x140307aa0\n",
|
|
||||||
"ggml_metal_init: loaded kernel_mul_mm_f16_f32 0x140307f80\n",
|
|
||||||
"ggml_metal_init: loaded kernel_mul_mm_q4_0_f32 0x140308460\n",
|
|
||||||
"ggml_metal_init: loaded kernel_mul_mm_q4_1_f32 0x140308940\n",
|
|
||||||
"ggml_metal_init: loaded kernel_mul_mm_q2_K_f32 0x140308e20\n",
|
|
||||||
"ggml_metal_init: loaded kernel_mul_mm_q3_K_f32 0x140309300\n",
|
|
||||||
"ggml_metal_init: loaded kernel_mul_mm_q4_K_f32 0x1403097e0\n",
|
|
||||||
"ggml_metal_init: loaded kernel_mul_mm_q5_K_f32 0x140309cc0\n",
|
|
||||||
"ggml_metal_init: loaded kernel_mul_mm_q6_K_f32 0x14030a1a0\n",
|
|
||||||
"ggml_metal_init: loaded kernel_rope 0x14030a400\n",
|
|
||||||
"ggml_metal_init: loaded kernel_alibi_f32 0x14030aa00\n",
|
|
||||||
"ggml_metal_init: loaded kernel_cpy_f32_f16 0x14030afd0\n",
|
|
||||||
"ggml_metal_init: loaded kernel_cpy_f32_f32 0x14030b5a0\n",
|
|
||||||
"ggml_metal_init: loaded kernel_cpy_f16_f16 0x14030bb70\n",
|
|
||||||
"ggml_metal_init: recommendedMaxWorkingSetSize = 21845.34 MB\n",
|
|
||||||
"ggml_metal_init: hasUnifiedMemory = true\n",
|
|
||||||
"ggml_metal_init: maxTransferRate = built-in GPU\n",
|
|
||||||
"llama_new_context_with_model: compute buffer total size = 91.35 MB\n",
|
|
||||||
"llama_new_context_with_model: max tensor size = 87.89 MB\n",
|
|
||||||
"ggml_metal_add_buffer: allocated 'data ' buffer, size = 6984.06 MB, ( 6984.50 / 21845.34)\n",
|
|
||||||
"ggml_metal_add_buffer: allocated 'eval ' buffer, size = 1.36 MB, ( 6985.86 / 21845.34)\n",
|
|
||||||
"ggml_metal_add_buffer: allocated 'kv ' buffer, size = 402.00 MB, ( 7387.86 / 21845.34)\n",
|
|
||||||
"ggml_metal_add_buffer: allocated 'alloc ' buffer, size = 90.02 MB, ( 7477.88 / 21845.34)\n",
|
|
||||||
"AVX = 0 | AVX2 = 0 | AVX512 = 0 | AVX512_VBMI = 0 | AVX512_VNNI = 0 | FMA = 0 | NEON = 1 | ARM_FMA = 1 | F16C = 0 | FP16_VA = 1 | WASM_SIMD = 0 | BLAS = 1 | SSE3 = 0 | VSX = 0 | \n"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"source": [
|
"source": [
|
||||||
"n_gpu_layers = 40 # Change this value based on your model and your GPU VRAM pool.\n",
|
"n_gpu_layers = 40 # Change this value based on your model and your GPU VRAM pool.\n",
|
||||||
"n_batch = 512 # Should be between 1 and n_ctx, consider the amount of VRAM in your GPU.\n",
|
"n_batch = 512 # Should be between 1 and n_ctx, consider the amount of VRAM in your GPU.\n",
|
||||||
"\n",
|
"\n",
|
||||||
"# Make sure the model path is correct for your system!\n",
|
"# Make sure the model path is correct for your system!\n",
|
||||||
"llm = LlamaCpp(\n",
|
"llm = LlamaCpp(\n",
|
||||||
" model_path=\"/Users/rlm/Desktop/Code/llama.cpp/llama-2-13b-chat.ggmlv3.q4_0.bin\",\n",
|
" model_path=\"/Users/rlm/Desktop/Code/llama.cpp/models/openorca-platypus2-13b.gguf.q4_0.bin\",\n",
|
||||||
" n_gpu_layers=n_gpu_layers,\n",
|
" n_gpu_layers=n_gpu_layers,\n",
|
||||||
" n_batch=n_batch,\n",
|
" n_batch=n_batch,\n",
|
||||||
" callback_manager=callback_manager,\n",
|
" callback_manager=callback_manager,\n",
|
||||||
" verbose=True,\n",
|
" verbose=True, # Verbose is required to pass to the callback manager\n",
|
||||||
")"
|
")"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
@ -505,11 +434,13 @@
|
|||||||
"text": [
|
"text": [
|
||||||
"\n",
|
"\n",
|
||||||
"\n",
|
"\n",
|
||||||
"Justin Bieber was born on March 1, 1994. The Super Bowl is played at the end of the NFL season which runs from September to February.\n",
|
"1. Identify Justin Bieber's birth date: Justin Bieber was born on March 1, 1994.\n",
|
||||||
"\n",
|
"\n",
|
||||||
"In 1994, the NFL season ended with Super Bowl XXVIII which was played on January 28th, 1994.\n",
|
"2. Find the Super Bowl winner of that year: The NFL season of 1993 with the Super Bowl being played in January or of 1994.\n",
|
||||||
"\n",
|
"\n",
|
||||||
"So, there was no Super Bowl in the year Justin Bieber was born. The Super Bowl has only been around since 1967 and is played annually between the champions of the National Football Conference (NFC) and the American Football Conference (AFC)."
|
"3. Determine which team won the game: The Dallas Cowboys faced the Buffalo Bills in Super Bowl XXVII on January 31, 1993 (as the year is mis-labelled due to a error). The Dallas Cowboys won this matchup.\n",
|
||||||
|
"\n",
|
||||||
|
"So, Justin Bieber was born when the Dallas Cowboys were the reigning NFL Super Bowl."
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -517,17 +448,17 @@
|
|||||||
"output_type": "stream",
|
"output_type": "stream",
|
||||||
"text": [
|
"text": [
|
||||||
"\n",
|
"\n",
|
||||||
"llama_print_timings: load time = 427.90 ms\n",
|
"llama_print_timings: load time = 427.63 ms\n",
|
||||||
"llama_print_timings: sample time = 98.36 ms / 133 runs ( 0.74 ms per token, 1352.18 tokens per second)\n",
|
"llama_print_timings: sample time = 115.85 ms / 164 runs ( 0.71 ms per token, 1415.67 tokens per second)\n",
|
||||||
"llama_print_timings: prompt eval time = 427.83 ms / 45 tokens ( 9.51 ms per token, 105.18 tokens per second)\n",
|
"llama_print_timings: prompt eval time = 427.53 ms / 45 tokens ( 9.50 ms per token, 105.26 tokens per second)\n",
|
||||||
"llama_print_timings: eval time = 3687.12 ms / 132 runs ( 27.93 ms per token, 35.80 tokens per second)\n",
|
"llama_print_timings: eval time = 4526.53 ms / 163 runs ( 27.77 ms per token, 36.01 tokens per second)\n",
|
||||||
"llama_print_timings: total time = 4401.84 ms\n"
|
"llama_print_timings: total time = 5293.77 ms\n"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"data": {
|
"data": {
|
||||||
"text/plain": [
|
"text/plain": [
|
||||||
"'\\n\\nJustin Bieber was born on March 1, 1994. The Super Bowl is played at the end of the NFL season which runs from September to February.\\n\\nIn 1994, the NFL season ended with Super Bowl XXVIII which was played on January 28th, 1994.\\n\\nSo, there was no Super Bowl in the year Justin Bieber was born. The Super Bowl has only been around since 1967 and is played annually between the champions of the National Football Conference (NFC) and the American Football Conference (AFC).'"
|
"\"\\n\\n1. Identify Justin Bieber's birth date: Justin Bieber was born on March 1, 1994.\\n\\n2. Find the Super Bowl winner of that year: The NFL season of 1993 with the Super Bowl being played in January or of 1994.\\n\\n3. Determine which team won the game: The Dallas Cowboys faced the Buffalo Bills in Super Bowl XXVII on January 31, 1993 (as the year is mis-labelled due to a error). The Dallas Cowboys won this matchup.\\n\\nSo, Justin Bieber was born when the Dallas Cowboys were the reigning NFL Super Bowl.\""
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"execution_count": 5,
|
"execution_count": 5,
|
||||||
@ -537,9 +468,7 @@
|
|||||||
],
|
],
|
||||||
"source": [
|
"source": [
|
||||||
"llm_chain = LLMChain(prompt=prompt, llm=llm)\n",
|
"llm_chain = LLMChain(prompt=prompt, llm=llm)\n",
|
||||||
"\n",
|
|
||||||
"question = \"What NFL team won the Super Bowl in the year Justin Bieber was born?\"\n",
|
"question = \"What NFL team won the Super Bowl in the year Justin Bieber was born?\"\n",
|
||||||
"\n",
|
|
||||||
"llm_chain.run(question)"
|
"llm_chain.run(question)"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
@ -563,101 +492,20 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": 4,
|
"execution_count": null,
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
"outputs": [
|
"outputs": [],
|
||||||
{
|
|
||||||
"name": "stderr",
|
|
||||||
"output_type": "stream",
|
|
||||||
"text": [
|
|
||||||
"llama.cpp: loading model from /Users/rlm/Desktop/Code/llama.cpp/llama-2-13b-chat.ggmlv3.q4_0.bin\n",
|
|
||||||
"llama_model_load_internal: format = ggjt v3 (latest)\n",
|
|
||||||
"llama_model_load_internal: n_vocab = 32000\n",
|
|
||||||
"llama_model_load_internal: n_ctx = 512\n",
|
|
||||||
"llama_model_load_internal: n_embd = 5120\n",
|
|
||||||
"llama_model_load_internal: n_mult = 256\n",
|
|
||||||
"llama_model_load_internal: n_head = 40\n",
|
|
||||||
"llama_model_load_internal: n_head_kv = 40\n",
|
|
||||||
"llama_model_load_internal: n_layer = 40\n",
|
|
||||||
"llama_model_load_internal: n_rot = 128\n",
|
|
||||||
"llama_model_load_internal: n_gqa = 1\n",
|
|
||||||
"llama_model_load_internal: rnorm_eps = 5.0e-06\n",
|
|
||||||
"llama_model_load_internal: n_ff = 13824\n",
|
|
||||||
"llama_model_load_internal: freq_base = 10000.0\n",
|
|
||||||
"llama_model_load_internal: freq_scale = 1\n",
|
|
||||||
"llama_model_load_internal: ftype = 2 (mostly Q4_0)\n",
|
|
||||||
"llama_model_load_internal: model size = 13B\n",
|
|
||||||
"llama_model_load_internal: ggml ctx size = 0.11 MB\n",
|
|
||||||
"llama_model_load_internal: mem required = 6983.72 MB (+ 400.00 MB per state)\n",
|
|
||||||
"llama_new_context_with_model: kv self size = 400.00 MB\n",
|
|
||||||
"ggml_metal_init: allocating\n",
|
|
||||||
"ggml_metal_init: loading '/Users/rlm/miniforge3/envs/llama2/lib/python3.9/site-packages/llama_cpp/ggml-metal.metal'\n",
|
|
||||||
"ggml_metal_init: loaded kernel_add 0x113b42480\n",
|
|
||||||
"ggml_metal_init: loaded kernel_add_row 0x113b44210\n",
|
|
||||||
"ggml_metal_init: loaded kernel_mul 0x113b43a80\n",
|
|
||||||
"ggml_metal_init: loaded kernel_mul_row 0x113b44880\n",
|
|
||||||
"ggml_metal_init: loaded kernel_scale 0x113b45010\n",
|
|
||||||
"ggml_metal_init: loaded kernel_silu 0x113b45650\n",
|
|
||||||
"ggml_metal_init: loaded kernel_relu 0x113b427f0\n",
|
|
||||||
"ggml_metal_init: loaded kernel_gelu 0x113b46300\n",
|
|
||||||
"ggml_metal_init: loaded kernel_soft_max 0x113b46980\n",
|
|
||||||
"ggml_metal_init: loaded kernel_diag_mask_inf 0x113b46e20\n",
|
|
||||||
"ggml_metal_init: loaded kernel_get_rows_f16 0x113b47860\n",
|
|
||||||
"ggml_metal_init: loaded kernel_get_rows_q4_0 0x113b48010\n",
|
|
||||||
"ggml_metal_init: loaded kernel_get_rows_q4_1 0x113b48880\n",
|
|
||||||
"ggml_metal_init: loaded kernel_get_rows_q2_K 0x113b48f70\n",
|
|
||||||
"ggml_metal_init: loaded kernel_get_rows_q3_K 0x113b49e00\n",
|
|
||||||
"ggml_metal_init: loaded kernel_get_rows_q4_K 0x113b4a530\n",
|
|
||||||
"ggml_metal_init: loaded kernel_get_rows_q5_K 0x113b4ac70\n",
|
|
||||||
"ggml_metal_init: loaded kernel_get_rows_q6_K 0x113b4b3b0\n",
|
|
||||||
"ggml_metal_init: loaded kernel_rms_norm 0x113b4bb00\n",
|
|
||||||
"ggml_metal_init: loaded kernel_norm 0x113b4c1a0\n",
|
|
||||||
"ggml_metal_init: loaded kernel_mul_mat_f16_f32 0x113b4cba0\n",
|
|
||||||
"ggml_metal_init: loaded kernel_mul_mat_q4_0_f32 0x113b4d360\n",
|
|
||||||
"ggml_metal_init: loaded kernel_mul_mat_q4_1_f32 0x113b4dba0\n",
|
|
||||||
"ggml_metal_init: loaded kernel_mul_mat_q2_K_f32 0x113b4e560\n",
|
|
||||||
"ggml_metal_init: loaded kernel_mul_mat_q3_K_f32 0x113b4ed10\n",
|
|
||||||
"ggml_metal_init: loaded kernel_mul_mat_q4_K_f32 0x113b4f580\n",
|
|
||||||
"ggml_metal_init: loaded kernel_mul_mat_q5_K_f32 0x113b4fdc0\n",
|
|
||||||
"ggml_metal_init: loaded kernel_mul_mat_q6_K_f32 0x113b50740\n",
|
|
||||||
"ggml_metal_init: loaded kernel_mul_mm_f16_f32 0x113b51250\n",
|
|
||||||
"ggml_metal_init: loaded kernel_mul_mm_q4_0_f32 0x113b51a80\n",
|
|
||||||
"ggml_metal_init: loaded kernel_mul_mm_q4_1_f32 0x113b522b0\n",
|
|
||||||
"ggml_metal_init: loaded kernel_mul_mm_q2_K_f32 0x113b52ae0\n",
|
|
||||||
"ggml_metal_init: loaded kernel_mul_mm_q3_K_f32 0x113b53310\n",
|
|
||||||
"ggml_metal_init: loaded kernel_mul_mm_q4_K_f32 0x113b53b40\n",
|
|
||||||
"ggml_metal_init: loaded kernel_mul_mm_q5_K_f32 0x113b54370\n",
|
|
||||||
"ggml_metal_init: loaded kernel_mul_mm_q6_K_f32 0x113b54ba0\n",
|
|
||||||
"ggml_metal_init: loaded kernel_rope 0x113b551a0\n",
|
|
||||||
"ggml_metal_init: loaded kernel_alibi_f32 0x113b55b10\n",
|
|
||||||
"ggml_metal_init: loaded kernel_cpy_f32_f16 0x113b56450\n",
|
|
||||||
"ggml_metal_init: loaded kernel_cpy_f32_f32 0x113b56dc0\n",
|
|
||||||
"ggml_metal_init: loaded kernel_cpy_f16_f16 0x113b576b0\n",
|
|
||||||
"ggml_metal_init: recommendedMaxWorkingSetSize = 21845.34 MB\n",
|
|
||||||
"ggml_metal_init: hasUnifiedMemory = true\n",
|
|
||||||
"ggml_metal_init: maxTransferRate = built-in GPU\n",
|
|
||||||
"llama_new_context_with_model: compute buffer total size = 91.35 MB\n",
|
|
||||||
"llama_new_context_with_model: max tensor size = 87.89 MB\n",
|
|
||||||
"ggml_metal_add_buffer: allocated 'data ' buffer, size = 6984.06 MB, ( 6984.50 / 21845.34)\n",
|
|
||||||
"ggml_metal_add_buffer: allocated 'eval ' buffer, size = 1.36 MB, ( 6985.86 / 21845.34)\n",
|
|
||||||
"ggml_metal_add_buffer: allocated 'kv ' buffer, size = 402.00 MB, ( 7387.86 / 21845.34)\n",
|
|
||||||
"ggml_metal_add_buffer: allocated 'alloc ' buffer, size = 90.02 MB, ( 7477.88 / 21845.34)AVX = 0 | AVX2 = 0 | AVX512 = 0 | AVX512_VBMI = 0 | AVX512_VNNI = 0 | FMA = 0 | NEON = 1 | ARM_FMA = 1 | F16C = 0 | FP16_VA = 1 | WASM_SIMD = 0 | BLAS = 1 | SSE3 = 0 | VSX = 0 | \n",
|
|
||||||
"\n"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"source": [
|
"source": [
|
||||||
"n_gpu_layers = 1 # Metal set to 1 is enough.\n",
|
"n_gpu_layers = 1 # Metal set to 1 is enough.\n",
|
||||||
"n_batch = 512 # Should be between 1 and n_ctx, consider the amount of RAM of your Apple Silicon Chip.\n",
|
"n_batch = 512 # Should be between 1 and n_ctx, consider the amount of RAM of your Apple Silicon Chip.\n",
|
||||||
"\n",
|
|
||||||
"# Make sure the model path is correct for your system!\n",
|
"# Make sure the model path is correct for your system!\n",
|
||||||
"llm = LlamaCpp(\n",
|
"llm = LlamaCpp(\n",
|
||||||
" model_path=\"/Users/rlm/Desktop/Code/llama.cpp/llama-2-13b-chat.ggmlv3.q4_0.bin\",\n",
|
" model_path=\"/Users/rlm/Desktop/Code/llama.cpp/models/openorca-platypus2-13b.gguf.q4_0.bin\",\n",
|
||||||
" n_gpu_layers=n_gpu_layers,\n",
|
" n_gpu_layers=n_gpu_layers,\n",
|
||||||
" n_batch=n_batch,\n",
|
" n_batch=n_batch,\n",
|
||||||
" f16_kv=True, # MUST set to True, otherwise you will run into problem after a couple of calls\n",
|
" f16_kv=True, # MUST set to True, otherwise you will run into problem after a couple of calls\n",
|
||||||
" callback_manager=callback_manager,\n",
|
" callback_manager=callback_manager,\n",
|
||||||
" verbose=True,\n",
|
" verbose=True, # Verbose is required to pass to the callback manager\n",
|
||||||
")"
|
")"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
@ -687,142 +535,27 @@
|
|||||||
"\n",
|
"\n",
|
||||||
"We can specify [grammars](https://github.com/ggerganov/llama.cpp/blob/master/grammars/README.md) to constrain model outputs.\n",
|
"We can specify [grammars](https://github.com/ggerganov/llama.cpp/blob/master/grammars/README.md) to constrain model outputs.\n",
|
||||||
"\n",
|
"\n",
|
||||||
"Supply the path to the specifed `json.gbnf` file."
|
"This will sample tokens according to the grammar.\n",
|
||||||
|
" \n",
|
||||||
|
"For example, supply the path to the specifed `json.gbnf` file in order to produce JSON."
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": 6,
|
"execution_count": null,
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
"outputs": [
|
"outputs": [],
|
||||||
{
|
|
||||||
"name": "stderr",
|
|
||||||
"output_type": "stream",
|
|
||||||
"text": [
|
|
||||||
"llama.cpp: loading model from /Users/rlm/Desktop/Code/llama.cpp/llama-2-13b-chat.ggmlv3.q4_0.bin\n",
|
|
||||||
"llama_model_load_internal: format = ggjt v3 (latest)\n",
|
|
||||||
"llama_model_load_internal: n_vocab = 32000\n",
|
|
||||||
"llama_model_load_internal: n_ctx = 512\n",
|
|
||||||
"llama_model_load_internal: n_embd = 5120\n",
|
|
||||||
"llama_model_load_internal: n_mult = 256\n",
|
|
||||||
"llama_model_load_internal: n_head = 40\n",
|
|
||||||
"llama_model_load_internal: n_head_kv = 40\n",
|
|
||||||
"llama_model_load_internal: n_layer = 40\n",
|
|
||||||
"llama_model_load_internal: n_rot = 128\n",
|
|
||||||
"llama_model_load_internal: n_gqa = 1\n",
|
|
||||||
"llama_model_load_internal: rnorm_eps = 5.0e-06\n",
|
|
||||||
"llama_model_load_internal: n_ff = 13824\n",
|
|
||||||
"llama_model_load_internal: freq_base = 10000.0\n",
|
|
||||||
"llama_model_load_internal: freq_scale = 1\n",
|
|
||||||
"llama_model_load_internal: ftype = 2 (mostly Q4_0)\n",
|
|
||||||
"llama_model_load_internal: model size = 13B\n",
|
|
||||||
"llama_model_load_internal: ggml ctx size = 0.11 MB\n",
|
|
||||||
"llama_model_load_internal: mem required = 6983.72 MB (+ 400.00 MB per state)\n",
|
|
||||||
"llama_new_context_with_model: kv self size = 400.00 MB\n",
|
|
||||||
"ggml_metal_init: allocating\n",
|
|
||||||
"ggml_metal_init: loading '/Users/rlm/miniforge3/envs/llama2/lib/python3.9/site-packages/llama_cpp/ggml-metal.metal'\n",
|
|
||||||
"ggml_metal_init: loaded kernel_add 0x1516fb530\n",
|
|
||||||
"ggml_metal_init: loaded kernel_add_row 0x1516fb790\n",
|
|
||||||
"ggml_metal_init: loaded kernel_mul 0x1516fb9f0\n",
|
|
||||||
"ggml_metal_init: loaded kernel_mul_row 0x1516fbc50\n",
|
|
||||||
"ggml_metal_init: loaded kernel_scale 0x1516fbeb0\n",
|
|
||||||
"ggml_metal_init: loaded kernel_silu 0x1516fc110\n",
|
|
||||||
"ggml_metal_init: loaded kernel_relu 0x1516fc370\n",
|
|
||||||
"ggml_metal_init: loaded kernel_gelu 0x1516fc5d0\n",
|
|
||||||
"ggml_metal_init: loaded kernel_soft_max 0x1516fc830\n",
|
|
||||||
"ggml_metal_init: loaded kernel_diag_mask_inf 0x1516fca90\n",
|
|
||||||
"ggml_metal_init: loaded kernel_get_rows_f16 0x1516fccf0\n",
|
|
||||||
"ggml_metal_init: loaded kernel_get_rows_q4_0 0x1516fcf50\n",
|
|
||||||
"ggml_metal_init: loaded kernel_get_rows_q4_1 0x1516fd1b0\n",
|
|
||||||
"ggml_metal_init: loaded kernel_get_rows_q2_K 0x1516fd410\n",
|
|
||||||
"ggml_metal_init: loaded kernel_get_rows_q3_K 0x1516fd670\n",
|
|
||||||
"ggml_metal_init: loaded kernel_get_rows_q4_K 0x1516fd8d0\n",
|
|
||||||
"ggml_metal_init: loaded kernel_get_rows_q5_K 0x1516fdb30\n",
|
|
||||||
"ggml_metal_init: loaded kernel_get_rows_q6_K 0x1516fdd90\n",
|
|
||||||
"ggml_metal_init: loaded kernel_rms_norm 0x1516fdff0\n",
|
|
||||||
"ggml_metal_init: loaded kernel_norm 0x1516fe250\n",
|
|
||||||
"ggml_metal_init: loaded kernel_mul_mat_f16_f32 0x1516fe4b0\n",
|
|
||||||
"ggml_metal_init: loaded kernel_mul_mat_q4_0_f32 0x1516fe710\n",
|
|
||||||
"ggml_metal_init: loaded kernel_mul_mat_q4_1_f32 0x1516fe970\n",
|
|
||||||
"ggml_metal_init: loaded kernel_mul_mat_q2_K_f32 0x1516febd0\n",
|
|
||||||
"ggml_metal_init: loaded kernel_mul_mat_q3_K_f32 0x1516fee30\n",
|
|
||||||
"ggml_metal_init: loaded kernel_mul_mat_q4_K_f32 0x1516ff090\n",
|
|
||||||
"ggml_metal_init: loaded kernel_mul_mat_q5_K_f32 0x1516ff2f0\n",
|
|
||||||
"ggml_metal_init: loaded kernel_mul_mat_q6_K_f32 0x1516ff550\n",
|
|
||||||
"ggml_metal_init: loaded kernel_mul_mm_f16_f32 0x1516ff7b0\n",
|
|
||||||
"ggml_metal_init: loaded kernel_mul_mm_q4_0_f32 0x121fce650\n",
|
|
||||||
"ggml_metal_init: loaded kernel_mul_mm_q4_1_f32 0x121fcdce0\n",
|
|
||||||
"ggml_metal_init: loaded kernel_mul_mm_q2_K_f32 0x121fceab0\n",
|
|
||||||
"ggml_metal_init: loaded kernel_mul_mm_q3_K_f32 0x121fced10\n",
|
|
||||||
"ggml_metal_init: loaded kernel_mul_mm_q4_K_f32 0x121fcef70\n",
|
|
||||||
"ggml_metal_init: loaded kernel_mul_mm_q5_K_f32 0x121fcf1d0\n",
|
|
||||||
"ggml_metal_init: loaded kernel_mul_mm_q6_K_f32 0x121fcf430\n",
|
|
||||||
"ggml_metal_init: loaded kernel_rope 0x121fcf690\n",
|
|
||||||
"ggml_metal_init: loaded kernel_alibi_f32 0x121fcf8f0\n",
|
|
||||||
"ggml_metal_init: loaded kernel_cpy_f32_f16 0x121fcfb50\n",
|
|
||||||
"ggml_metal_init: loaded kernel_cpy_f32_f32 0x121fcfdb0\n",
|
|
||||||
"ggml_metal_init: loaded kernel_cpy_f16_f16 0x121fd0010\n",
|
|
||||||
"ggml_metal_init: recommendedMaxWorkingSetSize = 21845.34 MB\n",
|
|
||||||
"ggml_metal_init: hasUnifiedMemory = true\n",
|
|
||||||
"ggml_metal_init: maxTransferRate = built-in GPU\n"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "stdout",
|
|
||||||
"output_type": "stream",
|
|
||||||
"text": [
|
|
||||||
"root ::= object \n",
|
|
||||||
"object ::= [{] ws object_11 [}] \n",
|
|
||||||
"value ::= object | array | string | number | boolean | [n] [u] [l] [l] \n",
|
|
||||||
"array ::= [[] ws array_15 []] \n",
|
|
||||||
"string ::= [\"] string_18 [\"] ws \n",
|
|
||||||
"number ::= number_19 number_20 ws \n",
|
|
||||||
"boolean ::= boolean_21 ws \n",
|
|
||||||
"ws ::= ws_23 \n",
|
|
||||||
"object_8 ::= string [:] ws value object_10 \n",
|
|
||||||
"object_9 ::= [,] ws string [:] ws value \n",
|
|
||||||
"object_10 ::= object_9 object_10 | \n",
|
|
||||||
"object_11 ::= object_8 | \n",
|
|
||||||
"array_12 ::= value array_14 \n",
|
|
||||||
"array_13 ::= [,] ws value \n",
|
|
||||||
"array_14 ::= array_13 array_14 | \n",
|
|
||||||
"array_15 ::= array_12 | \n",
|
|
||||||
"string_16 ::= [^\"\\] | [\\] string_17 \n",
|
|
||||||
"string_17 ::= [\"\\/bfnrt] | [u] [0-9a-fA-F] [0-9a-fA-F] [0-9a-fA-F] [0-9a-fA-F] \n",
|
|
||||||
"string_18 ::= string_16 string_18 | \n",
|
|
||||||
"number_19 ::= [-] | \n",
|
|
||||||
"number_20 ::= [0-9] number_20 | [0-9] \n",
|
|
||||||
"boolean_21 ::= [t] [r] [u] [e] | [f] [a] [l] [s] [e] \n",
|
|
||||||
"ws_22 ::= [ <U+0009><U+000A>] ws \n",
|
|
||||||
"ws_23 ::= ws_22 | \n"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "stderr",
|
|
||||||
"output_type": "stream",
|
|
||||||
"text": [
|
|
||||||
"llama_new_context_with_model: compute buffer total size = 91.35 MB\n",
|
|
||||||
"llama_new_context_with_model: max tensor size = 87.89 MB\n",
|
|
||||||
"ggml_metal_add_buffer: allocated 'data ' buffer, size = 6984.06 MB, (14468.72 / 21845.34)\n",
|
|
||||||
"ggml_metal_add_buffer: allocated 'eval ' buffer, size = 1.36 MB, (14470.08 / 21845.34)\n",
|
|
||||||
"ggml_metal_add_buffer: allocated 'kv ' buffer, size = 402.00 MB, (14872.08 / 21845.34)\n",
|
|
||||||
"ggml_metal_add_buffer: allocated 'alloc ' buffer, size = 90.02 MB, (14962.09 / 21845.34)\n",
|
|
||||||
"AVX = 0 | AVX2 = 0 | AVX512 = 0 | AVX512_VBMI = 0 | AVX512_VNNI = 0 | FMA = 0 | NEON = 1 | ARM_FMA = 1 | F16C = 0 | FP16_VA = 1 | WASM_SIMD = 0 | BLAS = 1 | SSE3 = 0 | VSX = 0 | \n",
|
|
||||||
"from_string grammar:\n",
|
|
||||||
"\n"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"source": [
|
"source": [
|
||||||
"n_gpu_layers = 1 \n",
|
"n_gpu_layers = 1 # Metal set to 1 is enough.\n",
|
||||||
"n_batch = 512\n",
|
"n_batch = 512 # Should be between 1 and n_ctx, consider the amount of RAM of your Apple Silicon Chip.\n",
|
||||||
|
"# Make sure the model path is correct for your system!\n",
|
||||||
"llm = LlamaCpp(\n",
|
"llm = LlamaCpp(\n",
|
||||||
" model_path=\"/Users/rlm/Desktop/Code/llama.cpp/llama-2-13b-chat.ggmlv3.q4_0.bin\",\n",
|
" model_path=\"/Users/rlm/Desktop/Code/llama.cpp/models/openorca-platypus2-13b.gguf.q4_0.bin\",\n",
|
||||||
" n_gpu_layers=n_gpu_layers,\n",
|
" n_gpu_layers=n_gpu_layers,\n",
|
||||||
" n_batch=n_batch,\n",
|
" n_batch=n_batch,\n",
|
||||||
" f16_kv=True, # MUST set to True, otherwise you will run into problem after a couple of calls\n",
|
" f16_kv=True, # MUST set to True, otherwise you will run into problem after a couple of calls\n",
|
||||||
" callback_manager=callback_manager,\n",
|
" callback_manager=callback_manager,\n",
|
||||||
" verbose=True,\n",
|
" verbose=True, # Verbose is required to pass to the callback manager\n",
|
||||||
" grammar_path=\"/Users/rlm/Desktop/Code/langchain-main/langchain/libs/langchain/langchain/llms/grammars/json.gbnf\",\n",
|
" grammar_path=\"/Users/rlm/Desktop/Code/langchain-main/langchain/libs/langchain/langchain/llms/grammars/json.gbnf\",\n",
|
||||||
")"
|
")"
|
||||||
]
|
]
|
||||||
@ -832,23 +565,29 @@
|
|||||||
"execution_count": 7,
|
"execution_count": 7,
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
"outputs": [
|
"outputs": [
|
||||||
{
|
|
||||||
"name": "stderr",
|
|
||||||
"output_type": "stream",
|
|
||||||
"text": [
|
|
||||||
"Error in LangChainTracer.on_llm_start callback: ctypes objects containing pointers cannot be pickled\n",
|
|
||||||
"Exception ignored in: <function LlamaGrammar.__del__ at 0x1402b15e0>\n",
|
|
||||||
"Traceback (most recent call last):\n",
|
|
||||||
" File \"/Users/rlm/miniforge3/envs/llama2/lib/python3.9/site-packages/llama_cpp/llama_grammar.py\", line 46, in __del__\n",
|
|
||||||
" if self.grammar is not None:\n",
|
|
||||||
"AttributeError: 'LlamaGrammar' object has no attribute 'grammar'\n"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"name": "stdout",
|
"name": "stdout",
|
||||||
"output_type": "stream",
|
"output_type": "stream",
|
||||||
"text": [
|
"text": [
|
||||||
"{\"name\": \"John Doe\", \"age\": 30, \"gender\": \"male\"}"
|
"{\n",
|
||||||
|
" \"name\": \"John Doe\",\n",
|
||||||
|
" \"age\": 34,\n",
|
||||||
|
" \"\": {\n",
|
||||||
|
" \"title\": \"Software Developer\",\n",
|
||||||
|
" \"company\": \"Google\"\n",
|
||||||
|
" },\n",
|
||||||
|
" \"interests\": [\n",
|
||||||
|
" \"Sports\",\n",
|
||||||
|
" \"Music\",\n",
|
||||||
|
" \"Cooking\"\n",
|
||||||
|
" ],\n",
|
||||||
|
" \"address\": {\n",
|
||||||
|
" \"street_number\": 123,\n",
|
||||||
|
" \"street_name\": \"Oak Street\",\n",
|
||||||
|
" \"city\": \"Mountain View\",\n",
|
||||||
|
" \"state\": \"California\",\n",
|
||||||
|
" \"postal_code\": 94040\n",
|
||||||
|
" }}"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -856,132 +595,55 @@
|
|||||||
"output_type": "stream",
|
"output_type": "stream",
|
||||||
"text": [
|
"text": [
|
||||||
"\n",
|
"\n",
|
||||||
"llama_print_timings: load time = 317.62 ms\n",
|
"llama_print_timings: load time = 357.51 ms\n",
|
||||||
"llama_print_timings: sample time = 141.83 ms / 22 runs ( 6.45 ms per token, 155.11 tokens per second)\n",
|
"llama_print_timings: sample time = 1213.30 ms / 144 runs ( 8.43 ms per token, 118.68 tokens per second)\n",
|
||||||
"llama_print_timings: prompt eval time = 316.89 ms / 9 tokens ( 35.21 ms per token, 28.40 tokens per second)\n",
|
"llama_print_timings: prompt eval time = 356.78 ms / 9 tokens ( 39.64 ms per token, 25.23 tokens per second)\n",
|
||||||
"llama_print_timings: eval time = 575.93 ms / 21 runs ( 27.43 ms per token, 36.46 tokens per second)\n",
|
"llama_print_timings: eval time = 3947.16 ms / 143 runs ( 27.60 ms per token, 36.23 tokens per second)\n",
|
||||||
"llama_print_timings: total time = 1087.31 ms\n",
|
"llama_print_timings: total time = 5846.21 ms\n"
|
||||||
"Error in LangChainTracer.on_llm_end callback: ctypes objects containing pointers cannot be pickled\n",
|
|
||||||
"Exception ignored in: <function LlamaGrammar.__del__ at 0x1402b15e0>\n",
|
|
||||||
"Traceback (most recent call last):\n",
|
|
||||||
" File \"/Users/rlm/miniforge3/envs/llama2/lib/python3.9/site-packages/llama_cpp/llama_grammar.py\", line 46, in __del__\n",
|
|
||||||
" if self.grammar is not None:\n",
|
|
||||||
"AttributeError: 'LlamaGrammar' object has no attribute 'grammar'\n"
|
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"source": [
|
"source": [
|
||||||
|
"%%capture captured --no-stdout\n",
|
||||||
"result=llm(\"Describe a person in JSON format:\")"
|
"result=llm(\"Describe a person in JSON format:\")"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
|
||||||
"cell_type": "code",
|
|
||||||
"execution_count": 8,
|
|
||||||
"metadata": {},
|
|
||||||
"outputs": [
|
|
||||||
{
|
|
||||||
"data": {
|
|
||||||
"text/plain": [
|
|
||||||
"'John Doe'"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"execution_count": 8,
|
|
||||||
"metadata": {},
|
|
||||||
"output_type": "execute_result"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"source": [
|
|
||||||
"eval(result)[\"name\"]"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"cell_type": "markdown",
|
"cell_type": "markdown",
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
"source": [
|
"source": [
|
||||||
"We can also try `list.gbnf`."
|
"We can also supply `list.gbnf` to return a list."
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": 83,
|
"execution_count": null,
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
"outputs": [
|
"outputs": [],
|
||||||
{
|
|
||||||
"name": "stderr",
|
|
||||||
"output_type": "stream",
|
|
||||||
"text": [
|
|
||||||
"llama.cpp: loading model from /home/eryk/deepsense/llama-2-7b.ggmlv3.q4_0.bin\n",
|
|
||||||
"llama_model_load_internal: format = ggjt v3 (latest)\n",
|
|
||||||
"llama_model_load_internal: n_vocab = 32000\n",
|
|
||||||
"llama_model_load_internal: n_ctx = 512\n",
|
|
||||||
"llama_model_load_internal: n_embd = 4096\n",
|
|
||||||
"llama_model_load_internal: n_mult = 256\n",
|
|
||||||
"llama_model_load_internal: n_head = 32\n",
|
|
||||||
"llama_model_load_internal: n_head_kv = 32\n",
|
|
||||||
"llama_model_load_internal: n_layer = 32\n",
|
|
||||||
"llama_model_load_internal: n_rot = 128\n",
|
|
||||||
"llama_model_load_internal: n_gqa = 1\n",
|
|
||||||
"llama_model_load_internal: rnorm_eps = 5.0e-06\n",
|
|
||||||
"llama_model_load_internal: n_ff = 11008\n",
|
|
||||||
"llama_model_load_internal: freq_base = 10000.0\n",
|
|
||||||
"llama_model_load_internal: freq_scale = 1\n",
|
|
||||||
"llama_model_load_internal: ftype = 2 (mostly Q4_0)\n",
|
|
||||||
"llama_model_load_internal: model size = 7B\n",
|
|
||||||
"llama_model_load_internal: ggml ctx size = 0.08 MB\n",
|
|
||||||
"llama_model_load_internal: mem required = 3615.73 MB (+ 256.00 MB per state)\n",
|
|
||||||
"llama_new_context_with_model: kv self size = 256.00 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 | VSX = 0 | \n",
|
|
||||||
"llama_new_context_with_model: compute buffer total size = 71.84 MB\n",
|
|
||||||
"from_string grammar:\n",
|
|
||||||
"\n"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "stdout",
|
|
||||||
"output_type": "stream",
|
|
||||||
"text": [
|
|
||||||
"root ::= [[] items []] EOF \n",
|
|
||||||
"items ::= item items_7 \n",
|
|
||||||
"EOF ::= [<U+000A>] \n",
|
|
||||||
"item ::= string \n",
|
|
||||||
"items_4 ::= [,] items_6 item \n",
|
|
||||||
"ws ::= [ ] \n",
|
|
||||||
"items_6 ::= ws items_6 | \n",
|
|
||||||
"items_7 ::= items_4 items_7 | \n",
|
|
||||||
"string ::= [\"] word string_12 [\"] string_13 \n",
|
|
||||||
"word ::= word_14 \n",
|
|
||||||
"string_10 ::= string_11 word \n",
|
|
||||||
"string_11 ::= ws string_11 | ws \n",
|
|
||||||
"string_12 ::= string_10 string_12 | \n",
|
|
||||||
"string_13 ::= ws string_13 | \n",
|
|
||||||
"word_14 ::= [a-zA-Z] word_14 | [a-zA-Z] \n"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"source": [
|
"source": [
|
||||||
"n_gpu_layers = 1 \n",
|
"n_gpu_layers = 1 \n",
|
||||||
"n_batch = 512\n",
|
"n_batch = 512\n",
|
||||||
"llm = LlamaCpp(\n",
|
"llm = LlamaCpp(\n",
|
||||||
" model_path=\"/home/eryk/deepsense/llama-2-7b.ggmlv3.q4_0.bin\",\n",
|
" model_path=\"/Users/rlm/Desktop/Code/llama.cpp/models/openorca-platypus2-13b.gguf.q4_0.bin\",\n",
|
||||||
" n_gpu_layers=n_gpu_layers,\n",
|
" n_gpu_layers=n_gpu_layers,\n",
|
||||||
" n_batch=n_batch,\n",
|
" n_batch=n_batch,\n",
|
||||||
" f16_kv=True, # MUST set to True, otherwise you will run into problem after a couple of calls\n",
|
" f16_kv=True, # MUST set to True, otherwise you will run into problem after a couple of calls\n",
|
||||||
" callback_manager=callback_manager,\n",
|
" callback_manager=callback_manager,\n",
|
||||||
" verbose=True,\n",
|
" verbose=True,\n",
|
||||||
" grammar_path=\"/home/eryk/deepsense/langchain/libs/langchain/langchain/llms/grammars/list.gbnf\",\n",
|
" grammar_path=\"/Users/rlm/Desktop/Code/langchain-main/langchain/libs/langchain/langchain/llms/grammars/list.gbnf\",\n",
|
||||||
")"
|
")"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": 84,
|
"execution_count": 9,
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
"outputs": [
|
"outputs": [
|
||||||
{
|
{
|
||||||
"name": "stdout",
|
"name": "stdout",
|
||||||
"output_type": "stream",
|
"output_type": "stream",
|
||||||
"text": [
|
"text": [
|
||||||
"[\"Jane Eyre\" , \"Sense and Sensibility\" , \"A Tale of Two Cities\"]\n"
|
"[\"The Catcher in the Rye\", \"Wuthering Heights\", \"Anna Karenina\"]\n"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -989,37 +651,18 @@
|
|||||||
"output_type": "stream",
|
"output_type": "stream",
|
||||||
"text": [
|
"text": [
|
||||||
"\n",
|
"\n",
|
||||||
"llama_print_timings: load time = 1079.21 ms\n",
|
"llama_print_timings: load time = 322.34 ms\n",
|
||||||
"llama_print_timings: sample time = 225.57 ms / 29 runs ( 7.78 ms per token, 128.56 tokens per second)\n",
|
"llama_print_timings: sample time = 232.60 ms / 26 runs ( 8.95 ms per token, 111.78 tokens per second)\n",
|
||||||
"llama_print_timings: prompt eval time = 1078.34 ms / 11 tokens ( 98.03 ms per token, 10.20 tokens per second)\n",
|
"llama_print_timings: prompt eval time = 321.90 ms / 11 tokens ( 29.26 ms per token, 34.17 tokens per second)\n",
|
||||||
"llama_print_timings: eval time = 4389.99 ms / 28 runs ( 156.79 ms per token, 6.38 tokens per second)\n",
|
"llama_print_timings: eval time = 680.82 ms / 25 runs ( 27.23 ms per token, 36.72 tokens per second)\n",
|
||||||
"llama_print_timings: total time = 5807.84 ms\n"
|
"llama_print_timings: total time = 1295.27 ms\n"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"source": [
|
"source": [
|
||||||
|
"%%capture captured --no-stdout\n",
|
||||||
"result=llm(\"List of top-3 my favourite books:\")"
|
"result=llm(\"List of top-3 my favourite books:\")"
|
||||||
]
|
]
|
||||||
},
|
|
||||||
{
|
|
||||||
"cell_type": "code",
|
|
||||||
"execution_count": 85,
|
|
||||||
"metadata": {},
|
|
||||||
"outputs": [
|
|
||||||
{
|
|
||||||
"data": {
|
|
||||||
"text/plain": [
|
|
||||||
"['Jane Eyre', 'Sense and Sensibility', 'A Tale of Two Cities']"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"execution_count": 85,
|
|
||||||
"metadata": {},
|
|
||||||
"output_type": "execute_result"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"source": [
|
|
||||||
"eval(result)"
|
|
||||||
]
|
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"metadata": {
|
"metadata": {
|
||||||
|
Loading…
Reference in New Issue
Block a user