|
82 | 82 | "name": "stdout", |
83 | 83 | "output_type": "stream", |
84 | 84 | "text": [ |
85 | | - "huggingface_hub version: 0.35.3\n", |
86 | | - "tokenizers version: 0.22.1\n", |
87 | | - "torch version: 2.8.0\n" |
| 85 | + "huggingface_hub version: 1.5.0\n", |
| 86 | + "tokenizers version: 0.22.2\n", |
| 87 | + "torch version: 2.8.0+cu128\n" |
88 | 88 | ] |
89 | 89 | } |
90 | 90 | ], |
|
659 | 659 | }, |
660 | 660 | { |
661 | 661 | "cell_type": "code", |
662 | | - "execution_count": 14, |
| 662 | + "execution_count": null, |
663 | 663 | "id": "adf0a6b7-b688-42c9-966e-c223d34db99f", |
664 | 664 | "metadata": {}, |
665 | 665 | "outputs": [ |
666 | 666 | { |
667 | 667 | "data": { |
668 | 668 | "text/plain": [ |
669 | | - "tensor([[[-0.2256, -0.0164, -0.7070, ..., 0.4414, 0.1245, 1.0703],\n", |
670 | | - " [-0.6602, 0.5352, -0.0718, ..., -0.0737, 0.5391, 0.3086],\n", |
671 | | - " [-0.4785, -0.1562, 0.1045, ..., -0.2324, 0.2354, 0.6328]]],\n", |
| 669 | + "tensor([[[-0.2334, -0.0134, -0.7031, ..., 0.4316, 0.1177, 1.0703],\n", |
| 670 | + " [-0.6641, 0.5352, -0.0752, ..., -0.0698, 0.5430, 0.3203],\n", |
| 671 | + " [-0.4785, -0.1748, 0.1074, ..., -0.2354, 0.2354, 0.6289]]],\n", |
672 | 672 | " dtype=torch.bfloat16, grad_fn=<UnsafeViewBackward0>)" |
673 | 673 | ] |
674 | 674 | }, |
|
922 | 922 | "id": "699cb1b8-a67d-49fb-80a6-0dad9d81f392", |
923 | 923 | "outputId": "55b2f28c-142f-4698-9d23-d27456d3ed6d" |
924 | 924 | }, |
925 | | - "outputs": [ |
926 | | - { |
927 | | - "name": "stderr", |
928 | | - "output_type": "stream", |
929 | | - "text": [ |
930 | | - "/Users/sebastian/Developer/LLMs-from-scratch/.venv/lib/python3.13/site-packages/tqdm/auto.py:21: TqdmWarning: IProgress not found. Please update jupyter and ipywidgets. See https://ipywidgets.readthedocs.io/en/stable/user_install.html\n", |
931 | | - " from .autonotebook import tqdm as notebook_tqdm\n" |
932 | | - ] |
933 | | - } |
934 | | - ], |
| 925 | + "outputs": [], |
935 | 926 | "source": [ |
936 | 927 | "import json\n", |
937 | 928 | "import os\n", |
|
1182 | 1173 | "<think>\n", |
1183 | 1174 | "Okay, the user wants a short introduction to large language models. Let me start by recalling what I know. Large language models are AI systems that can understand and generate human language. They're trained on massive datasets, so they can learn complex patterns and nuances.\n", |
1184 | 1175 | "\n", |
1185 | | - "I should mention their ability to understand and generate text, not just specific tasks. Maybe include examples like chatbots or content generation. Also, emphasize their adaptability and efficiency. Oh, and maybe touch on their applications in various fields. Let me check if I'm covering all key points without being too technical. Keep it concise, around a sentence or two. Make sure it's clear and easy to understand.\n", |
| 1176 | + "I should mention their ability to understand and generate text, not just specific tasks. Maybe include examples like chatbots or language assistants. Also, emphasize their adaptability and versatility. Oh, and maybe touch on their applications in various fields. Let me check if I'm covering all key points without being too technical. Keep it concise, around a sentence or two. Make sure it's clear and easy to understand.\n", |
1186 | 1177 | "</think>\n", |
1187 | 1178 | "\n", |
1188 | | - "Large language models (LLMs) are AI systems designed to understand and generate human language, enabling tasks like text generation, translation, and content creation. They are trained on vast datasets, allowing them to learn complex patterns and nuances, making them versatile for a wide range of applications." |
| 1179 | + "Large language models (LLMs) are AI systems designed to understand and generate human language, enabling tasks like text generation, translation, and answering questions. They are trained on vast datasets, allowing them to learn complex patterns and nuances, making them versatile for applications in various domains.\n", |
| 1180 | + "\n", |
| 1181 | + "Generation speed: 48.46 tokens/sec\n", |
| 1182 | + "GPU memory used: 1.50 GB\n" |
1189 | 1183 | ] |
1190 | 1184 | } |
1191 | 1185 | ], |
1192 | 1186 | "source": [ |
| 1187 | + "import time\n", |
| 1188 | + "\n", |
1193 | 1189 | "input_token_ids_tensor = torch.tensor(input_token_ids, device=device).unsqueeze(0)\n", |
1194 | 1190 | "\n", |
| 1191 | + "if torch.cuda.is_available():\n", |
| 1192 | + " torch.cuda.reset_peak_memory_stats()\n", |
| 1193 | + "\n", |
| 1194 | + "start_time = time.perf_counter()\n", |
| 1195 | + "generated_tokens = 0\n", |
1195 | 1196 | "\n", |
1196 | 1197 | "for token in generate_text_basic_stream(\n", |
1197 | 1198 | " model=model,\n", |
1198 | 1199 | " token_ids=input_token_ids_tensor,\n", |
1199 | 1200 | " max_new_tokens=500,\n", |
1200 | 1201 | " eos_token_id=tokenizer.eos_token_id\n", |
1201 | 1202 | "):\n", |
| 1203 | + " generated_tokens += 1\n", |
1202 | 1204 | " token_id = token.squeeze(0).tolist()\n", |
1203 | 1205 | " print(\n", |
1204 | 1206 | " tokenizer.decode(token_id),\n", |
1205 | 1207 | " end=\"\",\n", |
1206 | 1208 | " flush=True\n", |
1207 | | - " )" |
| 1209 | + " )\n", |
| 1210 | + "\n", |
| 1211 | + "elapsed = time.perf_counter() - start_time\n", |
| 1212 | + "tokens_per_sec = generated_tokens / elapsed if elapsed > 0 else 0.0\n", |
| 1213 | + "print(f\"\\n\\nGeneration speed: {tokens_per_sec:.2f} tokens/sec\")\n", |
| 1214 | + "\n", |
| 1215 | + "if torch.cuda.is_available():\n", |
| 1216 | + " def calc_gpu_gb(x):\n", |
| 1217 | + " return f\"{x / 1024 / 1024 / 1024:.2f} GB\"\n", |
| 1218 | + "\n", |
| 1219 | + " print(f\"GPU memory used: {calc_gpu_gb(torch.cuda.max_memory_allocated())}\")\n" |
1208 | 1220 | ] |
1209 | 1221 | }, |
1210 | 1222 | { |
|
0 commit comments