{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "execution": {
     "iopub.execute_input": "2025-06-03T18:43:21.422682Z",
     "iopub.status.busy": "2025-06-03T18:43:21.422323Z",
     "iopub.status.idle": "2025-06-03T18:43:21.433788Z",
     "shell.execute_reply": "2025-06-03T18:43:21.433436Z",
     "shell.execute_reply.started": "2025-06-03T18:43:21.422664Z"
    }
   },
   "outputs": [],
   "source": [
    "# setup autoload\n",
    "%load_ext autoreload\n",
    "%autoreload 2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-05-16T13:58:21.040680Z",
     "start_time": "2024-05-16T13:58:19.777010Z"
    },
    "execution": {
     "iopub.execute_input": "2025-06-03T18:43:21.434457Z",
     "iopub.status.busy": "2025-06-03T18:43:21.434202Z",
     "iopub.status.idle": "2025-06-03T18:43:23.188013Z",
     "shell.execute_reply": "2025-06-03T18:43:23.187655Z",
     "shell.execute_reply.started": "2025-06-03T18:43:21.434445Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The autoreload extension is already loaded. To reload it, use:\n",
      "  %reload_ext autoreload\n"
     ]
    }
   ],
   "source": [
    "import ast\n",
    "import os\n",
    "import shutil\n",
    "import sys\n",
    "from collections import defaultdict\n",
    "\n",
    "import json\n",
    "import numpy as np\n",
    "import pandas as pd\n",
    "from preference_data_preparation_4min_30b_task import *\n",
    "from preference_helper import *\n",
    "from sklearn.model_selection import train_test_split\n",
    "from suno_utils.utils.s3 import download_s3_files\n",
    "from suno_utils.utils.text import read_json, read_jsonl, write_json, write_jsonl\n",
    "from tqdm import tqdm\n",
    "\n",
    "pd.set_option(\"display.max_rows\", 500)\n",
    "pd.set_option(\"display.max_columns\", 500)\n",
    "pd.set_option(\"display.width\", 1000)\n",
    "\n",
    "# setup autoload\n",
    "%load_ext autoreload\n",
    "%autoreload 2\n",
    "\n",
    "\n",
    "def custom_parse(x):\n",
    "    try:\n",
    "        return json.loads(x)\n",
    "    except:\n",
    "        return {}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-05-16T13:58:21.082172Z",
     "start_time": "2024-05-16T13:58:21.041926Z"
    },
    "execution": {
     "iopub.execute_input": "2025-06-03T18:43:23.188700Z",
     "iopub.status.busy": "2025-06-03T18:43:23.188396Z",
     "iopub.status.idle": "2025-06-03T18:43:23.245326Z",
     "shell.execute_reply": "2025-06-03T18:43:23.244958Z",
     "shell.execute_reply.started": "2025-06-03T18:43:23.188686Z"
    }
   },
   "outputs": [],
   "source": [
    "OUT_DATA_DIR = \"/app/suno/data/dpo/auk_mix_t1_v14\"\n",
    "os.makedirs(OUT_DATA_DIR, exist_ok=True)\n",
    "shutil.copyfile(\n",
    "    \"/app/suno/data/dpo/7v_v20_full/tokenizer_60k.json\",\n",
    "    os.path.join(OUT_DATA_DIR, \"tokenizer_60k.json\"),\n",
    ")\n",
    "NPZ_DIR = \"/app/suno/data/dpo/30b_npz\"\n",
    "# NOTE FOR 30b we increase this from 6016 up\n",
    "N_TOKENS_AUDIO = 6016"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-05-16T13:58:53.962528Z",
     "start_time": "2024-05-16T13:58:21.105919Z"
    },
    "execution": {
     "iopub.execute_input": "2025-06-03T18:43:23.246328Z",
     "iopub.status.busy": "2025-06-03T18:43:23.246152Z",
     "iopub.status.idle": "2025-06-03T18:43:37.586617Z",
     "shell.execute_reply": "2025-06-03T18:43:37.586255Z",
     "shell.execute_reply.started": "2025-06-03T18:43:23.246316Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Preference data shape (931852, 90)\n"
     ]
    }
   ],
   "source": [
    "df = pd.read_pickle(\n",
    "    \"/home/tony/Data/Preference/30b_v6/interesting_clips_v4_h_t_6_20250501_full_long.pkl\"\n",
    ")\n",
    "print(\"Preference data shape\", df.shape)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "execution": {
     "iopub.execute_input": "2025-06-03T18:43:37.587228Z",
     "iopub.status.busy": "2025-06-03T18:43:37.587012Z",
     "iopub.status.idle": "2025-06-03T18:43:39.597769Z",
     "shell.execute_reply": "2025-06-03T18:43:39.597399Z",
     "shell.execute_reply.started": "2025-06-03T18:43:37.587215Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(931852, 90) (465684, 90)\n",
      "after date cut (465684, 90)\n"
     ]
    }
   ],
   "source": [
    "df[\"created_at\"] = pd.to_datetime(df[\"created_at\"], utc=True)\n",
    "cutoff_date = pd.to_datetime(\"2025-04-12\", utc=True)\n",
    "# cutoff_date = pd.to_datetime(\"2025-04-17\", utc=True)\n",
    "print(df.shape, df[df[\"created_at\"] >= cutoff_date].shape)\n",
    "df = df[(df[\"created_at\"] >= cutoff_date)].copy()\n",
    "print(\"after date cut\", df.shape)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {
    "execution": {
     "iopub.execute_input": "2025-06-03T18:43:39.602984Z",
     "iopub.status.busy": "2025-06-03T18:43:39.602745Z",
     "iopub.status.idle": "2025-06-03T18:43:40.429557Z",
     "shell.execute_reply": "2025-06-03T18:43:40.429193Z",
     "shell.execute_reply.started": "2025-06-03T18:43:39.602970Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "after dropna (465684, 85)\n"
     ]
    }
   ],
   "source": [
    "df = df.dropna(axis=1, how=\"all\")\n",
    "print(\"after dropna\", df.shape)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-05-16T13:58:56.199480Z",
     "start_time": "2024-05-16T13:58:53.963687Z"
    },
    "execution": {
     "iopub.execute_input": "2025-06-03T18:43:40.430543Z",
     "iopub.status.busy": "2025-06-03T18:43:40.430301Z",
     "iopub.status.idle": "2025-06-03T18:49:02.664583Z",
     "shell.execute_reply": "2025-06-03T18:49:02.664215Z",
     "shell.execute_reply.started": "2025-06-03T18:43:40.430530Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "6442462\n",
      "6442462\n",
      "pre-downloaded df (465684, 85)\n",
      "downloaded df (465683, 85)\n"
     ]
    }
   ],
   "source": [
    "converted_paths = os.listdir(NPZ_DIR)\n",
    "print(len(converted_paths))\n",
    "\n",
    "converted_paths = set([f.replace(\".npz\", \"\") for f in converted_paths])\n",
    "print(len(converted_paths))\n",
    "\n",
    "print(\"pre-downloaded df\", df.shape)\n",
    "df[df[\"s3_id\"].isin(converted_paths)].shape\n",
    "df = df[df[\"s3_id\"].isin(converted_paths)].copy()\n",
    "print(\"downloaded df\", df.shape)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-05-16T13:58:56.467253Z",
     "start_time": "2024-05-16T13:58:56.207647Z"
    },
    "execution": {
     "iopub.execute_input": "2025-06-03T18:49:02.665136Z",
     "iopub.status.busy": "2025-06-03T18:49:02.664973Z",
     "iopub.status.idle": "2025-06-03T18:49:03.822609Z",
     "shell.execute_reply": "2025-06-03T18:49:03.822260Z",
     "shell.execute_reply.started": "2025-06-03T18:49:02.665123Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "is_30b\n",
      "True    465683\n",
      "Name: count, dtype: int64\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "task\n",
       "cover                 256083\n",
       "artist_consistency    182810\n",
       "infill                 26786\n",
       "artist_extend              4\n",
       "Name: count, dtype: int64"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df[\"is_30b\"] = df[\"model_name\"].str.contains(\"-t\")\n",
    "print(df[\"is_30b\"].value_counts())\n",
    "df[\"task\"].value_counts()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# LET's do the data prep"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {
    "execution": {
     "iopub.execute_input": "2025-06-03T18:49:03.823240Z",
     "iopub.status.busy": "2025-06-03T18:49:03.823001Z",
     "iopub.status.idle": "2025-06-03T18:49:03.836953Z",
     "shell.execute_reply": "2025-06-03T18:49:03.836653Z",
     "shell.execute_reply.started": "2025-06-03T18:49:03.823228Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(465683, 86)\n"
     ]
    }
   ],
   "source": [
    "# drop extend for now\n",
    "# reason is -- cause they are likely caused by extend from 13b\n",
    "# we don't want contamination\n",
    "# df = df[df[\"task\"] != \"extend\"].copy()\n",
    "print(df.shape)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-05-16T13:58:56.592883Z",
     "start_time": "2024-05-16T13:58:56.470781Z"
    },
    "execution": {
     "iopub.execute_input": "2025-06-03T18:49:03.837446Z",
     "iopub.status.busy": "2025-06-03T18:49:03.837271Z",
     "iopub.status.idle": "2025-06-03T18:49:03.996198Z",
     "shell.execute_reply": "2025-06-03T18:49:03.995838Z",
     "shell.execute_reply.started": "2025-06-03T18:49:03.837434Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "preference  model_name    \n",
      "False       chirp-v4-h-t-6    232842\n",
      "True        chirp-v4-h-t-6    232841\n",
      "Name: count, dtype: int64\n",
      "before filter on model name (465683, 86)\n",
      "after filter on model name (465683, 86)\n"
     ]
    }
   ],
   "source": [
    "## for 13b this is easy for now\n",
    "print(df.groupby([\"preference\"])[\"model_name\"].value_counts())\n",
    "print(\"before filter on model name\", df.shape)\n",
    "df = df[df[\"model_name\"].isin([\"chirp-v4-h-t-6\", \"chirp-v3p5-engine-t-6\"])]\n",
    "# df = df[df[\"model_name\"].isin([\"chirp-v3p5-engine-t-6\"])]\n",
    "print(\"after filter on model name\", df.shape)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {
    "execution": {
     "iopub.execute_input": "2025-06-03T18:49:03.996770Z",
     "iopub.status.busy": "2025-06-03T18:49:03.996573Z",
     "iopub.status.idle": "2025-06-03T18:49:04.012270Z",
     "shell.execute_reply": "2025-06-03T18:49:04.011995Z",
     "shell.execute_reply.started": "2025-06-03T18:49:03.996758Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "is_public\n",
      "False    454090\n",
      "True      11593\n",
      "Name: count, dtype: int64\n"
     ]
    }
   ],
   "source": [
    "print(df[\"is_public\"].value_counts())\n",
    "# remove public for now cause fucking users\n",
    "# df = df[~df[\"is_public\"]]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-05-16T13:58:56.909539Z",
     "start_time": "2024-05-16T13:58:56.595736Z"
    },
    "execution": {
     "iopub.execute_input": "2025-06-03T18:49:04.012734Z",
     "iopub.status.busy": "2025-06-03T18:49:04.012579Z",
     "iopub.status.idle": "2025-06-03T18:49:04.624021Z",
     "shell.execute_reply": "2025-06-03T18:49:04.623628Z",
     "shell.execute_reply.started": "2025-06-03T18:49:04.012723Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "before filter on request id pairs (465683, 86)\n",
      "after filter on request id pairs (465682, 86)\n",
      "preference  model_name    \n",
      "False       chirp-v4-h-t-6    232841\n",
      "True        chirp-v4-h-t-6    232841\n",
      "Name: count, dtype: int64\n"
     ]
    }
   ],
   "source": [
    "print(\"before filter on request id pairs\", df.shape)\n",
    "df = df[\n",
    "    df[\"request_id\"].isin(\n",
    "        df[\"request_id\"].value_counts().index[df[\"request_id\"].value_counts() == 2]\n",
    "    )\n",
    "]\n",
    "print(\"after filter on request id pairs\", df.shape)\n",
    "print(df.groupby([\"preference\"])[\"model_name\"].value_counts())\n",
    "assert df.shape[0] == df[\"request_id\"].nunique() * 2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {
    "execution": {
     "iopub.execute_input": "2025-06-03T18:49:04.625796Z",
     "iopub.status.busy": "2025-06-03T18:49:04.625607Z",
     "iopub.status.idle": "2025-06-03T18:50:15.511358Z",
     "shell.execute_reply": "2025-06-03T18:50:15.510996Z",
     "shell.execute_reply.started": "2025-06-03T18:49:04.625783Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "unique_requests 232841\n",
      "before removing duplicates (465682, 160)\n",
      "after removing duplicates (465682, 153)\n"
     ]
    }
   ],
   "source": [
    "# Let's use the old selection for now -- for quality assurance\n",
    "# expand the metadata columns -- this takes forever...~ 6 mins\n",
    "# test_slice = df[\"metadata\"].apply(lambda x: ast.literal_eval(str(x)))\n",
    "# test_slice = df[\"metadata\"].apply(lambda x: custom_parse(x))\n",
    "test_slice = df[\"metadata\"]  # .apply(lambda x: custom_parse(x))\n",
    "test_slice_series = test_slice.apply(pd.Series)\n",
    "df = pd.concat([df, test_slice_series], axis=1, join=\"inner\")\n",
    "print(\"unique_requests\", df[\"request_id\"].nunique())\n",
    "# remove the duplicates\n",
    "print(\"before removing duplicates\", df.shape)\n",
    "df = df.loc[:, ~df.columns.duplicated()].copy()\n",
    "print(\"after removing duplicates\", df.shape)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {
    "execution": {
     "iopub.execute_input": "2025-06-03T18:50:15.512060Z",
     "iopub.status.busy": "2025-06-03T18:50:15.511749Z",
     "iopub.status.idle": "2025-06-03T18:50:16.319307Z",
     "shell.execute_reply": "2025-06-03T18:50:16.318970Z",
     "shell.execute_reply.started": "2025-06-03T18:50:15.512047Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "task\n",
       "cover                 256082\n",
       "artist_consistency    182810\n",
       "infill                 26786\n",
       "artist_extend              4\n",
       "Name: count, dtype: int64"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df[\"task\"].value_counts()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {
    "execution": {
     "iopub.execute_input": "2025-06-03T18:50:16.319885Z",
     "iopub.status.busy": "2025-06-03T18:50:16.319685Z",
     "iopub.status.idle": "2025-06-03T18:50:17.187823Z",
     "shell.execute_reply": "2025-06-03T18:50:17.187497Z",
     "shell.execute_reply.started": "2025-06-03T18:50:16.319873Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "pos_diff_preference\n",
       "1.0    161927\n",
       "2.0     70914\n",
       "Name: count, dtype: int64"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df = df.sort_values(by=[\"request_id\", \"preference\", \"diff_preference\"])\n",
    "df[\"pos_diff_preference\"] = df[\"diff_preference\"].diff()\n",
    "# df[\"cer_diff_preference\"] = df[\"cer\"].diff()\n",
    "df[df[\"preference\"]][\"pos_diff_preference\"].value_counts()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {
    "execution": {
     "iopub.execute_input": "2025-06-03T18:50:17.188415Z",
     "iopub.status.busy": "2025-06-03T18:50:17.188181Z",
     "iopub.status.idle": "2025-06-03T18:50:17.489079Z",
     "shell.execute_reply": "2025-06-03T18:50:17.488721Z",
     "shell.execute_reply.started": "2025-06-03T18:50:17.188402Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "positive param_experiment\n",
      "text_1       5758\n",
      "temp_s_80    5605\n",
      "temp_s_70    5489\n",
      "Name: count, dtype: int64\n"
     ]
    }
   ],
   "source": [
    "try:\n",
    "    print(\"positive\", df[df[\"preference\"]][\"param_experiment\"].value_counts())\n",
    "except:\n",
    "    pass"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {
    "execution": {
     "iopub.execute_input": "2025-06-03T18:50:17.489680Z",
     "iopub.status.busy": "2025-06-03T18:50:17.489479Z",
     "iopub.status.idle": "2025-06-03T18:50:30.989567Z",
     "shell.execute_reply": "2025-06-03T18:50:30.989209Z",
     "shell.execute_reply.started": "2025-06-03T18:50:17.489667Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Found 39551 duplicated prompts 19776 unique requests\n",
      "Found 9451 request_ids with duplicate prompts but not highest play counts in their group\n",
      "['fa5aba0d-4424-438b-9f87-ba5d0ef503cb', '115a0270-2735-43a2-80d4-05b371926471', '14e7fadb-f34c-4f26-9bda-c378283f529a', '90a5dfe0-d1ba-4a62-9813-936e80ccabb8', '5c18e378-278c-4a9c-a60c-7c9508bbfaf3', 'f3edfa94-39fe-4c6b-b00d-7aea44f16447', '6897cd2a-59ee-4a54-831f-4e0f56ea74e1', '19726b9e-0f6e-4638-91f2-18d0a9d02050', '266d9dbb-ace9-42fe-b92e-e04d0d9bd3a8', 'a982e31f-1ff4-4503-83de-14cbe0a11f55']\n",
      "Before dedup user gen requests 465682\n",
      "After dedup user gen requests 465682\n"
     ]
    }
   ],
   "source": [
    "# Find duplicated prompts with count > 2\n",
    "duplicate_entries = df.groupby(\n",
    "    [\"user_id\", \"prompt_text\", \"tags\", \"task\", \"edited_clip_id\"]\n",
    ").filter(lambda x: len(x) > 2)\n",
    "print(\n",
    "    \"Found\",\n",
    "    len(duplicate_entries),\n",
    "    \"duplicated prompts\",\n",
    "    len(duplicate_entries[\"request_id\"].unique()),\n",
    "    \"unique requests\",\n",
    ")\n",
    "\n",
    "# Group by user_id, prompt_text, and tags to find duplicate prompt groups\n",
    "prompt_groups = duplicate_entries.groupby(\n",
    "    [\"user_id\", \"prompt_text\", \"tags\", \"task\", \"edited_clip_id\"]\n",
    ")\n",
    "\n",
    "# For each prompt group, find the request_id with the highest total reaction_play_count\n",
    "low_play_count_request_ids = []\n",
    "for prompt_key, prompt_group in prompt_groups:\n",
    "    # Get the sum of reaction_play_count for each request_id in this group\n",
    "    request_play_counts = prompt_group.groupby(\"request_id\")[\n",
    "        \"reaction_play_count\"\n",
    "    ].sum()\n",
    "\n",
    "    # Find the max play count in this group\n",
    "    max_play_count = request_play_counts.max()\n",
    "\n",
    "    # Add request_ids that don't have the max play count to our filter list\n",
    "    lower_play_count_request_ids = request_play_counts[\n",
    "        request_play_counts < max_play_count\n",
    "    ].index.tolist()\n",
    "    low_play_count_request_ids.extend(lower_play_count_request_ids)\n",
    "\n",
    "# Display the filtered request IDs\n",
    "print(\n",
    "    f\"Found {len(low_play_count_request_ids)} request_ids with duplicate prompts but not highest play counts in their group\"\n",
    ")\n",
    "print(\n",
    "    low_play_count_request_ids[:10]\n",
    "    if len(low_play_count_request_ids) > 10\n",
    "    else low_play_count_request_ids\n",
    ")\n",
    "print(\"Before dedup user gen requests\", df.shape[0])\n",
    "# df = df[~df[\"request_id\"].isin(low_play_count_request_ids)]\n",
    "print(\"After dedup user gen requests\", df.shape[0])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-05-16T13:59:40.799375Z",
     "start_time": "2024-05-16T13:59:36.394236Z"
    },
    "execution": {
     "iopub.execute_input": "2025-06-03T18:50:30.990093Z",
     "iopub.status.busy": "2025-06-03T18:50:30.989949Z",
     "iopub.status.idle": "2025-06-03T18:50:33.107667Z",
     "shell.execute_reply": "2025-06-03T18:50:33.107316Z",
     "shell.execute_reply.started": "2025-06-03T18:50:30.990080Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "11875\n",
      "good_continue_at\n",
      "True    465682\n",
      "Name: count, dtype: int64\n",
      "\n",
      " Check some basics... \n",
      " preference\n",
      "False    232841\n",
      "True     232841\n",
      "Name: count, dtype: int64 is_30b\n",
      "True    465682\n",
      "Name: count, dtype: int64 model_name\n",
      "chirp-v4-h-t-6    465682\n",
      "Name: count, dtype: int64 preference  model_name    \n",
      "False       chirp-v4-h-t-6    232841\n",
      "True        chirp-v4-h-t-6    232841\n",
      "Name: count, dtype: int64\n",
      "task\n",
      "cover                 256082\n",
      "artist_consistency    182810\n",
      "infill                 26786\n",
      "artist_extend              4\n",
      "Name: count, dtype: int64\n"
     ]
    }
   ],
   "source": [
    "df[\"id\"] = df[\"str_id\"]\n",
    "# get the original duration of the clips, if they are concacted\n",
    "df[\"original_duration_s\"] = df[\"total_start_s\"] + df[\"duration\"]\n",
    "# classify the continue at behavoirs by the duration choice\n",
    "audio_prompt_id_to_continue_at = {}\n",
    "\n",
    "for _, row in df[~df[\"continued_parent\"].isna()].iterrows():\n",
    "    audio_prompt_id = row[\"continued_parent\"]\n",
    "    if audio_prompt_id not in audio_prompt_id_to_continue_at:\n",
    "        audio_prompt_id_to_continue_at[audio_prompt_id] = row[\"continue_at\"]\n",
    "    else:\n",
    "        # pick the max\n",
    "        audio_prompt_id = max(\n",
    "            audio_prompt_id_to_continue_at[audio_prompt_id], row[\"continue_at\"]\n",
    "        )\n",
    "print(len(audio_prompt_id_to_continue_at))\n",
    "df[\"has_continue_and_start_continue_at\"] = df[\"id\"].apply(\n",
    "    lambda x: audio_prompt_id_to_continue_at.get(x)\n",
    ")\n",
    "# we want continue at to be at most of the clip...\n",
    "df[\"good_continue_at\"] = (\n",
    "    (df[\"has_continue_and_start_continue_at\"] / df[\"duration\"]) > 0.9\n",
    ") | df[\"has_continue_and_start_continue_at\"].isna()\n",
    "print(df[\"good_continue_at\"].value_counts())\n",
    "\n",
    "\n",
    "print(\n",
    "    \"\\n Check some basics... \\n\",\n",
    "    df[\"preference\"].value_counts(),\n",
    "    df[\"is_30b\"].value_counts(),\n",
    "    df[\"model_name\"].value_counts(),\n",
    "    df.groupby([\"preference\"])[\"model_name\"].value_counts(),\n",
    ")\n",
    "\n",
    "df = df.sort_values(by=[\"request_id\", \"preference\"])\n",
    "df[\"duration_rel_diff\"] = df[\"duration\"].diff()\n",
    "df[\"play_rel_diff\"] = df[\"reaction_play_count\"].diff()\n",
    "print(df[\"task\"].value_counts())\n",
    "\n",
    "df[\"post_infill_duration\"] = (\n",
    "    df[\"duration\"]\n",
    "    + df[\"infill_context_end_s\"]\n",
    "    - df[\"infill_context_start_s\"]\n",
    "    - df[\"include_future_s\"]\n",
    "    - df[\"include_history_s\"]\n",
    "    - df[\"infill_dur_s\"]\n",
    ")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {
    "execution": {
     "iopub.execute_input": "2025-06-03T18:50:33.108248Z",
     "iopub.status.busy": "2025-06-03T18:50:33.108048Z",
     "iopub.status.idle": "2025-06-03T18:50:33.276257Z",
     "shell.execute_reply": "2025-06-03T18:50:33.275933Z",
     "shell.execute_reply.started": "2025-06-03T18:50:33.108235Z"
    }
   },
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAjAAAAGdCAYAAAAMm0nCAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjkuMiwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8hTgPZAAAACXBIWXMAAA9hAAAPYQGoP6dpAAAtgUlEQVR4nO3de3BUZZ7/8U+fTiKXXAjpoCLo8CMmcbkkQSg2sZnIjMjUgFMF7Ao1rIhLCQ6rsiMjUAwCAYuAAy6i7kAhxYDKRFdd1+vuoru4WICglQwLE4GIw2WzbjqRkAsCSfr8/qDSQ8fcOul095N+v6pSlT7n6XOebz+BfHLOc85x2LZtCwAAwCBWuDsAAAAQKAIMAAAwDgEGAAAYhwADAACMQ4ABAADGIcAAAADjEGAAAIBxCDAAAMA4BBgAAGAcAgwAADBOTLg70NOqqmoVqoclOBxSSkpCSPcZbtFYs0Td1N37RWPNEnVHQt3NfelIrw8wtq2QD0Y49hlu0VizRN3RJhrrjsaaJeo2AaeQAACAcQgwAADAOAQYAABgHAIMAAAwDgEGAAAYhwADAACMQ4ABAADGIcAAAADjEGAAAI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OB7471y5Uq/NibVLEl79uzRfffdpzFjxmjMmDGaOXOmPvnkE9/63jbOzTqq2/ixttFt77//vj1ixAj7jTfesE+dOmWvWLHCHjt2rF1ZWRnurgXNli1b7ClTptgVFRW+r6qqKt/6lStX2vn5+faBAwfs//7v/7bvv/9+e+bMmWHsceD27dtnP/vss/a///u/2+np6fbevXv91m/bts2+88477b1799qlpaX2I488Yv/oRz+yL1++7Gszb948+2c/+5ldUlJiHzlyxJ40aZL9xBNPhLqUgHRU99KlS+158+b5jX11dbVfGxPr/tu//Vv7zTfftE+ePGmXlpbaDz/8sH333Xfb9fX1vjYd/Vw3NjbaU6dOtefOnWv/8Y9/tPft22ePHz/e3rRpUzhK6lBnav6bv/kbe8WKFX7jXVtb61tvWs22bdsff/yxvW/fPvvrr7+2T58+bT/77LP2iBEj7JMnT9q23fvGuVlHdZs+1gSYIPirv/oru6CgwPe6qanJdrvd9rZt28LYq+DasmWL/bOf/azVdTU1NfaIESPsDz/80LesrKzMTk9Pt4uLi0PUw+Bq+Yvc6/Xad911l/3SSy/5ltXU1NgjR46033vvPdu2/1zz0aNHfW0++eQTOyMjw/7mm29C1/luaCvA/OIXv2jzPb2hbtu27aqqKjs9Pd0+fPiwbdud+7net2+fnZmZaXs8Hl+bPXv22GPGjLGvXLkS0v53RcuabfvaL7Wnn366zfeYXnOzcePG2a+//npUjPP1muu2bfPHmlNI3XT16lUdP35ceXl5vmWWZSkvL0/FxcVh7FnwnTlzRm63Wz/+8Y+1ePFilZeXS5KOHTumhoYGv89g+PDhGjx4sEpKSsLU2+A6f/68PB6PX40JCQnKysryjXNxcbESExM1atQoX5u8vDxZlmX8KcXDhw8rNzdXkydP1qpVq3ThwgXfut5Sd21trSQpKSlJUud+rktKSpSenu53g0232626ujqVlZWFrvNd1LLmZu+++67Gjx+vqVOnatOmTfruu+9860yvuampSe+//74uXbqknJycqBhn6ft1NzN5rCP2TrymuHDhgpqampSSkuK3PCUl5Xvnlk02evRoFRYWatiwYfJ4PHrx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YMEFPPfWUCgoK1NDQoLVr12rKlCm68cYbw1VWh9qrOykpSS+88IImT54sl8ulc+fO6Te/+Y1uu+02TZgwQZK5dRcUFOi9997TP/7jP6p///6+c/oJCQnq06dPp36u3W630tLStGTJEj355JPyeDzavHmzZs+erbi4uDBW17qOaj579qzeffdd5efna8CAATpx4oQKCws1btw4ZWZmSjKvZknatGmTfvjDH+rmm29WfX293nvvPR0+fFg7duzolePcrL26e8NY8zTqIHnllVe0Y8cOeTwe3XHHHVqxYoXvcFxv8Mtf/lJHjhxRdXW1Bg4cqDvvvFO//OUvfedJr1y5ovXr1+v999/X1atX5Xa7tWrVqog4zNhZn332mebMmfO95dOmTdP69etl27a2bNmi119/XTU1Nbrzzju1atUqDRs2zNe2urpaa9eu1X/8x3/Isizde++9WrFihfr37x/KUgLSXt2rV6/W3/3d3+mPf/yjamtrNWjQIN11111atGiR3ylSE+vOyMhodXlhYaHvj4/O/Fz/z//8j1avXq3Dhw+rb9++mjZtmhYvXqyYmMj7+7Cjmv/3f/9XTz75pE6dOqVLly7p5ptv1j333KOFCxcqPj7e196kmiVp+fLlOnTokCoqKpSQkKCMjAw9/PDDuuuuuyT1vnFu1l7dvWGsCTAAAMA4zIEBAADGIcAAAADjEGAAAIBxCDAAAMA4BBgAAGAcAgwAADAOAQYAABiHAAMAAIxDgAEAAMYhwAAAAOMQYAAAgHEIMAAAwDj/H+Iw5QND7b3sAAAAAElFTkSuQmCC",
      "text/plain": [
       "<Figure size 640x480 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "df[\"post_infill_duration\"].hist(bins=np.linspace(-5, 360, 100))\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-05-16T13:59:41.035167Z",
     "start_time": "2024-05-16T13:59:40.801098Z"
    },
    "execution": {
     "iopub.execute_input": "2025-06-03T18:50:33.276843Z",
     "iopub.status.busy": "2025-06-03T18:50:33.276689Z",
     "iopub.status.idle": "2025-06-03T18:50:34.560313Z",
     "shell.execute_reply": "2025-06-03T18:50:34.559953Z",
     "shell.execute_reply.started": "2025-06-03T18:50:33.276830Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "after duration 0.9955162535807697\n",
      "after infill duration 0.9978977070189529\n",
      "neg_filter_reaction_play_count 1.0\n",
      "neg_filter_upvote_count 0.9901\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.9744\n",
      "pos_filter_cer_diff_preference 1.0\n",
      "pos_filter_bad_flags 0.9999\n",
      "after filter on play counts 0.9731\n",
      "after filter on higher quality 0.3144\n",
      "----------------\n",
      "negative 229029 positive 63875\n",
      "----------------\n",
      "total pair requests 232841  --> selected pair requests 63272 frac 0.272\n"
     ]
    }
   ],
   "source": [
    "normal_pos_play_count = 3\n",
    "# this is lower, cause a concat is probably already ensuring that it is good\n",
    "concat_pos_play_count = 1\n",
    "# this is a filter on the concated clip\n",
    "concat_total_play_count = 3\n",
    "\n",
    "all_fitlers = (df[\"duration\"] >= 10) & (df[\"duration\"] <= 240)\n",
    "print(\"after duration\", all_fitlers.sum() / df.shape[0])\n",
    "infill_duration_filter = (\n",
    "    ~df[\"task\"].isin(\n",
    "        [\n",
    "            \"infill\",\n",
    "            \"infill_intro\",\n",
    "            \"infill_outro\",\n",
    "        ]\n",
    "    )\n",
    ") | (df[\"post_infill_duration\"] <= 239)\n",
    "print(\"after infill duration\", infill_duration_filter.sum() / df.shape[0])\n",
    "# negative fitlers\n",
    "total_negative = df[~df[\"preference\"]].shape[0]\n",
    "neg_filter_reaction_play_count = (~df[\"preference\"]) & (df[\"reaction_play_count\"] >= 1)\n",
    "print(\n",
    "    \"neg_filter_reaction_play_count\",\n",
    "    round(neg_filter_reaction_play_count.sum() / total_negative, 4),\n",
    ")\n",
    "neg_filter_upvote_count = (~df[\"preference\"]) & (df[\"upvote_count\"] == 0)\n",
    "print(\n",
    "    \"neg_filter_upvote_count\",\n",
    "    round(neg_filter_upvote_count.sum() / total_negative, 4),\n",
    ")\n",
    "neg_filter_norm_play_frac = (~df[\"preference\"]) & (df[\"norm_play_frac\"] <= 3.1)\n",
    "print(\n",
    "    \"neg_filter_norm_play_frac\",\n",
    "    round(neg_filter_norm_play_frac.sum() / total_negative, 4),\n",
    ")\n",
    "neg_filter_continues = (~df[\"preference\"]) & (\n",
    "    df[\"has_continue_and_start_continue_at\"].isna()\n",
    ")\n",
    "print(\n",
    "    \"neg_filter_continues\",\n",
    "    round(neg_filter_continues.sum() / total_negative, 4),\n",
    ")\n",
    "\n",
    "neg_filter_selection_mask = (\n",
    "    all_fitlers\n",
    "    & infill_duration_filter\n",
    "    & neg_filter_reaction_play_count\n",
    "    & neg_filter_upvote_count\n",
    "    & neg_filter_norm_play_frac\n",
    "    & neg_filter_continues\n",
    ")\n",
    "\n",
    "print(\"----------------\")\n",
    "total_positive = df[df[\"preference\"]].shape[0]\n",
    "assert total_positive == total_negative\n",
    "pos_filter_continues = (df[\"preference\"]) & (df[\"good_continue_at\"])\n",
    "print(\"pos_filter_continues\", round(pos_filter_continues.sum() / total_positive, 4))\n",
    "pos_filter_reaction_play_count = (df[\"preference\"]) & (df[\"reaction_play_count\"] >= 1)\n",
    "print(\n",
    "    \"pos_filter_reaction_play_count\",\n",
    "    round(pos_filter_reaction_play_count.sum() / total_positive, 4),\n",
    ")\n",
    "pos_filter_relative_play_count = (df[\"preference\"]) & (df[\"play_rel_diff\"] >= 0)\n",
    "print(\n",
    "    \"pos_filter_relative_play_count\",\n",
    "    round(pos_filter_relative_play_count.sum() / total_positive, 4),\n",
    ")\n",
    "pos_filter_cer_diff_preference = (\n",
    "    df[\n",
    "        \"preference\"\n",
    "    ]  # & (df[\"pos_diff_preference\"] == 2) # & (df[\"cer_diff_preference\"] < 0.5) & (df[\"cer\"] < 0.99)\n",
    ")\n",
    "print(\n",
    "    \"pos_filter_cer_diff_preference\",\n",
    "    round(pos_filter_cer_diff_preference.sum() / total_positive, 4),\n",
    ")\n",
    "pos_filter_bad_flags = (\n",
    "    (df[\"preference\"]) & (df[\"flag_count\"] == 0) & (df[\"dislike_count\"] == 0)\n",
    ")\n",
    "print(\n",
    "    \"pos_filter_bad_flags\",\n",
    "    round(pos_filter_bad_flags.sum() / total_positive, 4),\n",
    ")\n",
    "pos_filter_play_counts = (df[\"preference\"]) & (\n",
    "    (\n",
    "        (df[\"part_of_concat\"])\n",
    "        & (df[\"reaction_play_count\"] >= concat_pos_play_count)\n",
    "        & (df[\"concat_play_counts\"] >= concat_total_play_count)\n",
    "    )\n",
    "    | (\n",
    "        (~df[\"part_of_concat\"]) & (df[\"reaction_play_count\"] >= normal_pos_play_count)\n",
    "        # & (df[\"norm_play_frac\"] >= 2.1)  # this is a bit of a luxury cut...\n",
    "    )\n",
    "    | (df[\"task\"].isin([\"infill\", \"infill_intro\", \"infill_outro\"]))\n",
    ")\n",
    "print(\n",
    "    \"after filter on play counts\",\n",
    "    round(pos_filter_play_counts.sum() / total_positive, 4),\n",
    ")\n",
    "high_quality_tasks_filter = (\n",
    "    (df[\"task\"].isin([\"cover\", \"extend\", \"artist_consistency\", \"\"]))\n",
    "    & (\n",
    "        (df[\"upvote_count\"] >= 1)  # (df[\"upvote_count\"] >= 1)\n",
    "        | (df[\"reaction_play_count\"] >= 5)\n",
    "        | (df[\"concat_play_counts\"] >= 5)\n",
    "    )\n",
    "    & (\n",
    "        (df[\"part_of_concat\"])\n",
    "        | (\n",
    "            (~df[\"part_of_concat\"])\n",
    "            & (df[\"norm_play_frac\"] >= 5.1)  # this is a bit of a luxury cut...\n",
    "            & (\n",
    "                df[\"norm_play_frac\"] >= df[\"reaction_play_count\"] / 3\n",
    "            )  # play duration is not low on average\n",
    "        )\n",
    "    )\n",
    ")\n",
    "medium_quality_tasks_filter = (\n",
    "    df[\"task\"].isin(\n",
    "        [\n",
    "            \"infill\",\n",
    "            \"infill_intro\",\n",
    "            \"infill_outro\",\n",
    "        ]\n",
    "    )\n",
    ") & (  # let more infill through only in this case...\n",
    "    (\n",
    "        df[\"upvote_count\"] >= 0\n",
    "    )  # (df[\"upvote_count\"] >= 1)  (df[\"pos_diff_preference\"] == 2)\n",
    "    | (df[\"reaction_play_count\"] >= 1)\n",
    "    | (df[\"concat_play_counts\"] >= 1)\n",
    ")\n",
    "pos_filter_higher_quality = (df[\"preference\"]) & (\n",
    "    high_quality_tasks_filter | medium_quality_tasks_filter\n",
    ")\n",
    "print(\n",
    "    \"after filter on higher quality\",\n",
    "    round(pos_filter_higher_quality.sum() / total_positive, 4),\n",
    ")\n",
    "\n",
    "user_gen_filter = (\n",
    "    df[\"user_n_clips\"] >= 100\n",
    ")  # user needs to have genereated at least 100 over the time period\n",
    "\n",
    "print(\"----------------\")\n",
    "pos_filter_selectin_mask = (\n",
    "    (df[\"preference\"])  # get basics aligned\n",
    "    & all_fitlers\n",
    "    & infill_duration_filter\n",
    "    & pos_filter_continues\n",
    "    & pos_filter_reaction_play_count\n",
    "    & pos_filter_relative_play_count\n",
    "    & pos_filter_cer_diff_preference\n",
    "    & pos_filter_bad_flags\n",
    "    & pos_filter_play_counts\n",
    "    & pos_filter_higher_quality\n",
    "    & user_gen_filter\n",
    ")\n",
    "print(\n",
    "    \"negative\",\n",
    "    sum(neg_filter_selection_mask),\n",
    "    \"positive\",\n",
    "    sum(pos_filter_selectin_mask),\n",
    ")\n",
    "\n",
    "neg_filter_requests = df[neg_filter_selection_mask][\"request_id\"].unique()\n",
    "pos_filter_requests = df[pos_filter_selectin_mask][\"request_id\"].unique()\n",
    "# looking for very strong signal here:\n",
    "# listen to the positive/negative more than once\n",
    "# disliked one of the clips\n",
    "unique_requests = set(pos_filter_requests).intersection(neg_filter_requests)\n",
    "print(\"----------------\")\n",
    "print(\n",
    "    \"total pair requests\",\n",
    "    df[\"request_id\"].nunique(),\n",
    "    \" --> selected pair requests\",\n",
    "    len(unique_requests),\n",
    "    f\"frac {len(unique_requests) / df['request_id'].nunique():.3f}\",\n",
    ")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-05-16T13:59:41.250737Z",
     "start_time": "2024-05-16T13:59:41.036434Z"
    },
    "execution": {
     "iopub.execute_input": "2025-06-03T18:50:34.560925Z",
     "iopub.status.busy": "2025-06-03T18:50:34.560763Z",
     "iopub.status.idle": "2025-06-03T18:50:35.016290Z",
     "shell.execute_reply": "2025-06-03T18:50:35.015931Z",
     "shell.execute_reply.started": "2025-06-03T18:50:34.560912Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "auk_mix_t1_v14 requests 63272 clips 126544 total khrs 5.382; N gpus for 1000 iters 7.909; 4 gpus for x iters 1977.250; n unique users 26926 n pro users 26111\n"
     ]
    }
   ],
   "source": [
    "df_slice = df[df[\"request_id\"].isin(set(unique_requests))].copy()\n",
    "print(\n",
    "    f\"{os.path.basename(OUT_DATA_DIR)} requests\",\n",
    "    df_slice[\"request_id\"].nunique(),\n",
    "    \"clips\",\n",
    "    df_slice.shape[0],\n",
    "    f\"total khrs {sum(df_slice['duration'] / 3600 / 1000):.3f};\",\n",
    "    f\"N gpus for 1000 iters {df_slice.shape[0] / 8 / 2 / 1000:.3f};\",\n",
    "    f\"4 gpus for x iters {df_slice.shape[0] / 8 / 2 / 4:.3f};\",\n",
    "    f\"n unique users {df_slice['user_id'].nunique()}\",\n",
    "    f\"n pro users {df_slice[df_slice['is_pro_user']]['user_id'].nunique()}\",\n",
    ")\n",
    "# 76171 152342 total khrs 2.880 n gpus for 1250 iters 3.809\n",
    "# v10 has 78866\n",
    "# v14 has 110402\n",
    "# 30b_t4_v12 requests 47755 clips 95510 total khrs 4.555; N gpus for 1000 iters 5.969; 4 gpus for x iters 1492.344; n unique users 13790 n pro users 13526\n",
    "# 30b_t4_v20 requests 18306 clips 36612 total khrs 1.754; N gpus for 1000 iters 2.288; 4 gpus for x iters 572.062; n unique users 6943 n pro users 6714\n",
    "# 30b_t5_v5 requests 21318 clips 42636 total khrs 1.938; N gpus for 1000 iters 2.665; 4 gpus for x iters 666.188; n unique users 11661 n pro users 9347\n",
    "# 30b_t5_v6 requests 22833 clips 45666 total khrs 2.072; N gpus for 1000 iters 2.854; 4 gpus for x iters 713.531; n unique users 12576 n pro users 9910\n",
    "# 30b_t5_v7 requests 33197 clips 66394 total khrs 2.846; N gpus for 1000 iters 4.150; 4 gpus for x iters 1037.406; n unique users 16665 n pro users 13050\n",
    "# 30b_t5_v8 requests 20907 clips 41814 total khrs 1.629; N gpus for 1000 iters 2.613; 4 gpus for x iters 653.344; n unique users 11102 n pro users 9052\n",
    "# 30b_t5_v9 requests 24645 clips 49290 total khrs 1.918; N gpus for 1000 iters 3.081; 4 gpus for x iters 770.156; n unique users 12661 n pro users 10229\n",
    "# 30b_t5_v11 requests 21975 clips 43950 total khrs 1.508; N gpus for 1000 iters 2.747; 4 gpus for x iters 686.719; n unique users 11173 n pro users 9270\n",
    "# 30b_t5_v12 requests 21436 clips 42872 total khrs 1.582; N gpus for 1000 iters 2.679; 4 gpus for x iters 669.875; n unique users 11553 n pro users 9374\n",
    "# 30b_t5_v13 requests 25912 clips 51824 total khrs 1.922; N gpus for 1000 iters 3.239; 4 gpus for x iters 809.750; n unique users 13429 n pro users 10737\n",
    "# 30b_t5_v14 requests 27687 clips 55374 total khrs 2.036; N gpus for 1000 iters 3.461; 4 gpus for x iters 865.219; n unique users 14196 n pro users 11227\n",
    "# 30b_t5_v15 requests 29563 clips 59126 total khrs 2.225; N gpus for 1000 iters 3.695; 4 gpus for x iters 923.844; n unique users 14684 n pro users 11642\n",
    "# 30b_t6_v1 requests 24678 clips 49356 total khrs 1.934; N gpus for 1000 iters 3.085; 4 gpus for x iters 771.188; n unique users 11350 n pro users 10065\n",
    "# 30b_t6_v2 requests 49341 clips 98682 total khrs 4.332; N gpus for 1000 iters 6.168; 4 gpus for x iters 1541.906; n unique users 19992 n pro users 16972\n",
    "# 30b_t6_v3 requests 54967 clips 109934 total khrs 4.826; N gpus for 1000 iters 6.871; 4 gpus for x iters 1717.719; n unique users 21653 n pro users 18266\n",
    "# 30b_t6_v5 requests 29459 clips 58918 total khrs 2.657; N gpus for 1000 iters 3.682; 4 gpus for x iters 920.594; n unique users 14091 n pro users 11884\n",
    "# 30b_t6_v7 requests 40056 clips 80112 total khrs 3.354; N gpus for 1000 iters 5.007; 4 gpus for x iters 1251.750; n unique users 17440 n pro users 14476\n",
    "# 30b_t6_v8 requests 31681 clips 63362 total khrs 2.681; N gpus for 1000 iters 3.960; 4 gpus for x iters 990.031; n unique users 15180 n pro users 15078\n",
    "# 30b_t6_v9 requests 55785 clips 111570 total khrs 4.727; N gpus for 1000 iters 6.973; 4 gpus for x iters 1743.281; n unique users 23114 n pro users 22871\n",
    "# 30b_t6_v10 requests 52209 clips 104418 total khrs 4.515; N gpus for 1000 iters 6.526; 4 gpus for x iters 1631.531; n unique users 22216 n pro users 21893\n",
    "# 30b_t6_v11 requests 31338 clips 62676 total khrs 2.493; N gpus for 1000 iters 3.917; 4 gpus for x iters 979.312; n unique users 15190 n pro users 14973\n",
    "# 30b_t6_v13 requests 50856 clips 101712 total khrs 3.987; N gpus for 1000 iters 6.357; 4 gpus for x iters 1589.250; n unique users 23547 n pro users 23097\n",
    "# 30b_t6_v15 requests 65213 clips 130426 total khrs 5.217; N gpus for 1000 iters 8.152; 4 gpus for x iters 2037.906; n unique users 28763 n pro users 27964\n",
    "# 30b_t6_v16 requests 37907 clips 75814 total khrs 2.956; N gpus for 1000 iters 4.738; 4 gpus for x iters 1184.594; n unique users 18448 n pro users 17212\n",
    "# 30b_t6_v17 requests 51543 clips 103086 total khrs 4.154; N gpus for 1000 iters 6.443; 4 gpus for x iters 1610.719; n unique users 24223 n pro users 21829\n",
    "# 30b_t6_v18 requests 94965 clips 189930 total khrs 7.483; N gpus for 1000 iters 11.871; 4 gpus for x iters 2967.656; n unique users 23852 n pro users 21767\n",
    "# 30b_t6_v19 requests 34289 clips 68578 total khrs 2.846; N gpus for 1000 iters 4.286; 4 gpus for x iters 1071.531; n unique users 11802 n pro users 10830\n",
    "# 30b_t6_v20 requests 53258 clips 106516 total khrs 4.270; N gpus for 1000 iters 6.657; 4 gpus for x iters 1664.312; n unique users 22096 n pro users 21171\n",
    "# 30b_t6_v22 requests 29971 clips 59942 total khrs 1.992; N gpus for 1000 iters 3.746; 4 gpus for x iters 936.594; n unique users 13611 n pro users 13036\n",
    "# 30b_t6_v24 requests 45333 clips 90666 total khrs 3.343; N gpus for 1000 iters 5.667; 4 gpus for x iters 1416.656; n unique users 18853 n pro users 18049\n",
    "# 30b_t6_v25 requests 28154 clips 56308 total khrs 2.401; N gpus for 1000 iters 3.519; 4 gpus for x iters 879.812; n unique users 12946 n pro users 12361\n",
    "# 30b_t6_v26 requests 30428 clips 60856 total khrs 2.599; N gpus for 1000 iters 3.804; 4 gpus for x iters 950.875; n unique users 13822 n pro users 13163\n",
    "# 30b_t6_v27 requests 43731 clips 87462 total khrs 3.862; N gpus for 1000 iters 5.466; 4 gpus for x iters 1366.594; n unique users 17898 n pro users 16865\n",
    "# 30b_t6_v28 requests 56869 clips 113738 total khrs 5.064; N gpus for 1000 iters 7.109; 4 gpus for x iters 1777.156; n unique users 22004 n pro users 20244\n",
    "# 30b_t6_v29 requests 32729 clips 65458 total khrs 2.604; N gpus for 1000 iters 4.091; 4 gpus for x iters 1022.781; n unique users 13739 n pro users 13503\n",
    "# 30b_t6_v30 requests 32553 clips 65106 total khrs 2.592; N gpus for 1000 iters 4.069; 4 gpus for x iters 1017.281; n unique users 13712 n pro users 13478\n",
    "# 30b_t6_v31 requests 41523 clips 83046 total khrs 3.164; N gpus for 1000 iters 5.190; 4 gpus for x iters 1297.594; n unique users 16266 n pro users 15967\n",
    "# 30b_t6_v32 requests 55942 clips 111884 total khrs 4.361; N gpus for 1000 iters 6.993; 4 gpus for x iters 1748.188; n unique users 20808 n pro users 20271\n",
    "# 30b_t6_v33 requests 182096 clips 364192 total khrs 13.745; N gpus for 1000 iters 22.762; 4 gpus for x iters 5690.500; n unique users 40437 n pro users 34524\n",
    "# auk_mix_t1_v2 requests 102002 clips 204004 total khrs 9.191; N gpus for 1000 iters 12.750; 4 gpus for x iters 3187.562; n unique users 36408 n pro users 34038\n",
    "# auk_mix_t1_v13 requests 53011 clips 106022 total khrs 4.496; N gpus for 1000 iters 6.626; 4 gpus for x iters 1656.594; n unique users 23713 n pro users 23117\n",
    "# auk_mix_t1_v14 requests 63272 clips 126544 total khrs 5.382; N gpus for 1000 iters 7.909; 4 gpus for x iters 1977.250; n unique users 26926 n pro users 26111"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-05-16T13:59:41.277006Z",
     "start_time": "2024-05-16T13:59:41.252105Z"
    },
    "execution": {
     "iopub.execute_input": "2025-06-03T18:50:35.016936Z",
     "iopub.status.busy": "2025-06-03T18:50:35.016692Z",
     "iopub.status.idle": "2025-06-03T18:50:35.067301Z",
     "shell.execute_reply": "2025-06-03T18:50:35.066966Z",
     "shell.execute_reply.started": "2025-06-03T18:50:35.016922Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "positive in playlist (13493, 159)\n",
      "task\n",
      "cover                 53704\n",
      "artist_consistency    51122\n",
      "infill                21718\n",
      "Name: count, dtype: int64\n"
     ]
    }
   ],
   "source": [
    "test_mask = (df_slice[\"preference\"]) & (\n",
    "    (df_slice[\"is_in_playlist\"]) | (df_slice[\"concat_in_playlist\"])\n",
    ")\n",
    "print(\"positive in playlist\", df_slice[test_mask].shape)\n",
    "print(df_slice[\"task\"].value_counts())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {
    "execution": {
     "iopub.execute_input": "2025-06-03T18:50:35.067867Z",
     "iopub.status.busy": "2025-06-03T18:50:35.067676Z",
     "iopub.status.idle": "2025-06-03T18:50:35.201249Z",
     "shell.execute_reply": "2025-06-03T18:50:35.200924Z",
     "shell.execute_reply.started": "2025-06-03T18:50:35.067854Z"
    }
   },
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAjAAAAGeCAYAAACKDztsAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjkuMiwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8hTgPZAAAACXBIWXMAAA9hAAAPYQGoP6dpAAAtaElEQVR4nO3dfXBUVZ7/8U/fTiKBPBDSAcyCyo+YBOUhQSgm2FmWXdApwa0CdoUaVsRKCU5EsiMCFoOQgEWCCy6irlJIZUBlIzXqLKjUls4OFhYgapGhYCMQmeFhMlY6kZAHFJJ0//5g09IhJN2QfjjJ+1VFkb73dN9zv7khH+45916bx+PxCAAAwCBWuDsAAAAQKAIMAAAwDgEGAAAYhwADAACMQ4ABAADGIcAAAADjEGAAAIBxCDAAAMA4BBgAAGAcAgwAADBOQAFmy5YtmjVrlrKzs5WTk6P8/HydPn3ap82jjz6qjIwMnz+rVq3yaVNVVaUFCxZozJgxysnJ0fr169XS0uLT5osvvtCMGTM0cuRITZ06Ve+///5N7iIAAOhpogJpfPjwYc2dO1ejRo1Sa2urXnrpJeXl5emjjz5S3759ve0eeeQRLV682Ps6NjbW+3Vra6sWLlwoh8OhsrIyVVdXa/ny5YqOjtYzzzwjSTp37pwWLlyoOXPmaMOGDTp48KBWrlyplJQU5ebmBrSDtbUNCuXTnmw2KTk5PuTbNQ118g918g916ho18g918k8w69T22V0JKMBs27bN53VJSYlycnJ0/PhxjR8/3ru8T58+SklJ6fAzPv/8c1VWVqq0tFQOh0MjRoxQQUGBNmzYoEWLFikmJkZlZWUaMmSInnvuOUnS8OHD9fXXX+s3v/lNwAHG41FYDsJwbdc01Mk/1Mk/1Klr1Mg/1Mk/4axTQAGmvY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8+/epXv/KOJ1++fFklJSX66KOPdOXKFTmdTq1evbpHnY7tyBdffKF58+Zdt3zGjBkqKSmRx+PR5s2btWvXLtXX1+u+++7T6tWrNWzYMG/buro6rV27Vv/zP/8jy7L0wAMPaOXKlerXr18odyWoOqtTYWGhnnrqKf3v//6vGhoaNHDgQN1///0qKCjwGbbt6XXKyMjocHlxcbH3P0/+/Jz95S9/UWFhoQ4fPqzY2FjNmDFDS5YsUVRUz/g/bld1+utf/6qlS5fq1KlTunTpkm6//XZNmTJF+fn5iouL87bv6XVasWKFDh06pOrqasXHxysjI0NPPPGE7r//fkmRdywRYAAAgHGYAwMAAIxDgAEAAMYhwAAAAOMQYAAAgHEIMAAAwDgEGAAAYBwCDAAAMA4BBgAAGIcAAwAAjEOAAQAAxiHAAAAA4/x/5VvcCvmv9KQAAAAASUVORK5CYII=",
      "text/plain": [
       "<Figure size 640x480 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "df_slice[\"post_infill_duration\"].hist(bins=np.linspace(-5, 300, 100))\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-05-16T13:59:41.323409Z",
     "start_time": "2024-05-16T13:59:41.278278Z"
    },
    "execution": {
     "iopub.execute_input": "2025-06-03T18:50:35.201815Z",
     "iopub.status.busy": "2025-06-03T18:50:35.201622Z",
     "iopub.status.idle": "2025-06-03T18:50:35.215331Z",
     "shell.execute_reply": "2025-06-03T18:50:35.215061Z",
     "shell.execute_reply.started": "2025-06-03T18:50:35.201801Z"
    }
   },
   "outputs": [],
   "source": [
    "# interesting_clips_must_be_positive_mask = (\n",
    "#     (df_slice[\"upvoted\"] == True)\n",
    "#     | (df_slice[\"has_action\"] == True)\n",
    "#     | (df_slice[\"part_of_concat\"] == True)\n",
    "# )\n",
    "# interesting_clips_must_be_not_negative_mask = (df_slice[\"downvoted\"] == False) # & (df_slice[\"dislike_count\"] < 1)\n",
    "# interesting_clips_mask = interesting_clips_must_be_positive_mask & interesting_clips_must_be_not_negative_mask\n",
    "# assert interesting_clips_mask.eq(df_slice[\"preference\"]).all()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-05-16T13:59:41.392244Z",
     "start_time": "2024-05-16T13:59:41.324472Z"
    },
    "execution": {
     "iopub.execute_input": "2025-06-03T18:50:35.215816Z",
     "iopub.status.busy": "2025-06-03T18:50:35.215644Z",
     "iopub.status.idle": "2025-06-03T18:50:35.225703Z",
     "shell.execute_reply": "2025-06-03T18:50:35.225448Z",
     "shell.execute_reply.started": "2025-06-03T18:50:35.215805Z"
    }
   },
   "outputs": [],
   "source": [
    "# save positive ids\n",
    "# positive_preference_ids = df_slice[df_slice[\"preference\"] == False][\"s3_id\"].to_json(orient='values')\n",
    "# with open('/home/tony/Data/Preference/7b_v2/7v_v20_full_recut_id_negative.json', 'w') as file:\n",
    "#     file.write(positive_preference_ids)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {
    "execution": {
     "iopub.execute_input": "2025-06-03T18:50:35.226170Z",
     "iopub.status.busy": "2025-06-03T18:50:35.226004Z",
     "iopub.status.idle": "2025-06-03T18:50:35.235969Z",
     "shell.execute_reply": "2025-06-03T18:50:35.235713Z",
     "shell.execute_reply.started": "2025-06-03T18:50:35.226159Z"
    }
   },
   "outputs": [],
   "source": [
    "# df_slice_2 = pd.read_pickle(\"/home/tony/Data/Preference/30b_v6/interesting_clips_v4_t_6_20241118_full_slice.pkl\")\n",
    "# df_total = pd.concat([df_slice, df_slice_2])\n",
    "# print(df_total.shape)\n",
    "# df_slice = df_total"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {
    "execution": {
     "iopub.execute_input": "2025-06-03T18:50:35.236465Z",
     "iopub.status.busy": "2025-06-03T18:50:35.236269Z",
     "iopub.status.idle": "2025-06-03T18:50:35.246348Z",
     "shell.execute_reply": "2025-06-03T18:50:35.246094Z",
     "shell.execute_reply.started": "2025-06-03T18:50:35.236454Z"
    }
   },
   "outputs": [],
   "source": [
    "# df_slice_prev = pd.read_pickle(\n",
    "#     \"/home/tony/Data/Preference/30b_v2/interesting_clips_v4_t_3_v13_20240902_slice.pkl\"\n",
    "# )\n",
    "# df_slice_prev = df_slice_prev[\n",
    "#     (\n",
    "#         (df_slice_prev[\"task\"] != \"infill\")\n",
    "#         & (df_slice_prev[\"task\"] != \"cover\")\n",
    "#         & (df_slice_prev[\"task\"] != \"artist_consistency\")\n",
    "#     )\n",
    "# ].copy()\n",
    "# df_slice = pd.concat([df_slice, df_slice_prev])\n",
    "# print(df_slice.shape)\n",
    "# print(df_slice[\"task\"].value_counts())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {
    "execution": {
     "iopub.execute_input": "2025-06-03T18:50:35.246835Z",
     "iopub.status.busy": "2025-06-03T18:50:35.246651Z",
     "iopub.status.idle": "2025-06-03T18:50:35.256718Z",
     "shell.execute_reply": "2025-06-03T18:50:35.256463Z",
     "shell.execute_reply.started": "2025-06-03T18:50:35.246823Z"
    }
   },
   "outputs": [],
   "source": [
    "# df_slice[(df_slice[\"preference\"]) & ((df_slice[\"task\"].str.strip() == \"\") | (df_slice[\"task\"].str.strip() == \"cover\"))].to_pickle(\n",
    "#     \"/home/tony/Data/Preference/30b_v5/interesting_clips_v4_t_5_20241018_full_with_cer_pos_gen.pkl\"\n",
    "# )\n",
    "# df_slice[(df_slice[\"preference\"]) & ((df_slice[\"task\"].str.strip() == \"\") | (df_slice[\"task\"].str.strip() == \"cover\"))].shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "metadata": {
    "execution": {
     "iopub.execute_input": "2025-06-03T18:50:35.257162Z",
     "iopub.status.busy": "2025-06-03T18:50:35.257016Z",
     "iopub.status.idle": "2025-06-03T18:50:35.267032Z",
     "shell.execute_reply": "2025-06-03T18:50:35.266774Z",
     "shell.execute_reply.started": "2025-06-03T18:50:35.257151Z"
    }
   },
   "outputs": [],
   "source": [
    "# df_slice.to_pickle(\"/home/tony/Data/Preference/30b_v6/interesting_clips_v4_h_t_6_20250108_full_slice.pkl\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "metadata": {
    "execution": {
     "iopub.execute_input": "2025-06-03T18:50:35.267490Z",
     "iopub.status.busy": "2025-06-03T18:50:35.267325Z",
     "iopub.status.idle": "2025-06-03T18:50:35.277243Z",
     "shell.execute_reply": "2025-06-03T18:50:35.276985Z",
     "shell.execute_reply.started": "2025-06-03T18:50:35.267479Z"
    }
   },
   "outputs": [],
   "source": [
    "# with open(\"/home/tony/Data/Preference/30b_v6/similarities_30b_t6.json\", \"r\") as fp:\n",
    "#     all_similarities = json.load(fp)\n",
    "\n",
    "# df_slice[\"similarity\"] = df_slice[\"id\"].map(all_similarities)\n",
    "# df_cover = df_slice[df_slice[\"task\"] == \"cover\"].copy()\n",
    "# df_artist = df_slice[df_slice[\"task\"] == \"artist_consistency\"].copy()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "metadata": {
    "execution": {
     "iopub.execute_input": "2025-06-03T18:50:35.277739Z",
     "iopub.status.busy": "2025-06-03T18:50:35.277546Z",
     "iopub.status.idle": "2025-06-03T18:50:35.287627Z",
     "shell.execute_reply": "2025-06-03T18:50:35.287374Z",
     "shell.execute_reply.started": "2025-06-03T18:50:35.277728Z"
    }
   },
   "outputs": [],
   "source": [
    "# df_cover[df_cover[\"preference\"]][\"similarity\"].hist(bins=200, label=\"positive\", alpha=0.5)\n",
    "# df_cover[~df_cover[\"preference\"]][\"similarity\"].hist(bins=200, label=\"negative\", alpha=0.5)\n",
    "# plt.legend()\n",
    "# plt.show()\n",
    "# df_cover[\"similarity_diff\"] = df_cover[\"similarity\"].diff()\n",
    "# df_cover[df_cover[\"preference\"]][\"similarity_diff\"].hist(bins=200)\n",
    "# plt.show()\n",
    "# df_cover[\"continued_parent\"] = None\n",
    "# df_cover[\"continue_at\"] = -1\n",
    "# too_similar = (df_cover[\"similarity\"] >= 0.99)\n",
    "# too_different = ( df_cover[\"similarity\"] < 0.25)\n",
    "# too_big_difference = (df_cover[\"similarity_diff\"] < -0.2)\n",
    "# df_cover_drops_id = df_cover[\n",
    "#     (df_cover[\"preference\"])\n",
    "#     & (too_similar | too_different | too_big_difference)\n",
    "# ][\"s3_id\"].unique()\n",
    "# print(\"total rows\", df_cover.shape[0], \"total drops\", len(df_cover_drops_id))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "metadata": {
    "execution": {
     "iopub.execute_input": "2025-06-03T18:50:35.288082Z",
     "iopub.status.busy": "2025-06-03T18:50:35.287920Z",
     "iopub.status.idle": "2025-06-03T18:50:35.298005Z",
     "shell.execute_reply": "2025-06-03T18:50:35.297748Z",
     "shell.execute_reply.started": "2025-06-03T18:50:35.288071Z"
    }
   },
   "outputs": [],
   "source": [
    "# df_artist[df_artist[\"preference\"]][\"similarity\"].hist(bins=200, label=\"positive\", alpha=0.5)\n",
    "# df_artist[~df_artist[\"preference\"]][\"similarity\"].hist(bins=200, label=\"negative\", alpha=0.5)\n",
    "# plt.legend()\n",
    "# plt.show()\n",
    "# df_artist[\"similarity_diff\"] = df_artist[\"similarity\"].diff()\n",
    "# df_artist[df_artist[\"preference\"]][\"similarity_diff\"].hist(bins=200)\n",
    "# plt.show()\n",
    "# too_similar = (df_artist[\"similarity\"] >= 0.95)\n",
    "# too_different = ( df_artist[\"similarity\"] < 0.4)\n",
    "# too_big_difference = (df_artist[\"similarity_diff\"] < -0.2)\n",
    "# df_artist_drops_id = df_artist[\n",
    "#     (df_artist[\"preference\"])\n",
    "#     & (too_similar | too_different | too_big_difference)\n",
    "# ][\"s3_id\"].unique()\n",
    "# print(\"total rows\", df_artist.shape[0], \"total drops\", len(df_artist_drops_id))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "metadata": {
    "execution": {
     "iopub.execute_input": "2025-06-03T18:50:35.298447Z",
     "iopub.status.busy": "2025-06-03T18:50:35.298301Z",
     "iopub.status.idle": "2025-06-03T18:50:35.308335Z",
     "shell.execute_reply": "2025-06-03T18:50:35.308084Z",
     "shell.execute_reply.started": "2025-06-03T18:50:35.298436Z"
    }
   },
   "outputs": [],
   "source": [
    "# print(\"before filter on cover similarity\", df_slice.shape)\n",
    "# df_slice = df_slice[~df_slice[\"s3_id\"].isin(df_cover_drops_id)].copy()\n",
    "# print(\"after filter on cover similarity\", df_slice.shape)\n",
    "# df_slice = df_slice[~df_slice[\"s3_id\"].isin(df_artist_drops_id)].copy()\n",
    "# print(\"after filter on artist similarity\", df_slice.shape)\n",
    "# df_slice = df_slice[\n",
    "#     df_slice[\"request_id\"].isin(\n",
    "#         df_slice[\"request_id\"].value_counts().index[df_slice[\"request_id\"].value_counts() == 2]\n",
    "#     )\n",
    "# ]\n",
    "# print(\"after filter on request id pairs\", df_slice.shape)\n",
    "# print(df_slice.groupby([\"preference\"])[\"model_name\"].value_counts())\n",
    "# assert df_slice.shape[0] == df_slice[\"request_id\"].nunique() * 2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "metadata": {
    "execution": {
     "iopub.execute_input": "2025-06-03T18:50:35.308788Z",
     "iopub.status.busy": "2025-06-03T18:50:35.308627Z",
     "iopub.status.idle": "2025-06-03T18:50:35.319960Z",
     "shell.execute_reply": "2025-06-03T18:50:35.319700Z",
     "shell.execute_reply.started": "2025-06-03T18:50:35.308777Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "is_public\n",
      "False    121494\n",
      "True       5050\n",
      "Name: count, dtype: int64\n"
     ]
    }
   ],
   "source": [
    "print(df_slice[\"is_public\"].value_counts())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "metadata": {
    "execution": {
     "iopub.execute_input": "2025-06-03T18:50:35.320436Z",
     "iopub.status.busy": "2025-06-03T18:50:35.320253Z",
     "iopub.status.idle": "2025-06-03T18:50:35.352175Z",
     "shell.execute_reply": "2025-06-03T18:50:35.351860Z",
     "shell.execute_reply.started": "2025-06-03T18:50:35.320425Z"
    }
   },
   "outputs": [],
   "source": [
    "df_slice[\"npz_path\"] = df_slice[\"s3_id\"].map(lambda x: f\"{NPZ_DIR}/{x}.npz\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-05-16T14:00:20.866354Z",
     "start_time": "2024-05-16T14:00:12.443344Z"
    },
    "execution": {
     "iopub.execute_input": "2025-06-03T18:50:35.352703Z",
     "iopub.status.busy": "2025-06-03T18:50:35.352523Z",
     "iopub.status.idle": "2025-06-03T18:50:35.997156Z",
     "shell.execute_reply": "2025-06-03T18:50:35.995850Z",
     "shell.execute_reply.started": "2025-06-03T18:50:35.352691Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(126544, 160)\n",
      "task\n",
      "cover                 53704\n",
      "artist_consistency    51122\n",
      "infill                21718\n",
      "Name: count, dtype: int64\n",
      "(104826, 160)\n",
      "task\n",
      "cover                 53704\n",
      "artist_consistency    51122\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[36], 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_20250426_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([\"cover\", \"artist_consistency\"])].copy()\n",
    "print(df_slice.shape)\n",
    "print(df_slice[\"task\"].value_counts())\n",
    "BREAK"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "metadata": {
    "execution": {
     "iopub.execute_input": "2025-06-03T18:51:22.836920Z",
     "iopub.status.busy": "2025-06-03T18:51:22.836662Z",
     "iopub.status.idle": "2025-06-03T18:51:29.217557Z",
     "shell.execute_reply": "2025-06-03T18:51:29.217200Z",
     "shell.execute_reply.started": "2025-06-03T18:51:22.836904Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(201960, 168)\n",
      "task\n",
      "                 193040\n",
      "upload_extend      4992\n",
      "extend             3928\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_20250412_20250501_full_long_slice.pkl\"\n",
    ")\n",
    "print(df_13b_slice.shape)\n",
    "print(df_13b_slice[\"task\"].value_counts())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "metadata": {
    "execution": {
     "iopub.execute_input": "2025-06-03T18:51:29.218356Z",
     "iopub.status.busy": "2025-06-03T18:51:29.218166Z",
     "iopub.status.idle": "2025-06-03T18:51:29.297846Z",
     "shell.execute_reply": "2025-06-03T18:51:29.297497Z",
     "shell.execute_reply.started": "2025-06-03T18:51:29.218343Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(104826, 160)\n",
      "task\n",
      "cover                 53704\n",
      "artist_consistency    51122\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": 39,
   "metadata": {
    "execution": {
     "iopub.execute_input": "2025-06-03T18:51:29.298429Z",
     "iopub.status.busy": "2025-06-03T18:51:29.298226Z",
     "iopub.status.idle": "2025-06-03T18:51:31.598782Z",
     "shell.execute_reply": "2025-06-03T18:51:31.598434Z",
     "shell.execute_reply.started": "2025-06-03T18:51:29.298416Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(306786, 174)\n",
      "task\n",
      "                      193040\n",
      "cover                  53704\n",
      "artist_consistency     51122\n",
      "upload_extend           4992\n",
      "extend                  3928\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": 40,
   "metadata": {
    "execution": {
     "iopub.execute_input": "2025-06-03T18:51:31.599367Z",
     "iopub.status.busy": "2025-06-03T18:51:31.599166Z",
     "iopub.status.idle": "2025-06-03T18:51:32.358937Z",
     "shell.execute_reply": "2025-06-03T18:51:32.358525Z",
     "shell.execute_reply.started": "2025-06-03T18:51:31.599353Z"
    }
   },
   "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": 41,
   "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:51:32.360028Z",
     "iopub.status.busy": "2025-06-03T18:51:32.359826Z",
     "iopub.status.idle": "2025-06-03T18:51:32.384119Z",
     "shell.execute_reply": "2025-06-03T18:51:32.383751Z",
     "shell.execute_reply.started": "2025-06-03T18:51:32.360015Z"
    }
   },
   "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": 42,
   "metadata": {
    "execution": {
     "iopub.execute_input": "2025-06-03T18:51:32.384670Z",
     "iopub.status.busy": "2025-06-03T18:51:32.384492Z",
     "iopub.status.idle": "2025-06-03T18:51:33.187908Z",
     "shell.execute_reply": "2025-06-03T18:51:33.187547Z",
     "shell.execute_reply.started": "2025-06-03T18:51:32.384658Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(306786, 174)\n",
      "(306786, 174)\n",
      "(306786, 174)\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": 43,
   "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:51:33.188429Z",
     "iopub.status.busy": "2025-06-03T18:51:33.188303Z",
     "iopub.status.idle": "2025-06-03T18:51:33.273381Z",
     "shell.execute_reply": "2025-06-03T18:51:33.273015Z",
     "shell.execute_reply.started": "2025-06-03T18:51:33.188416Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "153393\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": 44,
   "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:51:33.273958Z",
     "iopub.status.busy": "2025-06-03T18:51:33.273768Z",
     "iopub.status.idle": "2025-06-03T18:51:33.289902Z",
     "shell.execute_reply": "2025-06-03T18:51:33.289634Z",
     "shell.execute_reply.started": "2025-06-03T18:51:33.273945Z"
    }
   },
   "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": 45,
   "metadata": {
    "execution": {
     "iopub.execute_input": "2025-06-03T18:51:33.290361Z",
     "iopub.status.busy": "2025-06-03T18:51:33.290209Z",
     "iopub.status.idle": "2025-06-03T18:51:33.300501Z",
     "shell.execute_reply": "2025-06-03T18:51:33.300246Z",
     "shell.execute_reply.started": "2025-06-03T18:51:33.290349Z"
    }
   },
   "outputs": [],
   "source": [
    "# df_slice[\"continue_at\"] = -1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 46,
   "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:51:33.300975Z",
     "iopub.status.busy": "2025-06-03T18:51:33.300802Z",
     "iopub.status.idle": "2025-06-03T18:51:34.807160Z",
     "shell.execute_reply": "2025-06-03T18:51:34.806809Z",
     "shell.execute_reply.started": "2025-06-03T18:51:33.300964Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "151859 1534\n",
      "(303718, 174) (3068, 174)\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": 47,
   "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:51:34.807744Z",
     "iopub.status.busy": "2025-06-03T18:51:34.807545Z",
     "iopub.status.idle": "2025-06-03T18:51:41.670198Z",
     "shell.execute_reply": "2025-06-03T18:51:41.669838Z",
     "shell.execute_reply.started": "2025-06-03T18:51:34.807731Z"
    }
   },
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "100%|██████████████████████████████████████████████████████████████████████████████████████████████████████| 303718/303718 [00:06<00:00, 44362.36it/s]"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "15,638 hours of 303718 clips, 18.982375 nodes, 3163.7291666666665 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": 48,
   "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:51:41.670782Z",
     "iopub.status.busy": "2025-06-03T18:51:41.670586Z",
     "iopub.status.idle": "2025-06-03T18:52:25.994438Z",
     "shell.execute_reply": "2025-06-03T18:52:25.994082Z",
     "shell.execute_reply.started": "2025-06-03T18:51:41.670768Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "t_data_memmap is set to: 6016\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "100%|█████████████████████████████████████████████████████████████████████████████████████████████████████████████| 3068/3068 [00:44<00:00, 69.29it/s]"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Total 3068 clips, 0 different prompts\n",
      "89 hours of False\n",
      "87 hours of True\n",
      "gen: 105.0 hours\n",
      "cover: 30.6 hours\n",
      "artist_consistency: 34.1 hours\n",
      "extend: 6.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": 49,
   "metadata": {
    "execution": {
     "iopub.execute_input": "2025-06-03T18:52:25.994970Z",
     "iopub.status.busy": "2025-06-03T18:52:25.994821Z",
     "iopub.status.idle": "2025-06-03T18:52:26.781829Z",
     "shell.execute_reply": "2025-06-03T18:52:26.781430Z",
     "shell.execute_reply.started": "2025-06-03T18:52:25.994958Z"
    }
   },
   "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": 50,
   "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:52:26.783432Z",
     "iopub.status.busy": "2025-06-03T18:52:26.783241Z",
     "iopub.status.idle": "2025-06-03T20:07:51.453039Z",
     "shell.execute_reply": "2025-06-03T20:07:51.452579Z",
     "shell.execute_reply.started": "2025-06-03T18:52:26.783420Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "t_data_memmap is set to: 6016\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      " 35%|████████████████████████████████████▍                                                                    | 105513/303718 [25:56<45:15, 72.99it/s]"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "weird, /app/suno/data/dpo/30b_npz/c1150a74-6d63-43b1-b3e5-41d74a4b3c63.npz, with only v3.0\n",
      "105499, 'artist_arr is not a file in the archive', artist_consistency, /app/suno/data/dpo/30b_npz/c1150a74-6d63-43b1-b3e5-41d74a4b3c63.npz.\n",
      "WTF --> 105499, 'artist_arr is not a file in the archive', artist_consistency, /app/suno/data/dpo/30b_npz/c1150a74-6d63-43b1-b3e5-41d74a4b3c63.npz.\n",
      "WTF --> 105500, skip, preference: False, 937b20a3-a0fd-4d34-a0fc-7b86472dc271, task: .\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      " 61%|████████████████████████████████████████████████████████████████▎                                        | 186087/303718 [45:35<26:48, 73.12it/s]"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "186074, 'history_arr is not a file in the archive', upload_extend, /app/suno/data/dpo/13b_s32_npz/cf0c29c4-267e-4aa3-a3f8-009876019300.npz.\n",
      "WTF --> 186075, skip, preference: True, 3cb56754-6b0a-4492-9bce-299dff540fe1, task: upload_extend.\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      " 70%|█████████████████████████████████████████████████████████████████████████▎                               | 212013/303718 [51:53<21:37, 70.66it/s]"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "211998, 'history_arr is not a file in the archive', upload_extend, /app/suno/data/dpo/13b_s32_npz/a538ccbe-a313-4acf-99c7-317806e9d062.npz.\n",
      "WTF --> 211999, skip, preference: True, 83054a12-5b17-42f2-b702-7d025c5e3fe9, task: upload_extend.\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "100%|███████████████████████████████████████████████████████████████████████████████████████████████████████| 303718/303718 [1:15:24<00:00, 67.13it/s]\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Total 303712 clips, 30 different prompts\n",
      "8,807 hours of False\n",
      "8,683 hours of True\n",
      "gen: 10217.9 hours\n",
      "artist_consistency: 3355.6 hours\n",
      "extend: 497.6 hours\n",
      "cover: 3419.3 hours\n",
      "🚨 Error artist_consistency: 1\n",
      "🚨 Error upload_extend: 2\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": 51,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-05-16T13:59:41.937879Z",
     "start_time": "2024-05-16T13:59:41.937870Z"
    },
    "execution": {
     "iopub.execute_input": "2025-06-03T20:07:51.453690Z",
     "iopub.status.busy": "2025-06-03T20:07:51.453543Z",
     "iopub.status.idle": "2025-06-03T20:07:52.489344Z",
     "shell.execute_reply": "2025-06-03T20:07:52.488848Z",
     "shell.execute_reply.started": "2025-06-03T20:07:51.453675Z"
    }
   },
   "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": 52,
   "metadata": {
    "execution": {
     "iopub.execute_input": "2025-06-03T20:07:52.489976Z",
     "iopub.status.busy": "2025-06-03T20:07:52.489841Z",
     "iopub.status.idle": "2025-06-03T20:07:52.508923Z",
     "shell.execute_reply": "2025-06-03T20:07:52.508626Z",
     "shell.execute_reply.started": "2025-06-03T20:07:52.489962Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Counter({None: 1968, 'artist_consistency': 512, 'cover': 472, 'extend': 116})\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": 53,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-05-16T13:59:41.938629Z",
     "start_time": "2024-05-16T13:59:41.938621Z"
    },
    "execution": {
     "iopub.execute_input": "2025-06-03T20:07:52.509393Z",
     "iopub.status.busy": "2025-06-03T20:07:52.509280Z",
     "iopub.status.idle": "2025-06-03T20:07:52.520565Z",
     "shell.execute_reply": "2025-06-03T20:07:52.520277Z",
     "shell.execute_reply.started": "2025-06-03T20:07:52.509381Z"
    }
   },
   "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": 54,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-05-16T13:59:41.939205Z",
     "start_time": "2024-05-16T13:59:41.939198Z"
    },
    "execution": {
     "iopub.execute_input": "2025-06-03T20:07:52.521024Z",
     "iopub.status.busy": "2025-06-03T20:07:52.520913Z",
     "iopub.status.idle": "2025-06-03T20:07:52.531794Z",
     "shell.execute_reply": "2025-06-03T20:07:52.531502Z",
     "shell.execute_reply.started": "2025-06-03T20:07:52.521013Z"
    }
   },
   "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": 55,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-05-16T13:59:41.939977Z",
     "start_time": "2024-05-16T13:59:41.939969Z"
    },
    "execution": {
     "iopub.execute_input": "2025-06-03T20:07:52.532238Z",
     "iopub.status.busy": "2025-06-03T20:07:52.532130Z",
     "iopub.status.idle": "2025-06-03T20:07:52.542621Z",
     "shell.execute_reply": "2025-06-03T20:07:52.542340Z",
     "shell.execute_reply.started": "2025-06-03T20:07:52.532227Z"
    }
   },
   "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": 56,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-05-16T13:59:41.940610Z",
     "start_time": "2024-05-16T13:59:41.940603Z"
    },
    "execution": {
     "iopub.execute_input": "2025-06-03T20:07:52.543056Z",
     "iopub.status.busy": "2025-06-03T20:07:52.542950Z",
     "iopub.status.idle": "2025-06-03T20:07:52.553203Z",
     "shell.execute_reply": "2025-06-03T20:07:52.552918Z",
     "shell.execute_reply.started": "2025-06-03T20:07:52.543045Z"
    }
   },
   "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": 57,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-05-16T13:59:41.941167Z",
     "start_time": "2024-05-16T13:59:41.941159Z"
    },
    "execution": {
     "iopub.execute_input": "2025-06-03T20:07:52.553652Z",
     "iopub.status.busy": "2025-06-03T20:07:52.553542Z",
     "iopub.status.idle": "2025-06-03T20:07:52.564230Z",
     "shell.execute_reply": "2025-06-03T20:07:52.563947Z",
     "shell.execute_reply.started": "2025-06-03T20:07:52.553641Z"
    }
   },
   "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": 58,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-05-16T13:59:41.941801Z",
     "start_time": "2024-05-16T13:59:41.941793Z"
    },
    "execution": {
     "iopub.execute_input": "2025-06-03T20:07:52.564680Z",
     "iopub.status.busy": "2025-06-03T20:07:52.564572Z",
     "iopub.status.idle": "2025-06-03T20:07:52.579004Z",
     "shell.execute_reply": "2025-06-03T20:07:52.578725Z",
     "shell.execute_reply.started": "2025-06-03T20:07:52.564669Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1534 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": 59,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-05-16T13:59:41.942520Z",
     "start_time": "2024-05-16T13:59:41.942511Z"
    },
    "execution": {
     "iopub.execute_input": "2025-06-03T20:07:52.579456Z",
     "iopub.status.busy": "2025-06-03T20:07:52.579345Z",
     "iopub.status.idle": "2025-06-03T20:07:52.616801Z",
     "shell.execute_reply": "2025-06-03T20:07:52.616424Z",
     "shell.execute_reply.started": "2025-06-03T20:07:52.579444Z"
    }
   },
   "outputs": [],
   "source": [
    "train_info = read_json(os.path.join(OUT_DATA_DIR, f\"info_tr.json\"))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 60,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-05-16T13:59:41.943072Z",
     "start_time": "2024-05-16T13:59:41.943065Z"
    },
    "execution": {
     "iopub.execute_input": "2025-06-03T20:07:52.617329Z",
     "iopub.status.busy": "2025-06-03T20:07:52.617210Z",
     "iopub.status.idle": "2025-06-03T20:07:52.644453Z",
     "shell.execute_reply": "2025-06-03T20:07:52.644091Z",
     "shell.execute_reply.started": "2025-06-03T20:07:52.617317Z"
    }
   },
   "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": 61,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-05-16T13:59:41.944246Z",
     "start_time": "2024-05-16T13:59:41.944237Z"
    },
    "execution": {
     "iopub.execute_input": "2025-06-03T20:07:52.644970Z",
     "iopub.status.busy": "2025-06-03T20:07:52.644851Z",
     "iopub.status.idle": "2025-06-03T20:07:52.658030Z",
     "shell.execute_reply": "2025-06-03T20:07:52.657745Z",
     "shell.execute_reply.started": "2025-06-03T20:07:52.644957Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "total samples 303712 (303718, 174)\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": 62,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-05-16T13:59:41.945249Z",
     "start_time": "2024-05-16T13:59:41.945241Z"
    },
    "execution": {
     "iopub.execute_input": "2025-06-03T20:07:52.658485Z",
     "iopub.status.busy": "2025-06-03T20:07:52.658373Z",
     "iopub.status.idle": "2025-06-03T20:07:52.669600Z",
     "shell.execute_reply": "2025-06-03T20:07:52.669327Z",
     "shell.execute_reply.started": "2025-06-03T20:07:52.658474Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1 epoch per batch 4, total 4745.5\n"
     ]
    }
   ],
   "source": [
    "print(\"1 epoch per batch 4, total\", total_iters / 8 / 2 / 4)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 63,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-05-16T13:59:41.945972Z",
     "start_time": "2024-05-16T13:59:41.945964Z"
    },
    "execution": {
     "iopub.execute_input": "2025-06-03T20:07:52.670039Z",
     "iopub.status.busy": "2025-06-03T20:07:52.669932Z",
     "iopub.status.idle": "2025-06-03T20:07:52.680339Z",
     "shell.execute_reply": "2025-06-03T20:07:52.680059Z",
     "shell.execute_reply.started": "2025-06-03T20:07:52.670027Z"
    }
   },
   "outputs": [],
   "source": [
    "# !cd /home/tony/Work/tony/slurm/sem_4p5_dpo && sbatch sbatch_ipo_4p5"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 64,
   "metadata": {
    "execution": {
     "iopub.execute_input": "2025-06-03T20:07:52.680780Z",
     "iopub.status.busy": "2025-06-03T20:07:52.680672Z",
     "iopub.status.idle": "2025-06-03T20:07:52.702362Z",
     "shell.execute_reply": "2025-06-03T20:07:52.702062Z",
     "shell.execute_reply.started": "2025-06-03T20:07:52.680769Z"
    }
   },
   "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_2.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": 65,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-05-16T13:59:41.946562Z",
     "start_time": "2024-05-16T13:59:41.946555Z"
    },
    "execution": {
     "iopub.execute_input": "2025-06-03T20:07:52.702825Z",
     "iopub.status.busy": "2025-06-03T20:07:52.702715Z",
     "iopub.status.idle": "2025-06-03T20:07:52.714040Z",
     "shell.execute_reply": "2025-06-03T20:07:52.713754Z",
     "shell.execute_reply.started": "2025-06-03T20:07:52.702814Z"
    }
   },
   "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": 66,
   "metadata": {
    "execution": {
     "iopub.execute_input": "2025-06-03T20:07:52.714481Z",
     "iopub.status.busy": "2025-06-03T20:07:52.714374Z",
     "iopub.status.idle": "2025-06-03T20:07:52.725047Z",
     "shell.execute_reply": "2025-06-03T20:07:52.724758Z",
     "shell.execute_reply.started": "2025-06-03T20:07:52.714470Z"
    }
   },
   "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": 67,
   "metadata": {
    "execution": {
     "iopub.execute_input": "2025-06-03T20:07:52.725490Z",
     "iopub.status.busy": "2025-06-03T20:07:52.725382Z",
     "iopub.status.idle": "2025-06-03T20:07:52.735771Z",
     "shell.execute_reply": "2025-06-03T20:07:52.735493Z",
     "shell.execute_reply.started": "2025-06-03T20:07:52.725478Z"
    }
   },
   "outputs": [],
   "source": [
    "# train_metas = read_jsonl(os.path.join(OUT_DATA_DIR, f\"meta_tr.jsonl\"))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 68,
   "metadata": {
    "execution": {
     "iopub.execute_input": "2025-06-03T20:07:52.736200Z",
     "iopub.status.busy": "2025-06-03T20:07:52.736093Z",
     "iopub.status.idle": "2025-06-03T20:07:52.747156Z",
     "shell.execute_reply": "2025-06-03T20:07:52.746905Z",
     "shell.execute_reply.started": "2025-06-03T20:07:52.736189Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "dict_keys(['perference_0', 'perference_1'])"
      ]
     },
     "execution_count": 68,
     "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
}
