diff --git a/appendix-A/02_installing-python-libraries/README.md b/appendix-A/02_installing-python-libraries/README.md index c29cf96..be97c76 100644 --- a/appendix-A/02_installing-python-libraries/README.md +++ b/appendix-A/02_installing-python-libraries/README.md @@ -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 @@ -36,7 +27,6 @@ If you see the following issues, it's likely that your JupyterLab instance is co - 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: diff --git a/appendix-A/02_installing-python-libraries/python_environment_check.ipynb b/appendix-A/02_installing-python-libraries/python_environment_check.ipynb index 3965b7e..46e9b67 100644 --- a/appendix-A/02_installing-python-libraries/python_environment_check.ipynb +++ b/appendix-A/02_installing-python-libraries/python_environment_check.ipynb @@ -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" ] } ], @@ -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": { @@ -54,7 +45,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.11.4" + "version": "3.10.12" } }, "nbformat": 4, diff --git a/appendix-A/02_installing-python-libraries/python_environment_check.py b/appendix-A/02_installing-python-libraries/python_environment_check.py index bd8ce71..52f214f 100644 --- a/appendix-A/02_installing-python-libraries/python_environment_check.py +++ b/appendix-A/02_installing-python-libraries/python_environment_check.py @@ -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 diff --git a/appendix-A/02_installing-python-libraries/requirements.txt b/appendix-A/02_installing-python-libraries/requirements.txt deleted file mode 100644 index 09fc464..0000000 --- a/appendix-A/02_installing-python-libraries/requirements.txt +++ /dev/null @@ -1,8 +0,0 @@ -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 \ No newline at end of file diff --git a/ch05/01_main-chapter-code/previous_chapters.py b/ch05/01_main-chapter-code/previous_chapters.py index 5f89eee..610f6f4 100644 --- a/ch05/01_main-chapter-code/previous_chapters.py +++ b/ch05/01_main-chapter-code/previous_chapters.py @@ -35,7 +35,7 @@ class GPTDatasetV1(Dataset): 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") @@ -78,7 +78,7 @@ class MultiHeadAttention(nn.Module): # 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) diff --git a/requirements.txt b/requirements.txt index 09fc464..f5867f0 100644 --- a/requirements.txt +++ b/requirements.txt @@ -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 \ No newline at end of file +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 \ No newline at end of file