Skip to content

Commit 272b2b7

Browse files
committed
update software installation and include how to use google colab platform
1 parent ab27363 commit 272b2b7

3 files changed

Lines changed: 84 additions & 23 deletions

File tree

content/00-software-setup.md

Lines changed: 84 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
# Setting Up Programming Environment
22

33

4-
This page provides instructions for installing the required packages and their dependencies on a local computer or server.
54

5+
## Using Personal Computer
66

7-
## Install miniforge
7+
8+
This section provides instructions for installing the required packages and their dependencies on a local computer or server.
9+
10+
11+
### Install miniforge
812

913

1014
If you already have a preferred way to manage Python versions and libraries, you can stick to that. Otherwise, we recommend you to install Python3 and all required libraries using [Miniforge](https://conda-forge.org/download/), a free minimal installer for the package, dependency, and environment manager [Conda](https://docs.conda.io/en/latest/index.html).
@@ -17,10 +21,10 @@ $ conda --version
1721
```
1822

1923

20-
## Configure programming environment
24+
### Configure programming environment
2125

2226

23-
With Conda installed, run the command below to install required packages and depenencies (except PyTorch):
27+
With Conda installed, open the **Anaconda Prompt terminal**, and run the command below to install required packages and depenencies (except PyTorch):
2428
```console
2529
$ conda env create -y --file=https://raw.githubusercontent.com/ENCCS/practical-machine-learning/main/content/env/environment.yml
2630
```
@@ -41,10 +45,10 @@ Remember to activate your programming environment each time before running code
4145
:::
4246

4347

44-
## Validate programming environment
48+
### Validate programming environment
4549

4650

47-
Once the programming environment is fully set up, open a new terminal (just as you should do each time before running code examples), activate the programming environment, and launch JupyterLab by running the command below.
51+
Once the programming environment is fully set up, open a new **Anaconda Prompt terminal** (just as you should do each time before running code examples), activate the programming environment, and launch JupyterLab by running the command below:
4852
```console
4953
$ conda activate practical_machine_learning
5054

@@ -86,22 +90,25 @@ You should see output similar to the figure below. The exact package versions ma
8690
:::
8791

8892

89-
If the code runs without errors, it means the packages are correctly installed and your programming environment is ready for use. If you encounter an error (*e.g.*, ``ModuleNotFoundError``), it indicates that a package may not have been installed properly. In that case, please double-check your programming environment setup or bring the issue to the on-boarding session for assistance.
93+
If the code runs without errors, it means that all packages are correctly installed and your programming environment is ready to use.
9094

9195

9296
::::{warning}
93-
If you encounter an error like the one shown in the figure below, it usually means PyTorch is trying to load a DLL (such as fbgemm.dll), but one of its dependencies is missing or incompatible. The most common causes are a missing Microsoft Visual C++ runtime or a mismatch between the installed PyTorch build and your Python/OS environment.
97+
For Windows OS users, you might encounter an error
98+
(``ImportError: DLL load failed while importing _C: The specified procedure could not be found``) as described below.
99+
94100
:::{figure} ./env/pytorch_error.png
95101
:align: center
96102
:width: 80%
97103
:::
98104

99-
To verify, you can open another Jupyter notebook and test PyTorch again. You should see output similar to the example below.
105+
It is a very common Windows-specific PyTorch issue, and it means that the underlying C++/CUDA DLLs that torch depends on could not be loaded correctly.
100106

101-
:::{figure} ./env/pytorch_another_test.png
102-
:align: center
103-
:width: 80%
104-
:::
107+
You should reinstall the correct matching build via the command below.
108+
109+
```console
110+
$ conda install -y pytorch torchvision torchaudio torchtext cpuonly -c pytorch
111+
```
105112
::::
106113

107114

@@ -115,40 +122,94 @@ If you are using VS Code, you can select the installed ``practical_machine_learn
115122
:::
116123

117124

118-
## (Optional) Setting Up PyTorch with GPU Support
125+
126+
### (Optional) Setting Up PyTorch with GPU Support
119127

120128

121-
If your computer has a GPU, you can install PyTorch with GPU support. Below are step-by-step instructions to update the `practical_machine_learning` programming environment.
129+
**For Windows OS users**, if your computer has a GPU card, you can install PyTorch with GPU support.
130+
Below are step-by-step instructions to update the ``practical_machine_learning`` programming environment.
122131

123132

124133
First check your CUDA version.
125134
Open a terminal (Linux/macOS) or PowerShell (Windows) and run:
126-
```shell
127-
nvcc --version
135+
```console
136+
$ nvcc --version
128137
```
129138
If ``nvcc`` is not in your PATH, you can instead run ``nvidia-smi``.
139+
```console
140+
$ nvidia-smi
141+
```
142+
143+
130144
Here is the output from my Windows machine:
131145
:::{figure} ./env/test-cuda-compiler-driver.png
132146
:align: center
133147
:width: 80%
134148
:::
135149

136150

137-
Second, install the required packages and libraries using conda (for CUDA 12.1):
138-
```shell
139-
(base) C:\Users\wangy> conda activate practical_machine_learning
151+
Second, remove any CPU-only versions of PyTorch that may have been installed (for example, those coming from Conda’s defaults or conda-forge channels), and hten install an older, CUDA-compatible version of PyTorch directly using ``pip``.
152+
Here ``cu121`` indicates the CUDA version (12.1) that the PyTorch build was compiled with.
153+
140154

141-
(practical_machine_learning) C:\Users\wangy> conda install pytorch torchvision torchaudio pytorch-cuda=12.1 -c pytorch -c nvidia
155+
```console
156+
$ conda activate practical_machine_learning
157+
158+
$ conda remove pytorch torchvision torchaudio torchtext
159+
160+
$ pip install torch==2.4.0 torchvision==0.19.0 torchaudio==2.4.0 --index-url https://download.pytorch.org/whl/cu121
142161
```
143162

144163

145-
Third, verify your installation in a Jupyter Notebook. Run the following command and ensure it returns ``True`` for ``torch.cuda.is_available()``.
164+
Third, verify your installation in a Jupyter Notebook.
165+
Run the following command and ensure it returns ``True`` for ``torch.cuda.is_available()``.
146166

147167

148168
```python
149169
import torch
150170

151-
print(torch.__version__) # 2.5.1
171+
print(torch.__version__) # 2.4.0+cu121
152172
print(torch.cuda.is_available()) # True
153173
print(torch.cuda.get_device_name(0)) # NVIDIA GeForce GT 1030
154174
```
175+
176+
177+
## Using Google Colab
178+
179+
180+
You can also run all the code examples in tutorials using [Google Colab](https://colab.research.google.com/), a free cloud-based platform that provides Jupyter Notebook environments with preinstalled ML libraries.
181+
182+
183+
### Download Jupyter Notebooks
184+
185+
186+
- You can open each Jupyter Notebook (usually with the ``.ipynb`` extension) from [HERE](https://github.com/ENCCS/practical-machine-learning/tree/main/content/jupyter-notebooks), and then select **Download raw file** to save it locally.
187+
- Alternatively, you can download the entire repository at [HERE](https://github.com/ENCCS/practical-machine-learning/tree/main) by clicking the green ``<> Code`` button and choosing **Download ZIP** file. After unzipping the downloaded ZIP file, you will find all Jupyter Notebooks in the directory **practical-machine-learning-main/content/jupyter-notebooks**.
188+
189+
190+
### Upload Jupyter Notebooks to Google Drive
191+
192+
193+
Sign in to your [Google Drive](https://workspace.google.com/intl/en-US/products/drive/), then upload the downloaded Jupyter Notebooks to a convenient folder.
194+
You can simply drag and drop the files directly into Google Drive or use the option **New → File upload**.
195+
196+
197+
### Open Jupyter Notebooks in Google Colab
198+
199+
200+
Once uploaded, right-click the Jupyter Notebooks file in Google Drive and select **Open with → Google Colaboratory**.
201+
This will launch the notebook in Google Colab, where you can view, edit, and run the code cells interactively.
202+
203+
204+
### Connect to a Hosted Runtime
205+
206+
207+
In Google Colab, go to the top-right corner and click **Connect** to link your notebook to a Google-hosted runtime environment.
208+
If you need GPU or TPU acceleration, select **Runtime → Change runtime type**, then choose the desired hardware accelerator.
209+
210+
211+
### Run the Code
212+
213+
214+
After connecting, follow the instructions inside the Jupyter Notebooks.
215+
You can run each cell individually by pressing **Shift** + **Enter**, or execute the entire notebook using **Runtime → Run all**.
-5.64 KB
Binary file not shown.

content/env/pytorch_error.png

59.4 KB
Loading

0 commit comments

Comments
 (0)