Overview
This guide will help you set up your environment to run all the code examples from the book. We provide multiple setup options to accommodate different preferences and hardware configurations.Recommended for Beginners: We strongly recommend using Google Colab for the easiest setup. All examples in the book were built and tested using Google Colab with a free T4 GPU (16GB VRAM).
Setup Options
You can choose from three main approaches:- Cloud-based (Recommended): Google Colab with free GPU access
- Local with Conda: Full control with version-managed environment
- Local with pip: Quick setup if you already have Python 3.10
Cloud Setup (Google Colab)
Google Colab provides free access to GPUs and comes with most dependencies pre-installed, making it the most stable and hassle-free option.Open a Chapter Notebook
Click on any “Open in Colab” badge from the book’s repository table of contents.
Enable GPU Runtime
In Google Colab, navigate to:Runtime → Change runtime type → Hardware accelerator → GPU → GPU type → T4
Install Chapter Dependencies
Each notebook includes an installation cell at the top. Uncomment and run it to install required packages.For example, Chapter 1 requires:
Local Setup with Conda
Conda provides the most reliable local setup with full version control and dependency management. This method does not require separate C++ compiler installation.Prerequisites
- Storage: At least 10GB free disk space
- RAM: 8GB minimum (16GB recommended)
- GPU: NVIDIA GPU with CUDA support (optional but highly recommended)
Install Miniconda
Download and install Miniconda with Python 3.10 for your operating system.
Install PyTorch with GPU Support
Visit pytorch.org and select your configuration to get the appropriate installation command.For CUDA 11.8 (most common):
The
--upgrade flag ensures the CPU version is replaced with the GPU version.Local Setup with pip
For users who already have Python 3.10 installed and want a quick setup.Install PyTorch GPU
Follow the same PyTorch installation steps from the Conda setup.
Core Dependencies
The following packages are required throughout the book:| Category | Packages | Purpose |
|---|---|---|
| Deep Learning | torch==2.3.1transformers==4.41.2sentence-transformers==3.0.1 | Core LLM framework |
| Data Processing | numpy==1.26.4pandas==2.2.2datasets==2.20.0 | Data manipulation |
| Visualization | matplotlib==3.9.0 | Plotting and visualization |
| ML Tools | scikit-learn==1.5.0evaluate==0.4.2scipy>=1.15.0 | Machine learning utilities |
| NLP | sentencepiece==0.2.0nltk==3.8.1 | Text processing |
| Environment | jupyterlab==4.2.2ipywidgets==8.1.3 | Interactive notebooks |
Chapter-Specific Dependencies
Some chapters require additional packages:GPU Requirements
While you can run some examples on CPU, most chapters require GPU acceleration for practical performance.Minimum Requirements
- VRAM: 4GB (6GB+ recommended)
- CUDA: Version 11.8 or later
- GPU Examples: NVIDIA RTX 3060, T4 (Colab), A10G, or better
Cloud Alternatives
If you don’t have a local GPU:| Platform | GPU Options | Free Tier | Notes |
|---|---|---|---|
| Google Colab | T4 (16GB) | ✅ Yes | Recommended, session limits |
| Kaggle | P100 (16GB), T4 | ✅ Yes | 30 hours/week free |
| AWS SageMaker | Various | 🟡 Limited | ml.t3.medium free tier |
| Azure ML | Various | 🟡 Limited | Some free credits |
| Paperspace | Various | ❌ No | Affordable hourly rates |
Troubleshooting
”Microsoft Visual C++ 14.0 or greater is required”
This error occurs on Windows when installing packages that need compilation.Download Build Tools
Visit visualstudio.microsoft.com/visual-cpp-build-tools and click “Download Build Tools”.
CUDA Not Available
Iftorch.cuda.is_available() returns False:
-
Verify GPU drivers: Update to the latest NVIDIA drivers
-
Reinstall PyTorch: Make sure you installed the CUDA version
- Check CUDA compatibility: Your GPU must support CUDA 11.8 or later
Out of Memory Errors
If you get CUDA out-of-memory errors:Package Version Conflicts
If you encounter version conflicts:JupyterLab Kernel Issues
If JupyterLab doesn’t show the correct kernel:Import Errors
If you get import errors:-
Verify environment: Make sure you’re in the correct conda environment
-
Reinstall package: Try reinstalling the problematic package
-
Check dependencies: Some packages need others to be installed first
Next Steps
Once your environment is set up:- Start with Chapter 1: Introduction to Language Models
- Review the Prerequisites to ensure you have the necessary background
- Join the community discussions on GitHub
