{"metadata":{"kernelspec":{"display_name":"Python 3","language":"python","name":"python3"},"language_info":{"codemirror_mode":{"name":"ipython","version":3},"file_extension":".py","mimetype":"text/x-python","name":"python","nbconvert_exporter":"python","pygments_lexer":"ipython3","version":"3.12.13"},"rsna_one_dataset_reproduction":{"artifact_role":"documented inference notebook","diagnostic_outputs":[],"prediction_recipe_changed":false,"reason":"Inference-only replica with direct paths and the stable output-effective prediction path.","runtime_members_removed":5,"source_cells_sha256":"aefc642d72502d69c040a02f7c67f255dcef09083cf326ea36f9368acc6cc5dc","source_file_sha256":"30f1f71b0498b39f0dffd64060d5c8033ed2d424f11ef2476b65d725e90fb08f","source_notebook":"mattiaangeli/bend-the-knee-to-dinov3-the-original","source_script_version_id":342992625,"source_version_number":78},"kaggle":{"accelerator":"nvidiaTeslaT4","dataSources":[{"sourceType":"competition","sourceId":154281},{"sourceType":"datasetVersion","sourceId":19003959},{"sourceType":"datasetVersion","sourceId":19120128},{"sourceType":"datasetVersion","sourceId":19122845},{"sourceType":"datasetVersion","sourceId":19134209},{"sourceType":"datasetVersion","sourceId":19356288},{"sourceType":"modelInstanceVersion","sourceId":4533},{"sourceType":"datasetVersion","sourceId":18956429},{"sourceType":"datasetVersion","sourceId":18673450},{"sourceType":"datasetVersion","sourceId":18716507},{"sourceType":"datasetVersion","sourceId":18229736},{"sourceType":"datasetVersion","sourceId":18842180},{"sourceType":"datasetVersion","sourceId":18839182},{"sourceType":"datasetVersion","sourceId":18879001},{"sourceType":"datasetVersion","sourceId":19395706},{"sourceType":"datasetVersion","sourceId":19395055},{"sourceType":"kernelVersion","sourceId":342671664},{"sourceType":"kernelVersion","sourceId":342849430}],"isInternetEnabled":false,"language":"python","sourceType":"notebook","isGpuEnabled":false},"dinosaurs":{"anchor":"user-reported 0.932 CoAtNet + transformer blend","changes":["previously validated 88-feature transformer/Rad calibration","small CoAtNet tilt only for Medial Meniscus, Lateral Meniscus, Fracture","source attribution retained"],"default_submission":"submission.csv","name":"RSNA Knee | V18 Calibrated CoAtNet"},"papermill":{"default_parameters":{},"duration":157.978665,"end_time":"2026-09-04T03:00:14.732742+00:00","environment_variables":{},"exception":null,"input_path":"__notebook__.ipynb","output_path":"__notebook__.ipynb","parameters":{},"start_time":"2026-09-04T02:57:36.754077+00:00","version":"2.7.0"},"widgets":{"application/vnd.jupyter.widget-state+json":{"state":{"01a8219d17b0404b8147b0c67b89881e":{"model_module":"@jupyter-widgets/base","model_module_version":"2.0.0","model_name":"LayoutModel","state":{"_model_module":"@jupyter-widgets/base","_model_module_version":"2.0.0","_model_name":"LayoutModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"2.0.0","_view_name":"LayoutView","align_content":null,"align_items":null,"align_self":null,"border_bottom":null,"border_left":null,"border_right":null,"border_top":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,"padding":null,"right":null,"top":null,"visibility":null,"width":null}},"02053e27aa9144c49067bcb5f2341819":{"model_module":"@jupyter-widgets/base","model_module_version":"2.0.0","model_name":"LayoutModel","state":{"_model_module":"@jupyter-widgets/base","_model_module_version":"2.0.0","_model_name":"LayoutModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"2.0.0","_view_name":"LayoutView","align_content":null,"align_items":null,"align_self":null,"border_bottom":null,"border_left":null,"border_right":null,"border_top":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,"padding":null,"right":null,"top":null,"visibility":null,"width":null}},"02a0cd884a2143b0bf1b3a7e918fe7f3":{"model_module":"@jupyter-widgets/controls","model_module_version":"2.0.0","model_name":"HTMLModel","state":{"_dom_classes":[],"_model_module":"@jupyter-widgets/controls","_model_module_version":"2.0.0","_model_name":"HTMLModel","_view_count":null,"_view_module":"@jupyter-widgets/controls","_view_module_version":"2.0.0","_view_name":"HTMLView","description":"","description_allow_html":false,"layout":"IPY_MODEL_749c34a01ee84bdaa5b394bac8c0150e","placeholder":"​","style":"IPY_MODEL_78a366edbb964c7fa4d0e3307a7ee090","tabbable":null,"tooltip":null,"value":" 223/223 [00:00&lt;00:00, 1228.10it/s, Materializing param=layernorm.weight]"}},"02a3205153d04217975625763aaa8db3":{"model_module":"@jupyter-widgets/controls","model_module_version":"2.0.0","model_name":"HBoxModel","state":{"_dom_classes":[],"_model_module":"@jupyter-widgets/controls","_model_module_version":"2.0.0","_model_name":"HBoxModel","_view_count":null,"_view_module":"@jupyter-widgets/controls","_view_module_version":"2.0.0","_view_name":"HBoxView","box_style":"","children":["IPY_MODEL_ceb6d35a8b5348a293d7f8d6acac5ec7","IPY_MODEL_5fb7ac1cf99d4639b7155586162e7686","IPY_MODEL_409a78b98e6240cf8b41c3931705ddef"],"layout":"IPY_MODEL_c24a4be6b9be481db2080df2b5706714","tabbable":null,"tooltip":null}},"03d0f5c765cf4114988f79d5be3aabb9":{"model_module":"@jupyter-widgets/controls","model_module_version":"2.0.0","model_name":"HTMLStyleModel","state":{"_model_module":"@jupyter-widgets/controls","_model_module_version":"2.0.0","_model_name":"HTMLStyleModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"2.0.0","_view_name":"StyleView","background":null,"description_width":"","font_size":null,"text_color":null}},"05fa399345c74510b5f2b2b19d7d0718":{"model_module":"@jupyter-widgets/controls","model_module_version":"2.0.0","model_name":"FloatProgressModel","state":{"_dom_classes":[],"_model_module":"@jupyter-widgets/controls","_model_module_version":"2.0.0","_model_name":"FloatProgressModel","_view_count":null,"_view_module":"@jupyter-widgets/controls","_view_module_version":"2.0.0","_view_name":"ProgressView","bar_style":"success","description":"","description_allow_html":false,"layout":"IPY_MODEL_69ae5807ef8146f38842ce15d5b1c5ec","max":223,"min":0,"orientation":"horizontal","style":"IPY_MODEL_f71fdecd9c7f4d91a41b3291d62b8a14","tabbable":null,"tooltip":null,"value":223}},"0844e76d873546f7a11e3e45cf3da897":{"model_module":"@jupyter-widgets/controls","model_module_version":"2.0.0","model_name":"HTMLModel","state":{"_dom_classes":[],"_model_module":"@jupyter-widgets/controls","_model_module_version":"2.0.0","_model_name":"HTMLModel","_view_count":null,"_view_module":"@jupyter-widgets/controls","_view_module_version":"2.0.0","_view_name":"HTMLView","description":"","description_allow_html":false,"layout":"IPY_MODEL_e48a4a5241f44a3cb8232766f25c6740","placeholder":"​","style":"IPY_MODEL_55d6ada4eb02404fb67efa4c290ef597","tabbable":null,"tooltip":null,"value":" 223/223 [00:00&lt;00:00, 1145.57it/s, Materializing param=layernorm.weight]"}},"097f38fe4bee45b693ad539c99a885f3":{"model_module":"@jupyter-widgets/base","model_module_version":"2.0.0","model_name":"LayoutModel","state":{"_model_module":"@jupyter-widgets/base","_model_module_version":"2.0.0","_model_name":"LayoutModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"2.0.0","_view_name":"LayoutView","align_content":null,"align_items":null,"align_self":null,"border_bottom":null,"border_left":null,"border_right":null,"border_top":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,"padding":null,"right":null,"top":null,"visibility":null,"width":null}},"098969175b144ef19cd9b9b40e91843b":{"model_module":"@jupyter-widgets/controls","model_module_version":"2.0.0","model_name":"HTMLStyleModel","state":{"_model_module":"@jupyter-widgets/controls","_model_module_version":"2.0.0","_model_name":"HTMLStyleModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"2.0.0","_view_name":"StyleView","background":null,"description_width":"","font_size":null,"text_color":null}},"09a748599f8b410eac2e1ac51225ee2d":{"model_module":"@jupyter-widgets/controls","model_module_version":"2.0.0","model_name":"HTMLModel","state":{"_dom_classes":[],"_model_module":"@jupyter-widgets/controls","_model_module_version":"2.0.0","_model_name":"HTMLModel","_view_count":null,"_view_module":"@jupyter-widgets/controls","_view_module_version":"2.0.0","_view_name":"HTMLView","description":"","description_allow_html":false,"layout":"IPY_MODEL_36d9a8c88c4a4a89838c7dd4863a7b87","placeholder":"​","style":"IPY_MODEL_ec65a83566d04c519826e56c566a9e23","tabbable":null,"tooltip":null,"value":"Loading weights: 100%"}},"0d988e81acbf4b3599fdc66f4fccc918":{"model_module":"@jupyter-widgets/controls","model_module_version":"2.0.0","model_name":"FloatProgressModel","state":{"_dom_classes":[],"_model_module":"@jupyter-widgets/controls","_model_module_version":"2.0.0","_model_name":"FloatProgressModel","_view_count":null,"_view_module":"@jupyter-widgets/controls","_view_module_version":"2.0.0","_view_name":"ProgressView","bar_style":"success","description":"","description_allow_html":false,"layout":"IPY_MODEL_c05abb35c11a47dd97c2074f45402d9c","max":223,"min":0,"orientation":"horizontal","style":"IPY_MODEL_6f23de34399d4a919eea5975cd714aea","tabbable":null,"tooltip":null,"value":223}},"0db17a353b734fb6b364fa2684f17aad":{"model_module":"@jupyter-widgets/controls","model_module_version":"2.0.0","model_name":"HTMLModel","state":{"_dom_classes":[],"_model_module":"@jupyter-widgets/controls","_model_module_version":"2.0.0","_model_name":"HTMLModel","_view_count":null,"_view_module":"@jupyter-widgets/controls","_view_module_version":"2.0.0","_view_name":"HTMLView","description":"","description_allow_html":false,"layout":"IPY_MODEL_5cf9693a26334f96b2c35eac5b34eb3e","placeholder":"​","style":"IPY_MODEL_beded1b180564b478a4b4242ac0fe7da","tabbable":null,"tooltip":null,"value":" 223/223 [00:00&lt;00:00, 959.90it/s, Materializing param=layernorm.weight]"}},"0dcd5ee7fc8543d0b3f41d02d6b31e14":{"model_module":"@jupyter-widgets/controls","model_module_version":"2.0.0","model_name":"HTMLStyleModel","state":{"_model_module":"@jupyter-widgets/controls","_model_module_version":"2.0.0","_model_name":"HTMLStyleModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"2.0.0","_view_name":"StyleView","background":null,"description_width":"","font_size":null,"text_color":null}},"0ddd72b204b2460f92fe7b22b7b2fd5d":{"model_module":"@jupyter-widgets/base","model_module_version":"2.0.0","model_name":"LayoutModel","state":{"_model_module":"@jupyter-widgets/base","_model_module_version":"2.0.0","_model_name":"LayoutModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"2.0.0","_view_name":"LayoutView","align_content":null,"align_items":null,"align_self":null,"border_bottom":null,"border_left":null,"border_right":null,"border_top":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,"padding":null,"right":null,"top":null,"visibility":null,"width":null}},"0e0f95105a3d4275a1a3a2454d48a219":{"model_module":"@jupyter-widgets/controls","model_module_version":"2.0.0","model_name":"HBoxModel","state":{"_dom_classes":[],"_model_module":"@jupyter-widgets/controls","_model_module_version":"2.0.0","_model_name":"HBoxModel","_view_count":null,"_view_module":"@jupyter-widgets/controls","_view_module_version":"2.0.0","_view_name":"HBoxView","box_style":"","children":["IPY_MODEL_488b8a4dc7b8458394f85973b2f5d511","IPY_MODEL_e3e22b182f544755afb4a00f3f8f2653","IPY_MODEL_a623bc44dcc64940b95367b8673b0241"],"layout":"IPY_MODEL_8ace7b4df9024e13955a5d5cf0369567","tabbable":null,"tooltip":null}},"0eaff4426e5e4d52a16f2829463afb20":{"model_module":"@jupyter-widgets/base","model_module_version":"2.0.0","model_name":"LayoutModel","state":{"_model_module":"@jupyter-widgets/base","_model_module_version":"2.0.0","_model_name":"LayoutModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"2.0.0","_view_name":"LayoutView","align_content":null,"align_items":null,"align_self":null,"border_bottom":null,"border_left":null,"border_right":null,"border_top":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,"padding":null,"right":null,"top":null,"visibility":null,"width":null}},"100a57bd2b0c4ba7b986727286c86e68":{"model_module":"@jupyter-widgets/base","model_module_version":"2.0.0","model_name":"LayoutModel","state":{"_model_module":"@jupyter-widgets/base","_model_module_version":"2.0.0","_model_name":"LayoutModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"2.0.0","_view_name":"LayoutView","align_content":null,"align_items":null,"align_self":null,"border_bottom":null,"border_left":null,"border_right":null,"border_top":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,"padding":null,"right":null,"top":null,"visibility":null,"width":null}},"10402d8be7b04ae1ab1cae7ce1911f08":{"model_module":"@jupyter-widgets/controls","model_module_version":"2.0.0","model_name":"ProgressStyleModel","state":{"_model_module":"@jupyter-widgets/controls","_model_module_version":"2.0.0","_model_name":"ProgressStyleModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"2.0.0","_view_name":"StyleView","bar_color":null,"description_width":""}},"1064917783d44e09803c285c2effdf7b":{"model_module":"@jupyter-widgets/controls","model_module_version":"2.0.0","model_name":"HTMLStyleModel","state":{"_model_module":"@jupyter-widgets/controls","_model_module_version":"2.0.0","_model_name":"HTMLStyleModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"2.0.0","_view_name":"StyleView","background":null,"description_width":"","font_size":null,"text_color":null}},"13669aa7aefb4b6491bda1d1969b4670":{"model_module":"@jupyter-widgets/base","model_module_version":"2.0.0","model_name":"LayoutModel","state":{"_model_module":"@jupyter-widgets/base","_model_module_version":"2.0.0","_model_name":"LayoutModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"2.0.0","_view_name":"LayoutView","align_content":null,"align_items":null,"align_self":null,"border_bottom":null,"border_left":null,"border_right":null,"border_top":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,"padding":null,"right":null,"top":null,"visibility":null,"width":null}},"14412a251c754e029df3ab84ac7bf8cc":{"model_module":"@jupyter-widgets/controls","model_module_version":"2.0.0","model_name":"HTMLStyleModel","state":{"_model_module":"@jupyter-widgets/controls","_model_module_version":"2.0.0","_model_name":"HTMLStyleModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"2.0.0","_view_name":"StyleView","background":null,"description_width":"","font_size":null,"text_color":null}},"1507a6a0325245cca765e119ea33f638":{"model_module":"@jupyter-widgets/controls","model_module_version":"2.0.0","model_name":"HTMLStyleModel","state":{"_model_module":"@jupyter-widgets/controls","_model_module_version":"2.0.0","_model_name":"HTMLStyleModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"2.0.0","_view_name":"StyleView","background":null,"description_width":"","font_size":null,"text_color":null}},"15336796bcfa49c287b6250e5971fdbb":{"model_module":"@jupyter-widgets/base","model_module_version":"2.0.0","model_name":"LayoutModel","state":{"_model_module":"@jupyter-widgets/base","_model_module_version":"2.0.0","_model_name":"LayoutModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"2.0.0","_view_name":"LayoutView","align_content":null,"align_items":null,"align_self":null,"border_bottom":null,"border_left":null,"border_right":null,"border_top":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,"padding":null,"right":null,"top":null,"visibility":null,"width":null}},"178d45745c894064862998869a18cc77":{"model_module":"@jupyter-widgets/base","model_module_version":"2.0.0","model_name":"LayoutModel","state":{"_model_module":"@jupyter-widgets/base","_model_module_version":"2.0.0","_model_name":"LayoutModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"2.0.0","_view_name":"LayoutView","align_content":null,"align_items":null,"align_self":null,"border_bottom":null,"border_left":null,"border_right":null,"border_top":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,"padding":null,"right":null,"top":null,"visibility":null,"width":null}},"18172273e0fc4de488da1fd4dded1c43":{"model_module":"@jupyter-widgets/controls","model_module_version":"2.0.0","model_name":"HTMLModel","state":{"_dom_classes":[],"_model_module":"@jupyter-widgets/controls","_model_module_version":"2.0.0","_model_name":"HTMLModel","_view_count":null,"_view_module":"@jupyter-widgets/controls","_view_module_version":"2.0.0","_view_name":"HTMLView","description":"","description_allow_html":false,"layout":"IPY_MODEL_663052a56a984da58b875eaac07d1606","placeholder":"​","style":"IPY_MODEL_3e0241d60ce249559841fb1c363d6274","tabbable":null,"tooltip":null,"value":"Loading weights: 100%"}},"1989458a6ef24a62a8b5cd252d3812e9":{"model_module":"@jupyter-widgets/controls","model_module_version":"2.0.0","model_name":"HBoxModel","state":{"_dom_classes":[],"_model_module":"@jupyter-widgets/controls","_model_module_version":"2.0.0","_model_name":"HBoxModel","_view_count":null,"_view_module":"@jupyter-widgets/controls","_view_module_version":"2.0.0","_view_name":"HBoxView","box_style":"","children":["IPY_MODEL_58a59ee89ce04bf69ee30486566ab061","IPY_MODEL_91e2955282bd4c7e937acffa9d002d83","IPY_MODEL_4eda62dfd85b4901832fdfaa18be8ee8"],"layout":"IPY_MODEL_1bbff5a53f004b0e83b6f94d877e9240","tabbable":null,"tooltip":null}},"1bbff5a53f004b0e83b6f94d877e9240":{"model_module":"@jupyter-widgets/base","model_module_version":"2.0.0","model_name":"LayoutModel","state":{"_model_module":"@jupyter-widgets/base","_model_module_version":"2.0.0","_model_name":"LayoutModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"2.0.0","_view_name":"LayoutView","align_content":null,"align_items":null,"align_self":null,"border_bottom":null,"border_left":null,"border_right":null,"border_top":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,"padding":null,"right":null,"top":null,"visibility":null,"width":null}},"1be9455b98294b1aa892ac5aec5284b4":{"model_module":"@jupyter-widgets/controls","model_module_version":"2.0.0","model_name":"FloatProgressModel","state":{"_dom_classes":[],"_model_module":"@jupyter-widgets/controls","_model_module_version":"2.0.0","_model_name":"FloatProgressModel","_view_count":null,"_view_module":"@jupyter-widgets/controls","_view_module_version":"2.0.0","_view_name":"ProgressView","bar_style":"success","description":"","description_allow_html":false,"layout":"IPY_MODEL_b6fd0efdf4834243bde4a883825fe2d4","max":223,"min":0,"orientation":"horizontal","style":"IPY_MODEL_3c943590d3374259902598efba00fa04","tabbable":null,"tooltip":null,"value":223}},"1cf8fb0e6058400a8422d85078a3dceb":{"model_module":"@jupyter-widgets/controls","model_module_version":"2.0.0","model_name":"ProgressStyleModel","state":{"_model_module":"@jupyter-widgets/controls","_model_module_version":"2.0.0","_model_name":"ProgressStyleModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"2.0.0","_view_name":"StyleView","bar_color":null,"description_width":""}},"1d322dfc68634de381931f45454d669e":{"model_module":"@jupyter-widgets/base","model_module_version":"2.0.0","model_name":"LayoutModel","state":{"_model_module":"@jupyter-widgets/base","_model_module_version":"2.0.0","_model_name":"LayoutModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"2.0.0","_view_name":"LayoutView","align_content":null,"align_items":null,"align_self":null,"border_bottom":null,"border_left":null,"border_right":null,"border_top":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,"padding":null,"right":null,"top":null,"visibility":null,"width":null}},"1dd8bca50adf4f0f96a44655905acb54":{"model_module":"@jupyter-widgets/controls","model_module_version":"2.0.0","model_name":"HTMLStyleModel","state":{"_model_module":"@jupyter-widgets/controls","_model_module_version":"2.0.0","_model_name":"HTMLStyleModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"2.0.0","_view_name":"StyleView","background":null,"description_width":"","font_size":null,"text_color":null}},"1e2323525a8f4f52b26e14ba6f0b3e9d":{"model_module":"@jupyter-widgets/base","model_module_version":"2.0.0","model_name":"LayoutModel","state":{"_model_module":"@jupyter-widgets/base","_model_module_version":"2.0.0","_model_name":"LayoutModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"2.0.0","_view_name":"LayoutView","align_content":null,"align_items":null,"align_self":null,"border_bottom":null,"border_left":null,"border_right":null,"border_top":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,"padding":null,"right":null,"top":null,"visibility":null,"width":null}},"1eb103e2966d4dc999001fc848f21db6":{"model_module":"@jupyter-widgets/controls","model_module_version":"2.0.0","model_name":"HBoxModel","state":{"_dom_classes":[],"_model_module":"@jupyter-widgets/controls","_model_module_version":"2.0.0","_model_name":"HBoxModel","_view_count":null,"_view_module":"@jupyter-widgets/controls","_view_module_version":"2.0.0","_view_name":"HBoxView","box_style":"","children":["IPY_MODEL_c84d740736f84b3fa1eefeec86646109","IPY_MODEL_4f7a2ae3bd164b4a9514a1ffd1103076","IPY_MODEL_29a6c408afe24e9089b951870fadb0e0"],"layout":"IPY_MODEL_87bbc04364d6498b88719dfbbb5a1ee2","tabbable":null,"tooltip":null}},"1f693035528d448daffe4f9860c0d3db":{"model_module":"@jupyter-widgets/base","model_module_version":"2.0.0","model_name":"LayoutModel","state":{"_model_module":"@jupyter-widgets/base","_model_module_version":"2.0.0","_model_name":"LayoutModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"2.0.0","_view_name":"LayoutView","align_content":null,"align_items":null,"align_self":null,"border_bottom":null,"border_left":null,"border_right":null,"border_top":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,"padding":null,"right":null,"top":null,"visibility":null,"width":null}},"209a0f8c2e0244a2a17816095e76499d":{"model_module":"@jupyter-widgets/controls","model_module_version":"2.0.0","model_name":"HTMLModel","state":{"_dom_classes":[],"_model_module":"@jupyter-widgets/controls","_model_module_version":"2.0.0","_model_name":"HTMLModel","_view_count":null,"_view_module":"@jupyter-widgets/controls","_view_module_version":"2.0.0","_view_name":"HTMLView","description":"","description_allow_html":false,"layout":"IPY_MODEL_6e30292211f04a84a7bedaab45aff59c","placeholder":"​","style":"IPY_MODEL_cf708c198c384a94bcf5d1ba473fc6e3","tabbable":null,"tooltip":null,"value":"Loading weights: 100%"}},"20cc0525bb8148d48269a67fae468f33":{"model_module":"@jupyter-widgets/base","model_module_version":"2.0.0","model_name":"LayoutModel","state":{"_model_module":"@jupyter-widgets/base","_model_module_version":"2.0.0","_model_name":"LayoutModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"2.0.0","_view_name":"LayoutView","align_content":null,"align_items":null,"align_self":null,"border_bottom":null,"border_left":null,"border_right":null,"border_top":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,"padding":null,"right":null,"top":null,"visibility":null,"width":null}},"20da54e5b717403c8a91689ff903fd06":{"model_module":"@jupyter-widgets/controls","model_module_version":"2.0.0","model_name":"FloatProgressModel","state":{"_dom_classes":[],"_model_module":"@jupyter-widgets/controls","_model_module_version":"2.0.0","_model_name":"FloatProgressModel","_view_count":null,"_view_module":"@jupyter-widgets/controls","_view_module_version":"2.0.0","_view_name":"ProgressView","bar_style":"success","description":"","description_allow_html":false,"layout":"IPY_MODEL_a2579f7038b0418f91e2e75aacd6df43","max":223,"min":0,"orientation":"horizontal","style":"IPY_MODEL_10402d8be7b04ae1ab1cae7ce1911f08","tabbable":null,"tooltip":null,"value":223}},"22b016765aa6459eb44737a943dce141":{"model_module":"@jupyter-widgets/controls","model_module_version":"2.0.0","model_name":"HTMLModel","state":{"_dom_classes":[],"_model_module":"@jupyter-widgets/controls","_model_module_version":"2.0.0","_model_name":"HTMLModel","_view_count":null,"_view_module":"@jupyter-widgets/controls","_view_module_version":"2.0.0","_view_name":"HTMLView","description":"","description_allow_html":false,"layout":"IPY_MODEL_bad3c0fc39fa4decae455ebed98d090f","placeholder":"​","style":"IPY_MODEL_2e822c810ffc48b6adedf3ebb361ffd3","tabbable":null,"tooltip":null,"value":"Loading weights: 100%"}},"237d09eeb87b4e7e82cd688998370168":{"model_module":"@jupyter-widgets/controls","model_module_version":"2.0.0","model_name":"HTMLStyleModel","state":{"_model_module":"@jupyter-widgets/controls","_model_module_version":"2.0.0","_model_name":"HTMLStyleModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"2.0.0","_view_name":"StyleView","background":null,"description_width":"","font_size":null,"text_color":null}},"24a2c9ee2c534933bcbacc462a9c0715":{"model_module":"@jupyter-widgets/controls","model_module_version":"2.0.0","model_name":"HTMLStyleModel","state":{"_model_module":"@jupyter-widgets/controls","_model_module_version":"2.0.0","_model_name":"HTMLStyleModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"2.0.0","_view_name":"StyleView","background":null,"description_width":"","font_size":null,"text_color":null}},"255d562711c24fc1814b9052a91c1d0b":{"model_module":"@jupyter-widgets/controls","model_module_version":"2.0.0","model_name":"HBoxModel","state":{"_dom_classes":[],"_model_module":"@jupyter-widgets/controls","_model_module_version":"2.0.0","_model_name":"HBoxModel","_view_count":null,"_view_module":"@jupyter-widgets/controls","_view_module_version":"2.0.0","_view_name":"HBoxView","box_style":"","children":["IPY_MODEL_ec0355774b1a4c259c63d19eba43bff8","IPY_MODEL_b7b595332fe34e3890f0f47cc794cda3","IPY_MODEL_b97079b20e3f4c7aba9f056f6052da06"],"layout":"IPY_MODEL_8c54a60ed0f94d2ebe019a4023d7adf5","tabbable":null,"tooltip":null}},"256d056407b14b23b312cd1d7b156a89":{"model_module":"@jupyter-widgets/controls","model_module_version":"2.0.0","model_name":"ProgressStyleModel","state":{"_model_module":"@jupyter-widgets/controls","_model_module_version":"2.0.0","_model_name":"ProgressStyleModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"2.0.0","_view_name":"StyleView","bar_color":null,"description_width":""}},"2629c73aa1de4aea94348401800f694c":{"model_module":"@jupyter-widgets/controls","model_module_version":"2.0.0","model_name":"ProgressStyleModel","state":{"_model_module":"@jupyter-widgets/controls","_model_module_version":"2.0.0","_model_name":"ProgressStyleModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"2.0.0","_view_name":"StyleView","bar_color":null,"description_width":""}},"2701adafc52146269dd958e41356f324":{"model_module":"@jupyter-widgets/controls","model_module_version":"2.0.0","model_name":"HTMLStyleModel","state":{"_model_module":"@jupyter-widgets/controls","_model_module_version":"2.0.0","_model_name":"HTMLStyleModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"2.0.0","_view_name":"StyleView","background":null,"description_width":"","font_size":null,"text_color":null}},"2794b5f5c384447ab59d3600bc17b9de":{"model_module":"@jupyter-widgets/base","model_module_version":"2.0.0","model_name":"LayoutModel","state":{"_model_module":"@jupyter-widgets/base","_model_module_version":"2.0.0","_model_name":"LayoutModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"2.0.0","_view_name":"LayoutView","align_content":null,"align_items":null,"align_self":null,"border_bottom":null,"border_left":null,"border_right":null,"border_top":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,"padding":null,"right":null,"top":null,"visibility":null,"width":null}},"284bf1ef85d54b1db6721e7e47662932":{"model_module":"@jupyter-widgets/controls","model_module_version":"2.0.0","model_name":"FloatProgressModel","state":{"_dom_classes":[],"_model_module":"@jupyter-widgets/controls","_model_module_version":"2.0.0","_model_name":"FloatProgressModel","_view_count":null,"_view_module":"@jupyter-widgets/controls","_view_module_version":"2.0.0","_view_name":"ProgressView","bar_style":"success","description":"","description_allow_html":false,"layout":"IPY_MODEL_5e6a10e88e334ccab8a9e2596eb4d8b3","max":223,"min":0,"orientation":"horizontal","style":"IPY_MODEL_8c51b9adcc1145f5bd52f573554fba0c","tabbable":null,"tooltip":null,"value":223}},"289cdbef7d7f45a7979c6f7893264ab7":{"model_module":"@jupyter-widgets/controls","model_module_version":"2.0.0","model_name":"HTMLStyleModel","state":{"_model_module":"@jupyter-widgets/controls","_model_module_version":"2.0.0","_model_name":"HTMLStyleModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"2.0.0","_view_name":"StyleView","background":null,"description_width":"","font_size":null,"text_color":null}},"299a4b6710c74723976a534e1526048b":{"model_module":"@jupyter-widgets/base","model_module_version":"2.0.0","model_name":"LayoutModel","state":{"_model_module":"@jupyter-widgets/base","_model_module_version":"2.0.0","_model_name":"LayoutModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"2.0.0","_view_name":"LayoutView","align_content":null,"align_items":null,"align_self":null,"border_bottom":null,"border_left":null,"border_right":null,"border_top":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,"padding":null,"right":null,"top":null,"visibility":null,"width":null}},"29a6c408afe24e9089b951870fadb0e0":{"model_module":"@jupyter-widgets/controls","model_module_version":"2.0.0","model_name":"HTMLModel","state":{"_dom_classes":[],"_model_module":"@jupyter-widgets/controls","_model_module_version":"2.0.0","_model_name":"HTMLModel","_view_count":null,"_view_module":"@jupyter-widgets/controls","_view_module_version":"2.0.0","_view_name":"HTMLView","description":"","description_allow_html":false,"layout":"IPY_MODEL_2c4b59947f7e432f85dfbf3a154272ca","placeholder":"​","style":"IPY_MODEL_fa6a9a908f14421594266506b17f3e61","tabbable":null,"tooltip":null,"value":" 223/223 [00:00&lt;00:00, 1077.38it/s, Materializing param=layernorm.weight]"}},"29b678554c4b4726814fab0c61fc5ff0":{"model_module":"@jupyter-widgets/base","model_module_version":"2.0.0","model_name":"LayoutModel","state":{"_model_module":"@jupyter-widgets/base","_model_module_version":"2.0.0","_model_name":"LayoutModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"2.0.0","_view_name":"LayoutView","align_content":null,"align_items":null,"align_self":null,"border_bottom":null,"border_left":null,"border_right":null,"border_top":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,"padding":null,"right":null,"top":null,"visibility":null,"width":null}},"2c4b59947f7e432f85dfbf3a154272ca":{"model_module":"@jupyter-widgets/base","model_module_version":"2.0.0","model_name":"LayoutModel","state":{"_model_module":"@jupyter-widgets/base","_model_module_version":"2.0.0","_model_name":"LayoutModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"2.0.0","_view_name":"LayoutView","align_content":null,"align_items":null,"align_self":null,"border_bottom":null,"border_left":null,"border_right":null,"border_top":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,"padding":null,"right":null,"top":null,"visibility":null,"width":null}},"2e66c8a4b2d744a1a33261ec88682de0":{"model_module":"@jupyter-widgets/controls","model_module_version":"2.0.0","model_name":"HBoxModel","state":{"_dom_classes":[],"_model_module":"@jupyter-widgets/controls","_model_module_version":"2.0.0","_model_name":"HBoxModel","_view_count":null,"_view_module":"@jupyter-widgets/controls","_view_module_version":"2.0.0","_view_name":"HBoxView","box_style":"","children":["IPY_MODEL_75eab52f99744f3bb6d99f3aa62d8dc4","IPY_MODEL_da5a55252fa2435ab79f7e6e91284196","IPY_MODEL_dfe2a8ff305c4ffa943f4d3e026da100"],"layout":"IPY_MODEL_44e175682e19443aa0e54da9b7418a88","tabbable":null,"tooltip":null}},"2e822c810ffc48b6adedf3ebb361ffd3":{"model_module":"@jupyter-widgets/controls","model_module_version":"2.0.0","model_name":"HTMLStyleModel","state":{"_model_module":"@jupyter-widgets/controls","_model_module_version":"2.0.0","_model_name":"HTMLStyleModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"2.0.0","_view_name":"StyleView","background":null,"description_width":"","font_size":null,"text_color":null}},"30c204c11c664087b3048ba01fc987b2":{"model_module":"@jupyter-widgets/base","model_module_version":"2.0.0","model_name":"LayoutModel","state":{"_model_module":"@jupyter-widgets/base","_model_module_version":"2.0.0","_model_name":"LayoutModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"2.0.0","_view_name":"LayoutView","align_content":null,"align_items":null,"align_self":null,"border_bottom":null,"border_left":null,"border_right":null,"border_top":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,"padding":null,"right":null,"top":null,"visibility":null,"width":null}},"3150429ca26e45158495c7046c005ee2":{"model_module":"@jupyter-widgets/controls","model_module_version":"2.0.0","model_name":"HBoxModel","state":{"_dom_classes":[],"_model_module":"@jupyter-widgets/controls","_model_module_version":"2.0.0","_model_name":"HBoxModel","_view_count":null,"_view_module":"@jupyter-widgets/controls","_view_module_version":"2.0.0","_view_name":"HBoxView","box_style":"","children":["IPY_MODEL_58069f32a85e431b99ffa1de980cbc11","IPY_MODEL_cecae18ee7164ae0a8a3cfcd37a22c26","IPY_MODEL_0db17a353b734fb6b364fa2684f17aad"],"layout":"IPY_MODEL_02053e27aa9144c49067bcb5f2341819","tabbable":null,"tooltip":null}},"323e75fbd544481a8a74870f34fac04a":{"model_module":"@jupyter-widgets/controls","model_module_version":"2.0.0","model_name":"HTMLModel","state":{"_dom_classes":[],"_model_module":"@jupyter-widgets/controls","_model_module_version":"2.0.0","_model_name":"HTMLModel","_view_count":null,"_view_module":"@jupyter-widgets/controls","_view_module_version":"2.0.0","_view_name":"HTMLView","description":"","description_allow_html":false,"layout":"IPY_MODEL_01a8219d17b0404b8147b0c67b89881e","placeholder":"​","style":"IPY_MODEL_cf95799c368843c7819f4d8135d72f4c","tabbable":null,"tooltip":null,"value":" 223/223 [00:00&lt;00:00, 999.46it/s, Materializing param=layernorm.weight]"}},"3547b8a4b27e48d598c2d0e2ba902c7d":{"model_module":"@jupyter-widgets/controls","model_module_version":"2.0.0","model_name":"ProgressStyleModel","state":{"_model_module":"@jupyter-widgets/controls","_model_module_version":"2.0.0","_model_name":"ProgressStyleModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"2.0.0","_view_name":"StyleView","bar_color":null,"description_width":""}},"3608153b936d496999bae60b943183a9":{"model_module":"@jupyter-widgets/controls","model_module_version":"2.0.0","model_name":"HTMLStyleModel","state":{"_model_module":"@jupyter-widgets/controls","_model_module_version":"2.0.0","_model_name":"HTMLStyleModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"2.0.0","_view_name":"StyleView","background":null,"description_width":"","font_size":null,"text_color":null}},"36d9a8c88c4a4a89838c7dd4863a7b87":{"model_module":"@jupyter-widgets/base","model_module_version":"2.0.0","model_name":"LayoutModel","state":{"_model_module":"@jupyter-widgets/base","_model_module_version":"2.0.0","_model_name":"LayoutModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"2.0.0","_view_name":"LayoutView","align_content":null,"align_items":null,"align_self":null,"border_bottom":null,"border_left":null,"border_right":null,"border_top":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,"padding":null,"right":null,"top":null,"visibility":null,"width":null}},"373a5967417f4932ba27027caaddd5cb":{"model_module":"@jupyter-widgets/controls","model_module_version":"2.0.0","model_name":"HTMLStyleModel","state":{"_model_module":"@jupyter-widgets/controls","_model_module_version":"2.0.0","_model_name":"HTMLStyleModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"2.0.0","_view_name":"StyleView","background":null,"description_width":"","font_size":null,"text_color":null}},"3863ad62ca8d4fc6bfb21a524d163bb4":{"model_module":"@jupyter-widgets/base","model_module_version":"2.0.0","model_name":"LayoutModel","state":{"_model_module":"@jupyter-widgets/base","_model_module_version":"2.0.0","_model_name":"LayoutModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"2.0.0","_view_name":"LayoutView","align_content":null,"align_items":null,"align_self":null,"border_bottom":null,"border_left":null,"border_right":null,"border_top":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,"padding":null,"right":null,"top":null,"visibility":null,"width":null}},"3969c1a925ab4b92a040a2b264333f11":{"model_module":"@jupyter-widgets/controls","model_module_version":"2.0.0","model_name":"FloatProgressModel","state":{"_dom_classes":[],"_model_module":"@jupyter-widgets/controls","_model_module_version":"2.0.0","_model_name":"FloatProgressModel","_view_count":null,"_view_module":"@jupyter-widgets/controls","_view_module_version":"2.0.0","_view_name":"ProgressView","bar_style":"success","description":"","description_allow_html":false,"layout":"IPY_MODEL_30c204c11c664087b3048ba01fc987b2","max":223,"min":0,"orientation":"horizontal","style":"IPY_MODEL_2629c73aa1de4aea94348401800f694c","tabbable":null,"tooltip":null,"value":223}},"3a4a50efba42451e90e73a02181851b4":{"model_module":"@jupyter-widgets/controls","model_module_version":"2.0.0","model_name":"ProgressStyleModel","state":{"_model_module":"@jupyter-widgets/controls","_model_module_version":"2.0.0","_model_name":"ProgressStyleModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"2.0.0","_view_name":"StyleView","bar_color":null,"description_width":""}},"3c8df694057e4648a86e5c0c6d0b3be0":{"model_module":"@jupyter-widgets/base","model_module_version":"2.0.0","model_name":"LayoutModel","state":{"_model_module":"@jupyter-widgets/base","_model_module_version":"2.0.0","_model_name":"LayoutModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"2.0.0","_view_name":"LayoutView","align_content":null,"align_items":null,"align_self":null,"border_bottom":null,"border_left":null,"border_right":null,"border_top":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,"padding":null,"right":null,"top":null,"visibility":null,"width":null}},"3c943590d3374259902598efba00fa04":{"model_module":"@jupyter-widgets/controls","model_module_version":"2.0.0","model_name":"ProgressStyleModel","state":{"_model_module":"@jupyter-widgets/controls","_model_module_version":"2.0.0","_model_name":"ProgressStyleModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"2.0.0","_view_name":"StyleView","bar_color":null,"description_width":""}},"3cbdf255c9a2437292eb481e106c858d":{"model_module":"@jupyter-widgets/controls","model_module_version":"2.0.0","model_name":"HBoxModel","state":{"_dom_classes":[],"_model_module":"@jupyter-widgets/controls","_model_module_version":"2.0.0","_model_name":"HBoxModel","_view_count":null,"_view_module":"@jupyter-widgets/controls","_view_module_version":"2.0.0","_view_name":"HBoxView","box_style":"","children":["IPY_MODEL_209a0f8c2e0244a2a17816095e76499d","IPY_MODEL_9a3c0f2972ca4ff6aa60799e57d1ef83","IPY_MODEL_0844e76d873546f7a11e3e45cf3da897"],"layout":"IPY_MODEL_4f18bd2d1071452eab7b070e34ff3f23","tabbable":null,"tooltip":null}},"3cbfbbad363f4385b4041ec70077f74f":{"model_module":"@jupyter-widgets/controls","model_module_version":"2.0.0","model_name":"HTMLModel","state":{"_dom_classes":[],"_model_module":"@jupyter-widgets/controls","_model_module_version":"2.0.0","_model_name":"HTMLModel","_view_count":null,"_view_module":"@jupyter-widgets/controls","_view_module_version":"2.0.0","_view_name":"HTMLView","description":"","description_allow_html":false,"layout":"IPY_MODEL_64a2463d44294b86911a1609f911eac3","placeholder":"​","style":"IPY_MODEL_1064917783d44e09803c285c2effdf7b","tabbable":null,"tooltip":null,"value":"Loading weights: 100%"}},"3d2e2c5aa4004f529a69c2920039ac5f":{"model_module":"@jupyter-widgets/controls","model_module_version":"2.0.0","model_name":"HTMLStyleModel","state":{"_model_module":"@jupyter-widgets/controls","_model_module_version":"2.0.0","_model_name":"HTMLStyleModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"2.0.0","_view_name":"StyleView","background":null,"description_width":"","font_size":null,"text_color":null}},"3deb29d8ab2943f6b588e771e48a5ebe":{"model_module":"@jupyter-widgets/controls","model_module_version":"2.0.0","model_name":"HTMLModel","state":{"_dom_classes":[],"_model_module":"@jupyter-widgets/controls","_model_module_version":"2.0.0","_model_name":"HTMLModel","_view_count":null,"_view_module":"@jupyter-widgets/controls","_view_module_version":"2.0.0","_view_name":"HTMLView","description":"","description_allow_html":false,"layout":"IPY_MODEL_ede35c9a909f4dd6be6d17a11c8cd320","placeholder":"​","style":"IPY_MODEL_9cb61ef8f84d4ff797d0bb561126193c","tabbable":null,"tooltip":null,"value":" 223/223 [00:00&lt;00:00, 902.58it/s, Materializing param=layernorm.weight]"}},"3e0241d60ce249559841fb1c363d6274":{"model_module":"@jupyter-widgets/controls","model_module_version":"2.0.0","model_name":"HTMLStyleModel","state":{"_model_module":"@jupyter-widgets/controls","_model_module_version":"2.0.0","_model_name":"HTMLStyleModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"2.0.0","_view_name":"StyleView","background":null,"description_width":"","font_size":null,"text_color":null}},"3e4269f045144ca2957d2586db67ec8c":{"model_module":"@jupyter-widgets/controls","model_module_version":"2.0.0","model_name":"HTMLStyleModel","state":{"_model_module":"@jupyter-widgets/controls","_model_module_version":"2.0.0","_model_name":"HTMLStyleModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"2.0.0","_view_name":"StyleView","background":null,"description_width":"","font_size":null,"text_color":null}},"3ed045f047b645aeba7daa902550be1a":{"model_module":"@jupyter-widgets/controls","model_module_version":"2.0.0","model_name":"HTMLStyleModel","state":{"_model_module":"@jupyter-widgets/controls","_model_module_version":"2.0.0","_model_name":"HTMLStyleModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"2.0.0","_view_name":"StyleView","background":null,"description_width":"","font_size":null,"text_color":null}},"3f1363cd590149d68b800ef1511b5b3a":{"model_module":"@jupyter-widgets/base","model_module_version":"2.0.0","model_name":"LayoutModel","state":{"_model_module":"@jupyter-widgets/base","_model_module_version":"2.0.0","_model_name":"LayoutModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"2.0.0","_view_name":"LayoutView","align_content":null,"align_items":null,"align_self":null,"border_bottom":null,"border_left":null,"border_right":null,"border_top":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,"padding":null,"right":null,"top":null,"visibility":null,"width":null}},"409a78b98e6240cf8b41c3931705ddef":{"model_module":"@jupyter-widgets/controls","model_module_version":"2.0.0","model_name":"HTMLModel","state":{"_dom_classes":[],"_model_module":"@jupyter-widgets/controls","_model_module_version":"2.0.0","_model_name":"HTMLModel","_view_count":null,"_view_module":"@jupyter-widgets/controls","_view_module_version":"2.0.0","_view_name":"HTMLView","description":"","description_allow_html":false,"layout":"IPY_MODEL_cf685555d2654c57a1c0dbc81449b69e","placeholder":"​","style":"IPY_MODEL_373a5967417f4932ba27027caaddd5cb","tabbable":null,"tooltip":null,"value":" 223/223 [00:00&lt;00:00, 1053.86it/s, Materializing param=layernorm.weight]"}},"40a1ff147d3c4bf3ad2837e43955b9bf":{"model_module":"@jupyter-widgets/base","model_module_version":"2.0.0","model_name":"LayoutModel","state":{"_model_module":"@jupyter-widgets/base","_model_module_version":"2.0.0","_model_name":"LayoutModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"2.0.0","_view_name":"LayoutView","align_content":null,"align_items":null,"align_self":null,"border_bottom":null,"border_left":null,"border_right":null,"border_top":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,"padding":null,"right":null,"top":null,"visibility":null,"width":null}},"423b6a7bd6d34b15b8065a9c0bcdf1fb":{"model_module":"@jupyter-widgets/controls","model_module_version":"2.0.0","model_name":"FloatProgressModel","state":{"_dom_classes":[],"_model_module":"@jupyter-widgets/controls","_model_module_version":"2.0.0","_model_name":"FloatProgressModel","_view_count":null,"_view_module":"@jupyter-widgets/controls","_view_module_version":"2.0.0","_view_name":"ProgressView","bar_style":"success","description":"","description_allow_html":false,"layout":"IPY_MODEL_3f1363cd590149d68b800ef1511b5b3a","max":223,"min":0,"orientation":"horizontal","style":"IPY_MODEL_da139d630cce448bba7a7189114d3b2d","tabbable":null,"tooltip":null,"value":223}},"44e175682e19443aa0e54da9b7418a88":{"model_module":"@jupyter-widgets/base","model_module_version":"2.0.0","model_name":"LayoutModel","state":{"_model_module":"@jupyter-widgets/base","_model_module_version":"2.0.0","_model_name":"LayoutModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"2.0.0","_view_name":"LayoutView","align_content":null,"align_items":null,"align_self":null,"border_bottom":null,"border_left":null,"border_right":null,"border_top":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,"padding":null,"right":null,"top":null,"visibility":null,"width":null}},"488b8a4dc7b8458394f85973b2f5d511":{"model_module":"@jupyter-widgets/controls","model_module_version":"2.0.0","model_name":"HTMLModel","state":{"_dom_classes":[],"_model_module":"@jupyter-widgets/controls","_model_module_version":"2.0.0","_model_name":"HTMLModel","_view_count":null,"_view_module":"@jupyter-widgets/controls","_view_module_version":"2.0.0","_view_name":"HTMLView","description":"","description_allow_html":false,"layout":"IPY_MODEL_5d69742f57874c898dbb3e4aec99a71d","placeholder":"​","style":"IPY_MODEL_3d2e2c5aa4004f529a69c2920039ac5f","tabbable":null,"tooltip":null,"value":"Loading weights: 100%"}},"4b864b78db214512ad124047c4d9ef77":{"model_module":"@jupyter-widgets/base","model_module_version":"2.0.0","model_name":"LayoutModel","state":{"_model_module":"@jupyter-widgets/base","_model_module_version":"2.0.0","_model_name":"LayoutModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"2.0.0","_view_name":"LayoutView","align_content":null,"align_items":null,"align_self":null,"border_bottom":null,"border_left":null,"border_right":null,"border_top":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,"padding":null,"right":null,"top":null,"visibility":null,"width":null}},"4ba690ba7143496e94be6dfc3b7a147a":{"model_module":"@jupyter-widgets/controls","model_module_version":"2.0.0","model_name":"FloatProgressModel","state":{"_dom_classes":[],"_model_module":"@jupyter-widgets/controls","_model_module_version":"2.0.0","_model_name":"FloatProgressModel","_view_count":null,"_view_module":"@jupyter-widgets/controls","_view_module_version":"2.0.0","_view_name":"ProgressView","bar_style":"success","description":"","description_allow_html":false,"layout":"IPY_MODEL_0eaff4426e5e4d52a16f2829463afb20","max":223,"min":0,"orientation":"horizontal","style":"IPY_MODEL_be813dd7f81d411582b5507cb5861b56","tabbable":null,"tooltip":null,"value":223}},"4dd09d356fc749e3aaf294599a863fd3":{"model_module":"@jupyter-widgets/base","model_module_version":"2.0.0","model_name":"LayoutModel","state":{"_model_module":"@jupyter-widgets/base","_model_module_version":"2.0.0","_model_name":"LayoutModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"2.0.0","_view_name":"LayoutView","align_content":null,"align_items":null,"align_self":null,"border_bottom":null,"border_left":null,"border_right":null,"border_top":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,"padding":null,"right":null,"top":null,"visibility":null,"width":null}},"4eda62dfd85b4901832fdfaa18be8ee8":{"model_module":"@jupyter-widgets/controls","model_module_version":"2.0.0","model_name":"HTMLModel","state":{"_dom_classes":[],"_model_module":"@jupyter-widgets/controls","_model_module_version":"2.0.0","_model_name":"HTMLModel","_view_count":null,"_view_module":"@jupyter-widgets/controls","_view_module_version":"2.0.0","_view_name":"HTMLView","description":"","description_allow_html":false,"layout":"IPY_MODEL_c508a3b8c5a44b2e992f82012db5697a","placeholder":"​","style":"IPY_MODEL_9fcf60914a9b4a9da5dd7edb028d7fe5","tabbable":null,"tooltip":null,"value":" 223/223 [00:00&lt;00:00, 963.02it/s, Materializing param=layernorm.weight]"}},"4f18bd2d1071452eab7b070e34ff3f23":{"model_module":"@jupyter-widgets/base","model_module_version":"2.0.0","model_name":"LayoutModel","state":{"_model_module":"@jupyter-widgets/base","_model_module_version":"2.0.0","_model_name":"LayoutModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"2.0.0","_view_name":"LayoutView","align_content":null,"align_items":null,"align_self":null,"border_bottom":null,"border_left":null,"border_right":null,"border_top":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,"padding":null,"right":null,"top":null,"visibility":null,"width":null}},"4f31f57c03fc495f811ed31fe38563b6":{"model_module":"@jupyter-widgets/controls","model_module_version":"2.0.0","model_name":"HTMLModel","state":{"_dom_classes":[],"_model_module":"@jupyter-widgets/controls","_model_module_version":"2.0.0","_model_name":"HTMLModel","_view_count":null,"_view_module":"@jupyter-widgets/controls","_view_module_version":"2.0.0","_view_name":"HTMLView","description":"","description_allow_html":false,"layout":"IPY_MODEL_f6f1d4c13537448c96764409cdb36e86","placeholder":"​","style":"IPY_MODEL_88b1a65412ba4bbdab9928e95b2e3fa7","tabbable":null,"tooltip":null,"value":" 223/223 [00:00&lt;00:00, 1028.75it/s, Materializing param=layernorm.weight]"}},"4f7a2ae3bd164b4a9514a1ffd1103076":{"model_module":"@jupyter-widgets/controls","model_module_version":"2.0.0","model_name":"FloatProgressModel","state":{"_dom_classes":[],"_model_module":"@jupyter-widgets/controls","_model_module_version":"2.0.0","_model_name":"FloatProgressModel","_view_count":null,"_view_module":"@jupyter-widgets/controls","_view_module_version":"2.0.0","_view_name":"ProgressView","bar_style":"success","description":"","description_allow_html":false,"layout":"IPY_MODEL_1e2323525a8f4f52b26e14ba6f0b3e9d","max":223,"min":0,"orientation":"horizontal","style":"IPY_MODEL_3a4a50efba42451e90e73a02181851b4","tabbable":null,"tooltip":null,"value":223}},"55d6ada4eb02404fb67efa4c290ef597":{"model_module":"@jupyter-widgets/controls","model_module_version":"2.0.0","model_name":"HTMLStyleModel","state":{"_model_module":"@jupyter-widgets/controls","_model_module_version":"2.0.0","_model_name":"HTMLStyleModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"2.0.0","_view_name":"StyleView","background":null,"description_width":"","font_size":null,"text_color":null}},"5683c4fd82ce4a7d82541fdc553bd4c4":{"model_module":"@jupyter-widgets/base","model_module_version":"2.0.0","model_name":"LayoutModel","state":{"_model_module":"@jupyter-widgets/base","_model_module_version":"2.0.0","_model_name":"LayoutModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"2.0.0","_view_name":"LayoutView","align_content":null,"align_items":null,"align_self":null,"border_bottom":null,"border_left":null,"border_right":null,"border_top":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,"padding":null,"right":null,"top":null,"visibility":null,"width":null}},"57eafe8c675140339cd23233899919c7":{"model_module":"@jupyter-widgets/controls","model_module_version":"2.0.0","model_name":"FloatProgressModel","state":{"_dom_classes":[],"_model_module":"@jupyter-widgets/controls","_model_module_version":"2.0.0","_model_name":"FloatProgressModel","_view_count":null,"_view_module":"@jupyter-widgets/controls","_view_module_version":"2.0.0","_view_name":"ProgressView","bar_style":"success","description":"","description_allow_html":false,"layout":"IPY_MODEL_2794b5f5c384447ab59d3600bc17b9de","max":223,"min":0,"orientation":"horizontal","style":"IPY_MODEL_f8b6994d075e4345b31b0057f20c724f","tabbable":null,"tooltip":null,"value":223}},"58069f32a85e431b99ffa1de980cbc11":{"model_module":"@jupyter-widgets/controls","model_module_version":"2.0.0","model_name":"HTMLModel","state":{"_dom_classes":[],"_model_module":"@jupyter-widgets/controls","_model_module_version":"2.0.0","_model_name":"HTMLModel","_view_count":null,"_view_module":"@jupyter-widgets/controls","_view_module_version":"2.0.0","_view_name":"HTMLView","description":"","description_allow_html":false,"layout":"IPY_MODEL_3c8df694057e4648a86e5c0c6d0b3be0","placeholder":"​","style":"IPY_MODEL_68e39fae81564373b71a9e7045690708","tabbable":null,"tooltip":null,"value":"Loading weights: 100%"}},"58a59ee89ce04bf69ee30486566ab061":{"model_module":"@jupyter-widgets/controls","model_module_version":"2.0.0","model_name":"HTMLModel","state":{"_dom_classes":[],"_model_module":"@jupyter-widgets/controls","_model_module_version":"2.0.0","_model_name":"HTMLModel","_view_count":null,"_view_module":"@jupyter-widgets/controls","_view_module_version":"2.0.0","_view_name":"HTMLView","description":"","description_allow_html":false,"layout":"IPY_MODEL_8ab1c62f06a449c2845432cc6b93ebaa","placeholder":"​","style":"IPY_MODEL_237d09eeb87b4e7e82cd688998370168","tabbable":null,"tooltip":null,"value":"Loading weights: 100%"}},"59b283b32aac44ae8a242061b3d38fde":{"model_module":"@jupyter-widgets/controls","model_module_version":"2.0.0","model_name":"HTMLModel","state":{"_dom_classes":[],"_model_module":"@jupyter-widgets/controls","_model_module_version":"2.0.0","_model_name":"HTMLModel","_view_count":null,"_view_module":"@jupyter-widgets/controls","_view_module_version":"2.0.0","_view_name":"HTMLView","description":"","description_allow_html":false,"layout":"IPY_MODEL_299a4b6710c74723976a534e1526048b","placeholder":"​","style":"IPY_MODEL_aa8043b4053a42cfb63b9030736e7dcd","tabbable":null,"tooltip":null,"value":" 223/223 [00:00&lt;00:00, 950.66it/s, Materializing param=layernorm.weight]"}},"59e1b732a3e847d6a401105e980ca75f":{"model_module":"@jupyter-widgets/controls","model_module_version":"2.0.0","model_name":"HBoxModel","state":{"_dom_classes":[],"_model_module":"@jupyter-widgets/controls","_model_module_version":"2.0.0","_model_name":"HBoxModel","_view_count":null,"_view_module":"@jupyter-widgets/controls","_view_module_version":"2.0.0","_view_name":"HBoxView","box_style":"","children":["IPY_MODEL_81106355d997468f9247851eaed1fede","IPY_MODEL_423b6a7bd6d34b15b8065a9c0bcdf1fb","IPY_MODEL_cfe40aa13ebb44b2a733c125adfa51de"],"layout":"IPY_MODEL_b1cb8240f1f14d9cafd85b7caecf851a","tabbable":null,"tooltip":null}},"5cf9693a26334f96b2c35eac5b34eb3e":{"model_module":"@jupyter-widgets/base","model_module_version":"2.0.0","model_name":"LayoutModel","state":{"_model_module":"@jupyter-widgets/base","_model_module_version":"2.0.0","_model_name":"LayoutModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"2.0.0","_view_name":"LayoutView","align_content":null,"align_items":null,"align_self":null,"border_bottom":null,"border_left":null,"border_right":null,"border_top":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,"padding":null,"right":null,"top":null,"visibility":null,"width":null}},"5d69742f57874c898dbb3e4aec99a71d":{"model_module":"@jupyter-widgets/base","model_module_version":"2.0.0","model_name":"LayoutModel","state":{"_model_module":"@jupyter-widgets/base","_model_module_version":"2.0.0","_model_name":"LayoutModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"2.0.0","_view_name":"LayoutView","align_content":null,"align_items":null,"align_self":null,"border_bottom":null,"border_left":null,"border_right":null,"border_top":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,"padding":null,"right":null,"top":null,"visibility":null,"width":null}},"5e6a10e88e334ccab8a9e2596eb4d8b3":{"model_module":"@jupyter-widgets/base","model_module_version":"2.0.0","model_name":"LayoutModel","state":{"_model_module":"@jupyter-widgets/base","_model_module_version":"2.0.0","_model_name":"LayoutModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"2.0.0","_view_name":"LayoutView","align_content":null,"align_items":null,"align_self":null,"border_bottom":null,"border_left":null,"border_right":null,"border_top":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,"padding":null,"right":null,"top":null,"visibility":null,"width":null}},"5fb7ac1cf99d4639b7155586162e7686":{"model_module":"@jupyter-widgets/controls","model_module_version":"2.0.0","model_name":"FloatProgressModel","state":{"_dom_classes":[],"_model_module":"@jupyter-widgets/controls","_model_module_version":"2.0.0","_model_name":"FloatProgressModel","_view_count":null,"_view_module":"@jupyter-widgets/controls","_view_module_version":"2.0.0","_view_name":"ProgressView","bar_style":"success","description":"","description_allow_html":false,"layout":"IPY_MODEL_6688b9f540f44320b3ef4b8f8c623fef","max":223,"min":0,"orientation":"horizontal","style":"IPY_MODEL_8e5909c1d5b144f1ab499d2eed7224b1","tabbable":null,"tooltip":null,"value":223}},"625b1f5fc81f435ba8bfbeb1201e041a":{"model_module":"@jupyter-widgets/controls","model_module_version":"2.0.0","model_name":"ProgressStyleModel","state":{"_model_module":"@jupyter-widgets/controls","_model_module_version":"2.0.0","_model_name":"ProgressStyleModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"2.0.0","_view_name":"StyleView","bar_color":null,"description_width":""}},"629b547c39d64d38aa8831d29ee55bb7":{"model_module":"@jupyter-widgets/base","model_module_version":"2.0.0","model_name":"LayoutModel","state":{"_model_module":"@jupyter-widgets/base","_model_module_version":"2.0.0","_model_name":"LayoutModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"2.0.0","_view_name":"LayoutView","align_content":null,"align_items":null,"align_self":null,"border_bottom":null,"border_left":null,"border_right":null,"border_top":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,"padding":null,"right":null,"top":null,"visibility":null,"width":null}},"62d4e4c1d6f6484fb00e6b263cd6452e":{"model_module":"@jupyter-widgets/controls","model_module_version":"2.0.0","model_name":"HBoxModel","state":{"_dom_classes":[],"_model_module":"@jupyter-widgets/controls","_model_module_version":"2.0.0","_model_name":"HBoxModel","_view_count":null,"_view_module":"@jupyter-widgets/controls","_view_module_version":"2.0.0","_view_name":"HBoxView","box_style":"","children":["IPY_MODEL_3cbfbbad363f4385b4041ec70077f74f","IPY_MODEL_902ab029455a4bf9b333e38efeea779c","IPY_MODEL_4f31f57c03fc495f811ed31fe38563b6"],"layout":"IPY_MODEL_1d322dfc68634de381931f45454d669e","tabbable":null,"tooltip":null}},"64a2463d44294b86911a1609f911eac3":{"model_module":"@jupyter-widgets/base","model_module_version":"2.0.0","model_name":"LayoutModel","state":{"_model_module":"@jupyter-widgets/base","_model_module_version":"2.0.0","_model_name":"LayoutModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"2.0.0","_view_name":"LayoutView","align_content":null,"align_items":null,"align_self":null,"border_bottom":null,"border_left":null,"border_right":null,"border_top":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,"padding":null,"right":null,"top":null,"visibility":null,"width":null}},"663052a56a984da58b875eaac07d1606":{"model_module":"@jupyter-widgets/base","model_module_version":"2.0.0","model_name":"LayoutModel","state":{"_model_module":"@jupyter-widgets/base","_model_module_version":"2.0.0","_model_name":"LayoutModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"2.0.0","_view_name":"LayoutView","align_content":null,"align_items":null,"align_self":null,"border_bottom":null,"border_left":null,"border_right":null,"border_top":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,"padding":null,"right":null,"top":null,"visibility":null,"width":null}},"6688b9f540f44320b3ef4b8f8c623fef":{"model_module":"@jupyter-widgets/base","model_module_version":"2.0.0","model_name":"LayoutModel","state":{"_model_module":"@jupyter-widgets/base","_model_module_version":"2.0.0","_model_name":"LayoutModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"2.0.0","_view_name":"LayoutView","align_content":null,"align_items":null,"align_self":null,"border_bottom":null,"border_left":null,"border_right":null,"border_top":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,"padding":null,"right":null,"top":null,"visibility":null,"width":null}},"676aa0a43ca34c26b96b3713e02c3fe9":{"model_module":"@jupyter-widgets/base","model_module_version":"2.0.0","model_name":"LayoutModel","state":{"_model_module":"@jupyter-widgets/base","_model_module_version":"2.0.0","_model_name":"LayoutModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"2.0.0","_view_name":"LayoutView","align_content":null,"align_items":null,"align_self":null,"border_bottom":null,"border_left":null,"border_right":null,"border_top":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,"padding":null,"right":null,"top":null,"visibility":null,"width":null}},"68e39fae81564373b71a9e7045690708":{"model_module":"@jupyter-widgets/controls","model_module_version":"2.0.0","model_name":"HTMLStyleModel","state":{"_model_module":"@jupyter-widgets/controls","_model_module_version":"2.0.0","_model_name":"HTMLStyleModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"2.0.0","_view_name":"StyleView","background":null,"description_width":"","font_size":null,"text_color":null}},"69ae5807ef8146f38842ce15d5b1c5ec":{"model_module":"@jupyter-widgets/base","model_module_version":"2.0.0","model_name":"LayoutModel","state":{"_model_module":"@jupyter-widgets/base","_model_module_version":"2.0.0","_model_name":"LayoutModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"2.0.0","_view_name":"LayoutView","align_content":null,"align_items":null,"align_self":null,"border_bottom":null,"border_left":null,"border_right":null,"border_top":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,"padding":null,"right":null,"top":null,"visibility":null,"width":null}},"6ac07627fa00481da08d7a3203519fe4":{"model_module":"@jupyter-widgets/controls","model_module_version":"2.0.0","model_name":"HTMLStyleModel","state":{"_model_module":"@jupyter-widgets/controls","_model_module_version":"2.0.0","_model_name":"HTMLStyleModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"2.0.0","_view_name":"StyleView","background":null,"description_width":"","font_size":null,"text_color":null}},"6ac9cf5ccdb3453793af6e6c9a0e6462":{"model_module":"@jupyter-widgets/base","model_module_version":"2.0.0","model_name":"LayoutModel","state":{"_model_module":"@jupyter-widgets/base","_model_module_version":"2.0.0","_model_name":"LayoutModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"2.0.0","_view_name":"LayoutView","align_content":null,"align_items":null,"align_self":null,"border_bottom":null,"border_left":null,"border_right":null,"border_top":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,"padding":null,"right":null,"top":null,"visibility":null,"width":null}},"6b18934e03b640fca1141636b96a537d":{"model_module":"@jupyter-widgets/controls","model_module_version":"2.0.0","model_name":"HTMLModel","state":{"_dom_classes":[],"_model_module":"@jupyter-widgets/controls","_model_module_version":"2.0.0","_model_name":"HTMLModel","_view_count":null,"_view_module":"@jupyter-widgets/controls","_view_module_version":"2.0.0","_view_name":"HTMLView","description":"","description_allow_html":false,"layout":"IPY_MODEL_e6b7032fe702492083ae47fc680824bf","placeholder":"​","style":"IPY_MODEL_c56bc19b2c9e487e9c5440a1224e719e","tabbable":null,"tooltip":null,"value":"Loading weights: 100%"}},"6e30292211f04a84a7bedaab45aff59c":{"model_module":"@jupyter-widgets/base","model_module_version":"2.0.0","model_name":"LayoutModel","state":{"_model_module":"@jupyter-widgets/base","_model_module_version":"2.0.0","_model_name":"LayoutModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"2.0.0","_view_name":"LayoutView","align_content":null,"align_items":null,"align_self":null,"border_bottom":null,"border_left":null,"border_right":null,"border_top":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,"padding":null,"right":null,"top":null,"visibility":null,"width":null}},"6f23de34399d4a919eea5975cd714aea":{"model_module":"@jupyter-widgets/controls","model_module_version":"2.0.0","model_name":"ProgressStyleModel","state":{"_model_module":"@jupyter-widgets/controls","_model_module_version":"2.0.0","_model_name":"ProgressStyleModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"2.0.0","_view_name":"StyleView","bar_color":null,"description_width":""}},"728d6e8ffb934a3487ed4fa3f9924a16":{"model_module":"@jupyter-widgets/controls","model_module_version":"2.0.0","model_name":"ProgressStyleModel","state":{"_model_module":"@jupyter-widgets/controls","_model_module_version":"2.0.0","_model_name":"ProgressStyleModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"2.0.0","_view_name":"StyleView","bar_color":null,"description_width":""}},"72a44a215271488ab5aa83e395c944c8":{"model_module":"@jupyter-widgets/controls","model_module_version":"2.0.0","model_name":"HTMLStyleModel","state":{"_model_module":"@jupyter-widgets/controls","_model_module_version":"2.0.0","_model_name":"HTMLStyleModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"2.0.0","_view_name":"StyleView","background":null,"description_width":"","font_size":null,"text_color":null}},"746b385de3344b63921ca631de47f4d2":{"model_module":"@jupyter-widgets/base","model_module_version":"2.0.0","model_name":"LayoutModel","state":{"_model_module":"@jupyter-widgets/base","_model_module_version":"2.0.0","_model_name":"LayoutModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"2.0.0","_view_name":"LayoutView","align_content":null,"align_items":null,"align_self":null,"border_bottom":null,"border_left":null,"border_right":null,"border_top":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,"padding":null,"right":null,"top":null,"visibility":null,"width":null}},"749c34a01ee84bdaa5b394bac8c0150e":{"model_module":"@jupyter-widgets/base","model_module_version":"2.0.0","model_name":"LayoutModel","state":{"_model_module":"@jupyter-widgets/base","_model_module_version":"2.0.0","_model_name":"LayoutModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"2.0.0","_view_name":"LayoutView","align_content":null,"align_items":null,"align_self":null,"border_bottom":null,"border_left":null,"border_right":null,"border_top":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,"padding":null,"right":null,"top":null,"visibility":null,"width":null}},"74fd0d6b8c224ed3acf9f5a693cfbf6f":{"model_module":"@jupyter-widgets/controls","model_module_version":"2.0.0","model_name":"HTMLModel","state":{"_dom_classes":[],"_model_module":"@jupyter-widgets/controls","_model_module_version":"2.0.0","_model_name":"HTMLModel","_view_count":null,"_view_module":"@jupyter-widgets/controls","_view_module_version":"2.0.0","_view_name":"HTMLView","description":"","description_allow_html":false,"layout":"IPY_MODEL_b57fa6be90a94fbebe11e6fb09cc91a1","placeholder":"​","style":"IPY_MODEL_af6144783a5c4f1f92782b8644865ec4","tabbable":null,"tooltip":null,"value":" 223/223 [00:00&lt;00:00, 1189.31it/s, Materializing param=layernorm.weight]"}},"75eab52f99744f3bb6d99f3aa62d8dc4":{"model_module":"@jupyter-widgets/controls","model_module_version":"2.0.0","model_name":"HTMLModel","state":{"_dom_classes":[],"_model_module":"@jupyter-widgets/controls","_model_module_version":"2.0.0","_model_name":"HTMLModel","_view_count":null,"_view_module":"@jupyter-widgets/controls","_view_module_version":"2.0.0","_view_name":"HTMLView","description":"","description_allow_html":false,"layout":"IPY_MODEL_838863d1797a4efaa502eeb9bf3df880","placeholder":"​","style":"IPY_MODEL_1507a6a0325245cca765e119ea33f638","tabbable":null,"tooltip":null,"value":"Loading weights: 100%"}},"7742b316c79649f7a8836ddaae3d7f43":{"model_module":"@jupyter-widgets/base","model_module_version":"2.0.0","model_name":"LayoutModel","state":{"_model_module":"@jupyter-widgets/base","_model_module_version":"2.0.0","_model_name":"LayoutModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"2.0.0","_view_name":"LayoutView","align_content":null,"align_items":null,"align_self":null,"border_bottom":null,"border_left":null,"border_right":null,"border_top":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,"padding":null,"right":null,"top":null,"visibility":null,"width":null}},"77b52ce86ccc41c296f21da8a5045430":{"model_module":"@jupyter-widgets/base","model_module_version":"2.0.0","model_name":"LayoutModel","state":{"_model_module":"@jupyter-widgets/base","_model_module_version":"2.0.0","_model_name":"LayoutModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"2.0.0","_view_name":"LayoutView","align_content":null,"align_items":null,"align_self":null,"border_bottom":null,"border_left":null,"border_right":null,"border_top":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,"padding":null,"right":null,"top":null,"visibility":null,"width":null}},"78995e9932cf407c91b7bf70cbfd1a80":{"model_module":"@jupyter-widgets/base","model_module_version":"2.0.0","model_name":"LayoutModel","state":{"_model_module":"@jupyter-widgets/base","_model_module_version":"2.0.0","_model_name":"LayoutModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"2.0.0","_view_name":"LayoutView","align_content":null,"align_items":null,"align_self":null,"border_bottom":null,"border_left":null,"border_right":null,"border_top":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,"padding":null,"right":null,"top":null,"visibility":null,"width":null}},"78a366edbb964c7fa4d0e3307a7ee090":{"model_module":"@jupyter-widgets/controls","model_module_version":"2.0.0","model_name":"HTMLStyleModel","state":{"_model_module":"@jupyter-widgets/controls","_model_module_version":"2.0.0","_model_name":"HTMLStyleModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"2.0.0","_view_name":"StyleView","background":null,"description_width":"","font_size":null,"text_color":null}},"7932c89ad60c480b889926e494b893b4":{"model_module":"@jupyter-widgets/base","model_module_version":"2.0.0","model_name":"LayoutModel","state":{"_model_module":"@jupyter-widgets/base","_model_module_version":"2.0.0","_model_name":"LayoutModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"2.0.0","_view_name":"LayoutView","align_content":null,"align_items":null,"align_self":null,"border_bottom":null,"border_left":null,"border_right":null,"border_top":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,"padding":null,"right":null,"top":null,"visibility":null,"width":null}},"796ec4916eaf4464b3074a66946271e3":{"model_module":"@jupyter-widgets/controls","model_module_version":"2.0.0","model_name":"HTMLModel","state":{"_dom_classes":[],"_model_module":"@jupyter-widgets/controls","_model_module_version":"2.0.0","_model_name":"HTMLModel","_view_count":null,"_view_module":"@jupyter-widgets/controls","_view_module_version":"2.0.0","_view_name":"HTMLView","description":"","description_allow_html":false,"layout":"IPY_MODEL_6ac9cf5ccdb3453793af6e6c9a0e6462","placeholder":"​","style":"IPY_MODEL_3ed045f047b645aeba7daa902550be1a","tabbable":null,"tooltip":null,"value":"Loading weights: 100%"}},"798bf670d42640feb956c235720fa6b9":{"model_module":"@jupyter-widgets/base","model_module_version":"2.0.0","model_name":"LayoutModel","state":{"_model_module":"@jupyter-widgets/base","_model_module_version":"2.0.0","_model_name":"LayoutModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"2.0.0","_view_name":"LayoutView","align_content":null,"align_items":null,"align_self":null,"border_bottom":null,"border_left":null,"border_right":null,"border_top":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,"padding":null,"right":null,"top":null,"visibility":null,"width":null}},"7d71a3ce39a6412095d4c4cc49784d27":{"model_module":"@jupyter-widgets/base","model_module_version":"2.0.0","model_name":"LayoutModel","state":{"_model_module":"@jupyter-widgets/base","_model_module_version":"2.0.0","_model_name":"LayoutModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"2.0.0","_view_name":"LayoutView","align_content":null,"align_items":null,"align_self":null,"border_bottom":null,"border_left":null,"border_right":null,"border_top":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,"padding":null,"right":null,"top":null,"visibility":null,"width":null}},"7f2e14c43f00489da61d09637d46c3d6":{"model_module":"@jupyter-widgets/base","model_module_version":"2.0.0","model_name":"LayoutModel","state":{"_model_module":"@jupyter-widgets/base","_model_module_version":"2.0.0","_model_name":"LayoutModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"2.0.0","_view_name":"LayoutView","align_content":null,"align_items":null,"align_self":null,"border_bottom":null,"border_left":null,"border_right":null,"border_top":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,"padding":null,"right":null,"top":null,"visibility":null,"width":null}},"81106355d997468f9247851eaed1fede":{"model_module":"@jupyter-widgets/controls","model_module_version":"2.0.0","model_name":"HTMLModel","state":{"_dom_classes":[],"_model_module":"@jupyter-widgets/controls","_model_module_version":"2.0.0","_model_name":"HTMLModel","_view_count":null,"_view_module":"@jupyter-widgets/controls","_view_module_version":"2.0.0","_view_name":"HTMLView","description":"","description_allow_html":false,"layout":"IPY_MODEL_20cc0525bb8148d48269a67fae468f33","placeholder":"​","style":"IPY_MODEL_6ac07627fa00481da08d7a3203519fe4","tabbable":null,"tooltip":null,"value":"Loading weights: 100%"}},"833755703dac4d31a5e46b5af936ef86":{"model_module":"@jupyter-widgets/controls","model_module_version":"2.0.0","model_name":"HBoxModel","state":{"_dom_classes":[],"_model_module":"@jupyter-widgets/controls","_model_module_version":"2.0.0","_model_name":"HBoxModel","_view_count":null,"_view_module":"@jupyter-widgets/controls","_view_module_version":"2.0.0","_view_name":"HBoxView","box_style":"","children":["IPY_MODEL_c7f46600931740318cf3512209ac90a8","IPY_MODEL_3969c1a925ab4b92a040a2b264333f11","IPY_MODEL_323e75fbd544481a8a74870f34fac04a"],"layout":"IPY_MODEL_7d71a3ce39a6412095d4c4cc49784d27","tabbable":null,"tooltip":null}},"838863d1797a4efaa502eeb9bf3df880":{"model_module":"@jupyter-widgets/base","model_module_version":"2.0.0","model_name":"LayoutModel","state":{"_model_module":"@jupyter-widgets/base","_model_module_version":"2.0.0","_model_name":"LayoutModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"2.0.0","_view_name":"LayoutView","align_content":null,"align_items":null,"align_self":null,"border_bottom":null,"border_left":null,"border_right":null,"border_top":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,"padding":null,"right":null,"top":null,"visibility":null,"width":null}},"84600b98653b4bafa438550885c6a30f":{"model_module":"@jupyter-widgets/base","model_module_version":"2.0.0","model_name":"LayoutModel","state":{"_model_module":"@jupyter-widgets/base","_model_module_version":"2.0.0","_model_name":"LayoutModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"2.0.0","_view_name":"LayoutView","align_content":null,"align_items":null,"align_self":null,"border_bottom":null,"border_left":null,"border_right":null,"border_top":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,"padding":null,"right":null,"top":null,"visibility":null,"width":null}},"860820f2929e455f8f226758bdf52547":{"model_module":"@jupyter-widgets/controls","model_module_version":"2.0.0","model_name":"FloatProgressModel","state":{"_dom_classes":[],"_model_module":"@jupyter-widgets/controls","_model_module_version":"2.0.0","_model_name":"FloatProgressModel","_view_count":null,"_view_module":"@jupyter-widgets/controls","_view_module_version":"2.0.0","_view_name":"ProgressView","bar_style":"success","description":"","description_allow_html":false,"layout":"IPY_MODEL_d9cad3d803fe4cada226d10590d82dc4","max":223,"min":0,"orientation":"horizontal","style":"IPY_MODEL_728d6e8ffb934a3487ed4fa3f9924a16","tabbable":null,"tooltip":null,"value":223}},"87301415802145be84b5c2a88d23ad37":{"model_module":"@jupyter-widgets/controls","model_module_version":"2.0.0","model_name":"HBoxModel","state":{"_dom_classes":[],"_model_module":"@jupyter-widgets/controls","_model_module_version":"2.0.0","_model_name":"HBoxModel","_view_count":null,"_view_module":"@jupyter-widgets/controls","_view_module_version":"2.0.0","_view_name":"HBoxView","box_style":"","children":["IPY_MODEL_22b016765aa6459eb44737a943dce141","IPY_MODEL_284bf1ef85d54b1db6721e7e47662932","IPY_MODEL_d497ba1bf41949ef884998a6b8fafe3a"],"layout":"IPY_MODEL_178d45745c894064862998869a18cc77","tabbable":null,"tooltip":null}},"873971522e9b49e4a2572f891f96f748":{"model_module":"@jupyter-widgets/base","model_module_version":"2.0.0","model_name":"LayoutModel","state":{"_model_module":"@jupyter-widgets/base","_model_module_version":"2.0.0","_model_name":"LayoutModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"2.0.0","_view_name":"LayoutView","align_content":null,"align_items":null,"align_self":null,"border_bottom":null,"border_left":null,"border_right":null,"border_top":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,"padding":null,"right":null,"top":null,"visibility":null,"width":null}},"87bbc04364d6498b88719dfbbb5a1ee2":{"model_module":"@jupyter-widgets/base","model_module_version":"2.0.0","model_name":"LayoutModel","state":{"_model_module":"@jupyter-widgets/base","_model_module_version":"2.0.0","_model_name":"LayoutModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"2.0.0","_view_name":"LayoutView","align_content":null,"align_items":null,"align_self":null,"border_bottom":null,"border_left":null,"border_right":null,"border_top":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,"padding":null,"right":null,"top":null,"visibility":null,"width":null}},"88b1a65412ba4bbdab9928e95b2e3fa7":{"model_module":"@jupyter-widgets/controls","model_module_version":"2.0.0","model_name":"HTMLStyleModel","state":{"_model_module":"@jupyter-widgets/controls","_model_module_version":"2.0.0","_model_name":"HTMLStyleModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"2.0.0","_view_name":"StyleView","background":null,"description_width":"","font_size":null,"text_color":null}},"8ab1c62f06a449c2845432cc6b93ebaa":{"model_module":"@jupyter-widgets/base","model_module_version":"2.0.0","model_name":"LayoutModel","state":{"_model_module":"@jupyter-widgets/base","_model_module_version":"2.0.0","_model_name":"LayoutModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"2.0.0","_view_name":"LayoutView","align_content":null,"align_items":null,"align_self":null,"border_bottom":null,"border_left":null,"border_right":null,"border_top":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,"padding":null,"right":null,"top":null,"visibility":null,"width":null}},"8ace7b4df9024e13955a5d5cf0369567":{"model_module":"@jupyter-widgets/base","model_module_version":"2.0.0","model_name":"LayoutModel","state":{"_model_module":"@jupyter-widgets/base","_model_module_version":"2.0.0","_model_name":"LayoutModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"2.0.0","_view_name":"LayoutView","align_content":null,"align_items":null,"align_self":null,"border_bottom":null,"border_left":null,"border_right":null,"border_top":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,"padding":null,"right":null,"top":null,"visibility":null,"width":null}},"8c51b9adcc1145f5bd52f573554fba0c":{"model_module":"@jupyter-widgets/controls","model_module_version":"2.0.0","model_name":"ProgressStyleModel","state":{"_model_module":"@jupyter-widgets/controls","_model_module_version":"2.0.0","_model_name":"ProgressStyleModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"2.0.0","_view_name":"StyleView","bar_color":null,"description_width":""}},"8c54a60ed0f94d2ebe019a4023d7adf5":{"model_module":"@jupyter-widgets/base","model_module_version":"2.0.0","model_name":"LayoutModel","state":{"_model_module":"@jupyter-widgets/base","_model_module_version":"2.0.0","_model_name":"LayoutModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"2.0.0","_view_name":"LayoutView","align_content":null,"align_items":null,"align_self":null,"border_bottom":null,"border_left":null,"border_right":null,"border_top":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,"padding":null,"right":null,"top":null,"visibility":null,"width":null}},"8e5909c1d5b144f1ab499d2eed7224b1":{"model_module":"@jupyter-widgets/controls","model_module_version":"2.0.0","model_name":"ProgressStyleModel","state":{"_model_module":"@jupyter-widgets/controls","_model_module_version":"2.0.0","_model_name":"ProgressStyleModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"2.0.0","_view_name":"StyleView","bar_color":null,"description_width":""}},"902ab029455a4bf9b333e38efeea779c":{"model_module":"@jupyter-widgets/controls","model_module_version":"2.0.0","model_name":"FloatProgressModel","state":{"_dom_classes":[],"_model_module":"@jupyter-widgets/controls","_model_module_version":"2.0.0","_model_name":"FloatProgressModel","_view_count":null,"_view_module":"@jupyter-widgets/controls","_view_module_version":"2.0.0","_view_name":"ProgressView","bar_style":"success","description":"","description_allow_html":false,"layout":"IPY_MODEL_097f38fe4bee45b693ad539c99a885f3","max":223,"min":0,"orientation":"horizontal","style":"IPY_MODEL_256d056407b14b23b312cd1d7b156a89","tabbable":null,"tooltip":null,"value":223}},"91e2955282bd4c7e937acffa9d002d83":{"model_module":"@jupyter-widgets/controls","model_module_version":"2.0.0","model_name":"FloatProgressModel","state":{"_dom_classes":[],"_model_module":"@jupyter-widgets/controls","_model_module_version":"2.0.0","_model_name":"FloatProgressModel","_view_count":null,"_view_module":"@jupyter-widgets/controls","_view_module_version":"2.0.0","_view_name":"ProgressView","bar_style":"success","description":"","description_allow_html":false,"layout":"IPY_MODEL_7742b316c79649f7a8836ddaae3d7f43","max":223,"min":0,"orientation":"horizontal","style":"IPY_MODEL_1cf8fb0e6058400a8422d85078a3dceb","tabbable":null,"tooltip":null,"value":223}},"92fec4288c7944d689729500e2f9d89c":{"model_module":"@jupyter-widgets/controls","model_module_version":"2.0.0","model_name":"HTMLModel","state":{"_dom_classes":[],"_model_module":"@jupyter-widgets/controls","_model_module_version":"2.0.0","_model_name":"HTMLModel","_view_count":null,"_view_module":"@jupyter-widgets/controls","_view_module_version":"2.0.0","_view_name":"HTMLView","description":"","description_allow_html":false,"layout":"IPY_MODEL_77b52ce86ccc41c296f21da8a5045430","placeholder":"​","style":"IPY_MODEL_24a2c9ee2c534933bcbacc462a9c0715","tabbable":null,"tooltip":null,"value":" 223/223 [00:00&lt;00:00, 933.06it/s, Materializing param=layernorm.weight]"}},"949146bcf6a242e898a7ad0a565b0a01":{"model_module":"@jupyter-widgets/controls","model_module_version":"2.0.0","model_name":"HBoxModel","state":{"_dom_classes":[],"_model_module":"@jupyter-widgets/controls","_model_module_version":"2.0.0","_model_name":"HBoxModel","_view_count":null,"_view_module":"@jupyter-widgets/controls","_view_module_version":"2.0.0","_view_name":"HBoxView","box_style":"","children":["IPY_MODEL_6b18934e03b640fca1141636b96a537d","IPY_MODEL_1be9455b98294b1aa892ac5aec5284b4","IPY_MODEL_bf57433ee0d94e6ba0b266e5d5c1d154"],"layout":"IPY_MODEL_c80e5e0587cb461382ffd5e2926b5e85","tabbable":null,"tooltip":null}},"95823f5cdc45425c89ae17ae39861589":{"model_module":"@jupyter-widgets/controls","model_module_version":"2.0.0","model_name":"HTMLModel","state":{"_dom_classes":[],"_model_module":"@jupyter-widgets/controls","_model_module_version":"2.0.0","_model_name":"HTMLModel","_view_count":null,"_view_module":"@jupyter-widgets/controls","_view_module_version":"2.0.0","_view_name":"HTMLView","description":"","description_allow_html":false,"layout":"IPY_MODEL_798bf670d42640feb956c235720fa6b9","placeholder":"​","style":"IPY_MODEL_2701adafc52146269dd958e41356f324","tabbable":null,"tooltip":null,"value":"Loading weights: 100%"}},"9a3c0f2972ca4ff6aa60799e57d1ef83":{"model_module":"@jupyter-widgets/controls","model_module_version":"2.0.0","model_name":"FloatProgressModel","state":{"_dom_classes":[],"_model_module":"@jupyter-widgets/controls","_model_module_version":"2.0.0","_model_name":"FloatProgressModel","_view_count":null,"_view_module":"@jupyter-widgets/controls","_view_module_version":"2.0.0","_view_name":"ProgressView","bar_style":"success","description":"","description_allow_html":false,"layout":"IPY_MODEL_ad77da57c5c447689856ddca2aa2492a","max":223,"min":0,"orientation":"horizontal","style":"IPY_MODEL_3547b8a4b27e48d598c2d0e2ba902c7d","tabbable":null,"tooltip":null,"value":223}},"9bd813a6978942e89293f0c85e0cb936":{"model_module":"@jupyter-widgets/controls","model_module_version":"2.0.0","model_name":"HTMLStyleModel","state":{"_model_module":"@jupyter-widgets/controls","_model_module_version":"2.0.0","_model_name":"HTMLStyleModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"2.0.0","_view_name":"StyleView","background":null,"description_width":"","font_size":null,"text_color":null}},"9cb61ef8f84d4ff797d0bb561126193c":{"model_module":"@jupyter-widgets/controls","model_module_version":"2.0.0","model_name":"HTMLStyleModel","state":{"_model_module":"@jupyter-widgets/controls","_model_module_version":"2.0.0","_model_name":"HTMLStyleModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"2.0.0","_view_name":"StyleView","background":null,"description_width":"","font_size":null,"text_color":null}},"9cba444c200a4a2b93bcfc014b391051":{"model_module":"@jupyter-widgets/controls","model_module_version":"2.0.0","model_name":"HTMLStyleModel","state":{"_model_module":"@jupyter-widgets/controls","_model_module_version":"2.0.0","_model_name":"HTMLStyleModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"2.0.0","_view_name":"StyleView","background":null,"description_width":"","font_size":null,"text_color":null}},"9fcf60914a9b4a9da5dd7edb028d7fe5":{"model_module":"@jupyter-widgets/controls","model_module_version":"2.0.0","model_name":"HTMLStyleModel","state":{"_model_module":"@jupyter-widgets/controls","_model_module_version":"2.0.0","_model_name":"HTMLStyleModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"2.0.0","_view_name":"StyleView","background":null,"description_width":"","font_size":null,"text_color":null}},"a2579f7038b0418f91e2e75aacd6df43":{"model_module":"@jupyter-widgets/base","model_module_version":"2.0.0","model_name":"LayoutModel","state":{"_model_module":"@jupyter-widgets/base","_model_module_version":"2.0.0","_model_name":"LayoutModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"2.0.0","_view_name":"LayoutView","align_content":null,"align_items":null,"align_self":null,"border_bottom":null,"border_left":null,"border_right":null,"border_top":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,"padding":null,"right":null,"top":null,"visibility":null,"width":null}},"a350948ffbfb445599f1046997b0bb34":{"model_module":"@jupyter-widgets/controls","model_module_version":"2.0.0","model_name":"HTMLModel","state":{"_dom_classes":[],"_model_module":"@jupyter-widgets/controls","_model_module_version":"2.0.0","_model_name":"HTMLModel","_view_count":null,"_view_module":"@jupyter-widgets/controls","_view_module_version":"2.0.0","_view_name":"HTMLView","description":"","description_allow_html":false,"layout":"IPY_MODEL_5683c4fd82ce4a7d82541fdc553bd4c4","placeholder":"​","style":"IPY_MODEL_e4f49138cced4ee1a75f7057e0e17417","tabbable":null,"tooltip":null,"value":"Loading weights: 100%"}},"a623bc44dcc64940b95367b8673b0241":{"model_module":"@jupyter-widgets/controls","model_module_version":"2.0.0","model_name":"HTMLModel","state":{"_dom_classes":[],"_model_module":"@jupyter-widgets/controls","_model_module_version":"2.0.0","_model_name":"HTMLModel","_view_count":null,"_view_module":"@jupyter-widgets/controls","_view_module_version":"2.0.0","_view_name":"HTMLView","description":"","description_allow_html":false,"layout":"IPY_MODEL_4b864b78db214512ad124047c4d9ef77","placeholder":"​","style":"IPY_MODEL_3e4269f045144ca2957d2586db67ec8c","tabbable":null,"tooltip":null,"value":" 223/223 [00:00&lt;00:00, 946.55it/s, Materializing param=layernorm.weight]"}},"aa2f2f8a0a4f465daa9643f6b05cfb5a":{"model_module":"@jupyter-widgets/base","model_module_version":"2.0.0","model_name":"LayoutModel","state":{"_model_module":"@jupyter-widgets/base","_model_module_version":"2.0.0","_model_name":"LayoutModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"2.0.0","_view_name":"LayoutView","align_content":null,"align_items":null,"align_self":null,"border_bottom":null,"border_left":null,"border_right":null,"border_top":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,"padding":null,"right":null,"top":null,"visibility":null,"width":null}},"aa8043b4053a42cfb63b9030736e7dcd":{"model_module":"@jupyter-widgets/controls","model_module_version":"2.0.0","model_name":"HTMLStyleModel","state":{"_model_module":"@jupyter-widgets/controls","_model_module_version":"2.0.0","_model_name":"HTMLStyleModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"2.0.0","_view_name":"StyleView","background":null,"description_width":"","font_size":null,"text_color":null}},"acec9ece2daf400a996ef7c00b92ca85":{"model_module":"@jupyter-widgets/base","model_module_version":"2.0.0","model_name":"LayoutModel","state":{"_model_module":"@jupyter-widgets/base","_model_module_version":"2.0.0","_model_name":"LayoutModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"2.0.0","_view_name":"LayoutView","align_content":null,"align_items":null,"align_self":null,"border_bottom":null,"border_left":null,"border_right":null,"border_top":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,"padding":null,"right":null,"top":null,"visibility":null,"width":null}},"ad77da57c5c447689856ddca2aa2492a":{"model_module":"@jupyter-widgets/base","model_module_version":"2.0.0","model_name":"LayoutModel","state":{"_model_module":"@jupyter-widgets/base","_model_module_version":"2.0.0","_model_name":"LayoutModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"2.0.0","_view_name":"LayoutView","align_content":null,"align_items":null,"align_self":null,"border_bottom":null,"border_left":null,"border_right":null,"border_top":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,"padding":null,"right":null,"top":null,"visibility":null,"width":null}},"adb682d01f8c4879b09ba78b4a724adc":{"model_module":"@jupyter-widgets/controls","model_module_version":"2.0.0","model_name":"HBoxModel","state":{"_dom_classes":[],"_model_module":"@jupyter-widgets/controls","_model_module_version":"2.0.0","_model_name":"HBoxModel","_view_count":null,"_view_module":"@jupyter-widgets/controls","_view_module_version":"2.0.0","_view_name":"HBoxView","box_style":"","children":["IPY_MODEL_796ec4916eaf4464b3074a66946271e3","IPY_MODEL_0d988e81acbf4b3599fdc66f4fccc918","IPY_MODEL_59b283b32aac44ae8a242061b3d38fde"],"layout":"IPY_MODEL_acec9ece2daf400a996ef7c00b92ca85","tabbable":null,"tooltip":null}},"af6144783a5c4f1f92782b8644865ec4":{"model_module":"@jupyter-widgets/controls","model_module_version":"2.0.0","model_name":"HTMLStyleModel","state":{"_model_module":"@jupyter-widgets/controls","_model_module_version":"2.0.0","_model_name":"HTMLStyleModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"2.0.0","_view_name":"StyleView","background":null,"description_width":"","font_size":null,"text_color":null}},"b1cb8240f1f14d9cafd85b7caecf851a":{"model_module":"@jupyter-widgets/base","model_module_version":"2.0.0","model_name":"LayoutModel","state":{"_model_module":"@jupyter-widgets/base","_model_module_version":"2.0.0","_model_name":"LayoutModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"2.0.0","_view_name":"LayoutView","align_content":null,"align_items":null,"align_self":null,"border_bottom":null,"border_left":null,"border_right":null,"border_top":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,"padding":null,"right":null,"top":null,"visibility":null,"width":null}},"b45d5039b2c44e68b1fb6b262e7f7336":{"model_module":"@jupyter-widgets/controls","model_module_version":"2.0.0","model_name":"ProgressStyleModel","state":{"_model_module":"@jupyter-widgets/controls","_model_module_version":"2.0.0","_model_name":"ProgressStyleModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"2.0.0","_view_name":"StyleView","bar_color":null,"description_width":""}},"b4a5e462e4fd4fa3abc742b4691b45fb":{"model_module":"@jupyter-widgets/controls","model_module_version":"2.0.0","model_name":"ProgressStyleModel","state":{"_model_module":"@jupyter-widgets/controls","_model_module_version":"2.0.0","_model_name":"ProgressStyleModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"2.0.0","_view_name":"StyleView","bar_color":null,"description_width":""}},"b57fa6be90a94fbebe11e6fb09cc91a1":{"model_module":"@jupyter-widgets/base","model_module_version":"2.0.0","model_name":"LayoutModel","state":{"_model_module":"@jupyter-widgets/base","_model_module_version":"2.0.0","_model_name":"LayoutModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"2.0.0","_view_name":"LayoutView","align_content":null,"align_items":null,"align_self":null,"border_bottom":null,"border_left":null,"border_right":null,"border_top":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,"padding":null,"right":null,"top":null,"visibility":null,"width":null}},"b6fd0efdf4834243bde4a883825fe2d4":{"model_module":"@jupyter-widgets/base","model_module_version":"2.0.0","model_name":"LayoutModel","state":{"_model_module":"@jupyter-widgets/base","_model_module_version":"2.0.0","_model_name":"LayoutModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"2.0.0","_view_name":"LayoutView","align_content":null,"align_items":null,"align_self":null,"border_bottom":null,"border_left":null,"border_right":null,"border_top":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,"padding":null,"right":null,"top":null,"visibility":null,"width":null}},"b7b595332fe34e3890f0f47cc794cda3":{"model_module":"@jupyter-widgets/controls","model_module_version":"2.0.0","model_name":"FloatProgressModel","state":{"_dom_classes":[],"_model_module":"@jupyter-widgets/controls","_model_module_version":"2.0.0","_model_name":"FloatProgressModel","_view_count":null,"_view_module":"@jupyter-widgets/controls","_view_module_version":"2.0.0","_view_name":"ProgressView","bar_style":"success","description":"","description_allow_html":false,"layout":"IPY_MODEL_fa4079edbfc34eb19c7dfd906d9e2821","max":223,"min":0,"orientation":"horizontal","style":"IPY_MODEL_b4a5e462e4fd4fa3abc742b4691b45fb","tabbable":null,"tooltip":null,"value":223}},"b97079b20e3f4c7aba9f056f6052da06":{"model_module":"@jupyter-widgets/controls","model_module_version":"2.0.0","model_name":"HTMLModel","state":{"_dom_classes":[],"_model_module":"@jupyter-widgets/controls","_model_module_version":"2.0.0","_model_name":"HTMLModel","_view_count":null,"_view_module":"@jupyter-widgets/controls","_view_module_version":"2.0.0","_view_name":"HTMLView","description":"","description_allow_html":false,"layout":"IPY_MODEL_0ddd72b204b2460f92fe7b22b7b2fd5d","placeholder":"​","style":"IPY_MODEL_9cba444c200a4a2b93bcfc014b391051","tabbable":null,"tooltip":null,"value":" 223/223 [00:00&lt;00:00, 927.86it/s, Materializing param=layernorm.weight]"}},"bad3c0fc39fa4decae455ebed98d090f":{"model_module":"@jupyter-widgets/base","model_module_version":"2.0.0","model_name":"LayoutModel","state":{"_model_module":"@jupyter-widgets/base","_model_module_version":"2.0.0","_model_name":"LayoutModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"2.0.0","_view_name":"LayoutView","align_content":null,"align_items":null,"align_self":null,"border_bottom":null,"border_left":null,"border_right":null,"border_top":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,"padding":null,"right":null,"top":null,"visibility":null,"width":null}},"bca6da88486f462a8ab292bcfbb64f8c":{"model_module":"@jupyter-widgets/base","model_module_version":"2.0.0","model_name":"LayoutModel","state":{"_model_module":"@jupyter-widgets/base","_model_module_version":"2.0.0","_model_name":"LayoutModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"2.0.0","_view_name":"LayoutView","align_content":null,"align_items":null,"align_self":null,"border_bottom":null,"border_left":null,"border_right":null,"border_top":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,"padding":null,"right":null,"top":null,"visibility":null,"width":null}},"be813dd7f81d411582b5507cb5861b56":{"model_module":"@jupyter-widgets/controls","model_module_version":"2.0.0","model_name":"ProgressStyleModel","state":{"_model_module":"@jupyter-widgets/controls","_model_module_version":"2.0.0","_model_name":"ProgressStyleModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"2.0.0","_view_name":"StyleView","bar_color":null,"description_width":""}},"beded1b180564b478a4b4242ac0fe7da":{"model_module":"@jupyter-widgets/controls","model_module_version":"2.0.0","model_name":"HTMLStyleModel","state":{"_model_module":"@jupyter-widgets/controls","_model_module_version":"2.0.0","_model_name":"HTMLStyleModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"2.0.0","_view_name":"StyleView","background":null,"description_width":"","font_size":null,"text_color":null}},"bf57433ee0d94e6ba0b266e5d5c1d154":{"model_module":"@jupyter-widgets/controls","model_module_version":"2.0.0","model_name":"HTMLModel","state":{"_dom_classes":[],"_model_module":"@jupyter-widgets/controls","_model_module_version":"2.0.0","_model_name":"HTMLModel","_view_count":null,"_view_module":"@jupyter-widgets/controls","_view_module_version":"2.0.0","_view_name":"HTMLView","description":"","description_allow_html":false,"layout":"IPY_MODEL_100a57bd2b0c4ba7b986727286c86e68","placeholder":"​","style":"IPY_MODEL_72a44a215271488ab5aa83e395c944c8","tabbable":null,"tooltip":null,"value":" 223/223 [00:00&lt;00:00, 1016.04it/s, Materializing param=layernorm.weight]"}},"c05abb35c11a47dd97c2074f45402d9c":{"model_module":"@jupyter-widgets/base","model_module_version":"2.0.0","model_name":"LayoutModel","state":{"_model_module":"@jupyter-widgets/base","_model_module_version":"2.0.0","_model_name":"LayoutModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"2.0.0","_view_name":"LayoutView","align_content":null,"align_items":null,"align_self":null,"border_bottom":null,"border_left":null,"border_right":null,"border_top":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,"padding":null,"right":null,"top":null,"visibility":null,"width":null}},"c0968e71322b4df6afdc47dc4d36671c":{"model_module":"@jupyter-widgets/controls","model_module_version":"2.0.0","model_name":"HTMLModel","state":{"_dom_classes":[],"_model_module":"@jupyter-widgets/controls","_model_module_version":"2.0.0","_model_name":"HTMLModel","_view_count":null,"_view_module":"@jupyter-widgets/controls","_view_module_version":"2.0.0","_view_name":"HTMLView","description":"","description_allow_html":false,"layout":"IPY_MODEL_873971522e9b49e4a2572f891f96f748","placeholder":"​","style":"IPY_MODEL_1dd8bca50adf4f0f96a44655905acb54","tabbable":null,"tooltip":null,"value":"Loading weights: 100%"}},"c24a4be6b9be481db2080df2b5706714":{"model_module":"@jupyter-widgets/base","model_module_version":"2.0.0","model_name":"LayoutModel","state":{"_model_module":"@jupyter-widgets/base","_model_module_version":"2.0.0","_model_name":"LayoutModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"2.0.0","_view_name":"LayoutView","align_content":null,"align_items":null,"align_self":null,"border_bottom":null,"border_left":null,"border_right":null,"border_top":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,"padding":null,"right":null,"top":null,"visibility":null,"width":null}},"c4f22ce0e2144727b6c2df3615eaad01":{"model_module":"@jupyter-widgets/controls","model_module_version":"2.0.0","model_name":"HBoxModel","state":{"_dom_classes":[],"_model_module":"@jupyter-widgets/controls","_model_module_version":"2.0.0","_model_name":"HBoxModel","_view_count":null,"_view_module":"@jupyter-widgets/controls","_view_module_version":"2.0.0","_view_name":"HBoxView","box_style":"","children":["IPY_MODEL_09a748599f8b410eac2e1ac51225ee2d","IPY_MODEL_860820f2929e455f8f226758bdf52547","IPY_MODEL_92fec4288c7944d689729500e2f9d89c"],"layout":"IPY_MODEL_84600b98653b4bafa438550885c6a30f","tabbable":null,"tooltip":null}},"c508a3b8c5a44b2e992f82012db5697a":{"model_module":"@jupyter-widgets/base","model_module_version":"2.0.0","model_name":"LayoutModel","state":{"_model_module":"@jupyter-widgets/base","_model_module_version":"2.0.0","_model_name":"LayoutModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"2.0.0","_view_name":"LayoutView","align_content":null,"align_items":null,"align_self":null,"border_bottom":null,"border_left":null,"border_right":null,"border_top":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,"padding":null,"right":null,"top":null,"visibility":null,"width":null}},"c56bc19b2c9e487e9c5440a1224e719e":{"model_module":"@jupyter-widgets/controls","model_module_version":"2.0.0","model_name":"HTMLStyleModel","state":{"_model_module":"@jupyter-widgets/controls","_model_module_version":"2.0.0","_model_name":"HTMLStyleModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"2.0.0","_view_name":"StyleView","background":null,"description_width":"","font_size":null,"text_color":null}},"c7f46600931740318cf3512209ac90a8":{"model_module":"@jupyter-widgets/controls","model_module_version":"2.0.0","model_name":"HTMLModel","state":{"_dom_classes":[],"_model_module":"@jupyter-widgets/controls","_model_module_version":"2.0.0","_model_name":"HTMLModel","_view_count":null,"_view_module":"@jupyter-widgets/controls","_view_module_version":"2.0.0","_view_name":"HTMLView","description":"","description_allow_html":false,"layout":"IPY_MODEL_629b547c39d64d38aa8831d29ee55bb7","placeholder":"​","style":"IPY_MODEL_eac286c8910a4554bb7eef99952a9978","tabbable":null,"tooltip":null,"value":"Loading weights: 100%"}},"c80e5e0587cb461382ffd5e2926b5e85":{"model_module":"@jupyter-widgets/base","model_module_version":"2.0.0","model_name":"LayoutModel","state":{"_model_module":"@jupyter-widgets/base","_model_module_version":"2.0.0","_model_name":"LayoutModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"2.0.0","_view_name":"LayoutView","align_content":null,"align_items":null,"align_self":null,"border_bottom":null,"border_left":null,"border_right":null,"border_top":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,"padding":null,"right":null,"top":null,"visibility":null,"width":null}},"c84d740736f84b3fa1eefeec86646109":{"model_module":"@jupyter-widgets/controls","model_module_version":"2.0.0","model_name":"HTMLModel","state":{"_dom_classes":[],"_model_module":"@jupyter-widgets/controls","_model_module_version":"2.0.0","_model_name":"HTMLModel","_view_count":null,"_view_module":"@jupyter-widgets/controls","_view_module_version":"2.0.0","_view_name":"HTMLView","description":"","description_allow_html":false,"layout":"IPY_MODEL_4dd09d356fc749e3aaf294599a863fd3","placeholder":"​","style":"IPY_MODEL_098969175b144ef19cd9b9b40e91843b","tabbable":null,"tooltip":null,"value":"Loading weights: 100%"}},"c89850ba20434fc4b1cca01c855078ad":{"model_module":"@jupyter-widgets/controls","model_module_version":"2.0.0","model_name":"ProgressStyleModel","state":{"_model_module":"@jupyter-widgets/controls","_model_module_version":"2.0.0","_model_name":"ProgressStyleModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"2.0.0","_view_name":"StyleView","bar_color":null,"description_width":""}},"ca7ba678f3144190b98135538c588c62":{"model_module":"@jupyter-widgets/controls","model_module_version":"2.0.0","model_name":"HTMLStyleModel","state":{"_model_module":"@jupyter-widgets/controls","_model_module_version":"2.0.0","_model_name":"HTMLStyleModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"2.0.0","_view_name":"StyleView","background":null,"description_width":"","font_size":null,"text_color":null}},"cb12ae18a2374f60a175cceec31934bb":{"model_module":"@jupyter-widgets/controls","model_module_version":"2.0.0","model_name":"HTMLModel","state":{"_dom_classes":[],"_model_module":"@jupyter-widgets/controls","_model_module_version":"2.0.0","_model_name":"HTMLModel","_view_count":null,"_view_module":"@jupyter-widgets/controls","_view_module_version":"2.0.0","_view_name":"HTMLView","description":"","description_allow_html":false,"layout":"IPY_MODEL_15336796bcfa49c287b6250e5971fdbb","placeholder":"​","style":"IPY_MODEL_3608153b936d496999bae60b943183a9","tabbable":null,"tooltip":null,"value":" 223/223 [00:00&lt;00:00, 999.22it/s, Materializing param=layernorm.weight]"}},"ceb6d35a8b5348a293d7f8d6acac5ec7":{"model_module":"@jupyter-widgets/controls","model_module_version":"2.0.0","model_name":"HTMLModel","state":{"_dom_classes":[],"_model_module":"@jupyter-widgets/controls","_model_module_version":"2.0.0","_model_name":"HTMLModel","_view_count":null,"_view_module":"@jupyter-widgets/controls","_view_module_version":"2.0.0","_view_name":"HTMLView","description":"","description_allow_html":false,"layout":"IPY_MODEL_7f2e14c43f00489da61d09637d46c3d6","placeholder":"​","style":"IPY_MODEL_ca7ba678f3144190b98135538c588c62","tabbable":null,"tooltip":null,"value":"Loading weights: 100%"}},"cec6d9a8487e4e7f98e904a8ebe63121":{"model_module":"@jupyter-widgets/controls","model_module_version":"2.0.0","model_name":"FloatProgressModel","state":{"_dom_classes":[],"_model_module":"@jupyter-widgets/controls","_model_module_version":"2.0.0","_model_name":"FloatProgressModel","_view_count":null,"_view_module":"@jupyter-widgets/controls","_view_module_version":"2.0.0","_view_name":"ProgressView","bar_style":"success","description":"","description_allow_html":false,"layout":"IPY_MODEL_13669aa7aefb4b6491bda1d1969b4670","max":223,"min":0,"orientation":"horizontal","style":"IPY_MODEL_b45d5039b2c44e68b1fb6b262e7f7336","tabbable":null,"tooltip":null,"value":223}},"cecae18ee7164ae0a8a3cfcd37a22c26":{"model_module":"@jupyter-widgets/controls","model_module_version":"2.0.0","model_name":"FloatProgressModel","state":{"_dom_classes":[],"_model_module":"@jupyter-widgets/controls","_model_module_version":"2.0.0","_model_name":"FloatProgressModel","_view_count":null,"_view_module":"@jupyter-widgets/controls","_view_module_version":"2.0.0","_view_name":"ProgressView","bar_style":"success","description":"","description_allow_html":false,"layout":"IPY_MODEL_29b678554c4b4726814fab0c61fc5ff0","max":223,"min":0,"orientation":"horizontal","style":"IPY_MODEL_c89850ba20434fc4b1cca01c855078ad","tabbable":null,"tooltip":null,"value":223}},"cf685555d2654c57a1c0dbc81449b69e":{"model_module":"@jupyter-widgets/base","model_module_version":"2.0.0","model_name":"LayoutModel","state":{"_model_module":"@jupyter-widgets/base","_model_module_version":"2.0.0","_model_name":"LayoutModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"2.0.0","_view_name":"LayoutView","align_content":null,"align_items":null,"align_self":null,"border_bottom":null,"border_left":null,"border_right":null,"border_top":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,"padding":null,"right":null,"top":null,"visibility":null,"width":null}},"cf708c198c384a94bcf5d1ba473fc6e3":{"model_module":"@jupyter-widgets/controls","model_module_version":"2.0.0","model_name":"HTMLStyleModel","state":{"_model_module":"@jupyter-widgets/controls","_model_module_version":"2.0.0","_model_name":"HTMLStyleModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"2.0.0","_view_name":"StyleView","background":null,"description_width":"","font_size":null,"text_color":null}},"cf95799c368843c7819f4d8135d72f4c":{"model_module":"@jupyter-widgets/controls","model_module_version":"2.0.0","model_name":"HTMLStyleModel","state":{"_model_module":"@jupyter-widgets/controls","_model_module_version":"2.0.0","_model_name":"HTMLStyleModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"2.0.0","_view_name":"StyleView","background":null,"description_width":"","font_size":null,"text_color":null}},"cfe40aa13ebb44b2a733c125adfa51de":{"model_module":"@jupyter-widgets/controls","model_module_version":"2.0.0","model_name":"HTMLModel","state":{"_dom_classes":[],"_model_module":"@jupyter-widgets/controls","_model_module_version":"2.0.0","_model_name":"HTMLModel","_view_count":null,"_view_module":"@jupyter-widgets/controls","_view_module_version":"2.0.0","_view_name":"HTMLView","description":"","description_allow_html":false,"layout":"IPY_MODEL_aa2f2f8a0a4f465daa9643f6b05cfb5a","placeholder":"​","style":"IPY_MODEL_289cdbef7d7f45a7979c6f7893264ab7","tabbable":null,"tooltip":null,"value":" 223/223 [00:00&lt;00:00, 925.90it/s, Materializing param=layernorm.weight]"}},"d497ba1bf41949ef884998a6b8fafe3a":{"model_module":"@jupyter-widgets/controls","model_module_version":"2.0.0","model_name":"HTMLModel","state":{"_dom_classes":[],"_model_module":"@jupyter-widgets/controls","_model_module_version":"2.0.0","_model_name":"HTMLModel","_view_count":null,"_view_module":"@jupyter-widgets/controls","_view_module_version":"2.0.0","_view_name":"HTMLView","description":"","description_allow_html":false,"layout":"IPY_MODEL_676aa0a43ca34c26b96b3713e02c3fe9","placeholder":"​","style":"IPY_MODEL_03d0f5c765cf4114988f79d5be3aabb9","tabbable":null,"tooltip":null,"value":" 223/223 [00:00&lt;00:00, 889.09it/s, Materializing param=layernorm.weight]"}},"d9cad3d803fe4cada226d10590d82dc4":{"model_module":"@jupyter-widgets/base","model_module_version":"2.0.0","model_name":"LayoutModel","state":{"_model_module":"@jupyter-widgets/base","_model_module_version":"2.0.0","_model_name":"LayoutModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"2.0.0","_view_name":"LayoutView","align_content":null,"align_items":null,"align_self":null,"border_bottom":null,"border_left":null,"border_right":null,"border_top":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,"padding":null,"right":null,"top":null,"visibility":null,"width":null}},"da139d630cce448bba7a7189114d3b2d":{"model_module":"@jupyter-widgets/controls","model_module_version":"2.0.0","model_name":"ProgressStyleModel","state":{"_model_module":"@jupyter-widgets/controls","_model_module_version":"2.0.0","_model_name":"ProgressStyleModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"2.0.0","_view_name":"StyleView","bar_color":null,"description_width":""}},"da5a55252fa2435ab79f7e6e91284196":{"model_module":"@jupyter-widgets/controls","model_module_version":"2.0.0","model_name":"FloatProgressModel","state":{"_dom_classes":[],"_model_module":"@jupyter-widgets/controls","_model_module_version":"2.0.0","_model_name":"FloatProgressModel","_view_count":null,"_view_module":"@jupyter-widgets/controls","_view_module_version":"2.0.0","_view_name":"ProgressView","bar_style":"success","description":"","description_allow_html":false,"layout":"IPY_MODEL_746b385de3344b63921ca631de47f4d2","max":223,"min":0,"orientation":"horizontal","style":"IPY_MODEL_625b1f5fc81f435ba8bfbeb1201e041a","tabbable":null,"tooltip":null,"value":223}},"db24d2f392fb4f60b55c9a9afb75793a":{"model_module":"@jupyter-widgets/controls","model_module_version":"2.0.0","model_name":"HBoxModel","state":{"_dom_classes":[],"_model_module":"@jupyter-widgets/controls","_model_module_version":"2.0.0","_model_name":"HBoxModel","_view_count":null,"_view_module":"@jupyter-widgets/controls","_view_module_version":"2.0.0","_view_name":"HBoxView","box_style":"","children":["IPY_MODEL_e98db8959e38422db490b5167295e0ee","IPY_MODEL_20da54e5b717403c8a91689ff903fd06","IPY_MODEL_3deb29d8ab2943f6b588e771e48a5ebe"],"layout":"IPY_MODEL_7932c89ad60c480b889926e494b893b4","tabbable":null,"tooltip":null}},"dfe2a8ff305c4ffa943f4d3e026da100":{"model_module":"@jupyter-widgets/controls","model_module_version":"2.0.0","model_name":"HTMLModel","state":{"_dom_classes":[],"_model_module":"@jupyter-widgets/controls","_model_module_version":"2.0.0","_model_name":"HTMLModel","_view_count":null,"_view_module":"@jupyter-widgets/controls","_view_module_version":"2.0.0","_view_name":"HTMLView","description":"","description_allow_html":false,"layout":"IPY_MODEL_fb981c38f74c448e8b74d8dba2759288","placeholder":"​","style":"IPY_MODEL_e3ecd26922cf43d68842a228b77d6927","tabbable":null,"tooltip":null,"value":" 223/223 [00:00&lt;00:00, 1047.79it/s, Materializing param=layernorm.weight]"}},"e0091f2b45c94c9ab3685da4292bde27":{"model_module":"@jupyter-widgets/base","model_module_version":"2.0.0","model_name":"LayoutModel","state":{"_model_module":"@jupyter-widgets/base","_model_module_version":"2.0.0","_model_name":"LayoutModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"2.0.0","_view_name":"LayoutView","align_content":null,"align_items":null,"align_self":null,"border_bottom":null,"border_left":null,"border_right":null,"border_top":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,"padding":null,"right":null,"top":null,"visibility":null,"width":null}},"e209623efd8b4d0ab911a0e2d57059b7":{"model_module":"@jupyter-widgets/controls","model_module_version":"2.0.0","model_name":"HBoxModel","state":{"_dom_classes":[],"_model_module":"@jupyter-widgets/controls","_model_module_version":"2.0.0","_model_name":"HBoxModel","_view_count":null,"_view_module":"@jupyter-widgets/controls","_view_module_version":"2.0.0","_view_name":"HBoxView","box_style":"","children":["IPY_MODEL_a350948ffbfb445599f1046997b0bb34","IPY_MODEL_05fa399345c74510b5f2b2b19d7d0718","IPY_MODEL_74fd0d6b8c224ed3acf9f5a693cfbf6f"],"layout":"IPY_MODEL_40a1ff147d3c4bf3ad2837e43955b9bf","tabbable":null,"tooltip":null}},"e3b3a17026e94440adebda3bdb46bfa8":{"model_module":"@jupyter-widgets/base","model_module_version":"2.0.0","model_name":"LayoutModel","state":{"_model_module":"@jupyter-widgets/base","_model_module_version":"2.0.0","_model_name":"LayoutModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"2.0.0","_view_name":"LayoutView","align_content":null,"align_items":null,"align_self":null,"border_bottom":null,"border_left":null,"border_right":null,"border_top":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,"padding":null,"right":null,"top":null,"visibility":null,"width":null}},"e3e22b182f544755afb4a00f3f8f2653":{"model_module":"@jupyter-widgets/controls","model_module_version":"2.0.0","model_name":"FloatProgressModel","state":{"_dom_classes":[],"_model_module":"@jupyter-widgets/controls","_model_module_version":"2.0.0","_model_name":"FloatProgressModel","_view_count":null,"_view_module":"@jupyter-widgets/controls","_view_module_version":"2.0.0","_view_name":"ProgressView","bar_style":"success","description":"","description_allow_html":false,"layout":"IPY_MODEL_e0091f2b45c94c9ab3685da4292bde27","max":223,"min":0,"orientation":"horizontal","style":"IPY_MODEL_f6ebe2c9774b4559b5dca364ab692ed3","tabbable":null,"tooltip":null,"value":223}},"e3ecd26922cf43d68842a228b77d6927":{"model_module":"@jupyter-widgets/controls","model_module_version":"2.0.0","model_name":"HTMLStyleModel","state":{"_model_module":"@jupyter-widgets/controls","_model_module_version":"2.0.0","_model_name":"HTMLStyleModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"2.0.0","_view_name":"StyleView","background":null,"description_width":"","font_size":null,"text_color":null}},"e48a4a5241f44a3cb8232766f25c6740":{"model_module":"@jupyter-widgets/base","model_module_version":"2.0.0","model_name":"LayoutModel","state":{"_model_module":"@jupyter-widgets/base","_model_module_version":"2.0.0","_model_name":"LayoutModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"2.0.0","_view_name":"LayoutView","align_content":null,"align_items":null,"align_self":null,"border_bottom":null,"border_left":null,"border_right":null,"border_top":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,"padding":null,"right":null,"top":null,"visibility":null,"width":null}},"e4f49138cced4ee1a75f7057e0e17417":{"model_module":"@jupyter-widgets/controls","model_module_version":"2.0.0","model_name":"HTMLStyleModel","state":{"_model_module":"@jupyter-widgets/controls","_model_module_version":"2.0.0","_model_name":"HTMLStyleModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"2.0.0","_view_name":"StyleView","background":null,"description_width":"","font_size":null,"text_color":null}},"e6b7032fe702492083ae47fc680824bf":{"model_module":"@jupyter-widgets/base","model_module_version":"2.0.0","model_name":"LayoutModel","state":{"_model_module":"@jupyter-widgets/base","_model_module_version":"2.0.0","_model_name":"LayoutModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"2.0.0","_view_name":"LayoutView","align_content":null,"align_items":null,"align_self":null,"border_bottom":null,"border_left":null,"border_right":null,"border_top":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,"padding":null,"right":null,"top":null,"visibility":null,"width":null}},"e6ebfeb5c6834c2aa19208daff99ff46":{"model_module":"@jupyter-widgets/controls","model_module_version":"2.0.0","model_name":"HTMLModel","state":{"_dom_classes":[],"_model_module":"@jupyter-widgets/controls","_model_module_version":"2.0.0","_model_name":"HTMLModel","_view_count":null,"_view_module":"@jupyter-widgets/controls","_view_module_version":"2.0.0","_view_name":"HTMLView","description":"","description_allow_html":false,"layout":"IPY_MODEL_bca6da88486f462a8ab292bcfbb64f8c","placeholder":"​","style":"IPY_MODEL_14412a251c754e029df3ab84ac7bf8cc","tabbable":null,"tooltip":null,"value":" 223/223 [00:00&lt;00:00, 959.49it/s, Materializing param=layernorm.weight]"}},"e98db8959e38422db490b5167295e0ee":{"model_module":"@jupyter-widgets/controls","model_module_version":"2.0.0","model_name":"HTMLModel","state":{"_dom_classes":[],"_model_module":"@jupyter-widgets/controls","_model_module_version":"2.0.0","_model_name":"HTMLModel","_view_count":null,"_view_module":"@jupyter-widgets/controls","_view_module_version":"2.0.0","_view_name":"HTMLView","description":"","description_allow_html":false,"layout":"IPY_MODEL_78995e9932cf407c91b7bf70cbfd1a80","placeholder":"​","style":"IPY_MODEL_0dcd5ee7fc8543d0b3f41d02d6b31e14","tabbable":null,"tooltip":null,"value":"Loading weights: 100%"}},"eac286c8910a4554bb7eef99952a9978":{"model_module":"@jupyter-widgets/controls","model_module_version":"2.0.0","model_name":"HTMLStyleModel","state":{"_model_module":"@jupyter-widgets/controls","_model_module_version":"2.0.0","_model_name":"HTMLStyleModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"2.0.0","_view_name":"StyleView","background":null,"description_width":"","font_size":null,"text_color":null}},"eb755d649b474719803ebc0363c5c816":{"model_module":"@jupyter-widgets/base","model_module_version":"2.0.0","model_name":"LayoutModel","state":{"_model_module":"@jupyter-widgets/base","_model_module_version":"2.0.0","_model_name":"LayoutModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"2.0.0","_view_name":"LayoutView","align_content":null,"align_items":null,"align_self":null,"border_bottom":null,"border_left":null,"border_right":null,"border_top":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,"padding":null,"right":null,"top":null,"visibility":null,"width":null}},"ec0355774b1a4c259c63d19eba43bff8":{"model_module":"@jupyter-widgets/controls","model_module_version":"2.0.0","model_name":"HTMLModel","state":{"_dom_classes":[],"_model_module":"@jupyter-widgets/controls","_model_module_version":"2.0.0","_model_name":"HTMLModel","_view_count":null,"_view_module":"@jupyter-widgets/controls","_view_module_version":"2.0.0","_view_name":"HTMLView","description":"","description_allow_html":false,"layout":"IPY_MODEL_1f693035528d448daffe4f9860c0d3db","placeholder":"​","style":"IPY_MODEL_9bd813a6978942e89293f0c85e0cb936","tabbable":null,"tooltip":null,"value":"Loading weights: 100%"}},"ec65a83566d04c519826e56c566a9e23":{"model_module":"@jupyter-widgets/controls","model_module_version":"2.0.0","model_name":"HTMLStyleModel","state":{"_model_module":"@jupyter-widgets/controls","_model_module_version":"2.0.0","_model_name":"HTMLStyleModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"2.0.0","_view_name":"StyleView","background":null,"description_width":"","font_size":null,"text_color":null}},"ede35c9a909f4dd6be6d17a11c8cd320":{"model_module":"@jupyter-widgets/base","model_module_version":"2.0.0","model_name":"LayoutModel","state":{"_model_module":"@jupyter-widgets/base","_model_module_version":"2.0.0","_model_name":"LayoutModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"2.0.0","_view_name":"LayoutView","align_content":null,"align_items":null,"align_self":null,"border_bottom":null,"border_left":null,"border_right":null,"border_top":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,"padding":null,"right":null,"top":null,"visibility":null,"width":null}},"f3c8711ed1f941b79b5a57cce49a6ce7":{"model_module":"@jupyter-widgets/controls","model_module_version":"2.0.0","model_name":"HBoxModel","state":{"_dom_classes":[],"_model_module":"@jupyter-widgets/controls","_model_module_version":"2.0.0","_model_name":"HBoxModel","_view_count":null,"_view_module":"@jupyter-widgets/controls","_view_module_version":"2.0.0","_view_name":"HBoxView","box_style":"","children":["IPY_MODEL_c0968e71322b4df6afdc47dc4d36671c","IPY_MODEL_4ba690ba7143496e94be6dfc3b7a147a","IPY_MODEL_e6ebfeb5c6834c2aa19208daff99ff46"],"layout":"IPY_MODEL_eb755d649b474719803ebc0363c5c816","tabbable":null,"tooltip":null}},"f6ebe2c9774b4559b5dca364ab692ed3":{"model_module":"@jupyter-widgets/controls","model_module_version":"2.0.0","model_name":"ProgressStyleModel","state":{"_model_module":"@jupyter-widgets/controls","_model_module_version":"2.0.0","_model_name":"ProgressStyleModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"2.0.0","_view_name":"StyleView","bar_color":null,"description_width":""}},"f6f1d4c13537448c96764409cdb36e86":{"model_module":"@jupyter-widgets/base","model_module_version":"2.0.0","model_name":"LayoutModel","state":{"_model_module":"@jupyter-widgets/base","_model_module_version":"2.0.0","_model_name":"LayoutModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"2.0.0","_view_name":"LayoutView","align_content":null,"align_items":null,"align_self":null,"border_bottom":null,"border_left":null,"border_right":null,"border_top":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,"padding":null,"right":null,"top":null,"visibility":null,"width":null}},"f71ab98654664e51899a6e7ff98e3e44":{"model_module":"@jupyter-widgets/controls","model_module_version":"2.0.0","model_name":"HBoxModel","state":{"_dom_classes":[],"_model_module":"@jupyter-widgets/controls","_model_module_version":"2.0.0","_model_name":"HBoxModel","_view_count":null,"_view_module":"@jupyter-widgets/controls","_view_module_version":"2.0.0","_view_name":"HBoxView","box_style":"","children":["IPY_MODEL_95823f5cdc45425c89ae17ae39861589","IPY_MODEL_57eafe8c675140339cd23233899919c7","IPY_MODEL_cb12ae18a2374f60a175cceec31934bb"],"layout":"IPY_MODEL_3863ad62ca8d4fc6bfb21a524d163bb4","tabbable":null,"tooltip":null}},"f71fdecd9c7f4d91a41b3291d62b8a14":{"model_module":"@jupyter-widgets/controls","model_module_version":"2.0.0","model_name":"ProgressStyleModel","state":{"_model_module":"@jupyter-widgets/controls","_model_module_version":"2.0.0","_model_name":"ProgressStyleModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"2.0.0","_view_name":"StyleView","bar_color":null,"description_width":""}},"f8b6994d075e4345b31b0057f20c724f":{"model_module":"@jupyter-widgets/controls","model_module_version":"2.0.0","model_name":"ProgressStyleModel","state":{"_model_module":"@jupyter-widgets/controls","_model_module_version":"2.0.0","_model_name":"ProgressStyleModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"2.0.0","_view_name":"StyleView","bar_color":null,"description_width":""}},"fa4079edbfc34eb19c7dfd906d9e2821":{"model_module":"@jupyter-widgets/base","model_module_version":"2.0.0","model_name":"LayoutModel","state":{"_model_module":"@jupyter-widgets/base","_model_module_version":"2.0.0","_model_name":"LayoutModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"2.0.0","_view_name":"LayoutView","align_content":null,"align_items":null,"align_self":null,"border_bottom":null,"border_left":null,"border_right":null,"border_top":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,"padding":null,"right":null,"top":null,"visibility":null,"width":null}},"fa6a9a908f14421594266506b17f3e61":{"model_module":"@jupyter-widgets/controls","model_module_version":"2.0.0","model_name":"HTMLStyleModel","state":{"_model_module":"@jupyter-widgets/controls","_model_module_version":"2.0.0","_model_name":"HTMLStyleModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"2.0.0","_view_name":"StyleView","background":null,"description_width":"","font_size":null,"text_color":null}},"fb45eef5e5734cbb91d39d77d96c77e5":{"model_module":"@jupyter-widgets/controls","model_module_version":"2.0.0","model_name":"HBoxModel","state":{"_dom_classes":[],"_model_module":"@jupyter-widgets/controls","_model_module_version":"2.0.0","_model_name":"HBoxModel","_view_count":null,"_view_module":"@jupyter-widgets/controls","_view_module_version":"2.0.0","_view_name":"HBoxView","box_style":"","children":["IPY_MODEL_18172273e0fc4de488da1fd4dded1c43","IPY_MODEL_cec6d9a8487e4e7f98e904a8ebe63121","IPY_MODEL_02a0cd884a2143b0bf1b3a7e918fe7f3"],"layout":"IPY_MODEL_e3b3a17026e94440adebda3bdb46bfa8","tabbable":null,"tooltip":null}},"fb981c38f74c448e8b74d8dba2759288":{"model_module":"@jupyter-widgets/base","model_module_version":"2.0.0","model_name":"LayoutModel","state":{"_model_module":"@jupyter-widgets/base","_model_module_version":"2.0.0","_model_name":"LayoutModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"2.0.0","_view_name":"LayoutView","align_content":null,"align_items":null,"align_self":null,"border_bottom":null,"border_left":null,"border_right":null,"border_top":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,"padding":null,"right":null,"top":null,"visibility":null,"width":null}}},"version_major":2,"version_minor":0}},"dinosaurs_v4":{"name":"RSNA Knee | DINOsaur V4 — PublicDual 0.937→0.938 Push","base":"Renta K. weak-label 0.937 fork with attribution retained","known_control":"submission_dinosaur_v4_0937_control.csv","primary_candidate":"submission_dinosaur_v4_publicdual_candidate.csv","optional_probe":"submission_dinosaur_v4_publicdual_v6_probe.csv","default_submission":"submission.csv","public_rad_delta":"twin public-v15/E10 + E13 FS-crop + second E13/E11-layout","private_coat_residual_included":false,"excluded_private_dataset_version":19417108,"version_line":"V4"},"attribution":{"forked_from":"renta0426/rsna-knee-0-937-weak-label-dinov2-meniscus-resid","original_author":"Renta K. (renta0426)","original_url":"https://www.kaggle.com/code/renta0426/rsna-knee-0-937-weak-label-dinov2-meniscus-resid","credit_preserved":true,"derived_work":true},"dinosaurs_v4_publicsynovitis":{"name":"RSNA Knee | DINOsaur V4 — PublicSynovitis 0.938+ Push","base":"DINOsaur V4 PublicDual candidate","known_scored_control":"Renta-based V4 0.937","changed_target":"Synovitis only","default_alpha":0.08,"private_coat_artifact_used":false,"mattia_credit":"mattiaangeli/bend-the-knee-to-the-dinosaurs","renta_credit":"renta0426/rsna-knee-0-937-weak-label-dinov2-meniscus-resid","implementation_note":"new Synovitis/Effusion residual is independently written; exact report parser not copied","default_submission":"submission.csv"},"dinosaurs_v4_publiccoat":{"name":"RSNA Knee | DINOsaur V4 — PublicCoAt 0.939+ Push","version_line":"V4","informed_by":"kunaldesale2408/rsna-knee-abnormality-detectionv1","kunal_credit_preserved":true,"mattia_credit_preserved":true,"renta_credit_preserved":true,"private_coat_checkpoint_used":false,"new_model_passes":0,"default_submission":"submission.csv","primary_candidate":"submission_dinosaur_v4_publiccoat_main.csv","control_candidate":"submission_dinosaur_v4_publicdual_candidate.csv","public0033_schema_fix":"accept extra specialist columns; consume Medial Meniscus only","publicsynovitis_uid_fix":"validate UIDs through _blend_transformer; validate rank frames by length/labels"}},"nbformat_minor":4,"nbformat":4,"cells":[{"id":"53567c22-c4f2-49a4-b22a-ea2f2acf65f9","cell_type":"markdown","source":"# RSNA Knee | DINOsaur V4 🦖 ","metadata":{}},{"id":"9feaf2da-9580-45c6-aaff-7af9e39d795a","cell_type":"markdown","source":"## 🙏 Additional attribution — Kunal Desale\n\nThis DINOsaur V4 experiment was informed by the public Kaggle notebook:\n\n**Kunal Desale — `kunaldesale2408/rsna-knee-abnormality-detectionv1`**  \nhttps://www.kaggle.com/code/kunaldesale2408/rsna-knee-abnormality-detectionv1\n\nThank you to **Kunal Desale** for publishing the notebook and exposing the interaction between the public DINO/DINOv3/RadImageNet/Raptor stack and an additional CoAtNet residual branch.\n\n### What this fork does — and does not — take from that notebook\n\n- We **do not copy or require** the private CoAtNet `resgated e4/e6/e8` checkpoint bundle.\n- We **do not copy** the private-residual runtime.\n- We independently implement a **public-only analogue** using predictions from the public Raptor checkpoints that DINOsaur V4 already executes.\n- The Renta K. weak-label Medial-Meniscus residual remains credited to `renta0426`.\n- The Bend-the-Knee / DINOv3 lineage remains credited to Mattia Angeli and its upstream contributors.\n- All original checkpoints, datasets, and code retain their original authorship and licenses.\n\nThis is an auditable derived experiment, not a relabeling of someone else's work. Please preserve these credits if you fork it again.\n","metadata":{}},{"id":"771523d8","cell_type":"code","source":"\"\"\"Notebook cell source: capture the exact 336px DINO cache for public0033.\n\nThis file is embedded by ``build_public0033_meniscus10_notebook.py`` immediately\nbefore the unchanged upstream DINO prediction cell.  The capture is deliberately\nvery narrow: it only observes the cache and mask allocation made by the upstream\n``build_cache`` call for a 6-slot / 12-slice / 336px test volume.  It does not\nmodify the returned arrays or any parent prediction code.\n\"\"\"\n\nimport builtins as _p33_builtins\nimport inspect as _p33_inspect\nimport numpy as _p33_np\n\n\n_P33_CAPTURE_KEY = \"_public0033_cache_capture_v1\"\n\nif hasattr(_p33_builtins, _P33_CAPTURE_KEY):\n    raise RuntimeError(\"public0033: cache capture state already exists\")\n\n_p33_original_zeros = _p33_np.zeros\n\n\ndef _p33_normalize_shape(_p33_shape):\n    try:\n        return tuple(int(_p33_value) for _p33_value in _p33_shape)\n    except TypeError:\n        return None\n\n\ndef _p33_caller_studies():\n    \"\"\"Read only the local ``studies`` tuple from upstream ``build_cache``.\"\"\"\n\n    _p33_frame = _p33_inspect.currentframe()\n    try:\n        _p33_wrapper = None if _p33_frame is None else _p33_frame.f_back\n        _p33_caller = None if _p33_wrapper is None else _p33_wrapper.f_back\n        if _p33_caller is None or _p33_caller.f_code.co_name != \"build_cache\":\n            return None\n        _p33_value = _p33_caller.f_locals.get(\"studies\")\n        if not isinstance(_p33_value, (list, tuple)):\n            return None\n        _p33_studies = tuple(str(_p33_uid) for _p33_uid in _p33_value)\n        if not _p33_studies or any(not _p33_uid for _p33_uid in _p33_studies):\n            return None\n        if len(set(_p33_studies)) != len(_p33_studies):\n            raise RuntimeError(\"public0033: captured build_cache studies are not unique\")\n        return _p33_studies\n    finally:\n        # ``inspect`` frames retain all parent locals, including large DICOM objects.\n        del _p33_frame\n        del _p33_wrapper\n\n\n_p33_state = {\n    \"schema_version\": \"public0033_cache_capture_v1\",\n    \"original_zeros\": _p33_original_zeros,\n    \"numpy_module\": _p33_np,\n    \"events\": [],\n    \"cache_candidates\": [],\n    \"mask_candidates\": [],\n}\n\n\ndef _p33_zeros(\n    _p33_shape,\n    dtype=float,\n    order=\"C\",\n    *,\n    like=None,\n    _p33_delegate=_p33_original_zeros,\n    _p33_state_ref=_p33_state,\n):\n    \"\"\"Delegate ``numpy.zeros`` while retaining only the prescribed allocations.\"\"\"\n\n    if like is None:\n        _p33_value = _p33_delegate(_p33_shape, dtype=dtype, order=order)\n    else:\n        _p33_value = _p33_delegate(\n            _p33_shape, dtype=dtype, order=order, like=like\n        )\n\n    _p33_shape_tuple = _p33_normalize_shape(_p33_shape)\n    _p33_dtype = _p33_np.dtype(dtype)\n    _p33_studies = _p33_caller_studies()\n    _p33_event = {\n        \"shape\": list(_p33_shape_tuple) if _p33_shape_tuple is not None else None,\n        \"dtype\": _p33_dtype.str,\n        \"caller\": \"build_cache\" if _p33_studies is not None else None,\n        \"study_count\": len(_p33_studies) if _p33_studies is not None else None,\n    }\n    _p33_state_ref[\"events\"].append(_p33_event)\n\n    if _p33_studies is None:\n        return _p33_value\n\n    if (\n        _p33_shape_tuple is not None\n        and len(_p33_shape_tuple) == 5\n        and _p33_shape_tuple[0] == len(_p33_studies)\n        and _p33_shape_tuple[1:] == (6, 12, 336, 336)\n        and _p33_dtype == _p33_np.dtype(_p33_np.uint8)\n    ):\n        _p33_state_ref[\"cache_candidates\"].append(\n            {\"cache\": _p33_value, \"studies\": _p33_studies}\n        )\n    elif (\n        _p33_shape_tuple is not None\n        and len(_p33_shape_tuple) == 2\n        and _p33_shape_tuple[0] == len(_p33_studies)\n        and _p33_shape_tuple[1:] == (6,)\n        and _p33_dtype == _p33_np.dtype(_p33_np.float32)\n    ):\n        _p33_state_ref[\"mask_candidates\"].append(\n            {\"mask\": _p33_value, \"studies\": _p33_studies}\n        )\n    return _p33_value\n\n\n_p33_np.zeros = _p33_zeros\nsetattr(_p33_builtins, _P33_CAPTURE_KEY, _p33_state)\ndel _p33_state\ndel _p33_original_zeros\n","metadata":{"papermill":{"duration":0.041496,"end_time":"2026-09-04T02:57:39.17278+00:00","exception":false,"start_time":"2026-09-04T02:57:39.131284+00:00","status":"completed"},"tags":[],"trusted":true},"outputs":[],"execution_count":null},{"id":"000c389e","cell_type":"code","source":"from __future__ import annotations\nimport os\nimport gc\nimport hashlib\nimport json\nimport re\nimport time\nimport traceback\nimport threading\nfrom concurrent.futures import ThreadPoolExecutor\nfrom pathlib import Path\nimport numpy as np\nimport pandas as pd\nimport pydicom\nimport torch\nimport torch.nn as nn\nimport torch.nn.functional as F\n_ASSET_ROOTS = [\n    Path('/kaggle/input/rsna-knee-bend-dinov3-0917-repro-assets'),\n    Path('/kaggle/input/datasets/tonylica/rsna-knee-bend-dinov3-0917-repro-assets'),\n]\nASSET = next((path for path in _ASSET_ROOTS if (path / 'rsna-knee-weights' / 'manifest.json').is_file()),\n             _ASSET_ROOTS[0])\n_COMPETITION_ROOTS = [\n    Path('/kaggle/input/rsna-knee-abnormality-detection'),\n    Path('/kaggle/input/competitions/rsna-knee-abnormality-detection'),\n]\nROOT = next((path for path in _COMPETITION_ROOTS if (path / 'train.csv').is_file()),\n            _COMPETITION_ROOTS[0])\nDINO = Path('/kaggle/input/models/metaresearch/dinov2/pytorch/small/1')\nT0 = time.time()\nDEVS = [torch.device(f'cuda:{i}') for i in range(torch.cuda.device_count())]\nSEED = 2026\nTARGETS = ['ACL', 'MCL', 'Medial Meniscus', 'Lateral Meniscus', 'Medial OA', 'Lateral OA', 'PF OA', 'Effusion', 'Synovitis', \"Baker's\", 'Contusion', 'Fracture']\nCROP_MM = 130.0\nCACHE_IMG = 336\nGROUP = 3\nN_GROUP_MAX = 1\nCACHE_FRACTION = 0.45\nCACHE_BUDGET_MAX_GB = 24.0\nCACHE_BUDGET_GB = 12.0\nTEST_SHARE = 0.3\nHDR_THREADS = 16\nPIX_THREADS = 12\nORDER_THREADS = 32\nORDER_BUDGET_S = 5400\nAUG_ROT_DEG = 8.0\nAUG_SCALE = 0.08\nAUG_SHIFT = 0.05\nAUG_INTENSITY = 0.1\nLAT_MIN_OFFSET_MM = 20.0\nSLICE_BAND = (0.2, 0.8)\nRULES_NATIVE = {'order': 'normal', 'lat': 'centre', 'slot_fallback': False, 'decode_fill': 'nearest'}\nRULES_LEGACY = {'order': 'dominant_axis', 'lat': 'corner_x', 'slot_fallback': True, 'decode_fill': 'zero'}\nRULES = dict(RULES_NATIVE)\nLEGACY_LAT_OFFSET_MM = 5.0\nEVAL_BATCH = 8\nTIME_BUDGET = 8.0 * 3600\nSLOTS_RECOVERED = [('SAG_FLUID_FS', 'Sagittal', True, True), ('COR_FLUID_FS', 'Coronal', True, True), ('AX_FLUID_FS', 'Axial', True, True), ('SAG_FLUID_NOFS', 'Sagittal', True, False), ('COR_T1', 'Coronal', False, False), ('SAG_T1', 'Sagittal', False, False)]\nSLOTS_PUBLIC = [('SAG_FLUID', 'Sagittal', None, True), ('COR_FLUID', 'Coronal', None, True), ('AX_FLUID', 'Axial', None, True), ('SAG_STRUCT', 'Sagittal', None, False), ('COR_STRUCT', 'Coronal', None, False), ('AX_STRUCT', 'Axial', None, False)]\nSLOT_SCHEME = os.environ.get('SLOT_SCHEME', 'recovered')\nSLOTS = SLOTS_PUBLIC if SLOT_SCHEME == 'public' else SLOTS_RECOVERED\nN_SLOT = len(SLOTS)\nPOOL_PARTS = {'cls_mean': 2, 'cls_mean_focal': 3}\nSLOT_PRIOR_TABLE = {'ACL': (0, 3, 5), 'MCL': (1, 4), 'Medial Meniscus': (0, 1, 3, 4), 'Lateral Meniscus': (0, 1, 3, 4), 'Medial OA': (1, 4, 5), 'Lateral OA': (1, 4, 5), 'PF OA': (0, 2, 5), 'Effusion': (0, 2), 'Synovitis': (0, 2), \"Baker's\": (0,), 'Contusion': (0, 1, 2), 'Fracture': (0, 1, 2, 4, 5)}\nSLOT_PRIOR_STRENGTH = 0.55\nFATSAT_OPTS = {'FS', 'FATSAT', 'FAT_SAT', 'FSAT'}\n_SEP = re.compile('[_\\\\-.]')\n_FATSAT_RX = re.compile('\\\\bfs\\\\b|fatsat|fat sat|\\\\bstir\\\\b|\\\\bspair\\\\b|\\\\bspir\\\\b|\\\\bwe\\\\b|water excit|\\\\btirm\\\\b|\\\\bsting\\\\b|\\\\bfatsup\\\\b')\n_T1_RX = re.compile('\\\\bt1\\\\b|\\\\bt1w\\\\b')\n_T2_RX = re.compile('\\\\bt2\\\\b|\\\\bt2w\\\\b')\n_PD_RX = re.compile('\\\\bpd\\\\b|\\\\bpdw\\\\b|proton|\\\\bdp\\\\b|dens')\n\ndef log(msg):\n    print(f'[{time.time() - T0:7.1f}s] {msg}', flush=True)\nIMG = CACHE_IMG\n\ndef available_gb():\n    try:\n        with open('/proc/meminfo') as fh:\n            info = {k.strip(): v for k, v in (l.split(':', 1) for l in fh if ':' in l)}\n        return int(info['MemAvailable'].split()[0]) / 1024 ** 2\n    except Exception:\n        return CACHE_BUDGET_GB / CACHE_FRACTION\n\ndef plan_cache(n_study, n_test=0):\n    avail = available_gb()\n    budget = min(avail * CACHE_FRACTION, CACHE_BUDGET_MAX_GB)\n    n_total = n_study + max(n_test, int(TEST_SHARE * n_study))\n    per_slice = n_total * N_SLOT * IMG * IMG\n    afford = int(budget * 1024 ** 3 // max(per_slice, 1))\n    groups = max(1, min(N_GROUP_MAX, afford // GROUP))\n    log(f'memory: {avail:.1f} GB available, {budget:.1f} GB to the cache; sizing for {n_study} train + {n_total - n_study} test studies -> {groups} group(s) of {GROUP} = {groups * GROUP} slices per slot' + (f' (wanted {N_GROUP_MAX})' if groups < N_GROUP_MAX else ''))\n    return groups\nN_GROUP = plan_cache(len(pd.read_csv(ROOT / 'train.csv')), len(pd.read_csv(ROOT / 'test.csv')))\nCACHE_SLICES = GROUP * N_GROUP\nHDR_TAGS = ['SeriesDescription', 'SequenceName', 'ScanOptions', 'ScanningSequence', 'RepetitionTime', 'EchoTime', 'Laterality', 'PixelSpacing', 'Rows', 'Columns', 'RescaleSlope', 'RescaleIntercept', 'ImagePositionPatient', 'ImageOrientationPatient']\n\ndef _hdr_vec(s, n):\n    if not isinstance(s, str):\n        return None\n    try:\n        v = [float(x) for x in s.split('|')]\n    except ValueError:\n        return None\n    return np.array(v) if len(v) >= n else None\n\ndef side_from_geometry(h):\n    cx = {}\n    for r in h.itertuples(index=False):\n        ipp = _hdr_vec(getattr(r, 'ImagePositionPatient', None), 3)\n        iop = _hdr_vec(getattr(r, 'ImageOrientationPatient', None), 6)\n        ps = _hdr_vec(getattr(r, 'PixelSpacing', None), 2)\n        rows, cols = (getattr(r, 'Rows', None), getattr(r, 'Columns', None))\n        if ipp is None or iop is None or ps is None or (not rows) or (not cols):\n            continue\n        try:\n            c = ipp[:3] + iop[:3] * ps[1] * float(cols) / 2 + iop[3:6] * ps[0] * float(rows) / 2\n        except (TypeError, ValueError):\n            continue\n        cx.setdefault(r.StudyInstanceUID, []).append(float(c[0]))\n    out = {}\n    for st, xs in cx.items():\n        m = float(np.median(xs))\n        out[st] = None if abs(m) < LAT_MIN_OFFSET_MM else 'R' if m < 0 else 'L'\n    return out\n\ndef side_from_corner_x(h):\n    out = {}\n    for st, g in h.groupby('StudyInstanceUID'):\n        xs = []\n        for r in g.itertuples(index=False):\n            ipp = _hdr_vec(getattr(r, 'ImagePositionPatient', None), 3)\n            if ipp is not None and np.isfinite(ipp).all():\n                xs.append(float(ipp[0]))\n        if not xs:\n            out[st] = None\n            continue\n        x = float(np.median(xs))\n        out[st] = None if abs(x) < LEGACY_LAT_OFFSET_MM else 'R' if x < 0 else 'L'\n    return out\n\ndef lat_of(h, tag=''):\n    geo = side_from_corner_x(h) if RULES['lat'] == 'corner_x' else side_from_geometry(h)\n    d, n_tag, n_geo, n_none, n_disagree = ({}, 0, 0, 0, 0)\n    for st, g in h.groupby('StudyInstanceUID'):\n        v = [str(x).strip().upper() for x in g['Laterality'].dropna()]\n        if RULES['lat'] == 'corner_x' and 'ImageLaterality' in g.columns:\n            v += [str(x).strip().upper() for x in g['ImageLaterality'].dropna()]\n        v = [x[0] for x in v if x and x[0] in ('L', 'R')]\n        side = v[0] if v else None\n        if side is not None:\n            n_tag += 1\n            if geo.get(st) is not None and geo[st] != side:\n                n_disagree += 1\n        else:\n            side = geo.get(st)\n            n_geo += side is not None\n            n_none += side is None\n        d[st] = side\n    log(f'{tag}laterality: {n_tag} from the tag, {n_geo} from geometry, {n_none} unresolved; tag and geometry disagree on {n_disagree} ({n_disagree / max(n_tag, 1):.1%} of the tagged)')\n    return d\n\ndef probe(item):\n    split, study, series, path = item\n    row = {'split': split, 'StudyInstanceUID': study, 'SeriesInstanceUID': series, 'dir': path}\n    try:\n        files = sorted((e.name for e in os.scandir(path) if e.name.endswith('.dcm')))\n        row['files'] = files\n        row['n_slices'] = len(files)\n        if not files:\n            return row\n        ds = pydicom.dcmread(os.path.join(path, files[len(files) // 2]), stop_before_pixels=True, force=True)\n        for t in HDR_TAGS:\n            v = getattr(ds, t, None)\n            if v is None:\n                row[t] = None\n            elif isinstance(v, (list, tuple)) or type(v).__name__ == 'MultiValue':\n                row[t] = '|'.join((str(x) for x in v))\n            else:\n                row[t] = str(v)\n    except Exception as exc:\n        row['err'] = str(exc)[:120]\n    return row\n\ndef walk(split):\n    base = ROOT / split\n    items = []\n    if not base.is_dir():\n        return pd.DataFrame(columns=['split', 'StudyInstanceUID', 'SeriesInstanceUID', 'dir', 'files', 'n_slices'] + HDR_TAGS)\n    for study in os.scandir(base):\n        if study.is_dir():\n            for series in os.scandir(study.path):\n                if series.is_dir():\n                    items.append((split, study.name, series.name, series.path))\n    with ThreadPoolExecutor(max_workers=HDR_THREADS) as pool:\n        rows = list(pool.map(probe, items))\n    return pd.DataFrame(rows)\n\ndef annotate(df):\n    desc = df['SeriesDescription'].fillna('') + ' ' + df['SequenceName'].fillna('')\n    desc = desc.str.lower().str.replace(_SEP, ' ', regex=True)\n    opts = df['ScanOptions'].fillna('').str.upper().str.split('|')\n    opts_fs = opts.apply(lambda ts: any((t.strip() in FATSAT_OPTS for t in ts)))\n    df['fatsat'] = desc.str.contains(_FATSAT_RX) | opts_fs\n    tr = pd.to_numeric(df['RepetitionTime'], errors='coerce')\n    te = pd.to_numeric(df['EchoTime'], errors='coerce')\n    gre = df['ScanningSequence'].fillna('').str.upper().str.contains('GR')\n    t1, t2, pdw = (desc.str.contains(_T1_RX), desc.str.contains(_T2_RX), desc.str.contains(_PD_RX))\n    df['weight'] = np.where(t1 & ~t2 & ~pdw, 'T1', np.where(t2 & ~pdw, 'T2', np.where(pdw, 'PD', np.where(gre, 'GRE', np.where(tr < 800, 'T1', np.where(te > 60, 'T2', np.where(tr >= 800, 'PD', 'UNK')))))))\n    df['fluid'] = np.isin(df['weight'], ['PD', 'T2'])\n    df['px'] = pd.to_numeric(df['PixelSpacing'].fillna('').str.split('|').str[0].replace('', np.nan), errors='coerce')\n    return df\n\ndef pick_slots(series_df, plane_map):\n    series_df = series_df.copy()\n    series_df['plane'] = series_df['SeriesInstanceUID'].map(plane_map)\n    out = {}\n    for study, g in series_df.groupby('StudyInstanceUID'):\n        chosen = {}\n        for name, plane, fluid, fs in SLOTS:\n            sel = (g['plane'] == plane) & (g['fatsat'] == fs)\n            if fluid is not None:\n                sel &= g['fluid'] == fluid\n            cand = g[sel]\n            if len(cand) == 0 and RULES['slot_fallback'] and (fluid is False):\n                cand = g[(g['plane'] == plane) & ~g['fatsat']]\n            if len(cand):\n                chosen[name] = cand.sort_values('n_slices', ascending=False).iloc[0]\n        out[study] = chosen\n    return out\nORDER_TAGS = [(32, 50), (32, 55), (32, 19)]\nDECODE_FAILED = []\n\ndef _natural_key(name):\n    return tuple((int(x) if x.isdigit() else x.lower() for x in re.split('(\\\\d+)', str(name))))\n\ndef _order_dominant_axis(rec):\n    files, d = (rec['files'], rec['dir'])\n    rows = []\n    for pos, f in enumerate(files):\n        ipp = inst = None\n        try:\n            ds = pydicom.dcmread(os.path.join(d, f), force=True, stop_before_pixels=True, specific_tags=['ImagePositionPatient', 'InstanceNumber'])\n            raw = getattr(ds, 'ImagePositionPatient', None)\n            if raw is not None and len(raw) >= 3:\n                c = np.asarray(raw[:3], dtype=np.float64)\n                if np.isfinite(c).all():\n                    ipp = c\n            n = getattr(ds, 'InstanceNumber', None)\n            if n is not None:\n                inst = float(n)\n        except Exception:\n            pass\n        rows.append((f, ipp, inst, pos))\n    placed = [r for r in rows if r[1] is not None]\n    need = max(2, int(0.8 * len(rows)))\n    if len(placed) >= need:\n        xyz = np.stack([r[1] for r in placed])\n        axis = int(np.argmax(np.ptp(xyz, axis=0)))\n        spare = float(np.nanmedian(xyz[:, axis]))\n        rows.sort(key=lambda r: (float(r[1][axis]) if r[1] is not None else spare, r[2] if r[2] is not None else float('inf'), r[3]))\n    elif sum((r[2] is not None for r in rows)) >= need:\n        rows.sort(key=lambda r: (r[2] if r[2] is not None else float('inf'), r[3]))\n    else:\n        rows.sort(key=lambda r: _natural_key(r[0]))\n    return ([r[0] for r in rows], True)\n\ndef order_slices(rec):\n    if RULES['order'] == 'dominant_axis':\n        return _order_dominant_axis(rec)\n    files, d = (rec['files'], rec['dir'])\n    keyed = []\n    for f in files:\n        k = None\n        try:\n            ds = pydicom.dcmread(os.path.join(d, f), force=True, stop_before_pixels=True, specific_tags=ORDER_TAGS)\n            iop = np.asarray(ds.ImageOrientationPatient, dtype=float)\n            ipp = np.asarray(ds.ImagePositionPatient, dtype=float)\n            k = float(np.dot(ipp, np.cross(iop[:3], iop[3:])))\n        except Exception:\n            try:\n                k = float(ds.InstanceNumber)\n            except Exception:\n                k = None\n        keyed.append((k, f))\n    if any((k is None for k, _ in keyed)):\n        return (files, False)\n    return ([f for _, f in sorted(keyed, key=lambda t: t[0])], True)\n\ndef read_slot(rec, n_slice=None, out_size=None):\n    n_slice = GROUP if n_slice is None else n_slice\n    out_size = IMG if out_size is None else out_size\n    files, d, px = (rec.get('ordered') or rec['files'], rec['dir'], rec['px'])\n    n = len(files)\n    if n == 0:\n        return None\n    lo, hi = (int(SLICE_BAND[0] * (n - 1)), int(SLICE_BAND[1] * (n - 1)))\n    idx = np.unique(np.linspace(lo, hi, n_slice).astype(int)) if hi > lo else np.array([n // 2])\n    while len(idx) < n_slice:\n        idx = np.append(idx, idx[-1])\n    planes = []\n    for i in idx[:n_slice]:\n        try:\n            ds = pydicom.dcmread(os.path.join(d, files[int(i)]), force=True)\n            a = ds.pixel_array.astype(np.float32)\n            sl = float(getattr(ds, 'RescaleSlope', 1) or 1)\n            ic = float(getattr(ds, 'RescaleIntercept', 0) or 0)\n            a = a * sl + ic\n        except Exception:\n            a = None\n        planes.append(a)\n    got = [k for k, p in enumerate(planes) if p is not None]\n    if RULES['decode_fill'] == 'zero':\n        if not got:\n            DECODE_FAILED.append(rec.get('SeriesInstanceUID', d))\n        planes = [np.zeros((out_size, out_size), np.float32) if p is None else p for p in planes]\n        got = list(range(len(planes)))\n    if not got:\n        DECODE_FAILED.append(rec.get('SeriesInstanceUID', d))\n        return None\n    if len(got) < len(planes):\n        DECODE_FAILED.append(rec.get('SeriesInstanceUID', d))\n        for k, p in enumerate(planes):\n            if p is None:\n                planes[k] = planes[min(got, key=lambda j: abs(j - k))]\n    shp = planes[0].shape\n    planes = [p if p.shape == shp else np.zeros(shp, np.float32) for p in planes]\n    vol = np.stack(planes)\n    if px and np.isfinite(px) and (px > 0):\n        want = int(round(CROP_MM / px))\n        h, w = shp\n        if 16 < want < min(h, w):\n            cy, cx = (h // 2, w // 2)\n            half = want // 2\n            vol = vol[:, max(0, cy - half):cy + half, max(0, cx - half):cx + half]\n    lo_v, hi_v = np.percentile(vol, [1, 99])\n    vol = np.clip((vol - lo_v) / max(hi_v - lo_v, 1e-06), 0, 1)\n    t = torch.from_numpy(np.ascontiguousarray(vol)).unsqueeze(0)\n    t = F.interpolate(t, size=(out_size, out_size), mode='bilinear', align_corners=False)\n    return (t.squeeze(0) * 255).round().clamp(0, 255).to(torch.uint8)\n\ndef normalise_laterality(img, plane, lat):\n    if lat != 'R':\n        return img\n    if plane in ('Coronal', 'Axial'):\n        return torch.flip(img, dims=[-1])\n    return torch.flip(img, dims=[0])\nORDER_CACHE = os.environ.get('RSNA_ORDER_CACHE') or None\n\ndef build_cache(slot_map, plane_map, lat_map, tag):\n    studies = sorted(slot_map)\n    sidx = {s: i for i, s in enumerate(studies)}\n    cache = np.zeros((len(studies), N_SLOT, CACHE_SLICES, IMG, IMG), np.uint8)\n    mask = np.zeros((len(studies), N_SLOT), np.float32)\n    log(f'{tag}: cache {cache.shape} = {cache.nbytes / 1024 ** 3:.1f} GB')\n    jobs = [(st, k, plane, slot_map[st][name]) for st in studies for k, (name, plane, _, _) in enumerate(SLOTS) if name in slot_map[st]]\n    n_job = len(jobs)\n    t_ord = time.time()\n    n_slice_total = sum((len(j[3]['files']) for j in jobs))\n    log(f'{tag}: ordering {len(jobs)} slot-series ({n_slice_total} slice headers)')\n    ok = done = 0\n    CHUNK_O = 1024\n    seen = {}\n    if ORDER_CACHE and Path(ORDER_CACHE).is_file():\n        try:\n            import json as _json\n            seen = _json.loads(Path(ORDER_CACHE).read_text())\n        except (OSError, ValueError):\n            seen = {}\n        hit = 0\n        for _, _, _, rec in jobs:\n            e = seen.get(rec['SeriesInstanceUID'])\n            if e and len(e['files']) == len(rec['files']):\n                rec['ordered'] = e['files']\n                ok += int(e['good'])\n                hit += 1\n        jobs = [j for j in jobs if 'ordered' not in j[3]]\n        log(f'{tag}: {hit} slot-series ordered from {ORDER_CACHE}, {len(jobs)} to read')\n    with ThreadPoolExecutor(max_workers=ORDER_THREADS) as pool:\n        for c0 in range(0, len(jobs), CHUNK_O):\n            block = jobs[c0:c0 + CHUNK_O]\n            for (_, _, _, rec), (files, good) in zip(block, pool.map(lambda j: order_slices(j[3]), block)):\n                rec['ordered'] = files\n                ok += int(good)\n                done += 1\n                if ORDER_CACHE:\n                    seen[rec['SeriesInstanceUID']] = {'files': files, 'good': bool(good)}\n            budget = min(ORDER_BUDGET_S, max(60.0, (TIME_BUDGET - (time.time() - T0)) * 0.35))\n            if time.time() - t_ord > budget:\n                log(f'{tag}: ordering budget spent at {done}/{len(jobs)}; the rest keep file order')\n                break\n    if ORDER_CACHE and done:\n        import json as _json\n        _t = Path(ORDER_CACHE).with_suffix('.tmp')\n        _t.write_text(_json.dumps(seen))\n        _t.replace(Path(ORDER_CACHE))\n    log(f'{tag}: ordered {ok}/{n_job} by geometry ({n_job - ok} kept arbitrary) in {time.time() - t_ord:.0f}s')\n    jobs = [(st, k, plane, slot_map[st][name]) for st in studies for k, (name, plane, _, _) in enumerate(SLOTS) if name in slot_map[st]]\n    log(f'{tag}: decoding {len(jobs)} slot-series')\n    n_failed_before = len(DECODE_FAILED)\n    CHUNK = 512\n    done = 0\n    with ThreadPoolExecutor(max_workers=PIX_THREADS) as pool:\n        for c0 in range(0, len(jobs), CHUNK):\n            block = jobs[c0:c0 + CHUNK]\n            for (st, k, plane, _), img in zip(block, pool.map(lambda j: read_slot(j[3], CACHE_SLICES, IMG), block)):\n                done += 1\n                if img is None:\n                    continue\n                cache[sidx[st], k] = normalise_laterality(img, plane, lat_map.get(st)).numpy()\n                mask[sidx[st], k] = 1.0\n            if done % 4096 < CHUNK:\n                log(f'  {tag} {done}/{len(jobs)}')\n            if time.time() - T0 > TIME_BUDGET:\n                log(f'  {tag}: time budget reached during decode')\n                break\n    n_failed = len(DECODE_FAILED) - n_failed_before\n    log(f'{tag}: {int(mask.sum())}/{len(jobs)} slots filled' + (f'; {n_failed} series had a slice that would not decode' if n_failed else ''))\n    gc.collect()\n    return (studies, cache, mask)\n\nclass SlotHead(nn.Module):\n\n    def __init__(self, dim, n_slot, n_out, hidden=256, p=0.2, prior=False):\n        super().__init__()\n        self.proj = nn.Sequential(nn.LayerNorm(dim), nn.Linear(dim, hidden), nn.GELU())\n        self.slot_emb = nn.Parameter(torch.randn(n_slot, hidden) * 0.02)\n        self.query = nn.Parameter(torch.randn(n_out, hidden) * 0.02)\n        self.drop = nn.Dropout(p)\n        self.out = nn.Linear(hidden, n_out)\n        self.hidden = hidden\n        p_ = torch.zeros(n_out, n_slot)\n        if prior and n_slot == len(SLOTS) and (n_out == len(TARGETS)):\n            for t, slots in SLOT_PRIOR_TABLE.items():\n                if t in TARGETS:\n                    p_[TARGETS.index(t), list(slots)] = SLOT_PRIOR_STRENGTH\n        self.prior = prior\n        if prior:\n            self.register_buffer('slot_prior', p_)\n\n    def forward(self, x, mask):\n        h = self.proj(x) + self.slot_emb\n        att = torch.einsum('bsh,oh->bos', h, self.query) / self.hidden ** 0.5\n        if self.prior:\n            att = att + self.slot_prior.unsqueeze(0)\n        att = att.masked_fill(mask.unsqueeze(1) < 0.5, -10000.0).softmax(-1)\n        ctx = self.drop(torch.einsum('bos,bsh->boh', att, h))\n        return (ctx * self.out.weight.unsqueeze(0)).sum(-1) + self.out.bias\n\nclass Model(nn.Module):\n\n    def __init__(self, backbone, dim, pool='cls_mean', prior=False):\n        super().__init__()\n        self.backbone = backbone\n        self.pool = pool\n        self.head = SlotHead(dim * POOL_PARTS[pool], N_SLOT, len(TARGETS), prior=prior)\n        self.register_buffer('mean', torch.tensor([0.485, 0.456, 0.406]).view(1, 3, 1, 1))\n        self.register_buffer('std', torch.tensor([0.229, 0.224, 0.225]).view(1, 3, 1, 1))\n\n    def forward(self, imgs, mask, img_size=None):\n        B, S = imgs.shape[:2]\n        x = imgs.reshape(B * S, *imgs.shape[2:]).float().div_(255.0)\n        if img_size is not None and img_size != x.shape[-1]:\n            x = F.interpolate(x, size=(img_size, img_size), mode='bilinear', align_corners=False)\n        x = (x - self.mean) / self.std\n        out = self.backbone(pixel_values=x).last_hidden_state\n        patch = out[:, 1:]\n        parts = [out[:, 0], patch.mean(1)]\n        if self.pool == 'cls_mean_focal':\n            k = max(1, patch.shape[1] // 8)\n            parts.append(patch.topk(k, dim=1).values.mean(1))\n        feat = torch.cat(parts, dim=1).reshape(B, S, -1)\n        return self.head(feat, mask)\n\ndef build_model(unfreeze_last, source=None, variant='small', pool='cls_mean', prior=False):\n    from transformers import AutoModel\n    p = source if source is not None else find_dinov2(variant)\n    if p is None:\n        raise FileNotFoundError('DINOv2 weights not attached')\n    bb = AutoModel.from_pretrained(str(p))\n    n_layer = len(bb.encoder.layer)\n    for prm in bb.parameters():\n        prm.requires_grad = False\n    for blk in bb.encoder.layer[max(0, n_layer - unfreeze_last):]:\n        for prm in blk.parameters():\n            prm.requires_grad = True\n    for prm in bb.layernorm.parameters():\n        prm.requires_grad = True\n    dim = bb.config.hidden_size\n    trainable = sum((p.numel() for p in bb.parameters() if p.requires_grad))\n    log(f'backbone: {n_layer} blocks, last {unfreeze_last} trainable ({trainable / 1000000.0:.1f}M params), feature dim {dim * POOL_PARTS[pool]}')\n    return Model(bb, dim, pool=pool, prior=prior)\nFINGERPRINT_TOL = 0.002\n\ndef fingerprint(model, dev, img_size, n_slot=None, group=None, seed=None):\n    n_slot = N_SLOT if n_slot is None else n_slot\n    group = GROUP if group is None else group\n    seed = SEED if seed is None else seed\n    g = torch.Generator().manual_seed(seed)\n    imgs = torch.randint(0, 256, (2, n_slot, group, img_size, img_size), generator=g, dtype=torch.uint8).to(dev)\n    mask = torch.ones(2, n_slot, device=dev)\n    mask[1, -1] = 0.0\n    was_training = model.training\n    model.eval()\n    with torch.no_grad():\n        out = model(imgs, mask, img_size).float().cpu().numpy()\n    if was_training:\n        model.train()\n    return out\n\ndef check_fingerprint(model, dev, img_size, expected, tol=FINGERPRINT_TOL, tag=''):\n    got = fingerprint(model, dev, img_size)\n    exp = np.asarray(expected, np.float32)\n    if got.shape != exp.shape:\n        raise WeightsError(f'{tag}fingerprint shape {got.shape} != stored {exp.shape}: the architecture is not the one these weights were fitted to')\n    d = float(np.abs(got - exp).max())\n    if d > tol:\n        raise WeightsError(f'{tag}fingerprint differs by {d:.4g} (tolerance {tol:g}). The weights load but do not compute what they computed when fitted - preprocessing, resolution or architecture has moved between the two runs.')\n    log(f'{tag}fingerprint matches within {d:.2g}')\n    return d\n\nclass WeightsError(RuntimeError):\n    pass\nTTA_OVERLAP = True\nTTA_POOL = 'prob'\nPUBLIC_FRONTIER_TARGET_POOL = {'Fracture': 'max', 'Contusion': 'max', 'Medial Meniscus': 'max', 'Lateral Meniscus': 'max', 'ACL': 'top2', 'MCL': 'top2', \"Baker's\": 'max'}\nTTA_TARGET_POOL = {**PUBLIC_FRONTIER_TARGET_POOL, 'Synovitis': 'original_mean'}\nLEGACY_FOLD_SOFTPOOL_BETA = {'ACL': 6.0, 'MCL': 6.0, 'Medial Meniscus': 8.0, 'Lateral Meniscus': 8.0, \"Baker's\": 8.0, 'Contusion': 8.0, 'Fracture': 10.0}\nLEGACY_FOLD_SOFTPOOL_ALPHA = {'ACL': 0.2, 'MCL': 0.2, 'Medial Meniscus': 0.25, 'Lateral Meniscus': 0.25, \"Baker's\": 0.2, 'Contusion': 0.2, 'Fracture': 0.15}\n\ndef window_starts(n_slice, group, overlap=None):\n    overlap = TTA_OVERLAP if overlap is None else overlap\n    if overlap and n_slice >= group:\n        return list(range(n_slice - group + 1))\n    return [g * group for g in range(max(n_slice // group, 1))]\n\ndef apply_target_window_pool(values, probs, logits, original_probs, mapping, target_idx):\n    for target, mode in mapping.items():\n        j = target_idx[target]\n        if mode == 'max':\n            values[:, j] = probs[:, :, j].max(0).values\n        elif mode == 'mean':\n            values[:, j] = probs[:, :, j].mean(0)\n        elif mode == 'logit_mean':\n            values[:, j] = torch.sigmoid(logits[:, :, j].mean(0))\n        elif mode == 'original_mean':\n            values[:, j] = original_probs[:, :, j].mean(0)\n        elif mode in ('top2', 'top3'):\n            k = min(int(mode[3:]), probs.shape[0])\n            values[:, j] = probs[:, :, j].topk(k, dim=0).values.mean(0)\n        else:\n            raise ValueError(f'unknown TTA pooling mode for {target}: {mode}')\n    return values\n\ndef legacy_fold_soft_window_pool(original_probs, target_idx):\n    values = original_probs.mean(0).clone()\n    for target, beta in LEGACY_FOLD_SOFTPOOL_BETA.items():\n        j = target_idx[target]\n        x = original_probs[:, :, j]\n        weight = torch.softmax(float(beta) * x, dim=0)\n        values[:, j] = (weight * x).sum(0)\n    return values\n\n@torch.no_grad()\ndef predict_member(model, cache, mask, idx, dev, img_size, group=None, pool=None, starts=None, jitter=False, jitter_seed=SEED, return_public_frontier=False):\n    group = GROUP if group is None else group\n    pool = TTA_POOL if pool is None else pool\n    starts = window_starts(cache.shape[2], group) if starts is None else list(starts)\n    if not starts:\n        raise ValueError('predict_member was given no windows to average over')\n    target_idx = {t: j for j, t in enumerate(TARGETS)}\n    unknown = (set(TTA_TARGET_POOL) | set(PUBLIC_FRONTIER_TARGET_POOL)) - set(target_idx)\n    if unknown:\n        raise ValueError(f'unknown target(s) in TTA_TARGET_POOL: {unknown}')\n    jitter_gen = torch.Generator(device=dev)\n    jitter_gen.manual_seed(int(jitter_seed) % (2 ** 63 - 1))\n    model.eval()\n    out, public_frontier_out, public_soft_out = ([], [], [])\n    for b in range(0, len(idx), EVAL_BATCH):\n        sel = idx[b:b + EVAL_BATCH]\n        m = torch.from_numpy(mask[sel]).to(dev)\n        win_probs, win_logits, win_original_probs = ([], [], [])\n        for st in starts:\n            rows = torch.from_numpy(np.ascontiguousarray(cache[sel, :, st:st + group])).to(dev)\n            views = [rows] + ([augment(rows, generator=jitter_gen)] if jitter else [])\n            view_probs, view_logits = ([], [])\n            for view in views:\n                with torch.autocast('cuda', enabled=dev.type == 'cuda'):\n                    z = model(view, m, img_size).float()\n                view_logits.append(z)\n                view_probs.append(torch.sigmoid(z))\n            win_logits.append(torch.stack(view_logits).mean(0))\n            win_probs.append(torch.stack(view_probs).mean(0))\n            win_original_probs.append(view_probs[0])\n        probs = torch.stack(win_probs)\n        logits = torch.stack(win_logits)\n        original_probs = torch.stack(win_original_probs)\n        v = torch.sigmoid(logits.mean(0)) if pool == 'logit' else probs.mean(0)\n        v = apply_target_window_pool(v, probs, logits, original_probs, TTA_TARGET_POOL, target_idx)\n        out.append(v.cpu().numpy())\n        if return_public_frontier:\n            public_v = apply_target_window_pool(original_probs.mean(0), original_probs, logits, original_probs, PUBLIC_FRONTIER_TARGET_POOL, target_idx)\n            public_frontier_out.append(public_v.cpu().numpy())\n            public_soft = legacy_fold_soft_window_pool(original_probs, target_idx)\n            public_soft_out.append(public_soft.cpu().numpy())\n    primary = np.concatenate(out) if out else np.zeros((0, len(TARGETS)), np.float32)\n    if not return_public_frontier:\n        return primary\n    public_frontier = np.concatenate(public_frontier_out) if public_frontier_out else np.zeros((0, len(TARGETS)), np.float32)\n    public_soft = np.concatenate(public_soft_out) if public_soft_out else np.zeros((0, len(TARGETS)), np.float32)\n    return (primary, public_frontier, public_soft)\nBUILD_LOCK = threading.Lock()\nSTATE_LOCK = threading.Lock()\n\ndef _run_member(path, m, dev, Cte, Mte, idx, starts, jitter):\n    t0 = time.time()\n    with BUILD_LOCK:\n        if 'state' in m:\n            state, fp = (m['state'], None)\n        else:\n            ck = torch.load(Path(path) / m['file'], map_location='cpu', weights_only=False)\n            state, fp = (ck['model'], ck.get('fingerprint'))\n        model = build_model(int(m['config']['unfreeze_last']), variant=m['config']['variant'], pool=m['config'].get('pool', 'cls_mean'), prior=bool(m['config'].get('prior', False))).to(dev)\n        model.load_state_dict(state)\n        if fp is not None:\n            check_fingerprint(model, dev, IMG, fp, tag=f\"{m['id']}: \")\n        else:\n            log(f\"  {m['id']}: no stored fingerprint (legacy bundle) -- accepted at reduced weight\")\n    t_ready = time.time()\n    jitter_seed = SEED + int(hashlib.sha256(str(m['id']).encode()).hexdigest()[:8], 16)\n    public_member = 'state' not in m\n    predicted = predict_member(model, Cte, Mte, idx, dev, IMG, starts=starts, jitter=jitter, jitter_seed=jitter_seed, return_public_frontier=public_member)\n    if public_member:\n        p, public_p, public_soft = predicted\n    else:\n        p, public_p, public_soft = (predicted, None, None)\n    t_done = time.time()\n    del model, state\n    gc.collect()\n    if dev.type == 'cuda':\n        with torch.cuda.device(dev):\n            torch.cuda.empty_cache()\n    passes = len(starts) * (2 if jitter else 1)\n    return (p, public_p, public_soft, (t_ready - t0, (t_done - t_ready) / max(passes, 1)))\n\ndef _combine(per_member):\n    all_ids = sorted({s for m in per_member for s in m['ids']})\n    pos = {s: i for i, s in enumerate(all_ids)}\n    acc = np.zeros((len(all_ids), len(TARGETS)), np.float64)\n    tot = np.zeros(len(TARGETS), np.float64)\n    for m in per_member:\n        target_weight = m.get('target_weight')\n        w = np.asarray(target_weight if target_weight is not None else [float(m.get('weight', 1.0))] * len(TARGETS), dtype=np.float64)\n        if w.shape != (len(TARGETS),) or np.any(w < 0):\n            raise ValueError(f\"invalid target weights for {m.get('id')}: {w}\")\n        r = pd.DataFrame(m['pred']).rank(pct=True).to_numpy()\n        acc[[pos[s] for s in m['ids']]] += r * w[None, :]\n        tot += w\n    if np.any(tot <= 0):\n        raise ValueError(f'at least one target has no ensemble vote: {tot}')\n    return (all_ids, acc / tot[None, :])\n\ndef combine_public_members_by_fold(per_member, pred_key='pred'):\n    all_ids = sorted({study for member in per_member for study in member['ids']})\n    position = {study: i for i, study in enumerate(all_ids)}\n    groups = {}\n    for i, member in enumerate(per_member):\n        fold = member.get('fold')\n        key = f'fold_{fold}' if fold is not None else f'member_{i}'\n        groups.setdefault(key, []).append(member)\n    fold_ranks, diagnostics = ([], [])\n    for key, members_in_fold in sorted(groups.items()):\n        matrices = []\n        for member in members_in_fold:\n            values = np.full((len(all_ids), len(TARGETS)), np.nan, np.float64)\n            values[[position[study] for study in member['ids']]] = np.asarray(member[pred_key], np.float64)\n            if np.isnan(values).any():\n                raise WeightsError(f\"{member.get('id')}: incomplete {pred_key} coverage\")\n            matrices.append(values)\n        raw_fold_mean = np.mean(matrices, axis=0)\n        fold_ranks.append(pd.DataFrame(raw_fold_mean).rank(method='average', pct=True).to_numpy(np.float64))\n        diagnostics.append({'ensemble_group': key, 'members': len(members_in_fold)})\n    if len(fold_ranks) != 5:\n        raise WeightsError(f'legacy branch requires five folds, found {len(fold_ranks)}')\n    return (all_ids, np.mean(fold_ranks, axis=0), pd.DataFrame(diagnostics))\n\ndef blend_legacy_frontier_and_soft(frontier_rank, soft_rank):\n    output = np.asarray(frontier_rank, np.float64).copy()\n    for j, target in enumerate(TARGETS):\n        alpha = float(LEGACY_FOLD_SOFTPOOL_ALPHA.get(target, 0.0))\n        if alpha:\n            output[:, j] = (1.0 - alpha) * frontier_rank[:, j] + alpha * soft_rank[:, j]\n    return output\n\ndef infer_from_package(path, dev=None):\n    man = json.loads((Path(path) / 'manifest.json').read_text())\n    members = man['members']\n    log(f'weights package: {len(members)} member(s) from {path}; {len(DEVS)} device(s)')\n    test_df = pd.read_csv(ROOT / 'test.csv')\n    test_series = pd.read_csv(ROOT / 'test_series.csv')\n    plane_map = dict(zip(test_series['SeriesInstanceUID'], test_series['Anatomical_Plane']))\n    hte = annotate(walk('test_series'))\n    log(f'test header pass: {len(hte)} series')\n    groups = {}\n    for m in members:\n        groups.setdefault(m['pixel_group'], []).append(m)\n    groups.update(legacy_group_members())\n    per_member, public_frontier_members = ([], [])\n    est = {'fixed': None, 'win': None}\n\n    def bank(m, ids, pred, starts, jitter, public_pred=None, public_soft=None):\n        if float(np.std(pred)) < 1e-09:\n            log(f\"  {m['id']}: degenerate predictions; not banked\")\n            return\n        with STATE_LOCK:\n            per_member.append({'id': m['id'], 'fold': m.get('fold'), 'ids': ids, 'pred': pred, 'weight': m.get('weight', 1.0), 'target_weight': m.get('target_weight'), 'holdout': m.get('holdout')})\n            if public_pred is not None and len(starts) == len(starts_full):\n                if float(np.std(public_pred)) < 1e-09:\n                    raise WeightsError(f\"{m['id']}: degenerate public-frontier prediction\")\n                public_frontier_members.append({'id': m['id'], 'fold': m.get('fold'), 'ids': ids, 'pred': public_pred, 'soft_pred': public_soft})\n            elif public_pred is not None:\n                log(f\"  {m['id']}: public-frontier vote omitted because only {len(starts)} / {len(starts_full)} windows completed\")\n            all_ids, acc = _combine(per_member)\n            write_submission(acc, all_ids, test_df, 'submission.csv')\n            log(f\"  banked {m['id']} fold {m.get('fold', '?')} ({len(starts)} window(s){(', jitter' if jitter else '')}); submission.csv = weighted rank mean of {len(per_member)} member(s)\")\n    for gi, (key, gm) in enumerate(groups.items(), 1):\n        cfg = json.loads(key)\n        adopt_config_globals(cfg)\n        log(f\"decode group {gi}/{len(groups)}: {cfg['img']}px x {cfg['slices']} slices, crop {cfg['crop_mm']} mm -> {len(gm)} member(s)\")\n        st_te, Cte, Mte = build_cache(pick_slots(hte, plane_map), plane_map, lat_of(hte, 'test '), f'test g{gi}')\n        idx = np.arange(len(st_te))\n        starts_full = window_starts(Cte.shape[2], GROUP)\n        pending = sorted(gm, key=lambda m: -(m.get('holdout') or 0))\n        left_after = sum((len(g) for j, (_, g) in enumerate(groups.items(), 1) if j > gi))\n\n        def pop_next():\n            with STATE_LOCK:\n                if not pending:\n                    return (None, None, False)\n                left = TIME_BUDGET - (time.time() - T0)\n                remaining = len(pending) + left_after\n                slots_left = -(-remaining // len(DEVS))\n                starts, jit = (starts_full, False)\n                if est['fixed'] is not None and est['win'] is not None:\n                    afford = max(left * 0.9, 0.0)\n                    room = afford / max(slots_left, 1)\n                    if est['fixed'] + est['win'] > room:\n                        log(f'  {left / 60:.0f} min left: surrendering {len(pending)} member(s); not one more fits')\n                        pending.clear()\n                        return (None, None, False)\n                    jit = est['fixed'] + 2 * len(starts_full) * est['win'] <= room * 0.6\n                    per_win = est['win'] * (2 if jit else 1)\n                    n_win = int((room - est['fixed']) / per_win) if per_win > 0 else len(starts_full)\n                    n_win = max(1, min(len(starts_full), n_win))\n                    if n_win < len(starts_full):\n                        mid = (len(starts_full) - n_win) // 2\n                        starts = starts_full[mid:mid + n_win]\n                return (pending.pop(0), starts, jit)\n\n        def worker(dev):\n            others = [d for d in DEVS if d is not dev]\n            while True:\n                m, starts, jit = pop_next()\n                if m is None:\n                    return\n                for attempt, d in enumerate([dev] + others[:1]):\n                    try:\n                        p, public_p, public_soft, (fs, ws) = _run_member(path, m, d, Cte, Mte, idx, starts, jit)\n                        with STATE_LOCK:\n                            est['fixed'], est['win'] = (fs, ws)\n                        bank(m, st_te, p, starts, jit, public_p, public_soft)\n                        break\n                    except Exception as exc:\n                        log(f\"  MEMBER {m['id']} failed on {d} ({type(exc).__name__}: {exc}); \" + ('retrying on peer device' if attempt == 0 and others else 'dropped -- costs one vote, not the run'))\n                        if d.type == 'cuda':\n                            with torch.cuda.device(d):\n                                torch.cuda.empty_cache()\n        threads = [threading.Thread(target=worker, args=(d,)) for d in DEVS]\n        for t in threads:\n            t.start()\n        for t in threads:\n            t.join()\n        del Cte, Mte\n        gc.collect()\n    if not per_member:\n        raise WeightsError('no member produced predictions; submission stays at 0.5')\n    all_ids, acc = _combine(per_member)\n    sub = write_submission(acc, all_ids, test_df, 'submission.csv')\n    log(f'final submission.csv = weighted rank mean of {len(per_member)} member(s); {sub.shape}; nulls {int(sub[TARGETS].isna().sum().sum())}')\n    if len(public_frontier_members) == len(members):\n        frontier_ids, frontier_acc = _combine(public_frontier_members)\n        frontier_sub = write_submission(frontier_acc, frontier_ids, test_df, 'submission_public_0899.csv')\n        log(f'submission_public_0899.csv = exact no-jitter public-frontier rank mean of {len(public_frontier_members)} member(s); {frontier_sub.shape}; nulls {int(frontier_sub[TARGETS].isna().sum().sum())}')\n        fold_ids, fold_frontier, fold_diagnostics = combine_public_members_by_fold(public_frontier_members, 'pred')\n        soft_ids, fold_soft, _ = combine_public_members_by_fold(public_frontier_members, 'soft_pred')\n        if fold_ids != soft_ids:\n            raise WeightsError('legacy hard/soft study order mismatch')\n        legacy_prediction = blend_legacy_frontier_and_soft(fold_frontier, fold_soft)\n        legacy_sub = write_submission(legacy_prediction, fold_ids, test_df, 'submission_legacy_fold_blend.csv')\n        fold_diagnostics.to_csv('legacy_fold_diagnostics.csv', index=False)\n        log(f'legacy DINO aggregation written from five folds; {legacy_sub.shape}')\n    else:\n        log(f'public-frontier fallback not emitted: {len(public_frontier_members)} / {len(members)} required public members completed')\n    return sub\n\ndef adopt_config_globals(cfg):\n    global IMG, CACHE_IMG, GROUP, CACHE_SLICES, N_GROUP, CROP_MM, SLICE_BAND, RULES\n    CACHE_IMG = IMG = int(cfg['img'])\n    GROUP = int(cfg['group'])\n    CACHE_SLICES = int(cfg['slices'])\n    N_GROUP = max(CACHE_SLICES // GROUP, 1)\n    CROP_MM = float(cfg['crop_mm'])\n    SLICE_BAND = tuple((float(x) for x in cfg['band']))\n    rules = cfg.get('rules') or RULES_NATIVE\n    unknown = {k: v for k, v in rules.items() if k not in RULES_NATIVE or v not in (RULES_NATIVE[k], RULES_LEGACY[k])}\n    if unknown:\n        raise WeightsError(f'the members record pixel rules this pipeline cannot reproduce: {unknown}')\n    RULES = {**RULES_NATIVE, **rules}\n    if [s[0] for s in SLOTS] != list(cfg['slots']):\n        raise WeightsError(f\"the members were fitted on slots {cfg['slots']} and this pipeline defines {[s[0] for s in SLOTS]}; a weight would be read against the wrong slot\")\n\ndef augment(imgs, generator=None):\n    lead = imgs.shape[:-3]\n    x = imgs.reshape(-1, *imgs.shape[-3:]).float()\n    n, dev = (x.shape[0], x.device)\n    rot = (torch.rand(n, device=dev, generator=generator) - 0.5) * 2 * (AUG_ROT_DEG * np.pi / 180)\n    sc = 1.0 + torch.rand(n, device=dev, generator=generator) * AUG_SCALE\n    tx = (torch.rand(n, device=dev, generator=generator) - 0.5) * 2 * AUG_SHIFT\n    ty = (torch.rand(n, device=dev, generator=generator) - 0.5) * 2 * AUG_SHIFT\n    cos, sin = (torch.cos(rot) / sc, torch.sin(rot) / sc)\n    theta = torch.zeros(n, 2, 3, device=dev, dtype=torch.float32)\n    theta[:, 0, 0], theta[:, 0, 1], theta[:, 0, 2] = (cos, -sin, tx)\n    theta[:, 1, 0], theta[:, 1, 1], theta[:, 1, 2] = (sin, cos, ty)\n    grid = F.affine_grid(theta, x.shape, align_corners=False)\n    x = F.grid_sample(x, grid, mode='bilinear', padding_mode='border', align_corners=False)\n    scale = 1.0 + (torch.rand(n, 1, 1, 1, device=dev, generator=generator) - 0.5) * 2 * AUG_INTENSITY\n    x = (x * scale).clamp(0, 255)\n    return x.reshape(*lead, *x.shape[-3:]).to(imgs.dtype)\n\ndef write_submission(pred, studies, test_df, path):\n    sub = pd.DataFrame(pd.DataFrame(pred).rank(pct=True).values, columns=TARGETS)\n    sub.insert(0, 'StudyInstanceUID', studies)\n    sub = test_df[['StudyInstanceUID']].merge(sub, on='StudyInstanceUID', how='left')\n    sub[TARGETS] = sub[TARGETS].fillna(0.5)\n    sub.to_csv(path, index=False)\n    return sub\n\ndef find_dinov2(variant='small'):\n    if not (DINO / 'config.json').is_file():\n        raise FileNotFoundError(DINO)\n    return DINO\n\ndef legacy_group_members():\n    return {}\n\ndef run_dinov2():\n    path = ASSET / 'rsna-knee-weights'\n    infer_from_package(path, DEVS[0])\n    public = Path('/kaggle/working/submission_public_0899.csv')\n    if not public.is_file():\n        raise RuntimeError('public DINOv2 frontier was not produced')\n    public.replace('/kaggle/working/submission.csv')\n    for name in ('submission_legacy_fold_blend.csv', 'legacy_fold_diagnostics.csv'):\n        candidate = Path('/kaggle/working') / name\n        if candidate.is_file():\n            candidate.unlink()\nrun_dinov2()\n","metadata":{"papermill":{"duration":60.410325,"end_time":"2026-09-04T02:58:39.60598+00:00","exception":false,"start_time":"2026-09-04T02:57:39.195655+00:00","status":"completed"},"tags":[],"trusted":true},"outputs":[],"execution_count":null},{"id":"1479bd22","cell_type":"code","source":"\"\"\"Notebook cell source: invoke the bundled fullfit0033 cached inference runtime.\n\nThe preceding capture shim owns the only large array references.  This cell\nselects exactly one cache/mask pair, restores ``numpy.zeros`` before loading\nany new code, then calls the hash-bound runtime from the specialist bundle.\nFailures are intentionally propagated: there is no prediction fallback.\n\"\"\"\n\nimport builtins as _p33_builtins\nimport gc as _p33_gc\nimport hashlib as _p33_hashlib\nimport importlib.util as _p33_importlib_util\nimport json as _p33_json\nimport os as _p33_os\nfrom pathlib import Path as _P33Path\n\n\n_P33_CAPTURE_KEY = \"_public0033_cache_capture_v1\"\n_P33_BUNDLE_SCHEMA = \"public0033_meniscus10_bundle_v1\"\n_P33_RUNTIME_ENTRYPOINT = \"run_cached_inference(cache, mask, studies, output_paths)\"\n_p33_work_dir = _P33Path(_p33_os.environ.get(\"PUBLIC0033_WORK_DIR\", \"/kaggle/working\"))\n_p33_output_paths = {\n    \"bag_raw_csv\": str(_p33_work_dir / \"public0033_bag_raw.csv\"),\n    \"receipt_json\": str(_p33_work_dir / \"public0033_cached_inference_receipt.json\"),\n    \"work_dir\": str(_p33_work_dir),\n}\n\n\ndef _p33_sha256_file(_p33_path):\n    _p33_digest = _p33_hashlib.sha256()\n    with _p33_path.open(\"rb\") as _p33_handle:\n        for _p33_block in iter(lambda: _p33_handle.read(8 << 20), b\"\"):\n            _p33_digest.update(_p33_block)\n    return _p33_digest.hexdigest()\n\n\ndef _p33_restore_zeros(_p33_state):\n    _p33_numpy = _p33_state.get(\"numpy_module\")\n    _p33_original = _p33_state.get(\"original_zeros\")\n    if _p33_numpy is None or _p33_original is None:\n        raise RuntimeError(\"public0033: cache capture lacks original numpy.zeros\")\n    _p33_numpy.zeros = _p33_original\n\n\ndef _p33_capture_pair(_p33_state):\n    _p33_caches = _p33_state.get(\"cache_candidates\")\n    _p33_masks = _p33_state.get(\"mask_candidates\")\n    if not isinstance(_p33_caches, list) or not isinstance(_p33_masks, list):\n        raise RuntimeError(\"public0033: cache capture candidate registry is invalid\")\n    _p33_pairs = []\n    for _p33_cache_record in _p33_caches:\n        for _p33_mask_record in _p33_masks:\n            _p33_studies = _p33_cache_record.get(\"studies\")\n            if _p33_studies != _p33_mask_record.get(\"studies\"):\n                continue\n            _p33_cache = _p33_cache_record.get(\"cache\")\n            _p33_mask = _p33_mask_record.get(\"mask\")\n            if _p33_cache is None or _p33_mask is None:\n                continue\n            _p33_expected_n = len(_p33_studies)\n            if (\n                tuple(_p33_cache.shape) == (_p33_expected_n, 6, 12, 336, 336)\n                and str(_p33_cache.dtype) == \"uint8\"\n                and tuple(_p33_mask.shape) == (_p33_expected_n, 6)\n                and str(_p33_mask.dtype) == \"float32\"\n            ):\n                _p33_pairs.append((_p33_cache, _p33_mask, _p33_studies))\n    if len(_p33_pairs) != 1:\n        raise RuntimeError(\n            \"public0033: expected exactly one captured 6x12x336 cache/mask pair, \"\n            f\"got {len(_p33_pairs)}\"\n        )\n    return _p33_pairs[0]\n\n\ndef _p33_find_bundle():\n    _p33_input = _P33Path(_p33_os.environ.get(\"PUBLIC0033_INPUT_ROOT\", \"/kaggle/input\"))\n    if not _p33_input.is_dir():\n        raise RuntimeError(\"public0033: /kaggle/input is unavailable\")\n    _p33_matches = []\n    # Kaggle currently mounts datasets below\n    # ``/kaggle/input/datasets/<owner>/<slug>``.  Retain the historical direct\n    # mount form as well, but do not recurse through arbitrary dataset payloads.\n    _p33_manifest_paths = set(_p33_input.glob(\"*/bundle_manifest.json\"))\n    _p33_manifest_paths.update(\n        _p33_input.glob(\"datasets/*/*/bundle_manifest.json\")\n    )\n    for _p33_manifest_path in sorted(\n        _p33_manifest_paths, key=lambda _p33_path: _p33_path.as_posix()\n    ):\n        _p33_mount = _p33_manifest_path.parent\n        _p33_manifest = _p33_json.loads(_p33_manifest_path.read_text(encoding=\"utf-8\"))\n        if _p33_manifest.get(\"schema_version\") == _P33_BUNDLE_SCHEMA:\n            _p33_matches.append((_p33_mount, _p33_manifest_path, _p33_manifest))\n    if len(_p33_matches) != 1:\n        raise RuntimeError(\n            \"public0033: expected exactly one specialist bundle manifest with schema \"\n            f\"{_P33_BUNDLE_SCHEMA!r}, got {len(_p33_matches)}\"\n        )\n    _p33_root, _p33_manifest_path, _p33_manifest = _p33_matches[0]\n    _p33_runtime = _p33_manifest.get(\"runtime\")\n    if not isinstance(_p33_runtime, dict):\n        raise RuntimeError(\"public0033: bundle runtime binding is missing\")\n    if _p33_runtime.get(\"bundle_relative_path\") != \"public0033_runtime.py\":\n        raise RuntimeError(\"public0033: bundle runtime path drift\")\n    if _p33_runtime.get(\"entrypoint\") != _P33_RUNTIME_ENTRYPOINT:\n        raise RuntimeError(\"public0033: bundle runtime entrypoint drift\")\n    _p33_runtime_sha = _p33_runtime.get(\"sha256\")\n    if not isinstance(_p33_runtime_sha, str) or len(_p33_runtime_sha) != 64:\n        raise RuntimeError(\"public0033: bundle runtime SHA256 is invalid\")\n    _p33_runtime_path = _p33_root / \"public0033_runtime.py\"\n    if not _p33_runtime_path.is_file() or _p33_sha256_file(_p33_runtime_path) != _p33_runtime_sha:\n        raise RuntimeError(\"public0033: bundled runtime SHA256 mismatch\")\n    return _p33_root, _p33_manifest_path, _p33_manifest, _p33_runtime_path\n\n\n_p33_state = getattr(_p33_builtins, _P33_CAPTURE_KEY, None)\nif not isinstance(_p33_state, dict):\n    raise RuntimeError(\"public0033: cache capture state is missing\")\n\n_p33_cache = None\n_p33_mask = None\n_p33_studies = None\ntry:\n    _p33_cache, _p33_mask, _p33_studies = _p33_capture_pair(_p33_state)\n    # The shim is only for the unchanged parent DINO cell.  The specialist runtime\n    # must receive normal NumPy semantics, even if it allocates additional buffers.\n    _p33_restore_zeros(_p33_state)\n    _p33_root, _p33_manifest_path, _p33_manifest, _p33_runtime_path = _p33_find_bundle()\n    _p33_spec = _p33_importlib_util.spec_from_file_location(\n        \"public0033_runtime\", _p33_runtime_path\n    )\n    if _p33_spec is None or _p33_spec.loader is None:\n        raise RuntimeError(\"public0033: cannot load bundled runtime\")\n    _p33_module = _p33_importlib_util.module_from_spec(_p33_spec)\n    _p33_spec.loader.exec_module(_p33_module)\n    _p33_runner = getattr(_p33_module, \"run_cached_inference\", None)\n    if not callable(_p33_runner):\n        raise RuntimeError(\"public0033: run_cached_inference is missing from bundle\")\n    _p33_result = _p33_runner(\n        _p33_cache,\n        _p33_mask,\n        list(_p33_studies),\n        dict(_p33_output_paths),\n    )\n    if not isinstance(_p33_result, dict) or _p33_result.get(\"status\") != \"passed\":\n        raise RuntimeError(\"public0033: cached inference runtime did not report status=passed\")\n    if _p33_result.get(\"bag_raw_csv\") != _p33_output_paths[\"bag_raw_csv\"]:\n        raise RuntimeError(\"public0033: cached inference output path drift\")\n    if not _P33Path(_p33_output_paths[\"bag_raw_csv\"]).is_file():\n        raise RuntimeError(\"public0033: cached inference did not create bag_raw.csv\")\nfinally:\n    # Always undo the parent shim and drop its only strong references to the cache.\n    _p33_restore_zeros(_p33_state)\n    _p33_state.get(\"cache_candidates\", []).clear()\n    _p33_state.get(\"mask_candidates\", []).clear()\n    _p33_state.get(\"events\", []).clear()\n    if getattr(_p33_builtins, _P33_CAPTURE_KEY, None) is _p33_state:\n        delattr(_p33_builtins, _P33_CAPTURE_KEY)\n    _p33_cache = None\n    _p33_mask = None\n    _p33_studies = None\n    _p33_gc.collect()\n    try:\n        import torch as _p33_torch\n\n        if _p33_torch.cuda.is_available():\n            _p33_torch.cuda.empty_cache()\n    except Exception:\n        # Cleanup must not hide the primary error; no prediction fallback is made.\n        pass\n","metadata":{"jupyter":{"source_hidden":true},"papermill":{"duration":9.978116,"end_time":"2026-09-04T02:58:49.612979+00:00","exception":false,"start_time":"2026-09-04T02:58:39.634863+00:00","status":"completed"},"tags":[],"trusted":true},"outputs":[],"execution_count":null},{"id":"ab7cbb56","cell_type":"code","source":"_A5_SAVED = dict(globals())\nimport gc, os, time, warnings\nfrom concurrent.futures import ProcessPoolExecutor, as_completed\nfrom pathlib import Path\nimport cv2\nimport numpy as np\nimport pandas as pd\nimport pydicom\nimport timm\nimport torch\nimport torch.nn as nn\nimport torch.nn.functional as F\nwarnings.filterwarnings('ignore')\ncv2.setNumThreads(1)\nCROP_MM = 130.0\nSIZE = 336\nSLICE_BAND = (0.12, 0.88)\nN_SLICE = 16\nINTENSITY = 'slice'\nSLOTS = [('Sagittal', 1), ('Sagittal', 0), ('Coronal', 1), ('Coronal', 0), ('Axial', 1), ('Axial', 0)]\nN_SLOT = len(SLOTS)\nLABELS = ['ACL', 'MCL', 'Medial Meniscus', 'Lateral Meniscus', 'Medial OA', 'Lateral OA', 'PF OA', 'Effusion', 'Synovitis', \"Baker's\", 'Contusion', 'Fracture']\n_COMPETITION_ROOTS = [\n    Path('/kaggle/input/rsna-knee-abnormality-detection'),\n    Path('/kaggle/input/competitions/rsna-knee-abnormality-detection'),\n]\nCOMP = next((path for path in _COMPETITION_ROOTS if (path / 'train.csv').is_file()),\n            _COMPETITION_ROOTS[0])\nCKPT = ASSET / 'knee-mri-fold-weights'\nDEV = 'cuda' if torch.cuda.is_available() else 'cpu'\nprint(f'competition : {COMP}')\nprint(f'checkpoints : {CKPT}')\nprint(f'device      : {DEV}')\nfor i in range(torch.cuda.device_count() if DEV == 'cuda' else 0):\n    cc = torch.cuda.get_device_capability(i)\n    print(f'  gpu{i}       : {torch.cuda.get_device_name(i)} sm_{cc[0]}{cc[1]}, {torch.cuda.get_device_properties(i).total_memory / 2 ** 30:.0f} GiB, native bf16={cc >= (8, 0)}')\nSERIES_ROOT = COMP / 'test_series'\nif not SERIES_ROOT.exists():\n    SERIES_ROOT = COMP / 'train_series'\nprint('series root:', SERIES_ROOT)\n\ndef ordered_files(sdir, cap=64):\n    keyed = []\n    for f in sdir.glob('*.dcm'):\n        try:\n            ds = pydicom.dcmread(str(f), stop_before_pixels=True)\n            keyed.append((int(ds.InstanceNumber), str(f)))\n        except Exception:\n            continue\n        if len(keyed) >= cap * 4:\n            break\n    return [f for _, f in sorted(keyed)]\n\ndef series_side(path):\n    try:\n        return float(pydicom.dcmread(path, stop_before_pixels=True).ImagePositionPatient[0])\n    except Exception:\n        return 0.0\n\ndef read_crop(path):\n    try:\n        ds = pydicom.dcmread(path)\n        arr = ds.pixel_array.astype(np.float32)\n    except Exception:\n        return None\n    try:\n        ps = float(ds.PixelSpacing[0])\n    except Exception:\n        ps = CROP_MM / max(arr.shape)\n    half = int(round(CROP_MM / ps / 2))\n    cy, cx = (arr.shape[0] // 2, arr.shape[1] // 2)\n    y0, y1 = (max(0, cy - half), min(arr.shape[0], cy + half))\n    x0, x1 = (max(0, cx - half), min(arr.shape[1], cx + half))\n    crop = arr[y0:y1, x0:x1]\n    return None if crop.size == 0 else crop\n\ndef window(crop, lo, hi, flip):\n    c = np.clip((crop - lo) / max(hi - lo, 1e-06), 0, 1)\n    img = cv2.resize(c, (SIZE, SIZE), interpolation=cv2.INTER_AREA)\n    return img[:, ::-1].copy() if flip else img\n\ndef render(path, flip):\n    crop = read_crop(path)\n    if crop is None:\n        return None\n    lo, hi = np.percentile(crop[::4, ::4], [1, 99])\n    return window(crop, lo, hi, flip)\n\ndef build_study(args):\n    idx, study, recs = args\n    out = np.zeros((N_SLOT, N_SLICE, SIZE, SIZE), np.uint8)\n    mask = np.zeros(N_SLOT, np.uint8)\n    rows = pd.DataFrame(recs)\n    if len(rows):\n        for s_i, (plane, fs) in enumerate(SLOTS):\n            sub = rows[(rows.Anatomical_Plane == plane) & (rows.Fat_Suppression == fs)]\n            if sub.empty:\n                continue\n            files = ordered_files(SERIES_ROOT / study / sub.iloc[0].SeriesInstanceUID)\n            if not files:\n                continue\n            flip = plane != 'Sagittal' and series_side(files[0]) < 0\n            lo, hi = SLICE_BAND\n            i0 = int(round(lo * (len(files) - 1)))\n            i1 = int(round(hi * (len(files) - 1)))\n            avail = list(range(i0, i1 + 1))\n            if len(avail) >= N_SLICE:\n                picks = [avail[int(round(t))] for t in np.linspace(0, len(avail) - 1, N_SLICE)]\n                off = 0\n            else:\n                picks, off = (avail, (N_SLICE - len(avail)) // 2)\n            if INTENSITY == 'series':\n                crops = [read_crop(files[p]) for p in picks]\n                got = [x for x in crops if x is not None]\n                if got:\n                    samp = np.concatenate([x[::4, ::4].ravel() for x in got])\n                    lo_, hi_ = np.percentile(samp, [1, 99])\n                    for c, x in enumerate(crops):\n                        if x is None:\n                            x = read_crop(files[min(len(files) - 1, picks[c] + 1)])\n                        if x is not None:\n                            out[s_i, off + c] = (window(x, lo_, hi_, flip) * 255).astype(np.uint8)\n            else:\n                for c, p in enumerate(picks):\n                    img = render(files[p], flip)\n                    if img is None:\n                        img = render(files[min(len(files) - 1, p + 1)], flip)\n                    if img is not None:\n                        out[s_i, off + c] = (img * 255).astype(np.uint8)\n            mask[s_i] = len(picks)\n    return (idx, out, mask)\nsub_df = pd.read_csv(COMP / 'sample_submission.csv')\nser_csv = pd.read_csv(COMP / 'test_series.csv')\nif not (COMP / 'test_series').exists():\n    ser_csv = pd.read_csv(COMP / 'train_series.csv')\nser_csv = ser_csv.loc[:, ~ser_csv.columns.duplicated()]\nstudies = sub_df.StudyInstanceUID.tolist()\nby = {s: g.to_dict('records') for s, g in ser_csv[ser_csv.StudyInstanceUID.isin(set(studies))].groupby('StudyInstanceUID')}\nprint(f'{len(studies):,} test studies, {len(by):,} with series metadata')\nN_SLOT_TYPES, MASK_IDX = (6, 0)\n\ndef segment_softmax(scores, sidx, B):\n    T, K = scores.shape\n    idx = sidx.unsqueeze(1).expand(-1, K)\n    m = torch.full((B, K), float('-inf'), device=scores.device, dtype=scores.dtype)\n    m = m.scatter_reduce(0, idx, scores, reduce='amax', include_self=True)\n    e = (scores - m[sidx]).exp()\n    s = torch.zeros(B, K, device=scores.device, dtype=scores.dtype).index_add_(0, sidx, e)\n    return e / s[sidx].clamp(min=1e-06)\n\nclass MeanMaxPool(nn.Module):\n\n    def forward(self, f, sidx, B, slot=None, return_attn=False):\n        D = f.shape[1]\n        cnt = torch.zeros(B, device=f.device, dtype=f.dtype).index_add_(0, sidx, torch.ones(f.shape[0], device=f.device, dtype=f.dtype))\n        mean = torch.zeros(B, D, device=f.device, dtype=f.dtype).index_add_(0, sidx, f)\n        mean = mean / cnt.clamp(min=1).unsqueeze(1)\n        mx = torch.full((B, D), -10000.0, device=f.device, dtype=f.dtype)\n        mx = mx.scatter_reduce(0, sidx.unsqueeze(1).expand(-1, D), f, reduce='amax', include_self=True)\n        return (torch.cat([mean, mx], 1), None)\n\nclass LabelAttentionPool(nn.Module):\n\n    def __init__(self, d, n_labels=12, n_heads=4, slot_bias=True):\n        super().__init__()\n        self.d, self.k, self.h = (d, n_labels, n_heads)\n        self.q = nn.Parameter(torch.randn(n_labels, d) * 0.02)\n        self.key, self.val = (nn.Linear(d, d), nn.Linear(d, d))\n        self.slot_bias = nn.Parameter(torch.zeros(n_labels, N_SLOT_TYPES + 1)) if slot_bias else None\n\n    def forward(self, f, sidx, B, slot=None, return_attn=False):\n        scores = self.key(f) @ self.q.t() / self.d ** 0.5\n        if self.slot_bias is not None and slot is not None:\n            scores = scores + self.slot_bias.t()[slot]\n        a = segment_softmax(scores, sidx, B)\n        out = torch.zeros(B, self.k, self.d, device=f.device, dtype=f.dtype)\n        out = out.index_add_(0, sidx, a.unsqueeze(-1) * self.val(f).unsqueeze(1))\n        return (out, a)\n\nclass TokenXAttnPool(nn.Module):\n\n    def __init__(self, d, n_labels=12, n_heads=6, dropout=0.2):\n        super().__init__()\n        self.d, self.k = (d, n_labels)\n        self.q = nn.Parameter(torch.randn(n_labels, d) * 0.02)\n        self.slot_emb = nn.Embedding(N_SLOT_TYPES + 1, d, padding_idx=0)\n        self.kv_norm = nn.LayerNorm(d)\n        self.attn = nn.MultiheadAttention(d, n_heads, dropout=dropout, batch_first=True)\n\n    def forward(self, tok, sidx, B, slot=None, return_attn=False):\n        T, N, D = tok.shape\n        cnt = torch.bincount(sidx, minlength=B)\n        S = int(cnt.max().item())\n        starts = torch.cumsum(cnt, 0) - cnt\n        pos = torch.arange(T, device=tok.device) - starts[sidx]\n        kv = tok + self.slot_emb(slot).unsqueeze(1)\n        pad = tok.new_zeros(B, S, N, D)\n        pad[sidx, pos] = kv\n        keep = torch.zeros(B, S, dtype=torch.bool, device=tok.device)\n        keep[sidx, pos] = True\n        kpm = ~keep.repeat_interleave(N, dim=1)\n        pad = self.kv_norm(pad.reshape(B, S * N, D))\n        q = self.q.unsqueeze(0).expand(B, -1, -1)\n        att, w = self.attn(q, pad, pad, key_padding_mask=kpm, need_weights=return_attn, average_attn_weights=True)\n        cls = tok[:, 0]\n        mean = torch.zeros(B, D, device=tok.device, dtype=tok.dtype).index_add_(0, sidx, cls) / cnt.clamp(min=1).unsqueeze(1)\n        mx = torch.full((B, D), -10000.0, device=tok.device, dtype=tok.dtype)\n        mx = mx.scatter_reduce(0, sidx.unsqueeze(1).expand(-1, D), cls, reduce='amax', include_self=True)\n        base = torch.cat([mean, mx], 1).unsqueeze(1).expand(-1, self.k, -1)\n        return (torch.cat([att, base], -1), w)\n\nclass ViTSlotToken(nn.Module):\n\n    def __init__(self, vit, n_cat, dim=None):\n        super().__init__()\n        self.vit = vit\n        d = dim or vit.embed_dim\n        self.tok = nn.Embedding(n_cat + 1, d, padding_idx=MASK_IDX)\n        self.num_features = vit.num_features\n        self._orig_prefix = getattr(vit, 'num_prefix_tokens', 1)\n        vit.num_prefix_tokens = self._orig_prefix + 1\n        for blk in vit.blocks:\n            a = getattr(blk, 'attn', None)\n            if a is not None and hasattr(a, 'num_prefix_tokens'):\n                a.num_prefix_tokens = a.num_prefix_tokens + 1\n\n    @staticmethod\n    def _maybe(mod, x):\n        return x if mod is None else mod(x)\n\n    def forward_features(self, x, cat):\n        v = self.vit\n        x = v.patch_embed(x)\n        pos = v._pos_embed(x)\n        rope = None\n        if isinstance(pos, tuple):\n            x, rope = pos\n        else:\n            x = pos\n        x = self._maybe(getattr(v, 'patch_drop', None), x)\n        x = self._maybe(getattr(v, 'norm_pre', None), x)\n        npt = self._orig_prefix\n        tok = self.tok(cat).unsqueeze(1)\n        x = torch.cat([x[:, :npt], tok, x[:, npt:]], dim=1)\n        if rope is not None:\n            if getattr(v, 'rope_mixed', False):\n                for i, blk in enumerate(v.blocks):\n                    x = blk(x, rope=rope[i])\n            else:\n                for blk in v.blocks:\n                    x = blk(x, rope=rope)\n        else:\n            x = v.blocks(x)\n        return v.norm(x)\n\n    def forward_head(self, x, pre_logits=True):\n        return self.vit.forward_head(x, pre_logits=pre_logits)\nIMAGENET_MEAN = (0.485, 0.456, 0.406)\nIMAGENET_STD = (0.229, 0.224, 0.225)\n\nclass _GatedDepthBlock(nn.Module):\n\n    def __init__(self, n_slice, dropout=0.0, ls_init=0.1):\n        super().__init__()\n        self.norm = nn.GroupNorm(1, n_slice)\n        self.v = nn.Conv2d(n_slice, n_slice, 1)\n        self.g = nn.Conv2d(n_slice, n_slice, 1)\n        self.out = nn.Conv2d(n_slice, n_slice, 1)\n        self.gamma = nn.Parameter(torch.full((n_slice, 1, 1), ls_init))\n        self.drop = nn.Dropout2d(dropout) if dropout else nn.Identity()\n\n    def forward(self, x):\n        z = self.norm(x)\n        return x + self.gamma * self.drop(self.out(self.v(z) * F.silu(self.g(z))))\n\nclass DepthCompress(nn.Module):\n\n    def __init__(self, n_slice=16, out_ch=3, depth=1, dropout=0.0, ls_init=0.1, imagenet=True, proj_noise=0.25):\n        super().__init__()\n        self.imagenet = imagenet\n        self.blocks = nn.ModuleList([_GatedDepthBlock(n_slice, dropout, ls_init) for _ in range(depth)])\n        self.proj = nn.Conv2d(n_slice, out_ch, 1, bias=True)\n        if imagenet:\n            self.register_buffer('mu', torch.tensor(IMAGENET_MEAN).view(1, -1, 1, 1))\n            self.register_buffer('sd', torch.tensor(IMAGENET_STD).view(1, -1, 1, 1))\n\n    def forward(self, x):\n        keep = (x.amax(dim=1, keepdim=True) > 0).to(x.dtype)\n        z = x\n        for b in self.blocks:\n            z = b(z)\n        z = self.proj(z)\n        if self.imagenet:\n            z = (z - self.mu.to(z.dtype)) / self.sd.to(z.dtype)\n        return z * keep\nN_PLANE, N_CONTRAST = (3, 2)\n_PLANE_OF = lambda s: torch.clamp(s - 1, 0, 5) // 2\n_CONTRAST_OF = lambda s: torch.clamp(s - 1, 0, 5) % 2\n\nclass SlotDepthMixer(nn.Module):\n\n    def __init__(self, n_slice=16, ksize=5, alpha_max=0.25):\n        super().__init__()\n        self.n_slice, self.ksize, self.r = (n_slice, ksize, ksize // 2)\n        self.alpha_max = alpha_max\n        b = torch.tensor([1.0, 4.0, 6.0, 4.0, 1.0])\n        self.register_buffer('base', b.log()[self.r:])\n        n_u = self.r + 1\n        self.shared = nn.Parameter(torch.zeros(n_u))\n        self.plane_k = nn.Parameter(torch.zeros(N_PLANE, n_u))\n        self.contrast_k = nn.Parameter(torch.zeros(N_CONTRAST, n_u))\n        self.g0 = nn.Parameter(torch.zeros(()))\n        self.gate_p = nn.Parameter(torch.zeros(N_PLANE))\n        self.gate_c = nn.Parameter(torch.zeros(N_CONTRAST))\n        idx = torch.arange(n_slice)\n        self.register_buffer('off', idx[None, :] - idx[:, None])\n\n    def kernel(self, slot):\n        p, c = (_PLANE_OF(slot), _CONTRAST_OF(slot))\n        half = self.base + self.shared + self.plane_k[p] + self.contrast_k[c]\n        full = torch.cat([half.flip(-1)[..., :self.r], half], dim=-1)\n        return F.softmax(full, dim=-1)\n\n    def alpha(self, slot):\n        p, c = (_PLANE_OF(slot), _CONTRAST_OF(slot))\n        return self.alpha_max * torch.tanh(self.g0 + self.gate_p[p] + self.gate_c[c])\n\n    def forward(self, x, slot, vmask):\n        T, S, H, W = x.shape\n        if vmask is None:\n            raise ValueError('stem=mixer requires the padding mask')\n        k = self.kernel(slot)\n        v = vmask.to(k.dtype)\n        d = self.off + self.r\n        inb = (d >= 0) & (d < self.ksize)\n        kk = k[:, d.clamp(0, self.ksize - 1)] * inb\n        M = kk * v[:, None, :]\n        den = M.sum(-1, keepdim=True)\n        eye = torch.eye(S, device=x.device, dtype=M.dtype).expand(T, S, S)\n        ok = (den > 1e-06) & v[:, :, None].bool()\n        M = torch.where(ok, M / den.clamp(min=1e-06), eye)\n        a = self.alpha(slot)[:, None, None]\n        Aop = ((1.0 - a) * eye + a * M).to(x.dtype)\n        if x.is_contiguous(memory_format=torch.channels_last) and (not x.is_contiguous()):\n            y = torch.bmm(x.permute(0, 2, 3, 1).reshape(T, H * W, S), Aop.transpose(1, 2))\n            return y.reshape(T, H, W, S).permute(0, 3, 1, 2)\n        return torch.bmm(Aop, x.reshape(T, S, H * W)).reshape(T, S, H, W)\n\ndef _seg_mean_max(v, sidx, B):\n    D = v.shape[1]\n    cnt = torch.zeros(B, device=v.device, dtype=v.dtype).index_add_(0, sidx, torch.ones(v.shape[0], device=v.device, dtype=v.dtype))\n    mean = torch.zeros(B, D, device=v.device, dtype=v.dtype).index_add_(0, sidx, v)\n    mean = mean / cnt.clamp(min=1).unsqueeze(1)\n    mx = torch.full((B, D), -10000.0, device=v.device, dtype=v.dtype)\n    mx = mx.scatter_reduce(0, sidx.unsqueeze(1).expand(-1, D), v, reduce='amax', include_self=True)\n    return torch.cat([mean, mx], 1)\n\ndef _pad_kv(x, sidx, B, norm):\n    T, P, D = x.shape\n    cnt = torch.bincount(sidx, minlength=B)\n    S = int(cnt.max().item())\n    starts = torch.cumsum(cnt, 0) - cnt\n    pos = torch.arange(T, device=x.device) - starts[sidx]\n    pad = x.new_zeros(B, S, P, D)\n    pad[sidx, pos] = x\n    keep = torch.zeros(B, S, dtype=torch.bool, device=x.device)\n    keep[sidx, pos] = True\n    return (norm(pad.reshape(B, S * P, D)), ~keep.repeat_interleave(P, dim=1))\n\nclass _GatedDelta(nn.Module):\n\n    def __init__(self, d, n_labels, n_heads, dropout):\n        super().__init__()\n        self.q = nn.Parameter(torch.randn(n_labels, d) * 0.02)\n        self.kv_norm = nn.LayerNorm(d)\n        self.attn = nn.MultiheadAttention(d, n_heads, dropout=dropout, batch_first=True)\n        self.d_norm = nn.LayerNorm(d)\n        self.dw = nn.Parameter(torch.randn(n_labels, d) * (1.0 / d ** 0.5))\n        self.db = nn.Parameter(torch.zeros(n_labels))\n        self.gate = nn.Parameter(torch.zeros(n_labels))\n\n    def delta(self, pat, sidx, B, return_attn):\n        kv, kpm = _pad_kv(pat, sidx, B, self.kv_norm)\n        q = self.q.unsqueeze(0).expand(B, -1, -1)\n        att, w = self.attn(q, kv, kv, key_padding_mask=kpm, need_weights=return_attn, average_attn_weights=True)\n        return ((self.d_norm(att) * self.dw).sum(-1) + self.db, w)\n\nclass TokenResidualPool(_GatedDelta):\n\n    def __init__(self, d, n_labels=12, n_heads=6, pe=64, dropout=0.2):\n        super().__init__(d, n_labels, n_heads, dropout)\n        self.base = nn.Sequential(nn.LayerNorm(2 * d + pe), nn.Dropout(dropout), nn.Linear(2 * d + pe, n_labels))\n\n    def forward(self, tok, slot, sidx, B, pres, return_attn=False):\n        base = self.base(torch.cat([_seg_mean_max(tok[:, 1:].mean(1), sidx, B), pres], 1))\n        d_, w = self.delta(tok[:, 1:], sidx, B, return_attn)\n        return (base + self.gate * d_, w)\n\nclass CodexResidualPool(_GatedDelta):\n\n    def __init__(self, d, n_labels=12, n_heads=6, pe=64, dropout=0.2):\n        super().__init__(d, n_labels, n_heads, dropout)\n        self.base = nn.Sequential(nn.LayerNorm(2 * d + pe), nn.Dropout(dropout), nn.Linear(2 * d + pe, n_labels))\n\n    def forward(self, tok, slot, sidx, B, pres, return_attn=False):\n        base = self.base(torch.cat([_seg_mean_max(tok[:, 0], sidx, B), pres], 1))\n        d_, w = self.delta(tok[:, 1:], sidx, B, return_attn)\n        return (base + self.gate * d_, w)\n\nclass ClsAddPool(nn.Module):\n\n    def __init__(self, d, n_labels=12, pe=64, dropout=0.2):\n        super().__init__()\n        self.net = nn.Sequential(nn.LayerNorm(4 * d + pe), nn.Dropout(dropout), nn.Linear(4 * d + pe, n_labels))\n\n    def forward(self, tok, slot, sidx, B, pres, return_attn=False):\n        return (self.net(torch.cat([_seg_mean_max(tok[:, 1:].mean(1), sidx, B), _seg_mean_max(tok[:, 0], sidx, B), pres], 1)), None)\n\nclass Readout(nn.Module):\n\n    def __init__(self, pool, d, n_labels=12, pe=64):\n        super().__init__()\n        self.pool_kind, self.k = (pool, n_labels)\n        self.pres_emb = nn.Embedding(N_SLOT_TYPES + 1, pe, padding_idx=0)\n        if pool in ('xres', 'clsadd', 'xcodex'):\n            self.pool = {'xres': TokenResidualPool, 'clsadd': ClsAddPool, 'xcodex': CodexResidualPool}[pool](d, n_labels, pe=pe)\n        elif pool in ('attn', 'xattn'):\n            if pool == 'xattn':\n                self.pool = TokenXAttnPool(d, n_labels)\n                wd = 3 * d + pe\n            else:\n                self.pool = LabelAttentionPool(d, n_labels)\n                wd = d + pe\n            self.norm = nn.LayerNorm(wd)\n            self.w = nn.Parameter(torch.randn(n_labels, wd) * (1.0 / wd ** 0.5))\n            self.b = nn.Parameter(torch.zeros(n_labels))\n        else:\n            self.pool = MeanMaxPool()\n            self.net = nn.Sequential(nn.LayerNorm(2 * d + pe), nn.Dropout(0.2), nn.Linear(2 * d + pe, n_labels))\n        self.drop = nn.Dropout(0.2)\n\n    def forward(self, f, slot, sidx, B, return_attn=False):\n        pe = self.pres_emb(slot)\n        pres = torch.zeros(B, pe.shape[1], device=f.device, dtype=f.dtype).index_add_(0, sidx, pe)\n        if self.pool_kind in ('xres', 'clsadd', 'xcodex'):\n            return self.pool(f, slot, sidx, B, pres)[0]\n        pooled, attn = self.pool(f, sidx, B, slot=slot, return_attn=return_attn)\n        if self.pool_kind in ('attn', 'xattn'):\n            x = torch.cat([pooled, pres.unsqueeze(1).expand(-1, self.k, -1)], -1)\n            x = self.drop(self.norm(x))\n            return (x * self.w).sum(-1) + self.b\n        return self.net(torch.cat([pooled, pres], 1))\n\nclass Net(nn.Module):\n\n    def __init__(self, enc, cond, n_meta=0, pool='mean_max', stem='native', n_slice=16):\n        super().__init__()\n        self.enc, self.cond = (enc, cond)\n        self.compress = DepthCompress(n_slice, 3) if stem == 'compress' else None\n        self.mixer = SlotDepthMixer(n_slice) if stem == 'mixer' else None\n        self.tokens = pool in ('xattn', 'xres', 'clsadd', 'xcodex')\n        D = enc.num_features\n        self.meta_mlp = nn.Sequential(nn.LayerNorm(n_meta), nn.Linear(n_meta, 128), nn.GELU(), nn.Linear(128, D)) if n_meta > 0 else None\n        self.readout = Readout(pool, D)\n        if cond == 'post':\n            self.slot_emb = nn.Embedding(N_SLOT_TYPES + 1, D, padding_idx=MASK_IDX)\n\n    def forward(self, im, slot, smeta, sidx, B, vm=None):\n        if self.mixer is not None:\n            im = self.mixer(im, slot, vm)\n        if self.compress is not None:\n            im = self.compress(im)\n        f = self.enc.forward_features(im, slot) if self.cond == 'token' else self.enc.forward_features(im)\n        if self.tokens:\n            inner = getattr(self.enc, 'vit', self.enc)\n            orig = getattr(self.enc, '_orig_prefix', getattr(inner, 'num_prefix_tokens', 1))\n            f = torch.cat([f[:, :1], f[:, orig:]], 1)\n        else:\n            f = self.enc.forward_head(f, pre_logits=True)\n            if f.dim() > 2:\n                f = f.flatten(1)\n        ex = (lambda v: v.unsqueeze(1)) if self.tokens else lambda v: v\n        if self.cond == 'post':\n            f = f + ex(self.slot_emb(slot))\n        if self.meta_mlp is not None and smeta.shape[1] > 0:\n            mt = self.meta_mlp(smeta)\n            f = torch.cat([f, mt.unsqueeze(1)], 1) if self.tokens else f + mt\n        return self.readout(f, slot, sidx, B)\nmodels = []\nfor ckpt_path in sorted(CKPT.glob('*_f*.pt')):\n    z = torch.load(ckpt_path, map_location='cpu', weights_only=False)\n    cfg = z['cfg']\n    _stem = cfg.get('stem', 'native')\n    _in = 3 if _stem == 'compress' else cfg.get('n_slice', 16)\n    enc = timm.create_model(cfg['backbone'], pretrained=False, num_classes=0, in_chans=_in, **{'img_size': cfg['img']} if 'vit_' in cfg['backbone'] else {})\n    if cfg['cond'] == 'token':\n        enc = ViTSlotToken(enc, N_SLOT_TYPES)\n    m = Net(enc, cfg['cond'], cfg.get('n_meta', 0), cfg['pool'], stem=_stem, n_slice=cfg.get('n_slice', 16))\n    missing, unexpected = m.load_state_dict(z['state_dict'], strict=False)\n    assert not missing, f'missing {missing[:5]}'\n    assert not unexpected, f'unexpected {unexpected[:5]}'\n    models.append(m.eval())\n    print(f\"loaded {ckpt_path.name}  fold {z['fold']}  {cfg['backbone']} pool={cfg['pool']} meta={cfg['meta']}\")\nCFG = cfg\nassert CFG.get('n_meta', 0) == 0, f\"checkpoint expects {CFG['n_meta']} metadata features -- build slot_meta for the TEST studies and pass it to predict() before submitting\"\nprint(f\"\\n{len(models)} fold models ready | input norm: {CFG.get('norm', 'none')}\")\nAMP_PREF = 'bf16'\n\ndef amp_for(dev):\n    if not str(dev).startswith('cuda'):\n        return (torch.float32, False)\n    cc = torch.cuda.get_device_capability(dev)\n    if AMP_PREF == 'bf16':\n        return (torch.bfloat16, True)\n    if AMP_PREF == 'fp16':\n        return (torch.float16, True)\n    if AMP_PREF == 'fp32':\n        return (torch.float32, False)\n    return (torch.bfloat16 if cc >= (8, 0) else torch.float16, True)\nAMP_DT, AMP_ON = amp_for(DEV)\nWORKERS = max(1, min(4, os.cpu_count() or 4))\nCHUNK = 48\nMICRO = 8\nmodels = [m.to(DEV).eval() for m in models]\nprint(f\"device {DEV} | amp {str(AMP_DT).split('.')[-1]} (on={AMP_ON}) | workers {WORKERS} | chunk {CHUNK} | micro {MICRO}\")\n\ndef _norm_(im):\n    k = CFG.get('norm', 'none')\n    if k == 'zscore':\n        m = (im > 0).float()\n        n = m.sum(dim=(1, 2, 3), keepdim=True).clamp(min=1.0)\n        mu = (im * m).sum(dim=(1, 2, 3), keepdim=True) / n\n        var = (((im - mu) * m) ** 2).sum(dim=(1, 2, 3), keepdim=True) / n\n        return (im - mu) / (var.sqrt() + 1e-06) * m\n    if k == 'imagenet':\n        m = (im > 0).float()\n        return (im - 0.485) / 0.229 * m\n    return im\n\n@torch.no_grad()\ndef _micro(images, masks):\n    dev = DEV\n    ims, slots, sidx, vms = ([], [], [], [])\n    for b in range(len(masks)):\n        present = np.nonzero(masks[b] > 0)[0]\n        if len(present) == 0:\n            continue\n        blk = images[b][present]\n        ims.append(torch.from_numpy(blk))\n        vms.append(torch.from_numpy(blk.reshape(blk.shape[0], blk.shape[1], -1).max(2) > 0))\n        slots.append(torch.from_numpy(present + 1).long())\n        sidx.append(torch.full((len(present),), b, dtype=torch.long))\n    out = np.full((len(models), len(masks), len(LABELS)), np.nan, np.float32)\n    if not ims:\n        return out\n    im = _norm_(torch.cat(ims).to(dev, non_blocking=True).float().div_(255.0))\n    sl = torch.cat(slots).to(dev)\n    si = torch.cat(sidx).to(dev)\n    vm = torch.cat(vms).to(dev)\n    sm = torch.zeros(len(sl), CFG.get('n_meta', 0), device=dev)\n    per = torch.zeros(len(models), len(masks), len(LABELS), device=dev, dtype=torch.float32)\n    with torch.autocast('cuda' if str(dev).startswith('cuda') else 'cpu', dtype=AMP_DT, enabled=AMP_ON):\n        for fold_index, model in enumerate(models):\n            per[fold_index] = torch.sigmoid(model(im, sl, sm, si, len(masks), vm=vm).float())\n    got = per.cpu().numpy()\n    keep = np.array([(masks[b] > 0).any() for b in range(len(masks))])\n    out[:, keep] = got[:, keep]\n    return out\n\ndef predict(images, masks):\n    out = np.full((len(models), len(masks), len(LABELS)), np.nan, np.float32)\n    for a in range(0, len(masks), MICRO):\n        b = min(a + MICRO, len(masks))\n        out[:, a:b] = _micro(images[a:b], masks[a:b])\n    return out\npreds = np.full((len(models), len(studies), len(LABELS)), np.nan, np.float32)\nt0, done = (time.time(), 0)\nwith ProcessPoolExecutor(max_workers=WORKERS) as ex:\n    for c0 in range(0, len(studies), CHUNK):\n        block = studies[c0:c0 + CHUNK]\n        imgs = np.zeros((len(block), N_SLOT, N_SLICE, SIZE, SIZE), np.uint8)\n        msks = np.zeros((len(block), N_SLOT), np.uint8)\n        futs = [ex.submit(build_study, (i, s, by.get(s, []))) for i, s in enumerate(block)]\n        for f in as_completed(futs):\n            try:\n                i, a, k = f.result()\n                imgs[i], msks[i] = (a, k)\n            except Exception as e:\n                print(f'  study failed: {type(e).__name__}: {e}')\n        preds[:, c0:c0 + len(block)] = predict(imgs, msks)\n        done += len(block)\n        el = time.time() - t0\n        print(f'  {done:,}/{len(studies):,}  {el / 60:.1f}m  eta {el / done * (len(studies) - done) / 60:.1f}m', flush=True)\n        del imgs, msks\n        gc.collect()\nprint(f'\\ninference done in {(time.time() - t0) / 60:.1f} min')\nA5_W = 0.45\nA5_LABELS = list(LABELS)\n_a5_ok = np.isfinite(preds).all(axis=(0, 2))\n_a5_rank_mean = np.zeros((len(studies), len(LABELS)), np.float64)\nfor fold_index in range(preds.shape[0]):\n    fold = preds[fold_index][_a5_ok]\n    ordinal = fold.argsort(0).argsort(0).astype(np.float64)\n    _a5_rank_mean[_a5_ok] += ordinal / max(len(fold) - 1, 1)\n_a5_rank_mean /= preds.shape[0]\n_a5_rank_mean[~_a5_ok] = np.nan\nA5_PREDS = dict(zip(sub_df['StudyInstanceUID'].astype(str), _a5_rank_mean.astype(np.float32)))\nfor _a5k, _a5v in _A5_SAVED.items():\n    globals()[_a5k] = _a5v\ndel _A5_SAVED, _a5k, _a5v\n_a5_sub = pd.read_csv('/kaggle/working/submission.csv', dtype={'StudyInstanceUID': str})\nassert _a5_sub.columns.tolist()[1:] == A5_LABELS, 'submission schema drift'\nif A5_W > 0:\n    _a5_ours = np.stack([A5_PREDS[_u] for _u in _a5_sub['StudyInstanceUID'].astype(str)])\n    _a5_base_rank = _a5_sub[A5_LABELS].rank(method='average', pct=True)\n    _a5_ours_rank = pd.DataFrame(_a5_ours, columns=A5_LABELS, index=_a5_sub.index).rank(method='average', pct=True)\n    _a5_sub[A5_LABELS] = (1.0 - A5_W) * _a5_base_rank + A5_W * _a5_ours_rank\n    assert np.isfinite(_a5_sub[A5_LABELS].to_numpy()).all()\n    _a5_sub.to_csv('/kaggle/working/submission.csv', index=False)\n","metadata":{"jupyter":{"source_hidden":true},"papermill":{"duration":12.03597,"end_time":"2026-09-04T02:59:01.676219+00:00","exception":false,"start_time":"2026-09-04T02:58:49.640249+00:00","status":"completed"},"tags":[],"trusted":true},"outputs":[],"execution_count":null},{"id":"ffa1b754-6fd2-4b18-b525-fde8b2f8b36f","cell_type":"code","source":"# DINOSAUR_V4_SNAPSHOT_PRE_RAD_TRANSFORMER\nfrom pathlib import Path as _D4PRPath\nimport hashlib as _d4pr_hashlib\nimport shutil as _d4pr_shutil\n\n_d4pr_work = _D4PRPath('/kaggle/working')\n_d4pr_sub = _d4pr_work / 'submission.csv'\n_d4pr_snap = _d4pr_work / 'submission_dinosaur_v4_pre_rad.csv'\n\nif not _d4pr_sub.is_file():\n    raise FileNotFoundError(_d4pr_sub)\n\n_d4pr_shutil.copyfile(_d4pr_sub, _d4pr_snap)\n\ndef _d4pr_sha(path):\n    h = _d4pr_hashlib.sha256()\n    with path.open('rb') as f:\n        for block in iter(lambda: f.read(8 << 20), b''):\n            h.update(block)\n    return h.hexdigest()\n\nprint(\n    'DINOsaur V4: pre-Rad transformer snapshot preserved | '\n    f'sha256={_d4pr_sha(_d4pr_snap)}',\n    flush=True,\n)\n","metadata":{"tags":["DINOsaur-V4","pre-rad-snapshot"],"trusted":true},"outputs":[],"execution_count":null},{"id":"7f1cfc4a","cell_type":"code","source":"from __future__ import annotations\nimport contextlib as _rad_contextlib\nimport base64 as _rad_b64\nimport zlib as _rad_zlib\nimport gc as _rad_gc\nimport hashlib as _rad_hashlib\nimport json as _rad_json\nimport os as _rad_os\nimport re as _rad_re\nimport time as _rad_time\nfrom concurrent.futures import ThreadPoolExecutor as _RadThreadPool\nfrom pathlib import Path as _RadPath\nimport numpy as _rad_np\nimport pandas as _rad_pd\nimport pydicom as _rad_pydicom\nimport torch as _rad_torch\nimport torch.nn as _rad_nn\nimport torch.nn.functional as _rad_F\nfrom torchvision.models import resnet50 as _rad_resnet50\n_RAD_LABELS = ['ACL', 'MCL', 'Medial Meniscus', 'Lateral Meniscus', 'Medial OA', 'Lateral OA', 'PF OA', 'Effusion', 'Synovitis', \"Baker's\", 'Contusion', 'Fracture']\n_RAD_ALPHA = 0.5\n_RAD_EXCLUDE = (\"Baker's\", 'Fracture')\n_RAD_REFERENCE_HEADS_SHA256 = '0f465649799ecfbccaac1767844639e7ced44e1bc9babde6e4bac7c5d9b89eaa'\n_RAD_ENCODER_SHA256 = '08629f7e7bd3e29b8ee9522ca3f65ce4d010a7ddf74f0ea3c7e3f3d0bbab0734'\n_RAD_E13_HEADS_SHA256 = 'ad9f19af73bfdf4e49263c0e45060dc3cb239e1195039b26dc8c0a3a6bcd1a8a'\n_RAD_E13_MEMBER_WEIGHT = 0.5\n_RAD_V48_SECOND_ALPHA = 0.15\n_RAD_CAL_PAYLOAD = 'eNrtmk1vI8cRhv9KsJdcKKE/q6tzc4z4ZCMBcjQWhrCRDSG2ZEjaIEGQ/57n7RlRQ3KG4jqLJAcDS4o709NdXR9vvVU9/3z30+3N/bvffRuuawgxlm7eq2ePeffrpV8v/V9euvLraD3k6ilW6zn126vYd+U6eKmx9RiaF7OSx+X1weE67K7SdSgpVSauuaecUxr3rtp1LK0HyyV7y9Gmy/E6pBhTL61Zt2gWx+WtSew6JmOoM5AHutXp+ro8+ZrlsnvJOfDdfRL+Kl4zd2bqllNmga7rvrva2OzGNFuynGxpmnxrS/069hCtpt6T1dLLOQVsTbJ1fWunG2qXAX8NiU+7VK8rdqvNU89uwQwjpWyeLdTCnVy84ua9pthSjznHXLjDpZxbLe4WPRAQCT+LrSVcGGdLzNX0XKhesC2eV5uZ67lQPDlmSzUhS2+61ELtoTOyWGjdPudc73fvnj7c/Hg7ElpyzYXjdwIZ32m7X3INZ0crtvtc833ua6fyoUYUGf4H13rJpX+GK5aa5VbeWO9ye/03bLi97i8SpaSCl49nc4gdxI2p1dZyVmQnfL56jBH/j70GqSq6dyMROLHQGvCpcSnkYsyeohNErnVjbamVjs47wOpBa7BAsa61SXulDfSIwAbAkQqDmSK38WwImKK1kFJ3d11CpFqR1mPHlj1pWVAHeDfyU2hk0vGogz0GqCBbKmFMx9xIWEAbQ8I4PUvmAplQCeuij7GNXGMk3yhBsFIfEnvVE6HFYMHDtFuLzKwpya9gisaZduAkcyAvmw1ROjmd7OnBYytpOBqJjTyK4KzT0Pi0tQJYslc0nGqcNZV7dEaRvfcSewg9h4p41iwO+4CWMkNG1326VBmHFUoB7VoakzE+JAtYN/NknS9lLJ+9S5qR56Q2kLA4qgTuplGNmUJAkbXiGbrU0HCIsgtYaGOUVXbayNeykLfpGv8lulBfgiFEmx61xm3LTlrOPoa51Ng7IyJiT4tWxrE0ZmnJRnhawZsyLgjXIC9MRu0tRAgImkJ7bUyHKk1eUgIewtRjXGDJqO1mNJrHfNUty1HRW2SSoV3FAVIA//hrUXKANxhbRbEkgqAFKiCC43qOEXsPTaKtKCdkqx3/koMYsuP+mh4HrHoQtqSIw/h4DM7EpRL5zRirAcHiUDj2SUlr9fFAsElHBX/zWgJCQlw+83Qksw8Pt9+Ty0hmOBQBh9XQAr7fxjRQ2IkGTT/w8cAiBKwRc1jwcMh+WKtMgFShNaDGJWRAechNSOMUldXTynNIUPAaEKKkCv1cLFzxaowBOmX8vU8Pj1voWa5JTPFcGN4QXm+PpZPjA8QQYYp9Qab9rZiIAuLX8AA8f/jX4kHgI+BXCtBEeOTFvNPapIyC92YAEOmHypJcCSiFOpQi712M73IL8KiBX8Hz62pDNsAH8MK/rMR+tNSRIRJwAkIIY8Rn/fD2kB2V9I7BMX+KSJ/XJtNAbwFglmQZbu/90CZcMhAeZKudKAvlSBLwNwP1aA88BYpPdJRkbADGeBzWN2IOvySVELxyU0Lx0JHQHsFpEQRsCB9iO1qT3IOHGUjMDqeczX4BiIbvCjkiLD6t6G239p+gAML1KQuAdaLLdidDV6Y6uPR+9+3LT8KrlYgzAsjg7ok+VJakimvgAjn5qUFmtTGJKXGxSadg2UuLkWok4EvGJ0Hdsr+DmpVlGsUMZkxtuTI8vDAVaIsnSIDbK0DhVSpAFlu4iRtgrLYWRaArADOcFDAfErEdwBS8dWpNqHupW3o7nIukTmxlmASq4L/51ESrznqJTSkgCzslVSMncekb8659ljeyYttxK0oX9k50n3h2kDqoapToWt8S9/yO3tTXyteLu+19rkPViKkIblLnzJhJUhYENUJCtdfWKkEFe9WTsWin6azpqJFIfEwNyLNes+PZXFV3h+tIOXjb5mzIRnCLaWKuhnPtjsCVPAOwdkhQhBSMfWLVruTgwEM/WXt1FYgv5AN4IsyBiHrOSscCBjIomksgZCPFn9grqDrE9UXDQCSPfs5RXyeuQl3gwcEIdn5JzADhpG34s4uF5NQ24eh1GWISkEmYA6iFiNezYAbkKNGJhIk+l9XNXK3r7AgLT4YnRUuHicJS0NRLLG0KDrF1IbkaMzj2MoeKzAH/kTo9KsnWJe8gDZUuxs1iPi0CayABMdLIT4qQCbfENfCiAsujIsj9KMUQ1kXwXUBFZspHZm9Zj/dB/SrVy1qOJg9ApKAlmSQNpr6SjibnNgVoqZQCr8gllgsTiFAOCFSeDcYWuKOChZQXi5dPxouF5Oo6ogVTaxDwnVE8KfQFI6Zomwgb/oI4VG2Ae1MdsTQCwQuZp5ZROZPcdudWHrZRfwe4cPE1cv9L/FDuwRwGNYOttGllMRItS1K3sFDQDAwQMvgpfIzyIeQj2yTFOhomGLsBVPtAASGLqiXKnChASW/4ILUTGlftQlUVl8FDjifbKYIzLKXmco4anNPK6ZVl8MhVBs+D5YgTo8HXuIEDQDJF4wHEYL5PvEExn4PIt7x0JumDeUgjxHeFIZDt+6xN5mALCc6pMjTZ7oy8EomCUA09MTRvvuCLxyFC+sEWCGiqjE+HIAJ4g39Bi5sadSN9MJZaFWLbpubBNBvlmwrPAONJWS1DpaIgbyKuZSbKg7qZzgNKsqnwIX8RAOvINdgfRg0jPNJBWE+5xAQ9qDaAPh4nKInagjAL9otj26U+sAnbUERTF0QYjHV8j8OEA+mohtH9SLLuoUIh6uAWHI6yAw54uEsqL6zufMAAt3yW+6xSFLmKwEmYgIPlXHYbPAo3AvKovCk/0KR5m3fmKkpFz2W3ng58h7KzqVVHqVYUpfGlAJHvQ2dN7QKmXoQITggHUz9HGZhSty5smYHeSL4pFdvbXlXZcSJV7GCHKPpsePEmVAOm41WxbuW3Y+qkrhYhisbrSBqbGiGdAkBwd5gzNehxGUVhzu5JCKa2VAyL2pfYgYgUtcTwu3RKZzO2JublhfCDbO1Qqypu8SdTWO0501Z6iAAH68g21mECvjX8bZZ7yvpViqq9BlHCnhj7DFuiXm8qEwgrAkK9hpfbuU/nN/i4l7I/qQEnpR4qVHUxgDjblWuM2UZFhOpzp+apb8i4ua8gnyHrqPMHs839gK7gaaYDDtILqNTWOF8kxVYdMxlVDwE68/F8DR2CgpCSkkzkEvKY3x9GoRqjpn8ZLj62TyEoRVV1dxrV2GtNOMosPAjqSC6pm6yRKRJFM5wnixbhh6uLl9FdjElsUvX7WxR61T1gGohOkQaej27MxiR+DQjAndQ5SgL4Yb+VMKT2UncGK4se5hfeR7Jr6nygbTJcPGK7QSpXOoBJkuMXlFTYQX0aRsObYEQn22BNrDQdKwmZ1DDaZNcANxumdkGs3pZIJcaCcxBuPSlGziTf+UNZIgqmLMTWS1/XYNBxFowH5FchZb7uT5EQqervUK+Rc15pP55mBpKra6Wju5MCbZwiKOSS/HFuZyVRBFeeIoVrc35oNnVt1ARpKDaHF2BO1z3DLILOrOVZdhIG52ojyFxsVa1k6Bq+sOS7AA0upIqpiCt9Om8+1SsIoI4/ZYFKZq9tdwnhCzrVRpoCxpqSo+0ua1DNLCOMc3X19vGSZZ9znfEAMTUpymSGqYW/kpXU6FWV6+pah9OGLveaTkopOV1d3U9oWfAhMiyK46fRgPeL9LTSDAtUjj5cFN4D8S5zmaCjmaTjJ/Kvxb3MaFrHVI27QS2vRfcMCmeqcUXY+NX6652okyj19OEC3SaFrdWyeyJMxo7gPrANn17GjQ5RgtqvregNjzr1hYOOxATeos4b/IItGRxEFZC4aNruVL1ZbGx8ojpE5moLiGNavazB+baxPoXr/gK56zjI1VGbjtG8nA3Xg3SpFl2gtqzqsM/oGgb5Axj4w+XD1g48MBFrMAnR+TRxMci1+8h+uCC1e1nmC7XEWhf2zEdIw5SsCe3Tcc18XibsU/PKhJhd7a380s67RLEvQQWUw9KKjmps7qefVeub/IZQoLbK0qxnHRFP7qlOy8BURC7Fy2LDPk7N1F1VEm1lrZbSmSWVSoNk63DQXgvIohAjYcjXU7b/zI8u7RVvPiRChSqVjkiU6YQjrT1ImVAAN/WoKEp62V2aQGAdAuQKhSW5qouyIdQ4jNe5NS6I8v10hLIeqIIMqplDn71o0dYl4fEFkRZ4LmhFJNUSQqZCNlBT2fIWnKzJ9XWwG48bOzGZWEIffcVx/q23xAziBV83gf1cE4/+mvI8/EFV3QVmPW0a6rB7ZD314ploTllOSlFYqX3X4u7TJg6jmxLRWxit1FaPtArKoHfHeb3jwPmNGDqfvS+Iv9Ns14Vv6p9rfyft+HGiFqmJIQSU++rlbegPBqDumli9zoOGSptec8O6GAWqtaAgkOgqZ3P1WhQQ08aj2KGONuEIqdZetzuLFB6qQniid8HkZTnlyGsPGnA4lY5Qu1456WnbokG9IupwU0NoPhHTwRRUqynZU0HObV8QUyZuo/lb6tFhsdxb7bCoU9qWe8vLxBwj2laVzgS+bIZGMfee1Qaldl87gBZ5jjr3Y4rq2Xaf3LatohHwxzbqBKtv4d8bHnh1eUqfVRx07jc4zfzySrj8IGV9NMFX4mBKrq6FXc4Jz154/3737u7++fbxw+3Pz9N7eg0X0mHCeHfHbHrNhrCIpdXRA/LRRC4WR9sU/ZqJB46XJsJouwU1rPT+il6uKHqNAdbJ2InUJp0wVWBV7w8NuldU7uMyajZqh2N6UfeoM6ym1zLGizF6T6AnNQZiHO/KZMijZMOV2/yKQFKv0TSXq0Hb5teE9F4HLp50QKJ3OX64edZ7ie+++PLrd7t339z+5e7mx9/88Qt+f82dx5f//Omr6e8fvv/+49Pdwz0/f3/z19vH3z7x68uH++fpKhP+/Pjw/PDh4cfv+Hz86f5Jk99/93T7eHersfff/fnmh/H3y4fH8feLv9/x96ub5+l7vq9f0wj9msf8+HH6fhnDr3kMvzRGG3p8+PizVt3vaXy/ysjox5sPzx8fbxn+7cuWv7m9v3v68PFpsfH9pcWwLc1oyEI3f/7H/cPf7p7vnhZ6ev/+X/8GYIe3xg=='\n_RAD_CAL_W = 0.40\n_RAD_TOKEN_DIM, _RAD_HEAD_DIM = (2048, 512)\n_RAD_E11_SLOTS = [('SAG_NOFS', 'Sagittal', None, False), ('COR_NOFS', 'Coronal', None, False), ('AX_NOFS', 'Axial', None, False), ('SAG_FS', 'Sagittal', None, True)]\n_RAD_E11_CROP_MM = 130.0\n_RAD_E13_SLOTS = [('SAG_FS', 'Sagittal', None, True), ('COR_FS', 'Coronal', None, True), ('AX_FS', 'Axial', None, True), ('SAG_NOFS', 'Sagittal', None, False)]\n_RAD_E13_CROP_MM = 130.0\n_RAD_E13_CACHE_SLICES = 8\n_RAD_E13_IMG = 224\nSLOTS = [('SAG_FS', 'Sagittal', None, True), ('COR_FS', 'Coronal', None, True), ('AX_FS', 'Axial', None, True)]\nN_SLOT = len(SLOTS)\nCACHE_SLICES = 8\n\ndef _rad_sha256(path, chunk=8 << 20):\n    digest = _rad_hashlib.sha256()\n    with open(path, 'rb') as handle:\n        for block in iter(lambda: handle.read(chunk), b''):\n            digest.update(block)\n    return digest.hexdigest()\n\ndef _rad_find_file(name, expected_sha=None, explicit_env=None):\n    files = {_RAD_ENCODER_SHA256: ASSET / 'resnet-50-radimagenet-marwan/ResNet50.pt', _RAD_REFERENCE_HEADS_SHA256: ASSET / 'rsna-knee-e9-radimagenet-heads-v15/v52_radimagenet_heads.pt', _RAD_E13_HEADS_SHA256: ASSET / 'kernel-sources/rsna-knee-e13-train/rsna_rad_e11/v52_e11_heads.pt'}\n    path = files.get(expected_sha)\n    if path is None or not path.is_file():\n        raise FileNotFoundError(name)\n    if _rad_sha256(path) != expected_sha:\n        raise RuntimeError(f'hash mismatch for {path}')\n    return path\n\nclass _RadEncoder(_rad_nn.Module):\n\n    def __init__(self):\n        super().__init__()\n        self.backbone = _rad_nn.Sequential(*list(_rad_resnet50(weights=None).children())[:-2])\n\n    def forward(self, image):\n        return self.backbone(image).mean(dim=(2, 3))\n\nclass _RadHead(_rad_nn.Module):\n\n    def __init__(self):\n        super().__init__()\n        self.project = _rad_nn.Sequential(_rad_nn.LayerNorm(_RAD_TOKEN_DIM), _rad_nn.Linear(_RAD_TOKEN_DIM, _RAD_HEAD_DIM), _rad_nn.GELU())\n        self.plane = _rad_nn.Parameter(_rad_torch.randn(N_SLOT, _RAD_HEAD_DIM) * 0.01)\n        self.position = _rad_nn.Parameter(_rad_torch.randn(CACHE_SLICES, _RAD_HEAD_DIM) * 0.01)\n        self.query = _rad_nn.Parameter(_rad_torch.randn(len(_RAD_LABELS), _RAD_HEAD_DIM) * 0.02)\n        self.attn = _rad_nn.MultiheadAttention(_RAD_HEAD_DIM, 8, dropout=0.1, batch_first=True)\n        self.fuse = _rad_nn.Sequential(_rad_nn.LayerNorm(_RAD_HEAD_DIM * 4), _rad_nn.Linear(_RAD_HEAD_DIM * 4, _RAD_HEAD_DIM), _rad_nn.GELU(), _rad_nn.Dropout(0.15))\n        self.weight = _rad_nn.Parameter(_rad_torch.randn(len(_RAD_LABELS), _RAD_HEAD_DIM) * 0.02)\n        self.bias = _rad_nn.Parameter(_rad_torch.zeros(len(_RAD_LABELS)))\n\n    def forward(self, feature, mask):\n        token = self.project(feature.float())\n        token = token.view(len(token), N_SLOT, CACHE_SLICES, _RAD_HEAD_DIM)\n        token = token + self.plane[None, :, None] + self.position[None, None]\n        token = token.flatten(1, 2)\n        key_padding = mask <= 0\n        all_empty = key_padding.all(1)\n        if all_empty.any():\n            key_padding = key_padding.clone()\n            key_padding[all_empty, 0] = False\n        query = self.query.unsqueeze(0).expand(len(token), -1, -1)\n        attended = query + self.attn(query, token, token, key_padding_mask=key_padding, need_weights=False)[0]\n        denominator = mask.sum(1, keepdim=True).clamp_min(1).unsqueeze(-1)\n        mean = (token * mask.unsqueeze(-1)).sum(1, keepdim=True) / denominator\n        mean = mean.expand(-1, len(_RAD_LABELS), -1)\n        fused = self.fuse(_rad_torch.cat([attended, mean, _rad_torch.abs(attended - mean), attended * mean], dim=-1))\n        return (fused * self.weight.unsqueeze(0)).sum(-1) + self.bias\n\ndef _rad_load_public_heads(device, expected_sha):\n    heads_path = _rad_find_file('v52_radimagenet_heads.pt', expected_sha)\n    payload = _rad_torch.load(heads_path, map_location='cpu', weights_only=True)\n    expected = {'version': 'v52-radimagenet-resnet50-official-1', 'targets': _RAD_LABELS, 'encoder_sha256': _RAD_ENCODER_SHA256, 'encoder_source_commit': '0ce16f7375db4236e646829d1eca61cdb4282133', 'img': 224, 'slices_per_plane': 8, 'feature': 'global_average_pool'}\n    for key, value in expected.items():\n        if payload.get(key) != value:\n            raise RuntimeError(f'public-v15 head contract drift for {key}')\n    folds = payload.get('folds')\n    if not isinstance(folds, list) or len(folds) != 5:\n        raise RuntimeError('public-v15 bundle requires exactly five heads')\n    if sorted((int(record.get('fold', -1)) for record in folds)) != list(range(5)):\n        raise RuntimeError('public-v15 fold identity drift')\n    heads = []\n    for record in folds:\n        head = _RadHead().to(device).eval()\n        head.load_state_dict(record['state_dict'], strict=True)\n        heads.append(head)\n    return (heads, str(heads_path))\n\ndef _rad_load_e13_heads(device):\n    heads_path = _rad_find_file('v52_e11_heads.pt', _RAD_E13_HEADS_SHA256)\n    payload = _rad_torch.load(heads_path, map_location='cpu', weights_only=False)\n    expected = {'version': 'e11-radimagenet-resnet50-diverse-1', 'targets': _RAD_LABELS, 'encoder_sha256': _RAD_ENCODER_SHA256, 'slots': [list(slot) for slot in _RAD_E13_SLOTS], 'crop_mm': _RAD_E13_CROP_MM, 'img': _RAD_E13_IMG, 'slices_per_plane': _RAD_E13_CACHE_SLICES, 'feature': 'global_average_pool'}\n    for key, value in expected.items():\n        if payload.get(key) != value:\n            raise RuntimeError(f'E13 head contract drift for {key}')\n    folds = payload.get('folds')\n    if not isinstance(folds, list) or len(folds) != 5:\n        raise RuntimeError('E13 bundle requires exactly five heads')\n    if sorted((int(record.get('fold', -1)) for record in folds)) != list(range(5)):\n        raise RuntimeError('E13 fold identity drift')\n    heads = []\n    for record in folds:\n        head = _RadHead().to(device).eval()\n        head.load_state_dict(record['state_dict'], strict=True)\n        heads.append(head)\n    return (heads, str(heads_path))\n\n@_rad_torch.inference_mode()\ndef _rad_encode(encoder, pixels, slot_mask, device):\n    n, slots, slices, height, width = pixels.shape\n    features = _rad_np.zeros((n, slots * slices, _RAD_TOKEN_DIM), _rad_np.float16)\n    token_mask = _rad_np.repeat(slot_mask[:, :, None], slices, axis=2).reshape(n, -1)\n    valid = _rad_np.flatnonzero(token_mask.reshape(-1) > 0)\n    flat = pixels.reshape(-1, height, width)\n    batch = 192 if device.type == 'cuda' and _rad_torch.cuda.device_count() > 1 else 96 if device.type == 'cuda' else 8\n    for start in range(0, len(valid), batch):\n        indices = valid[start:start + batch]\n        image = _rad_torch.from_numpy(flat[indices]).to(device).float().div_(127.5).sub_(1.0)\n        image = image.unsqueeze(1).expand(-1, 3, -1, -1).contiguous()\n        amp = _rad_torch.autocast('cuda') if device.type == 'cuda' else _rad_contextlib.nullcontext()\n        with amp:\n            feature = encoder(image)\n        values = feature.float().cpu().numpy()\n        if not _rad_np.isfinite(values).all():\n            raise RuntimeError('V36 non-finite RadImageNet feature')\n        features.reshape(-1, _RAD_TOKEN_DIM)[indices] = values.astype(_rad_np.float16)\n    return (features, token_mask.astype(_rad_np.float32))\n\n@_rad_torch.inference_mode()\ndef _rad_predict_head(head, features, masks, device, batch=64):\n    predictions = []\n    for start in range(0, len(features), batch):\n        image = _rad_torch.from_numpy(features[start:start + batch]).to(device)\n        mask = _rad_torch.from_numpy(masks[start:start + batch]).to(device)\n        amp = _rad_torch.autocast('cuda') if device.type == 'cuda' else _rad_contextlib.nullcontext()\n        with amp:\n            predictions.append(_rad_torch.sigmoid(head(image, mask)).float().cpu())\n    return _rad_torch.cat(predictions).numpy()\n\ndef _rad_rank_columns(values):\n    return _rad_pd.DataFrame(_rad_np.asarray(values, dtype=_rad_np.float64)).rank(method='average', pct=True).to_numpy(_rad_np.float64)\n\ndef _rad_validate(frame, expected_ids):\n    if frame.columns.tolist() != ['StudyInstanceUID', *_RAD_LABELS]:\n        raise RuntimeError('V36 submission schema drift')\n    ids = frame['StudyInstanceUID'].astype(str).tolist()\n    if ids != list(map(str, expected_ids)) or len(ids) != len(set(ids)):\n        raise RuntimeError('V36 submission study identity/order drift')\n    values = frame[_RAD_LABELS].to_numpy(_rad_np.float64)\n    if not _rad_np.isfinite(values).all() or values.min() < 0 or values.max() > 1:\n        raise RuntimeError('V36 invalid submission values')\n\n\ndef _v18_cal_protocol(uids):\n    frame = _rad_pd.read_csv(\n        ROOT / 'test_series.csv',\n        dtype={\n            'StudyInstanceUID': str,\n            'SeriesInstanceUID': str,\n        },\n    )\n\n    frame['StudyInstanceUID'] = (\n        frame['StudyInstanceUID'].astype(str)\n    )\n\n    index = _rad_pd.Index(\n        [str(uid) for uid in uids],\n        name='StudyInstanceUID',\n    )\n\n    table = _rad_pd.DataFrame(index=index)\n\n    table['n_series'] = (\n        frame.groupby('StudyInstanceUID')\n        .size()\n        .reindex(index)\n        .fillna(0)\n    )\n\n    for plane in (\n        'Sagittal',\n        'Coronal',\n        'Axial',\n    ):\n        part = frame[\n            frame['Anatomical_Plane']\n            .astype(str)\n            .eq(plane)\n        ]\n\n        table[f'n_{plane[:3]}'] = (\n            part.groupby('StudyInstanceUID')\n            .size()\n            .reindex(index)\n            .fillna(0)\n        )\n\n    for flag in (\n        'Fat_Suppression',\n        'Fluid_Sensitive',\n    ):\n        marked = frame[\n            _rad_pd.to_numeric(\n                frame[flag],\n                errors='coerce',\n            )\n            .fillna(0)\n            > 0\n        ]\n\n        prefix = flag[:3]\n\n        table[prefix] = (\n            marked.groupby('StudyInstanceUID')\n            .size()\n            .reindex(index)\n            .fillna(0)\n        )\n\n        for plane in (\n            'Sagittal',\n            'Coronal',\n            'Axial',\n        ):\n            part = marked[\n                marked['Anatomical_Plane']\n                .astype(str)\n                .eq(plane)\n            ]\n\n            table[f'{prefix}_{plane[:3]}'] = (\n                part.groupby('StudyInstanceUID')\n                .size()\n                .reindex(index)\n                .fillna(0)\n            )\n\n    return table\n\n\ndef _v18_calibrate_transformer(\n    branch,\n    baseline_rank,\n    public_rank,\n    pass2_rank,\n    expected_ids,\n):\n    payload = _rad_json.loads(\n        _rad_zlib.decompress(\n            _rad_b64.b64decode(\n                _RAD_CAL_PAYLOAD\n            )\n        ).decode()\n    )\n\n    gate = set(payload['gate'])\n\n    protocol = _v18_cal_protocol(\n        expected_ids\n    )\n\n    if (\n        protocol.columns.tolist()\n        != list(\n            payload[\n                'protocol_columns'\n            ]\n        )\n    ):\n        raise RuntimeError(\n            'V18 calibration protocol '\n            'layout mismatch'\n        )\n\n    mean_rank = (\n        baseline_rank\n        + public_rank\n        + pass2_rank\n    ) / 3.0\n\n    blocks = [\n        baseline_rank,\n        public_rank,\n        pass2_rank,\n        public_rank - baseline_rank,\n        pass2_rank - baseline_rank,\n        mean_rank,\n    ]\n\n    for group in payload['groups']:\n        columns = [\n            _RAD_LABELS.index(target)\n            for target in group\n        ]\n\n        blocks.append(\n            mean_rank[\n                :,\n                columns,\n            ].mean(\n                axis=1,\n                keepdims=True,\n            )\n        )\n\n    blocks.append(\n        protocol.to_numpy(\n            _rad_np.float64\n        )\n    )\n\n    x = _rad_np.concatenate(\n        blocks,\n        axis=1,\n    )\n\n    centre = _rad_np.asarray(\n        payload['mean'],\n        _rad_np.float64,\n    )\n    spread = _rad_np.asarray(\n        payload['scale'],\n        _rad_np.float64,\n    )\n    coef = _rad_np.asarray(\n        payload['coef'],\n        _rad_np.float64,\n    )\n    bias = _rad_np.asarray(\n        payload['intercept'],\n        _rad_np.float64,\n    )\n\n    if (\n        x.shape[1] != 88\n        or coef.shape != (\n            len(_RAD_LABELS),\n            88,\n        )\n    ):\n        raise RuntimeError(\n            f'V18 calibration feature drift: '\n            f'x={x.shape}, coef={coef.shape}'\n        )\n\n    spread = _rad_np.where(\n        _rad_np.abs(spread) > 1e-8,\n        spread,\n        1.0,\n    )\n\n    adjusted = _rad_rank_columns(\n        (\n            (\n                x - centre\n            )\n            / spread\n        )\n        @ coef.T\n        + bias\n    )\n\n    output = branch.copy()\n\n    values = output[\n        _RAD_LABELS\n    ].to_numpy(\n        _rad_np.float64\n    ).copy()\n\n    for index, target in enumerate(\n        _RAD_LABELS\n    ):\n        if target in gate:\n            values[\n                :,\n                index,\n            ] = (\n                (\n                    1.0\n                    - _RAD_CAL_W\n                )\n                * values[\n                    :,\n                    index,\n                ]\n                + _RAD_CAL_W\n                * adjusted[\n                    :,\n                    index,\n                ]\n            )\n\n    output[\n        _RAD_LABELS\n    ] = _rad_rank_columns(\n        values\n    )\n\n    _rad_validate(\n        output,\n        expected_ids,\n    )\n\n    return output, gate\n\n\n\ndef _rad_main():\n    work = _RadPath('/kaggle/working')\n    primary = work / 'submission.csv'\n    test = _rad_pd.read_csv(ROOT / 'test.csv', dtype={'StudyInstanceUID': str})\n    expected_ids = test.StudyInstanceUID.astype(str).tolist()\n    baseline = _rad_pd.read_csv(primary, dtype={'StudyInstanceUID': str})\n    _rad_validate(baseline, expected_ids)\n    device = _rad_torch.device('cuda:0')\n    test_series = _rad_pd.read_csv(ROOT / 'test_series.csv', dtype={'StudyInstanceUID': str, 'SeriesInstanceUID': str})\n    plane = dict(zip(test_series.SeriesInstanceUID, test_series.Anatomical_Plane))\n\n    def cache(slots, crop, tag, threshold):\n        globals().update(SLOTS=list(slots), N_SLOT=len(slots), CACHE_SLICES=8, IMG=224, CACHE_IMG=224, CROP_MM=float(crop), RULES=dict(RULES_LEGACY))\n        headers = annotate(walk('test_series'))\n        studies, pixels, masks = build_cache(pick_slots(headers, plane), plane, lat_of(headers, tag + ' '), tag)\n        positions = {str(uid): index for index, uid in enumerate(studies)}\n        missing = [uid for uid in expected_ids if uid not in positions]\n        if missing:\n            raise RuntimeError(f'{len(missing)} studies absent from {tag}')\n        order = _rad_np.asarray([positions[uid] for uid in expected_ids], dtype=_rad_np.int64)\n        pixels, masks = (pixels[order], masks[order])\n        tokens = int(_rad_np.repeat(masks[:, :, None], CACHE_SLICES, axis=2).sum())\n        if tokens < int(threshold * len(test) * N_SLOT * CACHE_SLICES):\n            raise RuntimeError(f'insufficient slices for {tag}: {tokens}')\n        return (pixels, masks)\n    public_slots = [('SAG_FS', 'Sagittal', None, True), ('COR_FS', 'Coronal', None, True), ('AX_FS', 'Axial', None, True)]\n    pixels, masks = cache(public_slots, 10000.0, 'test-e10', 0.85)\n    encoder_path = _rad_find_file('ResNet50.pt', _RAD_ENCODER_SHA256)\n    encoder = _RadEncoder()\n    encoder.load_state_dict(_rad_torch.load(encoder_path, map_location='cpu', weights_only=True), strict=True)\n    encoder.eval().to(device)\n    for parameter in encoder.parameters():\n        parameter.requires_grad_(False)\n    if _rad_torch.cuda.device_count() > 1:\n        encoder = _rad_nn.DataParallel(encoder, device_ids=list(range(_rad_torch.cuda.device_count())))\n    reference_heads, _ = _rad_load_public_heads(device, _RAD_REFERENCE_HEADS_SHA256)\n    features, token_mask = _rad_encode(encoder, pixels, masks, device)\n    reference_predictions = [_rad_predict_head(head, features, token_mask, device) for head in reference_heads]\n    reference_probability = _rad_np.mean(_rad_np.stack(reference_predictions), axis=0)\n    reference_rank = _rad_rank_columns(reference_probability)\n    del reference_predictions, reference_heads\n    del reference_probability, features, token_mask, pixels, masks\n    _rad_gc.collect()\n    _rad_torch.cuda.empty_cache()\n    globals().update(SLOTS=list(_RAD_E13_SLOTS), N_SLOT=len(_RAD_E13_SLOTS), CACHE_SLICES=_RAD_E13_CACHE_SLICES, IMG=_RAD_E13_IMG, CACHE_IMG=_RAD_E13_IMG, CROP_MM=_RAD_E13_CROP_MM, RULES=dict(RULES_LEGACY))\n    e13_heads, _ = _rad_load_e13_heads(device)\n    pixels, masks = cache(_RAD_E13_SLOTS, _RAD_E13_CROP_MM, 'test-e13', 0.85)\n    features, token_mask = _rad_encode(encoder, pixels, masks, device)\n    e13_predictions = [_rad_predict_head(head, features, token_mask, device) for head in e13_heads]\n    e13_probability = _rad_np.mean(_rad_np.stack(e13_predictions), axis=0)\n    e13_rank = _rad_rank_columns(e13_probability)\n    reference_rank = _rad_rank_columns((1.0 - _RAD_E13_MEMBER_WEIGHT) * reference_rank + _RAD_E13_MEMBER_WEIGHT * e13_rank)\n    del e13_predictions, e13_probability, e13_rank\n    del features, token_mask, pixels, masks\n    _rad_gc.collect()\n    _rad_torch.cuda.empty_cache()\n    baseline_rank = _rad_rank_columns(baseline[_RAD_LABELS].to_numpy())\n    e10 = baseline.copy()\n    for index, target in enumerate(_RAD_LABELS):\n        if target not in _RAD_EXCLUDE:\n            e10[target] = (1.0 - _RAD_ALPHA) * baseline_rank[:, index] + _RAD_ALPHA * reference_rank[:, index]\n    _rad_validate(e10, expected_ids)\n    pixels, masks = cache(_RAD_E11_SLOTS, _RAD_E11_CROP_MM, 'test-v48-pass2', 0.55)\n    features, token_mask = _rad_encode(encoder, pixels, masks, device)\n    pass2_predictions = [_rad_predict_head(head, features, token_mask, device) for head in e13_heads]\n    pass2_probability = _rad_np.mean(_rad_np.stack(pass2_predictions), axis=0)\n    pass2_rank = _rad_rank_columns(pass2_probability)\n    final = e10.copy()\n    final[_RAD_LABELS] = (\n        (1.0 - _RAD_V48_SECOND_ALPHA)\n        * _rad_rank_columns(\n            e10[_RAD_LABELS].to_numpy()\n        )\n        + _RAD_V48_SECOND_ALPHA\n        * pass2_rank\n    )\n\n    final[_RAD_LABELS] = _rad_rank_columns(\n        final[_RAD_LABELS].to_numpy()\n    )\n\n    _rad_validate(\n        final,\n        expected_ids,\n    )\n\n    globals()['V18_TRANSFORMER_RAW'] = (\n        final.copy()\n    )\n    globals()['V18_CALIBRATOR_APPLIED'] = False\n    globals()['V18_CAL_GATE'] = tuple()\n\n    try:\n        calibrated, gate = (\n            _v18_calibrate_transformer(\n                final,\n                baseline_rank,\n                reference_rank,\n                pass2_rank,\n                expected_ids,\n            )\n        )\n\n        final = calibrated\n\n        globals()[\n            'V18_TRANSFORMER_CAL'\n        ] = final.copy()\n\n        globals()[\n            'V18_CALIBRATOR_APPLIED'\n        ] = True\n\n        globals()[\n            'V18_CAL_GATE'\n        ] = tuple(\n            sorted(gate)\n        )\n\n        print(\n            '[V18] 88-feature transformer '\n            'calibration applied to: '\n            + ', '.join(\n                sorted(gate)\n            ),\n            flush=True,\n        )\n\n    except Exception as exc:\n        print(\n            '[V18] calibration skipped '\n            'safely; raw transformer kept: '\n            f'{type(exc).__name__}: {exc}',\n            flush=True,\n        )\n\n    _rad_validate(\n        final,\n        expected_ids,\n    )\n\n    final.to_csv(\n        primary,\n        index=False,\n    )\n_rad_main()\n","metadata":{"jupyter":{"source_hidden":true},"papermill":{"duration":9.031485,"end_time":"2026-09-04T02:59:10.736437+00:00","exception":false,"start_time":"2026-09-04T02:59:01.704952+00:00","status":"completed"},"tags":[],"trusted":true},"outputs":[],"execution_count":null},{"id":"08ac5c23","cell_type":"code","source":"# RAPTOR_FOUR_VIEW_PROBABILITY_ENSEMBLE_V40\n# Global weights: v5=.55, v10=.10, reverse-v5=.15, v8=.20; outer=0.60\n#!/usr/bin/env python3\n\"\"\"Knee MRI: twelve findings from a single model\n\nThis notebook takes a knee MRI study and scores twelve findings at once: ACL tear, MCL tear,\nmedial and lateral meniscus tears, osteoarthritis in the medial, lateral and patellofemoral\ncompartments, joint effusion, synovitis, a Baker's cyst, bone contusion and fracture. It scores\n0.924 on the public leaderboard using one model, with no ensembling and no test-time augmentation.\n\nThis is the inference half of the work. The model was trained separately and its weights are\nattached as a dataset, so this notebook only loads them and predicts:\nhttps://www.kaggle.com/datasets/dreaddevelopment/raptor-knee-widedense\n\nWhere the training labels came from\n\nWorth saying up front, because it shapes everything else. The competition gives you 4,407 studies\nbut structured labels for only 58 of them. Every other study arrives with a free-text radiology\nreport and nothing more, so there is very little to train against out of the box.\n\nThe labels behind these weights were made by reading those reports with a language model and\nturning each into twelve probabilities rather than twelve yes or no answers. A report that says a\ntear is suspected becomes a number near 0.8, not a 1, which is a fairer target than forcing every\nhedged sentence into a hard label. That yields 4,349 studies to train on. The 58 studies that came\nwith real labels were never trained on and are used to check the result honestly; the model reaches\n0.9167 macro-AUC on them.\n\nBuilding a fixed input from studies that are all shaped differently\n\nThe hard part of this competition is not the network, it is that no two studies look alike. A\nstudy holds several DICOM series shot in different planes, the number of series varies, and the\nnumber of slices in a series varies more. Anything that expects a fixed-size input has to be given\none.\n\nThe approach here is to fill five fixed slots per study, always in the same order, for a stack of\n64 images:\n\n  18 slices from a sagittal series, preferring a fluid-sensitive one\n  14 slices from a second sagittal series, preferring one that is not fluid-sensitive\n  12 slices from a coronal series, preferring a fluid-sensitive one\n   8 slices from a second coronal series\n  12 slices from an axial series\n\nPreferring a fluid-sensitive series for some slots and not for others is deliberate. Fluid-\nsensitive sequences show swelling, effusion and acute injury clearly, while the other sequences\nshow anatomy and cartilage better, and the twelve findings are split across both. If a study has\nno series for a slot, the slot is left as zeros and the model is told to skip it rather than being\nfed something misleading.\n\nWithin a series, slices are taken evenly across 6 to 94 percent of the stack rather than from the\nmiddle. The outer slices are where the collateral ligaments and the lateral meniscus sit, and\ncutting them was measurably costing accuracy on exactly those findings.\n\nEvery slice is cropped to a 140 mm box around the centre of the image using the pixel spacing from\nthe DICOM header, then resized to 336 pixels. Cropping by millimetres rather than by pixel count\nmatters: it means a knee occupies the same fraction of the frame whether the scan was acquired at\n0.3 or 0.5 mm per pixel, so the model is not asked to learn scale differences that carry no medical\ninformation.\n\nHow the model reads the stack\n\nThree neighbouring slices are stacked into the three channels of one image. The network then sees\na little of what lies above and below the slice in the middle, which is most of the benefit of a 3D\nmodel at the cost of a 2D one. Each of these three-slice windows is passed through a CoAtNet\nbackbone at 384 pixels.\n\nThe windows are combined with an attention layer that has separate weights for each of the twelve\nfindings. This is the part that matters most. A cruciate tear may be visible on two sagittal slices\nwhile osteoarthritis is spread across many coronal ones, and a single pooled score forces those two\nto share one notion of which slices are important. Giving each finding its own attention weights\nlets each one draw on the slices that actually show it.\n\nRunning it\n\nScoring uses 42 windows per study. Inference runs in half precision and automatically retries a\nstudy in full precision if it fails, so no study is ever dropped from the submission. The notebook\nneeds no internet: the backbone is loaded from the attached weights rather than downloaded.\n\"\"\"\nimport os, sys, glob, time, json, gc\nos.environ.setdefault(\"HF_HUB_OFFLINE\", \"1\")\nos.environ.setdefault(\"TRANSFORMERS_OFFLINE\", \"1\")\nos.environ.setdefault(\"HF_HUB_DISABLE_TELEMETRY\", \"1\")\nimport numpy as np\nimport torch, torch.nn as nn, torch.nn.functional as F\nimport timm\n# T4 (Turing) cuDNN v9 has fp16/fp32 conv engines but NOT bf16 for these shapes\n# (\"GET was unable to find an engine...\"); benchmark lets it pick a valid algo for\n# the fixed (1,24,3,res,res) input.\ntorch.backends.cudnn.benchmark = True\ntorch.backends.cuda.matmul.allow_tf32 = True\n\n# ---- fixed config (must match training exactly) -----------------------------\n# Defaults are overwritten from each arm's immutable pixel contract before inference.\nIMG = 336\nCROP_MM = 140.0\nSPAN_LO, SPAN_HI = 0.02, 0.98\nSLOTS = [(\"Sagittal\", 1, 18), (\"Sagittal\", 0, 14), (\"Coronal\", 1, 12),\n         (\"Coronal\", 0, 8), (\"Axial\", -1, 12)]\nMAXS = sum(s[2] for s in SLOTS)\nK_EVAL = 62\nNORM = \"imagenet\"\nLAB = [\"ACL\", \"MCL\", \"Medial Meniscus\", \"Lateral Meniscus\", \"Medial OA\", \"Lateral OA\",\n       \"PF OA\", \"Effusion\", \"Synovitis\", \"Baker's\", \"Contusion\", \"Fracture\"]\n_MEAN = torch.tensor([0.485, 0.456, 0.406]).view(3, 1, 1)\n_STD = torch.tensor([0.229, 0.224, 0.225]).view(3, 1, 1)\n\n# Three arms: (weights filename, fallback arch, fallback res). ck carries arch+res too.\n# Selected 2026-08-19 by greedy forward selection AND exhaustive subset search over a 7-arm\n# panel on the 45-study gold set (phase2/blend_panel.py); both agree on this exact set.\n# Singles: coatnet384 0.9025 | swinbase384 0.8825 | effv2l480 0.8716.\n# Blend {coatnet+swin+effv2l} = 0.9068 (2-arm {coatnet+swin} = 0.9059, coatnet alone 0.9025).\n# Dropped as redundant: cnn336 (0.8833, the former champion), cnbase384 (0.8754),\n# cnlarge384 (0.8752), maxvit384 (0.8438).\n#\n# SINGLE ARM: coatnet_rmlp_2_rw_384 retrained on the EXPANDED 4,349-study corpus.\n#\n# Why one arm and not the 3-arm blend: on the live leaderboard CoAtNet alone scored 0.914 while\n# every blend scored 0.914-0.915, so ensembling is worth ~+0.001 there -- the ~+0.010 it showed\n# on the old 45-study gold set was gold-set noise. One arm is also 1/3 the kernel runtime.\n#\n# Corpus expansion: the corpus previously held 3,200 of the 4,349 labelled studies and only 45\n# of the 58 gold studies. Rebuilt to 4,407 studies (+37.8% training data, 58-study gate).\n#\n# Measured on the 58-study gate (the incumbent re-scored on the SAME gate for a fair compare):\n#   incumbent CoAtNet (3,155-study corpus) 0.8923\n#   this model       (4,349-study corpus) 0.9054   (+0.0131, better in 92.7% of 2000 bootstraps)\n# Biggest gains land on the findings that were capping us: Lateral Meniscus +0.071,\n# Fracture +0.057, Lateral OA +0.048, Medial Meniscus +0.035, ACL +0.028.\n# Four globally weighted views.  Weights and the 0.70 outer blend were frozen\n# after the same configuration improved both Gold58 anchor constructions.  There is\n# no per-target routing: every finding receives the same estimator.\n_SLOTS64 = [(\"Sagittal\", 1, 18), (\"Sagittal\", 0, 14), (\"Coronal\", 1, 12),\n            (\"Coronal\", 0, 8), (\"Axial\", -1, 12)]\n_SLOTS44 = [(\"Sagittal\", 1, 12), (\"Sagittal\", 0, 10), (\"Coronal\", 1, 8),\n            (\"Coronal\", 0, 6), (\"Axial\", -1, 8)]\nARMS = [\n    {\"name\": \"maxspan-v5\", \"file\": \"raptor_ft_coatnet_v5_full_swa.pt\",\n     \"arch\": \"coatnet_rmlp_2_rw_384.sw_in12k_ft_in1k\", \"res\": 384,\n     \"img\": 336, \"slots\": _SLOTS64, \"span\": (0.02, 0.98), \"k_eval\": 62,\n     \"reverse\": False, \"w\": 0.55},\n    {\"name\": \"native384dense-v10\", \"file\": \"raptor_ft_coatnet_v10_full.pt\",\n     \"arch\": \"coatnet_rmlp_2_rw_384.sw_in12k_ft_in1k\", \"res\": 384,\n     \"img\": 384, \"slots\": _SLOTS64, \"span\": (0.02, 0.98), \"k_eval\": 62,\n     \"reverse\": False, \"w\": 0.10},\n    {\"name\": \"maxspan-v5-reverse\", \"file\": \"raptor_ft_coatnet_v5_full_swa.pt\",\n     \"arch\": \"coatnet_rmlp_2_rw_384.sw_in12k_ft_in1k\", \"res\": 384,\n     \"img\": 336, \"slots\": _SLOTS64, \"span\": (0.02, 0.98), \"k_eval\": 62,\n     \"reverse\": True, \"w\": 0.15},\n    {\"name\": \"native384-v8\", \"file\": \"raptor_ft_coatnet_v8_full_swa.pt\",\n     \"arch\": \"coatnet_rmlp_2_rw_384.sw_in12k_ft_in1k\", \"res\": 384,\n     \"img\": 384, \"slots\": _SLOTS44, \"span\": (0.06, 0.94), \"k_eval\": 42,\n     \"reverse\": False, \"w\": 0.20},\n]\n\n\n# ============================================================================\n# Model -- verbatim from finetune_raptor.py\n# ============================================================================\ndef build_backbone(arch, pretrained=False):\n    # maxvit/maxxvit/coatnet are conv-attention hybrids: NO CLS token, NO interpolatable\n    # pos-embed -> avg pool. The \"vit\" substring in \"coatnet\"/\"maxvit\" must NOT route them\n    # down the ViT path (mirrors finetune_raptor.py exactly).\n    hybrid = arch.startswith((\"maxvit\", \"maxxvit\", \"coatnet\", \"coat_\", \"convnext\"))\n    is_vit = (not hybrid) and any(k in arch for k in (\"vit\", \"deit\", \"dinov2\", \"eva\", \"beit\"))\n    kw = dict(pretrained=pretrained, num_classes=0, in_chans=3)\n    if is_vit:\n        kw.update(global_pool=\"token\", dynamic_img_size=True)\n    else:\n        kw.update(global_pool=\"avg\")\n    return timm.create_model(arch, **kw)\n\n\nclass RaptorClassifier(nn.Module):\n    def __init__(self, backbone, F_dim=768, n=12, drop=0.2):\n        super().__init__()\n        self.backbone = backbone\n        self.norm = nn.LayerNorm(F_dim)\n        self.att = nn.Sequential(nn.Linear(F_dim, 256), nn.Tanh(), nn.Dropout(drop),\n                                 nn.Linear(256, n))\n        self.clsW = nn.Parameter(torch.zeros(n, F_dim))\n        self.clsb = nn.Parameter(torch.zeros(n))\n        nn.init.trunc_normal_(self.clsW, std=0.02)\n        self.n = n\n\n    def encode(self, x):\n        B, K = x.shape[:2]\n        f = self.backbone(x.flatten(0, 1))\n        return f.view(B, K, -1)\n\n    def head(self, feats):\n        h = self.norm(feats)\n        a = self.att(h)\n        a = torch.softmax(a, dim=1)\n        pooled = torch.einsum(\"bkn,bkf->bnf\", a, h)\n        logits = (pooled * self.clsW).sum(-1) + self.clsb\n        return logits\n\n    def forward(self, x):\n        return self.head(self.encode(x))\n\n\ndef load_model(pt_path, arch_default, res_default, device, ngpu=1):\n    ck = torch.load(pt_path, map_location=\"cpu\", weights_only=False)\n    arch = ck.get(\"arch\", arch_default)\n    ck_res = int(ck.get(\"res\", res_default))\n    bb = build_backbone(arch, pretrained=False)\n    model = RaptorClassifier(bb, F_dim=bb.num_features)\n    model.load_state_dict(ck[\"model\"], strict=True)\n    model.eval().to(device)\n    # NOTE: DataParallel removed on purpose. On the full hidden test it drove a system-RAM OOM\n    # (per-forward module replication over many studies); a single T4 handles K_EVAL=24 windows\n    # fine. Arms are also run SEQUENTIALLY (see main) so peak RAM == one model, not two.\n    del ck\n    gc.collect()\n    return model, ck_res\n\n\n# ============================================================================\n# Eval windowing -- verbatim from finetune_raptor.py StudyWindows (train=False)\n# ============================================================================\ndef _eval_centers(mask, D, k):\n    valid = np.where(mask > 0)[0]\n    if len(valid) < 3:\n        valid = np.arange(min(3, D))\n    lo, hi = int(valid.min()), int(valid.max())\n    cs = [c for c in range(lo + 1, hi) if c - 1 >= lo and c + 1 <= hi]\n    if not cs:\n        cs = [max(1, min((lo + hi) // 2, D - 2))]\n    idx = np.linspace(0, len(cs) - 1, k).round().astype(int)\n    return [cs[i] for i in idx]\n\n\ndef eval_windows(vol, mask, k, res, norm=NORM):\n    D = vol.shape[0]\n    cs = _eval_centers(mask, D, k)\n    wins = np.empty((len(cs), 3, res, res), np.float32)\n    for j, c in enumerate(cs):\n        c = max(1, min(c, D - 2))\n        tri = np.stack([vol[c - 1], vol[c], vol[c + 1]], 0).astype(np.float32) / 255.0\n        t = torch.from_numpy(tri)\n        if t.shape[-1] != res:\n            t = F.interpolate(t[None], size=(res, res), mode=\"bilinear\",\n                              align_corners=False)[0]\n        wins[j] = t.numpy()\n    x = torch.from_numpy(wins)\n    if norm == \"imagenet\":\n        x = (x - _MEAN) / _STD\n    return x\n\n\n@torch.no_grad()\ndef infer_probs(model, xwins, device):\n    x = xwins.unsqueeze(0).to(device)\n    use_cuda = device != \"cpu\" and str(device).startswith(\"cuda\")\n    if use_cuda:\n        # fp16 conv on T4 is fully cuDNN-supported (bf16 is NOT -> \"no engine\").\n        try:\n            with torch.autocast(\"cuda\", dtype=torch.float16):\n                o = torch.sigmoid(model(x).float())\n            return o[0].cpu().numpy()\n        except RuntimeError:\n            # fp32 always has a Turing conv engine; slower but never drops a study.\n            torch.cuda.empty_cache()\n            o = torch.sigmoid(model(x).float())\n            return o[0].cpu().numpy()\n    o = torch.sigmoid(model(x).float())\n    return o[0].cpu().numpy()\n\n\ndef rankpct(x):                                   # per-column percentile rank in [0,1]\n    order = x.argsort(0).argsort(0).astype(np.float64)\n    return order / max(1, (x.shape[0] - 1))\n\n\n# ============================================================================\n# Preprocessing -- verbatim from kprep2/dino_preprocess.py, retargeted to TEST\n# ============================================================================\ndef _make_reader():\n    import pydicom, cv2\n    from pydicom.pixel_data_handlers.util import apply_modality_lut\n\n    def order_and_meta(sdir):\n        fs = glob.glob(sdir + \"/*.dcm\"); recs = []; ps_list = []\n        for f in fs:\n            try:\n                h = pydicom.dcmread(f, stop_before_pixels=True)\n                iop = getattr(h, 'ImageOrientationPatient', None)\n                ipp = getattr(h, 'ImagePositionPatient', None)\n                if iop is not None and ipp is not None and len(iop) == 6:\n                    r = np.array(iop[:3], float); c = np.array(iop[3:], float)\n                    n = np.cross(r, c); pos = float(np.dot(np.array(ipp, float), n))\n                else:\n                    pos = float(getattr(h, 'InstanceNumber', 0) or 0)\n                ps = getattr(h, 'PixelSpacing', None); ps = float(ps[0]) if ps is not None else 0.5\n                ps_list.append(ps); recs.append((pos, f, ps))\n            except Exception:\n                recs.append((0.0, f, 0.5))\n        recs.sort(key=lambda x: x[0])\n        med_ps = float(np.median(ps_list)) if ps_list else 0.5\n        return [(f, ps) for _, f, ps in recs], med_ps\n\n    def read_px(f):\n        d = pydicom.dcmread(f)\n        a = apply_modality_lut(d.pixel_array, d).astype(np.float32)\n        if str(getattr(d, 'PhotometricInterpretation', '')) == 'MONOCHROME1':\n            a = a.max() - a\n        return a\n\n    def mm_crop_resize(a, ps):\n        h, w = a.shape; cpx = int(round(CROP_MM / max(ps, 1e-3)))\n        cpx = min(cpx, min(h, w)); y0 = (h - cpx) // 2; x0 = (w - cpx) // 2\n        a = a[y0:y0 + cpx, x0:x0 + cpx]\n        return cv2.resize(a, (IMG, IMG), interpolation=cv2.INTER_AREA)\n\n    return order_and_meta, read_px, mm_crop_resize\n\n\ndef _pick_series_for_slot(rows, plane, fluid, used):\n    cands = [r for r in rows if r['Anatomical_Plane'] == plane and r['SeriesInstanceUID'] not in used]\n    if fluid in (0, 1):\n        pref = [r for r in cands if int(r.get('Fluid_Sensitive', 0) or 0) == fluid]\n        if pref:\n            return pref[0]\n    return cands[0] if cands else None\n\n\ndef build_study(sid, ser_records, tsdir, reader):\n    order_and_meta, read_px, mm_crop_resize = reader\n    rows = ser_records.get(sid, [])\n    vol = np.zeros((MAXS, IMG, IMG), np.uint8); idx = 0; used = set()\n    for plane, fluid, k in SLOTS:\n        r = _pick_series_for_slot(rows, plane, fluid, used)\n        if r is None:\n            idx += k; continue\n        used.add(r['SeriesInstanceUID'])\n        files, med_ps = order_and_meta(f\"{tsdir}/{sid}/{r['SeriesInstanceUID']}\")\n        if not files:\n            idx += k; continue\n        # wide span: the collateral ligaments and lateral meniscus live in the\n        # peripheral slices the old 0.15-0.85 crop threw away. Must match the corpus\n        # the weights were trained on (knee_corpus_v2.py, SPAN_LO/SPAN_HI).\n        n = len(files); lo, hi = int(n * SPAN_LO), int(n * SPAN_HI) - 1; hi = max(hi, lo)\n        picks = np.linspace(lo, hi, k).round().astype(int) if n > 1 else [0] * k\n        arrs = []; pss = []\n        for p in picks:\n            fp, ps = files[min(p, n - 1)]\n            try:\n                arrs.append(read_px(fp)); pss.append(ps)\n            except Exception:\n                arrs.append(None); pss.append(med_ps)\n        valid = [a for a in arrs if a is not None]\n        if valid:\n            allpx = np.concatenate([a.ravel() for a in valid])\n            loq, hiq = np.percentile(allpx, [2.0, 98.0])\n        else:\n            loq, hiq = 0.0, 1.0\n        for a, ps in zip(arrs, pss):\n            if idx >= MAXS: break\n            if a is None: idx += 1; continue\n            aw = np.clip((a - loq) / (hiq - loq + 1e-6), 0, 1)\n            aw = mm_crop_resize(aw, ps if ps > 0 else med_ps)\n            vol[idx] = (aw * 255).astype(np.uint8); idx += 1\n        if idx >= MAXS: break\n    mask = (vol.reshape(MAXS, -1).sum(1) > 0).astype(np.uint8)\n    return vol, mask\n\n\n# ============================================================================\n# Test-root discovery + weights + main\n# ============================================================================\ndef find_test_root():\n    cands = [\"/kaggle/input/competitions/rsna-knee-abnormality-detection\",\n             \"/kaggle/input/rsna-knee-abnormality-detection\"]\n    for b in cands:\n        if os.path.exists(b + \"/test.csv\"):\n            return b\n    for d, _, f in os.walk(\"/kaggle/input\"):\n        if \"test.csv\" in f and (os.path.isdir(d + \"/test_series\") or os.path.isdir(d + \"/test_images\")):\n            return d\n    for d, _, f in os.walk(\"/kaggle/input\"):\n        if \"test.csv\" in f:\n            return d\n    raise RuntimeError(\"no test root under /kaggle/input\")\n\n\ndef find_weight_file(fname):\n    # direct dataset mounts first; NEVER recursive-glob the competitions DICOM tree.\n    direct = [f\"/kaggle/input/raptor-knee-maxspan/{fname}\",\n              f\"/kaggle/input/raptor-knee-native384dense/{fname}\",\n              f\"/kaggle/input/raptor-knee-native384/{fname}\",\n              f\"/kaggle/input/raptor-knee-arms/{fname}\",\n              f\"/kaggle/input/raptor-knee-arms/1/{fname}\",\n              f\"/kaggle/input/raptor-cnn336/{fname}\"]\n    for p in direct:\n        if os.path.exists(p):\n            return p\n    for d in sorted(glob.glob(\"/kaggle/input/*/\")):\n        if \"competition\" in d.lower():\n            continue\n        hits = glob.glob(os.path.join(d, \"**\", fname), recursive=True)\n        if hits:\n            return hits[0]\n    raise RuntimeError(f\"{fname} not found under /kaggle/input\")\n\n\ndef main():\n    import pandas as pd\n    t0 = time.time()\n    dev = \"cuda\" if torch.cuda.is_available() else \"cpu\"\n    ngpu = torch.cuda.device_count()\n    print(f\"device {dev} | gpus {ngpu} | torch {torch.__version__}\", flush=True)\n\n    ROOT = find_test_root()\n    tsdir = ROOT + \"/test_series\"\n    if not os.path.isdir(tsdir):\n        tsdir = ROOT + \"/test_images\"\n    print(\"test root:\", ROOT, \"| series dir:\", tsdir, flush=True)\n\n    test = pd.read_csv(ROOT + \"/test.csv\"); test[\"StudyInstanceUID\"] = test[\"StudyInstanceUID\"].astype(str)\n    test_ids = test[\"StudyInstanceUID\"].tolist()\n    tser = pd.read_csv(ROOT + \"/test_series.csv\")\n    tser[\"StudyInstanceUID\"] = tser[\"StudyInstanceUID\"].astype(str)\n    tser[\"SeriesInstanceUID\"] = tser[\"SeriesInstanceUID\"].astype(str)\n    SER = {k: v.to_dict(\"records\") for k, v in tser.groupby(\"StudyInstanceUID\")}\n    print(f\"test studies {len(test_ids)} | test series {len(tser)}\", flush=True)\n\n    sub_cols = [\"StudyInstanceUID\"] + LAB\n    ssub = os.path.join(ROOT, \"sample_submission.csv\")\n    if os.path.exists(ssub):\n        sub_cols = list(pd.read_csv(ssub, nrows=1).columns)\n\n    reader = _make_reader()\n    N = len(test_ids); A = len(ARMS)\n    arm_probs = [np.full((N, len(LAB)), 0.5, np.float32) for _ in range(A)]\n\n    # SEQUENTIAL ARMS (the OOM fix): only ONE model is resident at a time, so peak system RAM ==\n    # one model == the single-arm champion's footprint (which graded fine at 0.879). Holding both\n    # arms simultaneously OOM'd system RAM on the full hidden test. Each study is re-preprocessed\n    # per arm (build_study is cheap vs inference) and every per-study buffer is freed. Same models,\n    # same windowing, same rank-mean blend -> identical 0.8893 result, just serialized.\n    for a, arm in enumerate(ARMS):\n        # Restore the exact preprocessing contract used to train this checkpoint.\n        globals()[\"IMG\"] = int(arm[\"img\"])\n        globals()[\"SLOTS\"] = list(arm[\"slots\"])\n        globals()[\"MAXS\"] = sum(slot[2] for slot in SLOTS)\n        globals()[\"SPAN_LO\"], globals()[\"SPAN_HI\"] = map(float, arm[\"span\"])\n        globals()[\"K_EVAL\"] = int(arm[\"k_eval\"])\n        wp = find_weight_file(arm[\"file\"])\n        model, res = load_model(wp, arm[\"arch\"], arm[\"res\"], dev)\n        print(f\"[arm {a}] {arm['name']} | img {IMG} | slices {MAXS} | span {SPAN_LO:.2f}-{SPAN_HI:.2f} | windows {K_EVAL} | res {res} | {time.time()-t0:.0f}s\", flush=True)\n        for i, sid in enumerate(test_ids):\n            try:\n                vol, mask = build_study(sid, SER, tsdir, reader)\n                xw = eval_windows(vol, mask, k=K_EVAL, res=res, norm=NORM)\n                if bool(arm.get(\"reverse\", False)):\n                    xw = xw.flip(1).contiguous()\n                arm_probs[a][i] = infer_probs(model, xw, dev)\n                del vol, mask, xw\n            except Exception as e:\n                print(f\"  [arm {a}] study {i} {sid[:16]} FALLBACK ({type(e).__name__}: {e})\", flush=True)\n            if (i + 1) % 100 == 0 or i + 1 == N:\n                print(f\"  [arm {a}] {i+1}/{N} | {time.time()-t0:.0f}s\", flush=True)\n        del model\n        gc.collect()\n        if str(dev).startswith(\"cuda\"):\n            torch.cuda.empty_cache()\n        print(f\"[arm {a}] done + freed | {time.time()-t0:.0f}s\", flush=True)\n\n    # WEIGHTED rank-mean blend across the test set, per finding (the offline recipe).\n    # Weights come from ARMS[*][\"w\"] and are normalised here, so dropping/adding an arm can\n    # never silently change the scale. Falls back to equal weights if none are declared.\n    _w = np.array([float(a.get(\"w\", 1.0)) for a in ARMS], dtype=np.float64)\n    _w = _w / _w.sum()\n    print(f\"[blend] global probability mean w={dict(zip([a['name'] for a in ARMS], _w.round(4)))}\", flush=True)\n    probability_blend = np.tensordot(\n        _w, np.stack([np.clip(p, 0, 1) for p in arm_probs]), axes=(0, 0)\n    )\n    ranks = rankpct(probability_blend)                                         # (N,12) in [0,1]\n    if not np.isfinite(ranks).all():\n        ranks[~np.isfinite(ranks)] = 0.5\n\n    sub = pd.DataFrame(ranks.astype(np.float32), columns=LAB)\n    sub.insert(0, \"StudyInstanceUID\", test_ids)\n    sub = sub[sub_cols]\n    assert list(sub.columns) == sub_cols, \"column order drift\"\n    assert sub[\"StudyInstanceUID\"].tolist() == test_ids, \"row identity drift\"\n    assert np.isfinite(sub[LAB].values).all()\n    out = \"/kaggle/working/submission_coatnet.csv\"\n    sub.to_csv(out, index=False)\n    print(\"wrote\", out, \"|\", len(sub), \"rows x\", len(sub.columns), \"cols\", flush=True)\n    print(sub.head().to_string(index=False), flush=True)\n    print(f\"DONE {time.time()-t0:.0f}s\", flush=True)\n\n\nif __name__ == \"__main__\":\n    try:\n        main()\n    except Exception as _coat_exc:\n        import traceback as _coat_traceback\n        print(f\"CoAtNet branch failed; retaining transformer submission: {type(_coat_exc).__name__}: {_coat_exc}\", flush=True)\n        _coat_traceback.print_exc()\n\n\n\n# Blend two independently validated rank predictors. The default remains the transformer\n# submission if the CoAtNet branch did not complete, so a recoverable branch failure\n# cannot erase a valid competition artifact.\nfrom pathlib import Path as _BlendPath\nimport numpy as _blend_np\nimport pandas as _blend_pd\n\n_blend_work = _BlendPath('/kaggle/working')\n_blend_transformer_path = _blend_work / 'submission.csv'\n_blend_coatnet_path = _blend_work / 'submission_coatnet.csv'\nif _blend_coatnet_path.is_file():\n    _blend_transformer = _blend_pd.read_csv(_blend_transformer_path, dtype={'StudyInstanceUID': str})\n    _blend_coatnet = _blend_pd.read_csv(_blend_coatnet_path, dtype={'StudyInstanceUID': str})\n    _blend_labels = [c for c in _blend_transformer.columns if c != 'StudyInstanceUID']\n    if _blend_coatnet.columns.tolist() != _blend_transformer.columns.tolist():\n        raise RuntimeError('CoAtNet/transformer submission schema mismatch')\n    if _blend_coatnet['StudyInstanceUID'].tolist() != _blend_transformer['StudyInstanceUID'].tolist():\n        raise RuntimeError('CoAtNet/transformer study order mismatch')\n    _blend_tr = _blend_transformer[\n        _blend_labels\n    ].rank(\n        method='average',\n        pct=True,\n    )\n\n    _blend_cr = _blend_coatnet[\n        _blend_labels\n    ].rank(\n        method='average',\n        pct=True,\n    )\n\n    _blend_output = (\n        _blend_transformer.copy()\n    )\n\n    # One global outer weight, fixed before the public submission.\n    _coatnet_weight = {label: 0.60 for label in _blend_labels}\n\n    for _label in _blend_labels:\n        _cw = float(\n            _coatnet_weight[\n                _label\n            ]\n        )\n\n        _blend_output[\n            _label\n        ] = (\n            (\n                1.0\n                - _cw\n            )\n            * _blend_tr[\n                _label\n            ]\n            + _cw\n            * _blend_cr[\n                _label\n            ]\n        )\n\n    _blend_output[\n        _blend_labels\n    ] = _blend_output[\n        _blend_labels\n    ].rank(\n        method='average',\n        pct=True,\n    )\n\n    print(\n        '[V18] CoAtNet target weights: '\n        + ', '.join(\n            f'{label}='\n            f'{_coatnet_weight[label]:.2f}'\n            for label in _blend_labels\n            if (\n                _coatnet_weight[label]\n                != 0.50\n            )\n        ),\n        flush=True,\n    )\n\n    _blend_values = _blend_output[\n        _blend_labels\n    ].to_numpy(\n        _blend_np.float64\n    )\n    if not _blend_np.isfinite(_blend_values).all() or _blend_values.min() < 0 or _blend_values.max() > 1:\n        raise RuntimeError('invalid blended prediction values')\n    _blend_output.to_csv(_blend_transformer_path, index=False)\n    print(f'final submission.csv = V18 calibrated transformer + CoAtNet rank blend; {_blend_output.shape}', flush=True)\nelse:\n    print('CoAtNet output unavailable; submission.csv remains the validated transformer ensemble', flush=True)\n\n# V18 output hygiene.\nfor _v18_temp in (\n    _blend_work / 'submission_coatnet.csv',\n    _blend_work / 'submission_transformer_0920.csv',\n):\n    try:\n        if _v18_temp.is_file():\n            _v18_temp.unlink()\n    except OSError:\n        pass\n","metadata":{"jupyter":{"source_hidden":true},"papermill":{"duration":59.696838,"end_time":"2026-09-04T03:00:10.4629+00:00","exception":false,"start_time":"2026-09-04T02:59:10.766062+00:00","status":"completed"},"tags":[],"trusted":true},"outputs":[],"execution_count":null},{"id":"5fbc01dd","cell_type":"code","source":"\"\"\"Append-only runtime audit for the exact public H&S v38 inference notebook.\n\nThis module is embedded verbatim as the final notebook cell.  It must not write\nto ``submission.csv``.  Its only prediction-adjacent operation is a byte-for-byte\ncopy to ``submission_parent_exact.csv`` before validation.\n\"\"\"\n\nfrom __future__ import annotations\n\nimport hashlib as _i21_hashlib\nimport json as _i21_json\nimport os as _i21_os\nimport platform as _i21_platform\nimport shutil as _i21_shutil\nimport traceback as _i21_traceback\nfrom datetime import datetime as _i21_datetime, timezone as _i21_timezone\nfrom pathlib import Path as _I21Path\nfrom typing import Any as _I21Any, Mapping as _I21Mapping\n\nimport numpy as _i21_np\nimport pandas as _i21_pd\nimport torch as _i21_torch\n\n\n_I21_LABELS = [\n    \"ACL\",\n    \"MCL\",\n    \"Medial Meniscus\",\n    \"Lateral Meniscus\",\n    \"Medial OA\",\n    \"Lateral OA\",\n    \"PF OA\",\n    \"Effusion\",\n    \"Synovitis\",\n    \"Baker's\",\n    \"Contusion\",\n    \"Fracture\",\n]\n_I21_VISIBLE_UID_SHA256 = (\n    \"f8308447b47011121885d31b754b690b1bd3b51a78e8f07c0b148161f8396ea0\"\n)\n_I21_VISIBLE_SUBMISSION_SHA256 = (\n    \"1b03ce7f093efaffdf9acb9e8af05946bdd60b4fec1e0b1fc536b8198abb513b\"\n)\n_I21_PARENT_NOTEBOOK_SHA256 = (\n    \"af519f52b2473bf7622957c8802da368b5d67cbb899500e8bb944f0b2f2ab0e1\"\n)\n_I21_EXPECTED_RAD_GATE = [\n    \"ACL\",\n    \"Baker's\",\n    \"Contusion\",\n    \"Effusion\",\n    \"Lateral OA\",\n    \"Medial OA\",\n    \"PF OA\",\n]\n_I21_EXPECTED_RAPTOR_ARMS = [\n    {\"name\": \"maxspan-v5\", \"weight\": 0.55, \"windows\": 62},\n    {\"name\": \"native384dense-v10\", \"weight\": 0.10, \"windows\": 62},\n    {\"name\": \"maxspan-v5-reverse\", \"weight\": 0.15, \"windows\": 62},\n    {\"name\": \"native384-v8\", \"weight\": 0.20, \"windows\": 42},\n]\n\n\ndef _i21_sha256_bytes(payload: bytes) -> str:\n    return _i21_hashlib.sha256(payload).hexdigest()\n\n\ndef _i21_sha256_file(path: _I21Path) -> str:\n    digest = _i21_hashlib.sha256()\n    with path.open(\"rb\") as handle:\n        for block in iter(lambda: handle.read(8 << 20), b\"\"):\n            digest.update(block)\n    return digest.hexdigest()\n\n\ndef _i21_uid_sha256(uids: list[str]) -> str:\n    return _i21_sha256_bytes(\"\".join(f\"{uid}\\n\" for uid in uids).encode(\"utf-8\"))\n\n\ndef _i21_jsonable(value: _I21Any) -> _I21Any:\n    if isinstance(value, _I21Path):\n        return str(value)\n    if isinstance(value, (_i21_np.integer,)):\n        return int(value)\n    if isinstance(value, (_i21_np.floating,)):\n        return float(value)\n    if isinstance(value, (_i21_np.bool_,)):\n        return bool(value)\n    if isinstance(value, tuple):\n        return [_i21_jsonable(item) for item in value]\n    if isinstance(value, list):\n        return [_i21_jsonable(item) for item in value]\n    if isinstance(value, dict):\n        return {str(key): _i21_jsonable(item) for key, item in value.items()}\n    return value\n\n\ndef _i21_write_receipt(path: _I21Path, receipt: dict[str, _I21Any]) -> None:\n    path.write_text(\n        _i21_json.dumps(\n            _i21_jsonable(receipt),\n            ensure_ascii=False,\n            indent=2,\n            sort_keys=True,\n        )\n        + \"\\n\",\n        encoding=\"utf-8\",\n    )\n\n\ndef _i21_find_competition_root(\n    namespace: _I21Mapping[str, _I21Any], explicit_root: str | _I21Path | None\n) -> _I21Path:\n    candidates: list[_I21Path] = []\n    if explicit_root is not None:\n        candidates.append(_I21Path(explicit_root))\n    root_from_parent = namespace.get(\"ROOT\")\n    if root_from_parent is not None:\n        candidates.append(_I21Path(str(root_from_parent)))\n    candidates.extend(\n        [\n            _I21Path(\"/kaggle/input/rsna-knee-abnormality-detection\"),\n            _I21Path(\"/kaggle/input/competitions/rsna-knee-abnormality-detection\"),\n        ]\n    )\n    seen: set[str] = set()\n    for candidate in candidates:\n        key = str(candidate)\n        if key in seen:\n            continue\n        seen.add(key)\n        if (candidate / \"test.csv\").is_file() and (\n            candidate / \"test_series.csv\"\n        ).is_file():\n            return candidate\n    for directory, _, names in _i21_os.walk(\"/kaggle/input\"):\n        if \"test.csv\" in names and \"test_series.csv\" in names:\n            return _I21Path(directory)\n    raise RuntimeError(\"infra0021: competition test.csv/test_series.csv not found\")\n\n\ndef _i21_assert_frame(\n    frame: _i21_pd.DataFrame,\n    expected_uids: list[str],\n    *,\n    context: str,\n) -> _i21_np.ndarray:\n    expected_columns = [\"StudyInstanceUID\", *_I21_LABELS]\n    if frame.columns.tolist() != expected_columns:\n        raise RuntimeError(\n            f\"infra0021: {context} schema drift: {frame.columns.tolist()}\"\n        )\n    uids = frame[\"StudyInstanceUID\"].astype(str).tolist()\n    if uids != expected_uids:\n        raise RuntimeError(f\"infra0021: {context} UID/order drift\")\n    if len(uids) != len(set(uids)):\n        raise RuntimeError(f\"infra0021: {context} contains duplicate UIDs\")\n    values = frame[_I21_LABELS].to_numpy(_i21_np.float64)\n    if values.shape != (len(expected_uids), len(_I21_LABELS)):\n        raise RuntimeError(f\"infra0021: {context} prediction shape drift\")\n    if not _i21_np.isfinite(values).all():\n        raise RuntimeError(f\"infra0021: {context} contains non-finite predictions\")\n    if values.size and (float(values.min()) < 0.0 or float(values.max()) > 1.0):\n        raise RuntimeError(f\"infra0021: {context} predictions outside [0, 1]\")\n    return values\n\n\ndef _i21_manifest_member_count(namespace: _I21Mapping[str, _I21Any]) -> tuple[int, str]:\n    asset = namespace.get(\"ASSET\")\n    if asset is None:\n        raise RuntimeError(\"infra0021: parent ASSET variable missing\")\n    manifest_path = _I21Path(str(asset)) / \"rsna-knee-weights\" / \"manifest.json\"\n    if not manifest_path.is_file():\n        raise RuntimeError(f\"infra0021: DINO manifest missing: {manifest_path}\")\n    manifest = _i21_json.loads(manifest_path.read_text(encoding=\"utf-8\"))\n    members = manifest.get(\"members\")\n    if not isinstance(members, list) or len(members) != 20:\n        raise RuntimeError(\n            f\"infra0021: expected 20 DINO members, got \"\n            f\"{len(members) if isinstance(members, list) else type(members).__name__}\"\n        )\n    member_ids = [str(member.get(\"id\", \"\")) for member in members]\n    if any(not member_id for member_id in member_ids) or len(member_ids) != len(\n        set(member_ids)\n    ):\n        raise RuntimeError(\"infra0021: DINO member IDs missing or duplicated\")\n    return len(members), _i21_sha256_file(manifest_path)\n\n\ndef _i21_validate_a5(\n    namespace: _I21Mapping[str, _I21Any], study_count: int\n) -> dict[str, _I21Any]:\n    models = namespace.get(\"models\")\n    preds = namespace.get(\"preds\")\n    ok = namespace.get(\"_a5_ok\")\n    if not isinstance(models, list) or len(models) != 5:\n        raise RuntimeError(\n            f\"infra0021: expected five A5 models, got \"\n            f\"{len(models) if isinstance(models, list) else type(models).__name__}\"\n        )\n    predictions = _i21_np.asarray(preds)\n    expected_shape = (5, study_count, len(_I21_LABELS))\n    if predictions.shape != expected_shape:\n        raise RuntimeError(\n            f\"infra0021: A5 prediction shape {predictions.shape}, expected {expected_shape}\"\n        )\n    if not _i21_np.isfinite(predictions).all():\n        raise RuntimeError(\"infra0021: A5 predictions contain fallback NaN/inf\")\n    valid = _i21_np.asarray(ok, dtype=bool)\n    if valid.shape != (study_count,) or not valid.all():\n        raise RuntimeError(\"infra0021: A5 did not complete every study\")\n    return {\n        \"model_count\": len(models),\n        \"prediction_shape\": list(predictions.shape),\n        \"all_studies_complete\": bool(valid.all()),\n    }\n\n\ndef _i21_validate_rad(namespace: _I21Mapping[str, _I21Any]) -> dict[str, _I21Any]:\n    if namespace.get(\"V18_CALIBRATOR_APPLIED\") is not True:\n        raise RuntimeError(\"infra0021: V18 Rad/transformer calibrator was not applied\")\n    gate = sorted(str(item) for item in namespace.get(\"V18_CAL_GATE\", ()))\n    if gate != _I21_EXPECTED_RAD_GATE:\n        raise RuntimeError(f\"infra0021: V18 calibration gate drift: {gate}\")\n    return {\"calibrator_applied\": True, \"gate\": gate}\n\n\ndef _i21_validate_raptor(\n    namespace: _I21Mapping[str, _I21Any], expected_uids: list[str]\n) -> dict[str, _I21Any]:\n    arms = namespace.get(\"ARMS\")\n    if not isinstance(arms, list) or len(arms) != 4:\n        raise RuntimeError(\"infra0021: Raptor four-arm definition missing\")\n    observed = [\n        {\n            \"name\": str(arm.get(\"name\", \"\")),\n            \"weight\": float(arm.get(\"w\", -1.0)),\n            \"windows\": int(arm.get(\"k_eval\", -1)),\n        }\n        for arm in arms\n    ]\n    if observed != _I21_EXPECTED_RAPTOR_ARMS:\n        raise RuntimeError(f\"infra0021: Raptor arm contract drift: {observed}\")\n    weights = namespace.get(\"_coatnet_weight\")\n    if not isinstance(weights, dict) or set(weights) != set(_I21_LABELS):\n        raise RuntimeError(\"infra0021: Raptor outer-weight map missing or incomplete\")\n    if any(float(weights[label]) != 0.60 for label in _I21_LABELS):\n        raise RuntimeError(\"infra0021: Raptor outer global weight drift\")\n    coatnet = namespace.get(\"_blend_coatnet\")\n    if not isinstance(coatnet, _i21_pd.DataFrame):\n        raise RuntimeError(\n            \"infra0021: CoAtNet branch output unavailable; transformer fallback is forbidden\"\n        )\n    _i21_assert_frame(coatnet, expected_uids, context=\"CoAtNet branch\")\n    blended = namespace.get(\"_blend_output\")\n    if not isinstance(blended, _i21_pd.DataFrame):\n        raise RuntimeError(\"infra0021: final Raptor blend object missing\")\n    values = _i21_assert_frame(blended, expected_uids, context=\"in-memory final blend\")\n    return {\n        \"arm_contract\": observed,\n        \"outer_weight\": 0.60,\n        \"final_shape\": list(values.shape),\n        \"branch_output_present\": True,\n    }\n\n\ndef run_infra0021_audit(\n    namespace: _I21Mapping[str, _I21Any],\n    *,\n    work_dir: str | _I21Path = \"/kaggle/working\",\n    competition_root: str | _I21Path | None = None,\n    enforce_gpu: bool = True,\n) -> dict[str, _I21Any]:\n    \"\"\"Validate the completed parent notebook without changing its predictions.\"\"\"\n\n    work = _I21Path(work_dir)\n    work.mkdir(parents=True, exist_ok=True)\n    receipt_path = work / \"infra0021_runtime_receipt.json\"\n    receipt: dict[str, _I21Any] = {\n        \"schema_version\": \"infra0021_runtime_receipt_v1\",\n        \"infra_id\": \"infra0021_public0936_exact_clone_audit\",\n        \"status\": \"started\",\n        \"started_at_utc\": _i21_datetime.now(_i21_timezone.utc).isoformat(),\n        \"prediction_recipe_changed\": False,\n        \"competition_submission_performed\": False,\n        \"parent\": {\n            \"kernel\": \"prvsiyan/head-and-shoulders-knees-and-toes\",\n            \"version\": 38,\n            \"script_version_id\": 344807997,\n            \"public_score_provenance_only\": 0.936,\n            \"source_sha256\": _I21_PARENT_NOTEBOOK_SHA256,\n        },\n        \"gates\": {},\n    }\n    _i21_write_receipt(receipt_path, receipt)\n\n    try:\n        root = _i21_find_competition_root(namespace, competition_root)\n        test_path = root / \"test.csv\"\n        series_path = root / \"test_series.csv\"\n        test = _i21_pd.read_csv(test_path, dtype={\"StudyInstanceUID\": str})\n        if test.columns.tolist().count(\"StudyInstanceUID\") != 1:\n            raise RuntimeError(\"infra0021: test.csv StudyInstanceUID contract drift\")\n        test_uids = test[\"StudyInstanceUID\"].astype(str).tolist()\n        if not test_uids or any(not uid for uid in test_uids):\n            raise RuntimeError(\"infra0021: test.csv contains empty/no UIDs\")\n        if len(test_uids) != len(set(test_uids)):\n            raise RuntimeError(\"infra0021: test.csv contains duplicate UIDs\")\n        uid_sha = _i21_uid_sha256(test_uids)\n        visible_reference = uid_sha == _I21_VISIBLE_UID_SHA256\n\n        gpu_count = int(_i21_torch.cuda.device_count())\n        gpu_names = [\n            str(_i21_torch.cuda.get_device_name(index)) for index in range(gpu_count)\n        ]\n        if enforce_gpu:\n            if not _i21_torch.cuda.is_available():\n                raise RuntimeError(\"infra0021: CUDA is unavailable\")\n            if gpu_count != 2:\n                raise RuntimeError(\n                    f\"infra0021: expected exactly two GPUs, got {gpu_count}\"\n                )\n            if any(\"T4\" not in name.upper() for name in gpu_names):\n                raise RuntimeError(f\"infra0021: expected Tesla T4 GPUs, got {gpu_names}\")\n\n        submission_path = work / \"submission.csv\"\n        if not submission_path.is_file():\n            raise RuntimeError(\"infra0021: parent did not produce submission.csv\")\n        submission_sha = _i21_sha256_file(submission_path)\n        backup_path = work / \"submission_parent_exact.csv\"\n        _i21_shutil.copyfile(submission_path, backup_path)\n        backup_sha = _i21_sha256_file(backup_path)\n        if backup_sha != submission_sha:\n            raise RuntimeError(\"infra0021: byte backup of submission.csv changed\")\n\n        submission = _i21_pd.read_csv(\n            submission_path, dtype={\"StudyInstanceUID\": str}\n        )\n        submission_values = _i21_assert_frame(\n            submission, test_uids, context=\"submission.csv\"\n        )\n        if visible_reference and submission_sha != _I21_VISIBLE_SUBMISSION_SHA256:\n            raise RuntimeError(\n                \"infra0021: visible three-study output differs from exact v38 parent\"\n            )\n\n        dino_count, dino_manifest_sha = _i21_manifest_member_count(namespace)\n        a5 = _i21_validate_a5(namespace, len(test_uids))\n        rad = _i21_validate_rad(namespace)\n        raptor = _i21_validate_raptor(namespace, test_uids)\n        in_memory = namespace[\"_blend_output\"][_I21_LABELS].to_numpy(\n            _i21_np.float64\n        )\n        max_abs_csv_vs_memory = float(\n            _i21_np.max(_i21_np.abs(submission_values - in_memory))\n            if submission_values.size\n            else 0.0\n        )\n        if max_abs_csv_vs_memory > 1e-12:\n            raise RuntimeError(\n                \"infra0021: final CSV differs from the in-memory Raptor blend \"\n                f\"(max abs {max_abs_csv_vs_memory:.3e})\"\n            )\n\n        input_mounts = sorted(\n            str(path)\n            for path in _I21Path(\"/kaggle/input\").iterdir()\n        ) if _I21Path(\"/kaggle/input\").is_dir() else []\n        receipt.update(\n            {\n                \"status\": \"passed\",\n                \"completed_at_utc\": _i21_datetime.now(\n                    _i21_timezone.utc\n                ).isoformat(),\n                \"input\": {\n                    \"competition_root\": str(root),\n                    \"test_csv_sha256\": _i21_sha256_file(test_path),\n                    \"test_series_csv_sha256\": _i21_sha256_file(series_path),\n                    \"study_count\": len(test_uids),\n                    \"uid_sha256\": uid_sha,\n                    \"mode\": \"visible_reference\" if visible_reference else \"dynamic_hidden\",\n                    \"visible_static_output_sha_gate_applied\": visible_reference,\n                    \"mounts\": input_mounts,\n                },\n                \"environment\": {\n                    \"python\": _i21_platform.python_version(),\n                    \"torch\": str(_i21_torch.__version__),\n                    \"numpy\": str(_i21_np.__version__),\n                    \"pandas\": str(_i21_pd.__version__),\n                    \"cuda_available\": bool(_i21_torch.cuda.is_available()),\n                    \"gpu_count\": gpu_count,\n                    \"gpu_names\": gpu_names,\n                },\n                \"output\": {\n                    \"submission_path\": str(submission_path),\n                    \"submission_sha256\": submission_sha,\n                    \"backup_path\": str(backup_path),\n                    \"backup_sha256\": backup_sha,\n                    \"shape\": [len(test_uids), len(_I21_LABELS) + 1],\n                    \"max_abs_csv_vs_memory\": max_abs_csv_vs_memory,\n                },\n                \"gates\": {\n                    \"gpu_t4x2\": (not enforce_gpu)\n                    or (\n                        gpu_count == 2\n                        and all(\"T4\" in name.upper() for name in gpu_names)\n                    ),\n                    \"dino\": {\n                        \"member_count\": dino_count,\n                        \"manifest_sha256\": dino_manifest_sha,\n                    },\n                    \"a5\": a5,\n                    \"rad\": rad,\n                    \"raptor\": raptor,\n                    \"submission_schema_uid_range\": True,\n                    \"visible_exact_sha256\": (\n                        submission_sha == _I21_VISIBLE_SUBMISSION_SHA256\n                        if visible_reference\n                        else \"not_applicable_dynamic_input\"\n                    ),\n                },\n            }\n        )\n        _i21_write_receipt(receipt_path, receipt)\n        print(\n            \"infra0021 audit PASSED | \"\n            f\"mode={receipt['input']['mode']} studies={len(test_uids)} \"\n            f\"submission_sha256={submission_sha}\",\n            flush=True,\n        )\n        return receipt\n    except Exception as exc:\n        receipt.update(\n            {\n                \"status\": \"failed\",\n                \"completed_at_utc\": _i21_datetime.now(\n                    _i21_timezone.utc\n                ).isoformat(),\n                \"error\": {\n                    \"type\": type(exc).__name__,\n                    \"message\": str(exc),\n                    \"traceback\": _i21_traceback.format_exc(),\n                },\n            }\n        )\n        _i21_write_receipt(receipt_path, receipt)\n        raise\n\n\nif __name__ == \"__main__\":\n    run_infra0021_audit(globals())\n","metadata":{"jupyter":{"source_hidden":true},"papermill":{"duration":0.082453,"end_time":"2026-09-04T03:00:10.574199+00:00","exception":false,"start_time":"2026-09-04T03:00:10.491746+00:00","status":"completed"},"tags":[],"trusted":true},"outputs":[],"execution_count":null},{"id":"5bf75067","cell_type":"code","source":"\"\"\"Notebook cell source: Medial Meniscus T30 / R60 / bag10 overlay.\n\nThe exact 0.936 parent remains authoritative for every target except\nMedial Meniscus.  For Medial Meniscus only, rebuild the final rank from the\nalready-computed Transformer and Raptor rank components plus the fullfit0033\nbag rank:\n\n    0.30 * Transformer rank\n  + 0.60 * Raptor rank\n  + 0.10 * fullfit0033 bag rank\n\nand then apply the same final average-tie percentile rerank used by the parent.\n\nLateral Meniscus and the other ten targets are copied byte-for-byte from the\nexact 0.936 parent submission.\n\"\"\"\n\nimport csv as _p33_csv\nimport hashlib as _p33_hashlib\nimport json as _p33_json\nimport math as _p33_math\nimport os as _p33_os\nfrom pathlib import Path as _P33Path\n\nimport numpy as _p33_np\n\n\n_P33_LABELS = (\n    \"ACL\",\n    \"MCL\",\n    \"Medial Meniscus\",\n    \"Lateral Meniscus\",\n    \"Medial OA\",\n    \"Lateral OA\",\n    \"PF OA\",\n    \"Effusion\",\n    \"Synovitis\",\n    \"Baker's\",\n    \"Contusion\",\n    \"Fracture\",\n)\n\n_P33_MENISCUS = (\"Medial Meniscus\", \"Lateral Meniscus\")\n_P33_CUSTOM_TARGET = \"Medial Meniscus\"\n\n_P33_HEADER = (\"StudyInstanceUID\", *_P33_LABELS)\n_P33_BAG_HEADER = (\"StudyInstanceUID\", *_P33_MENISCUS)\n\n_P33_VISIBLE_UID_SHA256 = (\n    \"f8308447b47011121885d31b754b690b1bd3b51a78e8f07c0b148161f8396ea0\"\n)\n_P33_VISIBLE_PARENT_SHA256 = (\n    \"1b03ce7f093efaffdf9acb9e8af05946bdd60b4fec1e0b1fc536b8198abb513b\"\n)\n\n# Previous post-parent residual is disabled.\n_P33_PARENT_WEIGHT = _p33_np.float64(1.00)\n_P33_BAG_WEIGHT = _p33_np.float64(0.00)\n\n# New Medial-Meniscus-only three-way route.\n_P33_T_WEIGHT = _p33_np.float64(0.30)\n_P33_R_WEIGHT = _p33_np.float64(0.60)\n_P33_CUSTOM_BAG_WEIGHT = _p33_np.float64(0.10)\n\n\ndef _p33_sha256_file(_p33_path):\n    _p33_digest = _p33_hashlib.sha256()\n    with _p33_path.open(\"rb\") as _p33_handle:\n        for _p33_block in iter(lambda: _p33_handle.read(8 << 20), b\"\"):\n            _p33_digest.update(_p33_block)\n    return _p33_digest.hexdigest()\n\n\ndef _p33_uid_sha256(_p33_uids):\n    return _p33_hashlib.sha256(\n        \"\".join(f\"{_p33_uid}\\n\" for _p33_uid in _p33_uids).encode(\"utf-8\")\n    ).hexdigest()\n\n\ndef _p33_read_tokens(_p33_path, _p33_expected_header, _p33_context):\n    with _p33_path.open(\"r\", encoding=\"utf-8\", newline=\"\") as _p33_handle:\n        _p33_rows = list(_p33_csv.reader(_p33_handle))\n\n    if not _p33_rows or tuple(_p33_rows[0]) != tuple(_p33_expected_header):\n        raise RuntimeError(\n            f\"public0033: {_p33_context} schema drift: \"\n            f\"{_p33_rows[0] if _p33_rows else None!r}\"\n        )\n\n    _p33_data = _p33_rows[1:]\n    if not _p33_data or any(\n        len(_p33_row) != len(_p33_expected_header)\n        for _p33_row in _p33_data\n    ):\n        raise RuntimeError(\n            f\"public0033: {_p33_context} row width/emptiness drift\"\n        )\n    return _p33_data\n\n\ndef _p33_matrix(_p33_rows, _p33_columns, _p33_context):\n    _p33_values = _p33_np.empty(\n        (len(_p33_rows), len(_p33_columns)),\n        dtype=_p33_np.float64,\n    )\n\n    for _p33_row_index, _p33_row in enumerate(_p33_rows):\n        for _p33_column_index, _p33_column in enumerate(_p33_columns):\n            try:\n                _p33_value = float(_p33_row[_p33_column])\n            except (TypeError, ValueError) as _p33_exc:\n                raise RuntimeError(\n                    f\"public0033: {_p33_context} non-numeric value at \"\n                    f\"row={_p33_row_index}, column={_p33_column}\"\n                ) from _p33_exc\n\n            if (\n                not _p33_math.isfinite(_p33_value)\n                or _p33_value < 0.0\n                or _p33_value > 1.0\n            ):\n                raise RuntimeError(\n                    f\"public0033: {_p33_context} value outside [0,1] at \"\n                    f\"row={_p33_row_index}, column={_p33_column}\"\n                )\n\n            _p33_values[\n                _p33_row_index,\n                _p33_column_index,\n            ] = _p33_value\n\n    return _p33_values\n\n\ndef _p33_average_tie_rank_pct(_p33_values):\n    \"\"\"Pandas rank(method='average', pct=True) over the full test set.\"\"\"\n\n    _p33_values = _p33_np.asarray(\n        _p33_values,\n        dtype=_p33_np.float64,\n    )\n\n    if _p33_values.ndim != 1 or _p33_values.size == 0:\n        raise RuntimeError(\n            \"public0033: rank input must be a non-empty vector\"\n        )\n\n    if not _p33_np.isfinite(_p33_values).all():\n        raise RuntimeError(\n            \"public0033: rank input contains non-finite values\"\n        )\n\n    _p33_order = _p33_np.argsort(\n        _p33_values,\n        kind=\"mergesort\",\n    )\n    _p33_sorted = _p33_values[_p33_order]\n    _p33_rank = _p33_np.empty(\n        _p33_values.size,\n        dtype=_p33_np.float64,\n    )\n\n    _p33_start = 0\n    while _p33_start < _p33_values.size:\n        _p33_end = _p33_start + 1\n\n        while (\n            _p33_end < _p33_values.size\n            and _p33_sorted[_p33_end]\n            == _p33_sorted[_p33_start]\n        ):\n            _p33_end += 1\n\n        _p33_rank[\n            _p33_order[_p33_start:_p33_end]\n        ] = (\n            (_p33_start + 1 + _p33_end)\n            / 2.0\n            / _p33_values.size\n        )\n\n        _p33_start = _p33_end\n\n    return _p33_rank\n\n\ndef _p33_token_digest(_p33_rows, _p33_column):\n    _p33_digest = _p33_hashlib.sha256()\n\n    for _p33_row in _p33_rows:\n        _p33_digest.update(\n            _p33_row[0].encode(\"utf-8\")\n        )\n        _p33_digest.update(b\"\\x1f\")\n        _p33_digest.update(\n            _p33_row[_p33_column].encode(\"utf-8\")\n        )\n        _p33_digest.update(b\"\\n\")\n\n    return _p33_digest.hexdigest()\n\n\ndef _p33_competition_root():\n    _p33_candidates = []\n\n    _p33_explicit = _p33_os.environ.get(\n        \"PUBLIC0033_COMPETITION_ROOT\"\n    )\n    if _p33_explicit:\n        _p33_candidates.append(\n            _P33Path(_p33_explicit)\n        )\n\n    _p33_parent_root = globals().get(\"ROOT\")\n    if _p33_parent_root is not None:\n        _p33_candidates.append(\n            _P33Path(str(_p33_parent_root))\n        )\n\n    _p33_candidates.extend(\n        [\n            _P33Path(\n                \"/kaggle/input/rsna-knee-abnormality-detection\"\n            ),\n            _P33Path(\n                \"/kaggle/input/competitions/rsna-knee-abnormality-detection\"\n            ),\n        ]\n    )\n\n    _p33_seen = set()\n\n    for _p33_candidate in _p33_candidates:\n        _p33_key = str(_p33_candidate)\n\n        if _p33_key in _p33_seen:\n            continue\n\n        _p33_seen.add(_p33_key)\n\n        if (_p33_candidate / \"test.csv\").is_file():\n            return _p33_candidate\n\n    raise RuntimeError(\n        \"public0033: competition test.csv is unavailable\"\n    )\n\n\ndef _p33_test_uids(_p33_root):\n    with (\n        _p33_root / \"test.csv\"\n    ).open(\n        \"r\",\n        encoding=\"utf-8\",\n        newline=\"\",\n    ) as _p33_handle:\n        _p33_rows = list(\n            _p33_csv.reader(_p33_handle)\n        )\n\n    if (\n        not _p33_rows\n        or _p33_rows[0].count(\n            \"StudyInstanceUID\"\n        ) != 1\n    ):\n        raise RuntimeError(\n            \"public0033: test.csv StudyInstanceUID schema drift\"\n        )\n\n    _p33_index = _p33_rows[0].index(\n        \"StudyInstanceUID\"\n    )\n\n    _p33_uids = [\n        _p33_row[_p33_index]\n        for _p33_row in _p33_rows[1:]\n    ]\n\n    if (\n        not _p33_uids\n        or any(\n            not _p33_uid\n            for _p33_uid in _p33_uids\n        )\n    ):\n        raise RuntimeError(\n            \"public0033: test.csv contains empty UIDs\"\n        )\n\n    if len(set(_p33_uids)) != len(_p33_uids):\n        raise RuntimeError(\n            \"public0033: test.csv contains duplicate UIDs\"\n        )\n\n    return _p33_uids\n\n\ndef _p33_main():\n    _p33_work = _P33Path(\n        _p33_os.environ.get(\n            \"PUBLIC0033_WORK_DIR\",\n            \"/kaggle/working\",\n        )\n    )\n\n    _p33_parent_path = (\n        _p33_work\n        / \"submission_parent_exact.csv\"\n    )\n    _p33_current_path = (\n        _p33_work\n        / \"submission.csv\"\n    )\n    _p33_bag_path = (\n        _p33_work\n        / \"public0033_bag_raw.csv\"\n    )\n    _p33_audit_path = (\n        _p33_work\n        / \"infra0021_runtime_receipt.json\"\n    )\n    _p33_receipt_path = (\n        _p33_work\n        / \"public0033_overlay_receipt.json\"\n    )\n    _p33_temp_path = (\n        _p33_work\n        / \"submission_public0033.tmp.csv\"\n    )\n\n    for _p33_path, _p33_name in (\n        (\n            _p33_parent_path,\n            \"parent backup\",\n        ),\n        (\n            _p33_current_path,\n            \"current parent submission\",\n        ),\n        (\n            _p33_bag_path,\n            \"bag raw prediction\",\n        ),\n        (\n            _p33_audit_path,\n            \"infra0021 audit receipt\",\n        ),\n    ):\n        if not _p33_path.is_file():\n            raise RuntimeError(\n                f\"public0033: required \"\n                f\"{_p33_name} is missing: \"\n                f\"{_p33_path}\"\n            )\n\n    # The custom route requires the two components\n    # created by the upstream Raptor blending cell.\n    if (\n        \"_blend_tr\" not in globals()\n        or \"_blend_cr\" not in globals()\n        or \"_blend_transformer\" not in globals()\n        or \"_blend_coatnet\" not in globals()\n    ):\n        raise RuntimeError(\n            \"public0033: Transformer/Raptor blend \"\n            \"components are unavailable\"\n        )\n\n    if _P33_CUSTOM_TARGET not in _blend_tr.columns:\n        raise RuntimeError(\n            \"public0033: Medial Meniscus missing \"\n            \"from Transformer rank component\"\n        )\n\n    if _P33_CUSTOM_TARGET not in _blend_cr.columns:\n        raise RuntimeError(\n            \"public0033: Medial Meniscus missing \"\n            \"from Raptor rank component\"\n        )\n\n    _p33_audit = _p33_json.loads(\n        _p33_audit_path.read_text(\n            encoding=\"utf-8\"\n        )\n    )\n\n    if _p33_audit.get(\"status\") != \"passed\":\n        raise RuntimeError(\n            \"public0033: infra0021 audit did not pass\"\n        )\n\n    _p33_parent_sha = _p33_sha256_file(\n        _p33_parent_path\n    )\n\n    if (\n        _p33_sha256_file(_p33_current_path)\n        != _p33_parent_sha\n    ):\n        raise RuntimeError(\n            \"public0033: submission.csv changed \"\n            \"after the parent audit\"\n        )\n\n    _p33_parent_rows = _p33_read_tokens(\n        _p33_parent_path,\n        _P33_HEADER,\n        \"parent backup\",\n    )\n\n    _p33_parent_uids = [\n        _p33_row[0]\n        for _p33_row in _p33_parent_rows\n    ]\n\n    if (\n        any(\n            not _p33_uid\n            for _p33_uid in _p33_parent_uids\n        )\n        or len(\n            set(_p33_parent_uids)\n        )\n        != len(_p33_parent_uids)\n    ):\n        raise RuntimeError(\n            \"public0033: parent backup UID identity drift\"\n        )\n\n    _p33_root = _p33_competition_root()\n    _p33_test = _p33_test_uids(\n        _p33_root\n    )\n\n    if _p33_parent_uids != _p33_test:\n        raise RuntimeError(\n            \"public0033: parent backup UID order \"\n            \"differs from test.csv\"\n        )\n\n    # Explicitly verify that upstream rank components\n    # have the same row identity as the parent.\n    _p33_transformer_uids = (\n        _blend_transformer[\n            \"StudyInstanceUID\"\n        ]\n        .astype(str)\n        .tolist()\n    )\n\n    _p33_raptor_uids = (\n        _blend_coatnet[\n            \"StudyInstanceUID\"\n        ]\n        .astype(str)\n        .tolist()\n    )\n\n    if (\n        _p33_transformer_uids\n        != _p33_parent_uids\n    ):\n        raise RuntimeError(\n            \"public0033: Transformer component UID order drift\"\n        )\n\n    if (\n        _p33_raptor_uids\n        != _p33_parent_uids\n    ):\n        raise RuntimeError(\n            \"public0033: Raptor component UID order drift\"\n        )\n\n    _p33_uid_sha = _p33_uid_sha256(\n        _p33_parent_uids\n    )\n\n    _p33_visible_reference = (\n        _p33_uid_sha\n        == _P33_VISIBLE_UID_SHA256\n    )\n\n    if (\n        _p33_visible_reference\n        and _p33_parent_sha\n        != _P33_VISIBLE_PARENT_SHA256\n    ):\n        raise RuntimeError(\n            \"public0033: visible parent \"\n            \"submission SHA gate failed\"\n        )\n\n    _p33_parent_values = _p33_matrix(\n        _p33_parent_rows,\n        tuple(\n            range(\n                1,\n                len(_P33_HEADER),\n            )\n        ),\n        \"parent backup\",\n    )\n\n    _p33_bag_rows = _p33_read_tokens(\n        _p33_bag_path,\n        _P33_BAG_HEADER,\n        \"bag raw\",\n    )\n\n    _p33_bag_by_uid = {}\n\n    for _p33_row in _p33_bag_rows:\n        _p33_uid = _p33_row[0]\n\n        if (\n            not _p33_uid\n            or _p33_uid\n            in _p33_bag_by_uid\n        ):\n            raise RuntimeError(\n                \"public0033: bag raw UID identity drift\"\n            )\n\n        _p33_bag_by_uid[\n            _p33_uid\n        ] = _p33_row\n\n    if (\n        set(_p33_bag_by_uid)\n        != set(_p33_parent_uids)\n    ):\n        raise RuntimeError(\n            \"public0033: bag raw UID set \"\n            \"differs from parent backup\"\n        )\n\n    _p33_bag_rows_ordered = [\n        _p33_bag_by_uid[_p33_uid]\n        for _p33_uid in _p33_parent_uids\n    ]\n\n    _p33_bag_values = _p33_matrix(\n        _p33_bag_rows_ordered,\n        (1, 2),\n        \"bag raw\",\n    )\n\n    _p33_final_rows = [\n        list(_p33_row)\n        for _p33_row in _p33_parent_rows\n    ]\n\n    _p33_final_values = (\n        _p33_parent_values.copy()\n    )\n\n    # All eleven untouched targets must remain byte-identical\n    # to the exact 0.936 parent.\n    _p33_untouched_columns = []\n    _p33_untouched_digests_parent = {}\n\n    for (\n        _p33_target_index,\n        _p33_target,\n    ) in enumerate(_P33_LABELS):\n\n        _p33_column = (\n            _p33_target_index + 1\n        )\n\n        if (\n            _p33_target\n            != _P33_CUSTOM_TARGET\n        ):\n            _p33_untouched_columns.append(\n                _p33_column\n            )\n\n            _p33_untouched_digests_parent[\n                _p33_target\n            ] = _p33_token_digest(\n                _p33_parent_rows,\n                _p33_column,\n            )\n\n            continue\n\n        # Transformer rank and Raptor rank are exactly the\n        # pre-final-rerank components used by the parent.\n        _p33_tr_rank = _p33_np.asarray(\n            _blend_tr[\n                _P33_CUSTOM_TARGET\n            ].to_numpy(),\n            dtype=_p33_np.float64,\n        )\n\n        _p33_r_rank = _p33_np.asarray(\n            _blend_cr[\n                _P33_CUSTOM_TARGET\n            ].to_numpy(),\n            dtype=_p33_np.float64,\n        )\n\n        _p33_bag_rank = (\n            _p33_average_tie_rank_pct(\n                _p33_bag_values[\n                    :,\n                    _P33_MENISCUS.index(\n                        _P33_CUSTOM_TARGET\n                    ),\n                ]\n            )\n        )\n\n        if (\n            _p33_tr_rank.shape\n            != _p33_bag_rank.shape\n            or _p33_r_rank.shape\n            != _p33_bag_rank.shape\n        ):\n            raise RuntimeError(\n                \"public0033: custom component \"\n                \"shape mismatch\"\n            )\n\n        if not (\n            _p33_np.isfinite(\n                _p33_tr_rank\n            ).all()\n            and _p33_np.isfinite(\n                _p33_r_rank\n            ).all()\n            and _p33_np.isfinite(\n                _p33_bag_rank\n            ).all()\n        ):\n            raise RuntimeError(\n                \"public0033: custom component \"\n                \"contains non-finite values\"\n            )\n\n        # Directly replace a portion of the Transformer vote.\n        # Raptor remains at the parent's original 60%.\n        _p33_pre_rank = (\n            _P33_T_WEIGHT\n            * _p33_tr_rank\n            + _P33_R_WEIGHT\n            * _p33_r_rank\n            + _P33_CUSTOM_BAG_WEIGHT\n            * _p33_bag_rank\n        )\n\n        if (\n            not _p33_np.isfinite(\n                _p33_pre_rank\n            ).all()\n            or _p33_pre_rank.min()\n            < 0.0\n            or _p33_pre_rank.max()\n            > 1.0\n        ):\n            raise RuntimeError(\n                \"public0033: invalid pre-rerank \"\n                \"Medial Meniscus values\"\n            )\n\n        # Match the parent's final Raptor-blend contract.\n        _p33_blended = (\n            _p33_average_tie_rank_pct(\n                _p33_pre_rank\n            )\n        )\n\n        if (\n            not _p33_np.isfinite(\n                _p33_blended\n            ).all()\n            or _p33_blended.min()\n            < 0.0\n            or _p33_blended.max()\n            > 1.0\n        ):\n            raise RuntimeError(\n                \"public0033: invalid final \"\n                \"Medial Meniscus values\"\n            )\n\n        _p33_final_values[\n            :,\n            _p33_target_index,\n        ] = _p33_blended\n\n        for (\n            _p33_row_index,\n            _p33_value,\n        ) in enumerate(\n            _p33_blended\n        ):\n            _p33_final_rows[\n                _p33_row_index\n            ][\n                _p33_column\n            ] = format(\n                float(_p33_value),\n                \".17g\",\n            )\n\n    if any(\n        _p33_final_row[0]\n        != _p33_parent_row[0]\n        for (\n            _p33_final_row,\n            _p33_parent_row,\n        ) in zip(\n            _p33_final_rows,\n            _p33_parent_rows,\n        )\n    ):\n        raise RuntimeError(\n            \"public0033: output UID token changed\"\n        )\n\n    _p33_untouched_digests_final = {}\n\n    for (\n        _p33_target_index,\n        _p33_target,\n    ) in enumerate(_P33_LABELS):\n\n        if (\n            _p33_target\n            == _P33_CUSTOM_TARGET\n        ):\n            continue\n\n        _p33_column = (\n            _p33_target_index + 1\n        )\n\n        if any(\n            _p33_final_row[\n                _p33_column\n            ]\n            != _p33_parent_row[\n                _p33_column\n            ]\n            for (\n                _p33_final_row,\n                _p33_parent_row,\n            ) in zip(\n                _p33_final_rows,\n                _p33_parent_rows,\n            )\n        ):\n            raise RuntimeError(\n                \"public0033: untouched raw \"\n                f\"token changed: {_p33_target}\"\n            )\n\n        _p33_untouched_digests_final[\n            _p33_target\n        ] = _p33_token_digest(\n            _p33_final_rows,\n            _p33_column,\n        )\n\n    if (\n        _p33_untouched_digests_final\n        != _p33_untouched_digests_parent\n    ):\n        raise RuntimeError(\n            \"public0033: untouched raw-token \"\n            \"digest mismatch\"\n        )\n\n    if _p33_temp_path.exists():\n        _p33_temp_path.unlink()\n\n    with _p33_temp_path.open(\n        \"w\",\n        encoding=\"utf-8\",\n        newline=\"\",\n    ) as _p33_handle:\n\n        _p33_writer = _p33_csv.writer(\n            _p33_handle,\n            lineterminator=\"\\n\",\n        )\n\n        _p33_writer.writerow(\n            _P33_HEADER\n        )\n\n        _p33_writer.writerows(\n            _p33_final_rows\n        )\n\n    _p33_reloaded_rows = (\n        _p33_read_tokens(\n            _p33_temp_path,\n            _P33_HEADER,\n            \"temporary overlay\",\n        )\n    )\n\n    _p33_reloaded_uids = [\n        _p33_row[0]\n        for _p33_row\n        in _p33_reloaded_rows\n    ]\n\n    if (\n        _p33_reloaded_uids\n        != _p33_parent_uids\n    ):\n        raise RuntimeError(\n            \"public0033: temporary overlay \"\n            \"UID order drift\"\n        )\n\n    _p33_reloaded_values = (\n        _p33_matrix(\n            _p33_reloaded_rows,\n            tuple(\n                range(\n                    1,\n                    len(_P33_HEADER),\n                )\n            ),\n            \"temporary overlay\",\n        )\n    )\n\n    if not _p33_np.array_equal(\n        _p33_reloaded_values,\n        _p33_final_values,\n    ):\n        _p33_max_abs = float(\n            _p33_np.max(\n                _p33_np.abs(\n                    _p33_reloaded_values\n                    - _p33_final_values\n                )\n            )\n        )\n\n        raise RuntimeError(\n            \"public0033: CSV/in-memory gate \"\n            f\"failed (max abs \"\n            f\"{_p33_max_abs:.3e})\"\n        )\n\n    for (\n        _p33_target_index,\n        _p33_target,\n    ) in enumerate(_P33_LABELS):\n\n        if (\n            _p33_target\n            == _P33_CUSTOM_TARGET\n        ):\n            continue\n\n        _p33_column = (\n            _p33_target_index + 1\n        )\n\n        if (\n            _p33_token_digest(\n                _p33_reloaded_rows,\n                _p33_column,\n            )\n            != _p33_untouched_digests_parent[\n                _p33_target\n            ]\n        ):\n            raise RuntimeError(\n                \"public0033: temporary untouched \"\n                f\"token drift: {_p33_target}\"\n            )\n\n    _p33_os.replace(\n        _p33_temp_path,\n        _p33_current_path,\n    )\n\n    _p33_output_sha = (\n        _p33_sha256_file(\n            _p33_current_path\n        )\n    )\n\n    _p33_receipt = {\n        \"schema_version\": (\n            \"public0033_medial_t30_r60_b10_overlay_v1\"\n        ),\n        \"status\": \"passed\",\n        \"parent_authority\": str(\n            _p33_parent_path\n        ),\n        \"parent_submission_sha256\": (\n            _p33_parent_sha\n        ),\n        \"parent_uid_sha256\": (\n            _p33_uid_sha\n        ),\n        \"visible_parent_sha_gate_applied\": (\n            _p33_visible_reference\n        ),\n        \"legacy_post_parent_residual\": {\n            \"parent_rank_weight\": float(\n                _P33_PARENT_WEIGHT\n            ),\n            \"bag_rank_weight\": float(\n                _P33_BAG_WEIGHT\n            ),\n            \"enabled\": False,\n        },\n        \"bag_raw_path\": str(\n            _p33_bag_path\n        ),\n        \"bag_raw_sha256\": (\n            _p33_sha256_file(\n                _p33_bag_path\n            )\n        ),\n        \"targets_changed\": [\n            _P33_CUSTOM_TARGET\n        ],\n        \"custom_route\": {\n            \"target\": (\n                _P33_CUSTOM_TARGET\n            ),\n            \"transformer_rank_weight\": float(\n                _P33_T_WEIGHT\n            ),\n            \"raptor_rank_weight\": float(\n                _P33_R_WEIGHT\n            ),\n            \"bag_rank_weight\": float(\n                _P33_CUSTOM_BAG_WEIGHT\n            ),\n            \"weights_sum\": float(\n                _P33_T_WEIGHT\n                + _P33_R_WEIGHT\n                + _P33_CUSTOM_BAG_WEIGHT\n            ),\n            \"final_rerank\": True,\n        },\n        \"rank\": (\n            \"float64_average_tie_percentile_rank_over_all_test_studies\"\n        ),\n        \"untouched_targets\": [\n            _p33_target\n            for _p33_target\n            in _P33_LABELS\n            if _p33_target\n            != _P33_CUSTOM_TARGET\n        ],\n        \"untouched_target_raw_token_sha256\": (\n            _p33_untouched_digests_final\n        ),\n        \"output_path\": str(\n            _p33_current_path\n        ),\n        \"output_sha256\": (\n            _p33_output_sha\n        ),\n        \"csv_vs_memory_max_abs\": 0.0,\n    }\n\n    _p33_receipt_path.write_text(\n        _p33_json.dumps(\n            _p33_receipt,\n            ensure_ascii=False,\n            indent=2,\n            sort_keys=True,\n        )\n        + \"\\n\",\n        encoding=\"utf-8\",\n    )\n\n    print(\n        \"public0033 Medial T30/R60/bag10 \"\n        \"overlay PASSED | \"\n        f\"studies={len(_p33_parent_uids)} \"\n        f\"output_sha256={_p33_output_sha}\",\n        flush=True,\n    )\n\n\n_p33_main()","metadata":{"papermill":{"duration":0.077706,"end_time":"2026-09-04T03:00:10.68067+00:00","exception":false,"start_time":"2026-09-04T03:00:10.602964+00:00","status":"completed"},"tags":[],"trusted":true},"outputs":[],"execution_count":null},{"id":"d8e18e42-5a68-4fd1-bc63-4608c7bf5eb8","cell_type":"code","source":"# DINOSAUR_V4_PRESERVE_EXACT_0937_CONTROL\nfrom pathlib import Path as _D4Path\nimport hashlib as _d4_hashlib\nimport json as _d4_json\nimport shutil as _d4_shutil\n\n_d4_work = _D4Path('/kaggle/working')\n_d4_sub = _d4_work / 'submission.csv'\n_d4_receipt = _d4_work / 'public0033_overlay_receipt.json'\n_d4_control = _d4_work / 'submission_dinosaur_v4_0937_control.csv'\n\ndef _d4_sha(path):\n    h = _d4_hashlib.sha256()\n    with path.open('rb') as f:\n        for b in iter(lambda: f.read(8 << 20), b''):\n            h.update(b)\n    return h.hexdigest()\n\nfor _p in (_d4_sub, _d4_receipt):\n    if not _p.is_file():\n        raise FileNotFoundError(_p)\n_r = _d4_json.loads(_d4_receipt.read_text(encoding='utf-8'))\n_sha = _d4_sha(_d4_sub)\nif _r.get('status') != 'passed' or _r.get('output_sha256') != _sha:\n    raise RuntimeError('DINOsaur V4: 0.937 weak-label overlay receipt/output mismatch')\n_d4_shutil.copyfile(_d4_sub, _d4_control)\nprint(f'DINOsaur V4: exact 0.937 control preserved -> {_d4_control.name} | sha256={_sha}', flush=True)\n","metadata":{"tags":["DINOsaur-V4-0937-control"],"trusted":true},"outputs":[],"execution_count":null},{"id":"b0a639ee-dab4-4973-8653-4d6e79f95925","cell_type":"markdown","source":"## 🧪 DINOsaur V4 — PublicDual branch\n\nThe cells above still reproduce and preserve the known **0.937** Renta-based control.\n\nThis branch now rewinds only to the post-DINOv3 / pre-Rad transformer state and rebuilds the downstream path with a more diverse **public-only Rad-dual5** signal:\n\n1. two distinct five-fold public v15/E10 RadImageNet head families;\n2. E13 FS-crop specialist at 0.50 inside the Rad block;\n3. a second E13 pass on the E11 slot layout at 0.15;\n4. the same public four-view Raptor;\n5. the proven Renta Medial-Meniscus residual `T30 / R60 / bag10`.\n\nThe private CoAtNet `resgated e4/e6/e8` residual from the 0.938 reference is deliberately excluded.\n","metadata":{}},{"id":"412e4dc0-a132-4908-ba6c-6ee6018abf08","cell_type":"code","source":"# DINOSAUR_V4_PUBLICDUAL_RESTORE_PRE_RAD\nfrom pathlib import Path as _D4PDPath\nimport shutil as _d4pd_shutil\n\n_d4pd_work = _D4PDPath('/kaggle/working')\n_d4pd_pre = _d4pd_work / 'submission_dinosaur_v4_pre_rad.csv'\n_d4pd_primary = _d4pd_work / 'submission.csv'\n\nif not _d4pd_pre.is_file():\n    raise FileNotFoundError(_d4pd_pre)\n\n# Public-only branch: no private CoAt artifact is searched, imported, or loaded.\n_d4pd_shutil.copyfile(_d4pd_pre, _d4pd_primary)\nprint('DINOsaur V4 PublicDual: restored post-DINOv3 / pre-Rad transformer state', flush=True)\n","metadata":{"tags":["DINOsaur-V4","public-only","restore"],"trusted":true},"outputs":[],"execution_count":null},{"id":"30a28007-8d96-4683-8d58-7b1b008eee14","cell_type":"code","source":"from __future__ import annotations\nimport base64 as _rad_b64\nimport zlib as _rad_zlib\n_RAD_CAL_PAYLOAD = 'eNrtmk1vI8cRhv9KsJdcKKE/q6tzc4z4ZCMBcjQWhrCRDSG2ZEjaIEGQ/57n7RlRQ3KG4jqLJAcDS4o709NdXR9vvVU9/3z30+3N/bvffRuuawgxlm7eq2ePeffrpV8v/V9euvLraD3k6ilW6zn126vYd+U6eKmx9RiaF7OSx+X1weE67K7SdSgpVSauuaecUxr3rtp1LK0HyyV7y9Gmy/E6pBhTL61Zt2gWx+WtSew6JmOoM5AHutXp+ro8+ZrlsnvJOfDdfRL+Kl4zd2bqllNmga7rvrva2OzGNFuynGxpmnxrS/069hCtpt6T1dLLOQVsTbJ1fWunG2qXAX8NiU+7VK8rdqvNU89uwQwjpWyeLdTCnVy84ua9pthSjznHXLjDpZxbLe4WPRAQCT+LrSVcGGdLzNX0XKhesC2eV5uZ67lQPDlmSzUhS2+61ELtoTOyWGjdPudc73fvnj7c/Hg7ElpyzYXjdwIZ32m7X3INZ0crtvtc833ua6fyoUYUGf4H13rJpX+GK5aa5VbeWO9ye/03bLi97i8SpaSCl49nc4gdxI2p1dZyVmQnfL56jBH/j70GqSq6dyMROLHQGvCpcSnkYsyeohNErnVjbamVjs47wOpBa7BAsa61SXulDfSIwAbAkQqDmSK38WwImKK1kFJ3d11CpFqR1mPHlj1pWVAHeDfyU2hk0vGogz0GqCBbKmFMx9xIWEAbQ8I4PUvmAplQCeuij7GNXGMk3yhBsFIfEnvVE6HFYMHDtFuLzKwpya9gisaZduAkcyAvmw1ROjmd7OnBYytpOBqJjTyK4KzT0Pi0tQJYslc0nGqcNZV7dEaRvfcSewg9h4p41iwO+4CWMkNG1326VBmHFUoB7VoakzE+JAtYN/NknS9lLJ+9S5qR56Q2kLA4qgTuplGNmUJAkbXiGbrU0HCIsgtYaGOUVXbayNeykLfpGv8lulBfgiFEmx61xm3LTlrOPoa51Ng7IyJiT4tWxrE0ZmnJRnhawZsyLgjXIC9MRu0tRAgImkJ7bUyHKk1eUgIewtRjXGDJqO1mNJrHfNUty1HRW2SSoV3FAVIA//hrUXKANxhbRbEkgqAFKiCC43qOEXsPTaKtKCdkqx3/koMYsuP+mh4HrHoQtqSIw/h4DM7EpRL5zRirAcHiUDj2SUlr9fFAsElHBX/zWgJCQlw+83Qksw8Pt9+Ty0hmOBQBh9XQAr7fxjRQ2IkGTT/w8cAiBKwRc1jwcMh+WKtMgFShNaDGJWRAechNSOMUldXTynNIUPAaEKKkCv1cLFzxaowBOmX8vU8Pj1voWa5JTPFcGN4QXm+PpZPjA8QQYYp9Qab9rZiIAuLX8AA8f/jX4kHgI+BXCtBEeOTFvNPapIyC92YAEOmHypJcCSiFOpQi712M73IL8KiBX8Hz62pDNsAH8MK/rMR+tNSRIRJwAkIIY8Rn/fD2kB2V9I7BMX+KSJ/XJtNAbwFglmQZbu/90CZcMhAeZKudKAvlSBLwNwP1aA88BYpPdJRkbADGeBzWN2IOvySVELxyU0Lx0JHQHsFpEQRsCB9iO1qT3IOHGUjMDqeczX4BiIbvCjkiLD6t6G239p+gAML1KQuAdaLLdidDV6Y6uPR+9+3LT8KrlYgzAsjg7ok+VJakimvgAjn5qUFmtTGJKXGxSadg2UuLkWok4EvGJ0Hdsr+DmpVlGsUMZkxtuTI8vDAVaIsnSIDbK0DhVSpAFlu4iRtgrLYWRaArADOcFDAfErEdwBS8dWpNqHupW3o7nIukTmxlmASq4L/51ESrznqJTSkgCzslVSMncekb8659ljeyYttxK0oX9k50n3h2kDqoapToWt8S9/yO3tTXyteLu+19rkPViKkIblLnzJhJUhYENUJCtdfWKkEFe9WTsWin6azpqJFIfEwNyLNes+PZXFV3h+tIOXjb5mzIRnCLaWKuhnPtjsCVPAOwdkhQhBSMfWLVruTgwEM/WXt1FYgv5AN4IsyBiHrOSscCBjIomksgZCPFn9grqDrE9UXDQCSPfs5RXyeuQl3gwcEIdn5JzADhpG34s4uF5NQ24eh1GWISkEmYA6iFiNezYAbkKNGJhIk+l9XNXK3r7AgLT4YnRUuHicJS0NRLLG0KDrF1IbkaMzj2MoeKzAH/kTo9KsnWJe8gDZUuxs1iPi0CayABMdLIT4qQCbfENfCiAsujIsj9KMUQ1kXwXUBFZspHZm9Zj/dB/SrVy1qOJg9ApKAlmSQNpr6SjibnNgVoqZQCr8gllgsTiFAOCFSeDcYWuKOChZQXi5dPxouF5Oo6ogVTaxDwnVE8KfQFI6Zomwgb/oI4VG2Ae1MdsTQCwQuZp5ZROZPcdudWHrZRfwe4cPE1cv9L/FDuwRwGNYOttGllMRItS1K3sFDQDAwQMvgpfIzyIeQj2yTFOhomGLsBVPtAASGLqiXKnChASW/4ILUTGlftQlUVl8FDjifbKYIzLKXmco4anNPK6ZVl8MhVBs+D5YgTo8HXuIEDQDJF4wHEYL5PvEExn4PIt7x0JumDeUgjxHeFIZDt+6xN5mALCc6pMjTZ7oy8EomCUA09MTRvvuCLxyFC+sEWCGiqjE+HIAJ4g39Bi5sadSN9MJZaFWLbpubBNBvlmwrPAONJWS1DpaIgbyKuZSbKg7qZzgNKsqnwIX8RAOvINdgfRg0jPNJBWE+5xAQ9qDaAPh4nKInagjAL9otj26U+sAnbUERTF0QYjHV8j8OEA+mohtH9SLLuoUIh6uAWHI6yAw54uEsqL6zufMAAt3yW+6xSFLmKwEmYgIPlXHYbPAo3AvKovCk/0KR5m3fmKkpFz2W3ng58h7KzqVVHqVYUpfGlAJHvQ2dN7QKmXoQITggHUz9HGZhSty5smYHeSL4pFdvbXlXZcSJV7GCHKPpsePEmVAOm41WxbuW3Y+qkrhYhisbrSBqbGiGdAkBwd5gzNehxGUVhzu5JCKa2VAyL2pfYgYgUtcTwu3RKZzO2JublhfCDbO1Qqypu8SdTWO0501Z6iAAH68g21mECvjX8bZZ7yvpViqq9BlHCnhj7DFuiXm8qEwgrAkK9hpfbuU/nN/i4l7I/qQEnpR4qVHUxgDjblWuM2UZFhOpzp+apb8i4ua8gnyHrqPMHs839gK7gaaYDDtILqNTWOF8kxVYdMxlVDwE68/F8DR2CgpCSkkzkEvKY3x9GoRqjpn8ZLj62TyEoRVV1dxrV2GtNOMosPAjqSC6pm6yRKRJFM5wnixbhh6uLl9FdjElsUvX7WxR61T1gGohOkQaej27MxiR+DQjAndQ5SgL4Yb+VMKT2UncGK4se5hfeR7Jr6nygbTJcPGK7QSpXOoBJkuMXlFTYQX0aRsObYEQn22BNrDQdKwmZ1DDaZNcANxumdkGs3pZIJcaCcxBuPSlGziTf+UNZIgqmLMTWS1/XYNBxFowH5FchZb7uT5EQqervUK+Rc15pP55mBpKra6Wju5MCbZwiKOSS/HFuZyVRBFeeIoVrc35oNnVt1ARpKDaHF2BO1z3DLILOrOVZdhIG52ojyFxsVa1k6Bq+sOS7AA0upIqpiCt9Om8+1SsIoI4/ZYFKZq9tdwnhCzrVRpoCxpqSo+0ua1DNLCOMc3X19vGSZZ9znfEAMTUpymSGqYW/kpXU6FWV6+pah9OGLveaTkopOV1d3U9oWfAhMiyK46fRgPeL9LTSDAtUjj5cFN4D8S5zmaCjmaTjJ/Kvxb3MaFrHVI27QS2vRfcMCmeqcUXY+NX6652okyj19OEC3SaFrdWyeyJMxo7gPrANn17GjQ5RgtqvregNjzr1hYOOxATeos4b/IItGRxEFZC4aNruVL1ZbGx8ojpE5moLiGNavazB+baxPoXr/gK56zjI1VGbjtG8nA3Xg3SpFl2gtqzqsM/oGgb5Axj4w+XD1g48MBFrMAnR+TRxMci1+8h+uCC1e1nmC7XEWhf2zEdIw5SsCe3Tcc18XibsU/PKhJhd7a380s67RLEvQQWUw9KKjmps7qefVeub/IZQoLbK0qxnHRFP7qlOy8BURC7Fy2LDPk7N1F1VEm1lrZbSmSWVSoNk63DQXgvIohAjYcjXU7b/zI8u7RVvPiRChSqVjkiU6YQjrT1ImVAAN/WoKEp62V2aQGAdAuQKhSW5qouyIdQ4jNe5NS6I8v10hLIeqIIMqplDn71o0dYl4fEFkRZ4LmhFJNUSQqZCNlBT2fIWnKzJ9XWwG48bOzGZWEIffcVx/q23xAziBV83gf1cE4/+mvI8/EFV3QVmPW0a6rB7ZD314ploTllOSlFYqX3X4u7TJg6jmxLRWxit1FaPtArKoHfHeb3jwPmNGDqfvS+Iv9Ns14Vv6p9rfyft+HGiFqmJIQSU++rlbegPBqDumli9zoOGSptec8O6GAWqtaAgkOgqZ3P1WhQQ08aj2KGONuEIqdZetzuLFB6qQniid8HkZTnlyGsPGnA4lY5Qu1456WnbokG9IupwU0NoPhHTwRRUqynZU0HObV8QUyZuo/lb6tFhsdxb7bCoU9qWe8vLxBwj2laVzgS+bIZGMfee1Qaldl87gBZ5jjr3Y4rq2Xaf3LatohHwxzbqBKtv4d8bHnh1eUqfVRx07jc4zfzySrj8IGV9NMFX4mBKrq6FXc4Jz154/3737u7++fbxw+3Pz9N7eg0X0mHCeHfHbHrNhrCIpdXRA/LRRC4WR9sU/ZqJB46XJsJouwU1rPT+il6uKHqNAdbJ2InUJp0wVWBV7w8NuldU7uMyajZqh2N6UfeoM6ym1zLGizF6T6AnNQZiHO/KZMijZMOV2/yKQFKv0TSXq0Hb5teE9F4HLp50QKJ3OX64edZ7ie+++PLrd7t339z+5e7mx9/88Qt+f82dx5f//Omr6e8fvv/+49Pdwz0/f3/z19vH3z7x68uH++fpKhP+/Pjw/PDh4cfv+Hz86f5Jk99/93T7eHersfff/fnmh/H3y4fH8feLv9/x96ub5+l7vq9f0wj9msf8+HH6fhnDr3kMvzRGG3p8+PizVt3vaXy/ysjox5sPzx8fbxn+7cuWv7m9v3v68PFpsfH9pcWwLc1oyEI3f/7H/cPf7p7vnhZ6ev/+X/8GYIe3xg=='\n# Surgical reproduction of V48's deployed prediction branch.\n#\n# The pinned reference Rad family is fused with correct-contract E13, then\n# the same E13 heads run on the E11 layout at 0.15. No twin/legacy wrapper\n# follows it, matching the branch that produced V48's visible submission.\n\nimport contextlib as _rad_contextlib\nimport gc as _rad_gc\nimport hashlib as _rad_hashlib\nimport json as _rad_json\nimport os as _rad_os\nimport re as _rad_re\nimport time as _rad_time\nfrom concurrent.futures import ThreadPoolExecutor as _RadThreadPool\nfrom pathlib import Path as _RadPath\n\nimport numpy as _rad_np\nimport pandas as _rad_pd\nimport pydicom as _rad_pydicom\nimport torch as _rad_torch\nimport torch.nn as _rad_nn\nimport torch.nn.functional as _rad_F\nfrom torchvision.models import resnet50 as _rad_resnet50\n\n_RAD_LABELS = [\n    'ACL', 'MCL', 'Medial Meniscus', 'Lateral Meniscus', 'Medial OA',\n    'Lateral OA', 'PF OA', 'Effusion', 'Synovitis', \"Baker's\",\n    'Contusion', 'Fracture',\n]\n_RAD_ALPHA = 0.50\n_RAD_EXCLUDE = (\"Baker's\", 'Fracture')\n_RAD_HEADS_SHA256 = '54f657826b3458a7ba3d462e198ba380732f2b136246182312704929874a9a2c'\n_RAD_REFERENCE_HEADS_SHA256 = '0f465649799ecfbccaac1767844639e7ced44e1bc9babde6e4bac7c5d9b89eaa'\n_RAD_ENCODER_SHA256 = '08629f7e7bd3e29b8ee9522ca3f65ce4d010a7ddf74f0ea3c7e3f3d0bbab0734'\n_RAD_E13_HEADS_SHA256 = 'ad9f19af73bfdf4e49263c0e45060dc3cb239e1195039b26dc8c0a3a6bcd1a8a'\n_RAD_E13_MEMBER_WEIGHT = 0.50\n_RAD_V48_SECOND_ALPHA = 0.15\n_RAD_TWIN_ALT_WEIGHT = 0.500001\n_RAD_TOKEN_DIM, _RAD_HEAD_DIM = 2048, 512\n\n_RAD_E11_SLOTS = [\n    ('SAG_NOFS', 'Sagittal', None, False),\n    ('COR_NOFS', 'Coronal', None, False),\n    ('AX_NOFS', 'Axial', None, False),\n    ('SAG_FS', 'Sagittal', None, True),\n]\n_RAD_E11_CROP_MM = 130.0\n_RAD_E11_CACHE_SLICES = 8\n_RAD_E11_IMG = 224\n\n_RAD_E13_SLOTS = [\n    ('SAG_FS', 'Sagittal', None, True),\n    ('COR_FS', 'Coronal', None, True),\n    ('AX_FS', 'Axial', None, True),\n    ('SAG_NOFS', 'Sagittal', None, False),\n]\n_RAD_E13_CROP_MM = 130.0\n_RAD_E13_CACHE_SLICES = 8\n_RAD_E13_IMG = 224\n\n# Our independently trained five-fold family.  Its preprocessing and estimator\n# are preserved from V35: native DICOM geometry/fat-sat handling and a mean of\n# per-fold percentile ranks (rather than v15's rank of the probability mean).\n_OUR_N_SLOT, _OUR_N_SLICE, _OUR_IMG = 3, 8, 224\n\n# Exact V40/E10 test representation: three fat-suppressed planes, eight\n# acquired slices per plane, full frame, legacy ordering/laterality/fill.\nSLOTS = [\n    ('SAG_FS', 'Sagittal', None, True),\n    ('COR_FS', 'Coronal', None, True),\n    ('AX_FS', 'Axial', None, True),\n]\nN_SLOT = len(SLOTS)\nCACHE_SLICES = 8\nIMG = CACHE_IMG = 224\nCROP_MM = 10_000.0\nSLICE_BAND = (0.2, 0.8)\nRULES = dict(RULES_LEGACY)\nTIME_BUDGET = 8.0 * 3600\n\n\ndef _rad_log(message):\n    print(f'[Rad-dual5] {message}', flush=True)\n\n\ndef _rad_sha256(path, chunk=8 << 20):\n    digest = _rad_hashlib.sha256()\n    with open(path, 'rb') as handle:\n        for block in iter(lambda: handle.read(chunk), b''):\n            digest.update(block)\n    return digest.hexdigest()\n\n\ndef _rad_find_file(name, expected_sha=None, explicit_env=None):\n    if explicit_env and _rad_os.environ.get(explicit_env):\n        candidates = [_RadPath(_rad_os.environ[explicit_env])]\n    else:\n        candidates = []\n        base = _RadPath('/kaggle/input')\n        if base.is_dir():\n            for root, dirs, files in _rad_os.walk(base):\n                dirs[:] = [d for d in dirs if d not in ('train_series', 'test_series')]\n                if name in files:\n                    candidates.append(_RadPath(root) / name)\n    if not candidates:\n        raise FileNotFoundError(f'V36 missing input artifact {name}')\n    for path in candidates:\n        if expected_sha is None or _rad_sha256(path) == expected_sha:\n            return path\n    raise RuntimeError(f'V36 found {name}, but no copy has the required SHA-256')\n\n\nclass _RadEncoder(_rad_nn.Module):\n    def __init__(self):\n        super().__init__()\n        self.backbone = _rad_nn.Sequential(\n            *list(_rad_resnet50(weights=None).children())[:-2]\n        )\n\n    def forward(self, image):\n        return self.backbone(image).mean(dim=(2, 3))\n\n\nclass _RadHead(_rad_nn.Module):\n    def __init__(self):\n        super().__init__()\n        self.project = _rad_nn.Sequential(\n            _rad_nn.LayerNorm(_RAD_TOKEN_DIM),\n            _rad_nn.Linear(_RAD_TOKEN_DIM, _RAD_HEAD_DIM),\n            _rad_nn.GELU(),\n        )\n        self.plane = _rad_nn.Parameter(_rad_torch.randn(N_SLOT, _RAD_HEAD_DIM) * .01)\n        self.position = _rad_nn.Parameter(_rad_torch.randn(CACHE_SLICES, _RAD_HEAD_DIM) * .01)\n        self.query = _rad_nn.Parameter(_rad_torch.randn(len(_RAD_LABELS), _RAD_HEAD_DIM) * .02)\n        self.attn = _rad_nn.MultiheadAttention(\n            _RAD_HEAD_DIM, 8, dropout=.10, batch_first=True\n        )\n        self.fuse = _rad_nn.Sequential(\n            _rad_nn.LayerNorm(_RAD_HEAD_DIM * 4),\n            _rad_nn.Linear(_RAD_HEAD_DIM * 4, _RAD_HEAD_DIM),\n            _rad_nn.GELU(),\n            _rad_nn.Dropout(.15),\n        )\n        self.weight = _rad_nn.Parameter(\n            _rad_torch.randn(len(_RAD_LABELS), _RAD_HEAD_DIM) * .02\n        )\n        self.bias = _rad_nn.Parameter(_rad_torch.zeros(len(_RAD_LABELS)))\n\n    def forward(self, feature, mask):\n        token = self.project(feature.float())\n        token = token.view(len(token), N_SLOT, CACHE_SLICES, _RAD_HEAD_DIM)\n        token = token + self.plane[None, :, None] + self.position[None, None]\n        token = token.flatten(1, 2)\n        key_padding = mask <= 0\n        all_empty = key_padding.all(1)\n        if all_empty.any():\n            key_padding = key_padding.clone()\n            key_padding[all_empty, 0] = False\n        query = self.query.unsqueeze(0).expand(len(token), -1, -1)\n        attended = query + self.attn(\n            query, token, token, key_padding_mask=key_padding, need_weights=False\n        )[0]\n        denominator = mask.sum(1, keepdim=True).clamp_min(1).unsqueeze(-1)\n        mean = (token * mask.unsqueeze(-1)).sum(1, keepdim=True) / denominator\n        mean = mean.expand(-1, len(_RAD_LABELS), -1)\n        fused = self.fuse(_rad_torch.cat(\n            [attended, mean, _rad_torch.abs(attended - mean), attended * mean], dim=-1\n        ))\n        return (fused * self.weight.unsqueeze(0)).sum(-1) + self.bias\n\n\ndef _rad_load_public_heads(device, expected_sha):\n    heads_path = _rad_find_file('v52_radimagenet_heads.pt', expected_sha)\n    payload = _rad_torch.load(heads_path, map_location='cpu', weights_only=True)\n    expected = {\n        'version': 'v52-radimagenet-resnet50-official-1',\n        'targets': _RAD_LABELS,\n        'encoder_sha256': _RAD_ENCODER_SHA256,\n        'encoder_source_commit': '0ce16f7375db4236e646829d1eca61cdb4282133',\n        'img': 224,\n        'slices_per_plane': 8,\n        'feature': 'global_average_pool',\n    }\n    for key, value in expected.items():\n        if payload.get(key) != value:\n            raise RuntimeError(f'public-v15 head contract drift for {key}')\n    folds = payload.get('folds')\n    if not isinstance(folds, list) or len(folds) != 5:\n        raise RuntimeError('public-v15 bundle requires exactly five heads')\n    if sorted(int(record.get('fold', -1)) for record in folds) != list(range(5)):\n        raise RuntimeError('public-v15 fold identity drift')\n    heads = []\n    for record in folds:\n        head = _RadHead().to(device).eval()\n        head.load_state_dict(record['state_dict'], strict=True)\n        heads.append(head)\n    return heads, str(heads_path)\n\n\ndef _rad_load_e13_heads(device):\n    # V48 used an unqualified filename shared by E11 and E13. Resolve the\n    # intended E13 bundle by content and validate its complete pixel contract.\n    heads_path = _rad_find_file('v52_e11_heads.pt', _RAD_E13_HEADS_SHA256)\n    payload = _rad_torch.load(heads_path, map_location='cpu', weights_only=False)\n    expected = {\n        'version': 'e11-radimagenet-resnet50-diverse-1',\n        'targets': _RAD_LABELS,\n        'encoder_sha256': _RAD_ENCODER_SHA256,\n        'slots': [list(slot) for slot in _RAD_E13_SLOTS],\n        'crop_mm': _RAD_E13_CROP_MM,\n        'img': _RAD_E13_IMG,\n        'slices_per_plane': _RAD_E13_CACHE_SLICES,\n        'feature': 'global_average_pool',\n    }\n    for key, value in expected.items():\n        if payload.get(key) != value:\n            raise RuntimeError(f'E13 head contract drift for {key}')\n    folds = payload.get('folds')\n    if not isinstance(folds, list) or len(folds) != 5:\n        raise RuntimeError('E13 bundle requires exactly five heads')\n    if sorted(int(record.get('fold', -1)) for record in folds) != list(range(5)):\n        raise RuntimeError('E13 fold identity drift')\n    heads = []\n    for record in folds:\n        head = _RadHead().to(device).eval()\n        head.load_state_dict(record['state_dict'], strict=True)\n        heads.append(head)\n    return heads, str(heads_path)\n\n\ndef _rad_load_models(device):\n    encoder_path = _rad_find_file(\n        'ResNet50.pt', _RAD_ENCODER_SHA256, explicit_env='RSNA_RAD_WEIGHT_PATH'\n    )\n    encoder = _RadEncoder()\n    encoder.load_state_dict(\n        _rad_torch.load(encoder_path, map_location='cpu', weights_only=True), strict=True\n    )\n    if sum(parameter.numel() for parameter in encoder.parameters()) != 23_508_032:\n        raise RuntimeError('V36 RadImageNet encoder parameter-count drift')\n    encoder.eval().to(device)\n    for parameter in encoder.parameters():\n        parameter.requires_grad_(False)\n    if device.type == 'cuda' and _rad_torch.cuda.device_count() > 1:\n        encoder = _rad_nn.DataParallel(\n            encoder, device_ids=list(range(_rad_torch.cuda.device_count()))\n        )\n\n    alt_heads, alt_path = _rad_load_public_heads(device, _RAD_HEADS_SHA256)\n    reference_heads, reference_path = _rad_load_public_heads(\n        device, _RAD_REFERENCE_HEADS_SHA256\n    )\n    if alt_path == reference_path:\n        raise RuntimeError('twin E10 branches resolved to the same artifact')\n    return encoder, alt_heads, reference_heads, str(encoder_path), alt_path, reference_path\n\n\n@_rad_torch.inference_mode()\ndef _rad_encode(encoder, pixels, slot_mask, device):\n    n, slots, slices, height, width = pixels.shape\n    features = _rad_np.zeros(\n        (n, slots * slices, _RAD_TOKEN_DIM), _rad_np.float16\n    )\n    token_mask = _rad_np.repeat(slot_mask[:, :, None], slices, axis=2).reshape(n, -1)\n    valid = _rad_np.flatnonzero(token_mask.reshape(-1) > 0)\n    flat = pixels.reshape(-1, height, width)\n    batch = 192 if device.type == 'cuda' and _rad_torch.cuda.device_count() > 1 else (\n        96 if device.type == 'cuda' else 8\n    )\n    for start in range(0, len(valid), batch):\n        indices = valid[start:start + batch]\n        image = _rad_torch.from_numpy(flat[indices]).to(device).float().div_(127.5).sub_(1.0)\n        image = image.unsqueeze(1).expand(-1, 3, -1, -1).contiguous()\n        amp = (_rad_torch.autocast('cuda')\n               if device.type == 'cuda' else _rad_contextlib.nullcontext())\n        with amp:\n            feature = encoder(image)\n        values = feature.float().cpu().numpy()\n        if not _rad_np.isfinite(values).all():\n            raise RuntimeError('V36 non-finite RadImageNet feature')\n        features.reshape(-1, _RAD_TOKEN_DIM)[indices] = values.astype(_rad_np.float16)\n    return features, token_mask.astype(_rad_np.float32)\n\n\n@_rad_torch.inference_mode()\ndef _rad_predict_head(head, features, masks, device, batch=64):\n    predictions = []\n    for start in range(0, len(features), batch):\n        image = _rad_torch.from_numpy(features[start:start + batch]).to(device)\n        mask = _rad_torch.from_numpy(masks[start:start + batch]).to(device)\n        amp = (_rad_torch.autocast('cuda')\n               if device.type == 'cuda' else _rad_contextlib.nullcontext())\n        with amp:\n            predictions.append(_rad_torch.sigmoid(head(image, mask)).float().cpu())\n    return _rad_torch.cat(predictions).numpy()\n\n\ndef _rad_rank_columns(values):\n    return _rad_pd.DataFrame(\n        _rad_np.asarray(values, dtype=_rad_np.float64)\n    ).rank(method='average', pct=True).to_numpy(_rad_np.float64)\n\n\ndef _rad_validate(frame, expected_ids):\n    if frame.columns.tolist() != ['StudyInstanceUID', *_RAD_LABELS]:\n        raise RuntimeError('V36 submission schema drift')\n    ids = frame['StudyInstanceUID'].astype(str).tolist()\n    if ids != list(map(str, expected_ids)) or len(ids) != len(set(ids)):\n        raise RuntimeError('V36 submission study identity/order drift')\n    values = frame[_RAD_LABELS].to_numpy(_rad_np.float64)\n    if not _rad_np.isfinite(values).all() or values.min() < 0 or values.max() > 1:\n        raise RuntimeError('V36 invalid submission values')\n\n\ndef _rad_main():\n    started = _rad_time.time()\n    work = _RadPath(_rad_os.environ.get('RSNA_RAD_OUTPUT_DIR', '/kaggle/working'))\n    primary = work / 'submission.csv'\n    if not primary.is_file():\n        raise FileNotFoundError('V37 requires the completed DINO parent submission.csv')\n    test = _rad_pd.read_csv(ROOT / 'test.csv', dtype={'StudyInstanceUID': str})\n    expected_ids = test['StudyInstanceUID'].astype(str).tolist()\n    baseline = _rad_pd.read_csv(primary, dtype={'StudyInstanceUID': str})\n    _rad_validate(baseline, expected_ids)\n\n    device = _rad_torch.device('cuda:0' if _rad_torch.cuda.is_available() else 'cpu')\n    if device.type != 'cuda':\n        raise RuntimeError('V37 RadImageNet inference requires CUDA')\n    (encoder, public_heads, reference_heads, encoder_path,\n     public_heads_path, reference_heads_path) = _rad_load_models(device)\n\n    # Family 1: public v15/E10 legacy pixels.  Keep this path bit-for-bit as in\n    # V36, including rank(mean(fold probability)).\n    test_series = _rad_pd.read_csv(\n        ROOT / 'test_series.csv',\n        dtype={'StudyInstanceUID': str, 'SeriesInstanceUID': str},\n    )\n    plane = dict(zip(test_series.SeriesInstanceUID, test_series.Anatomical_Plane))\n    headers = annotate(walk('test_series'))\n    studies, pixels, slot_mask = build_cache(\n        pick_slots(headers, plane), plane, lat_of(headers, 'test-e10 '), 'test-e10'\n    )\n    by_uid = {str(uid): index for index, uid in enumerate(studies)}\n    missing = [uid for uid in expected_ids if uid not in by_uid]\n    if missing:\n        raise RuntimeError(f'{len(missing)} test studies absent from public-v15 cache')\n    order = _rad_np.asarray([by_uid[uid] for uid in expected_ids], dtype=_rad_np.int64)\n    pixels, slot_mask = pixels[order], slot_mask[order]\n    token_count = int(\n        _rad_np.repeat(slot_mask[:, :, None], CACHE_SLICES, axis=2).sum()\n    )\n    if token_count < int(0.85 * len(test) * N_SLOT * CACHE_SLICES):\n        raise RuntimeError(f'insufficient acquired public-v15 test slices: {token_count}')\n\n    features, token_mask = _rad_encode(encoder, pixels, slot_mask, device)\n    del pixels, slot_mask, headers\n    _rad_gc.collect()\n    public_fold_predictions = [\n        _rad_predict_head(head, features, token_mask, device)\n        for head in public_heads\n    ]\n    reference_fold_predictions = [\n        _rad_predict_head(head, features, token_mask, device)\n        for head in reference_heads\n    ]\n    if len(public_fold_predictions) != 5 or len(reference_fold_predictions) != 5:\n        raise RuntimeError('twin E10 inference did not use all ten heads')\n\n    # Preserve each public recipe's rank(mean(fold probability)) estimator.\n    public_probability = _rad_np.mean(_rad_np.stack(public_fold_predictions), axis=0)\n    reference_probability = _rad_np.mean(\n        _rad_np.stack(reference_fold_predictions), axis=0\n    )\n    public_rank = _rad_rank_columns(public_probability)\n    reference_rank = _rad_rank_columns(reference_probability)\n    del (public_heads, reference_heads, public_fold_predictions,\n         reference_fold_predictions, public_probability, reference_probability,\n         features, token_mask)\n    _rad_gc.collect()\n    _rad_torch.cuda.empty_cache()\n    _rad_log(\n        f'twin public-v15 families complete ({public_heads_path}; {reference_heads_path})'\n    )\n\n    # One new member from V48: three fat-sensitive planes plus a sagittal\n    # structural anchor, all at a 130 mm crop. Average ranks inside the Rad block\n    # and re-rank the result exactly as V48 does before the unchanged E10 vote.\n    globals().update(\n        SLOTS=list(_RAD_E13_SLOTS),\n        N_SLOT=len(_RAD_E13_SLOTS),\n        CACHE_SLICES=int(_RAD_E13_CACHE_SLICES),\n        IMG=int(_RAD_E13_IMG),\n        CACHE_IMG=int(_RAD_E13_IMG),\n        CROP_MM=float(_RAD_E13_CROP_MM),\n        RULES=dict(RULES_LEGACY),\n    )\n    e13_heads, e13_path = _rad_load_e13_heads(device)\n    headers = annotate(walk('test_series'))\n    studies, pixels, slot_mask = build_cache(\n        pick_slots(headers, plane), plane, lat_of(headers, 'test-e13 '), 'test-e13'\n    )\n    by_uid = {str(uid): index for index, uid in enumerate(studies)}\n    missing = [uid for uid in expected_ids if uid not in by_uid]\n    if missing:\n        raise RuntimeError(f'{len(missing)} test studies absent from E13 cache')\n    order = _rad_np.asarray([by_uid[uid] for uid in expected_ids], dtype=_rad_np.int64)\n    pixels, slot_mask = pixels[order], slot_mask[order]\n    e13_token_count = int(\n        _rad_np.repeat(slot_mask[:, :, None], CACHE_SLICES, axis=2).sum()\n    )\n    if e13_token_count < int(0.85 * len(test) * N_SLOT * CACHE_SLICES):\n        raise RuntimeError(f'insufficient acquired E13 test slices: {e13_token_count}')\n    e13_features, e13_token_mask = _rad_encode(\n        encoder, pixels, slot_mask, device\n    )\n    del pixels, slot_mask, headers\n    _rad_gc.collect()\n    e13_predictions = [\n        _rad_predict_head(head, e13_features, e13_token_mask, device)\n        for head in e13_heads\n    ]\n    if len(e13_predictions) != 5:\n        raise RuntimeError('E13 inference did not use all five heads')\n    e13_probability = _rad_np.mean(_rad_np.stack(e13_predictions), axis=0)\n    if (\n        e13_probability.shape != (len(test), len(_RAD_LABELS))\n        or not _rad_np.isfinite(e13_probability).all()\n    ):\n        raise RuntimeError(f'invalid E13 prediction shape/value: {e13_probability.shape}')\n    e13_rank = _rad_rank_columns(e13_probability)\n    public_rank = _rad_rank_columns(\n        (1.0 - _RAD_E13_MEMBER_WEIGHT) * public_rank\n        + _RAD_E13_MEMBER_WEIGHT * e13_rank\n    )\n    reference_rank = _rad_rank_columns(\n        (1.0 - _RAD_E13_MEMBER_WEIGHT) * reference_rank\n        + _RAD_E13_MEMBER_WEIGHT * e13_rank\n    )\n    # V48 resolves this same bundle again after switching pixel layouts.\n    del (e13_predictions, e13_probability, e13_rank,\n         e13_features, e13_token_mask)\n    _rad_gc.collect()\n    _rad_torch.cuda.empty_cache()\n    _rad_log(\n        f'E13 FS-crop member complete at Rad-block weight '\n        f'{_RAD_E13_MEMBER_WEIGHT:.2f} ({e13_path})'\n    )\n\n    # E10 keeps its audited 0.50 parent/Rad vote. The two excluded findings\n    # remain the raw parent values, matching the audited deployment.\n    baseline_rank = _rad_rank_columns(baseline[_RAD_LABELS].to_numpy())\n\n    def _rad_e10_branch(head_rank):\n        branch = baseline.copy()\n        for index, target in enumerate(_RAD_LABELS):\n            if target not in _RAD_EXCLUDE:\n                branch[target] = (\n                    (1.0 - _RAD_ALPHA) * baseline_rank[:, index]\n                    + _RAD_ALPHA * head_rank[:, index]\n                )\n        return branch\n\n    candidate_alt = _rad_e10_branch(public_rank)\n    candidate_reference = _rad_e10_branch(reference_rank)\n    for branch in (candidate_alt, candidate_reference):\n        for target in _RAD_EXCLUDE:\n            if not _rad_np.array_equal(\n                branch[target].to_numpy(), baseline[target].to_numpy()\n            ):\n                raise RuntimeError(f'E10 failed to preserve raw parent values for {target}')\n        _rad_validate(branch, expected_ids)\n    # Diagnostic E10 output only; the final equal rank mean is formed after E11\n    # and the legacy-DINO tie-break have completed independently in each branch.\n    candidate = baseline.copy()\n    alt_e10_rank = _rad_rank_columns(candidate_alt[_RAD_LABELS].to_numpy())\n    reference_e10_rank = _rad_rank_columns(\n        candidate_reference[_RAD_LABELS].to_numpy()\n    )\n    candidate[_RAD_LABELS] = (\n        _RAD_TWIN_ALT_WEIGHT * alt_e10_rank\n        + (1.0 - _RAD_TWIN_ALT_WEIGHT) * reference_e10_rank\n    )\n    _rad_validate(candidate, expected_ids)\n    e10_path = work / 'submission_e10_v2.csv'\n    candidate.to_csv(e10_path, index=False)\n    _rad_log(\n        f'twin E10 branches complete at alpha={_RAD_ALPHA:.2f}; '\n        f'preserved raw={list(_RAD_EXCLUDE)}'\n    )\n\n    # V48's successful run selected the E13 bundle a second time after\n    # installing the older E11 slot order. Express that observed behavior\n    # directly, without relying on duplicate-filename directory order.\n    globals().update(\n        SLOTS=list(_RAD_E11_SLOTS),\n        N_SLOT=len(_RAD_E11_SLOTS),\n        CACHE_SLICES=int(_RAD_E11_CACHE_SLICES),\n        IMG=int(_RAD_E11_IMG),\n        CACHE_IMG=int(_RAD_E11_IMG),\n        CROP_MM=float(_RAD_E11_CROP_MM),\n        RULES=dict(RULES_LEGACY),\n    )\n    headers = annotate(walk('test_series'))\n    studies, pixels, slot_mask = build_cache(\n        pick_slots(headers, plane), plane,\n        lat_of(headers, 'test-v48-pass2 '), 'test-v48-pass2'\n    )\n    by_uid = {str(uid): index for index, uid in enumerate(studies)}\n    missing = [uid for uid in expected_ids if uid not in by_uid]\n    if missing:\n        raise RuntimeError(f'{len(missing)} test studies absent from V48 pass-2 cache')\n    order = _rad_np.asarray([by_uid[uid] for uid in expected_ids], dtype=_rad_np.int64)\n    pixels, slot_mask = pixels[order], slot_mask[order]\n    v48_pass2_token_count = int(\n        _rad_np.repeat(slot_mask[:, :, None], CACHE_SLICES, axis=2).sum()\n    )\n    if v48_pass2_token_count < int(0.55 * len(test) * N_SLOT * CACHE_SLICES):\n        raise RuntimeError(\n            f'insufficient acquired V48 pass-2 slices: {v48_pass2_token_count}'\n        )\n    v48_features, v48_token_mask = _rad_encode(\n        encoder, pixels, slot_mask, device\n    )\n    del pixels, slot_mask, headers\n    _rad_gc.collect()\n    v48_pass2_predictions = [\n        _rad_predict_head(head, v48_features, v48_token_mask, device)\n        for head in e13_heads\n    ]\n    if len(v48_pass2_predictions) != 5:\n        raise RuntimeError('V48 second pass did not use all five E13 heads')\n    v48_pass2_probability = _rad_np.mean(\n        _rad_np.stack(v48_pass2_predictions), axis=0\n    )\n    if (\n        v48_pass2_probability.shape != (len(test), len(_RAD_LABELS))\n        or not _rad_np.isfinite(v48_pass2_probability).all()\n    ):\n        raise RuntimeError(\n            f'invalid V48 pass-2 prediction: {v48_pass2_probability.shape}'\n        )\n    v48_pass2_rank = _rad_rank_columns(v48_pass2_probability)\n\n    reference_branch = candidate_reference.copy()\n    reference_branch[_RAD_LABELS] = _rad_rank_columns(\n        (1.0 - _RAD_V48_SECOND_ALPHA)\n        * _rad_rank_columns(candidate_reference[_RAD_LABELS].to_numpy())\n        + _RAD_V48_SECOND_ALPHA * v48_pass2_rank\n    )\n    _rad_validate(reference_branch, expected_ids)\n    _rad_log(\n        f'V48 second E13 pass complete at alpha '\n        f'{_RAD_V48_SECOND_ALPHA:.2f} on the E11 slot layout'\n    )\n\n    # V48 deploys the pinned reference branch directly after the second pass.\n    # The alternative-head twin and legacy-DINO tie-break are not part of .917.\n    _RAD_CAL = _rad_json.loads(_rad_zlib.decompress(\n        _rad_b64.b64decode(_RAD_CAL_PAYLOAD)).decode())\n    _RAD_CAL_GATE = set(_RAD_CAL['gate'])\n    _RAD_CAL_W = 0.40\n\n    def _rad_cal_protocol(uids):\n        frame = _rad_pd.read_csv(\n            ROOT / 'test_series.csv',\n            dtype={'StudyInstanceUID': str, 'SeriesInstanceUID': str},\n        )\n        frame['StudyInstanceUID'] = frame['StudyInstanceUID'].astype(str)\n        index = _rad_pd.Index([str(u) for u in uids], name='StudyInstanceUID')\n        table = _rad_pd.DataFrame(index=index)\n        table['n_series'] = frame.groupby(\n            'StudyInstanceUID').size().reindex(index).fillna(0)\n        for plane in ('Sagittal', 'Coronal', 'Axial'):\n            part = frame[frame['Anatomical_Plane'].astype(str) == plane]\n            table[f'n_{plane[:3]}'] = part.groupby(\n                'StudyInstanceUID').size().reindex(index).fillna(0)\n        for flag in ('Fat_Suppression', 'Fluid_Sensitive'):\n            marked = frame[_rad_pd.to_numeric(\n                frame[flag], errors='coerce').fillna(0) > 0]\n            table[flag[:3]] = marked.groupby(\n                'StudyInstanceUID').size().reindex(index).fillna(0)\n            for plane in ('Sagittal', 'Coronal', 'Axial'):\n                part = marked[marked['Anatomical_Plane'].astype(str) == plane]\n                table[f'{flag[:3]}_{plane[:3]}'] = part.groupby(\n                    'StudyInstanceUID').size().reindex(index).fillna(0)\n        if list(table.columns) != list(_RAD_CAL['protocol_columns']):\n            raise RuntimeError('calibration protocol layout mismatch')\n        return table.to_numpy(_rad_np.float64)\n\n    def _rad_calibrate(branch):\n        base = baseline_rank\n        public = reference_rank\n        pass2 = v48_pass2_rank\n        mean = (base + public + pass2) / 3.0\n        blocks = [base, public, pass2, public - base, pass2 - base, mean]\n        for _grp in _RAD_CAL['groups']:\n            cols = [_RAD_LABELS.index(t) for t in _grp]\n            blocks.append(mean[:, cols].mean(axis=1, keepdims=True))\n        blocks.append(_rad_cal_protocol(expected_ids))\n        x = _rad_np.concatenate(blocks, axis=1)\n        centre = _rad_np.asarray(_RAD_CAL['mean'], _rad_np.float64)\n        spread = _rad_np.asarray(_RAD_CAL['scale'], _rad_np.float64)\n        coef = _rad_np.asarray(_RAD_CAL['coef'], _rad_np.float64)\n        bias = _rad_np.asarray(_RAD_CAL['intercept'], _rad_np.float64)\n        if x.shape[1] != coef.shape[1]:\n            raise RuntimeError(\n                f'calibration expects {coef.shape[1]} columns, built {x.shape[1]}')\n        adjusted = _rad_rank_columns(((x - centre) / spread) @ coef.T + bias)\n        out = branch.copy()\n        values = out[_RAD_LABELS].to_numpy(_rad_np.float64).copy()\n        for index, target in enumerate(_RAD_LABELS):\n            if target in _RAD_CAL_GATE:\n                values[:, index] = (\n                    (1.0 - _RAD_CAL_W) * values[:, index]\n                    + _RAD_CAL_W * adjusted[:, index]\n                )\n        out[_RAD_LABELS] = _rad_rank_columns(values)\n        _rad_validate(out, expected_ids)\n        return out\n\n    final = _rad_calibrate(reference_branch)\n    globals()['V18_CALIBRATOR_APPLIED'] = True\n    globals()['V18_CAL_GATE'] = tuple(sorted(_RAD_CAL_GATE))\n    _rad_validate(final, expected_ids)\n    temporary = primary.with_suffix('.csv.tmp')\n    final.to_csv(temporary, index=False)\n    _rad_os.replace(temporary, primary)\n\n    receipt = {\n        'recipe': 'V48 deployed reference branch: correct E13@0.50-inside-Rad -> E10@0.50 -> same E13 on E11 layout@0.15',\n        'e13_member_weight_inside_rad': _RAD_E13_MEMBER_WEIGHT,\n        'e10_alpha': _RAD_ALPHA,\n        'e10_preserved_targets': list(_RAD_EXCLUDE),\n        'v48_second_alpha': _RAD_V48_SECOND_ALPHA,\n        'reference_heads_sha256': _RAD_REFERENCE_HEADS_SHA256,\n        'e13_heads_sha256': _RAD_E13_HEADS_SHA256,\n        'v48_second_heads_sha256': _RAD_E13_HEADS_SHA256,\n        'v48_second_slots': [list(slot) for slot in _RAD_E11_SLOTS],\n        'encoder_sha256': _RAD_ENCODER_SHA256,\n        'test_studies': len(expected_ids),\n        'e10_tokens': token_count,\n        'v48_second_tokens': v48_pass2_token_count,\n        'e13_tokens': e13_token_count,\n        'submission_sha256': _rad_sha256(primary),\n    }\n    (work / 'v50_v2_repro_receipt.json').write_text(\n        _rad_json.dumps(receipt, indent=2, sort_keys=True) + '\\n'\n    )\n    del (encoder, e13_heads, v48_pass2_predictions,\n         v48_pass2_probability, v48_pass2_rank, v48_features, v48_token_mask)\n    _rad_gc.collect()\n    _rad_torch.cuda.empty_cache()\n    _rad_log(\n        f'V48 reference branch complete; reference-v15={reference_heads_path}; '\n        f'e13-two-pass={e13_path}; second_alpha='\n        f'{_RAD_V48_SECOND_ALPHA:.2f}; encoder={encoder_path}; '\n        f'elapsed={(_rad_time.time()-started)/60:.1f}m'\n    )\n\n\n_rad_main()\n","metadata":{"tags":["DINOsaur-V4","public-rad-dual5"],"trusted":true},"outputs":[],"execution_count":null},{"id":"08ac5c23","cell_type":"code","source":"# RAPTOR_FOUR_VIEW_PROBABILITY_ENSEMBLE_V40\n# Global weights: v5=.55, v10=.10, reverse-v5=.15, v8=.20; outer=0.60\n#!/usr/bin/env python3\n\"\"\"Knee MRI: twelve findings from a single model\n\nThis notebook takes a knee MRI study and scores twelve findings at once: ACL tear, MCL tear,\nmedial and lateral meniscus tears, osteoarthritis in the medial, lateral and patellofemoral\ncompartments, joint effusion, synovitis, a Baker's cyst, bone contusion and fracture. It scores\n0.924 on the public leaderboard using one model, with no ensembling and no test-time augmentation.\n\nThis is the inference half of the work. The model was trained separately and its weights are\nattached as a dataset, so this notebook only loads them and predicts:\nhttps://www.kaggle.com/datasets/dreaddevelopment/raptor-knee-widedense\n\nWhere the training labels came from\n\nWorth saying up front, because it shapes everything else. The competition gives you 4,407 studies\nbut structured labels for only 58 of them. Every other study arrives with a free-text radiology\nreport and nothing more, so there is very little to train against out of the box.\n\nThe labels behind these weights were made by reading those reports with a language model and\nturning each into twelve probabilities rather than twelve yes or no answers. A report that says a\ntear is suspected becomes a number near 0.8, not a 1, which is a fairer target than forcing every\nhedged sentence into a hard label. That yields 4,349 studies to train on. The 58 studies that came\nwith real labels were never trained on and are used to check the result honestly; the model reaches\n0.9167 macro-AUC on them.\n\nBuilding a fixed input from studies that are all shaped differently\n\nThe hard part of this competition is not the network, it is that no two studies look alike. A\nstudy holds several DICOM series shot in different planes, the number of series varies, and the\nnumber of slices in a series varies more. Anything that expects a fixed-size input has to be given\none.\n\nThe approach here is to fill five fixed slots per study, always in the same order, for a stack of\n64 images:\n\n  18 slices from a sagittal series, preferring a fluid-sensitive one\n  14 slices from a second sagittal series, preferring one that is not fluid-sensitive\n  12 slices from a coronal series, preferring a fluid-sensitive one\n   8 slices from a second coronal series\n  12 slices from an axial series\n\nPreferring a fluid-sensitive series for some slots and not for others is deliberate. Fluid-\nsensitive sequences show swelling, effusion and acute injury clearly, while the other sequences\nshow anatomy and cartilage better, and the twelve findings are split across both. If a study has\nno series for a slot, the slot is left as zeros and the model is told to skip it rather than being\nfed something misleading.\n\nWithin a series, slices are taken evenly across 6 to 94 percent of the stack rather than from the\nmiddle. The outer slices are where the collateral ligaments and the lateral meniscus sit, and\ncutting them was measurably costing accuracy on exactly those findings.\n\nEvery slice is cropped to a 140 mm box around the centre of the image using the pixel spacing from\nthe DICOM header, then resized to 336 pixels. Cropping by millimetres rather than by pixel count\nmatters: it means a knee occupies the same fraction of the frame whether the scan was acquired at\n0.3 or 0.5 mm per pixel, so the model is not asked to learn scale differences that carry no medical\ninformation.\n\nHow the model reads the stack\n\nThree neighbouring slices are stacked into the three channels of one image. The network then sees\na little of what lies above and below the slice in the middle, which is most of the benefit of a 3D\nmodel at the cost of a 2D one. Each of these three-slice windows is passed through a CoAtNet\nbackbone at 384 pixels.\n\nThe windows are combined with an attention layer that has separate weights for each of the twelve\nfindings. This is the part that matters most. A cruciate tear may be visible on two sagittal slices\nwhile osteoarthritis is spread across many coronal ones, and a single pooled score forces those two\nto share one notion of which slices are important. Giving each finding its own attention weights\nlets each one draw on the slices that actually show it.\n\nRunning it\n\nScoring uses 42 windows per study. Inference runs in half precision and automatically retries a\nstudy in full precision if it fails, so no study is ever dropped from the submission. The notebook\nneeds no internet: the backbone is loaded from the attached weights rather than downloaded.\n\"\"\"\nimport os, sys, glob, time, json, gc\nos.environ.setdefault(\"HF_HUB_OFFLINE\", \"1\")\nos.environ.setdefault(\"TRANSFORMERS_OFFLINE\", \"1\")\nos.environ.setdefault(\"HF_HUB_DISABLE_TELEMETRY\", \"1\")\nimport numpy as np\nimport torch, torch.nn as nn, torch.nn.functional as F\nimport timm\n# T4 (Turing) cuDNN v9 has fp16/fp32 conv engines but NOT bf16 for these shapes\n# (\"GET was unable to find an engine...\"); benchmark lets it pick a valid algo for\n# the fixed (1,24,3,res,res) input.\ntorch.backends.cudnn.benchmark = True\ntorch.backends.cuda.matmul.allow_tf32 = True\n\n# ---- fixed config (must match training exactly) -----------------------------\n# Defaults are overwritten from each arm's immutable pixel contract before inference.\nIMG = 336\nCROP_MM = 140.0\nSPAN_LO, SPAN_HI = 0.02, 0.98\nSLOTS = [(\"Sagittal\", 1, 18), (\"Sagittal\", 0, 14), (\"Coronal\", 1, 12),\n         (\"Coronal\", 0, 8), (\"Axial\", -1, 12)]\nMAXS = sum(s[2] for s in SLOTS)\nK_EVAL = 62\nNORM = \"imagenet\"\nLAB = [\"ACL\", \"MCL\", \"Medial Meniscus\", \"Lateral Meniscus\", \"Medial OA\", \"Lateral OA\",\n       \"PF OA\", \"Effusion\", \"Synovitis\", \"Baker's\", \"Contusion\", \"Fracture\"]\n_MEAN = torch.tensor([0.485, 0.456, 0.406]).view(3, 1, 1)\n_STD = torch.tensor([0.229, 0.224, 0.225]).view(3, 1, 1)\n\n# Three arms: (weights filename, fallback arch, fallback res). ck carries arch+res too.\n# Selected 2026-08-19 by greedy forward selection AND exhaustive subset search over a 7-arm\n# panel on the 45-study gold set (phase2/blend_panel.py); both agree on this exact set.\n# Singles: coatnet384 0.9025 | swinbase384 0.8825 | effv2l480 0.8716.\n# Blend {coatnet+swin+effv2l} = 0.9068 (2-arm {coatnet+swin} = 0.9059, coatnet alone 0.9025).\n# Dropped as redundant: cnn336 (0.8833, the former champion), cnbase384 (0.8754),\n# cnlarge384 (0.8752), maxvit384 (0.8438).\n#\n# SINGLE ARM: coatnet_rmlp_2_rw_384 retrained on the EXPANDED 4,349-study corpus.\n#\n# Why one arm and not the 3-arm blend: on the live leaderboard CoAtNet alone scored 0.914 while\n# every blend scored 0.914-0.915, so ensembling is worth ~+0.001 there -- the ~+0.010 it showed\n# on the old 45-study gold set was gold-set noise. One arm is also 1/3 the kernel runtime.\n#\n# Corpus expansion: the corpus previously held 3,200 of the 4,349 labelled studies and only 45\n# of the 58 gold studies. Rebuilt to 4,407 studies (+37.8% training data, 58-study gate).\n#\n# Measured on the 58-study gate (the incumbent re-scored on the SAME gate for a fair compare):\n#   incumbent CoAtNet (3,155-study corpus) 0.8923\n#   this model       (4,349-study corpus) 0.9054   (+0.0131, better in 92.7% of 2000 bootstraps)\n# Biggest gains land on the findings that were capping us: Lateral Meniscus +0.071,\n# Fracture +0.057, Lateral OA +0.048, Medial Meniscus +0.035, ACL +0.028.\n# Four globally weighted views.  Weights and the 0.70 outer blend were frozen\n# after the same configuration improved both Gold58 anchor constructions.  There is\n# no per-target routing: every finding receives the same estimator.\n_SLOTS64 = [(\"Sagittal\", 1, 18), (\"Sagittal\", 0, 14), (\"Coronal\", 1, 12),\n            (\"Coronal\", 0, 8), (\"Axial\", -1, 12)]\n_SLOTS44 = [(\"Sagittal\", 1, 12), (\"Sagittal\", 0, 10), (\"Coronal\", 1, 8),\n            (\"Coronal\", 0, 6), (\"Axial\", -1, 8)]\nARMS = [\n    {\"name\": \"maxspan-v5\", \"file\": \"raptor_ft_coatnet_v5_full_swa.pt\",\n     \"arch\": \"coatnet_rmlp_2_rw_384.sw_in12k_ft_in1k\", \"res\": 384,\n     \"img\": 336, \"slots\": _SLOTS64, \"span\": (0.02, 0.98), \"k_eval\": 62,\n     \"reverse\": False, \"w\": 0.55},\n    {\"name\": \"native384dense-v10\", \"file\": \"raptor_ft_coatnet_v10_full.pt\",\n     \"arch\": \"coatnet_rmlp_2_rw_384.sw_in12k_ft_in1k\", \"res\": 384,\n     \"img\": 384, \"slots\": _SLOTS64, \"span\": (0.02, 0.98), \"k_eval\": 62,\n     \"reverse\": False, \"w\": 0.10},\n    {\"name\": \"maxspan-v5-reverse\", \"file\": \"raptor_ft_coatnet_v5_full_swa.pt\",\n     \"arch\": \"coatnet_rmlp_2_rw_384.sw_in12k_ft_in1k\", \"res\": 384,\n     \"img\": 336, \"slots\": _SLOTS64, \"span\": (0.02, 0.98), \"k_eval\": 62,\n     \"reverse\": True, \"w\": 0.15},\n    {\"name\": \"native384-v8\", \"file\": \"raptor_ft_coatnet_v8_full_swa.pt\",\n     \"arch\": \"coatnet_rmlp_2_rw_384.sw_in12k_ft_in1k\", \"res\": 384,\n     \"img\": 384, \"slots\": _SLOTS44, \"span\": (0.06, 0.94), \"k_eval\": 42,\n     \"reverse\": False, \"w\": 0.20},\n]\n\n\n# ============================================================================\n# Model -- verbatim from finetune_raptor.py\n# ============================================================================\ndef build_backbone(arch, pretrained=False):\n    # maxvit/maxxvit/coatnet are conv-attention hybrids: NO CLS token, NO interpolatable\n    # pos-embed -> avg pool. The \"vit\" substring in \"coatnet\"/\"maxvit\" must NOT route them\n    # down the ViT path (mirrors finetune_raptor.py exactly).\n    hybrid = arch.startswith((\"maxvit\", \"maxxvit\", \"coatnet\", \"coat_\", \"convnext\"))\n    is_vit = (not hybrid) and any(k in arch for k in (\"vit\", \"deit\", \"dinov2\", \"eva\", \"beit\"))\n    kw = dict(pretrained=pretrained, num_classes=0, in_chans=3)\n    if is_vit:\n        kw.update(global_pool=\"token\", dynamic_img_size=True)\n    else:\n        kw.update(global_pool=\"avg\")\n    return timm.create_model(arch, **kw)\n\n\nclass RaptorClassifier(nn.Module):\n    def __init__(self, backbone, F_dim=768, n=12, drop=0.2):\n        super().__init__()\n        self.backbone = backbone\n        self.norm = nn.LayerNorm(F_dim)\n        self.att = nn.Sequential(nn.Linear(F_dim, 256), nn.Tanh(), nn.Dropout(drop),\n                                 nn.Linear(256, n))\n        self.clsW = nn.Parameter(torch.zeros(n, F_dim))\n        self.clsb = nn.Parameter(torch.zeros(n))\n        nn.init.trunc_normal_(self.clsW, std=0.02)\n        self.n = n\n\n    def encode(self, x):\n        B, K = x.shape[:2]\n        f = self.backbone(x.flatten(0, 1))\n        return f.view(B, K, -1)\n\n    def head(self, feats):\n        h = self.norm(feats)\n        a = self.att(h)\n        a = torch.softmax(a, dim=1)\n        pooled = torch.einsum(\"bkn,bkf->bnf\", a, h)\n        logits = (pooled * self.clsW).sum(-1) + self.clsb\n        return logits\n\n    def forward(self, x):\n        return self.head(self.encode(x))\n\n\ndef load_model(pt_path, arch_default, res_default, device, ngpu=1):\n    ck = torch.load(pt_path, map_location=\"cpu\", weights_only=False)\n    arch = ck.get(\"arch\", arch_default)\n    ck_res = int(ck.get(\"res\", res_default))\n    bb = build_backbone(arch, pretrained=False)\n    model = RaptorClassifier(bb, F_dim=bb.num_features)\n    model.load_state_dict(ck[\"model\"], strict=True)\n    model.eval().to(device)\n    # NOTE: DataParallel removed on purpose. On the full hidden test it drove a system-RAM OOM\n    # (per-forward module replication over many studies); a single T4 handles K_EVAL=24 windows\n    # fine. Arms are also run SEQUENTIALLY (see main) so peak RAM == one model, not two.\n    del ck\n    gc.collect()\n    return model, ck_res\n\n\n# ============================================================================\n# Eval windowing -- verbatim from finetune_raptor.py StudyWindows (train=False)\n# ============================================================================\ndef _eval_centers(mask, D, k):\n    valid = np.where(mask > 0)[0]\n    if len(valid) < 3:\n        valid = np.arange(min(3, D))\n    lo, hi = int(valid.min()), int(valid.max())\n    cs = [c for c in range(lo + 1, hi) if c - 1 >= lo and c + 1 <= hi]\n    if not cs:\n        cs = [max(1, min((lo + hi) // 2, D - 2))]\n    idx = np.linspace(0, len(cs) - 1, k).round().astype(int)\n    return [cs[i] for i in idx]\n\n\ndef eval_windows(vol, mask, k, res, norm=NORM):\n    D = vol.shape[0]\n    cs = _eval_centers(mask, D, k)\n    wins = np.empty((len(cs), 3, res, res), np.float32)\n    for j, c in enumerate(cs):\n        c = max(1, min(c, D - 2))\n        tri = np.stack([vol[c - 1], vol[c], vol[c + 1]], 0).astype(np.float32) / 255.0\n        t = torch.from_numpy(tri)\n        if t.shape[-1] != res:\n            t = F.interpolate(t[None], size=(res, res), mode=\"bilinear\",\n                              align_corners=False)[0]\n        wins[j] = t.numpy()\n    x = torch.from_numpy(wins)\n    if norm == \"imagenet\":\n        x = (x - _MEAN) / _STD\n    return x\n\n\n@torch.no_grad()\ndef infer_probs(model, xwins, device):\n    x = xwins.unsqueeze(0).to(device)\n    use_cuda = device != \"cpu\" and str(device).startswith(\"cuda\")\n    if use_cuda:\n        # fp16 conv on T4 is fully cuDNN-supported (bf16 is NOT -> \"no engine\").\n        try:\n            with torch.autocast(\"cuda\", dtype=torch.float16):\n                o = torch.sigmoid(model(x).float())\n            return o[0].cpu().numpy()\n        except RuntimeError:\n            # fp32 always has a Turing conv engine; slower but never drops a study.\n            torch.cuda.empty_cache()\n            o = torch.sigmoid(model(x).float())\n            return o[0].cpu().numpy()\n    o = torch.sigmoid(model(x).float())\n    return o[0].cpu().numpy()\n\n\ndef rankpct(x):                                   # per-column percentile rank in [0,1]\n    order = x.argsort(0).argsort(0).astype(np.float64)\n    return order / max(1, (x.shape[0] - 1))\n\n\n# ============================================================================\n# Preprocessing -- verbatim from kprep2/dino_preprocess.py, retargeted to TEST\n# ============================================================================\ndef _make_reader():\n    import pydicom, cv2\n    from pydicom.pixel_data_handlers.util import apply_modality_lut\n\n    def order_and_meta(sdir):\n        fs = glob.glob(sdir + \"/*.dcm\"); recs = []; ps_list = []\n        for f in fs:\n            try:\n                h = pydicom.dcmread(f, stop_before_pixels=True)\n                iop = getattr(h, 'ImageOrientationPatient', None)\n                ipp = getattr(h, 'ImagePositionPatient', None)\n                if iop is not None and ipp is not None and len(iop) == 6:\n                    r = np.array(iop[:3], float); c = np.array(iop[3:], float)\n                    n = np.cross(r, c); pos = float(np.dot(np.array(ipp, float), n))\n                else:\n                    pos = float(getattr(h, 'InstanceNumber', 0) or 0)\n                ps = getattr(h, 'PixelSpacing', None); ps = float(ps[0]) if ps is not None else 0.5\n                ps_list.append(ps); recs.append((pos, f, ps))\n            except Exception:\n                recs.append((0.0, f, 0.5))\n        recs.sort(key=lambda x: x[0])\n        med_ps = float(np.median(ps_list)) if ps_list else 0.5\n        return [(f, ps) for _, f, ps in recs], med_ps\n\n    def read_px(f):\n        d = pydicom.dcmread(f)\n        a = apply_modality_lut(d.pixel_array, d).astype(np.float32)\n        if str(getattr(d, 'PhotometricInterpretation', '')) == 'MONOCHROME1':\n            a = a.max() - a\n        return a\n\n    def mm_crop_resize(a, ps):\n        h, w = a.shape; cpx = int(round(CROP_MM / max(ps, 1e-3)))\n        cpx = min(cpx, min(h, w)); y0 = (h - cpx) // 2; x0 = (w - cpx) // 2\n        a = a[y0:y0 + cpx, x0:x0 + cpx]\n        return cv2.resize(a, (IMG, IMG), interpolation=cv2.INTER_AREA)\n\n    return order_and_meta, read_px, mm_crop_resize\n\n\ndef _pick_series_for_slot(rows, plane, fluid, used):\n    cands = [r for r in rows if r['Anatomical_Plane'] == plane and r['SeriesInstanceUID'] not in used]\n    if fluid in (0, 1):\n        pref = [r for r in cands if int(r.get('Fluid_Sensitive', 0) or 0) == fluid]\n        if pref:\n            return pref[0]\n    return cands[0] if cands else None\n\n\ndef build_study(sid, ser_records, tsdir, reader):\n    order_and_meta, read_px, mm_crop_resize = reader\n    rows = ser_records.get(sid, [])\n    vol = np.zeros((MAXS, IMG, IMG), np.uint8); idx = 0; used = set()\n    for plane, fluid, k in SLOTS:\n        r = _pick_series_for_slot(rows, plane, fluid, used)\n        if r is None:\n            idx += k; continue\n        used.add(r['SeriesInstanceUID'])\n        files, med_ps = order_and_meta(f\"{tsdir}/{sid}/{r['SeriesInstanceUID']}\")\n        if not files:\n            idx += k; continue\n        # wide span: the collateral ligaments and lateral meniscus live in the\n        # peripheral slices the old 0.15-0.85 crop threw away. Must match the corpus\n        # the weights were trained on (knee_corpus_v2.py, SPAN_LO/SPAN_HI).\n        n = len(files); lo, hi = int(n * SPAN_LO), int(n * SPAN_HI) - 1; hi = max(hi, lo)\n        picks = np.linspace(lo, hi, k).round().astype(int) if n > 1 else [0] * k\n        arrs = []; pss = []\n        for p in picks:\n            fp, ps = files[min(p, n - 1)]\n            try:\n                arrs.append(read_px(fp)); pss.append(ps)\n            except Exception:\n                arrs.append(None); pss.append(med_ps)\n        valid = [a for a in arrs if a is not None]\n        if valid:\n            allpx = np.concatenate([a.ravel() for a in valid])\n            loq, hiq = np.percentile(allpx, [2.0, 98.0])\n        else:\n            loq, hiq = 0.0, 1.0\n        for a, ps in zip(arrs, pss):\n            if idx >= MAXS: break\n            if a is None: idx += 1; continue\n            aw = np.clip((a - loq) / (hiq - loq + 1e-6), 0, 1)\n            aw = mm_crop_resize(aw, ps if ps > 0 else med_ps)\n            vol[idx] = (aw * 255).astype(np.uint8); idx += 1\n        if idx >= MAXS: break\n    mask = (vol.reshape(MAXS, -1).sum(1) > 0).astype(np.uint8)\n    return vol, mask\n\n\n# ============================================================================\n# Test-root discovery + weights + main\n# ============================================================================\ndef find_test_root():\n    cands = [\"/kaggle/input/competitions/rsna-knee-abnormality-detection\",\n             \"/kaggle/input/rsna-knee-abnormality-detection\"]\n    for b in cands:\n        if os.path.exists(b + \"/test.csv\"):\n            return b\n    for d, _, f in os.walk(\"/kaggle/input\"):\n        if \"test.csv\" in f and (os.path.isdir(d + \"/test_series\") or os.path.isdir(d + \"/test_images\")):\n            return d\n    for d, _, f in os.walk(\"/kaggle/input\"):\n        if \"test.csv\" in f:\n            return d\n    raise RuntimeError(\"no test root under /kaggle/input\")\n\n\ndef find_weight_file(fname):\n    # direct dataset mounts first; NEVER recursive-glob the competitions DICOM tree.\n    direct = [f\"/kaggle/input/raptor-knee-maxspan/{fname}\",\n              f\"/kaggle/input/raptor-knee-native384dense/{fname}\",\n              f\"/kaggle/input/raptor-knee-native384/{fname}\",\n              f\"/kaggle/input/raptor-knee-arms/{fname}\",\n              f\"/kaggle/input/raptor-knee-arms/1/{fname}\",\n              f\"/kaggle/input/raptor-cnn336/{fname}\"]\n    for p in direct:\n        if os.path.exists(p):\n            return p\n    for d in sorted(glob.glob(\"/kaggle/input/*/\")):\n        if \"competition\" in d.lower():\n            continue\n        hits = glob.glob(os.path.join(d, \"**\", fname), recursive=True)\n        if hits:\n            return hits[0]\n    raise RuntimeError(f\"{fname} not found under /kaggle/input\")\n\n\ndef main():\n    import pandas as pd\n    t0 = time.time()\n    dev = \"cuda\" if torch.cuda.is_available() else \"cpu\"\n    ngpu = torch.cuda.device_count()\n    print(f\"device {dev} | gpus {ngpu} | torch {torch.__version__}\", flush=True)\n\n    ROOT = find_test_root()\n    tsdir = ROOT + \"/test_series\"\n    if not os.path.isdir(tsdir):\n        tsdir = ROOT + \"/test_images\"\n    print(\"test root:\", ROOT, \"| series dir:\", tsdir, flush=True)\n\n    test = pd.read_csv(ROOT + \"/test.csv\"); test[\"StudyInstanceUID\"] = test[\"StudyInstanceUID\"].astype(str)\n    test_ids = test[\"StudyInstanceUID\"].tolist()\n    tser = pd.read_csv(ROOT + \"/test_series.csv\")\n    tser[\"StudyInstanceUID\"] = tser[\"StudyInstanceUID\"].astype(str)\n    tser[\"SeriesInstanceUID\"] = tser[\"SeriesInstanceUID\"].astype(str)\n    SER = {k: v.to_dict(\"records\") for k, v in tser.groupby(\"StudyInstanceUID\")}\n    print(f\"test studies {len(test_ids)} | test series {len(tser)}\", flush=True)\n\n    sub_cols = [\"StudyInstanceUID\"] + LAB\n    ssub = os.path.join(ROOT, \"sample_submission.csv\")\n    if os.path.exists(ssub):\n        sub_cols = list(pd.read_csv(ssub, nrows=1).columns)\n\n    reader = _make_reader()\n    N = len(test_ids); A = len(ARMS)\n    arm_probs = [np.full((N, len(LAB)), 0.5, np.float32) for _ in range(A)]\n\n    # SEQUENTIAL ARMS (the OOM fix): only ONE model is resident at a time, so peak system RAM ==\n    # one model == the single-arm champion's footprint (which graded fine at 0.879). Holding both\n    # arms simultaneously OOM'd system RAM on the full hidden test. Each study is re-preprocessed\n    # per arm (build_study is cheap vs inference) and every per-study buffer is freed. Same models,\n    # same windowing, same rank-mean blend -> identical 0.8893 result, just serialized.\n    for a, arm in enumerate(ARMS):\n        # Restore the exact preprocessing contract used to train this checkpoint.\n        globals()[\"IMG\"] = int(arm[\"img\"])\n        globals()[\"SLOTS\"] = list(arm[\"slots\"])\n        globals()[\"MAXS\"] = sum(slot[2] for slot in SLOTS)\n        globals()[\"SPAN_LO\"], globals()[\"SPAN_HI\"] = map(float, arm[\"span\"])\n        globals()[\"K_EVAL\"] = int(arm[\"k_eval\"])\n        wp = find_weight_file(arm[\"file\"])\n        model, res = load_model(wp, arm[\"arch\"], arm[\"res\"], dev)\n        print(f\"[arm {a}] {arm['name']} | img {IMG} | slices {MAXS} | span {SPAN_LO:.2f}-{SPAN_HI:.2f} | windows {K_EVAL} | res {res} | {time.time()-t0:.0f}s\", flush=True)\n        for i, sid in enumerate(test_ids):\n            try:\n                vol, mask = build_study(sid, SER, tsdir, reader)\n                xw = eval_windows(vol, mask, k=K_EVAL, res=res, norm=NORM)\n                if bool(arm.get(\"reverse\", False)):\n                    xw = xw.flip(1).contiguous()\n                arm_probs[a][i] = infer_probs(model, xw, dev)\n                del vol, mask, xw\n            except Exception as e:\n                print(f\"  [arm {a}] study {i} {sid[:16]} FALLBACK ({type(e).__name__}: {e})\", flush=True)\n            if (i + 1) % 100 == 0 or i + 1 == N:\n                print(f\"  [arm {a}] {i+1}/{N} | {time.time()-t0:.0f}s\", flush=True)\n        del model\n        gc.collect()\n        if str(dev).startswith(\"cuda\"):\n            torch.cuda.empty_cache()\n        print(f\"[arm {a}] done + freed | {time.time()-t0:.0f}s\", flush=True)\n\n\n    # DINOSAUR_V4_EXPORT_PUBLIC_RAPTOR_ARM_RANKS\n    # Export only; the original public Raptor prediction is unchanged.\n    _d4_arm_paths = {}\n    for _d4_ai, _d4_arm in enumerate(ARMS):\n        _d4_slug = \"\".join(\n            ch.lower() if ch.isalnum() else \"_\"\n            for ch in str(_d4_arm[\"name\"])\n        ).strip(\"_\")\n        _d4_rank = (\n            pd.DataFrame(np.clip(arm_probs[_d4_ai], 0.0, 1.0), columns=LAB)\n            .rank(method=\"average\", pct=True)\n            .to_numpy(np.float64)\n        )\n        _d4_frame = pd.DataFrame(_d4_rank, columns=LAB)\n        _d4_frame.insert(0, \"StudyInstanceUID\", test_ids)\n        _d4_path = f\"/kaggle/working/dinosaur_v4_raptor_arm_{_d4_slug}.csv\"\n        _d4_frame.to_csv(_d4_path, index=False)\n        _d4_arm_paths[str(_d4_arm[\"name\"])] = _d4_path\n    print(\n        \"[DINOsaur V4] exported public Raptor arm ranks: \"\n        + \", \".join(sorted(_d4_arm_paths)),\n        flush=True,\n    )\n\n    # WEIGHTED rank-mean blend across the test set, per finding (the offline recipe).\n    # Weights come from ARMS[*][\"w\"] and are normalised here, so dropping/adding an arm can\n    # never silently change the scale. Falls back to equal weights if none are declared.\n    _w = np.array([float(a.get(\"w\", 1.0)) for a in ARMS], dtype=np.float64)\n    _w = _w / _w.sum()\n    print(f\"[blend] global probability mean w={dict(zip([a['name'] for a in ARMS], _w.round(4)))}\", flush=True)\n    probability_blend = np.tensordot(\n        _w, np.stack([np.clip(p, 0, 1) for p in arm_probs]), axes=(0, 0)\n    )\n    ranks = rankpct(probability_blend)                                         # (N,12) in [0,1]\n    if not np.isfinite(ranks).all():\n        ranks[~np.isfinite(ranks)] = 0.5\n\n    sub = pd.DataFrame(ranks.astype(np.float32), columns=LAB)\n    sub.insert(0, \"StudyInstanceUID\", test_ids)\n    sub = sub[sub_cols]\n    assert list(sub.columns) == sub_cols, \"column order drift\"\n    assert sub[\"StudyInstanceUID\"].tolist() == test_ids, \"row identity drift\"\n    assert np.isfinite(sub[LAB].values).all()\n    out = \"/kaggle/working/submission_coatnet.csv\"\n    sub.to_csv(out, index=False)\n    print(\"wrote\", out, \"|\", len(sub), \"rows x\", len(sub.columns), \"cols\", flush=True)\n    print(sub.head().to_string(index=False), flush=True)\n    print(f\"DONE {time.time()-t0:.0f}s\", flush=True)\n\n\nif __name__ == \"__main__\":\n    try:\n        main()\n    except Exception as _coat_exc:\n        import traceback as _coat_traceback\n        print(f\"CoAtNet branch failed; retaining transformer submission: {type(_coat_exc).__name__}: {_coat_exc}\", flush=True)\n        _coat_traceback.print_exc()\n\n\n\n# Blend two independently validated rank predictors. The default remains the transformer\n# submission if the CoAtNet branch did not complete, so a recoverable branch failure\n# cannot erase a valid competition artifact.\nfrom pathlib import Path as _BlendPath\nimport numpy as _blend_np\nimport pandas as _blend_pd\n\n_blend_work = _BlendPath('/kaggle/working')\n_blend_transformer_path = _blend_work / 'submission.csv'\n_blend_coatnet_path = _blend_work / 'submission_coatnet.csv'\nif _blend_coatnet_path.is_file():\n    _blend_transformer = _blend_pd.read_csv(_blend_transformer_path, dtype={'StudyInstanceUID': str})\n    _blend_coatnet = _blend_pd.read_csv(_blend_coatnet_path, dtype={'StudyInstanceUID': str})\n    _blend_labels = [c for c in _blend_transformer.columns if c != 'StudyInstanceUID']\n    if _blend_coatnet.columns.tolist() != _blend_transformer.columns.tolist():\n        raise RuntimeError('CoAtNet/transformer submission schema mismatch')\n    if _blend_coatnet['StudyInstanceUID'].tolist() != _blend_transformer['StudyInstanceUID'].tolist():\n        raise RuntimeError('CoAtNet/transformer study order mismatch')\n    _blend_tr = _blend_transformer[\n        _blend_labels\n    ].rank(\n        method='average',\n        pct=True,\n    )\n\n    _blend_cr = _blend_coatnet[\n        _blend_labels\n    ].rank(\n        method='average',\n        pct=True,\n    )\n\n    _blend_output = (\n        _blend_transformer.copy()\n    )\n\n    # One global outer weight, fixed before the public submission.\n    _coatnet_weight = {label: 0.60 for label in _blend_labels}\n\n    for _label in _blend_labels:\n        _cw = float(\n            _coatnet_weight[\n                _label\n            ]\n        )\n\n        _blend_output[\n            _label\n        ] = (\n            (\n                1.0\n                - _cw\n            )\n            * _blend_tr[\n                _label\n            ]\n            + _cw\n            * _blend_cr[\n                _label\n            ]\n        )\n\n    _blend_output[\n        _blend_labels\n    ] = _blend_output[\n        _blend_labels\n    ].rank(\n        method='average',\n        pct=True,\n    )\n\n    print(\n        '[V18] CoAtNet target weights: '\n        + ', '.join(\n            f'{label}='\n            f'{_coatnet_weight[label]:.2f}'\n            for label in _blend_labels\n            if (\n                _coatnet_weight[label]\n                != 0.50\n            )\n        ),\n        flush=True,\n    )\n\n    _blend_values = _blend_output[\n        _blend_labels\n    ].to_numpy(\n        _blend_np.float64\n    )\n    if not _blend_np.isfinite(_blend_values).all() or _blend_values.min() < 0 or _blend_values.max() > 1:\n        raise RuntimeError('invalid blended prediction values')\n    _blend_output.to_csv(_blend_transformer_path, index=False)\n    print(f'final submission.csv = V18 calibrated transformer + CoAtNet rank blend; {_blend_output.shape}', flush=True)\nelse:\n    print('CoAtNet output unavailable; submission.csv remains the validated transformer ensemble', flush=True)\n\n# V18 output hygiene.\nfor _v18_temp in (\n    _blend_work / 'submission_coatnet.csv',\n    _blend_work / 'submission_transformer_0920.csv',\n):\n    try:\n        if _v18_temp.is_file():\n            _v18_temp.unlink()\n    except OSError:\n        pass\n","metadata":{"jupyter":{"source_hidden":true},"papermill":{"duration":59.696838,"end_time":"2026-09-04T03:00:10.4629+00:00","exception":false,"start_time":"2026-09-04T02:59:10.766062+00:00","status":"completed"},"tags":["DINOsaur-V4","public-four-view-raptor"],"trusted":true},"outputs":[],"execution_count":null},{"id":"77410bd1-cbba-471b-bf18-451e8a7bce22","cell_type":"code","source":"# DINOSAUR_V4_PUBLICDUAL_REAPPLY_RENTA_MEDIAL_RESIDUAL\nfrom pathlib import Path as _D4MMPath\nimport hashlib as _d4mm_hashlib\nimport json as _d4mm_json\nimport os as _d4mm_os\nimport numpy as _d4mm_np\nimport pandas as _d4mm_pd\n\n_d4mm_work = _D4MMPath('/kaggle/working')\n_d4mm_primary = _d4mm_work / 'submission.csv'\n_d4mm_bag_path = _d4mm_work / 'public0033_bag_raw.csv'\n_d4mm_out = _d4mm_work / 'submission_dinosaur_v4_publicdual_candidate.csv'\n_d4mm_receipt = _d4mm_work / 'dinosaur_v4_publicdual_receipt.json'\n\nif not _d4mm_primary.is_file():\n    raise FileNotFoundError(_d4mm_primary)\nif not _d4mm_bag_path.is_file():\n    raise FileNotFoundError(\n        'public0033_bag_raw.csv is required: the Renta weak-label specialist '\n        'must complete before the PublicDual branch'\n    )\nfor _name in ('_blend_transformer', '_blend_tr', '_blend_cr'):\n    if _name not in globals():\n        raise RuntimeError(f'DINOsaur V4 PublicDual missing public parent component: {_name}')\n\n_base = _d4mm_pd.read_csv(_d4mm_primary, dtype={'StudyInstanceUID': str})\n_uids = _base['StudyInstanceUID'].astype(str).tolist()\n_labels = [c for c in _base.columns if c != 'StudyInstanceUID']\n_expected_labels = [\n    'ACL','MCL','Medial Meniscus','Lateral Meniscus',\n    'Medial OA','Lateral OA','PF OA','Effusion','Synovitis',\n    \"Baker's\",'Contusion','Fracture'\n]\nif _labels != _expected_labels:\n    raise RuntimeError(f'DINOsaur V4 PublicDual schema drift: {_labels}')\nif len(_uids) != len(set(_uids)):\n    raise RuntimeError('DINOsaur V4 PublicDual duplicate StudyInstanceUID')\n\n_bag = _d4mm_pd.read_csv(_d4mm_bag_path, dtype={'StudyInstanceUID': str})\n_required_bag_cols = {'StudyInstanceUID', 'Medial Meniscus'}\n_missing_bag_cols = sorted(_required_bag_cols.difference(_bag.columns))\nif _missing_bag_cols:\n    raise RuntimeError(\n        f'public0033 bag is missing required columns: {_missing_bag_cols}; '\n        f'available={_bag.columns.tolist()}'\n    )\n# public0033 may also contain Lateral Meniscus or future specialist columns.\n# This V4 route intentionally consumes only Medial Meniscus.\n_bag = _bag[['StudyInstanceUID', 'Medial Meniscus']].set_index('StudyInstanceUID').reindex(_uids)\nif _bag['Medial Meniscus'].isna().any():\n    raise RuntimeError('public0033 bag does not cover every PublicDual study')\n\n# Exact published residual recipe from the Renta 0.937 path.\n_bag_rank = _bag['Medial Meniscus'].rank(method='average', pct=True).to_numpy(_d4mm_np.float64)\n_tr_rank = _blend_tr['Medial Meniscus'].to_numpy(_d4mm_np.float64)\n_rr_rank = _blend_cr['Medial Meniscus'].to_numpy(_d4mm_np.float64)\n\n_mm = (\n    0.30 * _tr_rank\n    + 0.60 * _rr_rank\n    + 0.10 * _bag_rank\n)\n_mm = _d4mm_pd.Series(_mm).rank(method='average', pct=True).to_numpy(_d4mm_np.float64)\n\n_candidate = _base.copy()\n_candidate['Medial Meniscus'] = _mm\n\n_vals = _candidate[_labels].to_numpy(_d4mm_np.float64)\nif not _d4mm_np.isfinite(_vals).all() or _vals.min() < 0 or _vals.max() > 1:\n    raise RuntimeError('DINOsaur V4 PublicDual invalid prediction values')\n\n_tmp = _d4mm_work / '.submission_dinosaur_v4_publicdual.tmp.csv'\n_candidate.to_csv(_tmp, index=False)\n_d4mm_os.replace(_tmp, _d4mm_primary)\n_candidate.to_csv(_d4mm_out, index=False)\n\ndef _d4mm_sha(path):\n    h = _d4mm_hashlib.sha256()\n    with path.open('rb') as f:\n        for block in iter(lambda: f.read(8 << 20), b''):\n            h.update(block)\n    return h.hexdigest()\n\n_receipt = {\n    'schema_version': 'dinosaur_v4_publicdual_v1',\n    'status': 'passed',\n    'version_name': 'DINOsaur V4',\n    'private_coat_residual_included': False,\n    'public_rad_recipe': (\n        'twin public-v15/E10 families + E13 FS-crop@0.50 + '\n        'second E13/E11-layout@0.15'\n    ),\n    'public_raptor_recipe': 'four-view probability ensemble',\n    'medial_meniscus_recipe': '0.30 transformer rank + 0.60 Raptor rank + 0.10 Renta weak-label bag rank',\n    'output_sha256': _d4mm_sha(_d4mm_out),\n    'rows': len(_candidate),\n}\n_d4mm_receipt.write_text(\n    _d4mm_json.dumps(_receipt, indent=2, sort_keys=True) + '\\n',\n    encoding='utf-8',\n)\n\nprint(\n    '[DINOsaur V4 PublicDual] candidate PASSED | '\n    f'rows={len(_candidate)} | sha256={_receipt[\"output_sha256\"]}',\n    flush=True,\n)\n","metadata":{"tags":["DINOsaur-V4","publicdual","renta-medial-residual"],"trusted":true},"outputs":[],"execution_count":null},{"id":"f252d75d-d445-4a48-9170-51325419a448","cell_type":"markdown","source":"### Optional PublicDual + V6 probe\n\nThe previous V6 five-target overlay did **not** beat 0.937 on its own, so it is no longer the default.  \nFor completeness, this cell writes a separate probe on top of the new PublicDual parent, then restores `submission.csv` to the safer PublicDual candidate.\n","metadata":{}},{"id":"3abb9450-bc35-4fb0-b382-15468ed999ec","cell_type":"code","source":"# DINOSAUR_V4_PUBLICDUAL_V6_PROBE_ONLY\nfrom pathlib import Path as _D4V6Path\nimport shutil as _d4v6_shutil\nimport numpy as _d4v6_np\nimport pandas as _d4v6_pd\n\n_d4v6_work = _D4V6Path('/kaggle/working')\n_d4v6_main = _d4v6_work / 'submission_dinosaur_v4_publicdual_candidate.csv'\n_d4v6_probe = _d4v6_work / 'submission_dinosaur_v4_publicdual_v6_probe.csv'\n_d4v6_primary = _d4v6_work / 'submission.csv'\n\nif not _d4v6_main.is_file():\n    raise FileNotFoundError(_d4v6_main)\nfor _name in ('_blend_tr', '_blend_cr'):\n    if _name not in globals():\n        raise RuntimeError(f'V6 probe missing parent rank component: {_name}')\n\n_frame = _d4v6_pd.read_csv(_d4v6_main, dtype={'StudyInstanceUID': str})\n_labels = [c for c in _frame.columns if c != 'StudyInstanceUID']\n_weights = {\n    'ACL': 0.80,\n    'Lateral OA': 0.35,\n    'PF OA': 0.35,\n    'Synovitis': 0.35,\n    \"Baker's\": 0.375,\n}\n\n_probe = _frame.copy()\nfor _target, _rw in _weights.items():\n    raw = (\n        (1.0 - float(_rw)) * _blend_tr[_target].to_numpy(_d4v6_np.float64)\n        + float(_rw) * _blend_cr[_target].to_numpy(_d4v6_np.float64)\n    )\n    _probe[_target] = _d4v6_pd.Series(raw).rank(method='average', pct=True).to_numpy(_d4v6_np.float64)\n\n# Never disturb the proven Renta MM residual in this probe.\n_probe['Medial Meniscus'] = _frame['Medial Meniscus'].to_numpy()\n\n_vals = _probe[_labels].to_numpy(_d4v6_np.float64)\nif not _d4v6_np.isfinite(_vals).all() or _vals.min() < 0 or _vals.max() > 1:\n    raise RuntimeError('DINOsaur V4 PublicDual V6 probe invalid')\n\n_probe.to_csv(_d4v6_probe, index=False)\n\n# Keep safer PublicDual as Kaggle's default submission.csv.\n_d4v6_shutil.copyfile(_d4v6_main, _d4v6_primary)\n\nprint('DINOsaur V4 outputs:', flush=True)\nprint('  submission_dinosaur_v4_0937_control.csv          -> known 0.937 control', flush=True)\nprint('  submission_dinosaur_v4_publicdual_candidate.csv  -> PRIMARY public-only candidate', flush=True)\nprint('  submission_dinosaur_v4_publicdual_v6_probe.csv   -> optional probe', flush=True)\nprint('  submission.csv                                   -> PRIMARY PublicDual candidate', flush=True)\n","metadata":{"tags":["DINOsaur-V4","probe-only"],"trusted":true},"outputs":[],"execution_count":null},{"id":"4de5b3e3-f8d6-441d-b2bc-c51cfcdf0143","cell_type":"markdown","source":"## 🧪 V4 PublicSynovitis residual\n\nThe uploaded 0.938 reference contains a multilingual report-label parser with a specific **Synovitis backoff**: when Synovitis is not explicitly addressed, Effusion and synovial-proxy evidence are used as a weak auxiliary signal.\n\nThe exact report parser is **not copied** into this fork. More importantly, the displayed scored inference path in the reference still obtains its major final boost from a private CoAtNet residual, so reproducing the full 0.938 score without that artifact would be misleading.\n\nInstead, this V4 branch transfers only the high-level idea in a test-time-safe way: it uses **MRI-model agreement on Synovitis plus MRI-model agreement on Effusion** as a tiny, decorrelated residual for the Synovitis column only.\n\nThe known Renta Medial-Meniscus route and the other 11 targets remain untouched. Three fixed variants are written so the experiment is auditable:\n\n- `safe`: 4% auxiliary residual;\n- `main`: 8% auxiliary residual;\n- `probe`: 14% auxiliary residual.\n\n`submission.csv` is the conservative `main` candidate.\n","metadata":{}},{"id":"e5b90051-fcee-4f8d-b6e9-5c4f68c080ee","cell_type":"code","source":"# DINOSAUR_V4_PUBLIC_SYN0VITIS_EFFUSION_RESIDUAL\n# Independently written V4 experiment; no private CoAt artifact is used.\n\nfrom pathlib import Path as _D4SPath\nimport hashlib as _d4s_hashlib\nimport json as _d4s_json\nimport shutil as _d4s_shutil\nimport numpy as _d4s_np\nimport pandas as _d4s_pd\n\n_D4S_WORK = _D4SPath('/kaggle/working')\n_D4S_BASE = _D4S_WORK / 'submission_dinosaur_v4_publicdual_candidate.csv'\n_D4S_CONTROL = _D4S_WORK / 'submission_dinosaur_v4_publicsynovitis_control.csv'\n_D4S_SAFE = _D4S_WORK / 'submission_dinosaur_v4_publicsynovitis_safe.csv'\n_D4S_MAIN = _D4S_WORK / 'submission_dinosaur_v4_publicsynovitis_main.csv'\n_D4S_PROBE = _D4S_WORK / 'submission_dinosaur_v4_publicsynovitis_probe.csv'\n_D4S_PRIMARY = _D4S_WORK / 'submission.csv'\n_D4S_RECEIPT = _D4S_WORK / 'dinosaur_v4_publicsynovitis_receipt.json'\n\n_D4S_TARGET = 'Synovitis'\n_D4S_AUX = 'Effusion'\n_D4S_ALPHAS = {'safe': 0.04, 'main': 0.08, 'probe': 0.14}\n\nif not _D4S_BASE.is_file():\n    raise FileNotFoundError(\n        'PublicSynovitis requires submission_dinosaur_v4_publicdual_candidate.csv'\n    )\n\nfor _name in ('_blend_tr', '_blend_cr'):\n    if _name not in globals():\n        raise RuntimeError(f'PublicSynovitis missing public parent component: {_name}')\n\n_base = _d4s_pd.read_csv(_D4S_BASE, dtype={'StudyInstanceUID': str})\n_uids = _base['StudyInstanceUID'].astype(str).tolist()\n_labels = [c for c in _base.columns if c != 'StudyInstanceUID']\n\n_expected = [\n    'ACL','MCL','Medial Meniscus','Lateral Meniscus',\n    'Medial OA','Lateral OA','PF OA','Effusion','Synovitis',\n    \"Baker's\",'Contusion','Fracture'\n]\nif _labels != _expected:\n    raise RuntimeError(f'PublicSynovitis schema drift: {_labels}')\nif len(_uids) != len(set(_uids)):\n    raise RuntimeError('PublicSynovitis duplicate StudyInstanceUID')\n\n# _blend_tr/_blend_cr intentionally contain only the 12 label columns.\n# UID identity belongs to _blend_transformer, from which _blend_tr was derived.\nif '_blend_transformer' not in globals():\n    raise RuntimeError('PublicSynovitis missing _blend_transformer UID carrier')\nif _blend_transformer['StudyInstanceUID'].astype(str).tolist() != _uids:\n    raise RuntimeError('PublicSynovitis transformer UID order drift')\nfor _frame_name, _frame in (('transformer-ranks', _blend_tr), ('raptor-ranks', _blend_cr)):\n    if len(_frame) != len(_uids):\n        raise RuntimeError(\n            f'PublicSynovitis {_frame_name} row-count drift: '\n            f'{len(_frame)} != {len(_uids)}'\n        )\n    _missing = [c for c in _labels if c not in _frame.columns]\n    if _missing:\n        raise RuntimeError(\n            f'PublicSynovitis {_frame_name} missing labels: {_missing}'\n        )\n\n# Preserve exact input candidate before touching one column.\n_d4s_shutil.copyfile(_D4S_BASE, _D4S_CONTROL)\n\ndef _rank(x):\n    x = _d4s_np.asarray(x, dtype=_d4s_np.float64)\n    if x.shape != (len(_base),) or not _d4s_np.isfinite(x).all():\n        raise RuntimeError('PublicSynovitis invalid component vector')\n    if float(_d4s_np.std(x)) < 1e-12:\n        raise RuntimeError('PublicSynovitis degenerate component vector')\n    return _d4s_pd.Series(x).rank(method='average', pct=True).to_numpy(_d4s_np.float64)\n\n# Two-family agreement for the target.\n_tr_syn = _rank(_blend_tr[_D4S_TARGET].to_numpy())\n_rr_syn = _rank(_blend_cr[_D4S_TARGET].to_numpy())\n_syn_consensus = _rank(0.55 * _tr_syn + 0.45 * _rr_syn)\n\n# Independent auxiliary evidence: Effusion from the same two broad model families.\n_tr_eff = _rank(_blend_tr[_D4S_AUX].to_numpy())\n_rr_eff = _rank(_blend_cr[_D4S_AUX].to_numpy())\n_eff_consensus = _rank(0.55 * _tr_eff + 0.45 * _rr_eff)\n\n# Small auxiliary backoff. 82% remains direct Synovitis evidence.\n_proxy = _rank(0.82 * _syn_consensus + 0.18 * _eff_consensus)\n\n_base_syn = _rank(_base[_D4S_TARGET].to_numpy())\n\noutputs = {}\ndiagnostics = {\n    'corr_base_proxy': float(_d4s_np.corrcoef(_base_syn, _proxy)[0, 1]),\n    'corr_syn_eff': float(_d4s_np.corrcoef(_syn_consensus, _eff_consensus)[0, 1]),\n}\n\nfor _variant, _alpha in _D4S_ALPHAS.items():\n    _candidate = _base.copy()\n\n    # Rank-space residual; only Synovitis changes.\n    _new_syn = _rank(\n        (1.0 - float(_alpha)) * _base_syn\n        + float(_alpha) * _proxy\n    )\n    _candidate[_D4S_TARGET] = _new_syn\n\n    # Hard integrity gate: all other targets must remain bitwise-equivalent\n    # after CSV parsing, especially the proven Renta Medial-Meniscus route.\n    for _t in _labels:\n        if _t == _D4S_TARGET:\n            continue\n        if not _d4s_np.array_equal(\n            _candidate[_t].to_numpy(),\n            _base[_t].to_numpy(),\n        ):\n            raise RuntimeError(f'PublicSynovitis changed protected target: {_t}')\n\n    _vals = _candidate[_labels].to_numpy(_d4s_np.float64)\n    if not _d4s_np.isfinite(_vals).all():\n        raise RuntimeError(f'PublicSynovitis {_variant}: non-finite predictions')\n    if _vals.min() < 0.0 or _vals.max() > 1.0:\n        raise RuntimeError(f'PublicSynovitis {_variant}: prediction outside [0,1]')\n\n    _path = {\n        'safe': _D4S_SAFE,\n        'main': _D4S_MAIN,\n        'probe': _D4S_PROBE,\n    }[_variant]\n    _candidate.to_csv(_path, index=False)\n    outputs[_variant] = str(_path)\n\n# Main is the Kaggle default; safe and probe remain available for one-at-a-time testing.\n_d4s_shutil.copyfile(_D4S_MAIN, _D4S_PRIMARY)\n\ndef _sha(path):\n    h = _d4s_hashlib.sha256()\n    with path.open('rb') as f:\n        for block in iter(lambda: f.read(8 << 20), b''):\n            h.update(block)\n    return h.hexdigest()\n\n_receipt = {\n    'schema_version': 'dinosaur_v4_publicsynovitis_v1',\n    'status': 'passed',\n    'version_name': 'DINOsaur V4',\n    'base_candidate': str(_D4S_BASE),\n    'changed_target': _D4S_TARGET,\n    'protected_targets': [t for t in _labels if t != _D4S_TARGET],\n    'alphas': _D4S_ALPHAS,\n    'proxy': {\n        'synovitis_transformer_weight': 0.55,\n        'synovitis_raptor_weight': 0.45,\n        'direct_synovitis_weight_inside_proxy': 0.82,\n        'effusion_aux_weight_inside_proxy': 0.18,\n    },\n    'diagnostics': diagnostics,\n    'private_coat_artifact_used': False,\n    'mattia_attribution': 'mattiaangeli/bend-the-knee-to-the-dinosaurs',\n    'renta_attribution': 'renta0426/rsna-knee-0-937-weak-label-dinov2-meniscus-resid',\n    'outputs': outputs,\n    'default_submission': str(_D4S_PRIMARY),\n    'default_sha256': _sha(_D4S_PRIMARY),\n}\n_D4S_RECEIPT.write_text(\n    _d4s_json.dumps(_receipt, indent=2, sort_keys=True) + '\\n',\n    encoding='utf-8',\n)\n\nprint('DINOsaur V4 PublicSynovitis outputs:', flush=True)\nprint('  submission_dinosaur_v4_publicsynovitis_control.csv  = PublicDual control', flush=True)\nprint('  submission_dinosaur_v4_publicsynovitis_safe.csv     = alpha 0.04', flush=True)\nprint('  submission_dinosaur_v4_publicsynovitis_main.csv     = alpha 0.08 (DEFAULT)', flush=True)\nprint('  submission_dinosaur_v4_publicsynovitis_probe.csv    = alpha 0.14', flush=True)\nprint(\n    f'  corr(base,proxy)={diagnostics[\"corr_base_proxy\"]:.4f} | '\n    f'corr(syn,eff)={diagnostics[\"corr_syn_eff\"]:.4f}',\n    flush=True,\n)\n","metadata":{"tags":["DINOsaur-V4","public-only","synovitis-residual","independent-implementation"],"trusted":true},"outputs":[],"execution_count":null},{"id":"519ffc61-cc78-4c5e-9857-72039c488af6","cell_type":"markdown","source":"## 🧪 DINOsaur V4 — Public CoAt checkpoint-diversity residual\n\nThe uploaded reference uses an additional **private CoAtNet residual** inside the Raptor family. Its internal blend is around `0.40`, but reproducing that directly would require private checkpoints, so this fork does not do that.\n\nInstead, this branch uses only public Raptor predictions that DINOsaur V4 already computes:\n\n- `maxspan-v5` remains the dominant public Raptor anchor;\n- `native384dense-v10` is a different public checkpoint / dense view;\n- `native384-v8` is another public checkpoint with a different slice budget and span;\n- `reverse-v5` is retained only as a separate view-diversity probe because it shares the v5 checkpoint.\n\nThe **main residual uses only v10 + v8**, making it checkpoint-diverse rather than merely another view of the dominant v5 arm. No additional model pass is required.\n\nOutputs:\n- `safe`: internal residual alpha `0.08`;\n- `main`: alpha `0.16`;\n- `probe`: alpha `0.24`;\n- `viewprobe`: alpha `0.16` with reverse-v5 included.\n\n`submission.csv` is the `main` candidate. The outer Transformer/Raptor blend remains `0.40 / 0.60`, and the proven Renta Medial-Meniscus formula is re-applied with the modified Raptor rank.\n","metadata":{}},{"id":"508203c6-5953-4c8d-b1d2-8b8a51952b37","cell_type":"code","source":"# DINOSAUR_V4_PUBLIC_COAT_CHECKPOINT_DIVERSITY_RESIDUAL\n# Independently written; inspired by the high-level residual principle in\n# kunaldesale2408/rsna-knee-abnormality-detectionv1.\n# No private CoAt checkpoint/manifest/runtime is loaded.\n\nfrom pathlib import Path as _D4CRPath\nimport hashlib as _d4cr_hashlib\nimport json as _d4cr_json\nimport shutil as _d4cr_shutil\nimport numpy as _d4cr_np\nimport pandas as _d4cr_pd\n\n_W = _D4CRPath('/kaggle/working')\n_BAG = _W / 'public0033_bag_raw.csv'\n_CONTROL = _W / 'submission_dinosaur_v4_publicdual_candidate.csv'\n_SAFE = _W / 'submission_dinosaur_v4_publiccoat_safe.csv'\n_MAIN = _W / 'submission_dinosaur_v4_publiccoat_main.csv'\n_PROBE = _W / 'submission_dinosaur_v4_publiccoat_probe.csv'\n_VIEW = _W / 'submission_dinosaur_v4_publiccoat_viewprobe.csv'\n_PRIMARY = _W / 'submission.csv'\n_RECEIPT = _W / 'dinosaur_v4_publiccoat_receipt.json'\n\nLABS = [\n    'ACL','MCL','Medial Meniscus','Lateral Meniscus',\n    'Medial OA','Lateral OA','PF OA','Effusion','Synovitis',\n    \"Baker's\",'Contusion','Fracture'\n]\nMM = 'Medial Meniscus'\n\nfor _name in ('_blend_tr','_blend_cr'):\n    if _name not in globals():\n        raise RuntimeError(f'PublicCoAt missing parent component: {_name}')\nfor _p in (_CONTROL,_BAG):\n    if not _p.is_file():\n        raise FileNotFoundError(_p)\n\ncontrol = _d4cr_pd.read_csv(_CONTROL, dtype={'StudyInstanceUID':str})\nuids = control['StudyInstanceUID'].astype(str).tolist()\nif control.columns.tolist() != ['StudyInstanceUID', *LABS]:\n    raise RuntimeError('PublicCoAt control schema drift')\nif len(uids) != len(set(uids)):\n    raise RuntimeError('PublicCoAt duplicate UID')\n\ndef rankv(x):\n    x = _d4cr_np.asarray(x, _d4cr_np.float64)\n    if x.shape != (len(uids),) or not _d4cr_np.isfinite(x).all():\n        raise RuntimeError(f'PublicCoAt bad rank vector {x.shape}')\n    return _d4cr_pd.Series(x).rank(method='average', pct=True).to_numpy(_d4cr_np.float64)\n\ndef load_arm(slug):\n    p = _W / f'dinosaur_v4_raptor_arm_{slug}.csv'\n    if not p.is_file():\n        raise FileNotFoundError(p)\n    f = _d4cr_pd.read_csv(p, dtype={'StudyInstanceUID':str})\n    if f.columns.tolist() != ['StudyInstanceUID', *LABS]:\n        raise RuntimeError(f'PublicCoAt arm schema drift: {p.name}')\n    if f['StudyInstanceUID'].astype(str).tolist() != uids:\n        raise RuntimeError(f'PublicCoAt arm UID drift: {p.name}')\n    v = f[LABS].to_numpy(_d4cr_np.float64)\n    if not _d4cr_np.isfinite(v).all():\n        raise RuntimeError(f'PublicCoAt non-finite arm: {p.name}')\n    return v\n\nv10 = load_arm('native384dense_v10')\nrev = load_arm('maxspan_v5_reverse')\nv8 = load_arm('native384_v8')\n\ncheckpoint_res = _d4cr_np.zeros_like(v10, dtype=_d4cr_np.float64)\nview_res = _d4cr_np.zeros_like(v10, dtype=_d4cr_np.float64)\nfor j in range(len(LABS)):\n    checkpoint_res[:,j] = rankv(0.45*v10[:,j] + 0.55*v8[:,j])\n    view_res[:,j] = rankv(0.35*v10[:,j] + 0.15*rev[:,j] + 0.50*v8[:,j])\n\ntr = _blend_tr[LABS].to_numpy(_d4cr_np.float64)\nrr = _blend_cr[LABS].to_numpy(_d4cr_np.float64)\nif tr.shape != (len(uids),len(LABS)) or rr.shape != tr.shape:\n    raise RuntimeError('PublicCoAt parent shape drift')\n\nbag = _d4cr_pd.read_csv(_BAG, dtype={'StudyInstanceUID':str})\n_required_bag_cols = {'StudyInstanceUID', MM}\n_missing_bag_cols = sorted(_required_bag_cols.difference(bag.columns))\nif _missing_bag_cols:\n    raise RuntimeError(\n        f'PublicCoAt Renta bag missing required columns: {_missing_bag_cols}; '\n        f'available={bag.columns.tolist()}'\n    )\nbag = bag[['StudyInstanceUID', MM]].set_index('StudyInstanceUID').reindex(uids)\nif bag[MM].isna().any():\n    raise RuntimeError('PublicCoAt Renta bag coverage drift')\nbag_rank = rankv(bag[MM].to_numpy(_d4cr_np.float64))\nmmj = LABS.index(MM)\n\ndef build(alpha, residual):\n    nr = _d4cr_np.empty_like(rr)\n    for j in range(len(LABS)):\n        nr[:,j] = rankv((1.0-alpha)*rr[:,j] + alpha*residual[:,j])\n\n    out = _d4cr_np.empty_like(nr)\n    for j in range(len(LABS)):\n        out[:,j] = rankv(0.40*tr[:,j] + 0.60*nr[:,j])\n\n    # Preserve Renta T30 / modified-R60 / bag10.\n    out[:,mmj] = rankv(0.30*tr[:,mmj] + 0.60*nr[:,mmj] + 0.10*bag_rank)\n\n    f = _d4cr_pd.DataFrame(out, columns=LABS)\n    f.insert(0,'StudyInstanceUID',uids)\n    vals = f[LABS].to_numpy(_d4cr_np.float64)\n    if not _d4cr_np.isfinite(vals).all() or vals.min() < 0 or vals.max() > 1:\n        raise RuntimeError('PublicCoAt invalid output')\n    return f, nr\n\nsafe,safe_r = build(0.08, checkpoint_res)\nmain,main_r = build(0.16, checkpoint_res)\nprobe,probe_r = build(0.24, checkpoint_res)\nview,view_r = build(0.16, view_res)\n\nsafe.to_csv(_SAFE,index=False)\nmain.to_csv(_MAIN,index=False)\nprobe.to_csv(_PROBE,index=False)\nview.to_csv(_VIEW,index=False)\n_d4cr_shutil.copyfile(_MAIN,_PRIMARY)\n\ndef mean_corr(a,b):\n    xs=[]\n    for j in range(a.shape[1]):\n        if _d4cr_np.std(a[:,j]) < 1e-12 or _d4cr_np.std(b[:,j]) < 1e-12:\n            continue\n        xs.append(float(_d4cr_np.corrcoef(a[:,j],b[:,j])[0,1]))\n    return float(_d4cr_np.mean(xs)) if xs else float('nan')\n\ndef sha(p):\n    h=_d4cr_hashlib.sha256()\n    with p.open('rb') as f:\n        for z in iter(lambda:f.read(8<<20),b''):\n            h.update(z)\n    return h.hexdigest()\n\ndiag = {\n    'corr_public_raptor_vs_checkpoint_residual': mean_corr(rr,checkpoint_res),\n    'corr_public_raptor_vs_view_residual': mean_corr(rr,view_res),\n    'corr_v10_vs_v8': mean_corr(v10,v8),\n}\nreceipt = {\n    'schema_version':'dinosaur_v4_publiccoat_residual_v1',\n    'status':'passed',\n    'version_name':'DINOsaur V4',\n    'inspiration_credit':'kunaldesale2408/rsna-knee-abnormality-detectionv1',\n    'implementation':'independent public-only checkpoint-diversity residual',\n    'private_coat_checkpoint_used':False,\n    'private_manifest_used':False,\n    'new_model_passes':0,\n    'checkpoint_residual_weights':{'native384dense-v10':0.45,'native384-v8':0.55},\n    'viewprobe_weights':{'native384dense-v10':0.35,'maxspan-v5-reverse':0.15,'native384-v8':0.50},\n    'alphas':{'safe':0.08,'main':0.16,'probe':0.24,'viewprobe':0.16},\n    'outer_transformer_weight':0.40,\n    'outer_raptor_weight':0.60,\n    'renta_medial_recipe':'T30 / modified-R60 / bag10',\n    'diagnostics':diag,\n    'default_sha256':sha(_PRIMARY),\n}\n_RECEIPT.write_text(_d4cr_json.dumps(receipt,indent=2,sort_keys=True)+'\\n',encoding='utf-8')\n\nprint('DINOsaur V4 PublicCoAt outputs:',flush=True)\nprint('  submission_dinosaur_v4_publiccoat_safe.csv      alpha=0.08',flush=True)\nprint('  submission_dinosaur_v4_publiccoat_main.csv      alpha=0.16 DEFAULT',flush=True)\nprint('  submission_dinosaur_v4_publiccoat_probe.csv     alpha=0.24',flush=True)\nprint('  submission_dinosaur_v4_publiccoat_viewprobe.csv alpha=0.16 + reverse-v5',flush=True)\nprint('  diagnostics:',_d4cr_json.dumps(diag,sort_keys=True),flush=True)\n","metadata":{"tags":["DINOsaur-V4","public-only","coat-diversity-residual","kunal-attributed","independent-implementation"],"trusted":true},"outputs":[],"execution_count":null}]}