From 5dd44c5c94d4181d3d2901f9ba2f6d1d89e8a377 Mon Sep 17 00:00:00 2001 From: theelderemo Date: Thu, 22 Jan 2026 15:45:40 -0500 Subject: [PATCH 1/2] Add optimized Colab/Kaggle notebook with flash attention and performance improvements --- notebooks/HeartLib.ipynb | 142 +++++++++++++++++++++++++++++++++++++++ notebooks/heartlib.py | 90 +++++++++++++++++++++++++ 2 files changed, 232 insertions(+) create mode 100644 notebooks/HeartLib.ipynb create mode 100644 notebooks/heartlib.py diff --git a/notebooks/HeartLib.ipynb b/notebooks/HeartLib.ipynb new file mode 100644 index 0000000..9f51053 --- /dev/null +++ b/notebooks/HeartLib.ipynb @@ -0,0 +1,142 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "collapsed": true, + "id": "YkaqrXnP0WXF", + "outputId": "a4cc5401-3a68-4640-fd62-ef72859b51c8" + }, + "outputs": [], + "source": [ + "# @title Setup Environment\n", + "import os\n", + "\n", + "!sudo apt-get update && sudo apt-get install -y ffmpeg\n", + "\n", + "if not os.path.exists(\"heartlib\"):\n", + " !git clone https://github.com/HeartMuLa/heartlib.git\n", + "\n", + "%cd heartlib\n", + "\n", + "!pip install -e .\n", + "!pip install -u \"huggingface_hub[cli]\"\n", + "!pip install flash-attn --no-build-isolation\n", + "!pip install accelerate" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "collapsed": true, + "id": "OcdLjfex0l6N", + "outputId": "596d5598-bdd3-4992-ebce-0ff13bac5bf7" + }, + "outputs": [], + "source": [ + "# @title Download Checkpoints\n", + "import os\n", + "\n", + "if os.path.basename(os.getcwd()) != \"heartlib\":\n", + " %cd heartlib\n", + "\n", + "os.makedirs('./ckpt', exist_ok=True)\n", + "\n", + "!huggingface-cli download --local-dir './ckpt' 'HeartMuLa/HeartMuLaGen'\n", + "!huggingface-cli download --local-dir './ckpt/HeartMuLa-oss-3B' 'HeartMuLa/HeartMuLa-oss-3B'\n", + "!huggingface-cli download --local-dir './ckpt/HeartCodec-oss' 'HeartMuLa/HeartCodec-oss'\n", + "!huggingface-cli download --local-dir './ckpt/HeartTranscriptor-oss' 'HeartMuLa/HeartTranscriptor-oss'" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/", + "height": 407 + }, + "id": "m7i-Cm0j0o3d", + "outputId": "ae1df797-78bb-4fc8-d2fd-d1fa89fdb81e" + }, + "outputs": [], + "source": [ + "# @title Run Music Generation\n", + "# No Touchy\n", + "import os\n", + "from IPython.display import Audio, display\n", + "import torch\n", + "\n", + "torch.backends.cuda.matmul.allow_tf32 = True\n", + "torch.backends.cudnn.allow_tf32 = True\n", + "torch.set_float32_matmul_precision('high')\n", + "\n", + "os.environ['PYTORCH_CUDA_ALLOC_CONF'] = 'max_split_size_mb:512'\n", + "os.environ['CUDA_LAUNCH_BLOCKING'] = '0'\n", + "\n", + "# -----------------------------------------------------------------------------\n", + "# 1. SETUP YOUR LYRICS AND TAGS (you can touch this lol)\n", + "# -----------------------------------------------------------------------------\n", + "my_lyrics = \"\"\"\n", + "[Verse]\n", + "The sun creeps in across the floor\n", + "I hear the traffic outside the door\n", + "The coffee pot begins to hiss\n", + "It is another morning just like this\n", + "\n", + "[Chorus]\n", + "Every day the light returns\n", + "Every day the fire burns\n", + "\"\"\"\n", + "\n", + "my_tags = \"piano,happy,pop\"\n", + "# -----------------------------------------------------------------------------\n", + "# Do Not Touch This Code Below, lol.\n", + "\n", + "if os.path.basename(os.getcwd()) != \"heartlib\":\n", + " if os.path.exists(\"heartlib\"):\n", + " %cd heartlib\n", + " else:\n", + " raise FileNotFoundError(\"Repo not found. Please run Block 1 (Setup) first.\")\n", + "\n", + "!python ./examples/run_music_generation.py \\\n", + " --model_path=./ckpt \\\n", + " --version=\"3B\" \\\n", + " --lyrics=\"$my_lyrics\" \\\n", + " --tags=\"$my_tags\" \\\n", + " --save_path=\"./assets/output.mp3\"\n", + "\n", + "if os.path.exists(\"./assets/output.mp3\"):\n", + " print(\"✓ Generation complete!\")\n", + " display(Audio(\"./assets/output.mp3\"))\n", + "else:\n", + " print(\"✗ Generation failed. Check logs above.\")\n" + ] + } + ], + "metadata": { + "accelerator": "GPU", + "colab": { + "gpuType": "A100", + "machine_shape": "hm", + "provenance": [] + }, + "kernelspec": { + "display_name": "Python 3", + "name": "python3" + }, + "language_info": { + "name": "python" + } + }, + "nbformat": 4, + "nbformat_minor": 0 +} diff --git a/notebooks/heartlib.py b/notebooks/heartlib.py new file mode 100644 index 0000000..542ceb2 --- /dev/null +++ b/notebooks/heartlib.py @@ -0,0 +1,90 @@ +# -*- coding: utf-8 -*- +"""HeartLib.ipynb + +Automatically generated by Colab. + +Original file is located at + https://colab.research.google.com/drive/19yVmN9HIomBSi89nnpkUqzNkd8Ddb4sn +""" + +# Commented out IPython magic to ensure Python compatibility. +# @title Setup Environment +import os + +!sudo apt-get update && sudo apt-get install -y ffmpeg + +if not os.path.exists("heartlib"): + !git clone https://github.com/HeartMuLa/heartlib.git + +# %cd heartlib + +!pip install -e . +!pip install -u "huggingface_hub[cli]" +!pip install flash-attn --no-build-isolation +!pip install accelerate + +# Commented out IPython magic to ensure Python compatibility. +# @title Download Checkpoints +import os + +if os.path.basename(os.getcwd()) != "heartlib": +# %cd heartlib + +os.makedirs('./ckpt', exist_ok=True) + +!huggingface-cli download --local-dir './ckpt' 'HeartMuLa/HeartMuLaGen' +!huggingface-cli download --local-dir './ckpt/HeartMuLa-oss-3B' 'HeartMuLa/HeartMuLa-oss-3B' +!huggingface-cli download --local-dir './ckpt/HeartCodec-oss' 'HeartMuLa/HeartCodec-oss' +!huggingface-cli download --local-dir './ckpt/HeartTranscriptor-oss' 'HeartMuLa/HeartTranscriptor-oss' + +# Commented out IPython magic to ensure Python compatibility. +# @title Run Music Generation +# No Touchy +import os +from IPython.display import Audio, display +import torch + +torch.backends.cuda.matmul.allow_tf32 = True +torch.backends.cudnn.allow_tf32 = True +torch.set_float32_matmul_precision('high') + +os.environ['PYTORCH_CUDA_ALLOC_CONF'] = 'max_split_size_mb:512' +os.environ['CUDA_LAUNCH_BLOCKING'] = '0' + +# ----------------------------------------------------------------------------- +# 1. SETUP YOUR LYRICS AND TAGS (you can touch this lol) +# ----------------------------------------------------------------------------- +my_lyrics = """ +[Verse] +The sun creeps in across the floor +I hear the traffic outside the door +The coffee pot begins to hiss +It is another morning just like this + +[Chorus] +Every day the light returns +Every day the fire burns +""" + +my_tags = "piano,happy,pop" +# ----------------------------------------------------------------------------- +# Do Not Touch This Code Below, lol. + +if os.path.basename(os.getcwd()) != "heartlib": + if os.path.exists("heartlib"): +# %cd heartlib + else: + raise FileNotFoundError("Repo not found. Please run Block 1 (Setup) first.") + +!python ./examples/run_music_generation.py \ + --model_path=./ckpt \ + --version="3B" \ + --lyrics="$my_lyrics" \ + --tags="$my_tags" \ + --save_path="./assets/output.mp3" + +if os.path.exists("./assets/output.mp3"): + print("✓ Generation complete!") + display(Audio("./assets/output.mp3")) +else: + print("✗ Generation failed. Check logs above.") \ No newline at end of file From 00eea0bc0633fefb1ea9931ec82a52f1026c4b55 Mon Sep 17 00:00:00 2001 From: theelderemo Date: Thu, 22 Jan 2026 15:56:04 -0500 Subject: [PATCH 2/2] changed metadata --- notebooks/HeartLib.ipynb | 89 +++++++++++++++++++--------------------- 1 file changed, 43 insertions(+), 46 deletions(-) diff --git a/notebooks/HeartLib.ipynb b/notebooks/HeartLib.ipynb index 9f51053..047a847 100644 --- a/notebooks/HeartLib.ipynb +++ b/notebooks/HeartLib.ipynb @@ -1,15 +1,39 @@ { + "nbformat": 4, + "nbformat_minor": 0, + "metadata": { + "colab": { + "provenance": [], + "machine_shape": "hm", + "gpuType": "A100", + "include_colab_link": true + }, + "kernelspec": { + "name": "python3", + "display_name": "Python 3" + }, + "language_info": { + "name": "python" + }, + "accelerator": "GPU" + }, "cells": [ + { + "cell_type": "markdown", + "metadata": { + "id": "view-in-github", + "colab_type": "text" + }, + "source": [ + "\"Open" + ] + }, { "cell_type": "code", "execution_count": null, "metadata": { - "colab": { - "base_uri": "https://localhost:8080/" - }, - "collapsed": true, "id": "YkaqrXnP0WXF", - "outputId": "a4cc5401-3a68-4640-fd62-ef72859b51c8" + "collapsed": true }, "outputs": [], "source": [ @@ -31,16 +55,6 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": { - "colab": { - "base_uri": "https://localhost:8080/" - }, - "collapsed": true, - "id": "OcdLjfex0l6N", - "outputId": "596d5598-bdd3-4992-ebce-0ff13bac5bf7" - }, - "outputs": [], "source": [ "# @title Download Checkpoints\n", "import os\n", @@ -54,20 +68,15 @@ "!huggingface-cli download --local-dir './ckpt/HeartMuLa-oss-3B' 'HeartMuLa/HeartMuLa-oss-3B'\n", "!huggingface-cli download --local-dir './ckpt/HeartCodec-oss' 'HeartMuLa/HeartCodec-oss'\n", "!huggingface-cli download --local-dir './ckpt/HeartTranscriptor-oss' 'HeartMuLa/HeartTranscriptor-oss'" - ] + ], + "metadata": { + "id": "OcdLjfex0l6N" + }, + "execution_count": null, + "outputs": [] }, { "cell_type": "code", - "execution_count": null, - "metadata": { - "colab": { - "base_uri": "https://localhost:8080/", - "height": 407 - }, - "id": "m7i-Cm0j0o3d", - "outputId": "ae1df797-78bb-4fc8-d2fd-d1fa89fdb81e" - }, - "outputs": [], "source": [ "# @title Run Music Generation\n", "# No Touchy\n", @@ -119,24 +128,12 @@ " display(Audio(\"./assets/output.mp3\"))\n", "else:\n", " print(\"✗ Generation failed. Check logs above.\")\n" - ] - } - ], - "metadata": { - "accelerator": "GPU", - "colab": { - "gpuType": "A100", - "machine_shape": "hm", - "provenance": [] - }, - "kernelspec": { - "display_name": "Python 3", - "name": "python3" - }, - "language_info": { - "name": "python" + ], + "metadata": { + "id": "m7i-Cm0j0o3d" + }, + "execution_count": null, + "outputs": [] } - }, - "nbformat": 4, - "nbformat_minor": 0 -} + ] +} \ No newline at end of file