Files
LLMs-from-scratch/setup/02_installing-python-libraries/README.md

87 lines
3.8 KiB
Markdown
Raw Normal View History

2024-07-14 08:53:16 -05:00
# Installing Python Packages and Libraries Used In This Book
2024-01-21 20:16:19 -06:00
This document provides more information on double-checking your installed Python version and packages. (Please see the [../01_optional-python-setup-preferences](../01_optional-python-setup-preferences) folder for more information on installing Python and Python packages.)
2024-03-18 08:00:49 -05:00
I used the following libraries listed [here](https://github.com/rasbt/LLMs-from-scratch/blob/main/requirements.txt) for this book. Newer versions of these libraries are likely compatible as well. However, if you experience any problems with the code, you can try these library versions as a fallback.
2024-01-21 20:16:19 -06:00
> **Note:**
> If you you are using `uv` as described in [Option 1: Using uv](../01_optional-python-setup-preferences/README.md), you can replace `pip` via `uv pip` in the commands below. For example, `pip install -r requirements.txt` becomes `uv pip install -r requirements.txt`
2024-03-18 08:00:49 -05:00
To install these requirements most conveniently, you can use the `requirements.txt` file in the root directory for this code repository and execute the following command:
2023-07-23 13:18:13 -05:00
```bash
2023-07-23 13:18:13 -05:00
pip install -r requirements.txt
```
2024-07-27 13:39:23 -05:00
Alternatively, you can install it via the GitHub URL as follows:
```bash
pip install -r https://raw.githubusercontent.com/rasbt/LLMs-from-scratch/main/requirements.txt
```
2023-07-23 13:18:13 -05:00
Then, after completing the installation, please check if all the packages are installed and are up to date using
```bash
python python_environment_check.py
2023-07-23 13:18:13 -05:00
```
2024-04-15 22:05:03 -04:00
<img src="https://sebastianraschka.com/images/LLMs-from-scratch-images/setup/02_installing-python-libraries/check_1.jpg" width="600px">
2023-07-23 13:18:13 -05:00
It's also recommended to check the versions in JupyterLab by running the `python_environment_check.ipynb` in this directory, which should ideally give you the same results as above.
2023-07-23 13:18:13 -05:00
2024-04-15 22:05:03 -04:00
<img src="https://sebastianraschka.com/images/LLMs-from-scratch-images/setup/02_installing-python-libraries/check_2.jpg" width="500px">
2023-07-23 13:18:13 -05:00
If you see the following issues, it's likely that your JupyterLab instance is connected to wrong conda environment:
2024-04-15 22:05:03 -04:00
<img src="https://sebastianraschka.com/images/LLMs-from-scratch-images/setup/02_installing-python-libraries/jupyter-issues.jpg" width="450px">
2023-07-23 13:18:13 -05:00
In this case, you may want to use `watermark` to check if you opened the JupyterLab instance in the right conda environment using the `--conda` flag:
2024-04-15 22:05:03 -04:00
<img src="https://sebastianraschka.com/images/LLMs-from-scratch-images/setup/02_installing-python-libraries/watermark.jpg" width="350px">
2024-01-21 20:16:19 -06:00
&nbsp;
2024-01-21 20:16:19 -06:00
## Installing PyTorch
PyTorch can be installed just like any other Python library or package using pip. For example:
```bash
2024-09-13 08:16:53 -05:00
pip install torch
2024-01-21 20:16:19 -06:00
```
However, since PyTorch is a comprehensive library featuring CPU- and GPU-compatible codes, the installation may require additional settings and explanation (see the *A.1.3 Installing PyTorch in the book for more information*).
It's also highly recommended to consult the installation guide menu on the official PyTorch website at [https://pytorch.org](https://pytorch.org).
2024-04-15 22:05:03 -04:00
<img src="https://sebastianraschka.com/images/LLMs-from-scratch-images/setup/02_installing-python-libraries/pytorch-installer.jpg" width="600px">
2024-01-21 20:16:19 -06:00
2024-09-13 08:16:53 -05:00
<br>
2024-01-21 20:16:19 -06:00
2026-02-27 18:33:39 -05:00
&nbsp;
## JupyterLab tips
If you are viewing the notebook code in JupyterLab rather than VSCode, note that JupyterLab (in its default setting) has had scrolling bugs in recent versions. My recommendation is to go to Settings -> Settings Editor and change the "Windowing mode" to "none" (as illustrated below), which seems to address the issue.
![Jupyter Glitch 1](https://sebastianraschka.com/images/reasoning-from-scratch-images/bonus/setup/jupyter_glitching_1.webp)
<br>
![Jupyter Glitch 2](https://sebastianraschka.com/images/reasoning-from-scratch-images/bonus/setup/jupyter_glitching_2.webp)
<br>
2024-01-21 20:16:19 -06:00
---
Any questions? Please feel free to reach out in the [Discussion Forum](https://github.com/rasbt/LLMs-from-scratch/discussions).