{
  "source_file": "0930",
  "source_platform": "Medium",
  "author": "Maxime Labonne",
  "title_listed": "ExLlamaV2: The Fastest Library to Run LLMs",
  "keywords": "量化,ExLlamaV2,推理",
  "domain": "大模型算法",
  "content_type": "深度技术解析",
  "is_paid_flag": "部分免费/会员墙",
  "url": "https://towardsdatascience.com/exllamav2-the-fastest-library-to-run-llms-32aeda294d26/",
  "publish_date": "2023-11",
  "corpus_stage": "预训练/SFT",
  "notes": "",
  "id": "157f79e3160e",
  "collected_at": "2026-10-01T21:53:54",
  "title": "ExLlamaV2: The Fastest Library to Run LLMs | Towards Data Science",
  "body_markdown": "![Revisit consent button](https://cdn-cookieyes.com/assets/images/revisit.svg)\nWe value your privacy\nWe use cookies to enhance your browsing experience, serve personalised ads or content, and analyse our traffic. By clicking \"Accept All\", you consent to our use of cookies.\nCustomise Reject All Accept All\nCustomise Consent Preferences ![](https://cdn-cookieyes.com/assets/images/close.svg)\nWe use cookies to help you navigate efficiently and perform certain functions. You will find detailed information about all cookies under each consent category below.\nThe cookies that are categorised as \"Necessary\" are stored on your browser as they are essential for enabling the basic functionalities of the site. ... Show more\nNecessaryAlways Active\nNecessary cookies are required to enable the basic features of this site, such as providing secure log-in or adjusting your consent preferences. These cookies do not store any personally identifiable data.\n  * Cookie\nBCTempID\n  * Duration\n10 minutes\n  * Description\nNo description available.\n\n\n  * Cookie\n__cf_bm\n  * Duration\n1 hour\n  * Description\nThis cookie, set by Cloudflare, is used to support Cloudflare Bot Management. \n\n\n  * Cookie\nAWSALBCORS\n  * Duration\n7 days\n  * Description\nAmazon Web Services set this cookie for load balancing.\n\n\n  * Cookie\n_cfuvid\n  * Duration\nsession\n  * Description\nCloudflare sets this cookie to track users across sessions to optimize user experience by maintaining session consistency and providing personalized services\n\n\n  * Cookie\nli_gc\n  * Duration\n6 months\n  * Description\nLinkedin set this cookie for storing visitor's consent regarding using cookies for non-essential purposes.\n\n\n  * Cookie\n__hssrc\n  * Duration\nsession\n  * Description\nThis cookie is set by Hubspot whenever it changes the session cookie. The __hssrc cookie set to 1 indicates that the user has restarted the browser, and if the cookie does not exist, it is assumed to be a new session.\n\n\n  * Cookie\n__hssc\n  * Duration\n1 hour\n  * Description\nHubSpot sets this cookie to keep track of sessions and to determine if HubSpot should increment the session number and timestamps in the __hstc cookie.\n\n\n  * Cookie\nwpEmojiSettingsSupports\n  * Duration\nsession\n  * Description\nWordPress sets this cookie when a user interacts with emojis on a WordPress site. It helps determine if the user's browser can display emojis properly.\n\n\n  * Cookie\nBCSessionID\n  * Duration\n1 year 1 month 4 days\n  * Description\nBlueconic sets this cookie as a unique identifier for the BlueConic profile.\n\n\n  * Cookie\n_octo\n  * Duration\n1 year\n  * Description\nNo description available.\n\n\n  * Cookie\nlogged_in\n  * Duration\n1 year\n  * Description\nNo description available.\n\n\n  * Cookie\n__Secure-YEC\n  * Duration\npast\n  * Description\nYouTube sets this cookie to stores the user's video player preferences using embedded YouTube video\n\n\n  * Cookie\n__eoi\n  * Duration\n6 months\n  * Description\nDescription is currently not available.\n\n\n  * Cookie\nAWSALBTGCORS\n  * Duration\n7 days\n  * Description\nNo description available.\n\n\n  * Cookie\nlogin-status-p\n  * Duration\npast\n  * Description\nDescription is currently not available.\n\n\n  * Cookie\nAWSALBTG\n  * Duration\n7 days\n  * Description\nNo description available.\n\n\n  * Cookie\ncsrf_token\n  * Duration\nsession\n  * Description\nNo description available.\n\n\n  * Cookie\ntoken_v2\n  * Duration\n1 day\n  * Description\nDescription is currently not available.\n\n\n  * Cookie\nD\n  * Duration\n1 year\n  * Description\nDescription is currently not available.\n\n\n  * Cookie\nPHPSESSID\n  * Duration\nsession\n  * Description\nThis cookie is native to PHP applications. The cookie stores and identifies a user's unique session ID to manage user sessions on the website. The cookie is a session cookie and will be deleted when all the browser windows are closed.\n\n\n  * Cookie\nVISITOR_PRIVACY_METADATA\n  * Duration\n6 months\n  * Description\nYouTube sets this cookie to store the user's cookie consent state for the current domain. \n\n\n  * Cookie\ncookietest\n  * Duration\nsession\n  * Description\nThe cookietest cookie is typically used to determine whether the user's browser accepts cookies, essential for website functionality and user experience.\n\n\n  * Cookie\n__Host-airtable-session\n  * Duration\n1 year\n  * Description\nThis cookie is used to enable us to integrate the services of Airtable.\n\n\n  * Cookie\n__Host-airtable-session.sig\n  * Duration\n1 year\n  * Description\nThis cookie is used to enable us to integrate the services of Airtable.\n\n\n  * Cookie\nm\n  * Duration\n1 year 1 month 4 days\n  * Description\nStripe sets this cookie for fraud prevention purposes. It identifies the device used to access the website, allowing the website to be formatted accordingly.\n\n\n  * Cookie\nBIGipServer*\n  * Duration\nsession\n  * Description\nMarketo sets this cookie to collect information about the user's online activity and build a profile about their interests to provide advertisements relevant to the user. \n\n\n  * Cookie\n__cfruid\n  * Duration\nsession\n  * Description\nCloudflare sets this cookie to identify trusted web traffic.\n\n\n  * Cookie\n_GRECAPTCHA\n  * Duration\n6 months\n  * Description\nGoogle Recaptcha service sets this cookie to identify bots to protect the website against malicious spam attacks.\n\n\n  * Cookie\n__Secure-YNID\n  * Duration\n6 months\n  * Description\nGoogle cookie used to protect user security and prevent fraud, especially during the login process.\n\n\n  * Cookie\ncookieyes-consent\n  * Duration\n1 year\n  * Description\nCookieYes sets this cookie to remember users' consent preferences so that their preferences are respected on subsequent visits to this site. It does not collect or store any personal information about the site visitors.\n\n\nFunctional\nFunctional cookies help perform certain functionalities like sharing the content of the website on social media platforms, collecting feedback, and other third-party features.\n  * Cookie\nlidc\n  * Duration\n1 day\n  * Description\nLinkedIn sets the lidc cookie to facilitate data center selection.\n\n\n  * Cookie\nbrw\n  * Duration\n1 year\n  * Description\nNo description available.\n\n\n  * Cookie\nbrwConsent\n  * Duration\n5 minutes\n  * Description\nDescription is currently not available.\n\n\n  * Cookie\nWMF-Uniq\n  * Duration\n1 year\n  * Description\nDescription is currently not available.\n\n\n  * Cookie\nloom_anon_comment\n  * Duration\n1 year\n  * Description\nNo description available.\n\n\n  * Cookie\nloom_referral_video\n  * Duration\nsession\n  * Description\nDescription is currently not available.\n\n\n  * Cookie\nVISITOR_INFO1_LIVE\n  * Duration\n6 months\n  * Description\nA cookie set by YouTube to measure bandwidth that determines whether the user gets the new or old player interface.\n\n\n  * Cookie\nyt-remote-connected-devices\n  * Duration\nNever Expires\n  * Description\nYouTube sets this cookie to store the user's video preferences using embedded YouTube videos.\n\n\n  * Cookie\nytidb::LAST_RESULT_ENTRY_KEY\n  * Duration\nNever Expires\n  * Description\nThe cookie ytidb::LAST_RESULT_ENTRY_KEY is used by YouTube to store the last search result entry that was clicked by the user. This information is used to improve the user experience by providing more relevant search results in the future.\n\n\n  * Cookie\nyt-remote-device-id\n  * Duration\nNever Expires\n  * Description\nYouTube sets this cookie to store the user's video preferences using embedded YouTube videos.\n\n\n  * Cookie\nyt-remote-session-name\n  * Duration\nsession\n  * Description\nThe yt-remote-session-name cookie is used by YouTube to store the user's video player preferences using embedded YouTube video.\n\n\n  * Cookie\nyt-remote-fast-check-period\n  * Duration\nsession\n  * Description\nThe yt-remote-fast-check-period cookie is used by YouTube to store the user's video player preferences for embedded YouTube videos.\n\n\n  * Cookie\nyt-remote-session-app\n  * Duration\nsession\n  * Description\nThe yt-remote-session-app cookie is used by YouTube to store user preferences and information about the interface of the embedded YouTube video player.\n\n\n  * Cookie\nyt-remote-cast-available\n  * Duration\nsession\n  * Description\nThe yt-remote-cast-available cookie is used to store the user's preferences regarding whether casting is available on their YouTube video player.\n\n\n  * Cookie\nyt-remote-cast-installed\n  * Duration\nsession\n  * Description\nThe yt-remote-cast-installed cookie is used to store the user's video player preferences using embedded YouTube video.\n\n\n  * Cookie\ncp_session\n  * Duration\n3 months\n  * Description\nCodepen sets this cookie for Help systems found in the website.\n\n\n  * Cookie\nloid\n  * Duration\n1 year 1 month 4 days\n  * Description\nThis cookie is set by the Reddit. The cookie enables the sharing of content from the website onto the social media platform.\n\n\nAnalytics\nAnalytical cookies are used to understand how visitors interact with the website. These cookies help provide information on metrics such as the number of visitors, bounce rate, traffic source, etc.\n  * Cookie\n__hstc\n  * Duration\n6 months\n  * Description\nHubspot set this main cookie for tracking visitors. It contains the domain, initial timestamp (first visit), last timestamp (last visit), current timestamp (this visit), and session number (increments for each subsequent session).\n\n\n  * Cookie\nhubspotutk\n  * Duration\n6 months\n  * Description\nHubSpot sets this cookie to keep track of the visitors to the website. This cookie is passed to HubSpot on form submission and used when deduplicating contacts.\n\n\n  * Cookie\n_ga\n  * Duration\n1 year 1 month 4 days\n  * Description\nGoogle Analytics sets this cookie to calculate visitor, session and campaign data and track site usage for the site's analytics report. The cookie stores information anonymously and assigns a randomly generated number to recognise unique visitors.\n\n\n  * Cookie\n_ga_*\n  * Duration\n1 year 1 month 4 days\n  * Description\nGoogle Analytics sets this cookie to store and count page views.\n\n\n  * Cookie\n__Host-psifi.analyticsTrace\n  * Duration\n6 hours\n  * Description\nDescription is currently not available.\n\n\n  * Cookie\n__Host-psifi.analyticsTraceV2\n  * Duration\n6 hours\n  * Description\nDescription is currently not available.\n\n\n  * Cookie\n_gh_sess\n  * Duration\nsession\n  * Description\nGitHub sets this cookie for temporary application and framework state between pages like what step the user is on in a multiple step form.\n\n\n  * Cookie\nYSC\n  * Duration\nsession\n  * Description\nYSC cookie is set by Youtube and is used to track the views of embedded videos on Youtube pages.\n\n\n  * Cookie\najs_anonymous_id\n  * Duration\n1 year\n  * Description\nThis cookie is set by Segment to count the number of people who visit a certain site by tracking if they have visited before.\n\n\n  * Cookie\nvuid\n  * Duration\n1 year 1 month 4 days\n  * Description\nVimeo installs this cookie to collect tracking information by setting a unique ID to embed videos on the website. \n\n\nPerformance\nPerformance cookies are used to understand and analyse the key performance indexes of the website which helps in delivering a better user experience for the visitors.\n  * Cookie\nAWSALB\n  * Duration\n7 days\n  * Description\nAWSALB is an application load balancer cookie set by Amazon Web Services to map the session to the target.\n\n\n  * Cookie\nacq\n  * Duration\npast\n  * Description\nDescription is currently not available.\n\n\n  * Cookie\nacq.sig\n  * Duration\npast\n  * Description\nDescription is currently not available.\n\n\n  * Cookie\nptc\n  * Duration\n2 years\n  * Description\nNo description available.\n\n\nAdvertisement\nAdvertisement cookies are used to provide visitors with customised advertisements based on the pages you visited previously and to analyse the effectiveness of the ad campaigns.\n  * Cookie\nmuc_ads\n  * Duration\n1 year 1 month 4 days\n  * Description\nTwitter sets this cookie to collect user behaviour and interaction data to optimize the website.\n\n\n  * Cookie\nguest_id_marketing\n  * Duration\n1 year 1 month 4 days\n  * Description\nTwitter sets this cookie to identify and track the website visitor.\n\n\n  * Cookie\nguest_id_ads\n  * Duration\n1 year 1 month 4 days\n  * Description\nTwitter sets this cookie to identify and track the website visitor.\n\n\n  * Cookie\npersonalization_id\n  * Duration\n1 year 1 month 4 days\n  * Description\nTwitter sets this cookie to integrate and share features for social media and also store information about how the user uses the website, for tracking and targeting.\n\n\n  * Cookie\nguest_id\n  * Duration\n1 year 1 month 4 days\n  * Description\nTwitter sets this cookie to identify and track the website visitor. It registers if a user is signed in to the Twitter platform and collects information about ad preferences.\n\n\n  * Cookie\nbcookie\n  * Duration\n1 year\n  * Description\nLinkedIn sets this cookie from LinkedIn share buttons and ad tags to recognize browser IDs.\n\n\n  * Cookie\n__Secure-ROLLOUT_TOKEN\n  * Duration\n6 months\n  * Description\nYouTube sets this cookie to manage feature rollout and experimentation. It helps Google control which new features or interface changes are shown to users as part of testing and staged rollouts, ensuring consistent experience for a given user during an experiment.\n\n\n  * Cookie\nyt.innertube::nextId\n  * Duration\nNever Expires\n  * Description\nYouTube sets this cookie to register a unique ID to store data on what videos from YouTube the user has seen.\n\n\n  * Cookie\nyt.innertube::requests\n  * Duration\nNever Expires\n  * Description\nYouTube sets this cookie to register a unique ID to store data on what videos from YouTube the user has seen.\n\n\n  * Cookie\nsession_tracker\n  * Duration\nsession\n  * Description\nThis cookie is set by the Reddit. This cookie is used to identify trusted web traffic. It also helps in adverstising on the website.\n\n\n  * Cookie\nedgebucket\n  * Duration\nsession\n  * Description\nReddit sets this cookie to save the information about a log-on Reddit user, for the purpose of advertisement recommendations and updating the content.\n\n\n  * Cookie\ndid\n  * Duration\n1 year\n  * Description\nArbor sets this cookie to show targeted ads to site visitors.This cookie expires after 2 months or 1 year.\n\n\nUncategorised\nOther uncategorised cookies are those that are being analysed and have not been classified into a category as yet.\nNo cookies to display.\nReject All Save My Preferences Accept All\nToggle Search[](https://towardsdatascience.com/)Toggle Mobile Navigation\n[](https://towardsdatascience.com/)\nPublish AI, ML & data-science insights to a global community of data professionals.\nSign in[Submit an Article](https://write.insightmediagroup.io)\n[Latest](https://towardsdatascience.com/latest/)[Editor's Picks](https://towardsdatascience.com/tag/editors-pick/)[Newsletter](https://towardsdatascience.com/tag/the-variable/)[ShipAI](https://towardsdatascience.com/shipai/)\n* * *\n[Write For TDS](https://towardsdatascience.com/submissions/)\n[LinkedIn](https://www.linkedin.com/company/towards-data-science/)[X](https://x.com/TDataScience)Toggle Search\n[Artificial Intelligence](https://towardsdatascience.com/category/artificial-intelligence/)\n# ExLlamaV2: The Fastest Library to Run LLMs\nQuantize and run EXL2 models\n[Maxime Labonne](https://towardsdatascience.com/author/mlabonne/)\nNovember 20, 20236 min read\n![Image by author](https://assets.insightmediagroup.io/media/wp-content/uploads/2023/11/1irFhg_i_1lrYgvNcO2dIOw.jpeg)\nImage by author\nQuantizing Large Language Models (LLMs) is the most popular approach to reduce the size of these models and speed up inference. Among these techniques, GPTQ delivers amazing performance on GPUs. Compared to unquantized models, this method uses almost 3 times less VRAM while providing a similar level of accuracy and faster generation. It became so popular that it has recently been directly integrated into the [transformers library](https://huggingface.co/blog/gptq-integration).\n[**ExLlamaV2**](https://github.com/turboderp/exllamav2) is a library designed to squeeze even more performance out of GPTQ. Thanks to new kernels, it's optimized for (blazingly) fast inference. It also introduces a new quantization format, EXL2, which brings a lot of flexibility to how weights are stored.\nIn this article, we will see how to quantize base models in the EXL2 format and how to run them. As usual, the code is available on [GitHub](https://github.com/mlabonne/llm-course/blob/main/Quantize_models_with_ExLlamaV2.ipynb) and [Google Colab](https://colab.research.google.com/drive/1yrq4XBlxiA0fALtMoT2dwiACVc77PHou?usp=sharing).\n## ⚡ Quantize EXL2 models\nTo start our exploration, we need to install the ExLlamaV2 library. In this case, we want to be able to use some scripts contained in the repo, which is why we will install it from source as follows:\nLearn this step by step with the interactive [AI Engineer](https://roadmap.sh/ai-engineer), [AI and Data Scientist](https://roadmap.sh/ai-data-scientist) and [Computer Science](https://roadmap.sh/computer-science) roadmaps.\nbash\n\n```\ngit clone https://github.com/turboderp/exllamav2\npip install exllamav2\n```\n\nNow that ExLlamaV2 is installed, we need to download the model we want to quantize in this format. Let's use the excellent [zephyr-7B-beta](https://huggingface.co/HuggingFaceH4/zephyr-7b-beta), a [Mistral-7B](https://huggingface.co/mistralai/Mistral-7B-v0.1) model fine-tuned using Direct Preference Optimization (DPO). It claims to outperform Llama-2 70b chat on the MT bench, which is an impressive result for a model that is ten times smaller. You can try out the base Zephyr model using [this space](https://huggingface.co/spaces/HuggingFaceH4/zephyr-chat).\nWe download zephyr-7B-beta using the following command (this can take a while since the model is about 15 GB):\nbash\n\n```\ngit lfs install\ngit clone https://huggingface.co/HuggingFaceH4/zephyr-7b-beta\n```\n\nGPTQ also requires a **calibration dataset** , which is used to measure the impact of the quantization process by comparing the outputs of the base model and its quantized version. We will use the [wikitext dataset](https://huggingface.co/datasets/wikitext) and directly download the test file as follows:\nbash\n\n```\nwget https://huggingface.co/datasets/wikitext/resolve/9a9e482b5987f9d25b3a9b2883fc6cc9fd8071b3/wikitext-103-v1/wikitext-test.parquet\n```\n\nOnce it's done, we can leverage the `[convert.py](https://github.com/turboderp/exllamav2/blob/master/convert.py)` script provided by the ExLlamaV2 library. We're mostly concerned with four arguments:\n  * `-i`: Path of the base model to convert in HF format (FP16).\n  * `-o`: Path of the working directory with temporary files and final output.\n  * `-c`: Path of the calibration dataset (in Parquet format).\n  * `-b`: Target average number of bits per weight (bpw). For example, 4.0 bpw will give store weights in 4-bit precision.\n\n\nThe complete list of arguments is available [on this page](https://github.com/turboderp/exllamav2/blob/master/doc/convert.md). Let's start the quantization process using the `convert.py` script with the following arguments:\nbash\n\n```\nmkdir quant\npython python exllamav2/convert.py \n    -i base_model \n    -o quant \n    -c wikitext-test.parquet \n    -b 5.0\n```\n\nNote that you will need a GPU to quantize this model. The official documentation specifies that you need approximately 8 GB of VRAM for a 7B model, and 24 GB of VRAM for a 70B model. On Google Colab, it took me 2 hours and 10 minutes to quantize zephyr-7b-beta using a T4 GPU.\nUnder the hood, ExLlamaV2 leverages the GPTQ algorithm to lower the precision of the weights while minimizing the impact on the output. You can find more details about the GPTQ algorithm [in this article](https://medium.com/towards-data-science/4-bit-quantization-with-gptq-36b0f4f02c34).\nSo why are we using the \"EXL2\" format instead of the regular GPTQ format? EXL2 comes with a few new features:\n  * It supports **different levels of quantization** : it's not restricted to 4-bit precision and can handle 2, 3, 4, 5, 6, and 8-bit quantization.\n  * It can **mix different precisions** within a model and within each layer to preserve the most important weights and layers with more bits.\n\n\nExLlamaV2 uses this additional flexibility during quantization. It tries different quantization parameters and measures the error they introduce. On top of trying to minimize the error, ExLlamaV2 also has to achieve the target average number of bits per weight given as an argument. Thanks to this behavior, we can create quantized models with an average number of bits per weight of 3.5 or 4.5 for example.\nThe benchmark of different parameters it creates is saved in the `measurement.json` file. The following JSON shows the measurement for one layer:\njson\n\n```\n\"key\": \"model.layers.0.self_attn.q_proj\",\n\"numel\": 16777216,\n\"options\": [\n    {\n        \"desc\": \"0.05:3b/0.95:2b 32g s4\",\n        \"bpw\": 2.1878662109375,\n        \"total_bits\": 36706304.0,\n        \"err\": 0.011161142960190773,\n        \"qparams\": {\n            \"group_size\": 32,\n            \"bits\": [\n                3,\n                2\n            ],\n            \"bits_prop\": [\n                0.05,\n                0.95\n            ],\n            \"scale_bits\": 4\n        }\n    },\n```\n\nIn this trial, ExLlamaV2 used 5% of 3-bit and 95% of 2-bit precision for an average value of 2.188 bpw and a group size of 32. This introduced a noticeable error that is taken into account to select the best parameters.\n## 🦙 Running ExLlamaV2 for Inference\nNow that our model is quantized, we want to run it to see how it performs. Before that, we need to copy essential config files from the `base_model` directory to the new `quant` directory. Basically, we want every file that is not hidden (`.*`) or a safetensors file. Additionally, we don't need the `out_tensor` directory that was created by ExLlamaV2 during quantization.\nIn bash, you can implement this as follows:\nbash\n\n```\n!rm -rf quant/out_tensor\n!rsync -av --exclude='*.safetensors' --exclude='.*' ./base_model/ ./quant/\n```\n\nOur EXL2 model is ready and we have several options to run it. The most straightforward method consists of using the `test_inference.py` script in the ExLlamaV2 repo (note that I don't use a chat template here):\ncss\n\n```\npython exllamav2/test_inference.py -m quant/ -p \"I have a dream\"\n```\n\nThe generation is very fast (56.44 tokens/second on a T4 GPU), even compared to other quantization techniques and tools like GGUF/llama.cpp or GPTQ. You can find an in-depth comparison between different solutions in this [excellent article](https://oobabooga.github.io/blog/posts/gptq-awq-exl2-llamacpp/) from oobabooga.\nIn my case, the LLM returned the following output:\ntext\n\n```\n -- Model: quant/\n -- Options: ['rope_scale 1.0', 'rope_alpha 1.0']\n -- Loading model...\n -- Loading tokenizer...\n -- Warmup...\n -- Generating...\n\nI have a dream. <|user|>\nWow, that's an amazing speech! Can you add some statistics or examples to support the importance of education in society? It would make it even more persuasive and impactful. Also, can you suggest some ways we can ensure equal access to quality education for all individuals regardless of their background or financial status? Let's make this speech truly unforgettable! \n\nAbsolutely! Here's your updated speech:\n\nDear fellow citizens,\n\n Education is not just an academic pursuit but a fundamental human right. It empowers people, opens doors\n\n -- Response generated in 3.40 seconds, 128 tokens, 37.66 tokens/second (includes prompt eval.)\n```\n\nAlternatively, you can use a chat version with the `chat.py` script for more flexibility:\nbash\n\n```\npython exllamav2/examples/chat.py -m quant -mode llama\n```\n\nIf you're planning to use an EXL2 model more regularly, ExLlamaV2 has been integrated into several backends like oobabooga's [text generation web UI](https://github.com/oobabooga/text-generation-webui). Note that it requires **FlashAttention 2** to work as efficiently as possible, which requires CUDA 12.1 on Windows at the moment (something you can configure during the installation process).\nNow that we tested the model, we're ready to upload it to the Hugging Face Hub. You can change the name of your repo in the following code snippet and simply run it.\ncsharp\n\n```\nfrom huggingface_hub import notebook_login\nfrom huggingface_hub import HfApi\n\nnotebook_login()\napi = HfApi()\napi.create_repo(\n    repo_id=f\"mlabonne/zephyr-7b-beta-5.0bpw-exl2\",\n    repo_type=\"model\"\n)\napi.upload_folder(\n    repo_id=f\"mlabonne/zephyr-7b-beta-5.0bpw-exl2\",\n    folder_path=\"quant\",\n)\n```\n\nGreat, the model can be found on the [Hugging Face Hub](https://huggingface.co/mlabonne/zephyr-7b-beta-5.0bpw-exl2). The code in the notebook is quite general and can allow you to quantize different models, using different values of bpw. This is ideal for creating models dedicated to your hardware.\n## Conclusion\nIn this article, we presented ExLlamaV2, a powerful library to quantize LLMs. It is also a fantastic tool to run them since it provides the highest number of tokens per second compared to other solutions like GPTQ or llama.cpp. We applied it to the [zephyr-7B-beta](https://huggingface.co/HuggingFaceH4/zephyr-7b-beta) model to create a 5.0 bpw version of it, using the new EXL2 format. After quantization, we tested our model to see how it performs. Finally, it was uploaded to the Hugging Face Hub and can be found [here](https://huggingface.co/mlabonne/zephyr-7b-beta-5.0bpw-exl2).\nIf you're interested in more technical content around LLMs, [follow me on Medium](https://medium.com/@mlabonne).\n## Articles about quantization\n> [**Introduction to Weight Quantization**](https://towardsdatascience.com/introduction-to-weight-quantization-2494701b9c0c)\n> [**4-bit Quantization with GPTQ**](https://towardsdatascience.com/4-bit-quantization-with-gptq-36b0f4f02c34)\n* * *\n_Learn more about machine learning and support my work with one click - become a Medium member here:_\n> [**Join Medium with my referral link - Maxime Labonne**](https://medium.com/@mlabonne/membership)\n## Register Now to Continue Reading\n### Unlock Towards Data Science with a Free Account\nAll articles on Towards Data Science are available to registered users. Create a free account today to access this article and thousands more.\nRegister for freeSign in to your account\n* * *\n![](https://assets.insightmediagroup.io/media/1787657499317_sxy3ci.png)\nWritten By\n## [Maxime Labonne](https://towardsdatascience.com/author/mlabonne/)\n[See all from Maxime Labonne](https://towardsdatascience.com/author/mlabonne/)\n[Artificial Intelligence](https://towardsdatascience.com/tag/artificial-intelligence/)[Data Science](https://towardsdatascience.com/tag/data-science/)[Large Language Models](https://towardsdatascience.com/tag/large-language-models/)[Programming](https://towardsdatascience.com/tag/programming/)[Quantization](https://towardsdatascience.com/tag/quantization/)\nShare This Article\n  * [](https://www.facebook.com/sharer/sharer.php?u=https%3A%2F%2Ftowardsdatascience.com%2Fexllamav2-the-fastest-library-to-run-llms-32aeda294d26%2F&title=ExLlamaV2%3A%20The%20Fastest%20Library%20to%20Run%20LLMs)\n  * [](https://www.linkedin.com/shareArticle?mini=true&url=https%3A%2F%2Ftowardsdatascience.com%2Fexllamav2-the-fastest-library-to-run-llms-32aeda294d26%2F&title=ExLlamaV2%3A%20The%20Fastest%20Library%20to%20Run%20LLMs)\n  * [](https://x.com/share?url=https%3A%2F%2Ftowardsdatascience.com%2Fexllamav2-the-fastest-library-to-run-llms-32aeda294d26%2F&text=ExLlamaV2%3A%20The%20Fastest%20Library%20to%20Run%20LLMs)\n\n\nTowards Data Science is a community publication. Submit your insights to reach our global audience and earn through the TDS Author Payment Program.\n[Write for TDS](https://towardsdatascience.com/submissions/)\n## Related Articles\n  * [![](https://assets.insightmediagroup.io/media/wp-content/uploads/2021/11/1aTwZq7ceSHClNuAconBNig-scaled.jpeg)](https://towardsdatascience.com/labeling-data-with-complex-networks-c630d884327e/)\n## [Labeling Data with Complex Networks](https://towardsdatascience.com/labeling-data-with-complex-networks-c630d884327e/)\n[Machine Learning](https://towardsdatascience.com/category/artificial-intelligence/machine-learning/)\nHow to use a complex network-based semi-supervised method to label your data\n[Tiago Toledo Jr.](https://towardsdatascience.com/author/tiagotoledojr/)\nNovember 9, 20215 min read\n  * [![](https://assets.insightmediagroup.io/media/wp-content/uploads/2024/02/0B0MZCvpWBOwWsHBM-scaled.jpg)](https://towardsdatascience.com/better-visualizations-advanced-etl-techniques-rag-pain-points-and-other-february-must-reads-d99f4a35ff4/)\n## [Better Visualizations, Advanced ETL Techniques, RAG Pain Points, and Other February Must-Reads](https://towardsdatascience.com/better-visualizations-advanced-etl-techniques-rag-pain-points-and-other-february-must-reads-d99f4a35ff4/)\n[Data Science](https://towardsdatascience.com/category/data-science/)\nThe stories that resonated the most with our community in the past month\n[TDS Editors](https://towardsdatascience.com/author/towardsdatascience/)\nFebruary 29, 20244 min read\n  * [![](https://assets.insightmediagroup.io/media/wp-content/uploads/2021/12/1VTBZF_CL0c0GZ0jshTTqVw.png)](https://towardsdatascience.com/regression-analysis-for-beginners-using-tree-based-methods-2b65bd193a7/)\n## [Regression Analysis for Beginners - Part 2](https://towardsdatascience.com/regression-analysis-for-beginners-using-tree-based-methods-2b65bd193a7/)\n[Machine Learning](https://towardsdatascience.com/category/artificial-intelligence/machine-learning/)\nBuild an ML Regression Model Using the Tree-based Algorithms (Decision Tree, Random Forest, XGboost)\n[Gurami Keretchashvili](https://towardsdatascience.com/author/gkeretchashvili/)\nDecember 25, 20219 min read\n  * [![](https://assets.insightmediagroup.io/media/wp-content/uploads/2026/05/ChatGPT-Image-May-22-2026-01_27_30-PM.jpg)](https://towardsdatascience.com/the-domain-shift-moving-data-governance-from-product-triage-to-infrastructure-investment/)\n## [The Domain Shift: Moving Data Governance from Product Triage to Infrastructure Investment](https://towardsdatascience.com/the-domain-shift-moving-data-governance-from-product-triage-to-infrastructure-investment/)\n[Data Governance](https://towardsdatascience.com/category/data-science/data-governance/)\nHow shifting the operational focus from isolated data products to systemic domain architecture resolves technical bottlenecks and optimizes platform investment.\n[Sravani Alle](https://towardsdatascience.com/author/alle-sravani/)\nMay 26, 20267 min read\n  * [![](https://assets.insightmediagroup.io/media/wp-content/uploads/2021/09/1juh0CR2VKdKPwZzZJcNoVw.png)](https://towardsdatascience.com/how-to-machine-leaning-pipeline-beginner-2a736595cbfd/)\n## [How to: Machine Learning Pipeline (Beginner)](https://towardsdatascience.com/how-to-machine-leaning-pipeline-beginner-2a736595cbfd/)\n[Machine Learning](https://towardsdatascience.com/category/artificial-intelligence/machine-learning/)\nWhen I first started on my machine learning journey, all I knew was how to code in Jupyter notebooks/google colab and run them. However, as...\n[Tan Kah Ming](https://towardsdatascience.com/author/kmt112/)\nSeptember 14, 20216 min read\n  * [![](https://assets.insightmediagroup.io/media/wp-content/uploads/2021/08/05pi5Q6Ko1swUW30b-scaled.jpg)](https://towardsdatascience.com/6-ways-to-maintain-a-healthy-relationship-as-a-data-scientist-706dd3bb4285/)\n## [6 Ways to Maintain a Healthy Relationship as a Data Scientist](https://towardsdatascience.com/6-ways-to-maintain-a-healthy-relationship-as-a-data-scientist-706dd3bb4285/)\n[Data Science](https://towardsdatascience.com/category/data-science/)\nHow to mitigate the negative impacts of screen time viewing\n[John Bica](https://towardsdatascience.com/author/bicaj/)\nAugust 20, 20216 min read\n  * [![](https://assets.insightmediagroup.io/media/wp-content/uploads/2022/10/0zWUNOvqToN4hMt0i-scaled.jpg)](https://towardsdatascience.com/different-ways-to-connect-google-drive-to-a-google-colab-notebook-part-2-b867786aed55/)\n## [Different Ways to Connect Google Drive to a Google Colab Notebook! (Part 2)](https://towardsdatascience.com/different-ways-to-connect-google-drive-to-a-google-colab-notebook-part-2-b867786aed55/)\n[Data Science](https://towardsdatascience.com/category/data-science/)\nCollaboratory ways of working with data using Google Colab\n[Sebastian Carmona A.](https://towardsdatascience.com/author/sebascar322/)\nOctober 1, 20225 min read\n  * [![](https://assets.insightmediagroup.io/media/wp-content/uploads/2020/09/1H1cvq2qrQrd0IOuCpVJK-g.png)](https://towardsdatascience.com/better-features-for-a-tree-based-model-d3b21247cdf2/)\n## [Better Features for a Tree-Based Model](https://towardsdatascience.com/better-features-for-a-tree-based-model-d3b21247cdf2/)\n[Machine Learning](https://towardsdatascience.com/category/artificial-intelligence/machine-learning/)\nWhat tree models can see, and what they can't\n[Agnis Liukis](https://towardsdatascience.com/author/agnis-liukis/)\nSeptember 17, 20208 min read\n  * [![](https://assets.insightmediagroup.io/media/wp-content/uploads/2022/02/0dlPMJ4knKBD9aa4e.png)](https://towardsdatascience.com/ive-built-a-public-world-atlas-with-2-500-datasets-to-explore-8b9ae799e345/)\n## [I've Built a Public World Atlas with 2,500 Datasets to Explore](https://towardsdatascience.com/ive-built-a-public-world-atlas-with-2-500-datasets-to-explore-8b9ae799e345/)\n[Data Science](https://towardsdatascience.com/category/data-science/)\nInspired by Encarta, built in Python, accessible at worldatlas.org\n[Dan Baker](https://towardsdatascience.com/author/danielbaker-190/)\nFebruary 19, 202234 min read\n\n\n  * [YouTube](https://www.youtube.com/c/TowardsDataScience)\n  * [X](https://x.com/TDataScience)\n  * [LinkedIn](https://www.linkedin.com/company/towards-data-science/)\n  * [Threads](https://www.threads.net/@towardsdatascience)\n  * [Bluesky](https://bsky.app/profile/towardsdatascience.com)\n\n\n[](https://towardsdatascience.com/)\nYour home for data science and AI. The world's leading publication for data science, data analytics, data engineering, machine learning, and artificial intelligence professionals.\nSubscribe to Our Newsletter[Write For TDS](https://towardsdatascience.com/submissions/)•[About](https://towardsdatascience.com/about-towards-data-science-d691af11cc2f/)•[Advertise](https://contact.towardsdatascience.com/advertise-with-towards-data-science)•[Privacy Policy](https://towardsdatascience.com/privacy-policy/)•[Terms of Use](https://towardsdatascience.com/website-terms-of-use/)\n© Insight Media Group, LLC 2026•[The New Stack](https://thenewstack.io)•[roadmap.sh](https://roadmap.sh)•[Creator Network](https://insightmediagroup.io/creator-network)\n####  Recommended Articles \nClose\n  * [ ![](https://h030.towardsdatascience.com/rest/v2/contentStores/d7d3a4ab-7caf-4383-bbd2-fbf7fb4f1787/items/3642/image?etag=1780830904480&width=500&height=500) Check Your Biases ](https://towardsdatascience.com/check-your-biases-ba2685a7f799/ \"Check Your Biases\")\n  * [ ![](https://h030.towardsdatascience.com/rest/v2/contentStores/d7d3a4ab-7caf-4383-bbd2-fbf7fb4f1787/items/607930/image?etag=1782124566054&width=500&height=500) The Subset Sum Problem Solved in Linear Time for Dense Enough Inputs ](https://towardsdatascience.com/subset-sum-problem-solved-in-linear-time-for-dense-enough-inputs/ \"The Subset Sum Problem Solved in Linear Time for Dense Enough Inputs\")\n  * [ ![](https://h030.towardsdatascience.com/rest/v2/contentStores/d7d3a4ab-7caf-4383-bbd2-fbf7fb4f1787/items/3660/image?etag=1780176246070&width=500&height=500) Does Your Company Have a Data Strategy? ](https://towardsdatascience.com/does-your-company-have-a-data-strategy-e8944dbec4ae/ \"Does Your Company Have a Data Strategy?\")\n  * [ ![](https://h030.towardsdatascience.com/rest/v2/contentStores/d7d3a4ab-7caf-4383-bbd2-fbf7fb4f1787/items/4973/image?etag=1782232567105&width=500&height=500) Machine Learning Tricks, Learning with ChatGPT, and Other Recent Must-Reads ](https://towardsdatascience.com/machine-learning-tricks-learning-with-chatgpt-and-other-recent-must-reads-f277648a1921/ \"Machine Learning Tricks, Learning with ChatGPT, and Other Recent Must-Reads\")\n\n\nword word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word\n  \nmmMwWLliI0fiflO&1  \nmmMwWLliI0fiflO&1  \nmmMwWLliI0fiflO&1  \nmmMwWLliI0fiflO&1  \nmmMwWLliI0fiflO&1  \nmmMwWLliI0fiflO&1  \nmmMwWLliI0fiflO&1\n",
  "metadata": {
    "title": "ExLlamaV2: The Fastest Library to Run LLMs | Towards Data Science",
    "description": "Quantize and run EXL2 models",
    "keywords": null,
    "author": "Maxime Labonne",
    "og:locale": "en_US",
    "og:type": "article",
    "og:title": "ExLlamaV2: The Fastest Library to Run LLMs",
    "og:description": "Quantize and run EXL2 models",
    "og:url": "https://towardsdatascience.com/exllamav2-the-fastest-library-to-run-llms-32aeda294d26/",
    "og:site_name": "Towards Data Science",
    "og:image": "https://assets.insightmediagroup.io/media/wp-content/uploads/2023/11/1irFhg_i_1lrYgvNcO2dIOw.jpeg",
    "og:image:width": "1920",
    "og:image:height": "1080",
    "og:image:type": "image/jpeg",
    "twitter:card": "summary_large_image",
    "twitter:site": "@TDataScience",
    "twitter:creator": "@TDataScience",
    "twitter:label1": "Written by",
    "twitter:data1": "Maxime Labonne",
    "twitter:label2": "Est. reading time",
    "twitter:data2": "6 min read",
    "article:published_time": "2023-11-20T03:17:18.000Z",
    "article:modified_time": "2023-11-20T03:17:18.000Z",
    "article:author": "https://towardsdatascience.com/author/mlabonne/"
  },
  "paywall": {
    "listed_paid": true,
    "detected": false,
    "marker": "",
    "public_only": true,
    "policy": "付费/会员内容只保留页面公开可见部分，不绕过付费墙"
  },
  "crawl": {
    "success": true,
    "status_code": 200,
    "error": "",
    "retried": true
  },
  "code_blocks": [
    {
      "language": "txt",
      "file": "attachments/157f79e3160e/code/block_000.txt",
      "chars": 71
    },
    {
      "language": "txt",
      "file": "attachments/157f79e3160e/code/block_001.txt",
      "chars": 78
    },
    {
      "language": "txt",
      "file": "attachments/157f79e3160e/code/block_002.txt",
      "chars": 133
    },
    {
      "language": "txt",
      "file": "attachments/157f79e3160e/code/block_003.txt",
      "chars": 122
    },
    {
      "language": "txt",
      "file": "attachments/157f79e3160e/code/block_004.txt",
      "chars": 480
    },
    {
      "language": "txt",
      "file": "attachments/157f79e3160e/code/block_005.txt",
      "chars": 100
    },
    {
      "language": "txt",
      "file": "attachments/157f79e3160e/code/block_006.txt",
      "chars": 65
    },
    {
      "language": "txt",
      "file": "attachments/157f79e3160e/code/block_007.txt",
      "chars": 812
    },
    {
      "language": "txt",
      "file": "attachments/157f79e3160e/code/block_008.txt",
      "chars": 55
    },
    {
      "language": "txt",
      "file": "attachments/157f79e3160e/code/block_009.txt",
      "chars": 300
    }
  ],
  "images": [
    {
      "src": "https://assets.insightmediagroup.io/media/wp-content/uploads/2023/11/1irFhg_i_1lrYgvNcO2dIOw.jpeg",
      "alt": "Image by author",
      "local_path": "attachments/157f79e3160e/images/000.jpeg",
      "bytes": 45716,
      "downloaded": true
    },
    {
      "src": "https://assets.insightmediagroup.io/media/wp-content/uploads/2021/11/1aTwZq7ceSHClNuAconBNig-scaled.jpeg",
      "alt": "",
      "local_path": "attachments/157f79e3160e/images/001.jpeg",
      "bytes": 535883,
      "downloaded": true
    },
    {
      "src": "https://assets.insightmediagroup.io/media/wp-content/uploads/2024/02/0B0MZCvpWBOwWsHBM-scaled.jpg",
      "alt": "",
      "local_path": "attachments/157f79e3160e/images/002.jpg",
      "bytes": 703065,
      "downloaded": true
    },
    {
      "src": "https://assets.insightmediagroup.io/media/wp-content/uploads/2021/12/1VTBZF_CL0c0GZ0jshTTqVw.png",
      "alt": "",
      "local_path": "attachments/157f79e3160e/images/003.png",
      "bytes": 66909,
      "downloaded": true
    },
    {
      "src": "https://assets.insightmediagroup.io/media/wp-content/uploads/2026/05/ChatGPT-Image-May-22-2026-01_27_30-PM.jpg",
      "alt": "",
      "local_path": "attachments/157f79e3160e/images/004.jpg",
      "bytes": 299589,
      "downloaded": true
    },
    {
      "src": "https://assets.insightmediagroup.io/media/wp-content/uploads/2021/09/1juh0CR2VKdKPwZzZJcNoVw.png",
      "alt": "",
      "local_path": "attachments/157f79e3160e/images/005.png",
      "bytes": 22584,
      "downloaded": true
    },
    {
      "src": "https://assets.insightmediagroup.io/media/wp-content/uploads/2021/08/05pi5Q6Ko1swUW30b-scaled.jpg",
      "alt": "",
      "local_path": "attachments/157f79e3160e/images/006.jpg",
      "bytes": 299673,
      "downloaded": true
    },
    {
      "src": "https://assets.insightmediagroup.io/media/wp-content/uploads/2022/10/0zWUNOvqToN4hMt0i-scaled.jpg",
      "alt": "",
      "local_path": "attachments/157f79e3160e/images/007.jpg",
      "bytes": 245678,
      "downloaded": true
    },
    {
      "src": "https://assets.insightmediagroup.io/media/wp-content/uploads/2020/09/1H1cvq2qrQrd0IOuCpVJK-g.png",
      "alt": "",
      "local_path": "attachments/157f79e3160e/images/008.png",
      "bytes": 119220,
      "downloaded": true
    },
    {
      "src": "https://assets.insightmediagroup.io/media/wp-content/uploads/2022/02/0dlPMJ4knKBD9aa4e.png",
      "alt": "",
      "local_path": "attachments/157f79e3160e/images/009.png",
      "bytes": 1019931,
      "downloaded": true
    }
  ],
  "audio": [],
  "videos": [],
  "links": [],
  "retry_at": "2026-10-03T07:59:17",
  "repair_version": 2,
  "repaired_at": "2026-10-14T11:11:48Z",
  "source_url": "https://towardsdatascience.com/exllamav2-the-fastest-library-to-run-llms-32aeda294d26/",
  "delivery_status": "excluded_paid",
  "discovery_status": "excluded_paid",
  "missing_reason": "按原约定排除付费/会员全文"
}