{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "execution": {
     "iopub.execute_input": "2025-06-03T18:01:39.943375Z",
     "iopub.status.busy": "2025-06-03T18:01:39.943112Z",
     "iopub.status.idle": "2025-06-03T18:01:39.954936Z",
     "shell.execute_reply": "2025-06-03T18:01:39.954600Z",
     "shell.execute_reply.started": "2025-06-03T18:01:39.943359Z"
    }
   },
   "outputs": [],
   "source": [
    "# setup autoload\n",
    "%load_ext autoreload\n",
    "%autoreload 2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-05-16T13:58:21.040680Z",
     "start_time": "2024-05-16T13:58:19.777010Z"
    },
    "execution": {
     "iopub.execute_input": "2025-06-03T18:01:39.956523Z",
     "iopub.status.busy": "2025-06-03T18:01:39.956328Z",
     "iopub.status.idle": "2025-06-03T18:01:42.175119Z",
     "shell.execute_reply": "2025-06-03T18:01:42.174671Z",
     "shell.execute_reply.started": "2025-06-03T18:01:39.956511Z"
    }
   },
   "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",
    "\n",
    "sys.path.append(\"/home/tony/Work/tony/Preference\")\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-06-03T18:01:42.176906Z",
     "iopub.status.busy": "2025-06-03T18:01:42.176702Z",
     "iopub.status.idle": "2025-06-03T18:01:42.244863Z",
     "shell.execute_reply": "2025-06-03T18:01:42.244421Z",
     "shell.execute_reply.started": "2025-06-03T18:01:42.176893Z"
    }
   },
   "outputs": [],
   "source": [
    "OUT_DATA_DIR = \"/app/suno/data/dpo/auk_mix_t1_v6\"\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:01:42.246330Z",
     "iopub.status.busy": "2025-06-03T18:01:42.246228Z",
     "iopub.status.idle": "2025-06-03T18:02:09.757603Z",
     "shell.execute_reply": "2025-06-03T18:02:09.757104Z",
     "shell.execute_reply.started": "2025-06-03T18:01:42.246319Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Preference data shape (1063314, 90)\n"
     ]
    }
   ],
   "source": [
    "df = pd.read_pickle(\n",
    "    \"/home/tony/Data/Preference/30b_v6/interesting_clips_v4_h_t_6_20250411_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:02:09.759354Z",
     "iopub.status.busy": "2025-06-03T18:02:09.759143Z",
     "iopub.status.idle": "2025-06-03T18:02:11.084415Z",
     "shell.execute_reply": "2025-06-03T18:02:11.083934Z",
     "shell.execute_reply.started": "2025-06-03T18:02:09.759340Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "after dropna (1063314, 85)\n"
     ]
    }
   ],
   "source": [
    "df = df.dropna(axis=1, how=\"all\")\n",
    "print(\"after dropna\", df.shape)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "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:02:11.085102Z",
     "iopub.status.busy": "2025-06-03T18:02:11.084923Z",
     "iopub.status.idle": "2025-06-03T18:08:02.705226Z",
     "shell.execute_reply": "2025-06-03T18:08:02.704729Z",
     "shell.execute_reply.started": "2025-06-03T18:02:11.085088Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "6442462\n",
      "6442462\n",
      "pre-downloaded df (1063314, 85)\n",
      "downloaded df (1063314, 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": 7,
   "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:08:02.705963Z",
     "iopub.status.busy": "2025-06-03T18:08:02.705731Z",
     "iopub.status.idle": "2025-06-03T18:08:02.994671Z",
     "shell.execute_reply": "2025-06-03T18:08:02.994257Z",
     "shell.execute_reply.started": "2025-06-03T18:08:02.705949Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "is_30b\n",
      "True    1063314\n",
      "Name: count, dtype: int64\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "task\n",
       "cover                 555186\n",
       "artist_consistency    465022\n",
       "infill                 43090\n",
       "                          10\n",
       "artist_cover               6\n",
       "Name: count, dtype: int64"
      ]
     },
     "execution_count": 7,
     "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": 8,
   "metadata": {
    "execution": {
     "iopub.execute_input": "2025-06-03T18:08:02.995334Z",
     "iopub.status.busy": "2025-06-03T18:08:02.995162Z",
     "iopub.status.idle": "2025-06-03T18:08:03.009014Z",
     "shell.execute_reply": "2025-06-03T18:08:03.008655Z",
     "shell.execute_reply.started": "2025-06-03T18:08:02.995322Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(1063314, 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": 9,
   "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:08:03.009646Z",
     "iopub.status.busy": "2025-06-03T18:08:03.009435Z",
     "iopub.status.idle": "2025-06-03T18:08:03.309926Z",
     "shell.execute_reply": "2025-06-03T18:08:03.309449Z",
     "shell.execute_reply.started": "2025-06-03T18:08:03.009633Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "preference  model_name    \n",
      "False       chirp-v4-h-t-6    531657\n",
      "True        chirp-v4-h-t-6    531657\n",
      "Name: count, dtype: int64\n",
      "before filter on model name (1063314, 86)\n",
      "after filter on model name (1063314, 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": 10,
   "metadata": {
    "execution": {
     "iopub.execute_input": "2025-06-03T18:08:03.310604Z",
     "iopub.status.busy": "2025-06-03T18:08:03.310433Z",
     "iopub.status.idle": "2025-06-03T18:08:03.327935Z",
     "shell.execute_reply": "2025-06-03T18:08:03.327572Z",
     "shell.execute_reply.started": "2025-06-03T18:08:03.310591Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "is_public\n",
      "False    1034392\n",
      "True       28922\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": 11,
   "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:08:03.328466Z",
     "iopub.status.busy": "2025-06-03T18:08:03.328356Z",
     "iopub.status.idle": "2025-06-03T18:08:04.462762Z",
     "shell.execute_reply": "2025-06-03T18:08:04.462250Z",
     "shell.execute_reply.started": "2025-06-03T18:08:03.328456Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "before filter on request id pairs (1063314, 86)\n",
      "after filter on request id pairs (1063314, 86)\n",
      "preference  model_name    \n",
      "False       chirp-v4-h-t-6    531657\n",
      "True        chirp-v4-h-t-6    531657\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": 12,
   "metadata": {
    "execution": {
     "iopub.execute_input": "2025-06-03T18:08:04.463476Z",
     "iopub.status.busy": "2025-06-03T18:08:04.463283Z",
     "iopub.status.idle": "2025-06-03T18:10:22.985317Z",
     "shell.execute_reply": "2025-06-03T18:10:22.984814Z",
     "shell.execute_reply.started": "2025-06-03T18:08:04.463462Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "unique_requests 531657\n",
      "before removing duplicates (1063314, 159)\n",
      "after removing duplicates (1063314, 152)\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": 13,
   "metadata": {
    "execution": {
     "iopub.execute_input": "2025-06-03T18:10:22.985998Z",
     "iopub.status.busy": "2025-06-03T18:10:22.985819Z",
     "iopub.status.idle": "2025-06-03T18:10:23.824437Z",
     "shell.execute_reply": "2025-06-03T18:10:23.824018Z",
     "shell.execute_reply.started": "2025-06-03T18:10:22.985984Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "task\n",
       "cover                 555186\n",
       "artist_consistency    465022\n",
       "infill                 43090\n",
       "                          10\n",
       "artist_cover               6\n",
       "Name: count, dtype: int64"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df[\"task\"].value_counts()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {
    "execution": {
     "iopub.execute_input": "2025-06-03T18:10:23.825119Z",
     "iopub.status.busy": "2025-06-03T18:10:23.824926Z",
     "iopub.status.idle": "2025-06-03T18:10:25.450414Z",
     "shell.execute_reply": "2025-06-03T18:10:25.449990Z",
     "shell.execute_reply.started": "2025-06-03T18:10:23.825105Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "pos_diff_preference\n",
       "1.0    365487\n",
       "2.0    166170\n",
       "Name: count, dtype: int64"
      ]
     },
     "execution_count": 14,
     "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": 15,
   "metadata": {
    "execution": {
     "iopub.execute_input": "2025-06-03T18:10:25.451078Z",
     "iopub.status.busy": "2025-06-03T18:10:25.450905Z",
     "iopub.status.idle": "2025-06-03T18:10:25.984488Z",
     "shell.execute_reply": "2025-06-03T18:10:25.984002Z",
     "shell.execute_reply.started": "2025-06-03T18:10:25.451065Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "positive param_experiment\n",
      "min_p_0001    16919\n",
      "min_p_002     15970\n",
      "text_1        13273\n",
      "temp_s_80     13141\n",
      "temp_s_70     12382\n",
      "step_12        8452\n",
      "text_3         8135\n",
      "step_8         8025\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": 16,
   "metadata": {
    "execution": {
     "iopub.execute_input": "2025-06-03T18:10:25.985194Z",
     "iopub.status.busy": "2025-06-03T18:10:25.985015Z",
     "iopub.status.idle": "2025-06-03T18:11:03.817706Z",
     "shell.execute_reply": "2025-06-03T18:11:03.817197Z",
     "shell.execute_reply.started": "2025-06-03T18:10:25.985180Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Found 89692 duplicated prompts 44847 unique requests\n",
      "Found 21934 request_ids with duplicate prompts but not highest play counts in their group\n",
      "['31f6cf77-5db4-466d-a6f5-c455dcdab4d7', '5ad6125e-1eac-48a5-ae59-716454c0225d', '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', '0b3c3723-51a7-43ea-9f36-a7cd229c52b3', 'a5ff1bec-31e3-4454-9489-819b63900441', '4dd11a3d-190a-41e6-afe1-6456bd5a81d9']\n",
      "Before dedup user gen requests 1063314\n",
      "After dedup user gen requests 1019446\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": 17,
   "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:11:03.818406Z",
     "iopub.status.busy": "2025-06-03T18:11:03.818221Z",
     "iopub.status.idle": "2025-06-03T18:11:07.581161Z",
     "shell.execute_reply": "2025-06-03T18:11:07.580686Z",
     "shell.execute_reply.started": "2025-06-03T18:11:03.818392Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "19362\n",
      "good_continue_at\n",
      "True    1019446\n",
      "Name: count, dtype: int64\n",
      "\n",
      " Check some basics... \n",
      " preference\n",
      "False    509723\n",
      "True     509723\n",
      "Name: count, dtype: int64 is_30b\n",
      "True    1019446\n",
      "Name: count, dtype: int64 model_name\n",
      "chirp-v4-h-t-6    1019446\n",
      "Name: count, dtype: int64 preference  model_name    \n",
      "False       chirp-v4-h-t-6    509723\n",
      "True        chirp-v4-h-t-6    509723\n",
      "Name: count, dtype: int64\n",
      "task\n",
      "cover                 532368\n",
      "artist_consistency    445310\n",
      "infill                 41752\n",
      "                          10\n",
      "artist_cover               6\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": 18,
   "metadata": {
    "execution": {
     "iopub.execute_input": "2025-06-03T18:11:07.581842Z",
     "iopub.status.busy": "2025-06-03T18:11:07.581667Z",
     "iopub.status.idle": "2025-06-03T18:11:07.741484Z",
     "shell.execute_reply": "2025-06-03T18:11:07.741078Z",
     "shell.execute_reply.started": "2025-06-03T18:11:07.581828Z"
    }
   },
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAjAAAAGdCAYAAAAMm0nCAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjkuMiwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8hTgPZAAAACXBIWXMAAA9hAAAPYQGoP6dpAAAqZklEQVR4nO3dfXRU9Z3H8c/cSQKBPIBJECms0mSTUCIkqCdNHBrrStkt2nOA3cJZrOJyAOsDHJfysCwKQRoCigeobmGRRVDY1BXUqmW72hUXDyC0JykFIxBpK27aTTICeUBIMnP3D05GJuRpwpCZ38z7dQ5H5t7f3Pv75jdxPtynn8O2bVsAAAAGsULdAQAAgEARYAAAgHEIMAAAwDgEGAAAYBwCDAAAMA4BBgAAGIcAAwAAjEOAAQAAxiHAAAAA4xBgAACAcWJC3YHrze1uUF9NluBwSCkpiX26z1CLxpol6qbuyBeNNUvUHQ51t/WlOxEfYGxbfT4YodhnqEVjzRJ1R5torDsaa5ao2wScQgIAAMYhwAAAAOMQYAAAgHEIMAAAwDgEGAAAYBwCDAAAMA4BBgAAGIcAAwAAjEOAAQAAxiHAAAAA4xBgAACAcQgwAADAOAQYAABgnIifjRpmsSyHLMvhe+312vJ6DZkaFQDQZwgwCBuW5VDyoAGKcX51YLDV49X5cxcIMQAAPwQYhA3LcijGaWl+WbmqahqVMSRBG6bnybIcBBgAgB8CDMJOVU2jjlfXh7obAIAwxkW8AADAOAQYAABgHAIMAAAwDgEGAAAYhwADAACMQ4ABAADGIcAAAADjEGAAAIBxCDAAAMA4BBgAAGAcAgwAADAOAQYAABiHAAMAAIxDgAEAAMYhwAAAAOMQYAAAgHEIMAAAwDgEGAAAYBwCDAAAMA4BBgAAGIcAAwAAjHNNAeZf//VflZWVpR//+Me+ZZcuXVJxcbHy8/OVl5enxx9/XHV1dX7vq66u1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/esrCylpaVp5syZ+uyzz/QXf/EXfd3NoBk5cqTeeOMNNTQ06Je//KUWL16sV155JdTduu46qzsjI8P4seYU0jUaPHiwnE6n3G6333K32x3R8zYlJSXplltu0WeffabU1FS1tLSovr7er43b7VZaWlqIehhcbXV0Nc6pqan64osv/Na3trbq/PnzEfNzkKQRI0Zo8ODB+uMf/yjJ/LpXrlypffv2afv27Ro6dKhveU8+16mpqVfdrdL2Opxr76zmjowdO1aS/MbbxJrj4uJ08803KycnRwsWLFB2drZ27NgR0eMsdV53R0wbawLMNYqLi9Po0aN18OBB3zKv16uDBw/6nWeMNE1NTTpz5ozS0tKUk5Oj2NhYv5/B6dOnVV1drdzc3NB1MoiGDx+utLQ0vxobGxv129/+1jfOeXl5qq+v17Fjx3xtDh06JK/XqzFjxvR5n6+XP//5zzp37pzvf2Cm1m3btlauXKl3331X27dv14gRI/zW9+RznZubq5MnT/oF2wMHDighIcF3mD6cdFdzRyorKyV99YVlWs2d8Xq9am5ujshx7kpb3R0xbaw5hRQEDz30kBYvXqycnByNGTNG27dv15dffqkpU6aEumtBs2bNGn3729/WsGHDVFNTo5/85CeyLEv33nuvEhMTNXXqVJWWlio5OVkJCQlatWqV8vLyjAowTU1N+uyzz3yvP//8c1VWVio5OVnDhg3TAw88oJ/+9Ke6+eabNXz4cG3YsEFDhgzRPffcI+nyhX/jx4/Xk08+qeLiYrW0tOjpp5/WpEmTdOONN4aqrG51VXdycrKef/55TZw4UampqTpz5oyeeeYZ3XzzzRo/frwkc+suLi7W22+/rX/5l3/RwIEDfef0ExMT1b9//x59rl0ulzIyMrRo0SItXLhQtbW1Wr9+vWbMmKG4uLgQVtex7mr+7LPP9NZbb6moqEiDBg3SiRMntHr1at1xxx3Kzs6WZF7NkrRu3Tp961vf0k033aSmpia9/fbbOnz4sLZu3RqR49ymq7ojYayZjTpIXnnlFW3dulW1tbUaNWqUli1b5jscFwmeeOIJHTlyROfOndMNN9yg2267TU888YTvPOmlS5dUWlqqd955R83NzXK5XFq+fHlYHGbsqY8++kgPPPDAVcsnT56s0tJS2batjRs36tVXX1V9fb1uu+02LV++XCNHjvS1PXfunJ5++mn993//tyzL0ne+8x0tW7ZMAwcO7MtSAtJV3StWrNCjjz6qjz/+WA0NDRoyZIjuvPNOzZ8/3+8UqYl1Z2Vldbh89erVvn989ORz/b//+79asWKFDh8+rPj4eE2ePFkLFixQTEz4/fuwu5r/9Kc/aeHChTp16pQuXLigm266Sffcc48eeeQRJSQk+NqbVLMkLV26VIcOHVJNTY0SExOVlZWl2bNn684775QUeePcpqu6I2GsCTAAAMA4XAMDAACMQ4ABAADGIcAAAADjEGAAAIBxCDAAAMA4BBgAAGAcAgwAADAOAQYAABiHAAMAAIxDgAEAAMYhwAAAAOMQYAAAgHH+H54NDQyOM4vTAAAAAElFTkSuQmCC",
      "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": 19,
   "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:11:07.742194Z",
     "iopub.status.busy": "2025-06-03T18:11:07.742015Z",
     "iopub.status.idle": "2025-06-03T18:11:09.917857Z",
     "shell.execute_reply": "2025-06-03T18:11:09.917350Z",
     "shell.execute_reply.started": "2025-06-03T18:11:07.742180Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "after duration 0.9961214228119979\n",
      "after infill duration 0.9984216917816148\n",
      "neg_filter_reaction_play_count 1.0\n",
      "neg_filter_upvote_count 0.9889\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.9736\n",
      "pos_filter_cer_diff_preference 1.0\n",
      "pos_filter_bad_flags 0.9999\n",
      "after filter on play counts 0.9663\n",
      "after filter on higher quality 0.2964\n",
      "----------------\n",
      "negative 501342 positive 128465\n",
      "----------------\n",
      "total pair requests 509723  --> selected pair requests 126863 frac 0.249\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",
    ")\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",
    ") & (\n",
    "    (\n",
    "        df[\"upvote_count\"] >= 1\n",
    "    )  # (df[\"upvote_count\"] >= 1)  (df[\"pos_diff_preference\"] == 2)\n",
    "    | (df[\"reaction_play_count\"] >= 5)\n",
    "    | (df[\"concat_play_counts\"] >= 5)\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": 20,
   "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:11:09.921088Z",
     "iopub.status.busy": "2025-06-03T18:11:09.920883Z",
     "iopub.status.idle": "2025-06-03T18:11:10.720508Z",
     "shell.execute_reply": "2025-06-03T18:11:10.720006Z",
     "shell.execute_reply.started": "2025-06-03T18:11:09.921074Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "auk_mix_t1_v6 requests 126863 clips 253726 total khrs 11.363; N gpus for 1000 iters 15.858; 4 gpus for x iters 3964.469; n unique users 42720 n pro users 39331\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"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "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:11:10.721191Z",
     "iopub.status.busy": "2025-06-03T18:11:10.721009Z",
     "iopub.status.idle": "2025-06-03T18:11:10.807895Z",
     "shell.execute_reply": "2025-06-03T18:11:10.807423Z",
     "shell.execute_reply.started": "2025-06-03T18:11:10.721177Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "positive in playlist (33953, 158)\n",
      "task\n",
      "artist_consistency    117588\n",
      "cover                 107618\n",
      "infill                 28516\n",
      "                           4\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": 22,
   "metadata": {
    "execution": {
     "iopub.execute_input": "2025-06-03T18:11:10.808569Z",
     "iopub.status.busy": "2025-06-03T18:11:10.808398Z",
     "iopub.status.idle": "2025-06-03T18:11:10.945498Z",
     "shell.execute_reply": "2025-06-03T18:11:10.945083Z",
     "shell.execute_reply.started": "2025-06-03T18:11:10.808555Z"
    }
   },
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAjAAAAGdCAYAAAAMm0nCAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjkuMiwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8hTgPZAAAACXBIWXMAAA9hAAAPYQGoP6dpAAAyAklEQVR4nO3dfXBUVZ7/8U93J4FAHghJECOo/IgkaCAJamFiZzLOis4OulXArlDDqFiU4CDCKgoUg5IAlQQFF1F3oJBCHieyAzo+MVM6qy4WIGglw4aNQGRGwmbdPEjIk0LS3b8/2LR0DEl36HT3Sd6vqtTQ957ce+43N+Yz5557r8XlcrkEAABgEGuwOwAAAOArAgwAADAOAQYAABiHAAMAAIxDgAEAAMYhwAAAAOMQYAAAgHEIMAA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XbtW8+fPV0REhIqLizVixAgtXbpUkjR69Gh98cUXev3115WTk+OnQ0d/khg1QA6nSzExke5lbQ6nzte3yOl0BbFnAICeuKo5MI2NjZKk2NhYSVJZWZlaW1uVnZ3tbjN69GglJSWptLRUklRaWqoxY8YoISHB3cZut6upqUkVFRXuNu0B6PI27dsAfBUTGSab1aKFxSWavOGAFhaXKMzGKAwAmMqnEZjLOZ1OFRQUaMKECRozZowkqba2VuHh4YqJifFoGx8fr5qaGneby8OLJPfn7to0NTXp+++/18CBA73upyXAf5/a9xfo/ZomWHWqqG7S8aqGTvsSijifvEOdukeNvEOdvNObdfJ2mz0OMPn5+Tp16pR2797d000ERHx8dL/ar2mCXae4uMFB3b+3gl0nU1Cn7lEj71An7wSzTj0KMCtXrtTHH3+snTt3avjw4e7lCQkJam1tVUNDg8coTF1dnRITE91tjh075rG99ruULm/T8c6l2tpaRUVF+TT6cmnfjXIFcIqDxXLpBxro/ZqmN+tks1m9DibnzjXL4XD6twN+xPnkHerUPWrkHerknd6sU/u2u+NTgHG5XFq1apU++OAD7dixQyNHjvRYn5aWpvDwcB06dEj33nuvJOn06dOqqqpSRkaGJCkjI0MbN25UXV2d4uPjJUkHDx5UVFSUkpOT3W3+4z/+w2PbBw8edG/Dtz4rKCdhsPZrmlCoU7D3741QqJMJqFP3qJF3qJN3glknnybx5ufn6+2339a6des0ePBg1dTUqKamRt9//70kKTo6WtOmTVNRUZEOHz6ssrIyLVu2TJmZme7wYbfblZycrMWLF+vLL7/UgQMHtH79es2cOVMRERGSpBkzZqiyslLPP/+8vvrqK+3atUv79+/XrFmz/HrwAADATD6NwPzud7+TJD344IMeywsLCzV16lRJ0rJly2S1WrVgwQJdvHhRdrtdK1ascLe12WzauHGj8vLyNH36dEVGRmrKlClasGCBu83IkSO1adMmFRYWavv27Ro+fLhWr17NLdQAAECSjwHmxIkT3bYZMGCAVqxY4RFaOrruuuu0efPmLrczceJEvfXWW750DwAA9BO8CwkAABiHAAMAAIxDgAEAAMYh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wYE8lF7VVZ3y8vL0+OOP67/+67/U2NioYcOG6c4779TChQs9Ltv29TqlpKR0urywsND9f568+T377//+b+Xl5enIkSOKjIzUlClTtGjRIoWF9Y3/j9tdnf7nf/5HzzzzjE6dOqWWlhZde+21uvvuuzVv3jxFRUW52/f1Oi1btkyHDx9WdXW1oqOjlZKSokcffVR33nmnpNA7lwgwAADAOMyBAQAAxiHAAAAA4xBgAACAcQgwAADAOAQYAABgHAIMAAAwDgEGAAAYhwADAACMQ4ABAADGIcAAAADjEGAAAIBxCDAAAMA4/x+36UU+IOOyWAAAAABJRU5ErkJggg==",
      "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": 23,
   "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:11:10.946153Z",
     "iopub.status.busy": "2025-06-03T18:11:10.945991Z",
     "iopub.status.idle": "2025-06-03T18:11:10.959666Z",
     "shell.execute_reply": "2025-06-03T18:11:10.959321Z",
     "shell.execute_reply.started": "2025-06-03T18:11:10.946140Z"
    }
   },
   "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": 24,
   "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:11:10.960209Z",
     "iopub.status.busy": "2025-06-03T18:11:10.960101Z",
     "iopub.status.idle": "2025-06-03T18:11:10.971006Z",
     "shell.execute_reply": "2025-06-03T18:11:10.970662Z",
     "shell.execute_reply.started": "2025-06-03T18:11:10.960197Z"
    }
   },
   "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": 25,
   "metadata": {
    "execution": {
     "iopub.execute_input": "2025-06-03T18:11:10.971471Z",
     "iopub.status.busy": "2025-06-03T18:11:10.971366Z",
     "iopub.status.idle": "2025-06-03T18:11:10.982416Z",
     "shell.execute_reply": "2025-06-03T18:11:10.982075Z",
     "shell.execute_reply.started": "2025-06-03T18:11:10.971460Z"
    }
   },
   "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": 26,
   "metadata": {
    "execution": {
     "iopub.execute_input": "2025-06-03T18:11:10.983059Z",
     "iopub.status.busy": "2025-06-03T18:11:10.982871Z",
     "iopub.status.idle": "2025-06-03T18:11:10.993834Z",
     "shell.execute_reply": "2025-06-03T18:11:10.993491Z",
     "shell.execute_reply.started": "2025-06-03T18:11:10.983048Z"
    }
   },
   "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": 27,
   "metadata": {
    "execution": {
     "iopub.execute_input": "2025-06-03T18:11:10.994295Z",
     "iopub.status.busy": "2025-06-03T18:11:10.994189Z",
     "iopub.status.idle": "2025-06-03T18:11:11.005608Z",
     "shell.execute_reply": "2025-06-03T18:11:11.005258Z",
     "shell.execute_reply.started": "2025-06-03T18:11:10.994284Z"
    }
   },
   "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": 28,
   "metadata": {
    "execution": {
     "iopub.execute_input": "2025-06-03T18:11:11.006195Z",
     "iopub.status.busy": "2025-06-03T18:11:11.005993Z",
     "iopub.status.idle": "2025-06-03T18:11:11.016540Z",
     "shell.execute_reply": "2025-06-03T18:11:11.016204Z",
     "shell.execute_reply.started": "2025-06-03T18:11:11.006183Z"
    }
   },
   "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": 29,
   "metadata": {
    "execution": {
     "iopub.execute_input": "2025-06-03T18:11:11.017043Z",
     "iopub.status.busy": "2025-06-03T18:11:11.016935Z",
     "iopub.status.idle": "2025-06-03T18:11:11.027649Z",
     "shell.execute_reply": "2025-06-03T18:11:11.027316Z",
     "shell.execute_reply.started": "2025-06-03T18:11:11.017032Z"
    }
   },
   "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": 30,
   "metadata": {
    "execution": {
     "iopub.execute_input": "2025-06-03T18:11:11.028117Z",
     "iopub.status.busy": "2025-06-03T18:11:11.028008Z",
     "iopub.status.idle": "2025-06-03T18:11:11.038825Z",
     "shell.execute_reply": "2025-06-03T18:11:11.038493Z",
     "shell.execute_reply.started": "2025-06-03T18:11:11.028106Z"
    }
   },
   "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": 31,
   "metadata": {
    "execution": {
     "iopub.execute_input": "2025-06-03T18:11:11.039430Z",
     "iopub.status.busy": "2025-06-03T18:11:11.039235Z",
     "iopub.status.idle": "2025-06-03T18:11:11.049676Z",
     "shell.execute_reply": "2025-06-03T18:11:11.049337Z",
     "shell.execute_reply.started": "2025-06-03T18:11:11.039418Z"
    }
   },
   "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": 32,
   "metadata": {
    "execution": {
     "iopub.execute_input": "2025-06-03T18:11:11.050137Z",
     "iopub.status.busy": "2025-06-03T18:11:11.050032Z",
     "iopub.status.idle": "2025-06-03T18:11:11.060876Z",
     "shell.execute_reply": "2025-06-03T18:11:11.060547Z",
     "shell.execute_reply.started": "2025-06-03T18:11:11.050127Z"
    }
   },
   "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": 33,
   "metadata": {
    "execution": {
     "iopub.execute_input": "2025-06-03T18:11:11.061490Z",
     "iopub.status.busy": "2025-06-03T18:11:11.061294Z",
     "iopub.status.idle": "2025-06-03T18:11:11.073893Z",
     "shell.execute_reply": "2025-06-03T18:11:11.073532Z",
     "shell.execute_reply.started": "2025-06-03T18:11:11.061478Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "is_public\n",
      "False    241971\n",
      "True      11755\n",
      "Name: count, dtype: int64\n"
     ]
    }
   ],
   "source": [
    "print(df_slice[\"is_public\"].value_counts())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "metadata": {
    "execution": {
     "iopub.execute_input": "2025-06-03T18:11:11.074496Z",
     "iopub.status.busy": "2025-06-03T18:11:11.074295Z",
     "iopub.status.idle": "2025-06-03T18:11:11.126264Z",
     "shell.execute_reply": "2025-06-03T18:11:11.125835Z",
     "shell.execute_reply.started": "2025-06-03T18:11:11.074484Z"
    }
   },
   "outputs": [],
   "source": [
    "df_slice[\"npz_path\"] = df_slice[\"s3_id\"].map(lambda x: f\"{NPZ_DIR}/{x}.npz\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "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:11:11.126977Z",
     "iopub.status.busy": "2025-06-03T18:11:11.126746Z",
     "iopub.status.idle": "2025-06-03T18:11:11.412481Z",
     "shell.execute_reply": "2025-06-03T18:11:11.411953Z",
     "shell.execute_reply.started": "2025-06-03T18:11:11.126963Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(253726, 159)\n",
      "task\n",
      "artist_consistency    117588\n",
      "cover                 107618\n",
      "infill                 28516\n",
      "                           4\n",
      "Name: count, dtype: int64\n",
      "(253726, 159)\n",
      "task\n",
      "artist_consistency    117588\n",
      "cover                 107618\n",
      "infill                 28516\n",
      "                           4\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[35], 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_20250411_full_long_slice.pkl\"\n",
    "# )\n",
    "print(df_slice.shape)\n",
    "print(df_slice[\"task\"].value_counts())\n",
    "# df_slice = df_slice[df_slice[\"task\"].isin([\"extend\", \"\"])].copy()\n",
    "print(df_slice.shape)\n",
    "print(df_slice[\"task\"].value_counts())\n",
    "BREAK"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "metadata": {
    "execution": {
     "iopub.execute_input": "2025-06-03T18:13:07.061169Z",
     "iopub.status.busy": "2025-06-03T18:13:07.060857Z",
     "iopub.status.idle": "2025-06-03T18:13:10.925347Z",
     "shell.execute_reply": "2025-06-03T18:13:10.924981Z",
     "shell.execute_reply.started": "2025-06-03T18:13:07.061153Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(153414, 159)\n",
      "task\n",
      "                 121424\n",
      "extend            19502\n",
      "upload_extend     12488\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_20250411_full_long_slice.pkl\"\n",
    ")\n",
    "print(df_13b_slice.shape)\n",
    "print(df_13b_slice[\"task\"].value_counts())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "metadata": {
    "execution": {
     "iopub.execute_input": "2025-06-03T18:13:10.926055Z",
     "iopub.status.busy": "2025-06-03T18:13:10.925927Z",
     "iopub.status.idle": "2025-06-03T18:13:11.400805Z",
     "shell.execute_reply": "2025-06-03T18:13:11.400458Z",
     "shell.execute_reply.started": "2025-06-03T18:13:10.926042Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(253726, 159)\n",
      "task\n",
      "artist_consistency    117588\n",
      "cover                 107618\n",
      "infill                 28516\n",
      "                           4\n",
      "Name: count, dtype: int64\n"
     ]
    }
   ],
   "source": [
    "df_30b_slice = df_slice.copy()\n",
    "print(df_30b_slice.shape)\n",
    "print(df_30b_slice[\"task\"].value_counts())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "metadata": {
    "execution": {
     "iopub.execute_input": "2025-06-03T18:13:11.401416Z",
     "iopub.status.busy": "2025-06-03T18:13:11.401210Z",
     "iopub.status.idle": "2025-06-03T18:13:15.452290Z",
     "shell.execute_reply": "2025-06-03T18:13:15.451948Z",
     "shell.execute_reply.started": "2025-06-03T18:13:11.401403Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(407140, 168)\n",
      "task\n",
      "                      121428\n",
      "artist_consistency    117588\n",
      "cover                 107618\n",
      "infill                 28516\n",
      "extend                 19502\n",
      "upload_extend          12488\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": 39,
   "metadata": {
    "execution": {
     "iopub.execute_input": "2025-06-03T18:13:15.453350Z",
     "iopub.status.busy": "2025-06-03T18:13:15.452919Z",
     "iopub.status.idle": "2025-06-03T18:13:16.429832Z",
     "shell.execute_reply": "2025-06-03T18:13:16.429427Z",
     "shell.execute_reply.started": "2025-06-03T18:13:15.453335Z"
    }
   },
   "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": 40,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-05-16T13:59:41.932296Z",
     "start_time": "2024-05-16T13:59:41.932287Z"
    },
    "execution": {
     "iopub.execute_input": "2025-06-03T18:13:36.734381Z",
     "iopub.status.busy": "2025-06-03T18:13:36.734073Z",
     "iopub.status.idle": "2025-06-03T18:13:36.758380Z",
     "shell.execute_reply": "2025-06-03T18:13:36.758004Z",
     "shell.execute_reply.started": "2025-06-03T18:13:36.734366Z"
    }
   },
   "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": 41,
   "metadata": {
    "execution": {
     "iopub.execute_input": "2025-06-03T18:13:36.759195Z",
     "iopub.status.busy": "2025-06-03T18:13:36.759005Z",
     "iopub.status.idle": "2025-06-03T18:13:37.782012Z",
     "shell.execute_reply": "2025-06-03T18:13:37.781660Z",
     "shell.execute_reply.started": "2025-06-03T18:13:36.759181Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(407140, 168)\n",
      "(407140, 168)\n",
      "(407140, 168)\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": 42,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-05-16T13:59:41.932966Z",
     "start_time": "2024-05-16T13:59:41.932957Z"
    },
    "execution": {
     "iopub.execute_input": "2025-06-03T18:13:37.782525Z",
     "iopub.status.busy": "2025-06-03T18:13:37.782399Z",
     "iopub.status.idle": "2025-06-03T18:13:37.867572Z",
     "shell.execute_reply": "2025-06-03T18:13:37.867221Z",
     "shell.execute_reply.started": "2025-06-03T18:13:37.782512Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "203570\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": 43,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-05-16T13:59:41.933558Z",
     "start_time": "2024-05-16T13:59:41.933550Z"
    },
    "execution": {
     "iopub.execute_input": "2025-06-03T18:13:37.868099Z",
     "iopub.status.busy": "2025-06-03T18:13:37.867974Z",
     "iopub.status.idle": "2025-06-03T18:13:37.881709Z",
     "shell.execute_reply": "2025-06-03T18:13:37.881422Z",
     "shell.execute_reply.started": "2025-06-03T18:13:37.868086Z"
    }
   },
   "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": 44,
   "metadata": {
    "execution": {
     "iopub.execute_input": "2025-06-03T18:13:37.882686Z",
     "iopub.status.busy": "2025-06-03T18:13:37.882513Z",
     "iopub.status.idle": "2025-06-03T18:13:37.893225Z",
     "shell.execute_reply": "2025-06-03T18:13:37.892961Z",
     "shell.execute_reply.started": "2025-06-03T18:13:37.882674Z"
    }
   },
   "outputs": [],
   "source": [
    "# df_slice[\"continue_at\"] = -1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 45,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-05-16T13:59:41.934277Z",
     "start_time": "2024-05-16T13:59:41.934268Z"
    },
    "execution": {
     "iopub.execute_input": "2025-06-03T18:13:37.893700Z",
     "iopub.status.busy": "2025-06-03T18:13:37.893540Z",
     "iopub.status.idle": "2025-06-03T18:13:39.823484Z",
     "shell.execute_reply": "2025-06-03T18:13:39.823142Z",
     "shell.execute_reply.started": "2025-06-03T18:13:37.893688Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "201534 2036\n",
      "(403068, 168) (4072, 168)\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": 46,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-05-16T13:59:41.935620Z",
     "start_time": "2024-05-16T13:59:41.935613Z"
    },
    "execution": {
     "iopub.execute_input": "2025-06-03T18:13:39.823993Z",
     "iopub.status.busy": "2025-06-03T18:13:39.823877Z",
     "iopub.status.idle": "2025-06-03T18:13:48.686054Z",
     "shell.execute_reply": "2025-06-03T18:13:48.685702Z",
     "shell.execute_reply.started": "2025-06-03T18:13:39.823981Z"
    }
   },
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "100%|██████████████████████████████████████████████████████████████████████████████████████████████████████| 403068/403068 [00:08<00:00, 45565.76it/s]"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "18,741 hours of 403068 clips, 25.19175 nodes, 4198.625 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 / 2 / 6} iters\"\n",
    ")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 47,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-05-16T13:59:41.936268Z",
     "start_time": "2024-05-16T13:59:41.936260Z"
    },
    "execution": {
     "iopub.execute_input": "2025-06-03T18:13:48.686562Z",
     "iopub.status.busy": "2025-06-03T18:13:48.686444Z",
     "iopub.status.idle": "2025-06-03T18:14:54.782609Z",
     "shell.execute_reply": "2025-06-03T18:14:54.782278Z",
     "shell.execute_reply.started": "2025-06-03T18:13:48.686549Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "t_data_memmap is set to: 6016\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "100%|█████████████████████████████████████████████████████████████████████████████████████████████████████████████| 4072/4072 [01:05<00:00, 61.83it/s]"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Total 4072 clips, 0 different prompts\n",
      "118 hours of False\n",
      "117 hours of True\n",
      "artist_consistency: 79.8 hours\n",
      "cover: 66.0 hours\n",
      "infill: 6.0 hours\n",
      "extend: 19.6 hours\n",
      "gen: 64.6 hours\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": 48,
   "metadata": {
    "execution": {
     "iopub.execute_input": "2025-06-03T18:14:54.783182Z",
     "iopub.status.busy": "2025-06-03T18:14:54.782981Z",
     "iopub.status.idle": "2025-06-03T18:14:54.831842Z",
     "shell.execute_reply": "2025-06-03T18:14:54.831514Z",
     "shell.execute_reply.started": "2025-06-03T18:14:54.783169Z"
    }
   },
   "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": 49,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-05-16T13:59:41.936964Z",
     "start_time": "2024-05-16T13:59:41.936957Z"
    },
    "execution": {
     "iopub.execute_input": "2025-06-03T18:14:54.832518Z",
     "iopub.status.busy": "2025-06-03T18:14:54.832198Z",
     "iopub.status.idle": "2025-06-03T19:57:29.950093Z",
     "shell.execute_reply": "2025-06-03T19:57:29.949583Z",
     "shell.execute_reply.started": "2025-06-03T18:14:54.832506Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "t_data_memmap is set to: 6016\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "  0%|▎                                                                                                        | 1149/403068 [00:20<1:41:19, 66.12it/s]"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1138, 'full_arr is not a file in the archive', infill, /app/suno/data/dpo/30b_npz/ccb707e8-1c1a-4317-8370-a8fc312a4b87.npz.\n",
      "WTF --> 1139, skip, preference: True, 692d2bb5-2634-413b-aa9b-f9a1bc291967, task: infill.\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "  6%|██████                                                                                                  | 23722/403068 [06:12<1:29:11, 70.89it/s]"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "23714, '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 --> 23715, skip, preference: True, 10754475-08f0-4951-b71a-c2fe0991c409, task: upload_extend.\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "  7%|███████▋                                                                                                | 29774/403068 [07:44<1:30:29, 68.76it/s]"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "29760, 'full_arr is not a file in the archive', infill, /app/suno/data/dpo/30b_npz/dbd5f931-c157-41fb-b204-90ec3baa5db3.npz.\n",
      "WTF --> 29761, skip, preference: True, dd1cd0d7-e6ba-4306-b200-9a490d9aa5a0, task: infill.\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      " 11%|███████████▊                                                                                            | 45675/403068 [11:44<1:24:27, 70.53it/s]"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "45660, 'full_arr is not a file in the archive', infill, /app/suno/data/dpo/30b_npz/2f176b3f-ef12-4179-aee5-556756deae58.npz.\n",
      "WTF --> 45661, skip, preference: True, 9a5c7e2c-2698-423a-9688-836fe9f78058, task: infill.\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      " 17%|█████████████████▎                                                                                      | 66882/403068 [16:58<1:17:05, 72.68it/s]"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "66874, 'full_arr is not a file in the archive', infill, /app/suno/data/dpo/30b_npz/8dddfd98-f72b-47c5-a5b5-637e3e3f6e5a.npz.\n",
      "WTF --> 66875, skip, preference: True, 539f7741-6451-4eab-a55c-e32946a685ec, task: infill.\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      " 19%|███████████████████▋                                                                                    | 76135/403068 [19:16<1:17:28, 70.33it/s]"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "76120, 'full_arr is not a file in the archive', infill, /app/suno/data/dpo/30b_npz/c5cf93c9-178b-4c62-ad9e-582cf563b2e0.npz.\n",
      "WTF --> 76121, skip, preference: True, b1a272e3-8180-4128-a876-7c3babea63fe, task: infill.\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      " 20%|████████████████████▋                                                                                   | 80339/403068 [20:20<1:16:44, 70.09it/s]"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "80326, 'full_arr is not a file in the archive', infill, /app/suno/data/dpo/30b_npz/22af1130-3df2-4798-87bf-d002d0e5bdb2.npz.\n",
      "WTF --> 80327, skip, preference: True, c25c2fac-5f9a-4a67-9f49-93dbc19c36d0, task: infill.\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      " 23%|███████████████████████▍                                                                                | 90957/403068 [22:58<1:12:22, 71.88it/s]"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "90948, 'full_arr is not a file in the archive', infill, /app/suno/data/dpo/30b_npz/419cca10-dc66-48db-b3a6-db8d7b661539.npz.\n",
      "WTF --> 90949, skip, preference: True, 85e59615-85da-4d60-80d5-67a617f4ceb7, task: infill.\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      " 23%|████████████████████████                                                                                | 93481/403068 [23:36<1:12:47, 70.88it/s]"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "93466, 'full_arr is not a file in the archive', infill, /app/suno/data/dpo/30b_npz/f23bf59e-143e-44ab-bb2c-749914a0015d.npz.\n",
      "WTF --> 93467, skip, preference: True, bf776438-653a-4a89-a9f4-1c230b31cc4d, task: infill.\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      " 34%|███████████████████████████████████                                                                    | 137204/403068 [34:28<1:03:44, 69.51it/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",
      "137189, 'cover_arr is not a file in the archive', cover, /app/suno/data/dpo/30b_npz/025128d0-1ef2-497b-a7aa-b77645e04131.npz.\n",
      "WTF --> 137189, 'cover_arr is not a file in the archive', cover, /app/suno/data/dpo/30b_npz/025128d0-1ef2-497b-a7aa-b77645e04131.npz.\n",
      "WTF --> 137190, skip, preference: False, 73b9f258-0fb2-40ed-82c4-c047c0668f69, task: artist_consistency.\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      " 37%|██████████████████████████████████████▌                                                                | 150886/403068 [37:52<1:00:25, 69.55it/s]"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "150874, 'full_arr is not a file in the archive', infill, /app/suno/data/dpo/30b_npz/94e21fbb-3c89-43fa-b2d7-57447ca9bac6.npz.\n",
      "WTF --> 150875, skip, preference: True, f01db30d-818b-49c4-95ac-f4621c02d833, task: infill.\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      " 46%|████████████████████████████████████████████████▌                                                        | 186387/403068 [46:44<52:02, 69.38it/s]"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "186376, 'full_arr is not a file in the archive', infill, /app/suno/data/dpo/30b_npz/db9b3c17-eb96-406f-8886-5cf8fe5583cf.npz.\n",
      "WTF --> 186377, skip, preference: True, 169cfd5d-8150-4099-ac45-eb694b40b3fe, task: infill.\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      " 54%|████████████████████████████████████████████████████████▍                                                | 216515/403068 [54:49<44:18, 70.17it/s]"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "216506, '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 --> 216507, skip, preference: True, 409fc6b6-73a1-4884-b80f-6d34ee88ccd1, task: upload_extend.\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      " 64%|█████████████████████████████████████████████████████████████████▌                                     | 256575/403068 [1:04:50<35:30, 68.77it/s]"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "256564, 'full_arr is not a file in the archive', infill, /app/suno/data/dpo/30b_npz/4d5be30b-404c-4f1d-8ebd-5c4661ca819f.npz.\n",
      "WTF --> 256565, skip, preference: True, f5253d4c-ef09-4215-9e03-60df4b4256c9, task: infill.\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      " 71%|████████████████████████████████████████████████████████████████████████▊                              | 284932/403068 [1:11:57<28:18, 69.55it/s]"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "284924, 'full_arr is not a file in the archive', infill, /app/suno/data/dpo/30b_npz/233c39fd-7a7c-4484-9f12-e8132061a41d.npz.\n",
      "WTF --> 284925, skip, preference: True, d984ee29-f547-44f8-837b-999308310e6b, task: infill.\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      " 72%|█████████████████████████████████████████████████████████████████████████▉                             | 289118/403068 [1:13:00<26:33, 71.50it/s]"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "289104, 'full_arr is not a file in the archive', infill, /app/suno/data/dpo/30b_npz/885100f5-63d2-48e6-b95e-629617184741.npz.\n",
      "WTF --> 289105, skip, preference: True, 2a11cb67-e7aa-4f7c-a862-9cb60b06b31c, task: infill.\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      " 72%|█████████████████████████████████████████████████████████████████████████▉                             | 289278/403068 [1:13:03<27:04, 70.03it/s]"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "289264, 'full_arr is not a file in the archive', infill, /app/suno/data/dpo/30b_npz/655f5238-cff6-4e56-aaae-571565be42ce.npz.\n",
      "WTF --> 289265, skip, preference: True, b32277a3-0c3c-4ff3-b114-81bebe908873, task: infill.\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      " 75%|█████████████████████████████████████████████████████████████████████████████▍                         | 302910/403068 [1:16:30<24:09, 69.08it/s]"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "302902, 'history_arr is not a file in the archive', upload_extend, /app/suno/data/dpo/13b_s32_npz/bb5e7c57-8c2b-40d9-8069-2e87877246b1.npz.\n",
      "WTF --> 302903, skip, preference: True, b86b7cb4-72de-424b-99ed-f94f13e1475f, task: upload_extend.\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      " 86%|████████████████████████████████████████████████████████████████████████████████████████▎              | 345430/403068 [1:27:10<13:45, 69.83it/s]"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "345418, 'full_arr is not a file in the archive', infill, /app/suno/data/dpo/30b_npz/ceff47b5-c7f9-469e-8be4-fee5899ca309.npz.\n",
      "WTF --> 345419, skip, preference: True, 85c0d3fe-e67d-4657-ba92-dd57ed5784d2, task: infill.\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      " 98%|█████████████████████████████████████████████████████████████████████████████████████████████████████  | 395608/403068 [1:40:25<01:46, 69.89it/s]"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "395596, 'full_arr is not a file in the archive', infill, /app/suno/data/dpo/30b_npz/9ab4b856-e426-4ffe-96c4-b9d19b8504bc.npz.\n",
      "WTF --> 395597, skip, preference: True, 67f1bef1-b8b7-4eca-bd9f-500761f5cbeb, task: infill.\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "100%|███████████████████████████████████████████████████████████████████████████████████████████████████████| 403068/403068 [1:42:15<00:00, 65.69it/s]\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Total 403028 clips, 40 different prompts\n",
      "11,735 hours of False\n",
      "11,596 hours of True\n",
      "artist_consistency: 7719.4 hours\n",
      "infill: 595.0 hours\n",
      "gen: 6432.6 hours\n",
      "cover: 6840.9 hours\n",
      "extend: 1743.3 hours\n",
      "🚨 Error infill: 16\n",
      "🚨 Error upload_extend: 3\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": 50,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-05-16T13:59:41.937879Z",
     "start_time": "2024-05-16T13:59:41.937870Z"
    },
    "execution": {
     "iopub.execute_input": "2025-06-03T19:57:29.950933Z",
     "iopub.status.busy": "2025-06-03T19:57:29.950633Z",
     "iopub.status.idle": "2025-06-03T19:57:31.604606Z",
     "shell.execute_reply": "2025-06-03T19:57:31.604118Z",
     "shell.execute_reply.started": "2025-06-03T19:57:29.950919Z"
    }
   },
   "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": 51,
   "metadata": {
    "execution": {
     "iopub.execute_input": "2025-06-03T19:57:31.605427Z",
     "iopub.status.busy": "2025-06-03T19:57:31.605102Z",
     "iopub.status.idle": "2025-06-03T19:57:31.621615Z",
     "shell.execute_reply": "2025-06-03T19:57:31.621241Z",
     "shell.execute_reply.started": "2025-06-03T19:57:31.605412Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Counter({'artist_consistency': 1202, None: 1198, 'cover': 1036, 'extend': 356, 'infill': 280})\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": 52,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-05-16T13:59:41.938629Z",
     "start_time": "2024-05-16T13:59:41.938621Z"
    },
    "execution": {
     "iopub.execute_input": "2025-06-03T19:57:31.622294Z",
     "iopub.status.busy": "2025-06-03T19:57:31.622039Z",
     "iopub.status.idle": "2025-06-03T19:57:31.632721Z",
     "shell.execute_reply": "2025-06-03T19:57:31.632384Z",
     "shell.execute_reply.started": "2025-06-03T19:57:31.622281Z"
    }
   },
   "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": 53,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-05-16T13:59:41.939205Z",
     "start_time": "2024-05-16T13:59:41.939198Z"
    },
    "execution": {
     "iopub.execute_input": "2025-06-03T19:57:31.634323Z",
     "iopub.status.busy": "2025-06-03T19:57:31.634075Z",
     "iopub.status.idle": "2025-06-03T19:57:31.644924Z",
     "shell.execute_reply": "2025-06-03T19:57:31.644583Z",
     "shell.execute_reply.started": "2025-06-03T19:57:31.634311Z"
    }
   },
   "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": 54,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-05-16T13:59:41.939977Z",
     "start_time": "2024-05-16T13:59:41.939969Z"
    },
    "execution": {
     "iopub.execute_input": "2025-06-03T19:57:31.645523Z",
     "iopub.status.busy": "2025-06-03T19:57:31.645311Z",
     "iopub.status.idle": "2025-06-03T19:57:31.656253Z",
     "shell.execute_reply": "2025-06-03T19:57:31.655910Z",
     "shell.execute_reply.started": "2025-06-03T19:57:31.645512Z"
    }
   },
   "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": 55,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-05-16T13:59:41.940610Z",
     "start_time": "2024-05-16T13:59:41.940603Z"
    },
    "execution": {
     "iopub.execute_input": "2025-06-03T19:57:31.656910Z",
     "iopub.status.busy": "2025-06-03T19:57:31.656660Z",
     "iopub.status.idle": "2025-06-03T19:57:31.666801Z",
     "shell.execute_reply": "2025-06-03T19:57:31.666462Z",
     "shell.execute_reply.started": "2025-06-03T19:57:31.656898Z"
    }
   },
   "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": 56,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-05-16T13:59:41.941167Z",
     "start_time": "2024-05-16T13:59:41.941159Z"
    },
    "execution": {
     "iopub.execute_input": "2025-06-03T19:57:31.667288Z",
     "iopub.status.busy": "2025-06-03T19:57:31.667182Z",
     "iopub.status.idle": "2025-06-03T19:57:31.677945Z",
     "shell.execute_reply": "2025-06-03T19:57:31.677607Z",
     "shell.execute_reply.started": "2025-06-03T19:57:31.667277Z"
    }
   },
   "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": 57,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-05-16T13:59:41.941801Z",
     "start_time": "2024-05-16T13:59:41.941793Z"
    },
    "execution": {
     "iopub.execute_input": "2025-06-03T19:57:31.678575Z",
     "iopub.status.busy": "2025-06-03T19:57:31.678329Z",
     "iopub.status.idle": "2025-06-03T19:57:31.691751Z",
     "shell.execute_reply": "2025-06-03T19:57:31.691391Z",
     "shell.execute_reply.started": "2025-06-03T19:57:31.678563Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "2036 0\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": 58,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-05-16T13:59:41.942520Z",
     "start_time": "2024-05-16T13:59:41.942511Z"
    },
    "execution": {
     "iopub.execute_input": "2025-06-03T19:57:31.692431Z",
     "iopub.status.busy": "2025-06-03T19:57:31.692171Z",
     "iopub.status.idle": "2025-06-03T19:57:31.725064Z",
     "shell.execute_reply": "2025-06-03T19:57:31.724673Z",
     "shell.execute_reply.started": "2025-06-03T19:57:31.692419Z"
    }
   },
   "outputs": [],
   "source": [
    "train_info = read_json(os.path.join(OUT_DATA_DIR, f\"info_tr.json\"))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 59,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-05-16T13:59:41.943072Z",
     "start_time": "2024-05-16T13:59:41.943065Z"
    },
    "execution": {
     "iopub.execute_input": "2025-06-03T19:57:31.725756Z",
     "iopub.status.busy": "2025-06-03T19:57:31.725511Z",
     "iopub.status.idle": "2025-06-03T19:57:31.751157Z",
     "shell.execute_reply": "2025-06-03T19:57:31.750775Z",
     "shell.execute_reply.started": "2025-06-03T19:57:31.725744Z"
    }
   },
   "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": 60,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-05-16T13:59:41.944246Z",
     "start_time": "2024-05-16T13:59:41.944237Z"
    },
    "execution": {
     "iopub.execute_input": "2025-06-03T19:57:31.751699Z",
     "iopub.status.busy": "2025-06-03T19:57:31.751587Z",
     "iopub.status.idle": "2025-06-03T19:57:31.763391Z",
     "shell.execute_reply": "2025-06-03T19:57:31.763037Z",
     "shell.execute_reply.started": "2025-06-03T19:57:31.751687Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "total samples 403028 (403068, 168)\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": 61,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-05-16T13:59:41.945249Z",
     "start_time": "2024-05-16T13:59:41.945241Z"
    },
    "execution": {
     "iopub.execute_input": "2025-06-03T19:57:31.764011Z",
     "iopub.status.busy": "2025-06-03T19:57:31.763784Z",
     "iopub.status.idle": "2025-06-03T19:57:31.774617Z",
     "shell.execute_reply": "2025-06-03T19:57:31.774269Z",
     "shell.execute_reply.started": "2025-06-03T19:57:31.763998Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1 epoch per batch 4, total 6297.3125\n"
     ]
    }
   ],
   "source": [
    "print(\"1 epoch per batch 4, total\", total_iters / 8 / 2 / 4)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 62,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-05-16T13:59:41.945972Z",
     "start_time": "2024-05-16T13:59:41.945964Z"
    },
    "execution": {
     "iopub.execute_input": "2025-06-03T19:57:31.775255Z",
     "iopub.status.busy": "2025-06-03T19:57:31.775003Z",
     "iopub.status.idle": "2025-06-03T19:57:31.785224Z",
     "shell.execute_reply": "2025-06-03T19:57:31.784893Z",
     "shell.execute_reply.started": "2025-06-03T19:57:31.775243Z"
    }
   },
   "outputs": [],
   "source": [
    "# !cd /home/tony/Work/tony/slurm/sem_4p5_dpo && sbatch sbatch_ipo_4p5"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 63,
   "metadata": {
    "execution": {
     "iopub.execute_input": "2025-06-03T19:57:31.785754Z",
     "iopub.status.busy": "2025-06-03T19:57:31.785650Z",
     "iopub.status.idle": "2025-06-03T19:57:31.810029Z",
     "shell.execute_reply": "2025-06-03T19:57:31.809652Z",
     "shell.execute_reply.started": "2025-06-03T19:57:31.785744Z"
    }
   },
   "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_auk_mixed.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": 64,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-05-16T13:59:41.946562Z",
     "start_time": "2024-05-16T13:59:41.946555Z"
    },
    "execution": {
     "iopub.execute_input": "2025-06-03T19:57:31.810608Z",
     "iopub.status.busy": "2025-06-03T19:57:31.810452Z",
     "iopub.status.idle": "2025-06-03T19:57:31.821322Z",
     "shell.execute_reply": "2025-06-03T19:57:31.820971Z",
     "shell.execute_reply.started": "2025-06-03T19:57:31.810596Z"
    }
   },
   "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": 65,
   "metadata": {
    "execution": {
     "iopub.execute_input": "2025-06-03T19:57:31.821928Z",
     "iopub.status.busy": "2025-06-03T19:57:31.821819Z",
     "iopub.status.idle": "2025-06-03T19:57:31.832315Z",
     "shell.execute_reply": "2025-06-03T19:57:31.831985Z",
     "shell.execute_reply.started": "2025-06-03T19:57:31.821917Z"
    }
   },
   "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": 66,
   "metadata": {
    "execution": {
     "iopub.execute_input": "2025-06-03T19:57:31.832882Z",
     "iopub.status.busy": "2025-06-03T19:57:31.832777Z",
     "iopub.status.idle": "2025-06-03T19:57:31.843176Z",
     "shell.execute_reply": "2025-06-03T19:57:31.842847Z",
     "shell.execute_reply.started": "2025-06-03T19:57:31.832871Z"
    }
   },
   "outputs": [],
   "source": [
    "# train_metas = read_jsonl(os.path.join(OUT_DATA_DIR, f\"meta_tr.jsonl\"))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 67,
   "metadata": {
    "execution": {
     "iopub.execute_input": "2025-06-03T19:57:31.843787Z",
     "iopub.status.busy": "2025-06-03T19:57:31.843564Z",
     "iopub.status.idle": "2025-06-03T19:57:31.854910Z",
     "shell.execute_reply": "2025-06-03T19:57:31.854591Z",
     "shell.execute_reply.started": "2025-06-03T19:57:31.843775Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "dict_keys(['perference_0', 'perference_1'])"
      ]
     },
     "execution_count": 67,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "train_info.keys()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "suno_env_dev",
   "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
}
