Loading content/en/tutorials/python/index.md +26 −19 Original line number Diff line number Diff line Loading @@ -505,22 +505,22 @@ $ micromamba create -f environment.yml ### Exercise 3: Create a Micromamba environment 1. Create an environment called `nlp-env` with Python 3.11, transformers, and datasets 2. Activate it and verify transformers is installed 1. Create an environment called `sci-env` with Python 3.11, numpy, and scipy 2. Activate it and verify scipy is installed 3. Export the environment to `environment.yml` {{% alert title="Check your work" color="info" %}} ```shell-session $ micromamba activate nlp-env (nlp-env) $ python -c "import transformers; print(transformers.__version__)" 4.47.1 $ micromamba activate sci-env (sci-env) $ python -c "import scipy; print(scipy.__version__)" 1.14.1 $ cat environment.yml | head -5 name: nlp-env $ head -5 environment.yml name: sci-env channels: - conda-forge dependencies: - python=3.11 - python=3.11.* ``` {{% /alert %}} Loading Loading @@ -778,11 +778,17 @@ srun uv run python src/train.py PyTorch can't find CUDA or wrong version. **Solution**: Match PyTorch CUDA version to loaded modules: **Solution**: Match PyTorch CUDA version to the host driver. Check driver version: ```shell-session $ module load cuda/12.9 $ uv add torch --index https://download.pytorch.org/whl/cu124 $ nvidia-smi | grep "Driver Version" Driver Version: 550.54.15 CUDA Version: 12.4 ``` Then install matching PyTorch: ```shell-session $ uv add torch --index https://download.pytorch.org/whl/cu124 # for CUDA 12.4 ``` ### Slow package installation Loading @@ -808,26 +814,27 @@ $ git add uv.lock pyproject.toml # For UV $ git add pixi.lock pixi.toml # For Pixi ``` ### Exercise 5: Debug a broken environment ### Exercise 5: Restore from lockfile 1. Create a UV project 2. Add packages, then manually delete `.venv/` 3. Run `uv sync` to restore the environment 1. Create a UV project and add packages 2. Delete `.venv/` to simulate a fresh clone 3. Run `uv sync` to restore the exact environment 4. Verify packages work {{% alert title="Check your work" color="info" %}} ```shell-session $ rm -rf .venv/ $ uv run python -c "import torch" error: No virtual environment found $ ls pyproject.toml uv.lock src/ $ uv sync Resolved 15 packages in 12ms Installed 15 packages in 0.8s $ uv run python -c "import torch; print('Fixed!')" Fixed! $ uv run python -c "import torch; print('Restored!')" Restored! ``` The lockfile (`uv.lock`) ensures the exact same versions are installed. {{% /alert %}} --- Loading Loading
content/en/tutorials/python/index.md +26 −19 Original line number Diff line number Diff line Loading @@ -505,22 +505,22 @@ $ micromamba create -f environment.yml ### Exercise 3: Create a Micromamba environment 1. Create an environment called `nlp-env` with Python 3.11, transformers, and datasets 2. Activate it and verify transformers is installed 1. Create an environment called `sci-env` with Python 3.11, numpy, and scipy 2. Activate it and verify scipy is installed 3. Export the environment to `environment.yml` {{% alert title="Check your work" color="info" %}} ```shell-session $ micromamba activate nlp-env (nlp-env) $ python -c "import transformers; print(transformers.__version__)" 4.47.1 $ micromamba activate sci-env (sci-env) $ python -c "import scipy; print(scipy.__version__)" 1.14.1 $ cat environment.yml | head -5 name: nlp-env $ head -5 environment.yml name: sci-env channels: - conda-forge dependencies: - python=3.11 - python=3.11.* ``` {{% /alert %}} Loading Loading @@ -778,11 +778,17 @@ srun uv run python src/train.py PyTorch can't find CUDA or wrong version. **Solution**: Match PyTorch CUDA version to loaded modules: **Solution**: Match PyTorch CUDA version to the host driver. Check driver version: ```shell-session $ module load cuda/12.9 $ uv add torch --index https://download.pytorch.org/whl/cu124 $ nvidia-smi | grep "Driver Version" Driver Version: 550.54.15 CUDA Version: 12.4 ``` Then install matching PyTorch: ```shell-session $ uv add torch --index https://download.pytorch.org/whl/cu124 # for CUDA 12.4 ``` ### Slow package installation Loading @@ -808,26 +814,27 @@ $ git add uv.lock pyproject.toml # For UV $ git add pixi.lock pixi.toml # For Pixi ``` ### Exercise 5: Debug a broken environment ### Exercise 5: Restore from lockfile 1. Create a UV project 2. Add packages, then manually delete `.venv/` 3. Run `uv sync` to restore the environment 1. Create a UV project and add packages 2. Delete `.venv/` to simulate a fresh clone 3. Run `uv sync` to restore the exact environment 4. Verify packages work {{% alert title="Check your work" color="info" %}} ```shell-session $ rm -rf .venv/ $ uv run python -c "import torch" error: No virtual environment found $ ls pyproject.toml uv.lock src/ $ uv sync Resolved 15 packages in 12ms Installed 15 packages in 0.8s $ uv run python -c "import torch; print('Fixed!')" Fixed! $ uv run python -c "import torch; print('Restored!')" Restored! ``` The lockfile (`uv.lock`) ensures the exact same versions are installed. {{% /alert %}} --- Loading