<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet type="text/xsl" href="https://www.mindfiretechnology.com/blog/rss/xslt"?>
<rss xmlns:a10="http://www.w3.org/2005/Atom" version="2.0">
  <channel>
    <title>Mindfire Technology</title>
    <link>https://www.mindfiretechnology.com/blog/</link>
    <description>Welcome to our blog, where we share technical and business knowledge based on real life experiences.</description>
    <generator>Articulate, blogging built on Umbraco</generator>
    <item>
      <guid isPermaLink="false">2327</guid>
      <link>https://www.mindfiretechnology.com/blog/archive/installing-bitsandbtyes-for-windows-so-that-you-can-do-peft/</link>
      <category>System.String[]</category>
      <title>Installing BitsAndBtyes for Windows - So That You Can Do PEFT</title>
      <description>&lt;p&gt;When working with the Huggingface ecosystem, you may find tutorials that have you install a library called ‘bitsandbytes’. Particularly if you want to do PEFT or LORA to fine tune your own Large Language Models (LLMs). This should be as easy as: &lt;/p&gt;
&lt;pre&gt;&lt;code&gt;pip install bitsandbytes
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;But if you are in Windows (rather than Linux) you’ll quickly find that you get errors. I often get this error:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;CUDA_SETUP: WARNING! libcudart.so not found in any environmental path. Searching in backup paths...
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Or possibly this error:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;CUDA Setup failed despite GPU being available. Please run the following command to get more information:

python -m bitsandbytes
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Inspect the output of the command and see if you can locate CUDA libraries. You might need to add them to your &lt;code&gt;LD_LIBRARY_PATH&lt;/code&gt;. If you suspect a bug, please take the information from python -m bitsandbytes and open an issue at: &lt;a href="https://github.com/TimDettmers/bitsandbytes/issues"&gt;https://github.com/TimDettmers/bitsandbytes/issues&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;Not Windows Compatible?&lt;/h2&gt;
&lt;p&gt;It turns out that bitsandbytes isn’t yet compatible with Windows (as of this article's publication), and only works in Linux. So, are you just out of luck in Windows?&lt;/p&gt;
&lt;p&gt;One possibility you might come across if you search the Internet is that you might be able to install a custom Windows version created by Tim Dettmers by using this suggested command:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;python -m pip install bitsandbytes --prefer-binary --extra-index-url=https://jllllll.github.io/bitsandbytes-windows-webui
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;However, if you are like me, this didn’t work for you. It turns out that it’s a bit sensitive and if you have anything it doesn’t want it may not work. After trial and error, we managed to get it to work by following this order.&lt;/p&gt;
&lt;h2&gt;Script To Install BitsAndBytes for Windows&lt;/h2&gt;
&lt;p&gt;First, start with a fresh Conda (this may also work with a fresh virtual environment for Python, though we haven’t tried that yet). We know it works with a fresh Conda with basically nothing installed. &lt;/p&gt;
&lt;p&gt;Now presumably you’ll need Pytorch if you are going to do anything useful with bitsandbytes, so start by installing Pytorch using this URL:&lt;/p&gt;
&lt;p&gt;&lt;a href="https://pytorch.org/get-started/locally/"&gt;https://pytorch.org/get-started/locally/&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Here is the conda they suggested there for us:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;conda install pytorch torchvision torchaudio pytorch-cuda=12.1 -c pytorch -c nvidia
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Next, you’ll want to install Huggingface transformers library integrated with pytorch. Here is the relevant URL on how to do that: &lt;/p&gt;
&lt;p&gt;&lt;a href="https://huggingface.co/docs/transformers/installation"&gt;https://huggingface.co/docs/transformers/installation&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Here is the pip we used:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;pip install transformers vs pip install 'transformers[torch]' vs conda install conda-forge::transformers
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Now install Huggingface Hub:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;python -m pip install huggingface_hub
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Next install PEFT. Here is the URL that explains how: &lt;/p&gt;
&lt;p&gt;&lt;a href="https://huggingface.co/docs/peft/install"&gt;https://huggingface.co/docs/peft/install&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;I used this pip:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;pip install peft
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Next, you’ll need Cuda for Windows. Here is the URL that explains how:&lt;/p&gt;
&lt;p&gt;&lt;a href="https://docs.nvidia.com/cuda/cuda-installation-guide-microsoft-windows/index.html"&gt;https://docs.nvidia.com/cuda/cuda-installation-guide-microsoft-windows/index.html&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;I did this one via Conda:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;conda install cuda -c nvidia
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Verify that you now have cuda working by doing this:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;import torch
Torch.cuda.is_available() (Returns True)
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Also, you can verify you do NOT have bitsandbytes yet doing this:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;import transformers
transformers.is_bitsandbytes_available() (Returns False)
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Finally, we’re ready for bitsandbytes. Here is a custom version for Windows by Tim Dettmers as explained here:&lt;/p&gt;
&lt;p&gt;&lt;a href="https://github.com/TimDettmers/bitsandbytes/issues/822"&gt;https://github.com/TimDettmers/bitsandbytes/issues/822&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Here is the command that worked for me:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;python.exe -m pip install https://github.com/jllllll/bitsandbytes-windows-webui/releases/download/wheels/bitsandbytes-0.41.1-py3-none-win_amd64.whl
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Now check &lt;code&gt;transformers.is_bitsandbytes_available()&lt;/code&gt; and it should now be True.&lt;/p&gt;
&lt;p&gt;And that’s it! You now have bitsandbytes installed for Windows!&lt;/p&gt;
&lt;p&gt;However, one word of warning: This is actually an older version than the current version- so, I can’t vouch for how well it will work (comparatively speaking).&lt;/p&gt;
</description>
      <pubDate>Tue, 26 Mar 2024 09:00:00 -0600</pubDate>
      <a10:updated>2024-03-26T09:00:00-06:00</a10:updated>
    </item>
  </channel>
</rss>