You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/guides/storage.md
+4-6Lines changed: 4 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -173,7 +173,7 @@ At first it can seem strange that a "high-performance" file system is significan
173
173
Meta data lookups on Lustre are expensive compared to your laptop, where the local file system is able to aggressively cache meta data.
174
174
175
175
[](){#ref-guides-storage-venv}
176
-
### Python virtual environments with uenv
176
+
### Squash Python virtual environments with uenv
177
177
178
178
Python virtual environments can be very slow on Lustre, for example a simple `import numpy` command run on Lustre might take seconds, compared to milliseconds on your laptop.
179
179
@@ -191,7 +191,7 @@ This file can be mounted as a read-only [Squashfs](https://en.wikipedia.org/wiki
191
191
192
192
#### Step 1: create the virtual environment
193
193
194
-
The first step is to create the virtual environment using the usual workflow.
194
+
The first step is to create the virtual environment using the usual workflow described in the [uenv documentation][ref-uenv-venv].
195
195
196
196
=== "uv"
197
197
@@ -205,13 +205,11 @@ The first step is to create the virtual environment using the usual workflow.
205
205
206
206
# unset PYTHONPATH and set PYTHONUSERBASE to avoid conflicts
Copy file name to clipboardExpand all lines: docs/software/ml/pytorch.md
+5-49Lines changed: 5 additions & 49 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -779,55 +779,11 @@ There are two ways to access the software provided by the uenv, once it has been
779
779
[](){#ref-uenv-pytorch-venv}
780
780
### Adding Python packages on top of the uenv
781
781
782
-
Uenvs are read-only, and cannot be modified. However, it is possible to add Python packages on top of the uenv using virtual environments analogous to the setup with containers.
783
-
784
-
```console title="Creating a virtual environment on top of the uenv"
1. The `default` view is recommended, as it loads all the packages provided by the uenv.
799
-
This is important for PyTorch to work correctly, as it relies on the CUDA and NCCL libraries provided by the uenv.
800
-
2. The virtual environment is created in the current working directory, and can be activated and deactivated like any other Python virtual environment.
801
-
3. Activating the virtual environment will override the Python executable provided by the uenv, and use the one from the virtual environment instead.
802
-
This is important to ensure that the packages installed in the virtual environment are used.
803
-
4. The virtual environment can be used to install any Python package.
804
-
5. The virtual environment can be deactivated using the `deactivate` command.
805
-
This will restore the original Python executable provided by the uenv.
806
-
6. The uenv can be exited using the `exit` command or by typing `ctrl-d`.
807
-
808
-
809
-
!!! note "Squashing the virtual environment"
810
-
Python virtual environments can be slow on the parallel Lustre file system due to the amount of small files and potentially many processes accessing it.
811
-
If this becomes a bottleneck, consider [squashing the venv][ref-guides-storage-venv] into its own memory-mapped, read-only file system to enhance scalability and reduce load times.
812
-
813
-
??? bug "Python packages from uenv view shadowing those in a virtual environment"
814
-
Some uenv views set the `PYTHONPATH` environment variable and/or do not set the `PYTHONUSERBASE` environment variable.
815
-
This can lead to unexpected behavior when using Python virtual environments on top of the uenv, as the packages installed in the uenv view may take precedence over those in the virtual environment.
816
-
A possible workaround is to unset the `PYTHONPATH` and set the `PYTHONUSERBASE` environment variables, as described in the [Python virtual environments with uenv guide][ref-guides-storage-venv]:
It is recommended to apply this workaround if you are constrained by a Python package version installed in the uenv view that you need to change for your application.
822
-
823
-
!!! note
824
-
Keep in mind that
825
-
826
-
* this virtual environment is _specific_ to this particular uenv and won't actually work unless you are using it from inside this uenv - it relies on the resources packaged inside the uenv.
827
-
* every Slurm job making use of this virtual environment will need to activate it first (_inside_ the `srun` command).
828
-
829
-
Alternatively one can use the uenv as [upstream Spack instance][ref-build-uenv-spack] to to add both Python and non-Python packages.
830
-
However, this workflow is more involved and intended for advanced Spack users.
782
+
Python virtual environments can be created on top of the uenv to install additional Python packages not provided by the uenv itself, or to override existing packages.
783
+
Please refer to the [Python virtual environments with uenv documentation][ref-uenv-venv] and the [guide on performance][ref-guides-storage-venv] for more details on
784
+
- creating and managing virtual environments on top of uenvs
785
+
- best practices and caveats when using virtual environments with uenvs
Copy file name to clipboardExpand all lines: docs/software/uenv/index.md
+103Lines changed: 103 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -775,5 +775,108 @@ $ which uenv
775
775
/usr/bin/uenv
776
776
```
777
777
778
+
[](){#ref-uenv-venv}
779
+
## Python virtual environments on top of uenv views
778
780
781
+
When stacking a Python virtual environment on top of a _uenv view_, keep Python’s import resolution predictable with the following:
779
782
783
+
-**Unset `PYTHONPATH`**. Anything there is *prepended* to Python's `sys.path`, which can lead to surprising imports.
784
+
-**Set `PYTHONUSERBASE` to the view's root directory** (e.g., `/user-environment/env/default`) so the interpreter’s _user site_ resolves inside the view.
785
+
- You can derive this automatically from the interpreter you’re about to use: take the parent of `which python`:
- Do not use tools that resolve symlinks (such as `readlink -f` or Python's `Path.resolve()`), as the Python interpreter in the _uenv view_ is a symlink - following it would point outside the view.
790
+
- **Create the venv with `--system-site-packages`**.
791
+
`venv` disables the user site by default; enabling system site restores both the system site and the user site, so packages provided by the _uenv view_ become visible inside the venv.
792
+
793
+
=== "uv"
794
+
795
+
```console title="Creating a Python virtual environment on top of a uenv view"
The uenv is a read-only squashfs; a `--user` install would try to write into `PYTHONUSERBASE` (the uenv), which is not possible.
877
+
- Some uenv views already set`PYTHONUSERBASE`. If you start a uenv view that does this, you can skip setting `PYTHONUSERBASE` yourself.
878
+
- The virtual environment is _specific_ to a particular uenv and won't work unless used from inside this excact uenv - it relies on the resources packaged inside the uenv.
879
+
880
+
!!! note "Performance considerations"
881
+
On our Lustre parallel file system, large venvs can be slow due to many small files.
882
+
See [How to squash virtual environments][ref-guides-storage-venv] for turning a venv into a compact image to improve startup and import performance.
0 commit comments