Changes between Initial Version and Version 1 of en/UsingDeptGPU


Ignore:
Timestamp:
Oct 17, 2024, 1:57:20 PM (9 months ago)
Author:
Ales Horak
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • en/UsingDeptGPU

    v1 v1  
     1= How to use GPUs on the ML Department server =
     2
     3[[PageOutline(2-3)]]
     4
     5The ML Dept server hostname is `akeso.fi.muni.cz`.
     6
     7Follow these actions:
     8
     91. `ssh akeso`[[br]]
     10   If you are not currently inside the faculty network, you must [#ConnectingtoFIMUNIVPN connect to the FI MUNI VPN] first.
     111. `cd /nlp/projekty/...` or `cd /cyb-trials/...` to your project directory
     121. setup !HuggingFace cache as detailed [#ChangethecachelocationofHuggingFaceDatasets below]
     131. find available GPUs: run `gpustat` or `nvidia-smi`
     142. `export CUDA_DEVICE_ORDER=PCI_BUS_ID`
     153. choose a GPU with no running processes
     164. 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{{{
     27ssh xsurname@....fi.muni.cz
     28}}}
     29* Type in the secondary password again
     30
     31== Change the cache location of !HuggingFace Datasets ==
     32
     33Keep 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  {{{
     38export PROJECT_DIR=/nlp/projekty/...  # or
     39export 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{{{
     44mkdir $PROJECT_DIR/hf_cache
     45}}}
     46* To change the HF Datasets location run:
     47{{{
     48export 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{{{
     54ssh akeso
     55cd $PROJECT_DIR
     56virtualenv myenv
     57source myenv/bin/activate
     58}}}
     59This `myenv` activation must be done before any package is installed via `pip`/`pip3` or the `python`/`python3` command is run with your program.
     60
     61Alternatively, 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
     67The 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{{{
     74pip install ipykernel
     75python -m ipykernel install --user --name=myenv
     76}}}
     77 You should get the output:
     78{{{
     79Installed kernelspec myenv in /home/user/.local/share/jupyter/kernels/myenv
     80}}}
     81* To check all your connected venvs
     82{{{
     83jupyter kernelspec list
     84}}}
     85
     86==== Run Jupyter notebook on a personally selected port ====
     87{{{
     88jupyter notebook --no-browser --port 2222
     89}}}
     90The output should contain one line in the form
     91{{{
     92http://localhost:2222/?token=...
     93}}}
     94You 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{{{
     99ssh 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  {{{
     111ssh akeso
     112jupyter 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 ==
     1191. SSH tunell: https://medium.com/@apbetahouse45/how-to-run-jupyter-notebooks-on-remote-server-part-1-ssh-a2be0232c533
     1202. FI MUNI VPN: https://www.fi.muni.cz/tech/unix/vpn.html
     1213. Jupyter notebook with virtualenv: https://janakiev.com/blog/jupyter-virtual-envs/
     1224. !HuggingFace dataset location change: https://huggingface.co/docs/datasets/v1.12.0/cache.html
     123