{ "nbformat": 4, "nbformat_minor": 0, "metadata": { "colab": { "provenance": [], "gpuType": "T4" }, "kernelspec": { "name": "python3", "display_name": "Python 3" }, "language_info": { "name": "python" }, "accelerator": "GPU", "widgets": { "application/vnd.jupyter.widget-state+json": { "889a41c65d55459f9246f02f503ebbf0": { "model_module": "@jupyter-widgets/controls", "model_name": "HBoxModel", "model_module_version": "1.5.0", "state": { "_dom_classes": [], "_model_module": "@jupyter-widgets/controls", "_model_module_version": "1.5.0", "_model_name": "HBoxModel", "_view_count": null, "_view_module": "@jupyter-widgets/controls", "_view_module_version": "1.5.0", "_view_name": "HBoxView", "box_style": "", "children": [ "IPY_MODEL_fa68cdb4201a465d97743a0f2f11cc1d", "IPY_MODEL_a34d0134e905481eb98161ab8b4d5220", "IPY_MODEL_508acab63d0b404bacef7c521e304331" ], "layout": "IPY_MODEL_3dc910c9a2814ef6863f3638692b6d7a" } }, "fa68cdb4201a465d97743a0f2f11cc1d": { "model_module": "@jupyter-widgets/controls", "model_name": "HTMLModel", "model_module_version": "1.5.0", "state": { "_dom_classes": [], "_model_module": "@jupyter-widgets/controls", "_model_module_version": "1.5.0", "_model_name": "HTMLModel", "_view_count": null, "_view_module": "@jupyter-widgets/controls", "_view_module_version": "1.5.0", "_view_name": "HTMLView", "description": "", "description_tooltip": null, "layout": "IPY_MODEL_86feaf9bb378464688edfafff26c6461", "placeholder": "​", "style": "IPY_MODEL_b94f06f4d85941f18a81d19f1765a813", "value": "Generating train split: " } }, "a34d0134e905481eb98161ab8b4d5220": { "model_module": "@jupyter-widgets/controls", "model_name": "FloatProgressModel", "model_module_version": "1.5.0", "state": { "_dom_classes": [], "_model_module": "@jupyter-widgets/controls", "_model_module_version": "1.5.0", "_model_name": "FloatProgressModel", "_view_count": null, "_view_module": "@jupyter-widgets/controls", "_view_module_version": "1.5.0", "_view_name": "ProgressView", "bar_style": "success", "description": "", "description_tooltip": null, "layout": "IPY_MODEL_a44a1863a7d74884a791a510bafde50c", "max": 1, "min": 0, "orientation": "horizontal", "style": "IPY_MODEL_be843cdc969d468eade5b17f31c9853b", "value": 1 } }, "508acab63d0b404bacef7c521e304331": { "model_module": "@jupyter-widgets/controls", "model_name": "HTMLModel", "model_module_version": "1.5.0", "state": { "_dom_classes": [], "_model_module": "@jupyter-widgets/controls", "_model_module_version": "1.5.0", "_model_name": "HTMLModel", "_view_count": null, "_view_module": "@jupyter-widgets/controls", "_view_module_version": "1.5.0", "_view_name": "HTMLView", "description": "", "description_tooltip": null, "layout": "IPY_MODEL_360b89d6ce904eff9a2ef15ce0834d05", "placeholder": "​", "style": "IPY_MODEL_dadcd84da528485cb19808ce43c6f3b5", "value": " 247/0 [00:00<00:00, 2110.67 examples/s]" } }, "3dc910c9a2814ef6863f3638692b6d7a": { "model_module": "@jupyter-widgets/base", "model_name": "LayoutModel", "model_module_version": "1.2.0", "state": { "_model_module": "@jupyter-widgets/base", "_model_module_version": "1.2.0", "_model_name": "LayoutModel", "_view_count": null, "_view_module": "@jupyter-widgets/base", "_view_module_version": "1.2.0", "_view_name": "LayoutView", "align_content": null, "align_items": null, "align_self": null, "border": null, "bottom": null, "display": null, "flex": null, "flex_flow": null, "grid_area": null, "grid_auto_columns": null, "grid_auto_flow": null, "grid_auto_rows": null, "grid_column": null, "grid_gap": null, "grid_row": null, "grid_template_areas": null, "grid_template_columns": null, "grid_template_rows": null, "height": null, "justify_content": null, "justify_items": null, "left": null, "margin": null, "max_height": null, "max_width": null, "min_height": null, "min_width": null, "object_fit": null, "object_position": null, "order": null, "overflow": null, "overflow_x": null, "overflow_y": null, "padding": null, "right": null, "top": null, "visibility": null, "width": null } }, "86feaf9bb378464688edfafff26c6461": { "model_module": "@jupyter-widgets/base", "model_name": "LayoutModel", "model_module_version": "1.2.0", "state": { "_model_module": "@jupyter-widgets/base", "_model_module_version": "1.2.0", "_model_name": "LayoutModel", "_view_count": null, "_view_module": "@jupyter-widgets/base", "_view_module_version": "1.2.0", "_view_name": "LayoutView", "align_content": null, "align_items": null, "align_self": null, "border": null, "bottom": null, "display": null, "flex": null, "flex_flow": null, "grid_area": null, "grid_auto_columns": null, "grid_auto_flow": null, "grid_auto_rows": null, "grid_column": null, "grid_gap": null, "grid_row": null, "grid_template_areas": null, "grid_template_columns": null, "grid_template_rows": null, "height": null, "justify_content": null, "justify_items": null, "left": null, "margin": null, "max_height": null, "max_width": null, "min_height": null, "min_width": null, "object_fit": null, "object_position": null, "order": null, "overflow": null, "overflow_x": null, "overflow_y": null, "padding": null, "right": null, "top": null, "visibility": null, "width": null } }, "b94f06f4d85941f18a81d19f1765a813": { "model_module": "@jupyter-widgets/controls", "model_name": "DescriptionStyleModel", "model_module_version": "1.5.0", "state": { "_model_module": "@jupyter-widgets/controls", "_model_module_version": "1.5.0", "_model_name": "DescriptionStyleModel", "_view_count": null, "_view_module": "@jupyter-widgets/base", "_view_module_version": "1.2.0", "_view_name": "StyleView", "description_width": "" } }, "a44a1863a7d74884a791a510bafde50c": { "model_module": "@jupyter-widgets/base", "model_name": "LayoutModel", "model_module_version": "1.2.0", "state": { "_model_module": "@jupyter-widgets/base", "_model_module_version": "1.2.0", "_model_name": "LayoutModel", "_view_count": null, "_view_module": "@jupyter-widgets/base", "_view_module_version": "1.2.0", "_view_name": "LayoutView", "align_content": null, "align_items": null, "align_self": null, "border": null, "bottom": null, "display": null, "flex": null, "flex_flow": null, "grid_area": null, "grid_auto_columns": null, "grid_auto_flow": null, "grid_auto_rows": null, "grid_column": null, "grid_gap": null, "grid_row": null, "grid_template_areas": null, "grid_template_columns": null, "grid_template_rows": null, "height": null, "justify_content": null, "justify_items": null, "left": null, "margin": null, "max_height": null, "max_width": null, "min_height": null, "min_width": null, "object_fit": null, "object_position": null, "order": null, "overflow": null, "overflow_x": null, "overflow_y": null, "padding": null, "right": null, "top": null, "visibility": null, "width": "20px" } }, "be843cdc969d468eade5b17f31c9853b": { "model_module": "@jupyter-widgets/controls", "model_name": "ProgressStyleModel", "model_module_version": "1.5.0", "state": { "_model_module": "@jupyter-widgets/controls", "_model_module_version": "1.5.0", "_model_name": "ProgressStyleModel", "_view_count": null, "_view_module": "@jupyter-widgets/base", "_view_module_version": "1.2.0", "_view_name": "StyleView", "bar_color": null, "description_width": "" } }, "360b89d6ce904eff9a2ef15ce0834d05": { "model_module": "@jupyter-widgets/base", "model_name": "LayoutModel", "model_module_version": "1.2.0", "state": { "_model_module": "@jupyter-widgets/base", "_model_module_version": "1.2.0", "_model_name": "LayoutModel", "_view_count": null, "_view_module": "@jupyter-widgets/base", "_view_module_version": "1.2.0", "_view_name": "LayoutView", "align_content": null, "align_items": null, "align_self": null, "border": null, "bottom": null, "display": null, "flex": null, "flex_flow": null, "grid_area": null, "grid_auto_columns": null, "grid_auto_flow": null, "grid_auto_rows": null, "grid_column": null, "grid_gap": null, "grid_row": null, "grid_template_areas": null, "grid_template_columns": null, "grid_template_rows": null, "height": null, "justify_content": null, "justify_items": null, "left": null, "margin": null, "max_height": null, "max_width": null, "min_height": null, "min_width": null, "object_fit": null, "object_position": null, "order": null, "overflow": null, "overflow_x": null, "overflow_y": null, "padding": null, "right": null, "top": null, "visibility": null, "width": null } }, "dadcd84da528485cb19808ce43c6f3b5": { "model_module": "@jupyter-widgets/controls", "model_name": "DescriptionStyleModel", "model_module_version": "1.5.0", "state": { "_model_module": "@jupyter-widgets/controls", "_model_module_version": "1.5.0", "_model_name": "DescriptionStyleModel", "_view_count": null, "_view_module": "@jupyter-widgets/base", "_view_module_version": "1.2.0", "_view_name": "StyleView", "description_width": "" } }, "8a0bd3ae71614353bf304f0c6ba0129b": { "model_module": "@jupyter-widgets/controls", "model_name": "HBoxModel", "model_module_version": "1.5.0", "state": { "_dom_classes": [], "_model_module": "@jupyter-widgets/controls", "_model_module_version": "1.5.0", "_model_name": "HBoxModel", "_view_count": null, "_view_module": "@jupyter-widgets/controls", "_view_module_version": "1.5.0", "_view_name": "HBoxView", "box_style": "", "children": [ "IPY_MODEL_c6fbdd95446c460b95592cc07cde686a", "IPY_MODEL_5ff168b48f4b412087e1f766bb87956a", "IPY_MODEL_dadf2ccd980f470fab187b472edb8b8c" ], "layout": "IPY_MODEL_55ead45c0cff480b908b417ab80555e5" } }, "c6fbdd95446c460b95592cc07cde686a": { "model_module": "@jupyter-widgets/controls", "model_name": "HTMLModel", "model_module_version": "1.5.0", "state": { "_dom_classes": [], "_model_module": "@jupyter-widgets/controls", "_model_module_version": "1.5.0", "_model_name": "HTMLModel", "_view_count": null, "_view_module": "@jupyter-widgets/controls", "_view_module_version": "1.5.0", "_view_name": "HTMLView", "description": "", "description_tooltip": null, "layout": "IPY_MODEL_6a08100aae0c405ca468db9687e41077", "placeholder": "​", "style": "IPY_MODEL_e4032377ff5f46809fec908700763253", "value": "Map: 100%" } }, "5ff168b48f4b412087e1f766bb87956a": { "model_module": "@jupyter-widgets/controls", "model_name": "FloatProgressModel", "model_module_version": "1.5.0", "state": { "_dom_classes": [], "_model_module": "@jupyter-widgets/controls", "_model_module_version": "1.5.0", "_model_name": "FloatProgressModel", "_view_count": null, "_view_module": "@jupyter-widgets/controls", "_view_module_version": "1.5.0", "_view_name": "ProgressView", "bar_style": "success", "description": "", "description_tooltip": null, "layout": "IPY_MODEL_89b7379dc1964cbc960cc1587258fc7b", "max": 247, "min": 0, "orientation": "horizontal", "style": "IPY_MODEL_b0ebdcd1e69c41929808b9acaadf9297", "value": 247 } }, "dadf2ccd980f470fab187b472edb8b8c": { "model_module": "@jupyter-widgets/controls", "model_name": "HTMLModel", "model_module_version": "1.5.0", "state": { "_dom_classes": [], "_model_module": "@jupyter-widgets/controls", "_model_module_version": "1.5.0", "_model_name": "HTMLModel", "_view_count": null, "_view_module": "@jupyter-widgets/controls", "_view_module_version": "1.5.0", "_view_name": "HTMLView", "description": "", "description_tooltip": null, "layout": "IPY_MODEL_709ca2bd0b3d4911be981b4ad517785b", "placeholder": "​", "style": "IPY_MODEL_087013a6997e4afd81160abbcf385369", "value": " 247/247 [00:00<00:00, 3392.96 examples/s]" } }, "55ead45c0cff480b908b417ab80555e5": { "model_module": "@jupyter-widgets/base", "model_name": "LayoutModel", "model_module_version": "1.2.0", "state": { "_model_module": "@jupyter-widgets/base", "_model_module_version": "1.2.0", "_model_name": "LayoutModel", "_view_count": null, "_view_module": "@jupyter-widgets/base", "_view_module_version": "1.2.0", "_view_name": "LayoutView", "align_content": null, "align_items": null, "align_self": null, "border": null, "bottom": null, "display": null, "flex": null, "flex_flow": null, "grid_area": null, "grid_auto_columns": null, "grid_auto_flow": null, "grid_auto_rows": null, "grid_column": null, "grid_gap": null, "grid_row": null, "grid_template_areas": null, "grid_template_columns": null, "grid_template_rows": null, "height": null, "justify_content": null, "justify_items": null, "left": null, "margin": null, "max_height": null, "max_width": null, "min_height": null, "min_width": null, "object_fit": null, "object_position": null, "order": null, "overflow": null, "overflow_x": null, "overflow_y": null, "padding": null, "right": null, "top": null, "visibility": null, "width": null } }, "6a08100aae0c405ca468db9687e41077": { "model_module": "@jupyter-widgets/base", "model_name": "LayoutModel", "model_module_version": "1.2.0", "state": { "_model_module": "@jupyter-widgets/base", "_model_module_version": "1.2.0", "_model_name": "LayoutModel", "_view_count": null, "_view_module": "@jupyter-widgets/base", "_view_module_version": "1.2.0", "_view_name": "LayoutView", "align_content": null, "align_items": null, "align_self": null, "border": null, "bottom": null, "display": null, "flex": null, "flex_flow": null, "grid_area": null, "grid_auto_columns": null, "grid_auto_flow": null, "grid_auto_rows": null, "grid_column": null, "grid_gap": null, "grid_row": null, "grid_template_areas": null, "grid_template_columns": null, "grid_template_rows": null, "height": null, "justify_content": null, "justify_items": null, "left": null, "margin": null, "max_height": null, "max_width": null, "min_height": null, "min_width": null, "object_fit": null, "object_position": null, "order": null, "overflow": null, "overflow_x": null, "overflow_y": null, "padding": null, "right": null, "top": null, "visibility": null, "width": null } }, "e4032377ff5f46809fec908700763253": { "model_module": "@jupyter-widgets/controls", "model_name": "DescriptionStyleModel", "model_module_version": "1.5.0", "state": { "_model_module": "@jupyter-widgets/controls", "_model_module_version": "1.5.0", "_model_name": "DescriptionStyleModel", "_view_count": null, "_view_module": "@jupyter-widgets/base", "_view_module_version": "1.2.0", "_view_name": "StyleView", "description_width": "" } }, "89b7379dc1964cbc960cc1587258fc7b": { "model_module": "@jupyter-widgets/base", "model_name": "LayoutModel", "model_module_version": "1.2.0", "state": { "_model_module": "@jupyter-widgets/base", "_model_module_version": "1.2.0", "_model_name": "LayoutModel", "_view_count": null, "_view_module": "@jupyter-widgets/base", "_view_module_version": "1.2.0", "_view_name": "LayoutView", "align_content": null, "align_items": null, "align_self": null, "border": null, "bottom": null, "display": null, "flex": null, "flex_flow": null, "grid_area": null, "grid_auto_columns": null, "grid_auto_flow": null, "grid_auto_rows": null, "grid_column": null, "grid_gap": null, "grid_row": null, "grid_template_areas": null, "grid_template_columns": null, "grid_template_rows": null, "height": null, "justify_content": null, "justify_items": null, "left": null, "margin": null, "max_height": null, "max_width": null, "min_height": null, "min_width": null, "object_fit": null, "object_position": null, "order": null, "overflow": null, "overflow_x": null, "overflow_y": null, "padding": null, "right": null, "top": null, "visibility": null, "width": null } }, "b0ebdcd1e69c41929808b9acaadf9297": { "model_module": "@jupyter-widgets/controls", "model_name": "ProgressStyleModel", "model_module_version": "1.5.0", "state": { "_model_module": "@jupyter-widgets/controls", "_model_module_version": "1.5.0", "_model_name": "ProgressStyleModel", "_view_count": null, "_view_module": "@jupyter-widgets/base", "_view_module_version": "1.2.0", "_view_name": "StyleView", "bar_color": null, "description_width": "" } }, "709ca2bd0b3d4911be981b4ad517785b": { "model_module": "@jupyter-widgets/base", "model_name": "LayoutModel", "model_module_version": "1.2.0", "state": { "_model_module": "@jupyter-widgets/base", "_model_module_version": "1.2.0", "_model_name": "LayoutModel", "_view_count": null, "_view_module": "@jupyter-widgets/base", "_view_module_version": "1.2.0", "_view_name": "LayoutView", "align_content": null, "align_items": null, "align_self": null, "border": null, "bottom": null, "display": null, "flex": null, "flex_flow": null, "grid_area": null, "grid_auto_columns": null, "grid_auto_flow": null, "grid_auto_rows": null, "grid_column": null, "grid_gap": null, "grid_row": null, "grid_template_areas": null, "grid_template_columns": null, "grid_template_rows": null, "height": null, "justify_content": null, "justify_items": null, "left": null, "margin": null, "max_height": null, "max_width": null, "min_height": null, "min_width": null, "object_fit": null, "object_position": null, "order": null, "overflow": null, "overflow_x": null, "overflow_y": null, "padding": null, "right": null, "top": null, "visibility": null, "width": null } }, "087013a6997e4afd81160abbcf385369": { "model_module": "@jupyter-widgets/controls", "model_name": "DescriptionStyleModel", "model_module_version": "1.5.0", "state": { "_model_module": "@jupyter-widgets/controls", "_model_module_version": "1.5.0", "_model_name": "DescriptionStyleModel", "_view_count": null, "_view_module": "@jupyter-widgets/base", "_view_module_version": "1.2.0", "_view_name": "StyleView", "description_width": "" } }, "a94ae6150e384816af08c42c3a61ec46": { "model_module": "@jupyter-widgets/controls", "model_name": "HBoxModel", "model_module_version": "1.5.0", "state": { "_dom_classes": [], "_model_module": "@jupyter-widgets/controls", "_model_module_version": "1.5.0", "_model_name": "HBoxModel", "_view_count": null, "_view_module": "@jupyter-widgets/controls", "_view_module_version": "1.5.0", "_view_name": "HBoxView", "box_style": "", "children": [ "IPY_MODEL_286d18ebe28a437eb0c161fb897b376a", "IPY_MODEL_a50ee145fa744126a3f6b5969cf01f81", "IPY_MODEL_a233564db3b14bcc914696baeacb47e4" ], "layout": "IPY_MODEL_875dbd0522674d039839645366e78bec" } }, "286d18ebe28a437eb0c161fb897b376a": { "model_module": "@jupyter-widgets/controls", "model_name": "HTMLModel", "model_module_version": "1.5.0", "state": { "_dom_classes": [], "_model_module": "@jupyter-widgets/controls", "_model_module_version": "1.5.0", "_model_name": "HTMLModel", "_view_count": null, "_view_module": "@jupyter-widgets/controls", "_view_module_version": "1.5.0", "_view_name": "HTMLView", "description": "", "description_tooltip": null, "layout": "IPY_MODEL_d604777f01c14bfab72dc2d47aa8182f", "placeholder": "​", "style": "IPY_MODEL_426fab4da01c4de0a152746587e2c72e", "value": "Unsloth: Tokenizing ["text"] (num_proc=5): 100%" } }, "a50ee145fa744126a3f6b5969cf01f81": { "model_module": "@jupyter-widgets/controls", "model_name": "FloatProgressModel", "model_module_version": "1.5.0", "state": { "_dom_classes": [], "_model_module": "@jupyter-widgets/controls", "_model_module_version": "1.5.0", "_model_name": "FloatProgressModel", "_view_count": null, "_view_module": "@jupyter-widgets/controls", "_view_module_version": "1.5.0", "_view_name": "ProgressView", "bar_style": "success", "description": "", "description_tooltip": null, "layout": "IPY_MODEL_f77af22e2abf460d8544450d2b8d4c7d", "max": 247, "min": 0, "orientation": "horizontal", "style": "IPY_MODEL_286fa7954d514840801c8bc00a5cd6e9", "value": 247 } }, "a233564db3b14bcc914696baeacb47e4": { "model_module": "@jupyter-widgets/controls", "model_name": "HTMLModel", "model_module_version": "1.5.0", "state": { "_dom_classes": [], "_model_module": "@jupyter-widgets/controls", "_model_module_version": "1.5.0", "_model_name": "HTMLModel", "_view_count": null, "_view_module": "@jupyter-widgets/controls", "_view_module_version": "1.5.0", "_view_name": "HTMLView", "description": "", "description_tooltip": null, "layout": "IPY_MODEL_bfb6e9c5f1b24d9da32d1e8d26ebaaf1", "placeholder": "​", "style": "IPY_MODEL_3809a44e969d4b6e9f42411775b9bffc", "value": " 247/247 [00:01<00:00, 129.01 examples/s]" } }, "875dbd0522674d039839645366e78bec": { "model_module": "@jupyter-widgets/base", "model_name": "LayoutModel", "model_module_version": "1.2.0", "state": { "_model_module": "@jupyter-widgets/base", "_model_module_version": "1.2.0", "_model_name": "LayoutModel", "_view_count": null, "_view_module": "@jupyter-widgets/base", "_view_module_version": "1.2.0", "_view_name": "LayoutView", "align_content": null, "align_items": null, "align_self": null, "border": null, "bottom": null, "display": null, "flex": null, "flex_flow": null, "grid_area": null, "grid_auto_columns": null, "grid_auto_flow": null, "grid_auto_rows": null, "grid_column": null, "grid_gap": null, "grid_row": null, "grid_template_areas": null, "grid_template_columns": null, "grid_template_rows": null, "height": null, "justify_content": null, "justify_items": null, "left": null, "margin": null, "max_height": null, "max_width": null, "min_height": null, "min_width": null, "object_fit": null, "object_position": null, "order": null, "overflow": null, "overflow_x": null, "overflow_y": null, "padding": null, "right": null, "top": null, "visibility": null, "width": null } }, "d604777f01c14bfab72dc2d47aa8182f": { "model_module": "@jupyter-widgets/base", "model_name": "LayoutModel", "model_module_version": "1.2.0", "state": { "_model_module": "@jupyter-widgets/base", "_model_module_version": "1.2.0", "_model_name": "LayoutModel", "_view_count": null, "_view_module": "@jupyter-widgets/base", "_view_module_version": "1.2.0", "_view_name": "LayoutView", "align_content": null, "align_items": null, "align_self": null, "border": null, "bottom": null, "display": null, "flex": null, "flex_flow": null, "grid_area": null, "grid_auto_columns": null, "grid_auto_flow": null, "grid_auto_rows": null, "grid_column": null, "grid_gap": null, "grid_row": null, "grid_template_areas": null, "grid_template_columns": null, "grid_template_rows": null, "height": null, "justify_content": null, "justify_items": null, "left": null, "margin": null, "max_height": null, "max_width": null, "min_height": null, "min_width": null, "object_fit": null, "object_position": null, "order": null, "overflow": null, "overflow_x": null, "overflow_y": null, "padding": null, "right": null, "top": null, "visibility": null, "width": null } }, "426fab4da01c4de0a152746587e2c72e": { "model_module": "@jupyter-widgets/controls", "model_name": "DescriptionStyleModel", "model_module_version": "1.5.0", "state": { "_model_module": "@jupyter-widgets/controls", "_model_module_version": "1.5.0", "_model_name": "DescriptionStyleModel", "_view_count": null, "_view_module": "@jupyter-widgets/base", "_view_module_version": "1.2.0", "_view_name": "StyleView", "description_width": "" } }, "f77af22e2abf460d8544450d2b8d4c7d": { "model_module": "@jupyter-widgets/base", "model_name": "LayoutModel", "model_module_version": "1.2.0", "state": { "_model_module": "@jupyter-widgets/base", "_model_module_version": "1.2.0", "_model_name": "LayoutModel", "_view_count": null, "_view_module": "@jupyter-widgets/base", "_view_module_version": "1.2.0", "_view_name": "LayoutView", "align_content": null, "align_items": null, "align_self": null, "border": null, "bottom": null, "display": null, "flex": null, "flex_flow": null, "grid_area": null, "grid_auto_columns": null, "grid_auto_flow": null, "grid_auto_rows": null, "grid_column": null, "grid_gap": null, "grid_row": null, "grid_template_areas": null, "grid_template_columns": null, "grid_template_rows": null, "height": null, "justify_content": null, "justify_items": null, "left": null, "margin": null, "max_height": null, "max_width": null, "min_height": null, "min_width": null, "object_fit": null, "object_position": null, "order": null, "overflow": null, "overflow_x": null, "overflow_y": null, "padding": null, "right": null, "top": null, "visibility": null, "width": null } }, "286fa7954d514840801c8bc00a5cd6e9": { "model_module": "@jupyter-widgets/controls", "model_name": "ProgressStyleModel", "model_module_version": "1.5.0", "state": { "_model_module": "@jupyter-widgets/controls", "_model_module_version": "1.5.0", "_model_name": "ProgressStyleModel", "_view_count": null, "_view_module": "@jupyter-widgets/base", "_view_module_version": "1.2.0", "_view_name": "StyleView", "bar_color": null, "description_width": "" } }, "bfb6e9c5f1b24d9da32d1e8d26ebaaf1": { "model_module": "@jupyter-widgets/base", "model_name": "LayoutModel", "model_module_version": "1.2.0", "state": { "_model_module": "@jupyter-widgets/base", "_model_module_version": "1.2.0", "_model_name": "LayoutModel", "_view_count": null, "_view_module": "@jupyter-widgets/base", "_view_module_version": "1.2.0", "_view_name": "LayoutView", "align_content": null, "align_items": null, "align_self": null, "border": null, "bottom": null, "display": null, "flex": null, "flex_flow": null, "grid_area": null, "grid_auto_columns": null, "grid_auto_flow": null, "grid_auto_rows": null, "grid_column": null, "grid_gap": null, "grid_row": null, "grid_template_areas": null, "grid_template_columns": null, "grid_template_rows": null, "height": null, "justify_content": null, "justify_items": null, "left": null, "margin": null, "max_height": null, "max_width": null, "min_height": null, "min_width": null, "object_fit": null, "object_position": null, "order": null, "overflow": null, "overflow_x": null, "overflow_y": null, "padding": null, "right": null, "top": null, "visibility": null, "width": null } }, "3809a44e969d4b6e9f42411775b9bffc": { "model_module": "@jupyter-widgets/controls", "model_name": "DescriptionStyleModel", "model_module_version": "1.5.0", "state": { "_model_module": "@jupyter-widgets/controls", "_model_module_version": "1.5.0", "_model_name": "DescriptionStyleModel", "_view_count": null, "_view_module": "@jupyter-widgets/base", "_view_module_version": "1.2.0", "_view_name": "StyleView", "description_width": "" } } } } }, "cells": [ { "cell_type": "markdown", "metadata": { "id": "ORw3MSfvA5Qc" }, "source": [ "# Fine-Tune Phi-3 Mini for SysAdmin/DevOps\n", "\n", "This notebook fine-tunes **Phi-3 Mini (3.8B)** using **QLoRA via Unsloth** on your custom sysadmin training data.\n", "\n", "**Requirements:**\n", "- Google Colab with **T4 GPU** (free tier works)\n", "- Training data at `Google Drive > Train > training_data.jsonl`\n", "\n", "**Steps:**\n", "1. Install dependencies\n", "2. Mount Google Drive\n", "3. Load Phi-3 Mini (4-bit quantized)\n", "4. Apply LoRA adapters\n", "5. Load and format training data\n", "6. Train the model\n", "7. Test the fine-tuned model\n", "8. Export to GGUF for Ollama\n", "9. Save to Google Drive for download" ] }, { "cell_type": "markdown", "metadata": { "id": "r-KQ3SYIA5Qm" }, "source": [ "## Step 1: Install Dependencies\n", "This takes 2-3 minutes. Run once per session." ] }, { "cell_type": "code", "execution_count": null, "metadata": { "id": "NEyKiVhIA5Qq" }, "outputs": [], "source": [ "%%capture\n", "!pip install unsloth\n", "!pip install --no-deps trl peft accelerate bitsandbytes xformers\n", "print(\"Installation complete!\")" ] }, { "cell_type": "markdown", "metadata": { "id": "qezGI0PuA5Qu" }, "source": [ "## Step 2: Mount Google Drive\n", "Click the authorization link when prompted." ] }, { "cell_type": "code", "execution_count": null, "metadata": { "colab": { "base_uri": "https://localhost:8080/" }, "id": "ITh6Njc6A5Qw", "executionInfo": { "status": "ok", "timestamp": 1771506532232, "user_tz": -330, "elapsed": 4611, "user": { "displayName": "Lalatendu Swain", "userId": "11195427416677300178" } }, "outputId": "2fea4134-5da0-4cf1-c88a-540d6f1a2476" }, "outputs": [], "source": [ "from google.colab import drive\n", "drive.mount('/content/drive')\n", "\n", "import os\n", "data_file = '/content/drive/MyDrive/Train/training_data.jsonl'\n", "assert os.path.exists(data_file), f\"Training data not found at {data_file}\"\n", "\n", "# Count examples\n", "with open(data_file) as f:\n", " count = sum(1 for _ in f)\n", "print(f\"Training data found: {count} examples\")" ] }, { "cell_type": "markdown", "metadata": { "id": "CzeobljdA5Qy" }, "source": [ "## Step 3: Check GPU\n", "Verify you have a T4 GPU allocated." ] }, { "cell_type": "code", "execution_count": null, "metadata": { "colab": { "base_uri": "https://localhost:8080/" }, "id": "duCvgPWNA5Q3", "executionInfo": { "status": "ok", "timestamp": 1771506532264, "user_tz": -330, "elapsed": 25, "user": { "displayName": "Lalatendu Swain", "userId": "11195427416677300178" } }, "outputId": "1b24321c-d66e-4eef-ce30-460cfdb14582" }, "outputs": [], "source": [ "import torch\n", "print(f\"CUDA available: {torch.cuda.is_available()}\")\n", "if torch.cuda.is_available():\n", " print(f\"GPU: {torch.cuda.get_device_name(0)}\")\n", " props = torch.cuda.get_device_properties(0)\n", " vram = getattr(props, 'total_memory', None) or getattr(props, 'total_mem', 0)\n", " print(f\"VRAM: {vram / 1024**3:.1f} GB\")\n", "else:\n", " print(\"ERROR: No GPU found!\")\n", " print(\"Go to: Runtime > Change runtime type > T4 GPU\")" ] }, { "cell_type": "markdown", "metadata": { "id": "GkwPcZ7eA5Q_" }, "source": [ "## Step 4: Load Phi-3 Mini (4-bit Quantized)\n", "Downloads the model (~2 GB). Takes 2-3 minutes on first run." ] }, { "cell_type": "code", "execution_count": null, "metadata": { "colab": { "base_uri": "https://localhost:8080/" }, "id": "P4ytGOjYA5RC", "executionInfo": { "status": "ok", "timestamp": 1771506567457, "user_tz": -330, "elapsed": 35191, "user": { "displayName": "Lalatendu Swain", "userId": "11195427416677300178" } }, "outputId": "4580194b-df25-4ec5-8768-739ab8db26ab" }, "outputs": [], "source": [ "from unsloth import FastLanguageModel\n", "\n", "max_seq_length = 2048\n", "\n", "model, tokenizer = FastLanguageModel.from_pretrained(\n", " model_name = \"unsloth/Phi-3-mini-4k-instruct-bnb-4bit\",\n", " max_seq_length = max_seq_length,\n", " dtype = None, # Auto-detect (float16 on T4)\n", " load_in_4bit = True, # QLoRA 4-bit quantization\n", ")\n", "\n", "print(f\"Model loaded successfully!\")\n", "print(f\"Model type: {model.config.model_type}\")\n", "print(f\"Parameters: {model.num_parameters():,}\")" ] }, { "cell_type": "markdown", "metadata": { "id": "ZHOQfB5wA5RH" }, "source": [ "## Step 5: Apply LoRA Adapters\n", "Adds trainable adapter layers (~1-5% of parameters). The base model stays frozen." ] }, { "cell_type": "code", "execution_count": null, "metadata": { "colab": { "base_uri": "https://localhost:8080/" }, "id": "O_jONNdVA5RJ", "executionInfo": { "status": "ok", "timestamp": 1771506585884, "user_tz": -330, "elapsed": 18432, "user": { "displayName": "Lalatendu Swain", "userId": "11195427416677300178" } }, "outputId": "53add20b-a630-4098-bd62-4fac9c3f02c3" }, "outputs": [], "source": [ "model = FastLanguageModel.get_peft_model(\n", " model,\n", " r = 64, # LoRA rank (higher = more capacity, more memory)\n", " target_modules = [\n", " \"q_proj\", \"k_proj\", \"v_proj\", \"o_proj\",\n", " \"gate_proj\", \"up_proj\", \"down_proj\",\n", " ],\n", " lora_alpha = 128, # Scaling factor (typically 2x rank)\n", " lora_dropout = 0, # 0 is recommended by Unsloth\n", " bias = \"none\",\n", " use_gradient_checkpointing = \"unsloth\", # Saves ~30% memory\n", " random_state = 3407,\n", ")\n", "\n", "# Count trainable parameters\n", "trainable = sum(p.numel() for p in model.parameters() if p.requires_grad)\n", "total = sum(p.numel() for p in model.parameters())\n", "print(f\"Trainable parameters: {trainable:,} ({100*trainable/total:.2f}% of {total:,})\")" ] }, { "cell_type": "markdown", "metadata": { "id": "OfJvNXp_A5RL" }, "source": [ "## Step 6: Load and Format Training Data\n", "Loads your JSONL file and applies the Phi-3 chat template." ] }, { "cell_type": "code", "execution_count": null, "metadata": { "colab": { "base_uri": "https://localhost:8080/", "height": 153, "referenced_widgets": [ "889a41c65d55459f9246f02f503ebbf0", "fa68cdb4201a465d97743a0f2f11cc1d", "a34d0134e905481eb98161ab8b4d5220", "508acab63d0b404bacef7c521e304331", "3dc910c9a2814ef6863f3638692b6d7a", "86feaf9bb378464688edfafff26c6461", "b94f06f4d85941f18a81d19f1765a813", "a44a1863a7d74884a791a510bafde50c", "be843cdc969d468eade5b17f31c9853b", "360b89d6ce904eff9a2ef15ce0834d05", "dadcd84da528485cb19808ce43c6f3b5" ] }, "id": "Rh_fMdXKA5RN", "executionInfo": { "status": "ok", "timestamp": 1771506586740, "user_tz": -330, "elapsed": 859, "user": { "displayName": "Lalatendu Swain", "userId": "11195427416677300178" } }, "outputId": "a9d68060-8f1e-4e12-a7d4-09118b2d54bd" }, "outputs": [], "source": [ "from datasets import load_dataset\n", "from unsloth.chat_templates import get_chat_template\n", "\n", "# Set up Phi-3 chat template\n", "tokenizer = get_chat_template(\n", " tokenizer,\n", " chat_template = \"phi-3\",\n", ")\n", "\n", "# Load dataset\n", "dataset = load_dataset(\n", " \"json\",\n", " data_files = data_file,\n", " split = \"train\",\n", ")\n", "\n", "print(f\"Dataset loaded: {len(dataset)} examples\")\n", "print(f\"Columns: {dataset.column_names}\")\n", "print(f\"\\nFirst example preview:\")\n", "print(f\" User: {dataset[0]['messages'][-2]['content'][:80]}...\")\n", "print(f\" Assistant: {dataset[0]['messages'][-1]['content'][:80]}...\")" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "colab": { "base_uri": "https://localhost:8080/", "height": 208, "referenced_widgets": [ "8a0bd3ae71614353bf304f0c6ba0129b", "c6fbdd95446c460b95592cc07cde686a", "5ff168b48f4b412087e1f766bb87956a", "dadf2ccd980f470fab187b472edb8b8c", "55ead45c0cff480b908b417ab80555e5", "6a08100aae0c405ca468db9687e41077", "e4032377ff5f46809fec908700763253", "89b7379dc1964cbc960cc1587258fc7b", "b0ebdcd1e69c41929808b9acaadf9297", "709ca2bd0b3d4911be981b4ad517785b", "087013a6997e4afd81160abbcf385369" ] }, "id": "p7fCaRK_A5RP", "executionInfo": { "status": "ok", "timestamp": 1771506586883, "user_tz": -330, "elapsed": 97, "user": { "displayName": "Lalatendu Swain", "userId": "11195427416677300178" } }, "outputId": "5b94deac-2ff7-4fe7-d66a-4cdb8f676c32" }, "outputs": [], "source": [ "# Apply chat template to format messages\n", "def formatting_func(examples):\n", " convos = examples[\"messages\"]\n", " texts = [\n", " tokenizer.apply_chat_template(\n", " convo, tokenize=False, add_generation_prompt=False\n", " )\n", " for convo in convos\n", " ]\n", " return {\"text\": texts}\n", "\n", "dataset = dataset.map(formatting_func, batched=True)\n", "\n", "# Preview formatted output\n", "print(\"Formatted example (first 300 chars):\")\n", "print(dataset[0][\"text\"][:300])\n", "print(\"...\")" ] }, { "cell_type": "markdown", "metadata": { "id": "PvQLQtF7A5RR" }, "source": [ "## Step 7: Configure Training\n", "\n", "**Key settings you can adjust:**\n", "- `num_train_epochs`: More epochs = better learning but risk of overfitting (3 is a good default)\n", "- `per_device_train_batch_size`: Reduce to 1 if you get OOM errors\n", "- `learning_rate`: 2e-4 works well for most cases" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "colab": { "base_uri": "https://localhost:8080/", "height": 118, "referenced_widgets": [ "a94ae6150e384816af08c42c3a61ec46", "286d18ebe28a437eb0c161fb897b376a", "a50ee145fa744126a3f6b5969cf01f81", "a233564db3b14bcc914696baeacb47e4", "875dbd0522674d039839645366e78bec", "d604777f01c14bfab72dc2d47aa8182f", "426fab4da01c4de0a152746587e2c72e", "f77af22e2abf460d8544450d2b8d4c7d", "286fa7954d514840801c8bc00a5cd6e9", "bfb6e9c5f1b24d9da32d1e8d26ebaaf1", "3809a44e969d4b6e9f42411775b9bffc" ] }, "id": "a3mwh_nBA5RS", "executionInfo": { "status": "ok", "timestamp": 1771506589145, "user_tz": -330, "elapsed": 2260, "user": { "displayName": "Lalatendu Swain", "userId": "11195427416677300178" } }, "outputId": "2497fa20-a2d5-48a7-ea35-f273bfbf717d" }, "outputs": [], "source": [ "from trl import SFTTrainer\n", "from transformers import TrainingArguments\n", "\n", "trainer = SFTTrainer(\n", " model = model,\n", " tokenizer = tokenizer,\n", " train_dataset = dataset,\n", " dataset_text_field = \"text\",\n", " max_seq_length = max_seq_length,\n", " dataset_num_proc = 2,\n", " packing = False, # True can speed up training for short examples\n", " args = TrainingArguments(\n", " # --- Training ---\n", " num_train_epochs = 5, # 5 epochs for better memorization of facts\n", " per_device_train_batch_size = 2, # Reduce to 1 if OOM\n", " gradient_accumulation_steps = 4, # Effective batch size = 2 * 4 = 8\n", " warmup_steps = 10,\n", " learning_rate = 2e-4,\n", " lr_scheduler_type = \"linear\",\n", "\n", " # --- Precision ---\n", " fp16 = not torch.cuda.is_bf16_supported(),\n", " bf16 = torch.cuda.is_bf16_supported(),\n", "\n", " # --- Optimizer ---\n", " optim = \"adamw_8bit\",\n", " weight_decay = 0.01,\n", "\n", " # --- Logging ---\n", " logging_steps = 10,\n", " output_dir = \"outputs\",\n", " save_strategy = \"epoch\",\n", " seed = 3407,\n", " ),\n", ")\n", "\n", "print(\"Trainer configured!\")\n", "print(f\"Total training steps: {trainer.args.max_steps if trainer.args.max_steps > 0 else 'auto (based on epochs)'}\")\n", "print(f\"Epochs: {trainer.args.num_train_epochs}\")\n", "print(f\"Effective batch size: {trainer.args.per_device_train_batch_size * trainer.args.gradient_accumulation_steps}\")" ] }, { "cell_type": "markdown", "metadata": { "id": "idteaHbWA5RV" }, "source": [ "## Step 8: Train!\n", "\n", "This is the main training step. With 200 examples and 3 epochs on a T4 GPU, expect **10-30 minutes**.\n", "\n", "Watch the **training loss** - it should decrease over time. A final loss around **0.5-1.5** is normal." ] }, { "cell_type": "code", "execution_count": null, "metadata": { "colab": { "base_uri": "https://localhost:8080/", "height": 1000 }, "id": "WaI4rWeZA5RW", "executionInfo": { "status": "ok", "timestamp": 1771507359352, "user_tz": -330, "elapsed": 770188, "user": { "displayName": "Lalatendu Swain", "userId": "11195427416677300178" } }, "outputId": "6fa9c172-bc1c-49ce-b1b5-4dc7da65d6b5" }, "outputs": [], "source": [ "import time\n", "\n", "print(\"Starting training...\")\n", "start_time = time.time()\n", "\n", "trainer_stats = trainer.train()\n", "\n", "elapsed = time.time() - start_time\n", "print(f\"\\n{'='*50}\")\n", "print(f\"Training complete!\")\n", "print(f\"Duration: {elapsed/60:.1f} minutes\")\n", "print(f\"Final loss: {trainer_stats.training_loss:.4f}\")\n", "print(f\"{'='*50}\")" ] }, { "cell_type": "markdown", "metadata": { "id": "ZVumvF67A5RY" }, "source": [ "## Step 9: Test the Fine-Tuned Model\n", "\n", "Run a few test prompts to see how the model performs. Try questions from your training data AND questions it hasn't seen." ] }, { "cell_type": "code", "execution_count": null, "metadata": { "colab": { "base_uri": "https://localhost:8080/" }, "id": "TsUMyYqkA5RZ", "executionInfo": { "status": "ok", "timestamp": 1771507359449, "user_tz": -330, "elapsed": 71, "user": { "displayName": "Lalatendu Swain", "userId": "11195427416677300178" } }, "outputId": "a10683f0-6c46-4b02-d1ba-793a58687cb0" }, "outputs": [], "source": [ "# Switch to inference mode\n", "FastLanguageModel.for_inference(model)\n", "\n", "def ask(question, max_tokens=512):\n", " \"\"\"Ask the fine-tuned model a question.\"\"\"\n", " messages = [\n", " {\"role\": \"system\", \"content\": \"You are phi3-sysadmin, a fine-tuned AI assistant created by Lalatendu Keshari Swain. Provide clear, practical answers for server management and troubleshooting.\"},\n", " {\"role\": \"user\", \"content\": question},\n", " ]\n", " inputs = tokenizer.apply_chat_template(\n", " messages,\n", " tokenize = True,\n", " add_generation_prompt = True,\n", " return_tensors = \"pt\",\n", " ).to(\"cuda\")\n", "\n", " outputs = model.generate(\n", " input_ids = inputs,\n", " max_new_tokens = max_tokens,\n", " temperature = 0.7,\n", " top_p = 0.9,\n", " do_sample = True,\n", " )\n", "\n", " response = tokenizer.decode(outputs[0], skip_special_tokens=True)\n", " # Extract only the assistant's response\n", " if \"<|assistant|>\" in response:\n", " response = response.split(\"<|assistant|>\")[-1].strip()\n", " return response\n", "\n", "print(\"Model ready for testing!\")" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "colab": { "base_uri": "https://localhost:8080/" }, "id": "v3HqOB9uA5Rb", "executionInfo": { "status": "ok", "timestamp": 1771507373101, "user_tz": -330, "elapsed": 13650, "user": { "displayName": "Lalatendu Swain", "userId": "11195427416677300178" } }, "outputId": "d2e8c2ff-bca4-4e4d-9c46-79c9180ebe7a" }, "outputs": [], "source": [ "# Test 1: Question from training data (should answer well)\n", "print(\"=\" * 60)\n", "print(\"TEST 1: How do I check disk space usage?\")\n", "print(\"=\" * 60)\n", "print(ask(\"The server is running out of disk space. How do I find what's consuming the most space?\"))" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "colab": { "base_uri": "https://localhost:8080/" }, "id": "wQmbzRlFA5Rc", "executionInfo": { "status": "ok", "timestamp": 1771507391897, "user_tz": -330, "elapsed": 18801, "user": { "displayName": "Lalatendu Swain", "userId": "11195427416677300178" } }, "outputId": "59335ac3-10b0-47a1-958b-85bf8a9d5820" }, "outputs": [], "source": [ "# Test 2: Related question NOT in training data (tests generalization)\n", "print(\"=\" * 60)\n", "print(\"TEST 2: Unseen question - container troubleshooting\")\n", "print(\"=\" * 60)\n", "print(ask(\"A Docker container keeps crashing with exit code 137. What does this mean and how do I fix it?\"))" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "colab": { "base_uri": "https://localhost:8080/" }, "id": "0Xx-aVW6A5Re", "executionInfo": { "status": "ok", "timestamp": 1771507399148, "user_tz": -330, "elapsed": 7263, "user": { "displayName": "Lalatendu Swain", "userId": "11195427416677300178" } }, "outputId": "8f217c8a-0989-4c44-c11f-ece316625cfe" }, "outputs": [], "source": [ "# Test 3: Who trained you?\n", "print(\"=\" * 60)\n", "print(\"TEST 3: Who trained you?\")\n", "print(\"=\" * 60)\n", "print(ask(\"Who trained you? Who created this model?\"))" ] }, { "cell_type": "markdown", "metadata": { "id": "2CS5siR1A5Rf" }, "source": [ "## Step 10: Export to GGUF for Ollama\n", "\n", "This converts the model to GGUF format that Ollama can use.\n", "\n", "**Quantization options:**\n", "- `q4_k_m` - Recommended (good quality, ~2.3 GB)\n", "- `q5_k_m` - Slightly better quality (~2.8 GB)\n", "- `q8_0` - High quality (~4 GB)" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "colab": { "base_uri": "https://localhost:8080/" }, "id": "34mOubL7A5Rh", "outputId": "c370d032-3b6a-42d9-f5a1-74704d119204", "executionInfo": { "status": "ok", "timestamp": 1771508413499, "user_tz": -330, "elapsed": 456776, "user": { "displayName": "Lalatendu Swain", "userId": "11195427416677300178" } } }, "outputs": [], "source": [ "# Export to GGUF - this takes 5-10 minutes\n", "print(\"Exporting to GGUF format (this takes a few minutes)...\")\n", "\n", "model.save_pretrained_gguf(\n", " \"phi3-sysadmin\",\n", " tokenizer,\n", " quantization_method = \"q4_k_m\", # Change to q5_k_m or q8_0 if you want higher quality\n", ")\n", "\n", "print(\"\\nGGUF export complete!\")\n", "\n", "# List exported files\n", "import os\n", "for f in os.listdir(\"phi3-sysadmin\"):\n", " size = os.path.getsize(f\"phi3-sysadmin/{f}\") / 1024 / 1024\n", " print(f\" {f}: {size:.1f} MB\")" ] }, { "cell_type": "markdown", "metadata": { "id": "K_21hlMHA5Ri" }, "source": [ "## Step 11: Create Ollama Modelfile\n", "\n", "This creates the configuration file that Ollama needs to load the model with the correct chat template." ] }, { "cell_type": "code", "execution_count": null, "metadata": { "id": "_fbYP8qgA5Rj", "colab": { "base_uri": "https://localhost:8080/" }, "executionInfo": { "status": "ok", "timestamp": 1771508413541, "user_tz": -330, "elapsed": 28, "user": { "displayName": "Lalatendu Swain", "userId": "11195427416677300178" } }, "outputId": "1dff6397-c8dd-42c9-8ac8-a70e8270bcd8" }, "outputs": [], "source": [ "# Find the GGUF file - check both possible directories\n", "import glob as g\n", "gguf_search = g.glob(\"/content/phi3-sysadmin*/*.gguf\")\n", "gguf_search = [f for f in gguf_search if 'Q4_K_M' in f or 'q4_k_m' in f.lower()]\n", "if not gguf_search:\n", " gguf_search = g.glob(\"/content/phi3-sysadmin*/*.gguf\")\n", "gguf_path = gguf_search[0] if gguf_search else \"/content/phi3-sysadmin/unsloth.Q4_K_M.gguf\"\n", "gguf_file = os.path.basename(gguf_path)\n", "gguf_dir = os.path.dirname(gguf_path)\n", "print(f\"GGUF file: {gguf_file}\")\n", "print(f\"GGUF dir: {gguf_dir}\")\n", "\n", "# Create Modelfile for Ollama\n", "modelfile_content = f'''FROM ./{gguf_file}\n", "\n", "TEMPLATE \"\"\"<|system|>\n", "{{{{ .System }}}}<|end|>\n", "<|user|>\n", "{{{{ .Prompt }}}}<|end|>\n", "<|assistant|>\n", "{{{{ .Response }}}}<|end|>\n", "\"\"\"\n", "\n", "SYSTEM \"\"\"You are phi3-sysadmin, a fine-tuned AI assistant created by Lalatendu Keshari Swain. Provide clear, practical answers for server management and troubleshooting.\"\"\"\n", "\n", "PARAMETER stop <|end|>\n", "PARAMETER stop <|user|>\n", "PARAMETER stop <|assistant|>\n", "PARAMETER stop <|endoftext|>\n", "PARAMETER temperature 0.7\n", "PARAMETER top_p 0.9\n", "'''\n", "\n", "with open(f\"{gguf_dir}/Modelfile\", \"w\") as f:\n", " f.write(modelfile_content)\n", "\n", "print(\"Modelfile created!\")\n", "print(\"\\nContents:\")\n", "print(modelfile_content)" ] }, { "cell_type": "markdown", "metadata": { "id": "tWNRZtZAA5Rl" }, "source": [ "## Step 12: Save to Google Drive\n", "\n", "Copy the GGUF model and Modelfile to Google Drive so you can download them to your local machine." ] }, { "cell_type": "code", "execution_count": null, "metadata": { "id": "JrjckT4iA5Rm", "colab": { "base_uri": "https://localhost:8080/" }, "executionInfo": { "status": "ok", "timestamp": 1771508446527, "user_tz": -330, "elapsed": 32982, "user": { "displayName": "Lalatendu Swain", "userId": "11195427416677300178" } }, "outputId": "c4a8642a-f6ec-4d9e-db26-dd76da7420d9" }, "outputs": [], "source": [ "import shutil\n", "\n", "# Create output directory on Google Drive\n", "drive_output = \"/content/drive/MyDrive/Train/phi3-sysadmin\"\n", "os.makedirs(drive_output, exist_ok=True)\n", "\n", "# Copy GGUF file from wherever it was exported\n", "gguf_src = gguf_path\n", "print(f\"Copying GGUF file to Google Drive...\")\n", "print(f\" Source: {gguf_src}\")\n", "print(f\" Size: {os.path.getsize(gguf_src)/1024/1024:.1f} MB\")\n", "shutil.copy2(gguf_src, f\"{drive_output}/{gguf_file}\")\n", "print(f\" GGUF copied!\")\n", "\n", "# Copy Modelfile\n", "shutil.copy2(f\"{gguf_dir}/Modelfile\", f\"{drive_output}/Modelfile\")\n", "print(f\" Modelfile copied!\")\n", "\n", "print(f\"\\n{'='*50}\")\n", "print(f\"ALL DONE!\")\n", "print(f\"{'='*50}\")\n", "print(f\"\\nFiles saved to Google Drive > Train > phi3-sysadmin/\")\n", "print(f\"\\nContents:\")\n", "for f in os.listdir(drive_output):\n", " size = os.path.getsize(f\"{drive_output}/{f}\") / 1024 / 1024\n", " print(f\" {f}: {size:.1f} MB\")" ] }, { "cell_type": "markdown", "metadata": { "id": "YQNbZWQNA5Rn" }, "source": [ "## Step 13: Deploy to Ollama (Run on your local machine)\n", "\n", "After downloading the files from Google Drive to your local Linux machine, run these commands:\n", "\n", "```bash\n", "# 1. Copy files from Google Drive to local machine\n", "mkdir -p /media/lalatendu/Data/phi3-sysadmin\n", "# Download the phi3-sysadmin folder from Google Drive to this directory\n", "\n", "# 2. Create the Ollama model\n", "cd /media/lalatendu/Data/phi3-sysadmin\n", "OLLAMA_MODELS=/media/lalatendu/Data/ollama/models ollama create phi3-sysadmin -f Modelfile\n", "\n", "# 3. Run your fine-tuned model!\n", "OLLAMA_MODELS=/media/lalatendu/Data/ollama/models ollama run phi3-sysadmin\n", "\n", "# 4. Verify it appears in the model list\n", "OLLAMA_MODELS=/media/lalatendu/Data/ollama/models ollama list\n", "```" ] }, { "cell_type": "markdown", "metadata": { "id": "aKxPGMx_A5Ro" }, "source": [ "---\n", "\n", "## Optional: Save LoRA Adapter Only\n", "\n", "If you want to save the LoRA adapter separately (smaller, can be shared), run the cell below." ] }, { "cell_type": "code", "execution_count": null, "metadata": { "id": "ytne3bjiA5Ro", "colab": { "base_uri": "https://localhost:8080/" }, "executionInfo": { "status": "ok", "timestamp": 1771508452564, "user_tz": -330, "elapsed": 6022, "user": { "displayName": "Lalatendu Swain", "userId": "11195427416677300178" } }, "outputId": "26338e89-9e48-4eb7-a2cb-5b73045e296b" }, "outputs": [], "source": [ "# Save LoRA adapter to Google Drive (optional - much smaller than full GGUF)\n", "adapter_path = \"/content/drive/MyDrive/Train/phi3-sysadmin-lora\"\n", "model.save_pretrained(adapter_path)\n", "tokenizer.save_pretrained(adapter_path)\n", "\n", "adapter_size = sum(\n", " os.path.getsize(os.path.join(adapter_path, f))\n", " for f in os.listdir(adapter_path)\n", " if os.path.isfile(os.path.join(adapter_path, f))\n", ") / 1024 / 1024\n", "\n", "print(f\"LoRA adapter saved to: {adapter_path}\")\n", "print(f\"Adapter size: {adapter_size:.1f} MB\")\n", "print(f\"(Full GGUF is much larger - this is just the trained weights)\")" ] } ] }