Spaces:
Sleeping
Sleeping
File size: 27,452 Bytes
17a7426 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 |
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"True"
]
},
"execution_count": 1,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"import torch\n",
"\n",
"torch.cuda.is_available()"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"import glob\n",
"import math\n",
"import sys\n",
"import time\n",
"from pathlib import Path\n",
"from typing import Optional, Tuple, Union\n",
"\n",
"import lightning as L\n",
"import torch\n",
"from lightning.fabric.loggers import CSVLogger\n",
"from lightning.fabric.strategies import FSDPStrategy\n",
"from torch.utils.data import DataLoader\n",
"\n",
"# # support running without installing as a package\n",
"# wd = Path(__file__).parent.parent.resolve()\n",
"# sys.path.append(str(wd))\n",
"\n",
"from tsai_gpt.model import GPT, Block, Config\n",
"from tsai_gpt.packed_dataset import CombinedDataset, PackedDataset\n",
"from tsai_gpt.speed_monitor import SpeedMonitorBase, estimate_flops, measure_flops\n",
"from tsai_gpt.speed_monitor import SpeedMonitorFabric as SpeedMonitor\n",
"from tsai_gpt.utils import (\n",
" chunked_cross_entropy,\n",
" get_default_supported_precision,\n",
" num_parameters,\n",
" load_checkpoint,\n",
")"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
"model_name = \"pythia-160m\"\n",
"name = \"redpajama\"\n",
"out_dir = Path(\"out\") / name\n",
"save_interval = 1000\n",
"eval_interval = 1000\n",
"eval_iters = 100\n",
"log_interval = 100"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [],
"source": [
"# Hyperparameters\n",
"learning_rate = 6e-3\n",
"batch_size = 32\n",
"micro_batch_size = 8\n",
"gradient_accumulation_steps = batch_size // micro_batch_size\n",
"assert gradient_accumulation_steps > 0\n",
"# max_iters = 600000 # num_epochs * (epoch_size // micro_batch_size) // devices\n",
"max_iters = 15000\n",
"weight_decay = 1e-1\n",
"beta1 = 0.9\n",
"beta2 = 0.95\n",
"grad_clip = 1.0\n",
"decay_lr = True\n",
"warmup_iters = 2000\n",
"lr_decay_iters = max_iters\n",
"min_lr = 6e-6"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [],
"source": [
"# Data proportions from https://arxiv.org/pdf/2302.13971.pdf Table 1\n",
"data_config = [\n",
" (\"arxiv\", 2.5),\n",
" (\"book\", 4.5),\n",
" (\"c4\", 15.0),\n",
" (\"cc\", 67.0),\n",
" (\"github\", 4.5),\n",
" (\"stackexchange\", 2.0),\n",
" (\"wikipedia\", 4.5),\n",
"]"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [],
"source": [
"hparams = {\n",
" k: v\n",
" for k, v in locals().items()\n",
" if isinstance(v, (int, float, str)) and not k.startswith(\"_\")\n",
"}\n",
"logger = CSVLogger(\"out\", name, flush_logs_every_n_steps=log_interval)\n",
"\n",
"\n",
"def setup(\n",
" devices: int = 4,\n",
" train_data_dir: Path = Path(\"data/redpajama_sample\"),\n",
" val_data_dir: Optional[Path] = None,\n",
" precision: Optional[str] = None,\n",
" resume: Union[bool, Path] = False,\n",
") -> None:\n",
" precision = precision or get_default_supported_precision(training=True)\n",
"\n",
" if devices > 1:\n",
" strategy = FSDPStrategy(\n",
" auto_wrap_policy={Block},\n",
" activation_checkpointing_policy={Block},\n",
" state_dict_type=\"full\",\n",
" limit_all_gathers=True,\n",
" cpu_offload=False,\n",
" )\n",
" else:\n",
" strategy = \"auto\"\n",
"\n",
" fabric = L.Fabric(\n",
" devices=devices, strategy=strategy, precision=precision, loggers=logger\n",
" )\n",
" fabric.print(hparams)\n",
" fabric.launch(main, train_data_dir, val_data_dir, resume)"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [],
"source": [
"model_copy = None"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"outputs": [],
"source": [
"def main(\n",
" fabric: L.Fabric,\n",
" train_data_dir: Path,\n",
" val_data_dir: Path,\n",
" resume: Union[bool, Path],\n",
") -> None:\n",
" global model_copy\n",
" speed_monitor = SpeedMonitor(fabric, window_size=50, time_unit=\"seconds\")\n",
"\n",
" if fabric.global_rank == 0:\n",
" out_dir.mkdir(parents=True, exist_ok=True)\n",
"\n",
" config = Config.from_name(model_name)\n",
"\n",
" train_dataloader, val_dataloader = create_dataloaders(\n",
" batch_size=micro_batch_size,\n",
" block_size=config.block_size,\n",
" fabric=fabric,\n",
" train_data_dir=train_data_dir,\n",
" val_data_dir=val_data_dir,\n",
" seed=(1337 + fabric.global_rank),\n",
" )\n",
" if val_dataloader is None:\n",
" train_dataloader = fabric.setup_dataloaders(train_dataloader)\n",
" else:\n",
" train_dataloader, val_dataloader = fabric.setup_dataloaders(\n",
" train_dataloader, val_dataloader\n",
" )\n",
"\n",
" fabric.seed_everything(1337) # same seed for every process to init model (FSDP)\n",
"\n",
" fabric.print(f\"Loading model with {config.__dict__}\")\n",
" t0 = time.perf_counter()\n",
" import torch\n",
" import torch.nn as nn\n",
"\n",
" def _init_weights(module: nn.Module) -> None:\n",
" \"\"\"Meant to be used with `gpt.apply(gpt._init_weights)`.\"\"\"\n",
" if isinstance(module, nn.Linear):\n",
" torch.nn.init.normal_(module.weight, mean=0.0, std=0.02)\n",
" if module.bias is not None:\n",
" torch.nn.init.zeros_(module.bias)\n",
" elif isinstance(module, nn.Embedding):\n",
" torch.nn.init.normal_(module.weight, mean=0.0, std=0.02)\n",
"\n",
" with fabric.init_module(empty_init=True):\n",
" model = GPT(config)\n",
" model.apply(_init_weights)\n",
" model.apply(_init_weights)\n",
"\n",
" # checkpoint_path = Path(\"out/redpajama/iter-000999-ckpt.pth\")\n",
"\n",
" # load_checkpoint(fabric, model, checkpoint_path)\n",
"\n",
" # print(model.transformer.h[0].mlp.fc.weight)\n",
"\n",
" fabric.print(f\"Time to instantiate model: {time.perf_counter() - t0:.02f} seconds.\")\n",
" fabric.print(f\"Total parameters {num_parameters(model):,}\")\n",
"\n",
" model = fabric.setup(model)\n",
" optimizer = torch.optim.AdamW(\n",
" model.parameters(),\n",
" lr=learning_rate,\n",
" weight_decay=weight_decay,\n",
" betas=(beta1, beta2),\n",
" foreach=False,\n",
" )\n",
"\n",
" # model_copy = model\n",
"\n",
" optimizer = fabric.setup_optimizers(optimizer)\n",
"\n",
" state = {\n",
" \"model\": model,\n",
" \"optimizer\": optimizer,\n",
" \"hparams\": hparams,\n",
" \"iter_num\": 0,\n",
" \"step_count\": 0,\n",
" }\n",
"\n",
" if resume is True:\n",
" resume = max(out_dir.glob(\"*.pth\"), key=lambda p: int(p.name.split(\"-\")[1]))\n",
" if resume:\n",
" fabric.print(f\"Resuming training from {resume}\")\n",
" fabric.load(resume, state)\n",
"\n",
" train_time = time.perf_counter()\n",
" train(fabric, state, train_dataloader, val_dataloader, speed_monitor)\n",
" fabric.print(f\"Training time: {(time.perf_counter()-train_time):.2f}s\")\n",
" if fabric.device.type == \"cuda\":\n",
" fabric.print(f\"Memory used: {torch.cuda.max_memory_allocated() / 1e9:.02f} GB\")"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"outputs": [],
"source": [
"def train(\n",
" fabric: L.Fabric,\n",
" state: dict,\n",
" train_dataloader: DataLoader,\n",
" val_dataloader: DataLoader,\n",
" speed_monitor: SpeedMonitorBase,\n",
") -> None:\n",
" model = state[\"model\"]\n",
" optimizer = state[\"optimizer\"]\n",
"\n",
" if val_dataloader is not None:\n",
" validate(fabric, model, val_dataloader) # sanity check\n",
"\n",
" with torch.device(\"meta\"):\n",
" meta_model = GPT(model.config)\n",
" # \"estimated\" is not as precise as \"measured\". Estimated is optimistic but widely used in the wild.\n",
" # When comparing MFU or FLOP numbers with other projects that use estimated FLOPs,\n",
" # consider passing `SpeedMonitor(flops_per_batch=estimated_flops)` instead\n",
" estimated_flops = estimate_flops(meta_model) * micro_batch_size\n",
" fabric.print(\n",
" f\"Estimated TFLOPs: {estimated_flops * fabric.world_size / 1e12:.2f}\"\n",
" )\n",
" x = torch.randint(0, 1, (micro_batch_size, model.max_seq_length))\n",
" measured_flops = measure_flops(meta_model, x)\n",
" fabric.print(\n",
" f\"Measured TFLOPs: {measured_flops * fabric.world_size / 1e12:.2f}\"\n",
" )\n",
" del meta_model, x\n",
"\n",
" total_lengths = 0\n",
" total_t0 = time.perf_counter()\n",
"\n",
" for state[\"iter_num\"], train_data in enumerate(train_dataloader, state[\"iter_num\"]):\n",
" if state[\"iter_num\"] >= max_iters:\n",
" checkpoint_path = out_dir / f\"iter-{state['iter_num']:06d}-ckpt.pth\"\n",
" fabric.print(f\"Saving checkpoint to {str(checkpoint_path)!r}\")\n",
" fabric.save(checkpoint_path, state)\n",
" break\n",
"\n",
" # determine and set the learning rate for this iteration\n",
" lr = get_lr(state[\"iter_num\"]) if decay_lr else learning_rate\n",
" for param_group in optimizer.param_groups:\n",
" param_group[\"lr\"] = lr\n",
"\n",
" iter_t0 = time.perf_counter()\n",
"\n",
" input_ids = train_data[:, 0 : model.max_seq_length].contiguous()\n",
" targets = train_data[:, 1 : model.max_seq_length + 1].contiguous()\n",
"\n",
" is_accumulating = (state[\"iter_num\"] + 1) % gradient_accumulation_steps != 0\n",
" with fabric.no_backward_sync(model, enabled=is_accumulating):\n",
" logits = model(input_ids)\n",
" loss = chunked_cross_entropy(logits, targets, chunk_size=0)\n",
" fabric.backward(loss / gradient_accumulation_steps)\n",
"\n",
" # return\n",
"\n",
" if not is_accumulating:\n",
" fabric.clip_gradients(model, optimizer, max_norm=grad_clip)\n",
" optimizer.step()\n",
" optimizer.zero_grad()\n",
" state[\"step_count\"] += 1\n",
"\n",
" t1 = time.perf_counter()\n",
" total_lengths += input_ids.size(1)\n",
" speed_monitor.on_train_batch_end(\n",
" (state[\"iter_num\"] + 1) * micro_batch_size,\n",
" t1 - total_t0,\n",
" # this assumes that device FLOPs are the same and that all devices have the same batch size\n",
" fabric.world_size,\n",
" flops_per_batch=measured_flops,\n",
" lengths=total_lengths,\n",
" )\n",
" if state[\"iter_num\"] % log_interval == 0:\n",
" fabric.print(\n",
" f\"iter {state['iter_num']} step {state['step_count']}: loss {loss.item():.4f}, LR: {lr:.6f}, iter time:\"\n",
" f\" {(t1 - iter_t0) * 1000:.2f}ms{' (optimizer.step)' if not is_accumulating else ''}\"\n",
" )\n",
"\n",
" if (\n",
" val_dataloader is not None\n",
" and not is_accumulating\n",
" and state[\"step_count\"] % eval_interval == 0\n",
" ):\n",
" t0 = time.perf_counter()\n",
" val_loss = validate(fabric, model, val_dataloader)\n",
" t1 = time.perf_counter() - t0\n",
" speed_monitor.eval_end(t1)\n",
" fabric.print(\n",
" f\"step {state['iter_num']}: val loss {val_loss.item():.4f}, val time: {t1 * 1000:.2f}ms\"\n",
" )\n",
" fabric.barrier()\n",
" if not is_accumulating and state[\"step_count\"] % save_interval == 0:\n",
" checkpoint_path = out_dir / f\"iter-{state['iter_num']:06d}-ckpt.pth\"\n",
" fabric.print(f\"Saving checkpoint to {str(checkpoint_path)!r}\")\n",
" fabric.save(checkpoint_path, state)"
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {},
"outputs": [],
"source": [
"@torch.inference_mode()\n",
"def validate(\n",
" fabric: L.Fabric, model: torch.nn.Module, val_dataloader: DataLoader\n",
") -> torch.Tensor:\n",
" fabric.print(\"Validating ...\")\n",
" model.eval()\n",
"\n",
" losses = torch.zeros(eval_iters, device=fabric.device)\n",
" for k, val_data in enumerate(val_dataloader):\n",
" input_ids = val_data[:, 0 : model.max_seq_length].contiguous()\n",
" targets = val_data[:, 1 : model.max_seq_length + 1].contiguous()\n",
" logits = model(input_ids)\n",
" losses[k] = chunked_cross_entropy(logits, targets, chunk_size=0)\n",
" out = losses.mean()\n",
"\n",
" model.train()\n",
" return out"
]
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {},
"outputs": [],
"source": [
"def create_dataloader(\n",
" batch_size: int,\n",
" block_size: int,\n",
" data_dir: Path,\n",
" fabric: L.Fabric,\n",
" shuffle: bool = True,\n",
" seed: int = 12345,\n",
") -> DataLoader:\n",
" datasets = []\n",
" for prefix, _ in data_config:\n",
" filenames = glob.glob(str(data_dir / f\"{prefix}*\"))\n",
" dataset = PackedDataset(\n",
" filenames,\n",
" n_chunks=4,\n",
" block_size=block_size,\n",
" shuffle=shuffle,\n",
" seed=seed,\n",
" num_processes=fabric.world_size,\n",
" process_rank=fabric.global_rank,\n",
" )\n",
" datasets.append(dataset)\n",
"\n",
" if not datasets:\n",
" raise RuntimeError(\n",
" f\"No data found at {data_dir}. Make sure you ran prepare_redpajama.py to create the dataset.\"\n",
" )\n",
"\n",
" weights = [weight for _, weight in data_config]\n",
" sum_weights = sum(weights)\n",
" weights = [el / sum_weights for el in weights]\n",
"\n",
" combined_dataset = CombinedDataset(datasets=datasets, seed=seed, weights=weights)\n",
"\n",
" return DataLoader(\n",
" combined_dataset, batch_size=batch_size, shuffle=False, pin_memory=True\n",
" )"
]
},
{
"cell_type": "code",
"execution_count": 12,
"metadata": {},
"outputs": [],
"source": [
"def create_dataloaders(\n",
" batch_size: int,\n",
" block_size: int,\n",
" fabric: L.Fabric,\n",
" train_data_dir: Path = Path(\"data/redpajama_sample\"),\n",
" val_data_dir: Optional[Path] = None,\n",
" seed: int = 12345,\n",
") -> Tuple[DataLoader, DataLoader]:\n",
" # Increase by one because we need the next word as well\n",
" effective_block_size = block_size + 1\n",
" train_dataloader = create_dataloader(\n",
" batch_size=batch_size,\n",
" block_size=effective_block_size,\n",
" fabric=fabric,\n",
" data_dir=train_data_dir,\n",
" shuffle=True,\n",
" seed=seed,\n",
" )\n",
" val_dataloader = (\n",
" create_dataloader(\n",
" batch_size=batch_size,\n",
" block_size=effective_block_size,\n",
" fabric=fabric,\n",
" data_dir=val_data_dir,\n",
" shuffle=False,\n",
" seed=seed,\n",
" )\n",
" if val_data_dir\n",
" else None\n",
" )\n",
" return train_dataloader, val_dataloader"
]
},
{
"cell_type": "code",
"execution_count": 13,
"metadata": {},
"outputs": [],
"source": [
"def get_lr(it: int) -> float:\n",
" # 1) linear warmup for warmup_iters steps\n",
" if it < warmup_iters:\n",
" return learning_rate * it / warmup_iters\n",
" # 2) if it > lr_decay_iters, return min learning rate\n",
" if it > lr_decay_iters:\n",
" return min_lr\n",
" # 3) in between, use cosine decay down to min learning rate\n",
" decay_ratio = (it - warmup_iters) / (lr_decay_iters - warmup_iters)\n",
" assert 0 <= decay_ratio <= 1\n",
" coeff = 0.5 * (1.0 + math.cos(math.pi * decay_ratio)) # coeff ranges 0..1\n",
" return min_lr + coeff * (learning_rate - min_lr)"
]
},
{
"cell_type": "code",
"execution_count": 16,
"metadata": {},
"outputs": [],
"source": [
"# torch.set_float32_matmul_precision(\"medium\")\n",
"# setup(devices=1, train_data_dir=Path(\"data/lit-redpajama-sample\"))"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [],
"source": [
"from generate.base import main\n",
"from pathlib import Path"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"Loading model 'out/redpajama/lit_model.pth' with {'name': 'pythia-160m', 'hf_config': {'org': 'EleutherAI', 'name': 'pythia-160m'}, 'block_size': 2048, 'vocab_size': 50254, 'padding_multiple': 128, 'padded_vocab_size': 50304, 'n_layer': 12, 'n_head': 12, 'n_embd': 768, 'rotary_percentage': 0.25, 'parallel_residual': True, 'bias': True, 'lm_head_bias': False, 'n_query_groups': 12, 'shared_attention_norm': False, '_norm_class': 'LayerNorm', 'norm_eps': 1e-05, '_mlp_class': 'GptNeoxMLP', 'gelu_approximate': 'none', 'intermediate_size': 3072, 'rope_condense_ratio': 1, 'rope_base': 10000, 'head_size': 64, 'rope_n_elem': 16}\n",
"Time to instantiate model: 0.17 seconds.\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"Time to load the model weights: 0.50 seconds.\n",
"Seed set to 1234\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"Earth is a planet with rocky core and 100,000 hectares of natural Earth. Our planet is a planet with rocky core and 100,000 hectares of natural Earth. The sun has a warm, warm surface and the sun has a\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"Time for inference 1: 0.71 sec total, 70.90 tokens/sec\n",
"Memory used: 0.35 GB\n"
]
}
],
"source": [
"import torch\n",
"\n",
"torch.set_float32_matmul_precision(\"high\")\n",
"main(\n",
" prompt=\"Earth is a planet with rocky core and \",\n",
" checkpoint_dir=Path(\"out/redpajama\"),\n",
")"
]
},
{
"cell_type": "code",
"execution_count": 12,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"Loading model 'out/redpajama/lit_model.pth' with {'name': 'pythia-160m', 'hf_config': {'org': 'EleutherAI', 'name': 'pythia-160m'}, 'block_size': 2048, 'vocab_size': 50254, 'padding_multiple': 128, 'padded_vocab_size': 50304, 'n_layer': 12, 'n_head': 12, 'n_embd': 768, 'rotary_percentage': 0.25, 'parallel_residual': True, 'bias': True, 'lm_head_bias': False, 'n_query_groups': 12, 'shared_attention_norm': False, '_norm_class': 'LayerNorm', 'norm_eps': 1e-05, '_mlp_class': 'GptNeoxMLP', 'gelu_approximate': 'none', 'intermediate_size': 3072, 'rope_condense_ratio': 1, 'rope_base': 10000, 'head_size': 64, 'rope_n_elem': 16}\n",
"Time to instantiate model: 0.02 seconds.\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"Time to load the model weights: 0.49 seconds.\n",
"Seed set to 1234\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"I like to drive when it is raining outside and 100% of the time. The next day, I think you will see the right movement.\n",
"We already know that if you don't go to the center, you can be a hug, or a bit more vigor.\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"Time for inference 1: 0.69 sec total, 72.80 tokens/sec\n",
"Memory used: 0.35 GB\n"
]
}
],
"source": [
"main(\n",
" prompt=\"I like to drive when it is raining outside and \",\n",
" checkpoint_dir=Path(\"out/redpajama\"),\n",
")"
]
},
{
"cell_type": "code",
"execution_count": 13,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"Loading model 'out/redpajama/lit_model.pth' with {'name': 'pythia-160m', 'hf_config': {'org': 'EleutherAI', 'name': 'pythia-160m'}, 'block_size': 2048, 'vocab_size': 50254, 'padding_multiple': 128, 'padded_vocab_size': 50304, 'n_layer': 12, 'n_head': 12, 'n_embd': 768, 'rotary_percentage': 0.25, 'parallel_residual': True, 'bias': True, 'lm_head_bias': False, 'n_query_groups': 12, 'shared_attention_norm': False, '_norm_class': 'LayerNorm', 'norm_eps': 1e-05, '_mlp_class': 'GptNeoxMLP', 'gelu_approximate': 'none', 'intermediate_size': 3072, 'rope_condense_ratio': 1, 'rope_base': 10000, 'head_size': 64, 'rope_n_elem': 16}\n",
"Time to instantiate model: 0.02 seconds.\n",
"Time to load the model weights: 0.51 seconds.\n",
"Seed set to 1234\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"I like to drive when it is raining outside and 100% of the time. The next day, I think you will see the right movement.\n",
"We already know that if you don't go to the center, you can be a hug, or a bit more vigor.\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"Time for inference 1: 0.65 sec total, 76.96 tokens/sec\n",
"Memory used: 0.35 GB\n"
]
}
],
"source": [
"main(\n",
" prompt=\"I like to drive when it is raining outside and \",\n",
" checkpoint_dir=Path(\"out/redpajama\"),\n",
")"
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"Loading model 'out/redpajama/lit_model.pth' with {'name': 'pythia-160m', 'hf_config': {'org': 'EleutherAI', 'name': 'pythia-160m'}, 'block_size': 2048, 'vocab_size': 50254, 'padding_multiple': 128, 'padded_vocab_size': 50304, 'n_layer': 12, 'n_head': 12, 'n_embd': 768, 'rotary_percentage': 0.25, 'parallel_residual': True, 'bias': True, 'lm_head_bias': False, 'n_query_groups': 12, 'shared_attention_norm': False, '_norm_class': 'LayerNorm', 'norm_eps': 1e-05, '_mlp_class': 'GptNeoxMLP', 'gelu_approximate': 'none', 'intermediate_size': 3072, 'rope_condense_ratio': 1, 'rope_base': 10000, 'head_size': 64, 'rope_n_elem': 16}\n",
"Time to instantiate model: 0.02 seconds.\n",
"Time to load the model weights: 0.49 seconds.\n",
"Seed set to 1234\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"What a beautiful day it was, never imagined I would be able to 100,000 times a month. It was the beginning of a carpet, and was about 15 minutes to drain from the carpet. We were so overwhelmed, ready to do the kits,\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"Time for inference 1: 0.68 sec total, 73.18 tokens/sec\n",
"Memory used: 0.35 GB\n"
]
}
],
"source": [
"main(\n",
" prompt=\"What a beautiful day it was, never imagined I would be able to \",\n",
" checkpoint_dir=Path(\"out/redpajama\"),\n",
")"
]
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"Loading model 'out/redpajama/lit_model.pth' with {'name': 'pythia-160m', 'hf_config': {'org': 'EleutherAI', 'name': 'pythia-160m'}, 'block_size': 2048, 'vocab_size': 50254, 'padding_multiple': 128, 'padded_vocab_size': 50304, 'n_layer': 12, 'n_head': 12, 'n_embd': 768, 'rotary_percentage': 0.25, 'parallel_residual': True, 'bias': True, 'lm_head_bias': False, 'n_query_groups': 12, 'shared_attention_norm': False, '_norm_class': 'LayerNorm', 'norm_eps': 1e-05, '_mlp_class': 'GptNeoxMLP', 'gelu_approximate': 'none', 'intermediate_size': 3072, 'rope_condense_ratio': 1, 'rope_base': 10000, 'head_size': 64, 'rope_n_elem': 16}\n",
"Time to instantiate model: 0.02 seconds.\n",
"Time to load the model weights: 0.49 seconds.\n",
"Seed set to 1234\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"Do you think Einstein was the greatest ever physicist ever lived? I think 1 of the 1980s wrote a very deep, poetic narration of my life. I know all of you and your life is beautiful, especially in the sense of storytelling. You are. I know all of you\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"Time for inference 1: 0.68 sec total, 74.07 tokens/sec\n",
"Memory used: 0.35 GB\n"
]
}
],
"source": [
"main(\n",
" prompt=\"Do you think Einstein was the greatest ever physicist ever lived? I think \",\n",
" checkpoint_dir=Path(\"out/redpajama\"),\n",
")"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "base",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.13"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
|