{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "execution": {
     "iopub.execute_input": "2025-07-01T10:36:16.214454Z",
     "iopub.status.busy": "2025-07-01T10:36:16.214332Z",
     "iopub.status.idle": "2025-07-01T10:36:16.227399Z",
     "shell.execute_reply": "2025-07-01T10:36:16.226988Z",
     "shell.execute_reply.started": "2025-07-01T10:36:16.214436Z"
    }
   },
   "outputs": [],
   "source": [
    "# setup autoload\n",
    "%load_ext autoreload\n",
    "%autoreload 2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-05-16T13:58:21.040680Z",
     "start_time": "2024-05-16T13:58:19.777010Z"
    },
    "execution": {
     "iopub.execute_input": "2025-07-01T10:36:16.228331Z",
     "iopub.status.busy": "2025-07-01T10:36:16.228188Z",
     "iopub.status.idle": "2025-07-01T10:36:18.632871Z",
     "shell.execute_reply": "2025-07-01T10:36:18.632332Z",
     "shell.execute_reply.started": "2025-07-01T10:36:16.228316Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The autoreload extension is already loaded. To reload it, use:\n",
      "  %reload_ext autoreload\n"
     ]
    }
   ],
   "source": [
    "import ast\n",
    "import os\n",
    "import shutil\n",
    "import sys\n",
    "from collections import defaultdict\n",
    "\n",
    "import json\n",
    "import numpy as np\n",
    "import pandas as pd\n",
    "from preference_data_preparation_4min_30b_task import *\n",
    "from preference_helper import *\n",
    "from sklearn.model_selection import train_test_split\n",
    "from suno_utils.utils.s3 import download_s3_files\n",
    "from suno_utils.utils.text import read_json, read_jsonl, write_json, write_jsonl\n",
    "from tqdm import tqdm\n",
    "\n",
    "pd.set_option(\"display.max_rows\", 500)\n",
    "pd.set_option(\"display.max_columns\", 500)\n",
    "pd.set_option(\"display.width\", 1000)\n",
    "\n",
    "# setup autoload\n",
    "%load_ext autoreload\n",
    "%autoreload 2\n",
    "\n",
    "\n",
    "def custom_parse(x):\n",
    "    try:\n",
    "        return json.loads(x)\n",
    "    except:\n",
    "        return {}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-05-16T13:58:21.082172Z",
     "start_time": "2024-05-16T13:58:21.041926Z"
    },
    "execution": {
     "iopub.execute_input": "2025-07-01T10:36:18.633719Z",
     "iopub.status.busy": "2025-07-01T10:36:18.633428Z",
     "iopub.status.idle": "2025-07-01T10:36:18.719934Z",
     "shell.execute_reply": "2025-07-01T10:36:18.719480Z",
     "shell.execute_reply.started": "2025-07-01T10:36:18.633704Z"
    }
   },
   "outputs": [],
   "source": [
    "OUT_DATA_DIR = \"/app2/suno/data/dpo/bluejay_mix_t2\"\n",
    "os.makedirs(OUT_DATA_DIR, exist_ok=True)\n",
    "shutil.copyfile(\n",
    "    \"/app/suno/data/dpo/7v_v20_full/tokenizer_60k.json\",\n",
    "    os.path.join(OUT_DATA_DIR, \"tokenizer_60k.json\"),\n",
    ")\n",
    "NPZ_DIR = \"/app/suno/data/dpo/30b_npz\"\n",
    "# NOTE FOR 30b we increase this from 6016 up\n",
    "N_TOKENS_AUDIO = 6016"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-05-16T13:58:53.962528Z",
     "start_time": "2024-05-16T13:58:21.105919Z"
    },
    "execution": {
     "iopub.execute_input": "2025-06-03T18:43:23.246328Z",
     "iopub.status.busy": "2025-06-03T18:43:23.246152Z",
     "iopub.status.idle": "2025-06-03T18:43:37.586617Z",
     "shell.execute_reply": "2025-06-03T18:43:37.586255Z",
     "shell.execute_reply.started": "2025-06-03T18:43:23.246316Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Preference data shape (931852, 90)\n"
     ]
    }
   ],
   "source": [
    "df = pd.read_pickle(\n",
    "    \"/home/tony/Data/Preference/30b_v6/interesting_clips_v4_h_t_6_20250501_full_long.pkl\"\n",
    ")\n",
    "print(\"Preference data shape\", df.shape)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "execution": {
     "iopub.execute_input": "2025-06-03T18:43:37.587228Z",
     "iopub.status.busy": "2025-06-03T18:43:37.587012Z",
     "iopub.status.idle": "2025-06-03T18:43:39.597769Z",
     "shell.execute_reply": "2025-06-03T18:43:39.597399Z",
     "shell.execute_reply.started": "2025-06-03T18:43:37.587215Z"
    }
   },
   "outputs": [],
   "source": [
    "# df[\"created_at\"] = pd.to_datetime(df[\"created_at\"], utc=True)\n",
    "# cutoff_date = pd.to_datetime(\"2025-04-12\", utc=True)\n",
    "# # cutoff_date = pd.to_datetime(\"2025-04-17\", utc=True)\n",
    "# print(df.shape, df[df[\"created_at\"] >= cutoff_date].shape)\n",
    "# df = df[(df[\"created_at\"] >= cutoff_date)].copy()\n",
    "# print(\"after date cut\", df.shape)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {
    "execution": {
     "iopub.execute_input": "2025-06-03T18:43:39.602984Z",
     "iopub.status.busy": "2025-06-03T18:43:39.602745Z",
     "iopub.status.idle": "2025-06-03T18:43:40.429557Z",
     "shell.execute_reply": "2025-06-03T18:43:40.429193Z",
     "shell.execute_reply.started": "2025-06-03T18:43:39.602970Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "after dropna (931852, 85)\n"
     ]
    }
   ],
   "source": [
    "df = df.dropna(axis=1, how=\"all\")\n",
    "print(\"after dropna\", df.shape)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-05-16T13:58:56.199480Z",
     "start_time": "2024-05-16T13:58:53.963687Z"
    },
    "execution": {
     "iopub.execute_input": "2025-06-03T18:43:40.430543Z",
     "iopub.status.busy": "2025-06-03T18:43:40.430301Z",
     "iopub.status.idle": "2025-06-03T18:49:02.664583Z",
     "shell.execute_reply": "2025-06-03T18:49:02.664215Z",
     "shell.execute_reply.started": "2025-06-03T18:43:40.430530Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "6442462\n",
      "6442462\n",
      "pre-downloaded df (931852, 85)\n",
      "downloaded df (931851, 85)\n"
     ]
    }
   ],
   "source": [
    "converted_paths = os.listdir(NPZ_DIR)\n",
    "print(len(converted_paths))\n",
    "\n",
    "converted_paths = set([f.replace(\".npz\", \"\") for f in converted_paths])\n",
    "print(len(converted_paths))\n",
    "\n",
    "print(\"pre-downloaded df\", df.shape)\n",
    "df[df[\"s3_id\"].isin(converted_paths)].shape\n",
    "df = df[df[\"s3_id\"].isin(converted_paths)].copy()\n",
    "print(\"downloaded df\", df.shape)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-05-16T13:58:56.467253Z",
     "start_time": "2024-05-16T13:58:56.207647Z"
    },
    "execution": {
     "iopub.execute_input": "2025-06-03T18:49:02.665136Z",
     "iopub.status.busy": "2025-06-03T18:49:02.664973Z",
     "iopub.status.idle": "2025-06-03T18:49:03.822609Z",
     "shell.execute_reply": "2025-06-03T18:49:03.822260Z",
     "shell.execute_reply.started": "2025-06-03T18:49:02.665123Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "is_30b\n",
      "True    931851\n",
      "Name: count, dtype: int64\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "task\n",
       "cover                 502287\n",
       "artist_consistency    377994\n",
       "infill                 51546\n",
       "                          20\n",
       "artist_extend              4\n",
       "Name: count, dtype: int64"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df[\"is_30b\"] = df[\"model_name\"].str.contains(\"-t\")\n",
    "print(df[\"is_30b\"].value_counts())\n",
    "df[\"task\"].value_counts()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# LET's do the data prep"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {
    "execution": {
     "iopub.execute_input": "2025-06-03T18:49:03.823240Z",
     "iopub.status.busy": "2025-06-03T18:49:03.823001Z",
     "iopub.status.idle": "2025-06-03T18:49:03.836953Z",
     "shell.execute_reply": "2025-06-03T18:49:03.836653Z",
     "shell.execute_reply.started": "2025-06-03T18:49:03.823228Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(931851, 86)\n"
     ]
    }
   ],
   "source": [
    "# drop extend for now\n",
    "# reason is -- cause they are likely caused by extend from 13b\n",
    "# we don't want contamination\n",
    "# df = df[df[\"task\"] != \"extend\"].copy()\n",
    "print(df.shape)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-05-16T13:58:56.592883Z",
     "start_time": "2024-05-16T13:58:56.470781Z"
    },
    "execution": {
     "iopub.execute_input": "2025-06-03T18:49:03.837446Z",
     "iopub.status.busy": "2025-06-03T18:49:03.837271Z",
     "iopub.status.idle": "2025-06-03T18:49:03.996198Z",
     "shell.execute_reply": "2025-06-03T18:49:03.995838Z",
     "shell.execute_reply.started": "2025-06-03T18:49:03.837434Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "preference  model_name    \n",
      "False       chirp-v4-h-t-6    465926\n",
      "True        chirp-v4-h-t-6    465925\n",
      "Name: count, dtype: int64\n",
      "before filter on model name (931851, 86)\n",
      "after filter on model name (931851, 86)\n"
     ]
    }
   ],
   "source": [
    "## for 13b this is easy for now\n",
    "print(df.groupby([\"preference\"])[\"model_name\"].value_counts())\n",
    "print(\"before filter on model name\", df.shape)\n",
    "df = df[df[\"model_name\"].isin([\"chirp-v4-h-t-6\", \"chirp-v3p5-engine-t-6\"])]\n",
    "# df = df[df[\"model_name\"].isin([\"chirp-v3p5-engine-t-6\"])]\n",
    "print(\"after filter on model name\", df.shape)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {
    "execution": {
     "iopub.execute_input": "2025-06-03T18:49:03.996770Z",
     "iopub.status.busy": "2025-06-03T18:49:03.996573Z",
     "iopub.status.idle": "2025-06-03T18:49:04.012270Z",
     "shell.execute_reply": "2025-06-03T18:49:04.011995Z",
     "shell.execute_reply.started": "2025-06-03T18:49:03.996758Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "is_public\n",
      "False    908417\n",
      "True      23434\n",
      "Name: count, dtype: int64\n"
     ]
    }
   ],
   "source": [
    "print(df[\"is_public\"].value_counts())\n",
    "# remove public for now cause fucking users\n",
    "# df = df[~df[\"is_public\"]]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-05-16T13:58:56.909539Z",
     "start_time": "2024-05-16T13:58:56.595736Z"
    },
    "execution": {
     "iopub.execute_input": "2025-06-03T18:49:04.012734Z",
     "iopub.status.busy": "2025-06-03T18:49:04.012579Z",
     "iopub.status.idle": "2025-06-03T18:49:04.624021Z",
     "shell.execute_reply": "2025-06-03T18:49:04.623628Z",
     "shell.execute_reply.started": "2025-06-03T18:49:04.012723Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "before filter on request id pairs (931851, 86)\n",
      "after filter on request id pairs (931850, 86)\n",
      "preference  model_name    \n",
      "False       chirp-v4-h-t-6    465925\n",
      "True        chirp-v4-h-t-6    465925\n",
      "Name: count, dtype: int64\n"
     ]
    }
   ],
   "source": [
    "print(\"before filter on request id pairs\", df.shape)\n",
    "df = df[\n",
    "    df[\"request_id\"].isin(\n",
    "        df[\"request_id\"].value_counts().index[df[\"request_id\"].value_counts() == 2]\n",
    "    )\n",
    "]\n",
    "print(\"after filter on request id pairs\", df.shape)\n",
    "print(df.groupby([\"preference\"])[\"model_name\"].value_counts())\n",
    "assert df.shape[0] == df[\"request_id\"].nunique() * 2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {
    "execution": {
     "iopub.execute_input": "2025-06-03T18:49:04.625796Z",
     "iopub.status.busy": "2025-06-03T18:49:04.625607Z",
     "iopub.status.idle": "2025-06-03T18:50:15.511358Z",
     "shell.execute_reply": "2025-06-03T18:50:15.510996Z",
     "shell.execute_reply.started": "2025-06-03T18:49:04.625783Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "unique_requests 465925\n",
      "before removing duplicates (931850, 165)\n",
      "after removing duplicates (931850, 158)\n"
     ]
    }
   ],
   "source": [
    "# Let's use the old selection for now -- for quality assurance\n",
    "# expand the metadata columns -- this takes forever...~ 6 mins\n",
    "# test_slice = df[\"metadata\"].apply(lambda x: ast.literal_eval(str(x)))\n",
    "# test_slice = df[\"metadata\"].apply(lambda x: custom_parse(x))\n",
    "test_slice = df[\"metadata\"]  # .apply(lambda x: custom_parse(x))\n",
    "test_slice_series = test_slice.apply(pd.Series)\n",
    "df = pd.concat([df, test_slice_series], axis=1, join=\"inner\")\n",
    "print(\"unique_requests\", df[\"request_id\"].nunique())\n",
    "# remove the duplicates\n",
    "print(\"before removing duplicates\", df.shape)\n",
    "df = df.loc[:, ~df.columns.duplicated()].copy()\n",
    "print(\"after removing duplicates\", df.shape)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {
    "execution": {
     "iopub.execute_input": "2025-06-03T18:50:15.512060Z",
     "iopub.status.busy": "2025-06-03T18:50:15.511749Z",
     "iopub.status.idle": "2025-06-03T18:50:16.319307Z",
     "shell.execute_reply": "2025-06-03T18:50:16.318970Z",
     "shell.execute_reply.started": "2025-06-03T18:50:15.512047Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "task\n",
       "cover                 502286\n",
       "artist_consistency    377994\n",
       "infill                 51546\n",
       "                          20\n",
       "artist_extend              4\n",
       "Name: count, dtype: int64"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df[\"task\"].value_counts()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {
    "execution": {
     "iopub.execute_input": "2025-06-03T18:50:16.319885Z",
     "iopub.status.busy": "2025-06-03T18:50:16.319685Z",
     "iopub.status.idle": "2025-06-03T18:50:17.187823Z",
     "shell.execute_reply": "2025-06-03T18:50:17.187497Z",
     "shell.execute_reply.started": "2025-06-03T18:50:16.319873Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "pos_diff_preference\n",
       "1.0    324077\n",
       "2.0    141848\n",
       "Name: count, dtype: int64"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df = df.sort_values(by=[\"request_id\", \"preference\", \"diff_preference\"])\n",
    "df[\"pos_diff_preference\"] = df[\"diff_preference\"].diff()\n",
    "# df[\"cer_diff_preference\"] = df[\"cer\"].diff()\n",
    "df[df[\"preference\"]][\"pos_diff_preference\"].value_counts()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {
    "execution": {
     "iopub.execute_input": "2025-06-03T18:50:17.188415Z",
     "iopub.status.busy": "2025-06-03T18:50:17.188181Z",
     "iopub.status.idle": "2025-06-03T18:50:17.489079Z",
     "shell.execute_reply": "2025-06-03T18:50:17.488721Z",
     "shell.execute_reply.started": "2025-06-03T18:50:17.188402Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "positive param_experiment\n",
      "text_1        11556\n",
      "temp_s_80     11381\n",
      "temp_s_70     10863\n",
      "min_p_0001      363\n",
      "min_p_002       354\n",
      "step_8          191\n",
      "text_3          170\n",
      "step_12         168\n",
      "Name: count, dtype: int64\n"
     ]
    }
   ],
   "source": [
    "try:\n",
    "    print(\"positive\", df[df[\"preference\"]][\"param_experiment\"].value_counts())\n",
    "except:\n",
    "    pass"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {
    "execution": {
     "iopub.execute_input": "2025-06-03T18:50:17.489680Z",
     "iopub.status.busy": "2025-06-03T18:50:17.489479Z",
     "iopub.status.idle": "2025-06-03T18:50:30.989567Z",
     "shell.execute_reply": "2025-06-03T18:50:30.989209Z",
     "shell.execute_reply.started": "2025-06-03T18:50:17.489667Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Found 79903 duplicated prompts 39952 unique requests\n",
      "Found 19464 request_ids with duplicate prompts but not highest play counts in their group\n",
      "['c8390ab2-e5be-4d69-b5bf-4e9404088949', 'e12dafc1-45e3-4abd-9a58-d5e4293ae33b', '6f5b4451-853e-4196-818c-345d9fa0f684', '69e8eef7-4326-4796-b9f7-833143e3afde', 'b75e653f-eb32-409e-a5ce-1ef39f1fa1c1', 'fa5aba0d-4424-438b-9f87-ba5d0ef503cb', 'e3959990-3e05-4c7b-9792-8d57b0290b99', '115a0270-2735-43a2-80d4-05b371926471', '14e7fadb-f34c-4f26-9bda-c378283f529a', '47de7b19-69c3-4a23-967f-658950a9df5a']\n",
      "Before dedup user gen requests 931850\n",
      "After dedup user gen requests 931850\n"
     ]
    }
   ],
   "source": [
    "# Find duplicated prompts with count > 2\n",
    "duplicate_entries = df.groupby(\n",
    "    [\"user_id\", \"prompt_text\", \"tags\", \"task\", \"edited_clip_id\"]\n",
    ").filter(lambda x: len(x) > 2)\n",
    "print(\n",
    "    \"Found\",\n",
    "    len(duplicate_entries),\n",
    "    \"duplicated prompts\",\n",
    "    len(duplicate_entries[\"request_id\"].unique()),\n",
    "    \"unique requests\",\n",
    ")\n",
    "\n",
    "# Group by user_id, prompt_text, and tags to find duplicate prompt groups\n",
    "prompt_groups = duplicate_entries.groupby(\n",
    "    [\"user_id\", \"prompt_text\", \"tags\", \"task\", \"edited_clip_id\"]\n",
    ")\n",
    "\n",
    "# For each prompt group, find the request_id with the highest total reaction_play_count\n",
    "low_play_count_request_ids = []\n",
    "for prompt_key, prompt_group in prompt_groups:\n",
    "    # Get the sum of reaction_play_count for each request_id in this group\n",
    "    request_play_counts = prompt_group.groupby(\"request_id\")[\n",
    "        \"reaction_play_count\"\n",
    "    ].sum()\n",
    "\n",
    "    # Find the max play count in this group\n",
    "    max_play_count = request_play_counts.max()\n",
    "\n",
    "    # Add request_ids that don't have the max play count to our filter list\n",
    "    lower_play_count_request_ids = request_play_counts[\n",
    "        request_play_counts < max_play_count\n",
    "    ].index.tolist()\n",
    "    low_play_count_request_ids.extend(lower_play_count_request_ids)\n",
    "\n",
    "# Display the filtered request IDs\n",
    "print(\n",
    "    f\"Found {len(low_play_count_request_ids)} request_ids with duplicate prompts but not highest play counts in their group\"\n",
    ")\n",
    "print(\n",
    "    low_play_count_request_ids[:10]\n",
    "    if len(low_play_count_request_ids) > 10\n",
    "    else low_play_count_request_ids\n",
    ")\n",
    "print(\"Before dedup user gen requests\", df.shape[0])\n",
    "# df = df[~df[\"request_id\"].isin(low_play_count_request_ids)]\n",
    "print(\"After dedup user gen requests\", df.shape[0])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-05-16T13:59:40.799375Z",
     "start_time": "2024-05-16T13:59:36.394236Z"
    },
    "execution": {
     "iopub.execute_input": "2025-06-03T18:50:30.990093Z",
     "iopub.status.busy": "2025-06-03T18:50:30.989949Z",
     "iopub.status.idle": "2025-06-03T18:50:33.107667Z",
     "shell.execute_reply": "2025-06-03T18:50:33.107316Z",
     "shell.execute_reply.started": "2025-06-03T18:50:30.990080Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "22935\n",
      "good_continue_at\n",
      "True    931850\n",
      "Name: count, dtype: int64\n",
      "\n",
      " Check some basics... \n",
      " preference\n",
      "False    465925\n",
      "True     465925\n",
      "Name: count, dtype: int64 is_30b\n",
      "True    931850\n",
      "Name: count, dtype: int64 model_name\n",
      "chirp-v4-h-t-6    931850\n",
      "Name: count, dtype: int64 preference  model_name    \n",
      "False       chirp-v4-h-t-6    465925\n",
      "True        chirp-v4-h-t-6    465925\n",
      "Name: count, dtype: int64\n",
      "task\n",
      "cover                 502286\n",
      "artist_consistency    377994\n",
      "infill                 51546\n",
      "                          20\n",
      "artist_extend              4\n",
      "Name: count, dtype: int64\n"
     ]
    }
   ],
   "source": [
    "df[\"id\"] = df[\"str_id\"]\n",
    "# get the original duration of the clips, if they are concacted\n",
    "df[\"original_duration_s\"] = df[\"total_start_s\"] + df[\"duration\"]\n",
    "# classify the continue at behavoirs by the duration choice\n",
    "audio_prompt_id_to_continue_at = {}\n",
    "\n",
    "for _, row in df[~df[\"continued_parent\"].isna()].iterrows():\n",
    "    audio_prompt_id = row[\"continued_parent\"]\n",
    "    if audio_prompt_id not in audio_prompt_id_to_continue_at:\n",
    "        audio_prompt_id_to_continue_at[audio_prompt_id] = row[\"continue_at\"]\n",
    "    else:\n",
    "        # pick the max\n",
    "        audio_prompt_id = max(\n",
    "            audio_prompt_id_to_continue_at[audio_prompt_id], row[\"continue_at\"]\n",
    "        )\n",
    "print(len(audio_prompt_id_to_continue_at))\n",
    "df[\"has_continue_and_start_continue_at\"] = df[\"id\"].apply(\n",
    "    lambda x: audio_prompt_id_to_continue_at.get(x)\n",
    ")\n",
    "# we want continue at to be at most of the clip...\n",
    "df[\"good_continue_at\"] = (\n",
    "    (df[\"has_continue_and_start_continue_at\"] / df[\"duration\"]) > 0.9\n",
    ") | df[\"has_continue_and_start_continue_at\"].isna()\n",
    "print(df[\"good_continue_at\"].value_counts())\n",
    "\n",
    "\n",
    "print(\n",
    "    \"\\n Check some basics... \\n\",\n",
    "    df[\"preference\"].value_counts(),\n",
    "    df[\"is_30b\"].value_counts(),\n",
    "    df[\"model_name\"].value_counts(),\n",
    "    df.groupby([\"preference\"])[\"model_name\"].value_counts(),\n",
    ")\n",
    "\n",
    "df = df.sort_values(by=[\"request_id\", \"preference\"])\n",
    "df[\"duration_rel_diff\"] = df[\"duration\"].diff()\n",
    "df[\"play_rel_diff\"] = df[\"reaction_play_count\"].diff()\n",
    "print(df[\"task\"].value_counts())\n",
    "\n",
    "df[\"post_infill_duration\"] = (\n",
    "    df[\"duration\"]\n",
    "    + df[\"infill_context_end_s\"]\n",
    "    - df[\"infill_context_start_s\"]\n",
    "    - df[\"include_future_s\"]\n",
    "    - df[\"include_history_s\"]\n",
    "    - df[\"infill_dur_s\"]\n",
    ")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {
    "execution": {
     "iopub.execute_input": "2025-06-03T18:50:33.108248Z",
     "iopub.status.busy": "2025-06-03T18:50:33.108048Z",
     "iopub.status.idle": "2025-06-03T18:50:33.276257Z",
     "shell.execute_reply": "2025-06-03T18:50:33.275933Z",
     "shell.execute_reply.started": "2025-06-03T18:50:33.108235Z"
    }
   },
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAjAAAAGdCAYAAAAMm0nCAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjkuMiwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8hTgPZAAAACXBIWXMAAA9hAAAPYQGoP6dpAAAvEUlEQVR4nO3df3TUVX7/8dd88gMSkkBIgsjCKiUmoBES1JNNHJbVyrpF3XMi7UKLq1iO4CrCUVagFIUgmwQED6J2oUpRFJq1grr+oFvdisUTEGrJslEEIq7GZm0yQzAhgfyaz/cPvhkzMZBMfszMzTwf5+SczGfuzOe+547yyr2fHw7btm0BAAAYxAp2BwAAAPxFgAEAAMYhwAAAAOMQYAAAgHEIMAAAwDgEGAAAYBwCDAAAMA4BBgAAGIcAAwAAjEOAAQAAxokMdgf6m9tdp0DdLMHhkJKS4gO6z2ALx5ol6qbugS8ca5aoOxTqbutLVwZ8gLFtBXwwgrHPYAvHmiXqDjfhWHc41ixRtwlYQgIAAMYhwAAAAOMQYAAAgHEIMAAAwDgEGAAAYBwCDAAAMA4BBgAAGIcAAwAAj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KkIywERHR+uqq67S/v37vds8Ho/279/vs6QEAADCU0gexCtJd999t5YuXaqMjAxNnDhRL7zwgs6ePavbb7892F0DAABBFrIBZvr06Tp16pQ2bdqk6upqTZgwQc899xxLSAAAIDTPQgIAALiYkDwGBgAA4GIIMAAAwDgEGAAAYBwCDAAAMA4Bpo/s2LFDN954o66++mr9zd/8jY4cORLsLvWpp556Sunp6T4/P/nJT7zPNzY2Kj8/X9nZ2crKytIDDzwgl8sVxB7779ChQ7r33nvldDqVnp6ud9991+d527b15JNPyul0auLEiZozZ47+9Kc/+bQ5ffq0Fi9erMmTJ+vaa6/V8uXLVV9fH8Aq/NdV3cuWLfvO2M+dO9enjYl1b9myRTNmzFBWVpZycnJ033336eTJkz5tuvO9rqys1Lx58zRp0iTl5ORo7dq1amlpCWQp3dadmn/+859/Z7wfffRRnzYm1SxJO3fu1G233abJkydr8uTJmjlzpt5//33v8wNtnNt0VbfxY22j19566y37qquusl955RX7xIkT9ooVK+xrr73Wdrlcwe5an9m0aZN9yy232FVVVd4ft9vtff7RRx+1p06dapeUlNh//OMf7Z/97Gf2zJkzg9hj/+3du9d+4okn7P/4j/+w09LS7Hfeecfn+S1bttjXXHON/c4779hHjx617733XvvGG2+0z507520zd+5c+6c//aldWlpqHzp0yJ42bZr90EMPBboUv3RV99KlS+25c+f6jP3p06d92phY99///d/bu3btso8fP24fPXrUvueee+wf/ehHdn19vbdNV9/rlpYW+9Zbb7XnzJljf/LJJ/bevXvt7Oxse8OGDcEoqUvdqfmOO+6wV6xY4TPedXV13udNq9m2bfv3v/+9vXfvXvvzzz+3T548aT/xxBP2VVddZR8/fty27YE3zm26qtv0sSbA9IG//uu/tvPz872PW1tbbafTaW/ZsiWIvepbmzZtsn/60592+lxtba191VVX2Xv27PFuKy8vt9PS0uzDhw8HqId9q+M/5B6Px77++uvt5557zruttrbWzsjIsN98803btr+t+ciRI94277//vp2enm5//fXXget8L1wowPziF7+44GsGQt22bdtut9tOS0uzDx48aNt2977Xe/futceP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gAAGIcAAwAAjEOAAQAAxiHAAAAA4xBgAACAcQgwAADAOAQYAABgHAIMAAAwDgEGAAAYhwADAACMQ4ABAADGIcAAAADj/D8y4eWK9yOESAAAAABJRU5ErkJggg==",
      "text/plain": [
       "<Figure size 640x480 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "df[\"post_infill_duration\"].hist(bins=np.linspace(-5, 360, 100))\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-05-16T13:59:41.035167Z",
     "start_time": "2024-05-16T13:59:40.801098Z"
    },
    "execution": {
     "iopub.execute_input": "2025-06-03T18:50:33.276843Z",
     "iopub.status.busy": "2025-06-03T18:50:33.276689Z",
     "iopub.status.idle": "2025-06-03T18:50:34.560313Z",
     "shell.execute_reply": "2025-06-03T18:50:34.559953Z",
     "shell.execute_reply.started": "2025-06-03T18:50:33.276830Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "after duration 0.9956505875409133\n",
      "after infill duration 0.9979245586736063\n",
      "neg_filter_reaction_play_count 1.0\n",
      "neg_filter_upvote_count 0.9895\n",
      "neg_filter_norm_play_frac 1.0\n",
      "neg_filter_continues 1.0\n",
      "----------------\n",
      "pos_filter_continues 1.0\n",
      "pos_filter_reaction_play_count 1.0\n",
      "pos_filter_relative_play_count 0.9741\n",
      "pos_filter_cer_diff_preference 1.0\n",
      "pos_filter_bad_flags 0.9999\n",
      "after filter on play counts 0.9742\n",
      "after filter on higher quality 0.318\n",
      "----------------\n",
      "negative 458116 positive 130106\n",
      "----------------\n",
      "total pair requests 465925  --> selected pair requests 128741 frac 0.276\n"
     ]
    }
   ],
   "source": [
    "normal_pos_play_count = 3\n",
    "# this is lower, cause a concat is probably already ensuring that it is good\n",
    "concat_pos_play_count = 1\n",
    "# this is a filter on the concated clip\n",
    "concat_total_play_count = 3\n",
    "\n",
    "all_fitlers = (df[\"duration\"] >= 10) & (df[\"duration\"] <= 240)\n",
    "print(\"after duration\", all_fitlers.sum() / df.shape[0])\n",
    "infill_duration_filter = (\n",
    "    ~df[\"task\"].isin(\n",
    "        [\n",
    "            \"infill\",\n",
    "            \"infill_intro\",\n",
    "            \"infill_outro\",\n",
    "        ]\n",
    "    )\n",
    ") | (df[\"post_infill_duration\"] <= 239)\n",
    "print(\"after infill duration\", infill_duration_filter.sum() / df.shape[0])\n",
    "# negative fitlers\n",
    "total_negative = df[~df[\"preference\"]].shape[0]\n",
    "neg_filter_reaction_play_count = (~df[\"preference\"]) & (df[\"reaction_play_count\"] >= 1)\n",
    "print(\n",
    "    \"neg_filter_reaction_play_count\",\n",
    "    round(neg_filter_reaction_play_count.sum() / total_negative, 4),\n",
    ")\n",
    "neg_filter_upvote_count = (~df[\"preference\"]) & (df[\"upvote_count\"] == 0)\n",
    "print(\n",
    "    \"neg_filter_upvote_count\",\n",
    "    round(neg_filter_upvote_count.sum() / total_negative, 4),\n",
    ")\n",
    "neg_filter_norm_play_frac = (~df[\"preference\"]) & (df[\"norm_play_frac\"] <= 3.1)\n",
    "print(\n",
    "    \"neg_filter_norm_play_frac\",\n",
    "    round(neg_filter_norm_play_frac.sum() / total_negative, 4),\n",
    ")\n",
    "neg_filter_continues = (~df[\"preference\"]) & (\n",
    "    df[\"has_continue_and_start_continue_at\"].isna()\n",
    ")\n",
    "print(\n",
    "    \"neg_filter_continues\",\n",
    "    round(neg_filter_continues.sum() / total_negative, 4),\n",
    ")\n",
    "\n",
    "neg_filter_selection_mask = (\n",
    "    all_fitlers\n",
    "    & infill_duration_filter\n",
    "    & neg_filter_reaction_play_count\n",
    "    & neg_filter_upvote_count\n",
    "    & neg_filter_norm_play_frac\n",
    "    & neg_filter_continues\n",
    ")\n",
    "\n",
    "print(\"----------------\")\n",
    "total_positive = df[df[\"preference\"]].shape[0]\n",
    "assert total_positive == total_negative\n",
    "pos_filter_continues = (df[\"preference\"]) & (df[\"good_continue_at\"])\n",
    "print(\"pos_filter_continues\", round(pos_filter_continues.sum() / total_positive, 4))\n",
    "pos_filter_reaction_play_count = (df[\"preference\"]) & (df[\"reaction_play_count\"] >= 1)\n",
    "print(\n",
    "    \"pos_filter_reaction_play_count\",\n",
    "    round(pos_filter_reaction_play_count.sum() / total_positive, 4),\n",
    ")\n",
    "pos_filter_relative_play_count = (df[\"preference\"]) & (df[\"play_rel_diff\"] >= 0)\n",
    "print(\n",
    "    \"pos_filter_relative_play_count\",\n",
    "    round(pos_filter_relative_play_count.sum() / total_positive, 4),\n",
    ")\n",
    "pos_filter_cer_diff_preference = (\n",
    "    df[\n",
    "        \"preference\"\n",
    "    ]  # & (df[\"pos_diff_preference\"] == 2) # & (df[\"cer_diff_preference\"] < 0.5) & (df[\"cer\"] < 0.99)\n",
    ")\n",
    "print(\n",
    "    \"pos_filter_cer_diff_preference\",\n",
    "    round(pos_filter_cer_diff_preference.sum() / total_positive, 4),\n",
    ")\n",
    "pos_filter_bad_flags = (\n",
    "    (df[\"preference\"]) & (df[\"flag_count\"] == 0) & (df[\"dislike_count\"] == 0)\n",
    ")\n",
    "print(\n",
    "    \"pos_filter_bad_flags\",\n",
    "    round(pos_filter_bad_flags.sum() / total_positive, 4),\n",
    ")\n",
    "pos_filter_play_counts = (df[\"preference\"]) & (\n",
    "    (\n",
    "        (df[\"part_of_concat\"])\n",
    "        & (df[\"reaction_play_count\"] >= concat_pos_play_count)\n",
    "        & (df[\"concat_play_counts\"] >= concat_total_play_count)\n",
    "    )\n",
    "    | (\n",
    "        (~df[\"part_of_concat\"]) & (df[\"reaction_play_count\"] >= normal_pos_play_count)\n",
    "        # & (df[\"norm_play_frac\"] >= 2.1)  # this is a bit of a luxury cut...\n",
    "    )\n",
    "    | (df[\"task\"].isin([\"infill\", \"infill_intro\", \"infill_outro\"]))\n",
    ")\n",
    "print(\n",
    "    \"after filter on play counts\",\n",
    "    round(pos_filter_play_counts.sum() / total_positive, 4),\n",
    ")\n",
    "high_quality_tasks_filter = (\n",
    "    (df[\"task\"].isin([\"cover\", \"extend\", \"artist_consistency\", \"\"]))\n",
    "    & (\n",
    "        (df[\"upvote_count\"] >= 1)  # (df[\"upvote_count\"] >= 1)\n",
    "        | (df[\"reaction_play_count\"] >= 5)\n",
    "        | (df[\"concat_play_counts\"] >= 5)\n",
    "    )\n",
    "    & (\n",
    "        (df[\"part_of_concat\"])\n",
    "        | (\n",
    "            (~df[\"part_of_concat\"])\n",
    "            & (df[\"norm_play_frac\"] >= 5.1)  # this is a bit of a luxury cut...\n",
    "            & (\n",
    "                df[\"norm_play_frac\"] >= df[\"reaction_play_count\"] / 3\n",
    "            )  # play duration is not low on average\n",
    "        )\n",
    "    )\n",
    ")\n",
    "medium_quality_tasks_filter = (\n",
    "    df[\"task\"].isin(\n",
    "        [\n",
    "            \"infill\",\n",
    "            \"infill_intro\",\n",
    "            \"infill_outro\",\n",
    "        ]\n",
    "    )\n",
    ") & (  # let more infill through only in this case...\n",
    "    (\n",
    "        df[\"upvote_count\"] >= 0\n",
    "    )  # (df[\"upvote_count\"] >= 1)  (df[\"pos_diff_preference\"] == 2)\n",
    "    | (df[\"reaction_play_count\"] >= 1)\n",
    "    | (df[\"concat_play_counts\"] >= 1)\n",
    ")\n",
    "pos_filter_higher_quality = (df[\"preference\"]) & (\n",
    "    high_quality_tasks_filter | medium_quality_tasks_filter\n",
    ")\n",
    "print(\n",
    "    \"after filter on higher quality\",\n",
    "    round(pos_filter_higher_quality.sum() / total_positive, 4),\n",
    ")\n",
    "\n",
    "user_gen_filter = (\n",
    "    df[\"user_n_clips\"] >= 100\n",
    ")  # user needs to have genereated at least 100 over the time period\n",
    "\n",
    "print(\"----------------\")\n",
    "pos_filter_selectin_mask = (\n",
    "    (df[\"preference\"])  # get basics aligned\n",
    "    & all_fitlers\n",
    "    & infill_duration_filter\n",
    "    & pos_filter_continues\n",
    "    & pos_filter_reaction_play_count\n",
    "    & pos_filter_relative_play_count\n",
    "    & pos_filter_cer_diff_preference\n",
    "    & pos_filter_bad_flags\n",
    "    & pos_filter_play_counts\n",
    "    & pos_filter_higher_quality\n",
    "    & user_gen_filter\n",
    ")\n",
    "print(\n",
    "    \"negative\",\n",
    "    sum(neg_filter_selection_mask),\n",
    "    \"positive\",\n",
    "    sum(pos_filter_selectin_mask),\n",
    ")\n",
    "\n",
    "neg_filter_requests = df[neg_filter_selection_mask][\"request_id\"].unique()\n",
    "pos_filter_requests = df[pos_filter_selectin_mask][\"request_id\"].unique()\n",
    "# looking for very strong signal here:\n",
    "# listen to the positive/negative more than once\n",
    "# disliked one of the clips\n",
    "unique_requests = set(pos_filter_requests).intersection(neg_filter_requests)\n",
    "print(\"----------------\")\n",
    "print(\n",
    "    \"total pair requests\",\n",
    "    df[\"request_id\"].nunique(),\n",
    "    \" --> selected pair requests\",\n",
    "    len(unique_requests),\n",
    "    f\"frac {len(unique_requests) / df['request_id'].nunique():.3f}\",\n",
    ")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-05-16T13:59:41.250737Z",
     "start_time": "2024-05-16T13:59:41.036434Z"
    },
    "execution": {
     "iopub.execute_input": "2025-06-03T18:50:34.560925Z",
     "iopub.status.busy": "2025-06-03T18:50:34.560763Z",
     "iopub.status.idle": "2025-06-03T18:50:35.016290Z",
     "shell.execute_reply": "2025-06-03T18:50:35.015931Z",
     "shell.execute_reply.started": "2025-06-03T18:50:34.560912Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "bluejay_mix_t2 requests 128741 clips 257482 total khrs 11.045; N gpus for 1000 iters 16.093; 4 gpus for x iters 4023.156; n unique users 43058 n pro users 40242\n"
     ]
    }
   ],
   "source": [
    "df_slice = df[df[\"request_id\"].isin(set(unique_requests))].copy()\n",
    "print(\n",
    "    f\"{os.path.basename(OUT_DATA_DIR)} requests\",\n",
    "    df_slice[\"request_id\"].nunique(),\n",
    "    \"clips\",\n",
    "    df_slice.shape[0],\n",
    "    f\"total khrs {sum(df_slice['duration'] / 3600 / 1000):.3f};\",\n",
    "    f\"N gpus for 1000 iters {df_slice.shape[0] / 8 / 2 / 1000:.3f};\",\n",
    "    f\"4 gpus for x iters {df_slice.shape[0] / 8 / 2 / 4:.3f};\",\n",
    "    f\"n unique users {df_slice['user_id'].nunique()}\",\n",
    "    f\"n pro users {df_slice[df_slice['is_pro_user']]['user_id'].nunique()}\",\n",
    ")\n",
    "# 76171 152342 total khrs 2.880 n gpus for 1250 iters 3.809\n",
    "# v10 has 78866\n",
    "# v14 has 110402\n",
    "# 30b_t4_v12 requests 47755 clips 95510 total khrs 4.555; N gpus for 1000 iters 5.969; 4 gpus for x iters 1492.344; n unique users 13790 n pro users 13526\n",
    "# 30b_t4_v20 requests 18306 clips 36612 total khrs 1.754; N gpus for 1000 iters 2.288; 4 gpus for x iters 572.062; n unique users 6943 n pro users 6714\n",
    "# 30b_t5_v5 requests 21318 clips 42636 total khrs 1.938; N gpus for 1000 iters 2.665; 4 gpus for x iters 666.188; n unique users 11661 n pro users 9347\n",
    "# 30b_t5_v6 requests 22833 clips 45666 total khrs 2.072; N gpus for 1000 iters 2.854; 4 gpus for x iters 713.531; n unique users 12576 n pro users 9910\n",
    "# 30b_t5_v7 requests 33197 clips 66394 total khrs 2.846; N gpus for 1000 iters 4.150; 4 gpus for x iters 1037.406; n unique users 16665 n pro users 13050\n",
    "# 30b_t5_v8 requests 20907 clips 41814 total khrs 1.629; N gpus for 1000 iters 2.613; 4 gpus for x iters 653.344; n unique users 11102 n pro users 9052\n",
    "# 30b_t5_v9 requests 24645 clips 49290 total khrs 1.918; N gpus for 1000 iters 3.081; 4 gpus for x iters 770.156; n unique users 12661 n pro users 10229\n",
    "# 30b_t5_v11 requests 21975 clips 43950 total khrs 1.508; N gpus for 1000 iters 2.747; 4 gpus for x iters 686.719; n unique users 11173 n pro users 9270\n",
    "# 30b_t5_v12 requests 21436 clips 42872 total khrs 1.582; N gpus for 1000 iters 2.679; 4 gpus for x iters 669.875; n unique users 11553 n pro users 9374\n",
    "# 30b_t5_v13 requests 25912 clips 51824 total khrs 1.922; N gpus for 1000 iters 3.239; 4 gpus for x iters 809.750; n unique users 13429 n pro users 10737\n",
    "# 30b_t5_v14 requests 27687 clips 55374 total khrs 2.036; N gpus for 1000 iters 3.461; 4 gpus for x iters 865.219; n unique users 14196 n pro users 11227\n",
    "# 30b_t5_v15 requests 29563 clips 59126 total khrs 2.225; N gpus for 1000 iters 3.695; 4 gpus for x iters 923.844; n unique users 14684 n pro users 11642\n",
    "# 30b_t6_v1 requests 24678 clips 49356 total khrs 1.934; N gpus for 1000 iters 3.085; 4 gpus for x iters 771.188; n unique users 11350 n pro users 10065\n",
    "# 30b_t6_v2 requests 49341 clips 98682 total khrs 4.332; N gpus for 1000 iters 6.168; 4 gpus for x iters 1541.906; n unique users 19992 n pro users 16972\n",
    "# 30b_t6_v3 requests 54967 clips 109934 total khrs 4.826; N gpus for 1000 iters 6.871; 4 gpus for x iters 1717.719; n unique users 21653 n pro users 18266\n",
    "# 30b_t6_v5 requests 29459 clips 58918 total khrs 2.657; N gpus for 1000 iters 3.682; 4 gpus for x iters 920.594; n unique users 14091 n pro users 11884\n",
    "# 30b_t6_v7 requests 40056 clips 80112 total khrs 3.354; N gpus for 1000 iters 5.007; 4 gpus for x iters 1251.750; n unique users 17440 n pro users 14476\n",
    "# 30b_t6_v8 requests 31681 clips 63362 total khrs 2.681; N gpus for 1000 iters 3.960; 4 gpus for x iters 990.031; n unique users 15180 n pro users 15078\n",
    "# 30b_t6_v9 requests 55785 clips 111570 total khrs 4.727; N gpus for 1000 iters 6.973; 4 gpus for x iters 1743.281; n unique users 23114 n pro users 22871\n",
    "# 30b_t6_v10 requests 52209 clips 104418 total khrs 4.515; N gpus for 1000 iters 6.526; 4 gpus for x iters 1631.531; n unique users 22216 n pro users 21893\n",
    "# 30b_t6_v11 requests 31338 clips 62676 total khrs 2.493; N gpus for 1000 iters 3.917; 4 gpus for x iters 979.312; n unique users 15190 n pro users 14973\n",
    "# 30b_t6_v13 requests 50856 clips 101712 total khrs 3.987; N gpus for 1000 iters 6.357; 4 gpus for x iters 1589.250; n unique users 23547 n pro users 23097\n",
    "# 30b_t6_v15 requests 65213 clips 130426 total khrs 5.217; N gpus for 1000 iters 8.152; 4 gpus for x iters 2037.906; n unique users 28763 n pro users 27964\n",
    "# 30b_t6_v16 requests 37907 clips 75814 total khrs 2.956; N gpus for 1000 iters 4.738; 4 gpus for x iters 1184.594; n unique users 18448 n pro users 17212\n",
    "# 30b_t6_v17 requests 51543 clips 103086 total khrs 4.154; N gpus for 1000 iters 6.443; 4 gpus for x iters 1610.719; n unique users 24223 n pro users 21829\n",
    "# 30b_t6_v18 requests 94965 clips 189930 total khrs 7.483; N gpus for 1000 iters 11.871; 4 gpus for x iters 2967.656; n unique users 23852 n pro users 21767\n",
    "# 30b_t6_v19 requests 34289 clips 68578 total khrs 2.846; N gpus for 1000 iters 4.286; 4 gpus for x iters 1071.531; n unique users 11802 n pro users 10830\n",
    "# 30b_t6_v20 requests 53258 clips 106516 total khrs 4.270; N gpus for 1000 iters 6.657; 4 gpus for x iters 1664.312; n unique users 22096 n pro users 21171\n",
    "# 30b_t6_v22 requests 29971 clips 59942 total khrs 1.992; N gpus for 1000 iters 3.746; 4 gpus for x iters 936.594; n unique users 13611 n pro users 13036\n",
    "# 30b_t6_v24 requests 45333 clips 90666 total khrs 3.343; N gpus for 1000 iters 5.667; 4 gpus for x iters 1416.656; n unique users 18853 n pro users 18049\n",
    "# 30b_t6_v25 requests 28154 clips 56308 total khrs 2.401; N gpus for 1000 iters 3.519; 4 gpus for x iters 879.812; n unique users 12946 n pro users 12361\n",
    "# 30b_t6_v26 requests 30428 clips 60856 total khrs 2.599; N gpus for 1000 iters 3.804; 4 gpus for x iters 950.875; n unique users 13822 n pro users 13163\n",
    "# 30b_t6_v27 requests 43731 clips 87462 total khrs 3.862; N gpus for 1000 iters 5.466; 4 gpus for x iters 1366.594; n unique users 17898 n pro users 16865\n",
    "# 30b_t6_v28 requests 56869 clips 113738 total khrs 5.064; N gpus for 1000 iters 7.109; 4 gpus for x iters 1777.156; n unique users 22004 n pro users 20244\n",
    "# 30b_t6_v29 requests 32729 clips 65458 total khrs 2.604; N gpus for 1000 iters 4.091; 4 gpus for x iters 1022.781; n unique users 13739 n pro users 13503\n",
    "# 30b_t6_v30 requests 32553 clips 65106 total khrs 2.592; N gpus for 1000 iters 4.069; 4 gpus for x iters 1017.281; n unique users 13712 n pro users 13478\n",
    "# 30b_t6_v31 requests 41523 clips 83046 total khrs 3.164; N gpus for 1000 iters 5.190; 4 gpus for x iters 1297.594; n unique users 16266 n pro users 15967\n",
    "# 30b_t6_v32 requests 55942 clips 111884 total khrs 4.361; N gpus for 1000 iters 6.993; 4 gpus for x iters 1748.188; n unique users 20808 n pro users 20271\n",
    "# 30b_t6_v33 requests 182096 clips 364192 total khrs 13.745; N gpus for 1000 iters 22.762; 4 gpus for x iters 5690.500; n unique users 40437 n pro users 34524\n",
    "# auk_mix_t1_v2 requests 102002 clips 204004 total khrs 9.191; N gpus for 1000 iters 12.750; 4 gpus for x iters 3187.562; n unique users 36408 n pro users 34038\n",
    "# auk_mix_t1_v13 requests 53011 clips 106022 total khrs 4.496; N gpus for 1000 iters 6.626; 4 gpus for x iters 1656.594; n unique users 23713 n pro users 23117\n",
    "# auk_mix_t1_v14 requests 63272 clips 126544 total khrs 5.382; N gpus for 1000 iters 7.909; 4 gpus for x iters 1977.250; n unique users 26926 n pro users 26111"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-05-16T13:59:41.277006Z",
     "start_time": "2024-05-16T13:59:41.252105Z"
    },
    "execution": {
     "iopub.execute_input": "2025-06-03T18:50:35.016936Z",
     "iopub.status.busy": "2025-06-03T18:50:35.016692Z",
     "iopub.status.idle": "2025-06-03T18:50:35.067301Z",
     "shell.execute_reply": "2025-06-03T18:50:35.066966Z",
     "shell.execute_reply.started": "2025-06-03T18:50:35.016922Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "positive in playlist (29458, 164)\n",
      "task\n",
      "cover                 108844\n",
      "artist_consistency    107186\n",
      "infill                 41446\n",
      "                           6\n",
      "Name: count, dtype: int64\n"
     ]
    }
   ],
   "source": [
    "test_mask = (df_slice[\"preference\"]) & (\n",
    "    (df_slice[\"is_in_playlist\"]) | (df_slice[\"concat_in_playlist\"])\n",
    ")\n",
    "print(\"positive in playlist\", df_slice[test_mask].shape)\n",
    "print(df_slice[\"task\"].value_counts())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {
    "execution": {
     "iopub.execute_input": "2025-06-03T18:50:35.067867Z",
     "iopub.status.busy": "2025-06-03T18:50:35.067676Z",
     "iopub.status.idle": "2025-06-03T18:50:35.201249Z",
     "shell.execute_reply": "2025-06-03T18:50:35.200924Z",
     "shell.execute_reply.started": "2025-06-03T18:50:35.067854Z"
    }
   },
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAjAAAAGdCAYAAAAMm0nCAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjkuMiwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8hTgPZAAAACXBIWXMAAA9hAAAPYQGoP6dpAAAqfUlEQVR4nO3df3AUdZ7/8dd0fpCE/CAkIHKgcsQE1ghJ1IqJw/LdPVnuRK8KuFuow1UsStgVhLJQ4DgUgmwSULaQ1Vs45JCfx3IL6KpwW3qnHhYguEU2h4tI5HaNl/XyAzAhgfya/v7BpWFCfszAZGY+yfNRldLp+Uz3p9/pJC+6P/1pl23btgAAAAxihboDAAAA/iLAAAAA4xBgAACAcQgwAADAOAQYAABgHAIMAAAwDgEGAAAYhwADAACMQ4ABAADGIcAAAADjRIa6Az2tpqZOwXxYgsslpaQkBH27pqFOvqFOvqFO3aNGvqFOvunJ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oOxHT+uuTh05deqUpKt/ePtCnTri8XjU1NQUlscSl5AC5IknntDixYuVmZmpMWPGaOvWrbp06ZKmTJkS6q6FzOrVq/W9731PQ4cOVWVlpX7+85/Lsiw9/PDDSkhI0NSpU1VcXKykpCTFx8dr1apVys7O7vUBpr6+Xl999ZXz+uuvv9apU6eUlJSkoUOH6rHHHtMvfvEL3X777Ro2bJheeeUVDR48WA8++KCkKwPnxo0bp+eff14FBQVqbm7Wiy++qEmTJumWW24J1W4FXFd1SkpK0quvvqqJEycqNTVV5eXleumll3T77bdr3LhxkvpGnQoKCvTOO+/oH//xH9W/f39nnEFCQoJiYmJ8+jlzu91KS0vTokWL9Nxzz6mqqkrr1q3TjBkzFB0dHcK9C5zu6vTVV1/p7bff1vjx4zVgwACdPn1aRUVFuu+++zRq1ChJfaNOa9eu1Xe/+13deuutqq+v1zvvvKNjx45p8+bNYXks8TTqANqxY4c2b96sqqoqjR49WsuWLXNOQ/ZFzzzzjI4fP64LFy5o4MCBuueee/TMM88415MbGxtVXFysd999V01NTXK73Vq+fHmvOh3bkU8++USPPfbYdcsnT56s4uJi2bat9evXa8+ePaqtrdU999yj5cuXa8SIEU7bCxcu6MUXX9R//Md/yLIs/eAHP9CyZcvUv3//YO5Kj+qqTitWrNDcuXP1+9//XnV1dRo8eLAeeOABLViwwOuybW+vU0ZGRofLi4qKnH88+fJz9j//8z9asWKFjh07ptjYWE2ePFkLFy5UZGTv+Ddud3X605/+pOeee05nzpxRQ0ODbr31Vj344IN66qmnFB8f77Tv7XVaunSpjh49qsrKSiUkJCgjI0NPPvmkHnjgAUnhdywRYAAAgHEYAwMAAIxDgAEAAMYhwAAAAOMQYAAAgHEIMAAAwDgEGAAAYBwCDAAAMA4BBgAAGIcAAwAAjEOAAQAAxiHAAAAA4xBgAACAcf4/8N4OmPbxC+MAAAAASUVORK5CYII=",
      "text/plain": [
       "<Figure size 640x480 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "df_slice[\"post_infill_duration\"].hist(bins=np.linspace(-5, 300, 100))\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-05-16T13:59:41.323409Z",
     "start_time": "2024-05-16T13:59:41.278278Z"
    },
    "execution": {
     "iopub.execute_input": "2025-06-03T18:50:35.201815Z",
     "iopub.status.busy": "2025-06-03T18:50:35.201622Z",
     "iopub.status.idle": "2025-06-03T18:50:35.215331Z",
     "shell.execute_reply": "2025-06-03T18:50:35.215061Z",
     "shell.execute_reply.started": "2025-06-03T18:50:35.201801Z"
    }
   },
   "outputs": [],
   "source": [
    "# interesting_clips_must_be_positive_mask = (\n",
    "#     (df_slice[\"upvoted\"] == True)\n",
    "#     | (df_slice[\"has_action\"] == True)\n",
    "#     | (df_slice[\"part_of_concat\"] == True)\n",
    "# )\n",
    "# interesting_clips_must_be_not_negative_mask = (df_slice[\"downvoted\"] == False) # & (df_slice[\"dislike_count\"] < 1)\n",
    "# interesting_clips_mask = interesting_clips_must_be_positive_mask & interesting_clips_must_be_not_negative_mask\n",
    "# assert interesting_clips_mask.eq(df_slice[\"preference\"]).all()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-05-16T13:59:41.392244Z",
     "start_time": "2024-05-16T13:59:41.324472Z"
    },
    "execution": {
     "iopub.execute_input": "2025-06-03T18:50:35.215816Z",
     "iopub.status.busy": "2025-06-03T18:50:35.215644Z",
     "iopub.status.idle": "2025-06-03T18:50:35.225703Z",
     "shell.execute_reply": "2025-06-03T18:50:35.225448Z",
     "shell.execute_reply.started": "2025-06-03T18:50:35.215805Z"
    }
   },
   "outputs": [],
   "source": [
    "# save positive ids\n",
    "# positive_preference_ids = df_slice[df_slice[\"preference\"] == False][\"s3_id\"].to_json(orient='values')\n",
    "# with open('/home/tony/Data/Preference/7b_v2/7v_v20_full_recut_id_negative.json', 'w') as file:\n",
    "#     file.write(positive_preference_ids)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {
    "execution": {
     "iopub.execute_input": "2025-06-03T18:50:35.226170Z",
     "iopub.status.busy": "2025-06-03T18:50:35.226004Z",
     "iopub.status.idle": "2025-06-03T18:50:35.235969Z",
     "shell.execute_reply": "2025-06-03T18:50:35.235713Z",
     "shell.execute_reply.started": "2025-06-03T18:50:35.226159Z"
    }
   },
   "outputs": [],
   "source": [
    "# df_slice_2 = pd.read_pickle(\"/home/tony/Data/Preference/30b_v6/interesting_clips_v4_t_6_20241118_full_slice.pkl\")\n",
    "# df_total = pd.concat([df_slice, df_slice_2])\n",
    "# print(df_total.shape)\n",
    "# df_slice = df_total"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {
    "execution": {
     "iopub.execute_input": "2025-06-03T18:50:35.236465Z",
     "iopub.status.busy": "2025-06-03T18:50:35.236269Z",
     "iopub.status.idle": "2025-06-03T18:50:35.246348Z",
     "shell.execute_reply": "2025-06-03T18:50:35.246094Z",
     "shell.execute_reply.started": "2025-06-03T18:50:35.236454Z"
    }
   },
   "outputs": [],
   "source": [
    "# df_slice_prev = pd.read_pickle(\n",
    "#     \"/home/tony/Data/Preference/30b_v2/interesting_clips_v4_t_3_v13_20240902_slice.pkl\"\n",
    "# )\n",
    "# df_slice_prev = df_slice_prev[\n",
    "#     (\n",
    "#         (df_slice_prev[\"task\"] != \"infill\")\n",
    "#         & (df_slice_prev[\"task\"] != \"cover\")\n",
    "#         & (df_slice_prev[\"task\"] != \"artist_consistency\")\n",
    "#     )\n",
    "# ].copy()\n",
    "# df_slice = pd.concat([df_slice, df_slice_prev])\n",
    "# print(df_slice.shape)\n",
    "# print(df_slice[\"task\"].value_counts())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {
    "execution": {
     "iopub.execute_input": "2025-06-03T18:50:35.246835Z",
     "iopub.status.busy": "2025-06-03T18:50:35.246651Z",
     "iopub.status.idle": "2025-06-03T18:50:35.256718Z",
     "shell.execute_reply": "2025-06-03T18:50:35.256463Z",
     "shell.execute_reply.started": "2025-06-03T18:50:35.246823Z"
    }
   },
   "outputs": [],
   "source": [
    "# df_slice[(df_slice[\"preference\"]) & ((df_slice[\"task\"].str.strip() == \"\") | (df_slice[\"task\"].str.strip() == \"cover\"))].to_pickle(\n",
    "#     \"/home/tony/Data/Preference/30b_v5/interesting_clips_v4_t_5_20241018_full_with_cer_pos_gen.pkl\"\n",
    "# )\n",
    "# df_slice[(df_slice[\"preference\"]) & ((df_slice[\"task\"].str.strip() == \"\") | (df_slice[\"task\"].str.strip() == \"cover\"))].shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "metadata": {
    "execution": {
     "iopub.execute_input": "2025-06-03T18:50:35.257162Z",
     "iopub.status.busy": "2025-06-03T18:50:35.257016Z",
     "iopub.status.idle": "2025-06-03T18:50:35.267032Z",
     "shell.execute_reply": "2025-06-03T18:50:35.266774Z",
     "shell.execute_reply.started": "2025-06-03T18:50:35.257151Z"
    }
   },
   "outputs": [],
   "source": [
    "# df_slice.to_pickle(\"/home/tony/Data/Preference/30b_v6/interesting_clips_v4_h_t_6_20250108_full_slice.pkl\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "metadata": {
    "execution": {
     "iopub.execute_input": "2025-06-03T18:50:35.267490Z",
     "iopub.status.busy": "2025-06-03T18:50:35.267325Z",
     "iopub.status.idle": "2025-06-03T18:50:35.277243Z",
     "shell.execute_reply": "2025-06-03T18:50:35.276985Z",
     "shell.execute_reply.started": "2025-06-03T18:50:35.267479Z"
    }
   },
   "outputs": [],
   "source": [
    "# with open(\"/home/tony/Data/Preference/30b_v6/similarities_30b_t6.json\", \"r\") as fp:\n",
    "#     all_similarities = json.load(fp)\n",
    "\n",
    "# df_slice[\"similarity\"] = df_slice[\"id\"].map(all_similarities)\n",
    "# df_cover = df_slice[df_slice[\"task\"] == \"cover\"].copy()\n",
    "# df_artist = df_slice[df_slice[\"task\"] == \"artist_consistency\"].copy()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "metadata": {
    "execution": {
     "iopub.execute_input": "2025-06-03T18:50:35.277739Z",
     "iopub.status.busy": "2025-06-03T18:50:35.277546Z",
     "iopub.status.idle": "2025-06-03T18:50:35.287627Z",
     "shell.execute_reply": "2025-06-03T18:50:35.287374Z",
     "shell.execute_reply.started": "2025-06-03T18:50:35.277728Z"
    }
   },
   "outputs": [],
   "source": [
    "# df_cover[df_cover[\"preference\"]][\"similarity\"].hist(bins=200, label=\"positive\", alpha=0.5)\n",
    "# df_cover[~df_cover[\"preference\"]][\"similarity\"].hist(bins=200, label=\"negative\", alpha=0.5)\n",
    "# plt.legend()\n",
    "# plt.show()\n",
    "# df_cover[\"similarity_diff\"] = df_cover[\"similarity\"].diff()\n",
    "# df_cover[df_cover[\"preference\"]][\"similarity_diff\"].hist(bins=200)\n",
    "# plt.show()\n",
    "# df_cover[\"continued_parent\"] = None\n",
    "# df_cover[\"continue_at\"] = -1\n",
    "# too_similar = (df_cover[\"similarity\"] >= 0.99)\n",
    "# too_different = ( df_cover[\"similarity\"] < 0.25)\n",
    "# too_big_difference = (df_cover[\"similarity_diff\"] < -0.2)\n",
    "# df_cover_drops_id = df_cover[\n",
    "#     (df_cover[\"preference\"])\n",
    "#     & (too_similar | too_different | too_big_difference)\n",
    "# ][\"s3_id\"].unique()\n",
    "# print(\"total rows\", df_cover.shape[0], \"total drops\", len(df_cover_drops_id))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "metadata": {
    "execution": {
     "iopub.execute_input": "2025-06-03T18:50:35.288082Z",
     "iopub.status.busy": "2025-06-03T18:50:35.287920Z",
     "iopub.status.idle": "2025-06-03T18:50:35.298005Z",
     "shell.execute_reply": "2025-06-03T18:50:35.297748Z",
     "shell.execute_reply.started": "2025-06-03T18:50:35.288071Z"
    }
   },
   "outputs": [],
   "source": [
    "# df_artist[df_artist[\"preference\"]][\"similarity\"].hist(bins=200, label=\"positive\", alpha=0.5)\n",
    "# df_artist[~df_artist[\"preference\"]][\"similarity\"].hist(bins=200, label=\"negative\", alpha=0.5)\n",
    "# plt.legend()\n",
    "# plt.show()\n",
    "# df_artist[\"similarity_diff\"] = df_artist[\"similarity\"].diff()\n",
    "# df_artist[df_artist[\"preference\"]][\"similarity_diff\"].hist(bins=200)\n",
    "# plt.show()\n",
    "# too_similar = (df_artist[\"similarity\"] >= 0.95)\n",
    "# too_different = ( df_artist[\"similarity\"] < 0.4)\n",
    "# too_big_difference = (df_artist[\"similarity_diff\"] < -0.2)\n",
    "# df_artist_drops_id = df_artist[\n",
    "#     (df_artist[\"preference\"])\n",
    "#     & (too_similar | too_different | too_big_difference)\n",
    "# ][\"s3_id\"].unique()\n",
    "# print(\"total rows\", df_artist.shape[0], \"total drops\", len(df_artist_drops_id))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "metadata": {
    "execution": {
     "iopub.execute_input": "2025-06-03T18:50:35.298447Z",
     "iopub.status.busy": "2025-06-03T18:50:35.298301Z",
     "iopub.status.idle": "2025-06-03T18:50:35.308335Z",
     "shell.execute_reply": "2025-06-03T18:50:35.308084Z",
     "shell.execute_reply.started": "2025-06-03T18:50:35.298436Z"
    }
   },
   "outputs": [],
   "source": [
    "# print(\"before filter on cover similarity\", df_slice.shape)\n",
    "# df_slice = df_slice[~df_slice[\"s3_id\"].isin(df_cover_drops_id)].copy()\n",
    "# print(\"after filter on cover similarity\", df_slice.shape)\n",
    "# df_slice = df_slice[~df_slice[\"s3_id\"].isin(df_artist_drops_id)].copy()\n",
    "# print(\"after filter on artist similarity\", df_slice.shape)\n",
    "# df_slice = df_slice[\n",
    "#     df_slice[\"request_id\"].isin(\n",
    "#         df_slice[\"request_id\"].value_counts().index[df_slice[\"request_id\"].value_counts() == 2]\n",
    "#     )\n",
    "# ]\n",
    "# print(\"after filter on request id pairs\", df_slice.shape)\n",
    "# print(df_slice.groupby([\"preference\"])[\"model_name\"].value_counts())\n",
    "# assert df_slice.shape[0] == df_slice[\"request_id\"].nunique() * 2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "metadata": {
    "execution": {
     "iopub.execute_input": "2025-06-03T18:50:35.308788Z",
     "iopub.status.busy": "2025-06-03T18:50:35.308627Z",
     "iopub.status.idle": "2025-06-03T18:50:35.319960Z",
     "shell.execute_reply": "2025-06-03T18:50:35.319700Z",
     "shell.execute_reply.started": "2025-06-03T18:50:35.308777Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "is_public\n",
      "False    247127\n",
      "True      10355\n",
      "Name: count, dtype: int64\n"
     ]
    }
   ],
   "source": [
    "print(df_slice[\"is_public\"].value_counts())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "metadata": {
    "execution": {
     "iopub.execute_input": "2025-06-03T18:50:35.320436Z",
     "iopub.status.busy": "2025-06-03T18:50:35.320253Z",
     "iopub.status.idle": "2025-06-03T18:50:35.352175Z",
     "shell.execute_reply": "2025-06-03T18:50:35.351860Z",
     "shell.execute_reply.started": "2025-06-03T18:50:35.320425Z"
    }
   },
   "outputs": [],
   "source": [
    "df_slice[\"npz_path\"] = df_slice[\"s3_id\"].map(lambda x: f\"{NPZ_DIR}/{x}.npz\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-05-16T14:00:20.866354Z",
     "start_time": "2024-05-16T14:00:12.443344Z"
    },
    "execution": {
     "iopub.execute_input": "2025-06-03T18:50:35.352703Z",
     "iopub.status.busy": "2025-06-03T18:50:35.352523Z",
     "iopub.status.idle": "2025-06-03T18:50:35.997156Z",
     "shell.execute_reply": "2025-06-03T18:50:35.995850Z",
     "shell.execute_reply.started": "2025-06-03T18:50:35.352691Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(216030, 165)\n",
      "task\n",
      "cover                 108844\n",
      "artist_consistency    107186\n",
      "Name: count, dtype: int64\n",
      "(216030, 165)\n",
      "task\n",
      "cover                 108844\n",
      "artist_consistency    107186\n",
      "Name: count, dtype: int64\n"
     ]
    },
    {
     "ename": "NameError",
     "evalue": "name 'BREAK' is not defined",
     "output_type": "error",
     "traceback": [
      "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[0;31mNameError\u001b[0m                                 Traceback (most recent call last)",
      "Cell \u001b[0;32mIn[37], line 9\u001b[0m\n\u001b[1;32m      7\u001b[0m \u001b[38;5;28mprint\u001b[39m(df_slice\u001b[38;5;241m.\u001b[39mshape)\n\u001b[1;32m      8\u001b[0m \u001b[38;5;28mprint\u001b[39m(df_slice[\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mtask\u001b[39m\u001b[38;5;124m\"\u001b[39m]\u001b[38;5;241m.\u001b[39mvalue_counts())\n\u001b[0;32m----> 9\u001b[0m \u001b[43mBREAK\u001b[49m\n",
      "\u001b[0;31mNameError\u001b[0m: name 'BREAK' is not defined"
     ]
    }
   ],
   "source": [
    "# df_slice.to_pickle(\n",
    "#     \"/home/tony/Data/Preference/30b_v6/interesting_clips_v4_h_t_6_20250501_full_long_bluejay_r3.pkl\"\n",
    "# )\n",
    "print(df_slice.shape)\n",
    "print(df_slice[\"task\"].value_counts())\n",
    "df_slice = df_slice[df_slice[\"task\"].isin([\"cover\", \"artist_consistency\"])].copy()\n",
    "print(df_slice.shape)\n",
    "print(df_slice[\"task\"].value_counts())\n",
    "BREAK"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "execution": {
     "iopub.execute_input": "2025-07-01T10:37:34.609866Z",
     "iopub.status.busy": "2025-07-01T10:37:34.609514Z",
     "iopub.status.idle": "2025-07-01T10:37:48.166055Z",
     "shell.execute_reply": "2025-07-01T10:37:48.165489Z",
     "shell.execute_reply.started": "2025-07-01T10:37:34.609848Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(416048, 170)\n",
      "task\n",
      "                 397920\n",
      "upload_extend     10130\n",
      "extend             7998\n",
      "Name: count, dtype: int64\n"
     ]
    }
   ],
   "source": [
    "df_13b_slice = pd.read_pickle(\n",
    "    \"/home/tony/Data/Preference/13b_v32/interesting_clips_v4_h_s_32_20250501_full_long_bluejay_r3.pkl\"\n",
    ")\n",
    "print(df_13b_slice.shape)\n",
    "print(df_13b_slice[\"task\"].value_counts())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "execution": {
     "iopub.execute_input": "2025-07-01T10:37:48.167037Z",
     "iopub.status.busy": "2025-07-01T10:37:48.166882Z",
     "iopub.status.idle": "2025-07-01T10:37:55.671166Z",
     "shell.execute_reply": "2025-07-01T10:37:55.670593Z",
     "shell.execute_reply.started": "2025-07-01T10:37:48.167021Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(216030, 165)\n",
      "task\n",
      "cover                 108844\n",
      "artist_consistency    107186\n",
      "Name: count, dtype: int64\n"
     ]
    }
   ],
   "source": [
    "df_30b_slice = pd.read_pickle(\n",
    "    \"/home/tony/Data/Preference/30b_v6/interesting_clips_v4_h_t_6_20250501_full_long_bluejay_r3.pkl\"\n",
    ")\n",
    "print(df_30b_slice.shape)\n",
    "print(df_30b_slice[\"task\"].value_counts())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {
    "execution": {
     "iopub.execute_input": "2025-07-01T10:37:55.671877Z",
     "iopub.status.busy": "2025-07-01T10:37:55.671723Z",
     "iopub.status.idle": "2025-07-01T10:38:01.557402Z",
     "shell.execute_reply": "2025-07-01T10:38:01.556850Z",
     "shell.execute_reply.started": "2025-07-01T10:37:55.671861Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(632078, 176)\n",
      "task\n",
      "                      397920\n",
      "cover                 108844\n",
      "artist_consistency    107186\n",
      "upload_extend          10130\n",
      "extend                  7998\n",
      "Name: count, dtype: int64\n"
     ]
    }
   ],
   "source": [
    "df_total = pd.concat([df_13b_slice, df_30b_slice])\n",
    "print(df_total.shape)\n",
    "print(df_total[\"task\"].value_counts())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {
    "execution": {
     "iopub.execute_input": "2025-07-01T10:38:01.558457Z",
     "iopub.status.busy": "2025-07-01T10:38:01.558299Z",
     "iopub.status.idle": "2025-07-01T10:38:03.739193Z",
     "shell.execute_reply": "2025-07-01T10:38:03.738626Z",
     "shell.execute_reply.started": "2025-07-01T10:38:01.558442Z"
    }
   },
   "outputs": [],
   "source": [
    "df_slice = df_total.copy()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Need to kick out the ones has gpt prompt -- these are pairs with different text inputs"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-05-16T13:59:41.932296Z",
     "start_time": "2024-05-16T13:59:41.932287Z"
    },
    "execution": {
     "iopub.execute_input": "2025-07-01T10:38:20.135747Z",
     "iopub.status.busy": "2025-07-01T10:38:20.135375Z",
     "iopub.status.idle": "2025-07-01T10:38:20.166608Z",
     "shell.execute_reply": "2025-07-01T10:38:20.166068Z",
     "shell.execute_reply.started": "2025-07-01T10:38:20.135728Z"
    }
   },
   "outputs": [],
   "source": [
    "# don't have continue at\n",
    "df_slice[\"request_id\"] = df_slice[\"request_id\"].astype(str)\n",
    "# df_slice[\"npz_path\"] = df_slice[\"npz_path\"].apply(lambda x: str(x).replace(\"_npz\", \"_npz/\"))\n",
    "# df_slice[df_slice[\"continue_at\"].isna()][\"request_id\"].nunique(), df_slice[\"request_id\"].nunique()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {
    "execution": {
     "iopub.execute_input": "2025-07-01T10:38:20.167556Z",
     "iopub.status.busy": "2025-07-01T10:38:20.167405Z",
     "iopub.status.idle": "2025-07-01T10:38:22.299994Z",
     "shell.execute_reply": "2025-07-01T10:38:22.299428Z",
     "shell.execute_reply.started": "2025-07-01T10:38:20.167541Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(632078, 176)\n",
      "(632078, 176)\n",
      "(632078, 176)\n"
     ]
    }
   ],
   "source": [
    "print(df_slice.shape)\n",
    "df_slice = df_slice[df_slice[\"request_id\"].apply(lambda x: len(x) > 3)]\n",
    "print(df_slice.shape)\n",
    "# df_slice = df_slice[df_slice[\"is_pro_user\"]].copy()\n",
    "print(df_slice.shape)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-05-16T13:59:41.932966Z",
     "start_time": "2024-05-16T13:59:41.932957Z"
    },
    "execution": {
     "iopub.execute_input": "2025-07-01T10:38:22.300713Z",
     "iopub.status.busy": "2025-07-01T10:38:22.300564Z",
     "iopub.status.idle": "2025-07-01T10:38:22.380196Z",
     "shell.execute_reply": "2025-07-01T10:38:22.379652Z",
     "shell.execute_reply.started": "2025-07-01T10:38:22.300698Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "316039\n"
     ]
    }
   ],
   "source": [
    "final_filtered_requests = df_slice[\"request_id\"].astype(str).unique()\n",
    "# final_filtered_requests = df_slice[df_slice[\"is_pro_user\"]][\"request_id\"].astype(str).unique()\n",
    "print(len(final_filtered_requests))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-05-16T13:59:41.933558Z",
     "start_time": "2024-05-16T13:59:41.933550Z"
    },
    "execution": {
     "iopub.execute_input": "2025-07-01T10:38:22.381355Z",
     "iopub.status.busy": "2025-07-01T10:38:22.381198Z",
     "iopub.status.idle": "2025-07-01T10:38:22.395471Z",
     "shell.execute_reply": "2025-07-01T10:38:22.395032Z",
     "shell.execute_reply.started": "2025-07-01T10:38:22.381339Z"
    }
   },
   "outputs": [],
   "source": [
    "# df_slice.to_csv(\"/home/tony/Data/Preference/30b_v2/interesting_clips_v4_t_3_20240902_slice.csv\", index=False)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {
    "execution": {
     "iopub.execute_input": "2025-07-01T10:38:22.396088Z",
     "iopub.status.busy": "2025-07-01T10:38:22.395951Z",
     "iopub.status.idle": "2025-07-01T10:38:22.408254Z",
     "shell.execute_reply": "2025-07-01T10:38:22.407837Z",
     "shell.execute_reply.started": "2025-07-01T10:38:22.396073Z"
    }
   },
   "outputs": [],
   "source": [
    "# df_slice[\"continue_at\"] = -1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-05-16T13:59:41.934277Z",
     "start_time": "2024-05-16T13:59:41.934268Z"
    },
    "execution": {
     "iopub.execute_input": "2025-07-01T10:38:22.408856Z",
     "iopub.status.busy": "2025-07-01T10:38:22.408719Z",
     "iopub.status.idle": "2025-07-01T10:38:25.880269Z",
     "shell.execute_reply": "2025-07-01T10:38:25.879694Z",
     "shell.execute_reply.started": "2025-07-01T10:38:22.408843Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "312878 3161\n",
      "(625756, 176) (6322, 176)\n"
     ]
    }
   ],
   "source": [
    "train_requests, val_requests = train_test_split(\n",
    "    sorted(list(final_filtered_requests)), test_size=0.01, random_state=42\n",
    ")\n",
    "print(len(train_requests), len(val_requests))\n",
    "\n",
    "train_df = df_slice[df_slice[\"request_id\"].astype(str).isin(set(train_requests))].copy()\n",
    "val_df = df_slice[df_slice[\"request_id\"].astype(str).isin(set(val_requests))].copy()\n",
    "train_df = train_df.sort_values(by=[\"request_id\", \"preference\"])\n",
    "train_df = train_df  # .reset_index()\n",
    "val_df = val_df.sort_values(by=[\"request_id\", \"preference\"])\n",
    "val_df = val_df  # .reset_index()\n",
    "train_df = train_df.reset_index(drop=True)\n",
    "val_df = val_df.reset_index(drop=True)\n",
    "print(train_df.shape, val_df.shape)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Actually make"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-05-16T13:59:41.935620Z",
     "start_time": "2024-05-16T13:59:41.935613Z"
    },
    "execution": {
     "iopub.execute_input": "2025-07-01T10:38:59.831874Z",
     "iopub.status.busy": "2025-07-01T10:38:59.831326Z",
     "iopub.status.idle": "2025-07-01T10:39:23.376029Z",
     "shell.execute_reply": "2025-07-01T10:39:23.375450Z",
     "shell.execute_reply.started": "2025-07-01T10:38:59.831857Z"
    }
   },
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "100%|██████████████████████████████████████████████████████████████████████████████████████████████████████| 625756/625756 [00:23<00:00, 26597.29it/s]"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "32,260 hours of 625756 clips, 39.10975 nodes, 611.08984375 iters\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "\n"
     ]
    }
   ],
   "source": [
    "total_duration = 0\n",
    "for i, row in tqdm(train_df.iterrows(), total=len(train_df)):\n",
    "    # we need to alternate between preference: neg, pos\n",
    "    # print(i, row)\n",
    "    try:\n",
    "        assert row[\"preference\"] == (i % 2 == 1)\n",
    "        total_duration += row[\"duration\"]\n",
    "    except Exception as E:\n",
    "        print(i, row)\n",
    "        print(E)\n",
    "        raise ValueError()\n",
    "\n",
    "print(\n",
    "    f\"{round(total_duration / 60 / 60):,} hours of {train_df.shape[0]} clips, {train_df.shape[0] / 8 / 2 / 1000} nodes, {train_df.shape[0] / 8 / 8 / 16} iters\"\n",
    ")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-05-16T13:59:41.936268Z",
     "start_time": "2024-05-16T13:59:41.936260Z"
    },
    "execution": {
     "iopub.execute_input": "2025-07-01T10:39:23.377017Z",
     "iopub.status.busy": "2025-07-01T10:39:23.376856Z",
     "iopub.status.idle": "2025-07-01T10:41:07.522804Z",
     "shell.execute_reply": "2025-07-01T10:41:07.522246Z",
     "shell.execute_reply.started": "2025-07-01T10:39:23.377001Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "t_data_memmap is set to: 6016\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      " 35%|█████████████████████████████████████▉                                                                       | 2199/6322 [00:37<01:00, 68.15it/s]"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "weird, /app/suno/data/dpo/30b_npz/c1150a74-6d63-43b1-b3e5-41d74a4b3c63.npz, with only v3.0\n",
      "2187, 'artist_arr is not a file in the archive', artist_consistency, /app/suno/data/dpo/30b_npz/c1150a74-6d63-43b1-b3e5-41d74a4b3c63.npz.\n",
      "WTF --> 2187, 'artist_arr is not a file in the archive', artist_consistency, /app/suno/data/dpo/30b_npz/c1150a74-6d63-43b1-b3e5-41d74a4b3c63.npz.\n",
      "WTF --> 2188, skip, preference: False, 5378d8d5-d336-4934-8fc0-899f1b6bf8e0, task: .\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "100%|█████████████████████████████████████████████████████████████████████████████████████████████████████████████| 6322/6322 [01:44<00:00, 60.75it/s]"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Total 6320 clips, 2 different prompts\n",
      "184 hours of False\n",
      "182 hours of True\n",
      "gen: 213.5 hours\n",
      "artist_consistency: 67.6 hours\n",
      "extend: 10.6 hours\n",
      "cover: 73.8 hours\n",
      "🚨 Error artist_consistency: 1\n",
      "Done\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "\n"
     ]
    }
   ],
   "source": [
    "make_dataset(\n",
    "    val_df, OUT_DATA_DIR, is_val=True, npz_dir=NPZ_DIR, t_data_memmap=N_TOKENS_AUDIO\n",
    ")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {
    "execution": {
     "iopub.execute_input": "2025-07-01T10:41:07.523494Z",
     "iopub.status.busy": "2025-07-01T10:41:07.523339Z",
     "iopub.status.idle": "2025-07-01T10:41:07.545927Z",
     "shell.execute_reply": "2025-07-01T10:41:07.545479Z",
     "shell.execute_reply.started": "2025-07-01T10:41:07.523478Z"
    }
   },
   "outputs": [],
   "source": [
    "# test_npz = np.load(\"/app/suno/data/dpo/30b_npz/26d19085-18da-4701-af43-122684543891.npz\")\n",
    "# for k in test_npz.keys():\n",
    "#     print(k)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-05-16T13:59:41.936964Z",
     "start_time": "2024-05-16T13:59:41.936957Z"
    },
    "execution": {
     "iopub.execute_input": "2025-07-01T10:41:07.547008Z",
     "iopub.status.busy": "2025-07-01T10:41:07.546859Z",
     "iopub.status.idle": "2025-07-01T13:28:21.636494Z",
     "shell.execute_reply": "2025-07-01T13:28:21.635834Z",
     "shell.execute_reply.started": "2025-07-01T10:41:07.546993Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "t_data_memmap is set to: 6016\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "  6%|██████                                                                                                  | 36586/625756 [09:57<2:31:30, 64.81it/s]"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "36574, 'history_arr is not a file in the archive', upload_extend, /app/suno/data/dpo/13b_s32_npz/c8ad50dc-58c3-470f-a094-676e03f25de9.npz.\n",
      "WTF --> 36575, skip, preference: True, 10754475-08f0-4951-b71a-c2fe0991c409, task: upload_extend.\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "  9%|████████▉                                                                                               | 53601/625756 [14:37<2:23:09, 66.61it/s]"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "53588, 'history_arr is not a file in the archive', upload_extend, /app/suno/data/dpo/13b_s32_npz/316ec332-9b2b-4be4-a3e8-66b26fa3beff.npz.\n",
      "WTF --> 53589, skip, preference: True, f02d5e0c-5083-4375-a989-6d9a7420e0f9, task: upload_extend.\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      " 34%|███████████████████████████████████                                                                    | 212921/625756 [57:52<1:42:04, 67.41it/s]"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "weird, /app/suno/data/dpo/30b_npz/025128d0-1ef2-497b-a7aa-b77645e04131.npz, with only v3.0\n",
      "212909, 'cover_arr is not a file in the archive', cover, /app/suno/data/dpo/30b_npz/025128d0-1ef2-497b-a7aa-b77645e04131.npz.\n",
      "WTF --> 212909, 'cover_arr is not a file in the archive', cover, /app/suno/data/dpo/30b_npz/025128d0-1ef2-497b-a7aa-b77645e04131.npz.\n",
      "WTF --> 212910, skip, preference: False, 54ca21bd-79e1-4753-8224-4d78828d80ba, task: .\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      " 40%|████████████████████████████████████████▋                                                            | 251737/625756 [1:08:16<1:30:53, 68.58it/s]"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "251728, 'history_arr is not a file in the archive', upload_extend, /app/suno/data/dpo/13b_s32_npz/6148bda0-531b-4f9d-b12c-7a276545e872.npz.\n",
      "WTF --> 251729, skip, preference: True, 1cfdccd1-d576-484c-bf18-bfeb7c1a2370, task: upload_extend.\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      " 54%|██████████████████████████████████████████████████████▎                                              | 336642/625756 [1:31:05<1:11:07, 67.75it/s]"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "336630, 'history_arr is not a file in the archive', upload_extend, /app/suno/data/dpo/13b_s32_npz/cc918963-4a41-4bf1-b846-c9a140d1951b.npz.\n",
      "WTF --> 336631, skip, preference: True, 409fc6b6-73a1-4884-b80f-6d34ee88ccd1, task: upload_extend.\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      " 61%|█████████████████████████████████████████████████████████████▉                                       | 384038/625756 [1:43:58<1:01:14, 65.77it/s]"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "384024, 'history_arr is not a file in the archive', upload_extend, /app/suno/data/dpo/13b_s32_npz/cf0c29c4-267e-4aa3-a3f8-009876019300.npz.\n",
      "WTF --> 384025, skip, preference: True, 3cb56754-6b0a-4492-9bce-299dff540fe1, task: upload_extend.\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      " 70%|███████████████████████████████████████████████████████████████████████▉                               | 437344/625756 [1:58:01<46:32, 67.46it/s]"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "437330, 'history_arr is not a file in the archive', upload_extend, /app/suno/data/dpo/13b_s32_npz/a538ccbe-a313-4acf-99c7-317806e9d062.npz.\n",
      "WTF --> 437331, skip, preference: True, 83054a12-5b17-42f2-b702-7d025c5e3fe9, task: upload_extend.\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      " 70%|████████████████████████████████████████████████████████████████████████▎                              | 439568/625756 [1:58:36<49:26, 62.77it/s]IOPub message rate exceeded.\n",
      "The Jupyter server will temporarily stop sending output\n",
      "to the client in order to avoid crashing it.\n",
      "To change this limit, set the config variable\n",
      "`--ServerApp.iopub_msg_rate_limit`.\n",
      "\n",
      "Current values:\n",
      "ServerApp.iopub_msg_rate_limit=1000.0 (msgs/sec)\n",
      "ServerApp.rate_limit_window=3.0 (secs)\n",
      "\n",
      " 94%|████████████████████████████████████████████████████████████████████████████████████████████████▉      | 589004/625756 [2:37:37<08:46, 69.84it/s]"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "588992, 'history_arr is not a file in the archive', upload_extend, /app/suno/data/dpo/13b_s32_npz/1d6fb316-3320-409f-b8a6-189d385b69e6.npz.\n",
      "WTF --> 588993, skip, preference: True, b33d9b6e-9ab7-4392-8807-fd66ef850551, task: upload_extend.\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "100%|███████████████████████████████████████████████████████████████████████████████████████████████████████| 625756/625756 [2:47:13<00:00, 62.37it/s]\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Total 625736 clips, 68 different prompts\n",
      "18,158 hours of False\n",
      "17,909 hours of True\n",
      "artist_consistency: 7040.2 hours\n",
      "extend: 1013.3 hours\n",
      "gen: 21103.9 hours\n",
      "cover: 6910.1 hours\n",
      "🚨 Error upload_extend: 9\n",
      "🚨 Error cover: 1\n",
      "Done\n"
     ]
    }
   ],
   "source": [
    "make_dataset(\n",
    "    train_df, OUT_DATA_DIR, is_val=False, npz_dir=NPZ_DIR, t_data_memmap=N_TOKENS_AUDIO\n",
    ")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-01-29T19:46:47.549860Z",
     "start_time": "2024-01-29T19:46:47.548015Z"
    }
   },
   "source": [
    "# Validation"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-05-16T13:59:41.937879Z",
     "start_time": "2024-05-16T13:59:41.937870Z"
    },
    "execution": {
     "iopub.execute_input": "2025-07-01T13:28:21.637312Z",
     "iopub.status.busy": "2025-07-01T13:28:21.637142Z",
     "iopub.status.idle": "2025-07-01T13:28:22.618209Z",
     "shell.execute_reply": "2025-07-01T13:28:22.617648Z",
     "shell.execute_reply.started": "2025-07-01T13:28:21.637295Z"
    }
   },
   "outputs": [],
   "source": [
    "# verify\n",
    "mm = np.memmap(os.path.join(OUT_DATA_DIR, f\"data_val.bin\"), dtype=np.uint16, mode=\"r\")\n",
    "test_metas = read_jsonl(os.path.join(OUT_DATA_DIR, f\"meta_val.jsonl\"))\n",
    "test_info = read_json(os.path.join(OUT_DATA_DIR, f\"info_val.json\"))\n",
    "mm = mm.reshape(-1, N_TOKENS_AUDIO, 13)\n",
    "assert len(mm) == len(test_metas)\n",
    "assert mm[:100, :, 0].min() >= 0\n",
    "assert mm[:100, :, 0].max() <= 4000\n",
    "assert mm[:100, :, 1:].min() >= 0\n",
    "assert mm[:100, :, 1:].max() <= 2048"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {
    "execution": {
     "iopub.execute_input": "2025-07-01T13:28:22.618972Z",
     "iopub.status.busy": "2025-07-01T13:28:22.618815Z",
     "iopub.status.idle": "2025-07-01T13:28:22.638117Z",
     "shell.execute_reply": "2025-07-01T13:28:22.637639Z",
     "shell.execute_reply.started": "2025-07-01T13:28:22.618956Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Counter({None: 3971, 'cover': 1144, 'artist_consistency': 1019, 'extend': 186})\n"
     ]
    }
   ],
   "source": [
    "task_counts = Counter()\n",
    "for test_meta in test_metas:\n",
    "    task_counts[test_meta.get(\"task\")] += 1\n",
    "print(task_counts)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-05-16T13:59:41.938629Z",
     "start_time": "2024-05-16T13:59:41.938621Z"
    },
    "execution": {
     "iopub.execute_input": "2025-07-01T13:28:22.638763Z",
     "iopub.status.busy": "2025-07-01T13:28:22.638622Z",
     "iopub.status.idle": "2025-07-01T13:28:22.651631Z",
     "shell.execute_reply": "2025-07-01T13:28:22.651200Z",
     "shell.execute_reply.started": "2025-07-01T13:28:22.638748Z"
    }
   },
   "outputs": [],
   "source": [
    "# # randomly listen to some stuff\n",
    "# from suno_utils.tasks.dac_2c_12cb import preload_models as preload_codec_models\n",
    "# from suno_utils.tasks.dac_2c_12cb import (\n",
    "#     encode as codec_encode,\n",
    "#     decode_stream_to_full_audio as codec_decode,\n",
    "#     EMBEDDING_RATE as CODEC_EMBEDDING_RATE,\n",
    "#     decode as decode\n",
    "# )\n",
    "# os.environ[\"CUDA_VISIBLE_DEVICES\"] = \"0\"\n",
    "# _ = preload_codec_models(\"/app/suno/data/dpo/models/dac_2c_25x12.pt\", device=\"cuda\")\n",
    "# assert len(test_metas) == len(mm)\n",
    "# idx_list = list(range(len(test_metas)))\n",
    "# # random.shuffle(idx_list)\n",
    "# # idx_list = [idx for idx in idx_list if \"text\" in test_metas[idx]]\n",
    "# print(len(mm))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-05-16T13:59:41.939205Z",
     "start_time": "2024-05-16T13:59:41.939198Z"
    },
    "execution": {
     "iopub.execute_input": "2025-07-01T13:28:22.652234Z",
     "iopub.status.busy": "2025-07-01T13:28:22.652099Z",
     "iopub.status.idle": "2025-07-01T13:28:22.663795Z",
     "shell.execute_reply": "2025-07-01T13:28:22.663365Z",
     "shell.execute_reply.started": "2025-07-01T13:28:22.652220Z"
    }
   },
   "outputs": [],
   "source": [
    "# import random\n",
    "# idx = random.choice(test_info[\"perference_0\"][\"idx_list\"])\n",
    "# assert \"original_duration_s\" in test_metas[idx]\n",
    "# # positive index should be shifted by 1\n",
    "# pos_idx = idx + 1\n",
    "# print(\n",
    "#     \"tags:\",\n",
    "#     test_metas[idx].get(\"tags\") == test_metas[pos_idx].get(\"tags\"),\n",
    "#     test_metas[idx].get(\"tags\"),\n",
    "# )\n",
    "# arr = mm[idx, 1:].copy().astype(np.int16)[:, 1:]\n",
    "# pos_arr = mm[pos_idx, 1:].copy().astype(np.int16)[:, 1:]\n",
    "# pad_idx_arr = np.where(arr == COARSE_PAD_TOKEN)[0]\n",
    "# if len(pad_idx_arr) > 0:\n",
    "#     arr = arr[: pad_idx_arr[0], :]\n",
    "# pos_pad_idx_arr = np.where(pos_arr == COARSE_PAD_TOKEN)[0]\n",
    "# if len(pos_pad_idx_arr) > 0:\n",
    "#     pos_arr = pos_arr[: pos_pad_idx_arr[0], :]\n",
    "# a = decode(arr)\n",
    "# print(\"\\n negative example \\n\", test_metas[idx])\n",
    "# a.play(compress=False)\n",
    "# pos_a = decode(pos_arr)\n",
    "# print(\"\\n positive example \\n\", test_metas[pos_idx])\n",
    "# pos_a.play(compress=False)\n",
    "# print(\n",
    "#     \"text:\",\n",
    "#     test_metas[idx].get(\"text\") == test_metas[pos_idx].get(\"text\"),\n",
    "#     test_metas[idx].get(\"text\"),\n",
    "# )"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-05-16T13:59:41.939977Z",
     "start_time": "2024-05-16T13:59:41.939969Z"
    },
    "execution": {
     "iopub.execute_input": "2025-07-01T13:28:22.664410Z",
     "iopub.status.busy": "2025-07-01T13:28:22.664273Z",
     "iopub.status.idle": "2025-07-01T13:28:22.675586Z",
     "shell.execute_reply": "2025-07-01T13:28:22.675163Z",
     "shell.execute_reply.started": "2025-07-01T13:28:22.664395Z"
    }
   },
   "outputs": [],
   "source": [
    "# val_df[val_df[\"tags\"] == 'a vibrant blend of experimental jazz fusion, drum-and-bass and swagger fuzzed-out guitars']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-05-16T13:59:41.940610Z",
     "start_time": "2024-05-16T13:59:41.940603Z"
    },
    "execution": {
     "iopub.execute_input": "2025-07-01T13:28:22.677333Z",
     "iopub.status.busy": "2025-07-01T13:28:22.677182Z",
     "iopub.status.idle": "2025-07-01T13:28:22.688353Z",
     "shell.execute_reply": "2025-07-01T13:28:22.687939Z",
     "shell.execute_reply.started": "2025-07-01T13:28:22.677319Z"
    }
   },
   "outputs": [],
   "source": [
    "# from collections import Counter\n",
    "# c = Counter()\n",
    "# for _, row in df_slice.iterrows():\n",
    "#     # print(row[\"metadata\"])\n",
    "#     for k in ast.literal_eval(row[\"metadata\"]).keys():\n",
    "#         c[k] += 1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-05-16T13:59:41.941167Z",
     "start_time": "2024-05-16T13:59:41.941159Z"
    },
    "execution": {
     "iopub.execute_input": "2025-07-01T13:28:22.691407Z",
     "iopub.status.busy": "2025-07-01T13:28:22.691286Z",
     "iopub.status.idle": "2025-07-01T13:28:22.702279Z",
     "shell.execute_reply": "2025-07-01T13:28:22.701863Z",
     "shell.execute_reply.started": "2025-07-01T13:28:22.691395Z"
    }
   },
   "outputs": [],
   "source": [
    "# original_npz_path = f\"/app/suno/data/dpo/7b_npz/{test_metas[idx]['id']}.npz\"\n",
    "# original_npz_path = \"/app/suno/data/dpo/7b_npz/729c3011-f672-4ccd-8d82-1cbf2b52ff69.npz\"\n",
    "# original_arr = np.load(original_npz_path)[\"v2_raw\"]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-05-16T13:59:41.941801Z",
     "start_time": "2024-05-16T13:59:41.941793Z"
    },
    "execution": {
     "iopub.execute_input": "2025-07-01T13:28:22.702879Z",
     "iopub.status.busy": "2025-07-01T13:28:22.702739Z",
     "iopub.status.idle": "2025-07-01T13:28:22.717618Z",
     "shell.execute_reply": "2025-07-01T13:28:22.717167Z",
     "shell.execute_reply.started": "2025-07-01T13:28:22.702865Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "3159 1\n"
     ]
    }
   ],
   "source": [
    "def validation_on_metas(input_metas):\n",
    "    total_bad = 0\n",
    "    total_good = 0\n",
    "    for idx in range(len(input_metas)):\n",
    "        if idx % 2 == 0:\n",
    "            pos_idx = idx + 1\n",
    "            if input_metas[idx].get(\"tags\") != input_metas[pos_idx].get(\"tags\"):\n",
    "                # print(test_metas[idx].get(\"text\") == test_metas[pos_idx].get(\"text\"), test_metas[idx].get(\"tags\"), test_metas[pos_idx].get(\"tags\"))\n",
    "                total_bad += 1\n",
    "            else:\n",
    "                total_good += 1\n",
    "    print(total_good, total_bad)\n",
    "    return\n",
    "\n",
    "\n",
    "validation_on_metas(test_metas)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-05-16T13:59:41.942520Z",
     "start_time": "2024-05-16T13:59:41.942511Z"
    },
    "execution": {
     "iopub.execute_input": "2025-07-01T13:28:22.718427Z",
     "iopub.status.busy": "2025-07-01T13:28:22.718288Z",
     "iopub.status.idle": "2025-07-01T13:28:22.777412Z",
     "shell.execute_reply": "2025-07-01T13:28:22.776974Z",
     "shell.execute_reply.started": "2025-07-01T13:28:22.718414Z"
    }
   },
   "outputs": [],
   "source": [
    "train_info = read_json(os.path.join(OUT_DATA_DIR, f\"info_tr.json\"))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-05-16T13:59:41.943072Z",
     "start_time": "2024-05-16T13:59:41.943065Z"
    },
    "execution": {
     "iopub.execute_input": "2025-07-01T13:28:22.778019Z",
     "iopub.status.busy": "2025-07-01T13:28:22.777883Z",
     "iopub.status.idle": "2025-07-01T13:28:22.811546Z",
     "shell.execute_reply": "2025-07-01T13:28:22.811107Z",
     "shell.execute_reply.started": "2025-07-01T13:28:22.778005Z"
    }
   },
   "outputs": [],
   "source": [
    "n_neg_tr = train_info[\"perference_0\"][\"idx_list\"]\n",
    "n_pos_tr = train_info[\"perference_1\"][\"idx_list\"]\n",
    "assert len(n_pos_tr) == len(n_neg_tr)\n",
    "# make sure they are offset by 1 and exactly 1\n",
    "for i, j in zip(n_neg_tr, n_pos_tr):\n",
    "    assert i == j - 1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-05-16T13:59:41.944246Z",
     "start_time": "2024-05-16T13:59:41.944237Z"
    },
    "execution": {
     "iopub.execute_input": "2025-07-01T13:28:22.812141Z",
     "iopub.status.busy": "2025-07-01T13:28:22.812001Z",
     "iopub.status.idle": "2025-07-01T13:28:22.823749Z",
     "shell.execute_reply": "2025-07-01T13:28:22.823304Z",
     "shell.execute_reply.started": "2025-07-01T13:28:22.812127Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "total samples 625736 (625756, 176)\n"
     ]
    }
   ],
   "source": [
    "total_iters = len(n_neg_tr) + len(n_pos_tr)\n",
    "print(\"total samples\", total_iters, train_df.shape)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-05-16T13:59:41.945249Z",
     "start_time": "2024-05-16T13:59:41.945241Z"
    },
    "execution": {
     "iopub.execute_input": "2025-07-01T13:28:22.824350Z",
     "iopub.status.busy": "2025-07-01T13:28:22.824216Z",
     "iopub.status.idle": "2025-07-01T13:28:22.836058Z",
     "shell.execute_reply": "2025-07-01T13:28:22.835605Z",
     "shell.execute_reply.started": "2025-07-01T13:28:22.824336Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1 epoch per batch 4, total 9777.125\n"
     ]
    }
   ],
   "source": [
    "print(\"1 epoch per batch 4, total\", total_iters / 8 / 2 / 4)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 45,
   "metadata": {
    "execution": {
     "iopub.execute_input": "2025-07-05T13:46:24.373733Z",
     "iopub.status.busy": "2025-07-05T13:46:24.373430Z",
     "iopub.status.idle": "2025-07-05T14:46:24.494909Z",
     "shell.execute_reply": "2025-07-05T14:46:24.494340Z",
     "shell.execute_reply.started": "2025-07-05T13:46:24.373715Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Here\n"
     ]
    }
   ],
   "source": [
    "import time\n",
    "print(\"Here\")\n",
    "time.sleep(3600 * 1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 46,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-05-16T13:59:41.945972Z",
     "start_time": "2024-05-16T13:59:41.945964Z"
    },
    "execution": {
     "iopub.execute_input": "2025-07-05T14:46:24.495882Z",
     "iopub.status.busy": "2025-07-05T14:46:24.495727Z",
     "iopub.status.idle": "2025-07-05T14:46:25.821421Z",
     "shell.execute_reply": "2025-07-05T14:46:25.820781Z",
     "shell.execute_reply.started": "2025-07-05T14:46:24.495867Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Submitted batch job 7318\n"
     ]
    }
   ],
   "source": [
    "!cd /home/tony/Work/tony/slurm/bluejay && sbatch sbatch_ipo_bluejay"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "metadata": {
    "execution": {
     "iopub.execute_input": "2025-07-01T13:28:22.851661Z",
     "iopub.status.busy": "2025-07-01T13:28:22.851525Z",
     "iopub.status.idle": "2025-07-01T13:28:22.873063Z",
     "shell.execute_reply": "2025-07-01T13:28:22.872616Z",
     "shell.execute_reply.started": "2025-07-01T13:28:22.851647Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Cache kept!\n"
     ]
    }
   ],
   "source": [
    "import shutil\n",
    "\n",
    "# Basic file copy\n",
    "shutil.copy(\n",
    "    \"/home/tony/Work/tony/Preference/make_dataset_bluejay_r3_13b_30b_preauk.ipynb\",\n",
    "    os.path.join(OUT_DATA_DIR, \"make_dataset.ipynb\"),\n",
    ")\n",
    "print(\"Cache kept!\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# some gymathtics loading prev data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-05-16T13:59:41.946562Z",
     "start_time": "2024-05-16T13:59:41.946555Z"
    },
    "execution": {
     "iopub.execute_input": "2025-07-01T13:28:22.873683Z",
     "iopub.status.busy": "2025-07-01T13:28:22.873543Z",
     "iopub.status.idle": "2025-07-01T13:28:22.884768Z",
     "shell.execute_reply": "2025-07-01T13:28:22.884338Z",
     "shell.execute_reply.started": "2025-07-01T13:28:22.873669Z"
    }
   },
   "outputs": [],
   "source": [
    "# prev_v3_data = \"/app/suno/data/dpo/7v_v20_full/\"\n",
    "\n",
    "# test_val_metas = read_jsonl(os.path.join(prev_v3_data, f\"meta_val.jsonl\"))\n",
    "# test_tr_metas = read_jsonl(os.path.join(prev_v3_data, f\"meta_tr.jsonl\"))\n",
    "\n",
    "# all_ids = set()\n",
    "# for meta in test_val_metas:\n",
    "#     all_ids.add(meta[\"id\"])\n",
    "# for meta in test_tr_metas:\n",
    "#     all_ids.add(meta[\"id\"])\n",
    "# print(len(all_ids), len(test_val_metas) + len(test_tr_metas))\n",
    "\n",
    "# all_ids = list(all_ids)\n",
    "# with open(\"/home/tony/Data/Preference/7b_v2/7v_v20_full_recut_id.json\", \"w\") as fp:\n",
    "#     json.dump(all_ids, fp)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "metadata": {
    "execution": {
     "iopub.execute_input": "2025-07-01T13:28:22.885516Z",
     "iopub.status.busy": "2025-07-01T13:28:22.885380Z",
     "iopub.status.idle": "2025-07-01T13:28:22.896790Z",
     "shell.execute_reply": "2025-07-01T13:28:22.896365Z",
     "shell.execute_reply.started": "2025-07-01T13:28:22.885503Z"
    }
   },
   "outputs": [],
   "source": [
    "# x_data = train_df[train_df[\"preference\"]][\"similarity\"]\n",
    "# y_data = train_df[~train_df[\"preference\"]][\"similarity\"]\n",
    "# from matplotlib.colors import LogNorm\n",
    "\n",
    "# fig, (ax1, ax2) = plt.subplots(1, 2, figsize=(24, 10))\n",
    "\n",
    "# # 2D Histogram\n",
    "# h = ax1.hist2d(\n",
    "#     x_data,\n",
    "#     y_data,\n",
    "#     bins=(50, 50),\n",
    "#     cmap=\"coolwarm\",\n",
    "#     range=[[0, 1], [0, 1]],\n",
    "#     norm=LogNorm(),\n",
    "# )\n",
    "\n",
    "# ax1.set_xlabel(\"Semantic Distance (Preferred)\")\n",
    "# ax1.set_ylabel(\"Semantic Distance (Non-Preferred)\")\n",
    "# ax1.set_title(\n",
    "#     \"2D Histogram of Semantic Distances: Preferred vs Non-Preferred (Log Scale)\"\n",
    "# )\n",
    "\n",
    "# cbar1 = plt.colorbar(h[3], ax=ax1)\n",
    "# cbar1.set_label(\"Number of Request IDs (Log Scale)\")\n",
    "\n",
    "# # Scatter plot\n",
    "# ax2.scatter(x_data, y_data, alpha=0.1, s=1)\n",
    "# ax2.set_xlabel(\"Semantic Distance (Preferred)\")\n",
    "# ax2.set_ylabel(\"Semantic Distance (Non-Preferred)\")\n",
    "# ax2.set_title(\"Scatter Plot of Semantic Distances: Preferred vs Non-Preferred\")\n",
    "# ax2.set_xlim(0, 1)\n",
    "# ax2.set_ylim(0, 1)\n",
    "\n",
    "# plt.tight_layout()\n",
    "# plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "metadata": {
    "execution": {
     "iopub.execute_input": "2025-07-01T13:28:22.897364Z",
     "iopub.status.busy": "2025-07-01T13:28:22.897233Z",
     "iopub.status.idle": "2025-07-01T13:28:22.908309Z",
     "shell.execute_reply": "2025-07-01T13:28:22.907889Z",
     "shell.execute_reply.started": "2025-07-01T13:28:22.897350Z"
    }
   },
   "outputs": [],
   "source": [
    "# train_metas = read_jsonl(os.path.join(OUT_DATA_DIR, f\"meta_tr.jsonl\"))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "metadata": {
    "execution": {
     "iopub.execute_input": "2025-07-01T13:28:22.908909Z",
     "iopub.status.busy": "2025-07-01T13:28:22.908775Z",
     "iopub.status.idle": "2025-07-01T13:28:22.922258Z",
     "shell.execute_reply": "2025-07-01T13:28:22.921848Z",
     "shell.execute_reply.started": "2025-07-01T13:28:22.908896Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "dict_keys(['perference_0', 'perference_1'])"
      ]
     },
     "execution_count": 37,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "train_info.keys()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "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.10.15"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
