Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions guidance/models/llama_cpp/_llama_cpp.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,16 @@ def __init__(self, model_obj):

# get the bytes strings for all the tokens
tokens = []
for i in range(tokenizer.llama.n_vocab()):
tok = tokenizer.llama.detokenize([i]) # note that detokenize returns bytes directly
for i in range(tokenizer._model.n_vocab()):
tok = tokenizer._model.detokenize([i]) # note that detokenize returns bytes directly
if tok == b'':
tok = llama_cpp.llama_token_get_text(model_obj.model, i) # get text rep of special tokens
tokens.append(tok)

super().__init__(
tokens,
tokenizer.llama.token_bos(),
tokenizer.llama.token_eos()
tokenizer._model.token_bos(),
tokenizer._model.token_eos()
)

def __call__(self, byte_string):
Expand Down
24 changes: 18 additions & 6 deletions notebooks/tutorials/intro_to_guidance.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,28 @@
},
{
"cell_type": "code",
"execution_count": 1,
"execution_count": 3,
"metadata": {},
"outputs": [],
"outputs": [
{
"ename": "ModuleNotFoundError",
"evalue": "No module named 'guidance'",
"output_type": "error",
"traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mModuleNotFoundError\u001b[0m Traceback (most recent call last)",
"\u001b[0;32m/tmp/ipykernel_56968/3823389102.py\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0;32mfrom\u001b[0m \u001b[0mguidance\u001b[0m \u001b[0;32mimport\u001b[0m \u001b[0mmodels\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 2\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 3\u001b[0m \u001b[0;31m# For LlamaCpp, you need to provide the path on disk to a .gguf model\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 4\u001b[0m \u001b[0;31m# A sample model can be downloaded from\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 5\u001b[0m \u001b[0;31m# https://huggingface.co/TheBloke/Mistral-7B-Instruct-v0.2-GGUF/blob/main/mistral-7b-instruct-v0.2.Q8_0.gguf\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
"\u001b[0;31mModuleNotFoundError\u001b[0m: No module named 'guidance'"
]
}
],
"source": [
"from guidance import models\n",
"\n",
"# For LlamaCpp, you need to provide the path on disk to a .gguf model\n",
"# A sample model can be downloaded from\n",
"# https://huggingface.co/TheBloke/Mistral-7B-Instruct-v0.2-GGUF/blob/main/mistral-7b-instruct-v0.2.Q8_0.gguf\n",
"mistral = models.LlamaCpp(\"/home/scottlundberg_google_com/models/mistral-7b-instruct-v0.2.Q8_0.gguf\", n_gpu_layers=-1, n_ctx=4096)\n",
"mistral = models.LlamaCpp(\"/jingnan/lmaas/downloads/gemma-2b-it-q4_k_m.gguf\", n_gpu_layers=-1, n_ctx=4096)\n",
"\n",
"#llama2 = models.Transformers(\"meta-llama/Llama-2-7b-hf\")\n",
"#gpt3 = models.OpenAI(\"text-davinci-003\")\n",
Expand Down Expand Up @@ -612,7 +624,7 @@
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"display_name": "Python 3.10.12 64-bit",
"language": "python",
"name": "python3"
},
Expand All @@ -626,11 +638,11 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.5"
"version": "3.10.12"
},
"vscode": {
"interpreter": {
"hash": "fd8cabafb56980528edb83a46206c404687fdaed0bdad7c450ae020143ae38bc"
"hash": "97cc609b13305c559618ec78a438abc56230b9381f827f22d070313b9a1f3777"
}
}
},
Expand Down