Step | \n", "Training Loss | \n", "
---|---|
1 | \n", "1.537000 | \n", "
2 | \n", "1.443500 | \n", "
" ] }, "metadata": {} }, { "output_type": "stream", "name": "stderr", "text": [ "/usr/local/lib/python3.10/dist-packages/peft/utils/save_and_load.py:180: UserWarning: Setting `save_embedding_layers` to `True` as embedding layers found in `target_modules`.\n", " warnings.warn(\"Setting `save_embedding_layers` to `True` as embedding layers found in `target_modules`.\")\n", "/usr/local/lib/python3.10/dist-packages/torch/utils/checkpoint.py:464: UserWarning: torch.utils.checkpoint: the use_reentrant parameter should be passed explicitly. In version 2.4 we will raise an exception if use_reentrant is not passed. use_reentrant=False is recommended, but if you need to preserve the current default behavior, you can pass use_reentrant=True. Refer to docs for more details on the differences between the two variants.\n", " warnings.warn(\n", "/usr/local/lib/python3.10/dist-packages/peft/utils/save_and_load.py:180: UserWarning: Setting `save_embedding_layers` to `True` as embedding layers found in `target_modules`.\n", " warnings.warn(\"Setting `save_embedding_layers` to `True` as embedding layers found in `target_modules`.\")\n" ] }, { "output_type": "execute_result", "data": { "text/plain": [ "TrainOutput(global_step=2, training_loss=1.4902946949005127, metrics={'train_runtime': 17.0333, 'train_samples_per_second': 0.117, 'train_steps_per_second': 0.117, 'total_flos': 550276276224.0, 'train_loss': 1.4902946949005127, 'epoch': 0.0007974481658692185})" ] }, "metadata": {}, "execution_count": 29 } ] }, { "cell_type": "markdown", "source": [ "# Save Model and Push to Hub" ], "metadata": { "id": "vfrjVIN2rOWf" } }, { "cell_type": "code", "source": [ "# # Renable warnings for inference\n", "model.config.use_cache = True\n", "\n", "# Save trained model\n", "trainer.model.save_pretrained(\"gemma-ft\", save_embedding_layers=True)" ], "metadata": { "id": "s5v6uT-PDYCO" }, "execution_count": null, "outputs": [] }, { "cell_type": "code", "source": [ "write_key = userdata.get('HF_TOKEN')\n", "login(write_key)" ], "metadata": { "colab": { "base_uri": "https://localhost:8080/" }, "id": "jAyJq-3XDX9r", "outputId": "b5115872-c0fa-4e57-9ce5-68a5084ca95c" }, "execution_count": null, "outputs": [ { "output_type": "stream", "name": "stdout", "text": [ "The token has not been saved to the git credentials helper. Pass `add_to_git_credential=True` in this function directly or `--add-to-git-credential` if using via `huggingface-cli` if you want to set the git credential as well.\n", "Token is valid (permission: write).\n", "Your token has been saved to /root/.cache/huggingface/token\n", "Login successful\n" ] } ] }, { "cell_type": "code", "source": [ "# from huggingface_hub import notebook_login\n", "# notebook_login()" ], "metadata": { "id": "paRZrxqCbjxI" }, "execution_count": null, "outputs": [] }, { "cell_type": "code", "source": [ "# Push LoRA Adapters\n", "\n", "trainer.push_to_hub(\"bmartinc80/gemma-ft\")" ], "metadata": { "colab": { "base_uri": "https://localhost:8080/", "height": 255, "referenced_widgets": [ "517ba61eab604dbeafe8e9ed3da92ac3", "ddc20b0d5b684ea08584f35533876228", "7cdf2d82b2fa4579867cd54f4259cfd0", "9c5c7d47a5eb49e585372099c853db72", "aa1cbc4b5cf04e75b9495096bd116802", "f9fe1a6e91764a558d408e79609d92df", "6268ffdedcd6461c8a35a8578280a2fd", "85df3a34c5ea437793ad2eb01b8ee985", "08641e9c7b8e4befb6d32752a31908a2", "ef0714869adf49f58b2acc4cbfd07512", "803ca1b223194d93adeb89b7d2172547", "e5d7de61b1af4ebcaf6e4cb22b25464d", "6bf56bf6dc4b4a9081d172013974d734", "08bd68a82ac441ca843f48043b068159", "9374cc005ffc4814adccdc21e95ce4be", "1f4cff4178ff4d29957225a2bfdfb873", "f99180ceb12c45bd8dc5ba0533d5bab7", "638a09691932455e8d51a8527eb5d9cb", "e1635fbf4f7148e9bb067af8c5449c75", "63683fe1b8734939867081a0876a3964", "4b7a7f1c356e4ade9022be7fa3bc8ed5", "b053e218c8d04ea48339bb2f07c79558", "23035072acb1423da18015e29931fa8f", "718b2d7294194f1fa93677d9dca43e80", "dcb560c5bf6949778f8ef8f4dbb4ab3a", "7acd40975f2745e7af694285e80e56df", "7f34e5ee46d744a085e012a6b83a0f57", "7c977c78b05c4443a67d4f98a71d4383", "ecee013cdc444d92b894ea8ea76fed4d", "cb4f08ce2edb4cd0aa70bf610bfa8312", "22fae968553b407db9d9cadea46a06f9", "a626aa9e63f54a61b80693fac3f56e78", "e00a031b7ed44c3484f779a0d41c8c1f", "6727615955a8426ea3dcc425f8697334", "d8e8478b162d4016ac5f50ef35c65ad5", "64fe0bce16d74815b97edbb3351f7038", "6c5b03899a214de48413d70af5771959", "fc768a909f9348418b7810b41869fba5", "603fdc7a558242b98f5baba284527c08", "a46dd19154f3454e8e8c2d10d5708204", "a310fbf9b8f2499babf38f16aae54ee5", "e4c22055b01d4165af078c86a66940ea", "4c7e1a97ef13435e8dfd28c4d3546e6b", "991fdb8a2c6d45ee873d8edeeb3d68b4" ] }, "id": "D6UenhhuDX7Z", "outputId": "75d54c24-6d96-43e6-9017-059a70ecbabf" }, "execution_count": null, "outputs": [ { "output_type": "stream", "name": "stderr", "text": [ "/usr/local/lib/python3.10/dist-packages/peft/utils/save_and_load.py:180: UserWarning: Setting `save_embedding_layers` to `True` as embedding layers found in `target_modules`.\n", " warnings.warn(\"Setting `save_embedding_layers` to `True` as embedding layers found in `target_modules`.\")\n" ] }, { "output_type": "display_data", "data": { "text/plain": [ "Upload 3 LFS files: 0%| | 0/3 [00:00, ?it/s]" ], "application/vnd.jupyter.widget-view+json": { "version_major": 2, "version_minor": 0, "model_id": "517ba61eab604dbeafe8e9ed3da92ac3" } }, "metadata": {} }, { "output_type": "display_data", "data": { "text/plain": [ "adapter_model.safetensors: 0%| | 0.00/2.14G [00:00, ?B/s]" ], "application/vnd.jupyter.widget-view+json": { "version_major": 2, "version_minor": 0, "model_id": "e5d7de61b1af4ebcaf6e4cb22b25464d" } }, "metadata": {} }, { "output_type": "display_data", "data": { "text/plain": [ "events.out.tfevents.1716401851.218cecfccc92.2053.0: 0%| | 0.00/6.08k [00:00, ?B/s]" ], "application/vnd.jupyter.widget-view+json": { "version_major": 2, "version_minor": 0, "model_id": "23035072acb1423da18015e29931fa8f" } }, "metadata": {} }, { "output_type": "display_data", "data": { "text/plain": [ "training_args.bin: 0%| | 0.00/5.11k [00:00, ?B/s]" ], "application/vnd.jupyter.widget-view+json": { "version_major": 2, "version_minor": 0, "model_id": "6727615955a8426ea3dcc425f8697334" } }, "metadata": {} }, { "output_type": "execute_result", "data": { "text/plain": [ "CommitInfo(commit_url='https://huggingface.co/bmartinc80/gemma-ft/commit/5f3255dd574f9f38f8e26e1a03be7e60899bf391', commit_message='bmartinc80/gemma-ft', commit_description='', oid='5f3255dd574f9f38f8e26e1a03be7e60899bf391', pr_url=None, pr_revision=None, pr_num=None)" ], "application/vnd.google.colaboratory.intrinsic+json": { "type": "string" } }, "metadata": {}, "execution_count": 14 } ] }, { "cell_type": "markdown", "source": [ "# Test Model after Fine Tuning" ], "metadata": { "id": "4K_J7Zx8rofI" } }, { "cell_type": "code", "source": [ "# Merge Adapters with model\n", "\n", "merged_model = model.merge_and_unload()" ], "metadata": { "colab": { "base_uri": "https://localhost:8080/" }, "id": "WeaDSQv4DX5N", "outputId": "3661e086-263b-4638-8c35-fd465ccd8922" }, "execution_count": null, "outputs": [ { "output_type": "stream", "name": "stderr", "text": [ "/usr/local/lib/python3.10/dist-packages/peft/tuners/lora/bnb.py:325: UserWarning: Merge lora module to 4-bit linear may get different generations due to rounding errors.\n", " warnings.warn(\n" ] } ] }, { "cell_type": "code", "source": [ "text = \"Quote: If you want to know what a man's like\"\n", "device = \"cuda:0\"\n", "inputs = tokenizer(text, return_tensors=\"pt\").to(device)\n", "\n", "outputs = merged_model.generate(**inputs, max_new_tokens=20)\n", "print(tokenizer.decode(outputs[0], skip_special_tokens=True))" ], "metadata": { "colab": { "base_uri": "https://localhost:8080/" }, "id": "mqWjsDUbDX2v", "outputId": "6fccfa7f-d017-472d-b16d-5b91c55e1ff3" }, "execution_count": null, "outputs": [ { "output_type": "stream", "name": "stderr", "text": [ "`use_cache=True` is incompatible with gradient checkpointing. Setting `use_cache=False`.\n", "/usr/local/lib/python3.10/dist-packages/torch/utils/checkpoint.py:464: UserWarning: torch.utils.checkpoint: the use_reentrant parameter should be passed explicitly. In version 2.4 we will raise an exception if use_reentrant is not passed. use_reentrant=False is recommended, but if you need to preserve the current default behavior, you can pass use_reentrant=True. Refer to docs for more details on the differences between the two variants.\n", " warnings.warn(\n", "/usr/local/lib/python3.10/dist-packages/torch/utils/checkpoint.py:91: UserWarning: None of the inputs have requires_grad=True. Gradients will be None\n", " warnings.warn(\n" ] }, { "output_type": "stream", "name": "stdout", "text": [ "Quote: If you want to know what a man's like, take a look at how he treats his inferiors, for that is what he will treat his\n" ] } ] } ] }