Overview
This guide shows how to run Jupyter notebooks in VS Code using SLURM computational resources on a cluster environment.
Prerequisites
- VS Code with Remote SSH extension
- Connected to the cluster via VS Code Remote SSH
- Python environment with Jupyter installed
Method 1: Interactive Session with JupyterLab Server (Recommended)
Step 1: Request Interactive SLURM Session
In VS Code terminal, run:
srun --partition=gpu_devel --gres=gpu:1 --mem=32G --cpus-per-task=4 --time=05:00:00 --pty bashResource Options:
--partition=gpu_devel- Development partition with GPU--partition=cpu- CPU-only partition (for data analysis)--partition=gpu_h200- Production GPU partition--mem=16G- Adjust memory as needed--cpus-per-task=2- Adjust CPU cores as needed--time=02:00:00- Adjust time limit as needed
Step 2: Start JupyterLab
Once in the interactive session:
jupyter lab --no-browser --port=8888 --ip=0.0.0.0 --allow-rootNote the output: Copy the URL with token (e.g., http://localhost:8888/?token=abc123...)
Step 3: Connect VS Code to Jupyter Server
- Open your
.ipynbfile in VS Code - Click “Select Kernel” in the top-right corner
- Choose “Existing Jupyter Server”
- Paste the Jupyter URL from Step 2
- VS Code will connect and you can run cells directly!
Method 2: Direct Python Kernel (No Jupyter Server)
Step 1: Get Interactive Session
srun --partition=gpu_devel --gres=gpu:1 --mem=32G --cpus-per-task=4 --time=05:00:00 --pty bashStep 2: Use VS Code’s Built-in Jupyter
- Open your
.ipynbfile in VS Code - Click “Select Kernel”
- Choose “Python Environments”
- Select the Python interpreter from the compute node
- Run cells directly - no server needed!
Method 3: One-liner Launch
For quick setup:
srun --partition=gpu_devel --gres=gpu:1 --mem=32G --cpus-per-task=4 --time=05:00:00 --pty bash -c "
cd /path/to/your/project &&
jupyter lab --no-browser --port=8888 --ip=0.0.0.0 --allow-root
"Common Resource Configurations
For Data Analysis (No GPU needed)
srun --partition=cpu --mem=16G --cpus-per-task=2 --time=02:00:00 --pty bashFor ML Training (GPU required)
srun --partition=gpu_h200 --gres=gpu:1 --mem=32G --cpus-per-task=4 --time=08:00:00 --pty bashFor Large Dataset Processing
srun --partition=gpu_h200 --mem=64G --cpus-per-task=8 --time=04:00:00 --pty bashTroubleshooting
Error: QOSMinGRES
- Issue: GPU partition requires GPU resources
- Solution: Add
--gres=gpu:1or use CPU partition
Error: Port already in use
- Solution: Use different port:
--port=8889or--port=8890
Error: Unable to allocate resources
- Solution: Reduce resource requirements or try different partition
Connection Issues
- Check: VS Code port forwarding is working
- Alternative: Use
ssh -L 8888:compute_node:8888 user@login_node
Best Practices
-
Resource Management:
- Request only what you need
- Use CPU partition for data analysis
- Reserve GPU partition for ML workloads
-
Time Limits:
- Start with shorter time limits
- Extend if needed using
scontrol
-
Port Management:
- Use different ports for multiple sessions
- Check
netstat -tuln | grep 8888for port availability
-
Environment Setup:
- Activate conda/virtual environments before starting Jupyter
- Set proper environment variables if needed
Example Session
# 1. Request resources
srun --partition=gpu_devel --gres=gpu:1 --mem=32G --cpus-per-task=4 --time=05:00:00 --pty bash
# 2. Activate environment (if needed)
source ~/.bashrc
conda activate your_env
# 3. Navigate to project
cd /path/to/your/project
# 4. Start JupyterLab
jupyter lab --no-browser --port=8888 --ip=0.0.0.0 --allow-root
# 5. In VS Code: Select Kernel → Existing Jupyter Server → Paste URLBenefits of This Approach
- ✅ No browser required - Everything runs in VS Code
- ✅ Full computational resources - Access to requested CPUs/GPUs/memory
- ✅ Integrated development - VS Code debugging, Git, extensions
- ✅ Interactive computing - Real-time feedback and visualization
- ✅ Resource isolation - Dedicated resources for your session
This method gives you the full power of SLURM resources while maintaining the familiar VS Code interface for notebook development.