Title: Running basic example from docs results in `TypeError: 'NoneType' object is not callable` · Issue #1998 · abetlen/llama-cpp-python · GitHub
Open Graph Title: Running basic example from docs results in `TypeError: 'NoneType' object is not callable` · Issue #1998 · abetlen/llama-cpp-python
X Title: Running basic example from docs results in `TypeError: 'NoneType' object is not callable` · Issue #1998 · abetlen/llama-cpp-python
Description: Prerequisites Please answer the following questions for yourself before submitting an issue. I am running the latest code. Development is very rapid so there are no tagged versions as of now. I carefully followed the README.md. I searche...
Open Graph Description: Prerequisites Please answer the following questions for yourself before submitting an issue. I am running the latest code. Development is very rapid so there are no tagged versions as of now. I car...
X Description: Prerequisites Please answer the following questions for yourself before submitting an issue. I am running the latest code. Development is very rapid so there are no tagged versions as of now. I car...
Opengraph URL: https://github.com/abetlen/llama-cpp-python/issues/1998
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Running basic example from docs results in `TypeError: 'NoneType' object is not callable`","articleBody":"# Prerequisites\n\nPlease answer the following questions for yourself before submitting an issue.\n\n- [x] I am running the latest code. Development is very rapid so there are no tagged versions as of now.\n- [x] I carefully followed the [README.md](https://github.com/abetlen/llama-cpp-python/blob/main/README.md).\n- [x] I [searched using keywords relevant to my issue](https://docs.github.com/en/issues/tracking-your-work-with-issues/filtering-and-searching-issues-and-pull-requests) to make sure that I am creating a new issue that is not already open (or closed).\n- [x] I reviewed the [Discussions](https://github.com/abetlen/llama-cpp-python/discussions), and have a new bug or useful enhancement to share.\n\n# Expected Behavior\n\nI am trying to run the most basic examples [from the docs][1].\n\nI am trying to load a model that I've downloaded:\n\n```python\nfrom llama_cpp import Llama\n\n\nif __name__ == \"__main__\":\n llm = Llama(\n model_path=\"models/qwen2-0_5b-instruct-q4_0.gguf\",\n verbose=False,\n )\n output = llm(\n \"Q: Name the planets in the solar system? A: \",\n max_tokens=32,\n stop=[\"Q:\", \"\\n\"],\n echo=True,\n )\n print(output)\n```\n\nAnd I am also trying to load a model directly from Hugging Face hub:\n\n```python\nfrom llama_cpp import Llama\n\n\nif __name__ == \"__main__\":\n llm = Llama.from_pretrained(\n repo_id=\"Qwen/Qwen2-0.5B-Instruct-GGUF\",\n filename=\"*q4_0.gguf\",\n verbose=False,\n )\n```\n\nI expect these basic examples to run without error and produce some reasonable looking output.\n\n[1]: https://llama-cpp-python.readthedocs.io/en/latest/#high-level-api\n\n# Current Behavior\n\nIn both cases -- whether using a pre-downloaded model or pulling from Hugging Face Hub -- I am getting the following exception:\n\n```python\nException ignored in: \u003cfunction Llama.__del__ at 0x14b2e5940>\nTraceback (most recent call last):\n File \".../.venv/lib/python3.11/site-packages/llama_cpp/llama.py\", line 2205, in __del__\n File \".../.venv/lib/python3.11/site-packages/llama_cpp/llama.py\", line 2202, in close\n File \".../.pyenv/versions/3.11.11/lib/python3.11/contextlib.py\", line 609, in close\n File \".../.pyenv/versions/3.11.11/lib/python3.11/contextlib.py\", line 601, in __exit__\n File \".../.pyenv/versions/3.11.11/lib/python3.11/contextlib.py\", line 586, in __exit__\n File \".../.pyenv/versions/3.11.11/lib/python3.11/contextlib.py\", line 360, in __exit__\n File \".../.venv/lib/python3.11/site-packages/llama_cpp/_internals.py\", line 75, in close\n File \".../.pyenv/versions/3.11.11/lib/python3.11/contextlib.py\", line 609, in close\n File \".../.pyenv/versions/3.11.11/lib/python3.11/contextlib.py\", line 601, in __exit__\n File \".../.pyenv/versions/3.11.11/lib/python3.11/contextlib.py\", line 586, in __exit__\n File \".../.pyenv/versions/3.11.11/lib/python3.11/contextlib.py\", line 469, in _exit_wrapper\n File \".../.venv/lib/python3.11/site-packages/llama_cpp/_internals.py\", line 69, in free_model\nTypeError: 'NoneType' object is not callable\n```\n\nThis appears to be the line raising this exception:\n\nhttps://github.com/abetlen/llama-cpp-python/blob/99f2ebfde18912adeb7f714b49c1ddb624df3087/llama_cpp/_internals.py#L69\n\nIn the case of using the pre-downloaded model, I see the printed model output first before I get the exception. In the case of pulling from Hugging Face Hub, I get the exception immediately.\n\n# Environment and Context\n\n- macOS 15.4 running on M3 Apple Silicon\n- Python 3.11.11\n- GNU Make 3.81\n- llama-cpp-python @ 99f2ebf (the latest from `main` as of 2025-04-11)\n\n# Steps to Reproduce\n\n1. Copy either test script from above into `test-llama.py`.\n2. Run `python test-llama.py`\n\nThis seems to be an issue specific to the Python bindings, so I did not trying building `llama.cpp`.\n\nThis issue is possibly related to #1442.","author":{"url":"https://github.com/nchammas","@type":"Person","name":"nchammas"},"datePublished":"2025-04-11T14:45:21Z","url":"https://github.com/abetlen/llama-cpp-python/issues/1998"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:8ec8525a-7acb-8fe3-2960-97cadcf05e57 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | A832:30DBED:10D3EF1:151634C:6AFF89AF |
| html-safe-nonce | a39b783ef9808821d167cb490683ef4a8bd83b26b850bdef2a6dd2c8c7ed243b |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBODMyOjMwREJFRDoxMEQzRUYxOjE1MTYzNEM6NkFGRjg5QUYiLCJ2aXNpdG9yX2lkIjoiNTc4MzEzNzQ2MTE0ODI4OTQ1NSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | ea492df19825455457d1652380a078d573d293894fc38e13be7f478a2759e14f |
| hovercard-subject-tag | issue:2988878509 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/abetlen/llama-cpp-python/1998/issue_layout |
| twitter:image | https://opengraph.githubassets.com/abe965b17bfee43b6388cd76dff48403db51209d2e64f82a4a67270b7225774e/abetlen/llama-cpp-python/issues/1998 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/abe965b17bfee43b6388cd76dff48403db51209d2e64f82a4a67270b7225774e/abetlen/llama-cpp-python/issues/1998 |
| og:image:alt | Prerequisites Please answer the following questions for yourself before submitting an issue. I am running the latest code. Development is very rapid so there are no tagged versions as of now. I car... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | nchammas |
| hostname | github.com |
| expected-hostname | github.com |
| None | 587ad99a3e443b2e1cb0d3df059ec49ab54389861f13310766dfdeb615fed90d |
| turbo-cache-control | no-preview |
| go-import | github.com/abetlen/llama-cpp-python git https://github.com/abetlen/llama-cpp-python.git |
| octolytics-dimension-user_id | 6826477 |
| octolytics-dimension-user_login | abetlen |
| octolytics-dimension-repository_id | 617868717 |
| octolytics-dimension-repository_nwo | abetlen/llama-cpp-python |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 617868717 |
| octolytics-dimension-repository_network_root_nwo | abetlen/llama-cpp-python |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 5bb0fb68d64881d1344f5863d809515d496801e5 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width