{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"name":"python","version":"3.10.12","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"markdown","source":"This is Still WIP","metadata":{}},{"cell_type":"code","source":"import warnings\n# Settings the warnings to be ignored\nwarnings.filterwarnings('ignore')","metadata":{"execution":{"iopub.status.busy":"2023-08-30T10:19:52.670817Z","iopub.execute_input":"2023-08-30T10:19:52.671827Z","iopub.status.idle":"2023-08-30T10:19:52.678524Z","shell.execute_reply.started":"2023-08-30T10:19:52.671785Z","shell.execute_reply":"2023-08-30T10:19:52.677026Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import numpy as np\nimport pandas as pd\nfrom tensorflow import keras\nfrom scipy.stats import kendalltau","metadata":{"execution":{"iopub.status.busy":"2023-08-30T10:19:52.680688Z","iopub.execute_input":"2023-08-30T10:19:52.681081Z","iopub.status.idle":"2023-08-30T10:19:52.692821Z","shell.execute_reply.started":"2023-08-30T10:19:52.681045Z","shell.execute_reply":"2023-08-30T10:19:52.691576Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Define evaluation metrics\ndef calculate_top_k_slowdown(predictions, actual_runtimes, k):\n    best_runtime = np.min(actual_runtimes)\n    predicted_runtimes = [actual_runtimes[prediction] for prediction in predictions[:k]]\n    slowdowns = [(best_runtime - runtime) / best_runtime for runtime in predicted_runtimes]\n    metric = 1 - (np.min(slowdowns) / (best_runtime - 1))\n    return metric","metadata":{"execution":{"iopub.status.busy":"2023-08-30T10:19:52.695853Z","iopub.execute_input":"2023-08-30T10:19:52.696269Z","iopub.status.idle":"2023-08-30T10:19:52.709400Z","shell.execute_reply.started":"2023-08-30T10:19:52.696236Z","shell.execute_reply":"2023-08-30T10:19:52.708109Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def calculate_kendall_tau_correlation(predicted_ranking, actual_ranking):\n    correlation, _ = kendalltau(predicted_ranking, actual_ranking)\n    return correlation","metadata":{"execution":{"iopub.status.busy":"2023-08-30T10:19:52.710996Z","iopub.execute_input":"2023-08-30T10:19:52.711661Z","iopub.status.idle":"2023-08-30T10:19:52.723650Z","shell.execute_reply.started":"2023-08-30T10:19:52.711627Z","shell.execute_reply":"2023-08-30T10:19:52.722607Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Load and process the data\ndata = np.load('../input/predict-ai-model-runtime/npz_all/npz/tile/xla/valid/resnet_v1_50_official_batch_128_bf16_2bea628b72fd4080.npz')","metadata":{"execution":{"iopub.status.busy":"2023-08-30T10:19:52.727176Z","iopub.execute_input":"2023-08-30T10:19:52.728035Z","iopub.status.idle":"2023-08-30T10:19:52.751711Z","shell.execute_reply.started":"2023-08-30T10:19:52.727968Z","shell.execute_reply":"2023-08-30T10:19:52.750622Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(data.files) # prints the names of all arrays stored in this npz file","metadata":{"execution":{"iopub.status.busy":"2023-08-30T10:19:52.753311Z","iopub.execute_input":"2023-08-30T10:19:52.753677Z","iopub.status.idle":"2023-08-30T10:19:52.760404Z","shell.execute_reply.started":"2023-08-30T10:19:52.753644Z","shell.execute_reply":"2023-08-30T10:19:52.759280Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"configurations = data['config_feat']\nprint(configurations)","metadata":{"execution":{"iopub.status.busy":"2023-08-30T10:19:52.762178Z","iopub.execute_input":"2023-08-30T10:19:52.762880Z","iopub.status.idle":"2023-08-30T10:19:52.778077Z","shell.execute_reply.started":"2023-08-30T10:19:52.762842Z","shell.execute_reply":"2023-08-30T10:19:52.777098Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"actual_runtimes = data['config_runtime']\nprint(actual_runtimes)","metadata":{"execution":{"iopub.status.busy":"2023-08-30T10:19:52.779600Z","iopub.execute_input":"2023-08-30T10:19:52.780672Z","iopub.status.idle":"2023-08-30T10:19:52.789103Z","shell.execute_reply.started":"2023-08-30T10:19:52.780637Z","shell.execute_reply":"2023-08-30T10:19:52.788041Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def predict_tile_xla(configurations):\n    predicted_indices = []\n    for config in configurations:\n        # Perform your prediction using the model\n        prediction = model.predict(config)\n        predicted_index = process_prediction(prediction)\n        predicted_indices.append(predicted_index)\n    \n    return predicted_indices","metadata":{"execution":{"iopub.status.busy":"2023-08-30T10:19:52.790449Z","iopub.execute_input":"2023-08-30T10:19:52.791370Z","iopub.status.idle":"2023-08-30T10:19:52.799215Z","shell.execute_reply.started":"2023-08-30T10:19:52.791336Z","shell.execute_reply":"2023-08-30T10:19:52.797908Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def predict_layout(configurations):\n    predicted_indices = []\n    for config in configurations:\n        prediction = model.predict(config)\n        predicted_index = process_prediction(prediction)\n        predicted_indices.append(predicted_index)\n    \n    return predicted_indices","metadata":{"execution":{"iopub.status.busy":"2023-08-30T10:19:52.800795Z","iopub.execute_input":"2023-08-30T10:19:52.801363Z","iopub.status.idle":"2023-08-30T10:19:52.812951Z","shell.execute_reply.started":"2023-08-30T10:19:52.801330Z","shell.execute_reply":"2023-08-30T10:19:52.811846Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"ds = pd.read_csv(\"/kaggle/input/predict-ai-model-runtime/sample_submission.csv\")\nds.to_csv(\"/kaggle/working/submission.csv\")","metadata":{"execution":{"iopub.status.busy":"2023-08-30T10:19:52.815840Z","iopub.execute_input":"2023-08-30T10:19:52.816482Z","iopub.status.idle":"2023-08-30T10:19:52.852818Z","shell.execute_reply.started":"2023-08-30T10:19:52.816449Z","shell.execute_reply":"2023-08-30T10:19:52.851718Z"},"trusted":true},"execution_count":null,"outputs":[]}],"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"pygments_lexer":"ipython3","nbconvert_exporter":"python","version":"3.6.4","file_extension":".py","codemirror_mode":{"name":"ipython","version":3},"name":"python","mimetype":"text/x-python"}}