Add PyPI package (#576)

* Add PyPI package

* fixes

* fixes
This commit is contained in:
Sebastian Raschka
2025-03-23 19:28:49 -05:00
committed by GitHub
parent 7757c3d308
commit c21bfe4a23
52 changed files with 2173 additions and 2585 deletions

View File

@@ -1541,6 +1541,12 @@
"source": [
"from gpt_download import download_and_load_gpt2\n",
"from previous_chapters import GPTModel, load_weights_into_gpt\n",
"# If the `previous_chapters.py` file is not available locally,\n",
"# you can import it from the `llms-from-scratch` PyPI package.\n",
"# For details, see: https://github.com/rasbt/LLMs-from-scratch/tree/main/pkg\n",
"# E.g.,\n",
"# from llms_from_scratch.ch04 import GPTModel\n",
"# from llms_from_scratch.ch05 import download_and_load_gpt2, load_weights_into_gpt\n",
"\n",
"\n",
"BASE_CONFIG = {\n",
@@ -1626,6 +1632,13 @@
" text_to_token_ids,\n",
" token_ids_to_text\n",
")\n",
"# Alternatively:\n",
"# from llms_from_scratch.ch05 import (\n",
"# generate_text_simple,\n",
"# text_to_token_ids,\n",
"# token_ids_to_text\n",
"# )\n",
"\n",
"\n",
"token_ids = generate(\n",
" model=model,\n",
@@ -1727,7 +1740,12 @@
"from previous_chapters import (\n",
" calc_loss_loader,\n",
" train_model_simple\n",
")"
")\n",
"# Alternatively:\n",
"# from llms_from_scratch.ch05 import (\n",
"# calc_loss_loader,\n",
"# train_model_simple,\n",
"# )\n"
]
},
{
@@ -1939,6 +1957,8 @@
],
"source": [
"from previous_chapters import plot_losses\n",
"# Alternatively:\n",
"# from llms_from_scratch.ch05 import plot_losses\n",
"\n",
"epochs_tensor = torch.linspace(0, num_epochs, len(train_losses))\n",
"plot_losses(epochs_tensor, tokens_seen, train_losses, val_losses)"