Skip to content

Commit

Permalink
simplify requirements file (rasbt#76)
Browse files Browse the repository at this point in the history
  • Loading branch information
rasbt authored Mar 18, 2024
1 parent 3e122fa commit 329d046
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 49 deletions.
14 changes: 2 additions & 12 deletions appendix-A/02_installing-python-libraries/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,9 @@

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.)

I used the following main libraries in 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:
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.

- numpy 1.24.3
- scipy 1.10.1
- pandas 2.0.2
- matplotlib 3.7.1
- jupyterlab 4.0
- watermark 2.4.2
- torch 2.0.1
- tiktoken 0.5.1

To install these requirements most conveniently, you can use the `requirements.txt` file:
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:

```
pip install -r requirements.txt
Expand All @@ -36,7 +27,6 @@ If you see the following issues, it's likely that your JupyterLab instance is co

<img src="figures/jupyter-issues.jpg" width="450px">


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:

<img src="figures/watermark.jpg" width="350px">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,14 @@
"name": "stdout",
"output_type": "stream",
"text": [
"[OK] Your Python version is 3.11.4\n",
"[OK] numpy 1.25.2\n",
"[OK] scipy 1.11.1\n",
"[OK] pandas 2.0.3\n",
"[OK] matplotlib 3.7.2\n",
"[OK] jupyterlab 4.0.4\n",
"[OK] watermark 2.4.3\n",
"[OK] torch 2.0.1\n",
"[OK] tiktoken 0.5.1\n"
"[OK] Your Python version is 3.10.12\n",
"numpy >= 1.24.3 \n",
"matplotlib >= 3.7.1. \n",
"jupyterlab >= 4.0. \n",
"tensorflow >= 2.15.0 \n",
"torch >= 2.0.1 \n",
"tqdm >= 4.66.1 \n",
"tiktoken >= 0.5.1 \n"
]
}
],
Expand All @@ -28,14 +27,6 @@
"d = get_requirements_dict()\n",
"check_packages(d)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "d5ca05fc-98e0-4bba-a95e-350e1764a12c",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
Expand All @@ -54,7 +45,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.4"
"version": "3.10.12"
}
},
"nbformat": 4,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,18 @@ def get_packages(pkgs):

def get_requirements_dict():
PROJECT_ROOT = dirname(realpath(__file__))
REQUIREMENTS_FILE = join(PROJECT_ROOT, "requirements.txt")
PROJECT_ROOT_UP_TWO = dirname(dirname(PROJECT_ROOT))
REQUIREMENTS_FILE = join(PROJECT_ROOT_UP_TWO, "requirements.txt")
d = {}
with open(REQUIREMENTS_FILE) as f:
for line in f:
if not line.strip():
continue
line = line.split("#")[0]
print(line)
line = line.split(" ")
if not line[0].strip() or not line[-1].strip():
continue
d[line[0]] = line[-1]
return d

Expand Down
8 changes: 0 additions & 8 deletions appendix-A/02_installing-python-libraries/requirements.txt

This file was deleted.

4 changes: 2 additions & 2 deletions ch05/01_main-chapter-code/previous_chapters.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def __getitem__(self, idx):
return self.input_ids[idx], self.target_ids[idx]


def create_dataloader_v1(txt, batch_size=4, max_length=256,
def create_dataloader_v1(txt, batch_size=4, max_length=256,
stride=128, shuffle=True, drop_last=True):
# Initialize the tokenizer
tokenizer = tiktoken.get_encoding("gpt2")
Expand Down Expand Up @@ -78,7 +78,7 @@ def forward(self, x):

# We implicitly split the matrix by adding a `num_heads` dimension
# Unroll last dim: (b, num_tokens, d_out) -> (b, num_tokens, num_heads, head_dim)
keys = keys.view(b, num_tokens, self.num_heads, self.head_dim)
keys = keys.view(b, num_tokens, self.num_heads, self.head_dim)
values = values.view(b, num_tokens, self.num_heads, self.head_dim)
queries = queries.view(b, num_tokens, self.num_heads, self.head_dim)

Expand Down
15 changes: 7 additions & 8 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
numpy >= 1.24.3
scipy >= 1.10.1
pandas >= 2.0.2
matplotlib >= 3.7.1
jupyterlab >= 4.0
watermark >= 2.4.2
torch >= 2.0.1
tiktoken >= 0.5.1
numpy >= 1.24.3 # ch05
matplotlib >= 3.7.1. # ch04, ch05
jupyterlab >= 4.0. # all
tensorflow >= 2.15.0 # ch05
torch >= 2.0.1 # all
tqdm >= 4.66.1 # ch05
tiktoken >= 0.5.1 # ch02, ch04, ch05

0 comments on commit 329d046

Please sign in to comment.