Setting Up Your Environment
This comprehensive guide will walk you through creating the optimal development environment for working with AI and Large Language Models (LLMs).
Prerequisites
Before you begin, ensure you have:
- A computer with at least 8GB RAM (16GB+ recommended)
- Administrator/sudo access to your system
- Basic familiarity with command line interfaces
Installing Python
LLM development typically requires Python 3.8 or newer.
Windows Installation
- Download Python:
- Visit python.org
- Download the latest Python 3.x installer
- Ensure you check “Add Python to PATH” during installation
- Verify Installation:
python --version
macOS Installation
- Using Homebrew (recommended):
brew install python
- Alternative Method:
- Download from python.org
- Run the installer package
- Verify Installation:
python3 --version
Linux Installation
Most Linux distributions come with Python pre-installed. If not:
sudo apt update
sudo apt install python3 python3-pip
Verify with:
python3 --version
Setting Up Virtual Environments
Virtual environments keep dependencies organized and prevent conflicts.
Creating a Virtual Environment
# Install virtualenv if not already installed
pip install virtualenv
# Create a new environment
virtualenv llm_env
# Activate the environment
# On Windows:
llm_env\Scripts\activate
# On macOS/Linux:
source llm_env/bin/activate
Using Conda (Alternative)
- Install Miniconda:
- Download from conda.io
- Follow installation instructions
- Create a Conda Environment:
conda create -n llm_env python=3.10 conda activate llm_env
Installing Essential Libraries
With your environment activated, install these core packages:
pip install numpy pandas matplotlib scikit-learn torch transformers datasets
For additional LLM-specific tools:
pip install accelerate bitsandbytes sentencepiece tokenizers
GPU Setup (Optional but Recommended)
NVIDIA GPU Setup
- Install CUDA Toolkit:
- Download from NVIDIA Developer site
- Follow installation instructions for your OS
- Install cuDNN:
- Register at NVIDIA Developer Program
- Download and install cuDNN
- Install PyTorch with CUDA support:
pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu118
(Adjust CUDA version as needed)
- Verify GPU availability:
import torch print(f"CUDA available: {torch.cuda.is_available()}") print(f"CUDA device count: {torch.cuda.device_count()}") print(f"CUDA device name: {torch.cuda.get_device_name(0)}")
AMD GPU Setup
For AMD GPUs, use ROCm:
- Install ROCm:
- Follow instructions at ROCm Documentation
- Install PyTorch with ROCm support:
pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/rocm5.4.2
IDE Setup
Choose a development environment that suits your workflow:
VS Code (Recommended)
- Install VS Code:
- Download from code.visualstudio.com
- Install extensions:
- Python extension
- Jupyter extension
- IntelliCode
- Pylance
- Configure settings:
- Set your Python interpreter to your virtual environment
- Enable linting and formatting
PyCharm
- Install PyCharm:
- Download Community Edition from jetbrains.com
- Configure Python interpreter:
- File > Settings > Project > Python Interpreter
- Add your virtual environment
- Install plugins:
- Jupyter
- .env file support
Jupyter Notebooks
For exploratory work:
pip install jupyter
jupyter notebook
Version Control Setup
- Install Git:
- Configure Git:
git config --global user.name "Your Name" git config --global user.email "your.email@example.com"
- Connect to GitHub/GitLab:
- Generate SSH key:
ssh-keygen -t ed25519 -C "your.email@example.com"
- Add key to GitHub/GitLab account
- Generate SSH key:
Model Caching and Storage
Configure Hugging Face cache location:
# On Windows
setx HF_HOME "D:\AI\huggingface"
# On macOS/Linux
echo 'export HF_HOME="/path/to/storage"' >> ~/.bashrc
source ~/.bashrc
Testing Your Environment
Create a simple test script:
# test_environment.py
import sys
import torch
import transformers
print(f"Python version: {sys.version}")
print(f"PyTorch version: {torch.__version__}")
print(f"Transformers version: {transformers.__version__}")
# Test loading a small model
from transformers import pipeline
classifier = pipeline('sentiment-analysis', device=0 if torch.cuda.is_available() else -1)
result = classifier("This environment setup is working great!")
print(result)
Run it:
python test_environment.py
Troubleshooting Common Issues
Package Installation Failures
- Update pip:
pip install --upgrade pip
- Install build tools:
- Windows:
pip install wheel
- Linux:
sudo apt install build-essential
- Windows:
CUDA Not Detected
- Verify CUDA installation:
nvcc --version
- Check GPU compatibility
- Ensure matching CUDA toolkit and PyTorch versions
Memory Issues
- Close unnecessary applications
- Use smaller model variants
- Enable model optimization techniques like quantization
Next Steps
Now that your environment is set up, you’re ready to:
- Explore our Basic Customization tutorial
- Learn advanced capabilities in our Advanced Features tutorial