diff --git "a/Precompute_Moss_embeddings_for_Kaggle_train.ipynb" "b/Precompute_Moss_embeddings_for_Kaggle_train.ipynb" --- "a/Precompute_Moss_embeddings_for_Kaggle_train.ipynb" +++ "b/Precompute_Moss_embeddings_for_Kaggle_train.ipynb" @@ -7,7 +7,8 @@ "collapsed_sections": [ "2UkdVxcYo9HZ", "jRFJRfzHpK_k" - ] + ], + "gpuType": "T4" }, "kernelspec": { "name": "python3", @@ -15,6 +16,1041 @@ }, "language_info": { "name": "python" + }, + "accelerator": "GPU", + "widgets": { + "application/vnd.jupyter.widget-state+json": { + "version_major": 2, + "version_minor": 0, + "state": { + "9986492285484dd9a02a2d98294df365": { + "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_286ef39792b64285b4e00411f9f164f4", + "IPY_MODEL_f4b605b7fc584304b2f9d678cd19d52d", + "IPY_MODEL_9086634998894587b7426e5f85d4a772" + ], + "layout": "IPY_MODEL_465f1a815c2f4e3abb17f86cea7cfe37" + } + }, + "286ef39792b64285b4e00411f9f164f4": { + "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_bd497e5ca6334ae2ac5bed9e435d1d99", + "placeholder": "​", + "style": "IPY_MODEL_3f62a5e36dc64a90aaaddd10beda2c89", + "value": "Loading weights: 100%" + } + }, + "f4b605b7fc584304b2f9d678cd19d52d": { + "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_872dd12ca33745c0a2df02fcaadd3ed9", + "max": 759, + "min": 0, + "orientation": "horizontal", + "style": "IPY_MODEL_f4763b20721f464d85a982039de5aac7", + "value": 759 + } + }, + "9086634998894587b7426e5f85d4a772": { + "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_617b3cf8d602432e8353c15ff53035fd", + "placeholder": "​", + "style": "IPY_MODEL_700f63f58539460889296089b622a562", + "value": " 759/759 [01:17<00:00, 40.36it/s]" + } + }, + "465f1a815c2f4e3abb17f86cea7cfe37": { + "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 + } + }, + "bd497e5ca6334ae2ac5bed9e435d1d99": { + "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 + } + }, + "3f62a5e36dc64a90aaaddd10beda2c89": { + "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": "" + } + }, + "872dd12ca33745c0a2df02fcaadd3ed9": { + "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 + } + }, + "f4763b20721f464d85a982039de5aac7": { + "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": "" + } + }, + "617b3cf8d602432e8353c15ff53035fd": { + "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 + } + }, + "700f63f58539460889296089b622a562": { + "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": "" + } + }, + "e0ee90dd2732434b85e35b09618552b0": { + "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_016fd9eb87974e77b678b4f416a52bd3", + "IPY_MODEL_060ad3605f57494b902b4046f94031b7", + "IPY_MODEL_dc6426d4a0f64c91806f2c26a4611e7a" + ], + "layout": "IPY_MODEL_9762fe088c17408e9c2178929e77ebf2" + } + }, + "016fd9eb87974e77b678b4f416a52bd3": { + "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_85c2b7e8c5c0403a93cada634c7c8ee7", + "placeholder": "​", + "style": "IPY_MODEL_bfca39e1a1c24569b2aa3b74cdf509b9", + "value": "Text embeddings: 100%" + } + }, + "060ad3605f57494b902b4046f94031b7": { + "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_67b31013c7f54975a8f7738def8e7747", + "max": 7, + "min": 0, + "orientation": "horizontal", + "style": "IPY_MODEL_6ea2595bb10e46e894af0ad28e59b406", + "value": 7 + } + }, + "dc6426d4a0f64c91806f2c26a4611e7a": { + "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_ed0cdfbaba9345bb90803ea096906b9f", + "placeholder": "​", + "style": "IPY_MODEL_d96b27d202474f1c9ab7cea1ec85a35e", + "value": " 7/7 [00:00<00:00, 450.92it/s]" + } + }, + "9762fe088c17408e9c2178929e77ebf2": { + "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 + } + }, + "85c2b7e8c5c0403a93cada634c7c8ee7": { + "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 + } + }, + "bfca39e1a1c24569b2aa3b74cdf509b9": { + "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": "" + } + }, + "67b31013c7f54975a8f7738def8e7747": { + "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 + } + }, + "6ea2595bb10e46e894af0ad28e59b406": { + "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": "" + } + }, + "ed0cdfbaba9345bb90803ea096906b9f": { + "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 + } + }, + "d96b27d202474f1c9ab7cea1ec85a35e": { + "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": "" + } + }, + "2c83386bc54c455192fc4a95308b143c": { + "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_c273f6d7001845d29942546b8b34c1c4", + "IPY_MODEL_5b6ed2707cf84c54a8d9e3629063c1b1", + "IPY_MODEL_9842e9b1164f47f681cb46e35a07e52d" + ], + "layout": "IPY_MODEL_82e8aa0e195e4c0db5213aa386d7c168" + } + }, + "c273f6d7001845d29942546b8b34c1c4": { + "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_55c8761a4eee4819a6844ee3afaed282", + "placeholder": "​", + "style": "IPY_MODEL_622fa086d51744428795b9cf5f2329f9", + "value": "Kromoss VAE encoding: 100%" + } + }, + "5b6ed2707cf84c54a8d9e3629063c1b1": { + "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_ed16bbd1b79546bebd06a89615589eac", + "max": 7, + "min": 0, + "orientation": "horizontal", + "style": "IPY_MODEL_ff65caf1f1b34f9e902ffdfd1a143208", + "value": 7 + } + }, + "9842e9b1164f47f681cb46e35a07e52d": { + "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_950c632ffc8f42c4ba4a5868ffc24932", + "placeholder": "​", + "style": "IPY_MODEL_8fc39ecd7c03438c93e5ae7347800ad3", + "value": " 7/7 [00:16<00:00,  2.12s/it]" + } + }, + "82e8aa0e195e4c0db5213aa386d7c168": { + "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 + } + }, + "55c8761a4eee4819a6844ee3afaed282": { + "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 + } + }, + "622fa086d51744428795b9cf5f2329f9": { + "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": "" + } + }, + "ed16bbd1b79546bebd06a89615589eac": { + "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 + } + }, + "ff65caf1f1b34f9e902ffdfd1a143208": { + "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": "" + } + }, + "950c632ffc8f42c4ba4a5868ffc24932": { + "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 + } + }, + "8fc39ecd7c03438c93e5ae7347800ad3": { + "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": [ @@ -30,288 +1066,1437 @@ { "cell_type": "code", "metadata": { - "id": "1c6f852e" + "id": "1c6f852e", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 498, + "referenced_widgets": [ + "9986492285484dd9a02a2d98294df365", + "286ef39792b64285b4e00411f9f164f4", + "f4b605b7fc584304b2f9d678cd19d52d", + "9086634998894587b7426e5f85d4a772", + "465f1a815c2f4e3abb17f86cea7cfe37", + "bd497e5ca6334ae2ac5bed9e435d1d99", + "3f62a5e36dc64a90aaaddd10beda2c89", + "872dd12ca33745c0a2df02fcaadd3ed9", + "f4763b20721f464d85a982039de5aac7", + "617b3cf8d602432e8353c15ff53035fd", + "700f63f58539460889296089b622a562", + "e0ee90dd2732434b85e35b09618552b0", + "016fd9eb87974e77b678b4f416a52bd3", + "060ad3605f57494b902b4046f94031b7", + "dc6426d4a0f64c91806f2c26a4611e7a", + "9762fe088c17408e9c2178929e77ebf2", + "85c2b7e8c5c0403a93cada634c7c8ee7", + "bfca39e1a1c24569b2aa3b74cdf509b9", + "67b31013c7f54975a8f7738def8e7747", + "6ea2595bb10e46e894af0ad28e59b406", + "ed0cdfbaba9345bb90803ea096906b9f", + "d96b27d202474f1c9ab7cea1ec85a35e" + ] + }, + "outputId": "7f74a695-ae2b-4f72-b73d-f1ac02658a41" }, "source": [ + "\n", "# =============================================================================\n", - "# Kromoss (MOSS-Image) LoRA Training – PART 1: PRECOMPUTE EMBEDDINGS\n", + "# KROMOSS – CELL 1: INSTALLATION + DATASET PREPARATION\n", + "#\n", + "# Output:\n", + "# /content/tetsu_training_data/\n", + "#\n", + "# Dataset format:\n", + "# image.jpg\n", + "# image.txt\n", + "#\n", "# =============================================================================\n", "\n", - "from google.colab import userdata, drive\n", "import os\n", + "import gc\n", + "import sys\n", + "import subprocess\n", + "import warnings\n", + "import shutil\n", + "import zipfile\n", + "import random\n", + "\n", + "warnings.filterwarnings(\"ignore\")\n", + "\n", + "print(\"Installing dependencies...\")\n", + "\n", + "subprocess.run(\n", + " [\n", + " sys.executable, \"-m\", \"pip\", \"install\", \"-q\", \"--upgrade\",\n", + " \"diffusers>=0.38\",\n", + " \"transformers>=5.3\",\n", + " \"accelerate>=1.10\",\n", + " \"bitsandbytes\",\n", + " \"huggingface_hub\",\n", + " \"safetensors\",\n", + " \"Pillow\",\n", + " \"tqdm\"\n", + " ],\n", + " check=True\n", + ")\n", + "\n", + "import torch\n", + "from pathlib import Path\n", + "from google.colab import userdata, drive\n", "from huggingface_hub import login\n", "\n", + "# -------------------------------------------------------------------------\n", + "# AUTHENTICATION\n", + "# -------------------------------------------------------------------------\n", + "\n", "HF_TOKEN = userdata.get(\"HF_TOKEN\")\n", + "\n", + "if not HF_TOKEN:\n", + " raise RuntimeError(\"HF_TOKEN missing from Colab Secrets.\")\n", + "\n", "login(token=HF_TOKEN, add_to_git_credential=False)\n", - "print(\"Logged in with HF_TOKEN\")\n", "\n", - "#@title 2. Mount Drive + unpack dataset\n", + "print(\"Hugging Face authentication successful.\")\n", + "\n", + "# -------------------------------------------------------------------------\n", + "# GOOGLE DRIVE\n", + "# -------------------------------------------------------------------------\n", + "\n", "drive.mount(\"/content/drive\")\n", "\n", - "import zipfile, shutil, gc\n", - "from pathlib import Path\n", + "# -------------------------------------------------------------------------\n", + "# CONFIGURATION\n", + "# -------------------------------------------------------------------------\n", "\n", - "DATA_ZIP = \"/content/drive/MyDrive/tetsu_training_data.zip\"\n", - "DATA_DIR = Path(\"/content/tetsu_training_data\")\n", + "REPO_ID = \"lodestones/Kromoss\"\n", + "\n", + "DATA_ZIP = Path(\n", + " \"/content/drive/MyDrive/sm_merged.zip\"\n", + ")\n", + "\n", + "DATA_DIR = Path(\n", + " \"/content/sm_training_data\"\n", + ")\n", + "\n", + "TEXT_CACHE_DIR = Path(\n", + " \"/content/text_emb_cache\"\n", + ")\n", + "\n", + "DRIVE_DATASET_DIR = Path(\n", + " \"/content/drive/MyDrive/kromoss_precomputed_dataset\"\n", + ")\n", + "\n", + "RESOLUTION = 1024\n", + "MAX_SEQ_LEN = 4096\n", + "\n", + "SEED = 42\n", + "\n", + "random.seed(SEED)\n", + "torch.manual_seed(SEED)\n", + "torch.cuda.manual_seed_all(SEED)\n", + "\n", + "assert torch.cuda.is_available()\n", + "\n", + "print(\"GPU:\", torch.cuda.get_device_name(0))\n", + "print(\"VRAM:\", round(\n", + " torch.cuda.get_device_properties(0).total_memory / 1024**3, 2\n", + "), \"GB\")\n", + "\n", + "# -------------------------------------------------------------------------\n", + "# EXTRACT DATASET\n", + "# -------------------------------------------------------------------------\n", + "\n", + "if not DATA_ZIP.exists():\n", + " raise FileNotFoundError(DATA_ZIP)\n", "\n", "if DATA_DIR.exists():\n", " shutil.rmtree(DATA_DIR)\n", + "\n", "DATA_DIR.mkdir(parents=True, exist_ok=True)\n", "\n", - "print(f\"Extracting {DATA_ZIP} ...\")\n", - "with zipfile.ZipFile(DATA_ZIP, \"r\") as z:\n", - " z.extractall(DATA_DIR)\n", + "print(\"Extracting dataset...\")\n", + "\n", + "with zipfile.ZipFile(DATA_ZIP, \"r\") as archive:\n", + " archive.extractall(DATA_DIR)\n", + "\n", + "# Flatten one top-level directory if present.\n", + "\n", + "contents = list(DATA_DIR.iterdir())\n", + "\n", + "if len(contents) == 1 and contents[0].is_dir():\n", + "\n", + " root = contents[0]\n", "\n", - "# Flatten single top-level folder if present\n", - "subdirs = [d for d in DATA_DIR.iterdir() if d.is_dir()]\n", - "if len(list(DATA_DIR.glob(\"*\"))) == 1 and subdirs:\n", - " for item in subdirs[0].iterdir():\n", + " for item in list(root.iterdir()):\n", " shutil.move(str(item), str(DATA_DIR / item.name))\n", - " subdirs[0].rmdir()\n", "\n", - "print(\"Dataset ready:\", list(DATA_DIR.iterdir())[:8], \"...\")\n", + " root.rmdir()\n", "\n", - "#@title 3. Global Configuration\n", - "import torch\n", - "from transformers import AutoTokenizer, AutoModel, BitsAndBytesConfig\n", + "print(\"Dataset extracted.\")\n", "\n", - "REPO_ID = \"lodestones/Kromoss\"\n", - "RESOLUTION = 1024\n", - "MIXED_PRECISION = \"bf16\"\n", - "SEED = 42\n", - "MAX_SEQ_LEN = 512\n", + "# -------------------------------------------------------------------------\n", + "# COLLECT IMAGE/CAPTION PAIRS\n", + "# -------------------------------------------------------------------------\n", "\n", - "device = torch.device(\"cuda\")\n", - "dtype = torch.bfloat16 if MIXED_PRECISION == \"bf16\" else torch.float16\n", - "torch.manual_seed(SEED)\n", + "IMG_EXTS = {\n", + " \".jpg\", \".jpeg\", \".png\", \".webp\", \".bmp\"\n", + "}\n", "\n", - "#@title 4. Collect image-caption pairs\n", - "IMG_EXTS = {\".jpg\", \".jpeg\", \".png\", \".webp\", \".bmp\"}\n", "pairs = []\n", + "\n", "for img_path in sorted(DATA_DIR.rglob(\"*\")):\n", + "\n", " if img_path.suffix.lower() not in IMG_EXTS:\n", " continue\n", + "\n", " txt_path = img_path.with_suffix(\".txt\")\n", - " if txt_path.exists():\n", - " caption = txt_path.read_text(encoding=\"utf-8\").strip()\n", - " if caption:\n", - " pairs.append((str(img_path), caption))\n", "\n", - "print(f\"Found {len(pairs)} image-text pairs\")\n", - "assert len(pairs) > 0, \"No image + .txt pairs found\"\n", + " if not txt_path.exists():\n", + " continue\n", + "\n", + " caption = txt_path.read_text(\n", + " encoding=\"utf-8\"\n", + " ).strip()\n", + "\n", + " if caption:\n", + " pairs.append((img_path, caption))\n", + "\n", + "print(\"=\" * 70)\n", + "print(\"DATASET SUMMARY\")\n", + "print(\"=\" * 70)\n", + "\n", + "print(\"Images with captions:\", len(pairs))\n", + "\n", + "assert pairs, \"No image-caption pairs found.\"\n", + "\n", + "TEXT_CACHE_DIR.mkdir(parents=True, exist_ok=True)\n", + "DRIVE_DATASET_DIR.mkdir(parents=True, exist_ok=True)\n", + "\n", + "print(\"CELL 1 COMPLETE\")\n", + "\n", + "\n", + "# =============================================================================\n", + "# KROMOSS – CELL 2: PRECOMPUTE TEXT EMBEDDINGS\n", + "#\n", + "# Encoder:\n", + "# lodestones/Kromoss/text_encoder\n", + "#\n", + "# Tokenizer:\n", + "# lodestones/Kromoss/tokenizer\n", + "#\n", + "# Precision:\n", + "# 4-bit NF4, FP16 computation\n", + "#\n", + "# Output:\n", + "# /content/text_emb_cache/\n", + "#\n", + "# =============================================================================\n", + "\n", + "import torch\n", + "import gc\n", + "\n", + "from tqdm.auto import tqdm\n", + "from transformers import (\n", + " AutoTokenizer,\n", + " AutoModel,\n", + " BitsAndBytesConfig\n", + ")\n", + "\n", + "# -------------------------------------------------------------------------\n", + "# CONFIGURATION\n", + "# -------------------------------------------------------------------------\n", + "\n", + "device = torch.device(\"cuda\")\n", + "\n", + "print(\"Loading Kromoss tokenizer...\")\n", "\n", - "#@title 5. Precompute text embeddings with 4-bit quantized TE\n", - "print(\">>> Loading tokenizer ...\")\n", "tokenizer = AutoTokenizer.from_pretrained(\n", - " REPO_ID, subfolder=\"tokenizer\", trust_remote_code=True, token=HF_TOKEN\n", + " REPO_ID,\n", + " subfolder=\"tokenizer\",\n", + " trust_remote_code=True,\n", + " token=HF_TOKEN\n", ")\n", "\n", - "def build_prompt(text: str) -> str:\n", - " return f\"<|im_start|>user\\n{text}<|im_end|>\\n<|im_start|>assistant\\n\\n\"\n", + "# -------------------------------------------------------------------------\n", + "# QUANTIZATION\n", + "# -------------------------------------------------------------------------\n", "\n", - "print(\">>> Loading 4-bit NF4 text encoder (fits in ~6 GB) ...\")\n", "bnb_config = BitsAndBytesConfig(\n", " load_in_4bit=True,\n", " bnb_4bit_quant_type=\"nf4\",\n", - " bnb_4bit_compute_dtype=torch.bfloat16,\n", - " bnb_4bit_use_double_quant=True,\n", + " bnb_4bit_compute_dtype=torch.float16,\n", + " bnb_4bit_use_double_quant=True\n", ")\n", "\n", - "try:\n", - " text_encoder = AutoModel.from_pretrained(\n", - " REPO_ID,\n", - " subfolder=\"text_encoder\",\n", - " quantization_config=bnb_config,\n", - " device_map=\"auto\",\n", - " trust_remote_code=True,\n", - " token=HF_TOKEN,\n", - " )\n", - " print(\"Loaded quantized text_encoder from lodestones/Kromoss\")\n", - "except Exception as e:\n", - " print(f\"Kromoss text_encoder quant failed ({e}), falling back to Qwen/Qwen3.5-9B\")\n", - " text_encoder = AutoModel.from_pretrained(\n", - " \"Qwen/Qwen3.5-9B\",\n", - " quantization_config=bnb_config,\n", - " device_map=\"auto\",\n", - " trust_remote_code=True,\n", - " token=HF_TOKEN,\n", - " )\n", + "print(\"Loading quantized Kromoss text encoder...\")\n", + "\n", + "text_encoder = AutoModel.from_pretrained(\n", + " REPO_ID,\n", + " subfolder=\"text_encoder\",\n", + " quantization_config=bnb_config,\n", + " torch_dtype=torch.float16,\n", + " device_map=\"auto\",\n", + " trust_remote_code=True,\n", + " token=HF_TOKEN\n", + ")\n", "\n", "text_encoder.eval()\n", "text_encoder.requires_grad_(False)\n", "\n", - "EMB_CACHE = Path(\"/content/text_emb_cache\")\n", - "EMB_CACHE.mkdir(parents=True, exist_ok=True)\n", + "print(\"Text encoder loaded.\")\n", + "\n", + "# -------------------------------------------------------------------------\n", + "# ENCODING FUNCTION\n", + "# -------------------------------------------------------------------------\n", "\n", "@torch.no_grad()\n", - "def encode_prompt(prompt: str):\n", - " text = build_prompt(prompt)\n", + "def encode_prompt(prompt):\n", + "\n", + " formatted = tokenizer.apply_chat_template(\n", + " [\n", + " {\n", + " \"role\": \"user\",\n", + " \"content\": prompt\n", + " }\n", + " ],\n", + " tokenize=False,\n", + " add_generation_prompt=True,\n", + " enable_thinking=True\n", + " )\n", + "\n", " tokens = tokenizer(\n", - " text,\n", + " formatted,\n", " return_tensors=\"pt\",\n", - " padding=False,\n", " truncation=True,\n", - " max_length=MAX_SEQ_LEN,\n", - " add_special_tokens=False,\n", + " max_length=MAX_SEQ_LEN\n", " )\n", - " input_ids = tokens.input_ids.to(device)\n", - " attention_mask = tokens.attention_mask.to(device)\n", + "\n", + " tokens = tokens.to(device)\n", "\n", " outputs = text_encoder(\n", - " input_ids=input_ids,\n", - " attention_mask=attention_mask,\n", - " output_hidden_states=False,\n", - " return_dict=True,\n", + " **tokens,\n", + " use_cache=False,\n", + " return_dict=True\n", " )\n", - " return outputs.last_hidden_state.cpu(), attention_mask.cpu()\n", - "\n" - ], - "execution_count": null, - "outputs": [] - }, - { - "cell_type": "code", - "source": [ - "from tqdm.auto import tqdm\n", - "import torch\n", "\n", - "print(\">>> Precomputing text embeddings ...\")\n", - "for idx, (img_path, caption) in enumerate(tqdm(pairs)):\n", - " cache_file = EMB_CACHE / f\"{idx:06d}.pt\"\n", - " if cache_file.exists():\n", + " embedding = outputs.last_hidden_state\n", + "\n", + " attention_mask = tokens.attention_mask\n", + "\n", + " return (\n", + " embedding.detach().to(torch.bfloat16).cpu(),\n", + " attention_mask.detach().bool().cpu()\n", + " )\n", + "\n", + "# -------------------------------------------------------------------------\n", + "# PRECOMPUTE ALL CAPTIONS\n", + "# -------------------------------------------------------------------------\n", + "\n", + "print(\"=\" * 70)\n", + "print(\"PRECOMPUTING TEXT EMBEDDINGS\")\n", + "print(\"=\" * 70)\n", + "\n", + "for index, (img_path, caption) in enumerate(\n", + " tqdm(pairs, desc=\"Text embeddings\")\n", + "):\n", + "\n", + " output_file = TEXT_CACHE_DIR / f\"{index:08d}.pt\"\n", + "\n", + " if output_file.exists():\n", " continue\n", - " emb, mask = encode_prompt(caption)\n", - " torch.save({\"emb\": emb, \"mask\": mask, \"caption\": caption, \"img\": img_path}, cache_file)\n", - "\n", - "# ---------- Fully unload the quantized text encoder ----------\n", - "print(\">>> Unloading text encoder completely ...\")\n", - "if 'text_encoder' in globals():\n", - " del text_encoder\n", - "if 'tokenizer' in globals():\n", - " del tokenizer\n", + "\n", + " embedding, attention_mask = encode_prompt(caption)\n", + "\n", + " torch.save(\n", + " {\n", + " \"img\": str(img_path),\n", + " \"caption\": caption,\n", + " \"emb\": embedding,\n", + " \"mask\": attention_mask\n", + " },\n", + " output_file\n", + " )\n", + "\n", + " del embedding\n", + " del attention_mask\n", + "\n", + " if index % 25 == 0:\n", + " gc.collect()\n", + " torch.cuda.empty_cache()\n", + "\n", + "print(\"=\" * 70)\n", + "print(\"TEXT EMBEDDING PRECOMPUTATION COMPLETE\")\n", + "print(\"Files:\", len(list(TEXT_CACHE_DIR.glob(\"*.pt\"))))\n", + "print(\"=\" * 70)\n", + "\n", + "# -------------------------------------------------------------------------\n", + "# UNLOAD TEXT ENCODER\n", + "# -------------------------------------------------------------------------\n", + "\n", + "del text_encoder\n", + "del tokenizer\n", + "del bnb_config\n", + "\n", "gc.collect()\n", "torch.cuda.empty_cache()\n", "torch.cuda.ipc_collect()\n", - "print(f\"VRAM after TE unload: {torch.cuda.memory_allocated()/1024**3:.2f} GB\")" + "\n", + "print(\n", + " \"VRAM after text encoder unload:\",\n", + " round(torch.cuda.memory_allocated() / 1024**3, 2),\n", + " \"GB\"\n", + ")\n", + "\n" ], - "metadata": { - "id": "HDGJLFrocjqs" - }, - "execution_count": null, - "outputs": [] + "execution_count": 1, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "Installing dependencies...\n", + "Hugging Face authentication successful.\n", + "Drive already mounted at /content/drive; to attempt to forcibly remount, call drive.mount(\"/content/drive\", force_remount=True).\n", + "GPU: Tesla T4\n", + "VRAM: 14.56 GB\n", + "Extracting dataset...\n", + "Dataset extracted.\n", + "======================================================================\n", + "DATASET SUMMARY\n", + "======================================================================\n", + "Images with captions: 7\n", + "CELL 1 COMPLETE\n", + "Loading Kromoss tokenizer...\n" + ] + }, + { + "output_type": "stream", + "name": "stderr", + "text": [ + "[transformers] `torch_dtype` is deprecated! Use `dtype` instead!\n" + ] + }, + { + "output_type": "stream", + "name": "stdout", + "text": [ + "Loading quantized Kromoss text encoder...\n" + ] + }, + { + "output_type": "display_data", + "data": { + "text/plain": [ + "Loading weights: 0%| | 0/759 [00:00 128 channels\n", + "# 2. BatchNorm inverse normalization\n", + "#\n", + "# FINAL OUTPUT:\n", + "# image_latents: [128, 64, 64]\n", + "# encoder_hidden_states: [sequence_length, 4096]\n", + "# encoder_attention_mask: [sequence_length]\n", + "#\n", + "# OUTPUT:\n", + "# /content/drive/MyDrive/kromoss_precomputed_dataset/\n", + "#\n", "# =============================================================================\n", "\n", - "\"\"\"\n", - "[EXPLANATION OF DATASET PREPARATION]\n", - "This cell processes our active dataset by:\n", - "1. Loading the high-fidelity AutoencoderKLFlux2 VAE on CUDA.\n", - "2. Iterating through the images configured during dataset setup.\n", - "3. Downsampling/Center-cropping to 1024x1024 resolution.\n", - "4. Passing the image through the VAE encoder to yield compressed 2D latents.\n", - "5. Coupling these latents with the matching text embeddings cached in the previous step.\n", - "6. Saving the combined state (latents + text embeddings + attention masks) directly to Google Drive\n", - " under '/content/drive/MyDrive/kromoss_precomputed_dataset/' for instantaneous future loading.\n", - "\"\"\"\n", - "\n", "import torch\n", "import gc\n", + "import os\n", + "\n", "from pathlib import Path\n", - "from PIL import Image\n", + "from PIL import Image, ImageOps\n", "from tqdm.auto import tqdm\n", "from torchvision import transforms\n", - "from google.colab import userdata\n", "from diffusers import AutoencoderKLFlux2\n", "\n", - "# Configuration\n", - "REPO_ID = \"lodestones/Kromoss\"\n", - "HF_TOKEN = userdata.get(\"HF_TOKEN\")\n", - "RESOLUTION = 1024\n", - "EMB_CACHE = Path(\"/content/text_emb_cache\")\n", - "\n", - "# Target directory on Google Drive\n", - "DRIVE_DATASET_DIR = Path(\"/content/drive/MyDrive/kromoss_precomputed_dataset\")\n", - "DRIVE_DATASET_DIR.mkdir(parents=True, exist_ok=True)\n", + "# =============================================================================\n", + "# CONFIGURATION\n", + "# =============================================================================\n", "\n", "device = torch.device(\"cuda\")\n", "\n", - "print(\">>> Loading VAE model onto CUDA...\")\n", + "OVERWRITE_EXISTING = True\n", + "\n", + "assert TEXT_CACHE_DIR.exists(), \"Text embedding cache missing.\"\n", + "assert DRIVE_DATASET_DIR.exists(), \"Drive output directory missing.\"\n", + "\n", + "assert len(pairs) > 0, \"No image-caption pairs available.\"\n", + "\n", + "print(\"=\" * 75)\n", + "print(\"KROMOSS VAE PRECOMPUTATION\")\n", + "print(\"=\" * 75)\n", + "\n", + "gc.collect()\n", + "torch.cuda.empty_cache()\n", + "\n", + "# =============================================================================\n", + "# LOAD VAE\n", + "# =============================================================================\n", + "\n", + "print(\"Loading Kromoss VAE in FP32...\")\n", + "\n", "vae = AutoencoderKLFlux2.from_pretrained(\n", " REPO_ID,\n", " subfolder=\"vae\",\n", - " torch_dtype=torch.float32, # Encode in float32 for high fidelity\n", - " token=HF_TOKEN,\n", + " torch_dtype=torch.float32,\n", + " token=HF_TOKEN\n", ").to(device)\n", + "\n", "vae.eval()\n", "vae.requires_grad_(False)\n", "\n", - "# Transformation Pipeline\n", + "assert not vae.training\n", + "assert next(vae.parameters()).dtype == torch.float32\n", + "\n", + "print(\"VAE loaded.\")\n", + "print(\"VAE dtype:\", next(vae.parameters()).dtype)\n", + "\n", + "# =============================================================================\n", + "# BATCH NORMALIZATION STATISTICS\n", + "#\n", + "# Official Kromoss decoder:\n", + "#\n", + "# z = z * sqrt(running_var + eps) + running_mean\n", + "#\n", + "# Encoding performs the inverse:\n", + "#\n", + "# z = (z - running_mean) / sqrt(running_var + eps)\n", + "#\n", + "# Both operations happen on the PACKED 128-channel latent.\n", + "# =============================================================================\n", + "\n", + "assert hasattr(vae, \"bn\"), \"Missing VAE BatchNorm layer.\"\n", + "\n", + "BN_MEAN = vae.bn.running_mean.detach().to(\n", + " device=device,\n", + " dtype=torch.float32\n", + ").view(1, -1, 1, 1)\n", + "\n", + "BN_VAR = vae.bn.running_var.detach().to(\n", + " device=device,\n", + " dtype=torch.float32\n", + ").view(1, -1, 1, 1)\n", + "\n", + "BN_EPS = vae.config.batch_norm_eps\n", + "\n", + "assert BN_MEAN.shape == (1, 128, 1, 1)\n", + "assert BN_VAR.shape == (1, 128, 1, 1)\n", + "\n", + "assert torch.all(torch.isfinite(BN_MEAN))\n", + "assert torch.all(torch.isfinite(BN_VAR))\n", + "assert torch.all(BN_VAR >= 0)\n", + "\n", + "BN_STD = torch.sqrt(BN_VAR + BN_EPS)\n", + "\n", + "assert torch.all(BN_STD > 0)\n", + "\n", + "print(\"BatchNorm verified.\")\n", + "print(\"Channels:\", BN_MEAN.shape[1])\n", + "print(\"Epsilon:\", BN_EPS)\n", + "\n", + "# =============================================================================\n", + "# IMAGE TRANSFORMS\n", + "# =============================================================================\n", + "\n", "image_transforms = transforms.Compose([\n", - " transforms.Resize(RESOLUTION, interpolation=transforms.InterpolationMode.LANCZOS),\n", + "\n", + " transforms.Resize(\n", + " RESOLUTION,\n", + " interpolation=transforms.InterpolationMode.LANCZOS\n", + " ),\n", + "\n", " transforms.CenterCrop(RESOLUTION),\n", + "\n", " transforms.ToTensor(),\n", - " transforms.Normalize([0.5], [0.5]),\n", + "\n", + " transforms.Normalize(\n", + " [0.5, 0.5, 0.5],\n", + " [0.5, 0.5, 0.5]\n", + " )\n", "])\n", "\n", + "# =============================================================================\n", + "# KROMOSS LATENT ENCODING\n", + "# =============================================================================\n", + "\n", "@torch.no_grad()\n", - "def pre_encode_and_save():\n", - " # Retrieve all pre-encoded text embedding cache files\n", - " cached_text_files = sorted(EMB_CACHE.glob(\"*.pt\"))\n", - " print(f\">>> Found {len(cached_text_files)} cached text embeddings. Encoding corresponding images...\")\n", + "def encode_kromoss_latents(pixel_values):\n", "\n", - " for text_file in tqdm(cached_text_files, desc=\"Pre-encoding dataset\"):\n", - " # Load text cached data\n", - " text_data = torch.load(text_file, map_location=\"cpu\", weights_only=False)\n", + " # -------------------------------------------------------------------------\n", + " # 1. RAW VAE ENCODING\n", + " # -------------------------------------------------------------------------\n", "\n", - " # Prepare output destination on Drive\n", - " drive_save_path = DRIVE_DATASET_DIR / text_file.name\n", - " if drive_save_path.exists():\n", - " continue\n", + " posterior = vae.encode(pixel_values).latent_dist\n", "\n", - " # Load corresponding raw image\n", - " img_path = text_data[\"img\"]\n", - " img = Image.open(img_path).convert(\"RGB\")\n", + " z = posterior.sample()\n", "\n", - " # Process image through VAE\n", - " pixel_values = image_transforms(img).unsqueeze(0).to(device, dtype=torch.float32)\n", - " image_latents = vae.encode(pixel_values).latent_dist.sample()\n", + " assert z.ndim == 4\n", + " assert z.shape[1] == 32, (\n", + " f\"Unexpected raw VAE channels: {z.shape}\"\n", + " )\n", + "\n", + " B, C, H, W = z.shape\n", + "\n", + " assert H % 2 == 0\n", + " assert W % 2 == 0\n", + "\n", + " # -------------------------------------------------------------------------\n", + " # 2. SPATIAL-TO-CHANNEL PACKING\n", + " #\n", + " # [B, 32, 128, 128]\n", + " # |\n", + " # v\n", + " # [B, 128, 64, 64]\n", + " #\n", + " # Exact inverse of the official Kromoss decoder unpacking.\n", + " # -------------------------------------------------------------------------\n", + "\n", + " z = (\n", + " z.reshape(\n", + " B,\n", + " C,\n", + " H // 2,\n", + " 2,\n", + " W // 2,\n", + " 2\n", + " )\n", + " .permute(\n", + " 0, 1, 3, 5, 2, 4\n", + " )\n", + " .reshape(\n", + " B,\n", + " C * 4,\n", + " H // 2,\n", + " W // 2\n", + " )\n", + " )\n", + "\n", + " assert z.shape == (\n", + " B, 128, H // 2, W // 2\n", + " ), f\"Incorrect packed latent: {z.shape}\"\n", + "\n", + " # -------------------------------------------------------------------------\n", + " # 3. INVERSE BATCH NORMALIZATION\n", + " # -------------------------------------------------------------------------\n", + "\n", + " z = (z - BN_MEAN) / BN_STD\n", + "\n", + " # -------------------------------------------------------------------------\n", + " # 4. VALIDATION\n", + " # -------------------------------------------------------------------------\n", + "\n", + " assert torch.isfinite(z).all(), (\n", + " \"NaN or Inf detected in latent tensor.\"\n", + " )\n", + "\n", + " return z\n", + "\n", + "# =============================================================================\n", + "# LOAD TEXT CACHE\n", + "# =============================================================================\n", + "\n", + "cached_text_files = sorted(\n", + " TEXT_CACHE_DIR.glob(\"*.pt\")\n", + ")\n", + "\n", + "assert len(cached_text_files) == len(pairs), (\n", + " f\"Cache mismatch: {len(cached_text_files)} embeddings \"\n", + " f\"for {len(pairs)} image-caption pairs.\"\n", + ")\n", + "\n", + "print(\"=\" * 75)\n", + "print(\"DATASET VALIDATION\")\n", + "print(\"=\" * 75)\n", + "\n", + "print(\"Image-caption pairs:\", len(pairs))\n", + "print(\"Text cache files:\", len(cached_text_files))\n", + "print(\"Output:\", DRIVE_DATASET_DIR)\n", + "\n", + "# =============================================================================\n", + "# PROCESS DATASET\n", + "# =============================================================================\n", + "\n", + "successful = 0\n", + "skipped = 0\n", + "failed = []\n", + "\n", + "for text_file in tqdm(\n", + " cached_text_files,\n", + " desc=\"Kromoss VAE encoding\"\n", + "):\n", + "\n", + " output_file = DRIVE_DATASET_DIR / text_file.name\n", + "\n", + " if output_file.exists() and not OVERWRITE_EXISTING:\n", + " skipped += 1\n", + " continue\n", + "\n", + " try:\n", + "\n", + " # ---------------------------------------------------------------------\n", + " # 1. LOAD TEXT EMBEDDINGS\n", + " # ---------------------------------------------------------------------\n", + "\n", + " text_data = torch.load(\n", + " text_file,\n", + " map_location=\"cpu\",\n", + " weights_only=False\n", + " )\n", + "\n", + " img_path = Path(text_data[\"img\"])\n", + " caption = text_data[\"caption\"]\n", + "\n", + " embedding = text_data[\"emb\"].squeeze(0)\n", + "\n", + " attention_mask = (\n", + " text_data[\"mask\"].squeeze(0).bool()\n", + " )\n", + "\n", + " assert embedding.ndim == 2\n", + "\n", + " assert embedding.shape[-1] == 4096, (\n", + " f\"Incorrect text dimension: {embedding.shape}\"\n", + " )\n", + "\n", + " assert embedding.shape[0] == attention_mask.shape[0]\n", + "\n", + " assert torch.isfinite(embedding).all()\n", + "\n", + " assert img_path.exists(), (\n", + " f\"Missing image: {img_path}\"\n", + " )\n", + "\n", + " # ---------------------------------------------------------------------\n", + " # 2. LOAD IMAGE\n", + " # ---------------------------------------------------------------------\n", + "\n", + " with Image.open(img_path) as source:\n", + "\n", + " img = ImageOps.exif_transpose(\n", + " source\n", + " ).convert(\"RGB\")\n", + "\n", + " pixel_values = image_transforms(\n", + " img\n", + " ).unsqueeze(0).to(\n", + " device=device,\n", + " dtype=torch.float32\n", + " )\n", + "\n", + " assert pixel_values.shape == (\n", + " 1, 3, RESOLUTION, RESOLUTION\n", + " )\n", + "\n", + " # ---------------------------------------------------------------------\n", + " # 3. VAE ENCODING\n", + " # ---------------------------------------------------------------------\n", + "\n", + " image_latents = encode_kromoss_latents(\n", + " pixel_values\n", + " )\n", + "\n", + " assert image_latents.shape == (\n", + " 1, 128, 64, 64\n", + " )\n", + "\n", + " # ---------------------------------------------------------------------\n", + " # 4. ASSEMBLE TRAINING SAMPLE\n", + " # ---------------------------------------------------------------------\n", "\n", - " # Unified output state containing both modalities\n", " precomputed_sample = {\n", - " \"image_latents\": image_latents.squeeze(0).to(torch.bfloat16).cpu(), # Save in bf16 to conserve space\n", - " \"encoder_hidden_states\": text_data[\"emb\"].squeeze(0).to(torch.bfloat16).cpu(),\n", - " \"encoder_attention_mask\": text_data[\"mask\"].squeeze(0).cpu(),\n", - " \"caption\": text_data[\"caption\"]\n", + "\n", + " \"image_latents\": (\n", + " image_latents.squeeze(0)\n", + " .to(torch.bfloat16)\n", + " .cpu()\n", + " .contiguous()\n", + " ),\n", + "\n", + " \"encoder_hidden_states\": (\n", + " embedding\n", + " .to(torch.bfloat16)\n", + " .cpu()\n", + " .contiguous()\n", + " ),\n", + "\n", + " \"encoder_attention_mask\": (\n", + " attention_mask\n", + " .cpu()\n", + " .contiguous()\n", + " ),\n", + "\n", + " \"caption\": caption\n", " }\n", "\n", - " # Write directly to Google Drive\n", - " torch.save(precomputed_sample, drive_save_path)\n", + " # ---------------------------------------------------------------------\n", + " # 5. VALIDATE OUTPUT\n", + " # ---------------------------------------------------------------------\n", + "\n", + " assert precomputed_sample[\n", + " \"image_latents\"\n", + " ].shape == (128, 64, 64)\n", + "\n", + " assert precomputed_sample[\n", + " \"encoder_hidden_states\"\n", + " ].shape[-1] == 4096\n", "\n", - "# Execute pre-encoding\n", - "pre_encode_and_save()\n", + " assert precomputed_sample[\n", + " \"encoder_attention_mask\"\n", + " ].shape == (\n", + " precomputed_sample[\n", + " \"encoder_hidden_states\"\n", + " ].shape[0],\n", + " )\n", + "\n", + " assert precomputed_sample[\n", + " \"encoder_attention_mask\"\n", + " ].dtype == torch.bool\n", + "\n", + " assert torch.isfinite(\n", + " precomputed_sample[\"image_latents\"]\n", + " ).all()\n", + "\n", + " assert torch.isfinite(\n", + " precomputed_sample[\"encoder_hidden_states\"]\n", + " ).all()\n", + "\n", + " # ---------------------------------------------------------------------\n", + " # 6. ATOMIC SAVE\n", + " # ---------------------------------------------------------------------\n", + "\n", + " temp_file = output_file.with_suffix(\".tmp\")\n", + "\n", + " torch.save(\n", + " precomputed_sample,\n", + " temp_file\n", + " )\n", + "\n", + " os.replace(\n", + " temp_file,\n", + " output_file\n", + " )\n", + "\n", + " successful += 1\n", + "\n", + " # ---------------------------------------------------------------------\n", + " # 7. CLEANUP\n", + " # ---------------------------------------------------------------------\n", + "\n", + " del text_data\n", + " del precomputed_sample\n", + " del image_latents\n", + " del pixel_values\n", + " del embedding\n", + " del attention_mask\n", + "\n", + " if successful % 20 == 0:\n", + "\n", + " gc.collect()\n", + " torch.cuda.empty_cache()\n", + "\n", + " except Exception as e:\n", + "\n", + " failed.append(\n", + " (text_file.name, repr(e))\n", + " )\n", + "\n", + " print(\n", + " f\"\\nERROR processing {text_file.name}: {e}\"\n", + " )\n", + "\n", + " gc.collect()\n", + " torch.cuda.empty_cache()\n", + "\n", + "# =============================================================================\n", + "# RELEASE VAE\n", + "# =============================================================================\n", + "\n", + "print(\"\\nUnloading VAE...\")\n", "\n", - "# Release VAE and empty GPU memory cache\n", - "print(\">>> Pre-encoding finished. Unloading VAE model...\")\n", "del vae\n", + "del BN_MEAN\n", + "del BN_VAR\n", + "del BN_STD\n", + "\n", "gc.collect()\n", + "\n", "torch.cuda.empty_cache()\n", "torch.cuda.ipc_collect()\n", - "print(f\"VRAM after VAE unload: {torch.cuda.memory_allocated()/1024**3:.2f} GB\")" + "\n", + "# =============================================================================\n", + "# FINAL REPORT\n", + "# =============================================================================\n", + "\n", + "saved_files = sorted(\n", + " DRIVE_DATASET_DIR.glob(\"*.pt\")\n", + ")\n", + "\n", + "print(\"\\n\" + \"=\" * 75)\n", + "print(\"KROMOSS PRECOMPUTATION COMPLETE\")\n", + "print(\"=\" * 75)\n", + "\n", + "print(\"Successfully processed:\", successful)\n", + "print(\"Skipped:\", skipped)\n", + "print(\"Failed:\", len(failed))\n", + "print(\"Total output files:\", len(saved_files))\n", + "\n", + "print(\n", + " \"VRAM remaining:\",\n", + " round(\n", + " torch.cuda.memory_allocated() / 1024**3,\n", + " 2\n", + " ),\n", + " \"GB\"\n", + ")\n", + "\n", + "if failed:\n", + "\n", + " print(\"\\nFailed samples:\")\n", + "\n", + " for name, error in failed:\n", + " print(name, \":\", error)\n", + "\n", + "if not failed and len(saved_files) == len(pairs):\n", + "\n", + " print(\"\\nALL DATASET SAMPLES SUCCESSFULLY ENCODED.\")\n", + "\n", + "else:\n", + "\n", + " print(\"\\nWARNING: Dataset incomplete. Check failed samples.\")\n", + "\n", + "print(\"\\nOutput:\", DRIVE_DATASET_DIR)\n", + "print(\"=\" * 75)\n" ], - "execution_count": null, - "outputs": [] + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/", + "height": 605, + "referenced_widgets": [ + "2c83386bc54c455192fc4a95308b143c", + "c273f6d7001845d29942546b8b34c1c4", + "5b6ed2707cf84c54a8d9e3629063c1b1", + "9842e9b1164f47f681cb46e35a07e52d", + "82e8aa0e195e4c0db5213aa386d7c168", + "55c8761a4eee4819a6844ee3afaed282", + "622fa086d51744428795b9cf5f2329f9", + "ed16bbd1b79546bebd06a89615589eac", + "ff65caf1f1b34f9e902ffdfd1a143208", + "950c632ffc8f42c4ba4a5868ffc24932", + "8fc39ecd7c03438c93e5ae7347800ad3" + ] + }, + "id": "kSqXs5HX7HwV", + "outputId": "b5bc4727-8eaa-47a7-c992-c128b4d80b9e" + }, + "execution_count": 2, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "===========================================================================\n", + "KROMOSS VAE PRECOMPUTATION\n", + "===========================================================================\n", + "Loading Kromoss VAE in FP32...\n" + ] + }, + { + "output_type": "stream", + "name": "stderr", + "text": [ + "The config attributes {'force_upcast': True} were passed to AutoencoderKLFlux2, but are not expected and will be ignored. Please verify your config.json configuration file.\n" + ] + }, + { + "output_type": "stream", + "name": "stdout", + "text": [ + "VAE loaded.\n", + "VAE dtype: torch.float32\n", + "BatchNorm verified.\n", + "Channels: 128\n", + "Epsilon: 0.0001\n", + "===========================================================================\n", + "DATASET VALIDATION\n", + "===========================================================================\n", + "Image-caption pairs: 7\n", + "Text cache files: 7\n", + "Output: /content/drive/MyDrive/kromoss_precomputed_dataset\n" + ] + }, + { + "output_type": "display_data", + "data": { + "text/plain": [ + "Kromoss VAE encoding: 0%| | 0/7 [00:00