Let’s jump straight into the core. Building your base brain to jumpstart your own personal Replicant. The foundation for the AI Fine-Tuning.
Goal: This document outlines the fundamental steps and tools required to set up an environment for fine-tuning Large Language Models (LLMs), with a focus on practical application and local development on NVIDIA GPUs.
What You Need (The Essentials):
The Base AI Model: A powerful open-source Language Model you'll adapt. In our case, Mistral-7B-Instruct-v0.3. [My reasoning for Mistral: To support Parameter-Efficient Fine-Tuning (PEFT) with LoRA (Low-Rank Adaption) capability.
Your Computer's Brain (Python): This is the main language your computer speaks and the foundation for all AI work.
The "Robot Training Kit" (Python Libraries): These are specialized collections of Python code (called libraries or packages) like transformers, peft, bitsandbytes, torch, accelerate, trl, and datasets. They extend Python's capabilities to manage, train, and optimize your AI model.
JupyterLab: Your interactive workbench for writing, running, and experimenting with your AI code.
Your Special Data: The new "lessons" you'll give the robot (e.g., specific text examples, image data for textures).
A "Super Calculator" (NVIDIA GPU): This is the most crucial part for speeding up training and handling large models.
GPU Guide (VRAM is Key!):
In this chapter, I’ll help you with the first three major steps to enter my digital oblivion:
Install Python
Creating & Activating a Virtual Environment
Installing Python Libraries for your VE
1. Install Python and the listed libraries
This guide covers installing Python 3.11.x, which is great for AI/ML projects.
Download the Python Installer:
Go to the official Python website: python.org/downloads/
Find the latest Python 3.11.x version (e.g., Python 3.11.9) and download the "Windows installer (64-bit)".
Run the Installer (Crucial Steps!):
Double-click the downloaded .exe file.
MOST IMPORTANT: On the very first screen, make sure to check the box that says "Add python.exe to PATH" at the bottom. This lets you run Python commands from any folder in CMD.
Click "Customize installation".
Go through the next screens, and on the "Advanced Options" screen (or similar), choose a clean, easy-to-find install location like C:\Python311 or D:\Python311. Avoid the default AppData path or Program Files for smoother future use.
Click "Install" and let it complete.
Verify Installation in Command Prompt (CMD):
Open a BRAND NEW Command Prompt window (important to pick up PATH changes).
Type: python --version and press Enter.
Expected Result: You should see Python 3.11.x (e.g., Python 3.11.9).
If you see the correct version, Python is successfully installed and ready to go for your projects!
Note: I recommend using an older version of Python, since some libraries are not always supported by the latest version.
Creating & Activating a Virtual Environment
This guide shows you how to set up an isolated environment for your project, a crucial step after Python is installed. It is important to setup your desired organized folder structure. For this example, I use the following hierarchy:
D:\Projects_Python\ <-- Your main folder for all Python projects
├── Project_001\ <-- A specific project's folder
│ └── venv\ <-- The virtual environment for Project_001
│ ├── your_script.py <-- Your project's Python code
│ └── your_notebook.ipynb <-- Your Jupyter Notebooks
├── Project_002\ <-- Another specific project's folder
│ └── venv\ <-- The virtual environment for Project_002
└── Project_003\ <-- And so on...
The most common, most logical, and highly recommended best practice for organizing Python projects, especially those involving complex dependencies like AI/ML.
Organization is logical and superior for these reasons:
Clear Separation: It clearly separates your actual project code (scripts, notebooks, data, configuration) from the internal files of the virtual environment.
Easy Sharing/Backup: If you want to share Project_001 with someone, you just share the Project_001 folder (excluding the venv folder, which is easily recreated by the recipient).
Clean Environment Management: When you need to delete and recreate a virtual environment (e.g., if it gets corrupted or you want to start fresh with dependencies), you simply delete the venv folder within that specific project, without touching any of your project's code or data.
Logical Containment: The virtual environment (venv) truly belongs to its specific Project_00X folder.
This structure is what the python -m venv command is most naturally designed for when executed from inside your Project_00X folder.
Steps to Create & Activate a Virtual Environment for "Project_001":
Create Your Specific Project Folder ("Project_001"):
Manually create a new folder named Project_001 inside D:\Projects_Python\.
Example Path: D:\Projects_Python\Project_001
Open Command Prompt (or PowerShell):
Open a new CMD or PowerShell window.
Navigate to Your Specific Project Folder ("Project_001"):
Use the cd command to enter the Project_001 folder you just created.
Example: d: (to switch to D: drive) then cd Projects_Python\Project_001
Your terminal should now show: D:\Projects_Python\Project_001>
Create the Virtual Environment within Your Project Folder ("Project_001"):
While your CMD/PowerShell is inside your Project_001 folder, type this command and press Enter:
DOS
python -m venv venv
(This will create a new sub-folder named venv directly inside D:\Projects_Python\Project_001, which is your fully self-contained virtual environment.)
Activate the Virtual Environment:
In the same CMD/PowerShell window, type this command and press Enter:
DOS
venv\Scripts\activate
(If using PowerShell, you might need .\venv\Scripts\activate.)
Verify Activation:
Your command prompt should now display (venv) at the beginning of the line (e.g., (venv) D:\Projects_Python\Project_001>). This confirms the environment is active.
To further verify it's using this specific Python installation, type: python --version
Expected Result: It should show the Python version (e.g., Python 3.11.x) from within your active virtual environment.
You have now successfully created and activated an isolated virtual environment named venv for your specific project (Project_001)!
Your virtual environment is now ready for you to install project-specific libraries!
Installing Python Libraries for your Virtual Environment
his guide shows you how to install the specialized "toolboxes" you'll need into your project's specific virtual environment.
Activate Your Project's Virtual Environment (venv):
Crucial: Ensure your virtual environment for Project_001 is active. Your Command Prompt (or PowerShell) should show (venv) at the beginning of the line (e.g., (venv) D:\Projects_Python\Project_001>).
If it's not active, navigate to D:\Projects_Python\Project_001 and activate it: venv\Scripts\activate (or .\venv\Scripts\activate for PowerShell).
Install PyTorch (with CUDA support):
This is the powerful engine that uses your NVIDIA GPU. You need the version compatible with your CUDA drivers (which we identified as 12.x).
Type this command and press Enter:
DOS
pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu121
(This download is large and will take some time. Wait until it completes and your prompt reappears.)
Install Other AI Libraries:
These are the main tools for working with LLMs, efficient training, and data handling.
Type this single command and press Enter:
DOS
pip install transformers peft bitsandbytes accelerate trl datasets sentencepiece protobuf
(This will also take some time as it installs several packages. Wait until it completes and your prompt reappears.)
Verification: After both commands finish, you can quickly check if the key libraries are installed:
In your active terminal, type pip list and press Enter. You should see torch, transformers, peft, bitsandbytes, accelerate, trl, datasets, sentencepiece, and protobuf listed with their versions.
All your essential AI libraries are now installed within your isolated project environment (D:\Projects_Python\Project_001\venv)!
We’ll continue with the next steps creating your Hugging Face Account & Getting Your Authenrication Token.