Skip to content
Skills Library
AI & agents · Building & coding

environment-setup-pytorch

/environment-setup-pytorch

Set up Python environment for PyTorch-based NLP projects with transformers and alignment training. Use this skill when initializing project environments, managing dependencies from environment.yml files, installing required packages, and ensuring CUDA/device compatibility. Essential for reproducible machine learning research requiring specific package versions.

Licence
MIT
Last repository change
02.10.2026

Assessment and security

100/ 100Class: good
Format25 / 25
Frontmatter with name and description, valid name, description up to 1,024 characters, name matching the folder.
Discoverability25 / 25
Description explains when to use the skill, has a reasonable length and uses third person.
Content35 / 35
At least 150 words and at most 500 lines, headings, step lists, examples or code.
Hygiene15 / 15
No placeholders such as TODO, no Windows paths, with a licence.
Riskno signals detected in the scan
Files in this package
1
Scripts
0
HTML comments
0
URLs in SKILL.md
2
Deprecation

No signals detected. Repository changed on 02.10.2026, without references to retired models or APIs.

Licence

MIT, open: use and modify while retaining author attribution.

What it does and when to use it

Set up Python environment for PyTorch-based NLP projects with transformers and alignment training. Use this skill when initializing project environments, managing dependencies from environment.yml files, installing required packages, and ensuring CUDA/device compatibility. Essential for reproducible machine learning research requiring specific package versions.

Original author description

Set up Python environment for PyTorch-based NLP projects with transformers and alignment training. Use this skill when initializing project environments, managing dependencies from environment.yml files, installing required packages, and ensuring CUDA/device compatibility. Essential for reproducible machine learning research requiring specific package versions.

How it works

  1. Overview
  2. Environment Setup Workflow
  3. Common Packages for Alignment Training
  4. Dependency Conflict Resolution
  5. Reproducibility Best Practices
  6. Environment Variables
  7. Troubleshooting
  8. Project-Specific Setup
Original SKILL.md headings · 242 lines, 785 words
SKILL.md preview
---
name: environment-setup-pytorch
description: Set up Python environment for PyTorch-based NLP projects with transformers and alignment training. Use this skill when initializing project environments, managing dependencies from environment.yml files, installing required packages, and ensuring CUDA/device compatibility. Essential for reproducible machine learning research requiring specific package versions.
---

# Environment Setup for PyTorch Projects

## Overview

This skill covers setting up a complete Python environment for PyTorch-based NLP and language model alignment training, including dependency management and device verification.

## Environment Setup Workflow

### Step 1: Identify Environment Configuration Files

Check for conda/pip configuration files:
- `environment.yml` - Conda environment specification
- `requirements.txt` - Pip requirements
- `setup.py` - Package setup configuration
- `pyproject.toml` - Modern Python project config

### Step 2: Choose Installation Method

#### Option A: Conda Environment
```bash
# Create environment from YAML
conda env create -f environment.yml

# Activate environment
conda activate <env_name>
```

Benefits:
- Manages both Python and system dependencies
- Consistent across platforms
- Handles CUDA toolkit versions

#### Option B: Pip with Virtual Environment
```bash
# Create virtual environment
python -m venv venv
source venv/bin/activate  # Linux/Mac
# or: venv\Scripts\activate  # Windows

# Install requirements
pip install -r requirements.txt
```

#### Option C: Direct Pip Installation
```bash
# Install specific packages
pip install torch torchvision torchaudio
pip install transformers datasets accelerate peft
```

### Step 3: Verify Python Version and Packages

Get detailed environment information:
```bash
python -VV                      # Detailed Python version
python -m pip freeze           # All installed packages with versions
python -m pip show torch       # Specific package info
python -c "import torch; print(torch.__version__)"
```

### Step 4: Check CUDA/Device Availability

Verify GPU access for training:
```bash
python -c "import torch; print(f'CUDA available: {torch.cuda.is_available()}'); print(f'Device: {torch.cuda.get_device_name(0) if torch.cuda.is_available() else \"CPU\"}')"
```

### Step 5: Install Project in Development Mode

For local project development:
```bash
pip install -e .
# or for projects with setup.py
python setup.py develop
```

## Common Packages for Alignment Training

### Core PyTorch Stack
- `torch`: Deep learning framework
- `torchvision`: Computer vision utilities
- `torchaudio`: Audio processing
- `pytorch-cuda`: CUDA runtime (if using conda)

### NLP and Transformers
- `transformers`: Hugging Face models and utilities
- `tokenizers`: Fast tokenizer library
- `datasets`: Dataset loading and processing
- `accelerate`: Multi-GPU/device training utilities

### Alignment and Training
- `peft`: Parameter-Efficient Fine-Tuning (LoRA, etc.)
- `trl`: Transformers Reinforcement Learning
- `bitsandbytes`: 8-bit optimization utilities
- `flash-attn`: Optimized attention (optional, for efficiency)

### Development Tools
- `numpy`: Numerical computing
- `scipy`: Scientific computing
- `scikit-learn`: Machine learning utilities
- `wandb`: Weights & Biases experiment tracking (optional)

## Dependency Conflict Resolution

### Check for Conflicts
```bash
pip check
```

### Resolve Common Issues

#### PyTorch Version Mismatch
```bash
# Reinstall PyTorch with specific CUDA version
pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu118
# For CPU-only
pip install torch torchvision torchaudio
```

#### Package Incompatibilities
```bash
# Use environment solver
conda install --solver=libmamba  # Faster solver
# or
pip install --upgrade --upgrade-strategy eager <package>
```

#### Remove Conflicting Packages
```bash
pip uninstall -y <package_name>
pip install <package_name>==<specific_version>
```

### Conda Environment from File
When using conda with environment.yml, sometimes recreating helps:
```bash
# Backup current environment
conda env export > backup_env.yml

# Remove and recreate
conda env remove --name <env_name>
conda env create -f environment.yml
```

## Reproducibility Best Practices

### 1. Lock Dependency Versions
```bash
pip freeze > requirements-lock.txt
conda env export > env-lock.yml
```

### 2. Document Environment Information
Always log:
- Python version and build (`python -VV`)
- Key package versions (torch, transformers, cuda)
- Hardware details (GPU model, CPU)

```bash
# Create comprehensive environment log
{
    echo "=== Python Version ==="
    python -VV
    echo
    echo "=== Package Freeze ==="
    python -m pip freeze
    echo
    echo "=== PyTorch Info ==="
    python -c "import torch; print(f'PyTorch: {torch.__version__}'); print(f'CUDA Available: {torch.cuda.is_available()}')"
} > environment_info.txt
```

### 3. Test Critical Imports
```python
import torch
import transformers
from datasets import load_dataset
from peft import get_peft_model
print("All critical imports successful!")
```

## Environment Variables

### CUDA Configuration
```bash
export CUDA_VISIBLE_DEVICES=0,1,2,3  # Specify GPUs
export CUDA_LAUNCH_BLOCKING=1         # Synchronous GPU operations (for debugging)
```

### Training Configuration
```bash
export HF_DATASETS_CACHE=/path/to/cache  # Hugging Face cache
export TRANSFORMERS_CACHE=/path/to/cache
export TOKENIZERS_PARALLELISM=false      # Avoid warnings
```

### Debugging
```bash
export PYTHONUNBUFFERED=1  # Real-time output
export PYTHONBREAKPOINT=ipdb.set_trace  # Use ipdb for breakpoints
```

## Troubleshooting

### Import Errors
```bash
# Reinstall with no cache
pip install --no-cache-dir --force-reinstall <package>

# Check installation location
python -c "import <module>; print(<module>.__file__)"
```

### CUDA/Device Errors
```bash
# Verify CUDA installation
python -c "import torch; torch.cuda.is_available()"

# Check CUDA version
nvcc --version

# Match PyTorch CUDA version to installed CUDA
```

### Memory Issues
```bash
# Install CPU-only version for testing
pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cpu
```

## Project-Specific Setup

For SimPO and similar training projects:

1. Check `environment.yml` for required versions
2. Create conda environment if file exists
3. Verify transformers and torch compatibility
4. Confirm CUDA/device availability
5. Install project in dev mode if setup.py exists
6. Log all environment details for reproducibility

Versions

The database has no other skills named environment-setup-pytorch.

Database snapshot: 13.11.2026 · package version db4a9e342d09 (SHA-256 digest of the entire package)

Downloads in the last 30 days: 2 · ranking

Report a problem with this skill: harmful content, incorrect descriptions or an author’s removal request.

Similar skills

  • 100pytorch
    Assists with building, training, and deploying neural networks using PyTorch. Use when designing architectures for computer vision, NLP, or tabular data, optimizing training with mixed precision and distributed strategies, or exporting models for production inference. Trigger…
  • 100spark-environment-setup
    Set up a working ML training/inference environment on NVIDIA DGX Spark (GB10, aarch64, CUDA 13). Use when installing PyTorch/Unsloth/TRL/vLLM on DGX Spark, hitting libcudart or wheel-ABI errors on aarch64, or choosing between NGC containers and bare pip installs.
  • 100reproducible-ml
    Use when an ML result must be reproducible — fixing seeds, pinning environments, versioning data, and structuring projects so runs can be exactly recreated. Covers determinism gotchas across NumPy, PyTorch, and CUDA.
  • 100pytorch-model-trainer
    Build pytorch model trainer operations. Auto-activating skill for ML Training. Triggers on: pytorch model trainer, pytorch model trainer Part of the ML Training skill category. Use when working with pytorch model trainer functionality. Trigger with phrases like "pytorch model…
  • 100pytorch-patterns
    PyTorch deep learning patterns and best practices for building robust, efficient, and reproducible training pipelines, model architectures, and data loading. Use when writing or reviewing PyTorch training loops, model architectures, or data loading, or when a run will not reproduce.
  • 100pytorch-testing-logging
    Run PyTorch unit tests, save results to NumPy files, and log environment information for reproducibility. Use this skill when executing test suites for neural network functions, validating loss computations, saving tensor outputs for verification, and creating reproducibility…

Feedback and reports

Your message goes to Bartosz Sokoliński. An email address is needed only for a reply. See the privacy policy.