{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "import os\n",
    "import boto3\n",
    "import subprocess\n",
    "\n",
    "run_name = \"v2_infill_d3_t21_1E6_beta100_n16_bt16_acc4_4k\"\n",
    "CHECKPOINT_DIR = \"/app/suno/checkpoints/2025-06-01_17-26-31_s1454\"\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Upload checkpoint\n",
    "local_ckpt_filepath = os.path.join(CHECKPOINT_DIR, \"last_ckpt_infer.pt\")\n",
    "if not os.path.exists(local_ckpt_filepath):\n",
    "    raise FileNotFoundError(f\"Last checkpoint file not found at {local_ckpt_filepath}\")\n",
    "\n",
    "s3_client = boto3.client(\"s3\")\n",
    "s3_client.upload_file(\n",
    "    local_ckpt_filepath, \"suno-data\", \"christian/checkpoints/diffusion/modal_eval_ckpt.pt\"\n",
    ")\n",
    "print(\"Uploaded checkpoint to s3.\")\n",
    "\n",
    "# Launch modal eval\n",
    "print(f\"Launching modal eval for run {run_name}\")\n",
    "try:\n",
    "    result = subprocess.run(\n",
    "        [\"modal\", \"run\", \"/home/christian/code/christian/scripts/modal_upsample_v4.py\", \"--run-name\", run_name],\n",
    "        capture_output=True,\n",
    "        text=True,\n",
    "        check=True  # This raises CalledProcessError if the script fails\n",
    "    )\n",
    "    print(\"Modal eval succeeded.\")\n",
    "   #print(\"STDOUT:\", result.stdout)\n",
    "except subprocess.CalledProcessError as e:\n",
    "    print(\"Modal eval failed.\")\n",
    "    print(\"STDERR:\", e.stderr)\n",
    "    # Handle failure as needed (log, raise, etc.)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# now download the output from s3 to local and compute the statistics \n",
    "#os.system(\"aws s3 sync s3://suno-data/christian/outputs/auk-clips-up-u-2/ /app/data/eval_outputs\")\n",
    "\n",
    "try:\n",
    "    result = subprocess.run(\n",
    "            [\"aws\", \"s3\", \"sync\", \"s3://suno-data/christian/outputs/auk-clips-up-u-2/\", \"/app/suno/data/eval_outputs/auk-clips-up-u-2/\"],\n",
    "            capture_output=True,\n",
    "            text=True,\n",
    "            check=True  # This raises CalledProcessError if the script fails\n",
    "        )\n",
    "    print(\"S3 sync succeeded.\")\n",
    "except subprocess.CalledProcessError as e:\n",
    "    print(\"S3 sync failed.\")\n",
    "    print(\"STDERR:\", e.stderr)\n",
    "    # Handle failure as needed (log, raise, etc.)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "suno_env",
   "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.9"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
