| 1 | = How to use GPUs on the ML Department server = |
| 2 | |
| 3 | [[PageOutline(2-3)]] |
| 4 | |
| 5 | The ML Dept server hostname is `akeso.fi.muni.cz`. |
| 6 | |
| 7 | Follow these actions: |
| 8 | |
| 9 | 1. `ssh akeso`[[br]] |
| 10 | If you are not currently inside the faculty network, you must [#ConnectingtoFIMUNIVPN connect to the FI MUNI VPN] first. |
| 11 | 1. `cd /nlp/projekty/...` or `cd /cyb-trials/...` to your project directory |
| 12 | 1. setup !HuggingFace cache as detailed [#ChangethecachelocationofHuggingFaceDatasets below] |
| 13 | 1. find available GPUs: run `gpustat` or `nvidia-smi` |
| 14 | 2. `export CUDA_DEVICE_ORDER=PCI_BUS_ID` |
| 15 | 3. choose a GPU with no running processes |
| 16 | 4. limit your process to only selected GPU: |
| 17 | `export CUDA_VISIBLE_DEVICES=GID` where GID is the ID of the selected GPU (the first column in the `gpustat` or `nvidia-smi` listing). |
| 18 | |
| 19 | == Connecting to a GPU server == |
| 20 | ==== Connecting to FI MUNI VPN ==== |
| 21 | - Download the VPN configuration for FI MUNI from here: https://www.fi.muni.cz/tech/unix/vpn.html |
| 22 | - Use your faculty login `x.....` with your secondary password as the credentials |
| 23 | |
| 24 | ==== Connect to the server ==== |
| 25 | * Run command (replace `...` with the server name followed by a dot `.`): |
| 26 | {{{ |
| 27 | ssh xsurname@....fi.muni.cz |
| 28 | }}} |
| 29 | * Type in the secondary password again |
| 30 | |
| 31 | == Change the cache location of !HuggingFace Datasets == |
| 32 | |
| 33 | Keep your home directory small, there are quotas active. |
| 34 | |
| 35 | * find out your project directory `PROJECT_DIR`. It is located in one of the |
| 36 | NFS shares, i.e. `/nlp/projekty/...` or `/cyb-trials/...`. In the following instructions, we assume an environment variable `PROJECT_DIR` is set to your actual project directory, e.g. via |
| 37 | {{{ |
| 38 | export PROJECT_DIR=/nlp/projekty/... # or |
| 39 | export PROJECT_DIR=/cyb-trials/... |
| 40 | }}} |
| 41 | * You need to change the download location of datasets. The default location is in your home and it can easily get full |
| 42 | * prepare a cache directory in your project |
| 43 | {{{ |
| 44 | mkdir $PROJECT_DIR/hf_cache |
| 45 | }}} |
| 46 | * To change the HF Datasets location run: |
| 47 | {{{ |
| 48 | export HF_DATASETS_CACHE="$PROJECT_DIR/hf_cache" |
| 49 | }}} |
| 50 | * To make this change permanent so you don't need to type it every time you enter the server, add it to your `.bashrc` file in your home directory (including the setting for `PROJECT_DIR`). |
| 51 | |
| 52 | == Create virtual environment for your project == |
| 53 | {{{ |
| 54 | ssh akeso |
| 55 | cd $PROJECT_DIR |
| 56 | virtualenv myenv |
| 57 | source myenv/bin/activate |
| 58 | }}} |
| 59 | This `myenv` activation must be done before any package is installed via `pip`/`pip3` or the `python`/`python3` command is run with your program. |
| 60 | |
| 61 | Alternatively, you may run these commands with full path to your `myenv` and its `bin` subdirectory: |
| 62 | {{{ |
| 63 | $PROJECT_DIR/myenv/bin/pip install ... |
| 64 | $PROJECT_DIR/myenv/bin/python my_program.py |
| 65 | }}} |
| 66 | |
| 67 | The created environment may be dependent on the exact server setup and possibly may not work well at another server. |
| 68 | |
| 69 | == Run jupyter notebook on a GPU server == |
| 70 | |
| 71 | ==== Connect your virtual env with the Jupyter notebook ==== |
| 72 | * after [#Createvirtualenvironmentforyourproject activating] your `myenv` environment install `ipykernel` |
| 73 | {{{ |
| 74 | pip install ipykernel |
| 75 | python -m ipykernel install --user --name=myenv |
| 76 | }}} |
| 77 | You should get the output: |
| 78 | {{{ |
| 79 | Installed kernelspec myenv in /home/user/.local/share/jupyter/kernels/myenv |
| 80 | }}} |
| 81 | * To check all your connected venvs |
| 82 | {{{ |
| 83 | jupyter kernelspec list |
| 84 | }}} |
| 85 | |
| 86 | ==== Run Jupyter notebook on a personally selected port ==== |
| 87 | {{{ |
| 88 | jupyter notebook --no-browser --port 2222 |
| 89 | }}} |
| 90 | The output should contain one line in the form |
| 91 | {{{ |
| 92 | http://localhost:2222/?token=... |
| 93 | }}} |
| 94 | You will use it later, after setting up an SSH tunnel. |
| 95 | |
| 96 | ==== Create SSH Tunnelling ==== |
| 97 | * Open new second terminal and insert the following command |
| 98 | {{{ |
| 99 | ssh xsurname@akeso.fi.muni.cz -NL 2222:localhost:2222 |
| 100 | }}} |
| 101 | The second port must match the port selected when starting the jupyter notebook |
| 102 | |
| 103 | ==== Open Jupyter notebook on the local machine ==== |
| 104 | * Point your browser to a the previously obtained address of the notebook |
| 105 | http://localhost:2222?token=... [[br]] |
| 106 | If you have used the same port numbers, as we do, you do not need to change anything in the URL. |
| 107 | Otherwise, the port must match the first port in the [#CreateSSHTunnelling ssh tunelling] step. |
| 108 | * If you have correctly copied the `token`, then you are logged in. |
| 109 | Otherwise, to get the token again run: |
| 110 | {{{ |
| 111 | ssh akeso |
| 112 | jupyter notebook list |
| 113 | }}} |
| 114 | Copy the jupyter notebook URL and open it in your local browser. |
| 115 | |
| 116 | The notebook is opened with listing the directory of your project. |
| 117 | |
| 118 | == References used == |
| 119 | 1. SSH tunell: https://medium.com/@apbetahouse45/how-to-run-jupyter-notebooks-on-remote-server-part-1-ssh-a2be0232c533 |
| 120 | 2. FI MUNI VPN: https://www.fi.muni.cz/tech/unix/vpn.html |
| 121 | 3. Jupyter notebook with virtualenv: https://janakiev.com/blog/jupyter-virtual-envs/ |
| 122 | 4. !HuggingFace dataset location change: https://huggingface.co/docs/datasets/v1.12.0/cache.html |
| 123 | |