Skip to content

Commit

Permalink
Merge pull request #41 from psteinb/torch-intro-exercises
Browse files Browse the repository at this point in the history
last minute changes
  • Loading branch information
psteinb authored Aug 29, 2023
2 parents 272374f + 33fca3b commit 3bd0c4f
Show file tree
Hide file tree
Showing 11 changed files with 520 additions and 1,909 deletions.
157 changes: 132 additions & 25 deletions docs/60_Pytorch/00_versions.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,14 @@
"# Versions"
]
},
{
"cell_type": "markdown",
"id": "209e5a4b-964e-4453-814b-72ac48f67302",
"metadata": {},
"source": [
"As for every machine learning project, managing software and sofware dependencies is key. We have tried to make this process as easy as possible. Execute the cell below and you should be fine."
]
},
{
"cell_type": "code",
"execution_count": null,
Expand All @@ -18,94 +26,169 @@
"!sh enable_env_in_jupyter.sh"
]
},
{
"cell_type": "markdown",
"id": "bf7cf1ee-b271-4a13-8bf5-b6083ce5e426",
"metadata": {},
"source": [
"After you have launched the above cell and you do not get an error, you need to close the current notebook and reopen it. Then you should see the kernel `torch_intro_env` be available in the top right menue.\n",
"\n",
"The cells below are meant as a cross check to see if everything works as expected."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "38384033",
"execution_count": 1,
"id": "2347004f-a58b-4d52-b2ba-c0d093b2042b",
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"1.11.0\n"
]
}
],
"source": [
"import torch\n",
"print(torch.__version__)"
]
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 2,
"id": "685b7d74",
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"0.12.0a0+76b4a42\n"
]
}
],
"source": [
"import torchvision\n",
"print(torchvision.__version__)"
]
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 3,
"id": "9cdffa10",
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"2.0.7\n"
]
}
],
"source": [
"import pytorch_lightning as pl\n",
"print(pl.__version__)"
]
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 4,
"id": "444d4fef",
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"1.2.0\n"
]
}
],
"source": [
"import monai\n",
"print(monai.__version__)"
]
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 5,
"id": "7f41b1c5",
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"1.11.2\n"
]
}
],
"source": [
"import scipy\n",
"print(scipy.__version__)"
]
},
{
"cell_type": "markdown",
"id": "bbe5db54-abb9-446a-8d53-5bc3e4366d7e",
"metadata": {},
"source": [
"After we made sure, that all software is available at the versions we intended, let's look around the available hardware a bit."
]
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 6,
"id": "da8d5db3",
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"cuda devices available: 1\n"
]
}
],
"source": [
"print(\"cuda devices available:\", torch.cuda.device_count())"
]
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 7,
"id": "dff36cda",
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"True\n"
]
}
],
"source": [
"print(torch.cuda.is_available())"
]
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 8,
"id": "b0e1ed3e",
"metadata": {},
"outputs": [],
"source": [
"# let's create a regular n-dimensional object, in torch this is called a Tensor\n",
"x = torch.ones(10, 2, 32, 42)"
]
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 9,
"id": "860fe3ca",
"metadata": {},
"outputs": [],
Expand All @@ -120,23 +203,47 @@
"metadata": {},
"outputs": [],
"source": [
"# moving a tensor onto an accelerator is as easy as the following line\n",
"x.to(device)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "0c8efaeb",
"cell_type": "markdown",
"id": "becd8f52-cbc1-47cb-9874-b47cd38df062",
"metadata": {},
"outputs": [],
"source": []
"source": [
"## Fallback Environment\n",
"\n",
"Should there be any trouble with running the first cell in this notebook, there is another way to set up the kernel that will work with all or most of the notebooks.\n",
"\n",
"1. Start a [jupyter lab session on taurus](https://taurus.hrsk.tu-dresden.de/jupyter/hub/home). Make sure to select at least one GPU.\n",
"\n",
"2. In Jupyter lab, open a terminal and type the following commands. IMPORTANT: make sure to wait until the script reports that it is done. otherwise you may end up with a broken partial singularity image in your `~/.singularity/cache` directory.\n",
"\n",
" ```bash\n",
"\n",
" git clone https://gitlab.mn.tu-dresden.de/bia-pol/singularity-devbio-napari.git\n",
"\n",
" cd singularity-devbio-napari\n",
"\n",
" ./install.sh <version>\n",
"\n",
" ```\n",
"\n",
" Replace `<version>` with the version you want to install. For this session, `pol-course-pytorch` is the most suitable.\n",
"\n",
"3. You should now see an additional button named `devbio napari` on the jupyter lab home screen. Note: you may need to reload the page first.\n",
"\n",
"4. Klick on that button to start a jupyter notebook inside the singularity container. Note that the first command execution will take a while because of the additional time it takes to start the singularity container.\n",
"\n"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"display_name": "devbio-napari_pol-course-pytorch",
"language": "python",
"name": "python3"
"name": "devbio-napari_pol-course-pytorch"
},
"language_info": {
"codemirror_mode": {
Expand All @@ -148,7 +255,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.16"
"version": "3.10.8"
}
},
"nbformat": 4,
Expand Down
Loading

0 comments on commit 3bd0c4f

Please sign in to comment.