Skip to content

Commit 927f145

Browse files
committed
Add minimal examples folder with PyTorch Setup ex.
Signed-off-by: Fabrice Normandin <[email protected]>
1 parent de887ab commit 927f145

File tree

8 files changed

+102
-3
lines changed

8 files changed

+102
-3
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
.vscode
22
_build
3-
.idea
3+
.idea
4+
**/__pycache__

docs/Minimal_examples.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
.. ***************************
2+
.. Minimal Examples
3+
.. ***************************
4+
5+
6+
.. include:: examples/frameworks/README.rst

docs/conf.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@
3636
'Purpose_*',
3737
'Extra_compute_*',
3838
'IDT_*',
39-
'singularity/*']
39+
'singularity/*',
40+
'examples/*',]
4041
# The name of the Pygments (syntax highlighting) style to use.
4142
pygments_style = 'sphinx'
4243

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
*******************
2+
Software Frameworks
3+
*******************
4+
5+
6+
7+
.. include:: examples/frameworks/pytorch_setup/README.rst
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
PyTorch Setup
2+
===================
3+
4+
.. IDEA: Add a link to all the sections of the documentation that have to
5+
.. absolutely have been read before this tutorial.
6+
7+
**Prerequisites**: (Make sure to read the following before using this example!)
8+
9+
* :ref:`Quick Start`
10+
* :ref:`Running your code`
11+
* :ref:`Conda`
12+
13+
14+
**job.sh**
15+
16+
17+
.. literalinclude:: /examples/frameworks/pytorch_setup/job.sh
18+
:language: bash
19+
20+
21+
**main.py**
22+
23+
24+
.. literalinclude:: /examples/frameworks/pytorch_setup/main.py
25+
:language: python
26+
27+
28+
**Running this example**
29+
30+
31+
.. code-block:: bash
32+
33+
$ sbatch job.sh
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#!/bin/bash
2+
#SBATCH --gres=gpu:1
3+
#SBATCH --cpus-per-task=1
4+
#SBATCH --mem=16G
5+
#SBATCH --time=00:15:00
6+
#SBATCH --partition=unkillable
7+
8+
set -e # exit on error.
9+
echo "Date: $(date)"
10+
echo "Hostname: $(hostname)"
11+
12+
module purge
13+
# This example uses Conda to manage package dependencies.
14+
# See https://docs.mila.quebec/Userguide.html#conda for more information.
15+
module load anaconda/3
16+
17+
# Creating the environment for the first time:
18+
# conda create -y -n pytorch python=3.9 pytorch torchvision torchaudio \
19+
# pytorch-cuda=11.6 -c pytorch -c nvidia
20+
21+
# Activate the environment:
22+
conda activate pytorch
23+
24+
python main.py
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import torch
2+
import torch.backends.cuda
3+
4+
5+
def main():
6+
cuda_built = torch.backends.cuda.is_built()
7+
cuda_avail = torch.cuda.is_available()
8+
device_count = torch.cuda.device_count()
9+
10+
print(f"PyTorch built with CUDA: {cuda_built}")
11+
print(f"PyTorch detects CUDA available: {cuda_avail}")
12+
print(f"PyTorch-detected #GPUs: {device_count}")
13+
if device_count == 0:
14+
print(" No GPU detected, not printing devices' names.")
15+
else:
16+
for i in range(device_count):
17+
print(f" GPU {i}: {torch.cuda.get_device_name(i)}")
18+
19+
20+
if __name__ == "__main__":
21+
main()

docs/index.rst

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,13 @@ recommend you start by checking out the :ref:`short quick start guide
3636

3737
Theory_cluster
3838

39+
40+
.. toctree::
41+
:caption: Minimal Examples
42+
:maxdepth: 2
43+
44+
Minimal_examples
45+
3946
.. toctree::
4047
:caption: Extras
4148
:maxdepth: 2
@@ -53,4 +60,3 @@ recommend you start by checking out the :ref:`short quick start guide
5360
sections, or would simply like to contribute, please open an
5461
issue or make a pull request on the `github page
5562
<https://github.com/mila-iqia/mila-docs>`_.
56-

0 commit comments

Comments
 (0)