|
451 | 451 | "source": [
|
452 | 452 | "## Testing the Pre-Trained Model\n",
|
453 | 453 | "\n",
|
454 |
| - "If you've configured the workbench with a NVIDIA GPU or AMD accelerator, you can run inference to validate the output generated by the fine-tuned model and compare it to the output of the pre-trained model.\n", |
| 454 | + "If you've configured the workbench with a NVIDIA GPU or AMD accelerator, you can run inferences to validate the output generated by the fine-tuned model and compare it to the output of the pre-trained model." |
| 455 | + ] |
| 456 | + }, |
| 457 | + { |
| 458 | + "cell_type": "code", |
| 459 | + "execution_count": null, |
| 460 | + "id": "ac2be9e5", |
| 461 | + "metadata": {}, |
| 462 | + "outputs": [], |
| 463 | + "source": [ |
| 464 | + "# Install / upgrade dependencies\n", |
| 465 | + "!pip install --upgrade transformers peft" |
| 466 | + ] |
| 467 | + }, |
| 468 | + { |
| 469 | + "cell_type": "code", |
| 470 | + "execution_count": null, |
| 471 | + "id": "52431fb6", |
| 472 | + "metadata": {}, |
| 473 | + "outputs": [], |
| 474 | + "source": [ |
| 475 | + "import torch\n", |
| 476 | + "import json\n", |
| 477 | + "import transformers\n", |
455 | 478 | "\n",
|
456 |
| - "Check / update the pathes to the pre-trained and fine-tuned model checkpoints prior to executing the cells below. " |
| 479 | + "from transformers import AutoModelForCausalLM, AutoTokenizer, pipeline\n", |
| 480 | + "from peft import LoraConfig, PeftModel\n", |
| 481 | + "from IPython.display import display, Markdown" |
| 482 | + ] |
| 483 | + }, |
| 484 | + { |
| 485 | + "cell_type": "markdown", |
| 486 | + "id": "955d1383", |
| 487 | + "metadata": {}, |
| 488 | + "source": [ |
| 489 | + "Check / update the paths to the pre-trained and fine-tuned model checkpoints prior to executing the cells below. " |
457 | 490 | ]
|
458 | 491 | },
|
459 | 492 | {
|
|
506 | 539 | "messages = [\n",
|
507 | 540 | " {\n",
|
508 | 541 | " \"role\": \"user\",\n",
|
509 |
| - " \"content\": \"\"\n", |
| 542 | + " \"content\": \"Janet's ducks lay 16 eggs per day. She eats three for breakfast every morning and bakes muffins for her friends every day with four. She sells the remainder at the farmers' market daily for $2 per fresh duck egg. How much in dollars does she make every day at the farmers' market?\",\n", |
510 | 543 | " }\n",
|
511 | 544 | "]\n",
|
512 | 545 | "\n",
|
513 |
| - "outputs = pipeline(messages, max_new_tokens=256)\n", |
| 546 | + "outputs = pipeline(messages, max_new_tokens=256, temperature = 0.01)\n", |
514 | 547 | "\n",
|
515 | 548 | "output = \"\"\n",
|
516 | 549 | "for turn in outputs:\n",
|
517 |
| - " for item in turn[\"generated text\"]:\n", |
| 550 | + " for item in turn[\"generated_text\"]:\n", |
518 | 551 | " output += f\"# {item['role']}\\n\\n{item['content']}\\n\\n\"\n",
|
519 | 552 | "\n",
|
520 | 553 | "display(Markdown(output))"
|
|
540 | 573 | "outputs": [],
|
541 | 574 | "source": [
|
542 | 575 | "# Merge the fine-tuned adapters into the base model \n",
|
543 |
| - "finetuned_path = \"/opt/app-root/src/shared/Meta-Llama-3.1-8B-Instruct/checkpoint-30/\"\n", |
| 576 | + "finetuned_path = \"/opt/app-root/src/shared/Meta-Llama-3.1-8B-Instruct/checkpoint-300/\"\n", |
544 | 577 | "model = PeftModel.from_pretrained(base_model, finetuned_path)\n",
|
545 | 578 | "model = model.merge_and_unload()"
|
546 | 579 | ]
|
|
572 | 605 | "messages = [\n",
|
573 | 606 | " {\n",
|
574 | 607 | " \"role\": \"user\",\n",
|
575 |
| - " \"content\": \"\"\n", |
| 608 | + " \"content\": \"Janet's ducks lay 16 eggs per day. She eats three for breakfast every morning and bakes muffins for her friends every day with four. She sells the remainder at the farmers' market daily for $2 per fresh duck egg. How much in dollars does she make every day at the farmers' market?\",\n", |
576 | 609 | " }\n",
|
577 | 610 | "]\n",
|
578 | 611 | "\n",
|
579 |
| - "outputs = pipeline(messages, max_new_tokens=256)\n", |
| 612 | + "outputs = pipeline(messages, max_new_tokens=256, temperature = 0.01)\n", |
580 | 613 | "\n",
|
581 | 614 | "output = \"\"\n",
|
582 | 615 | "for turn in outputs:\n",
|
583 |
| - " for item in turn[\"generated text\"]:\n", |
| 616 | + " for item in turn[\"generated_text\"]:\n", |
584 | 617 | " output += f\"# {item['role']}\\n\\n{item['content']}\\n\\n\"\n",
|
585 | 618 | "\n",
|
586 | 619 | "display(Markdown(output))"
|
|
0 commit comments