{"id":16277775,"url":"https://github.com/aahouzi/llama2-chatbot-cpu","last_synced_at":"2025-03-20T01:33:08.297Z","repository":{"id":190643174,"uuid":"676989602","full_name":"aahouzi/llama2-chatbot-cpu","owner":"aahouzi","description":"A LLaMA2-7b chatbot with memory running on CPU, and optimized using smooth quantization, 4-bit quantization or Intel® Extension For PyTorch with bfloat16.","archived":false,"fork":false,"pushed_at":"2024-02-27T08:52:56.000Z","size":31758,"stargazers_count":13,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2024-10-18T23:15:54.589Z","etag":null,"topics":["4-bit-cpu","bfloat16","chatbot","chatbot-memory","chatgpt","cpu","huggingface","int8","intel","ipex","langchain","llama","llama2","meta","meta-ai","neural-compression","numa","optimization","smooth-quantization","streamlit"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/aahouzi.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-08-10T13:32:14.000Z","updated_at":"2024-09-03T13:34:20.000Z","dependencies_parsed_at":"2023-08-25T19:10:14.634Z","dependency_job_id":"44897134-fbc3-4ba1-acc1-ba0a8f04f80b","html_url":"https://github.com/aahouzi/llama2-chatbot-cpu","commit_stats":{"total_commits":68,"total_committers":3,"mean_commits":"22.666666666666668","dds":0.3088235294117647,"last_synced_commit":"01182b4fe05767005bc512105b80d053bb873aa6"},"previous_names":["aahouzi/llama2-chatbot-cpu"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aahouzi%2Fllama2-chatbot-cpu","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aahouzi%2Fllama2-chatbot-cpu/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aahouzi%2Fllama2-chatbot-cpu/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aahouzi%2Fllama2-chatbot-cpu/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/aahouzi","download_url":"https://codeload.github.com/aahouzi/llama2-chatbot-cpu/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":221456960,"owners_count":16825082,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["4-bit-cpu","bfloat16","chatbot","chatbot-memory","chatgpt","cpu","huggingface","int8","intel","ipex","langchain","llama","llama2","meta","meta-ai","neural-compression","numa","optimization","smooth-quantization","streamlit"],"created_at":"2024-10-10T18:56:20.737Z","updated_at":"2024-10-27T21:04:39.594Z","avatar_url":"https://github.com/aahouzi.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# LLaMA2 chatbot on CPU\n\n## :monocle_face: Description\n- This project is a Streamlit chatbot with Langchain deploying a **LLaMA2-7b-chat** model on **Intel® Server and Client CPUs**.\n- The chatbot has a memory that **remembers every part of the speech**, and allows users to optimize the model using  **Intel® Extension for PyTorch (IPEX) in bfloat16 with graph mode** or **smooth quantization** (A new quantization technique specifically designed for LLMs: [ArXiv link](https://arxiv.org/pdf/2211.10438.pdf)), or **4-bit quantization**. The user can expect **up to 4.3x speed-up** compared to stock PyTorch in default mode.\n\n- **IMPORTANT:** The CPU needs to support bfloat16 ops in order to be able to use such optimization. On top of software optimizations, I also introduced some hardware optimizations like non-uniform memory access (NUMA). User needs to **ask for access to LLaMA2** models by following this [link](https://huggingface.co/meta-llama#:~:text=Welcome%20to%20the%20official%20Hugging,processed%20within%201%2D2%20days). When getting approval from Meta, you can generate an authentification token from your HuggingFace account, and use it to load the model.\n\n## :scroll: Getting started\n\n1. Start by cloning the repository:  \n```bash\ngit clone https://github.com/aahouzi/llama2-chatbot-cpu.git\ncd llama2-chatbot-cpu\n```\n2. Create a Python 3.9 conda environment:\n```bash\nconda create -y -n llama2-chat python=3.9\n```\n3. Activate the environment:  \n```bash\nconda activate llama2-chat\n```\n4. Install requirements for NUMA:  \n```bash\nconda install -y gperftools -c conda-forge\nconda install -y intel-openmp\nsudo apt install numactl\n```\n5. Install the app requirements:  \n```bash\npip install -r requirements.txt\n```\n\n## :rocket: Start the app\n\n- Default mode (no optimizations):\n```bash\nbash launcher.sh --script=app/app.py --port=\u003cport\u003e --physical_cores=\u003cphysical_cores\u003e --auth_token=\u003cauth_token\u003e\n```\n\n- IPEX in graph mode with FP32:\n```bash\nbash launcher.sh --script=app/app.py --port=\u003cport\u003e --physical_cores=\u003cphysical_cores\u003e --auth_token=\u003cauth_token\u003e --ipex --jit\n```\n\n- IPEX in graph mode with bfloat16:\n```bash\nbash launcher.sh --script=app/app.py --port=\u003cport\u003e --physical_cores=\u003cphysical_cores\u003e --auth_token=\u003cauth_token\u003e --dtype=bfloat16 --ipex --jit\n```\n\n- Smooth quantization:\n```bash\nbash launcher.sh --script=app/app.py --port=\u003cport\u003e --physical_cores=\u003cphysical_cores\u003e --auth_token=\u003cauth_token\u003e --sq\n```\n\n- 4-bit quantization:\n```bash\nbash launcher.sh --script=app/app.py --port=\u003cport\u003e --physical_cores=\u003cphysical_cores\u003e --auth_token=\u003cauth_token\u003e --int4\n```\n\n\n## :computer: Chatbot demo\n\n    \n![](static/llama2-chat-demo.gif)\n\n\n\n## :mailbox_closed: Contact\nFor any information, feedback or questions, please [contact me][anas-email]\n\n\n\n\n\n\n\n\n\n[anas-email]: mailto:ahouzi2000@hotmail.fr\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faahouzi%2Fllama2-chatbot-cpu","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Faahouzi%2Fllama2-chatbot-cpu","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faahouzi%2Fllama2-chatbot-cpu/lists"}