# Paperspace Usage Information
## Preliminary
You should have been provided with Paperspace credits - these will allow you to spawn paid instances with better GPUs than what colab or paperspace offer on their free-tier. Additionally, unless you enable auto-shutdown, these instances will stay awake permanently, and not abort half-way through training.
## Instance Setup
Once you have signed up for Paperspace's gradient platform and applied your coupon:
1. Go to console.paperspace.com and create a under the "ICL Deep Learning 2023" team (selected at top left)
2. Create a notebook within that project. We recommend using the PyTorch 1.10 GPU runtime
3. Select a machine - you can use the free-tier CPU or GPU machines for most of the coursework questions, but when training your models we recommend using a paid P4000 instance. Choose your **auto-shutdown** period carefully, base on the network's training time, and whether you will need to go AFK
4. You can **directly connect the instance to your gitlab repository** by
a. Going to Advanced Options and pasting your gitlab link into the workspace field (```https://gitlab.doc.ic.ac.uk/<course>/<your_repo>.git```) **the .git is needed** - the easiest way to get this link is to copy the HTTPS clone link from gitlab.
b. Entering your doc username (e.g. **afs219** - not your email!) and password into the workspace username and password information
**Note** it seems there is a bug for passwords containing special characters (% & etc.) - the password field on paperspace will not properly pass these to the gitlab login, and you will get "Access denied". The current fix is to change your gitlab password.)
## Using the Paperspace Gradient Environment
Once your instance has spun-up, you will be greeted by a .ipynb similar to Google Colab. You can choose to work here, or press the Jupyter icon to the side (![](https://i.imgur.com/5d7mrEf.png)) to open JupyterLab.
If you are going to work in the web, I would strongly recommend using JupyterLab over their notebook environment. However, the best development experience is provided by working with VSCode and connecting to the remote kernel.
## Connecting VSCode to Gradient
In order to make this work you will need the Jupyter extension installed on VSCode. You should also ```git clone``` your repo onto whichever machine you'll be working from.
Assuming you have opened the repository within VScode, and have the ```dl_cw_X.ipynb``` file open you can then follow the steps in https://docs.paperspace.com/gradient/notebooks/notebooks-remote-kernel/
<!--
1. We will first need to retrieve the jupyter kernel url and token from Paperspace. Boot an instance as described above, and then create a dummy ```notebook.ipynb```.
a. Open the JupyterLab environment on Paperspace, and take note of the url (e.g. ```https://ncu2a5zm3q.clg07azjl.paperspacegradient.com/lab```)
b. Run the following snippet within a notebook, to retrieve the token
```python
from notebook import notebookapp
notebook_token = list(notebookapp.list_running_servers())[0]['token']
print(notebook_token)
```
this should return an alphanumerical string (e.g. ```310bdadb353de5d42de0c70c69ec0dd1```)
2. Combine these two to form the link with the token:
```<link without /lab>/?token=<token>``` e.g. ```https://ncu2a5zm3q.clg07azjl.paperspacegradient.com/?token=310bdadb353de5d42de0c70c69ec0dd1```)
3. Now press the Jupyter Server selection button at the bottom-right in VSCode ![](https://i.imgur.com/mXz6kKN.png) and paste in the url.
After reloading your VSCode window, it should work. Remember that you can run terminal commands through ipython directly by using ```!the_command```. For example, you can check that you are on the remote machine by running ```!pwd``` within the notebook - you should find you are in ```/notebooks``` by default. -->