{"id":2107,"date":"2026-10-22T15:43:33","date_gmt":"2026-10-22T15:43:33","guid":{"rendered":"https:\/\/makingmusic4ever.com\/?p=2107"},"modified":"2026-10-22T15:43:35","modified_gmt":"2026-10-22T15:43:35","slug":"how-to-generate-music-with-the-open-source-yue2-3b-model-on-google-colab","status":"publish","type":"post","link":"https:\/\/makingmusic4ever.com\/index.php\/2026\/10\/22\/how-to-generate-music-with-the-open-source-yue2-3b-model-on-google-colab\/","title":{"rendered":"How to Generate Music with the Open-Source YuE2-3B Model on Google Colab"},"content":{"rendered":"\n<p class=\"has-drop-cap wp-block-paragraph\">Who owns the song you created with artificial intelligence? The question sounds simple, but the answer can change depending on the plan you pay for, the version of the terms of service and even the month in which you accepted the rules.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Picture the scene. You spend an afternoon polishing a set of lyrics, choosing a style, generate ten versions and, finally, one of them moves you. You download the file, send it to a friend and maybe use it as the soundtrack for a video from your music school. Six months later, you cancel your subscription because the budget got tight. What happens to that song? Can you still use it? Can you monetize it? And who decides?<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">In this post I show an alternative: generating music with an open-source model, <strong>YuE2-3B<\/strong>, running on Google Colab. We will first talk about copyright and terms of use, then about the hardware required and, finally, follow a step-by-step guide with code that is ready to copy and paste. Open-source means that the model files and the code to run them are published, and anyone can download and run them independently, as long as they respect the license.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Before the first note: what you sign when you use a platform<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Platforms such as Suno are convenient: you write an idea, click a button and minutes later you have a complete song. But that convenience comes with a contract, and it is worth reading the clauses with the same attention we would give to a record deal.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">In 2026, after its agreement with Warner Music Group, Suno rewrote parts of its terms. Language that used to say subscribers owned their songs changed to say they may receive <strong>commercial use rights<\/strong>. The company itself explains that, even with those rights, the user is generally not considered the owner of the work, because the output was generated by the platform. The terms also make it clear that there is no guarantee that any copyright will exist in what was generated.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">There are other points. Songs created on the free plan are for non-commercial use only and cannot be monetized. Retroactive rights may be granted in limited cases, but without any guarantee. New terms took effect on September 3, 2026, and introduced download limits: 7 downloads in total on the free plan, 20 per month on Pro and 60 per month on Premier, applying even to songs created before the change. And, according to analyses of the terms, the user grants the platform a broad license to use what is submitted and what is generated to improve its models.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The company states that, if you cancel, your library stays in your account and songs downloaded as a subscriber keep their commercial rights. So, the problem is not necessarily what is written today. The problem is <strong>who writes the rules<\/strong>. They have changed more than once in a few months, they may change again, and you, who depend on the platform to access and download your own material, have no bargaining power at all. It is like composing in a studio that can change the contract after the recording. That is why you should always check the terms currently in force: they may have changed since I wrote this text.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">What changes with an open-source model<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">When you run an open model, the logic is reversed. You download the model files, run them on the machine you own or rented, and the result is an audio file that is in your hands. There is no subscriber account, no download limit and no music-platform clause telling you what you may or may not do with the result. If a service shuts down tomorrow, the model you downloaded keeps working. It is the difference between subscribing to a streaming service and owning your own recording equipment.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">But pay attention to a point many people forget: <strong>control is not the same as total freedom<\/strong>. The model has its own license. The YuE2-3B weights (the \u201cweights\u201d are the numbers the model learned, in other words, its knowledge stored in a file) are published under the Creative Commons <strong>CC BY-NC 4.0<\/strong> license, which allows non-commercial use and requires attribution to the authors. The inference code we use to run the model is Apache 2.0, which is far more permissive, but it is the weights that define what you can do with the music.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">In practice, this is great for study, teaching, demos, arrangement prototypes, soundtracks for personal projects and experiments. If your goal is to sell or monetize the music, read the license on the model\u2019s official page and, if possible, consult a lawyer who specializes in copyright. I am not a lawyer, this text is not legal advice, and laws vary from country to country.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">There is also the question of authorship. In many countries, copyright protection is tied to human creativity. The more of your own contribution a work contains, such as lyrics written by you, the structure, the arrangement choices and, afterwards, the editing and mixing, the stronger your position tends to be. Use AI as a session musician, not as a substitute for the composer.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">What about the training data?<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">There is a question that still has no definitive answer: the music used to train these models. Lawsuits around the world are debating whether training an AI on protected works is permitted use, and deals such as the one between Suno and Warner show that the market is negotiating the rules while the game is being played. This applies to closed platforms and open models alike, and it is an area of the law that may change in the coming years. So, follow the news and keep a record of which model and which settings you used for each track. The script we will use saves the \u201cartifacts\u201d of each generation, which helps with that.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">On balance, I still think it is better to generate music with an open model under your own control: you know which license applies, you choose the version, you keep your files and you do not depend on a company keeping today\u2019s rules. It is a risk decision, not a guarantee, and each person should weigh their own situation.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">The obstacle: the GPU<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Music-generation models perform billions of calculations at the same time, and the part that does this heavy lifting is the <strong>GPU<\/strong>, the graphics processing unit. Think of the computer\u2019s CPU as an excellent conductor who reads the score note by note, while the GPU is an entire orchestra playing in parallel. To run YuE2-3B at original quality, without compression, the recommendation is a card with about 24 GB of video memory (VRAM), which is where the model has to fit while it works. There are quantized versions, that is, compressed ones with some loss of quality, that run on smaller cards, but the experience is more limited.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">GPUs with that much memory often cost well over a thousand dollars, and in many countries import taxes and exchange rates push the price even higher. For a musician or teacher who just wants to experiment, buying one is like buying a grand piano to find out whether you enjoy playing. The way out is to rent the \u201cstudio\u201d by the hour.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Google Colab: the rehearsal studio rented by the hour<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Google Colab<\/strong> (short for Colaboratory) is a Google service that lets you write and run Python code directly in your browser, on the company\u2019s own computers, including machines with a GPU. It works like renting a rehearsal room: you pay for the time you use and, when you finish, you hand the room back.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The billing model that suits our case best is <em>pay as you go<\/em>. Instead of subscribing to a monthly plan, you buy <em>compute units<\/em>, which are Colab\u2019s currency. When I last checked, the price was US$ 9.99 for 100 units, with no subscription, and the units expire 90 days after purchase, which means three months. An A100 GPU consumes roughly 10 to 15 units per hour, which works out to 7 to 10 hours of use per 100 units, or around US$ 1 to US$ 1.50 per hour. Prices are in US dollars, change over time and may vary by region, so check the Colab pricing page before you buy.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Since each song takes a few minutes to generate, 100 units yield dozens of generations for a fraction of the price of a graphics card. There are two cautions. The first is that Google does not guarantee which GPU you will get. The second is that units keep being spent while the session is open, even if you are not generating anything. Finished? End the session under Runtime &gt; Disconnect and delete runtime.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Colab runs on Linux: how to activate the graphics card<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Under the interface, Colab runs <strong>Linux<\/strong> (Ubuntu). This explains a few details in the code: commands that start with an exclamation mark (!) are sent to the Linux terminal, such as apt-get, which installs programs. Commands that start with %%writefile save the content of the cell to a file. A cell is each block of code in the notebook, and you run them one at a time by clicking the play button beside each one.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Before anything else, activate the graphics card. The one suggested for this model is the <strong>A100<\/strong>, which has plenty of memory for it:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Go to colab.research.google.com and create a new notebook.<\/li>\n\n\n\n<li>In the menu, open Runtime > Change runtime type.<\/li>\n\n\n\n<li>Under Hardware accelerator, choose the A100 GPU.<\/li>\n\n\n\n<li>Save and click Connect.<\/li>\n<\/ol>\n\n\n\n<p class=\"wp-block-paragraph\">If the A100 is not available at the moment, Colab may offer a different card. In that case, try again later. Our script checks for the GPU right at the start and warns you if none is found.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">How the Python code works<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">All the code in this post is written in <strong>Python<\/strong>, a language widely used in artificial intelligence and known for being readable, almost like reading a recipe. You do not need to know how to program to use it: you just copy, paste and change a few texts, such as the style and the lyrics.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The flow is always the same and resembles studio work. First, we load the model onto the graphics card, like switching on the equipment. Then we define the <strong>style<\/strong>, which is the briefing for the band (genre, instruments, mood), and the <strong>lyrics<\/strong>, which also carry the structure of the song, with markers such as [Verse] and [Chorus]. Next, we tell it to generate and, finally, we save the audio and the artifacts, which are the auxiliary files of the process, including the melody and chord plan.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Two parameters deserve an explanation. The first is cot=&#8221;full&#8221;. The abbreviation comes from <em>chain of thought<\/em>. Instead of producing the audio in one go, the model first writes a symbolic plan of the song, with melody and chords in ABC notation (a simple text format for writing sheet music), and only then turns that plan into sound. It is like an arranger who sketches the score before calling in the musicians. For covers, the recommended mode is cot=&#8221;melody&#8221;. The second parameter is the <strong>seed<\/strong>: the number that starts the model\u2019s internal draw. With the same seed and the same texts, you tend to get the same result, like repeating the same take. Change the seed and new variations are born.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">And why do we use a venv? YuE2 requires Python 3.10, while Colab usually ships with a different version. The solution is to create a <strong>virtual environment<\/strong>, or <em>venv<\/em>: a folder with its own Python and its own libraries, isolated from the rest of the system. Think of a soundproof recording booth, where what happens inside does not interfere with the studio next door. That is why the scripts are run with \/content\/yue2_env\/bin\/python and not with the default Python.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Step 1: create the environment with Python 3.10<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">In the first cell we install Python 3.10 with apt-get, the program manager of Ubuntu, and create the virtual environment in the \/content\/yue2_env folder. It takes a few minutes to run.<\/p>\n\n\n\n<p class=\"has-light-blue-background-color has-background wp-block-paragraph\"># Cell 1: Install Python 3.10 and create the virtual environment (venv)<\/p>\n\n\n\n<p class=\"has-light-blue-background-color has-background wp-block-paragraph\">!sudo apt-get update -y<\/p>\n\n\n\n<p class=\"has-light-blue-background-color has-background wp-block-paragraph\">!sudo apt-get install -y python3.10 python3.10-dev python3.10-venv<\/p>\n\n\n\n<p class=\"has-light-blue-background-color has-background wp-block-paragraph\">!python3.10 -m venv \/content\/yue2_env<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Step 2: install YuE2<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">The second cell updates pip (Python\u2019s package installer), installs a specific version of the huggingface-hub library, downloads the YuE2 inference package straight from the official repository on Hugging Face and installs it inside the venv. Hugging Face is a kind of \u201cGitHub for AI models\u201d, where the model files are published. The weights, which take up a few gigabytes, are normally downloaded the first time the script loads the model, so the first run is the slowest.<\/p>\n\n\n\n<p class=\"has-light-blue-background-color has-background wp-block-paragraph\"># Cell 2: Install the inference package in the new environment<\/p>\n\n\n\n<p class=\"has-light-blue-background-color has-background wp-block-paragraph\">!\/content\/yue2_env\/bin\/python -m pip install &#8211;upgrade pip<\/p>\n\n\n\n<p class=\"has-light-blue-background-color has-background wp-block-paragraph\">!\/content\/yue2_env\/bin\/python -m pip install huggingface-hub==0.36.2<\/p>\n\n\n\n<p class=\"has-light-blue-background-color has-background wp-block-paragraph\">!\/content\/yue2_env\/bin\/hf download m-a-p\/YuE2-3B yue2_infer-0.1.5-py3-none-any.whl &#8211;local-dir .<\/p>\n\n\n\n<p class=\"has-light-blue-background-color has-background wp-block-paragraph\">!\/content\/yue2_env\/bin\/python -m pip install .\/yue2_infer-0.1.5-py3-none-any.whl<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Step 3: a quick test with the official example<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Before customizing anything, it is worth confirming that everything works by using the demo example from the repository itself. The script below downloads a ready-made request (style, lyrics and seed) and generates the song. If everything goes well, you will have a song.flac file (FLAC is a lossless audio format) next to the notebook.<\/p>\n\n\n\n<p class=\"has-light-blue-background-color has-background wp-block-paragraph\"># Cell 3: Create the test file with the official example<\/p>\n\n\n\n<p class=\"has-light-blue-background-color has-background wp-block-paragraph\">%%writefile teste_demo.py<\/p>\n\n\n\n<p class=\"has-light-blue-background-color has-background wp-block-paragraph\">import json<\/p>\n\n\n\n<p class=\"has-light-blue-background-color has-background wp-block-paragraph\">from pathlib import Path<\/p>\n\n\n\n<p class=\"has-light-blue-background-color has-background wp-block-paragraph\">from huggingface_hub import hf_hub_download<\/p>\n\n\n\n<p class=\"has-light-blue-background-color has-background wp-block-paragraph\">from yue2 import YuE2Pipeline<\/p>\n\n\n\n<p class=\"has-light-blue-background-color has-background wp-block-paragraph\">print(&#8220;Loading the YuE2Pipeline on the GPU&#8230;&#8221;)<\/p>\n\n\n\n<p class=\"has-light-blue-background-color has-background wp-block-paragraph\">pipe = YuE2Pipeline.from_pretrained(&#8220;m-a-p\/YuE2-3B&#8221;, device=&#8221;cuda&#8221;)<\/p>\n\n\n\n<p class=\"has-light-blue-background-color has-background wp-block-paragraph\"># Download the demo example from the repository<\/p>\n\n\n\n<p class=\"has-light-blue-background-color has-background wp-block-paragraph\">repo = &#8220;m-a-p\/YuE2-3B&#8221;<\/p>\n\n\n\n<p class=\"has-light-blue-background-color has-background wp-block-paragraph\">prompt_path = hf_hub_download(repo, &#8220;examples\/tonight-awake.json&#8221;)<\/p>\n\n\n\n<p class=\"has-light-blue-background-color has-background wp-block-paragraph\">demo = json.loads(Path(prompt_path).read_text(encoding=&#8221;utf-8&#8243;))<\/p>\n\n\n\n<p class=\"has-light-blue-background-color has-background wp-block-paragraph\">style, lyrics = demo[&#8220;style&#8221;], demo[&#8220;lyrics&#8221;]<\/p>\n\n\n\n<p class=\"has-light-blue-background-color has-background wp-block-paragraph\">print(&#8220;Generating the music&#8230;&#8221;)<\/p>\n\n\n\n<p class=\"has-light-blue-background-color has-background wp-block-paragraph\">song = pipe(style=style, lyrics=lyrics, cot=&#8221;full&#8221;, seed=demo[&#8220;seed&#8221;])<\/p>\n\n\n\n<p class=\"has-light-blue-background-color has-background wp-block-paragraph\"># Save the song and the artifacts<\/p>\n\n\n\n<p class=\"has-light-blue-background-color has-background wp-block-paragraph\">song.save(&#8220;song.flac&#8221;)<\/p>\n\n\n\n<p class=\"has-light-blue-background-color has-background wp-block-paragraph\">song.save_artifacts(&#8220;outputs\/song&#8221;)<\/p>\n\n\n\n<p class=\"has-light-blue-background-color has-background wp-block-paragraph\">print(&#8220;Generation complete! File saved as &#8216;song.flac&#8217;.&#8221;)<\/p>\n\n\n\n<p class=\"has-light-blue-background-color has-background wp-block-paragraph\"># Cell 4: Run the test with the venv&#8217;s Python 3.10<\/p>\n\n\n\n<p class=\"has-light-blue-background-color has-background wp-block-paragraph\">!\/content\/yue2_env\/bin\/python teste_demo.py<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Step 4: the configurable generation script<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">This is the script for everyday use. All the options sit in the CONFIGURE HERE block at the top of the file, so that is the only part you need to touch. Here is what each one does:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>CAPTION<\/strong>: the style of the song, with genre, instruments and mood. Write it in English, as in the official examples.<\/li>\n\n\n\n<li><strong>LYRICS<\/strong>: the lyrics, with markers such as [Verse 1] and [Chorus]. Write [Instrumental] for a track without vocals.<\/li>\n\n\n\n<li><strong>VOCAL_LANGUAGE<\/strong>: the language of the vocals. Use &#8220;en&#8221; for English, &#8220;pt&#8221; for Portuguese, &#8220;es&#8221; for Spanish, or &#8220;unknown&#8221; to let the model decide.<\/li>\n\n\n\n<li><strong>DURATION<\/strong>: the model decides the length of the track, so this value only trims the audio, with a 1.5-second fade-out, if it runs past the limit. Use -1 for no trimming.<\/li>\n\n\n\n<li><strong>BPM<\/strong> and <strong>KEYSCALE<\/strong>: tempo and key. They enter as text in the style, working as a request and not as a strict order.<\/li>\n\n\n\n<li><strong>BATCH_SIZE<\/strong>: how many variations to generate in sequence.<\/li>\n\n\n\n<li><strong>AUDIO_FORMAT<\/strong>: the final file format (wav, flac, mp3, opus, aac), converted with ffmpeg.<\/li>\n\n\n\n<li><strong>SEED<\/strong>: with -1, the seed is drawn at random on every generation. With a fixed number, the result tends to repeat.<\/li>\n\n\n\n<li><strong>OUTPUT_DIR<\/strong>: the folder where the files will be saved.<\/li>\n<\/ul>\n\n\n\n<p class=\"has-light-blue-background-color has-background wp-block-paragraph\"># Cell 5: Create the configurable generation script<\/p>\n\n\n\n<p class=\"has-light-blue-background-color has-background wp-block-paragraph\">%%writefile \/content\/generate_music.py<\/p>\n\n\n\n<p class=\"has-light-blue-background-color has-background wp-block-paragraph\">import os, sys, subprocess, inspect, time, random<\/p>\n\n\n\n<p class=\"has-light-blue-background-color has-background wp-block-paragraph\">from pathlib import Path<\/p>\n\n\n\n<p class=\"has-light-blue-background-color has-background wp-block-paragraph\"># &#8212; 0. Make sure we are running inside the YuE2 virtual environment &#8212;<\/p>\n\n\n\n<p class=\"has-light-blue-background-color has-background wp-block-paragraph\">VENV_DIR = &#8220;\/content\/yue2_env&#8221;<\/p>\n\n\n\n<p class=\"has-light-blue-background-color has-background wp-block-paragraph\">VENV_PYTHON = f&#8221;{VENV_DIR}\/bin\/python&#8221;<\/p>\n\n\n\n<p class=\"has-light-blue-background-color has-background wp-block-paragraph\">if os.path.exists(VENV_PYTHON) and os.path.realpath(sys.prefix) != os.path.realpath(VENV_DIR):<\/p>\n\n\n\n<p class=\"has-light-blue-background-color has-background wp-block-paragraph\">&nbsp;&nbsp;&nbsp; os.execv(VENV_PYTHON, [VENV_PYTHON] + sys.argv)<\/p>\n\n\n\n<p class=\"has-light-blue-background-color has-background wp-block-paragraph\">try:<\/p>\n\n\n\n<p class=\"has-light-blue-background-color has-background wp-block-paragraph\">&nbsp;&nbsp;&nbsp; import torch<\/p>\n\n\n\n<p class=\"has-light-blue-background-color has-background wp-block-paragraph\">except ImportError:<\/p>\n\n\n\n<p class=\"has-light-blue-background-color has-background wp-block-paragraph\">&nbsp;&nbsp;&nbsp; torch = None<\/p>\n\n\n\n<p class=\"has-light-blue-background-color has-background wp-block-paragraph\"># ===================== CONFIGURE HERE =====================<\/p>\n\n\n\n<p class=\"has-light-blue-background-color has-background wp-block-paragraph\">CAPTION = &#8220;blues with piano, cello, double bass, sax and soft drums&#8221;<\/p>\n\n\n\n<p class=\"has-light-blue-background-color has-background wp-block-paragraph\">LYRICS = &#8220;&#8221;&#8221;[Verse 1]<\/p>\n\n\n\n<p class=\"has-light-blue-background-color has-background wp-block-paragraph\">Walking down the street today<\/p>\n\n\n\n<p class=\"has-light-blue-background-color has-background wp-block-paragraph\">Thinking of the words you used to say<\/p>\n\n\n\n<p class=\"has-light-blue-background-color has-background wp-block-paragraph\">Everything feels different now<\/p>\n\n\n\n<p class=\"has-light-blue-background-color has-background wp-block-paragraph\">But I will find my way somehow<\/p>\n\n\n\n<p class=\"has-light-blue-background-color has-background wp-block-paragraph\">[Chorus]<\/p>\n\n\n\n<p class=\"has-light-blue-background-color has-background wp-block-paragraph\">I keep moving on, I keep moving strong<\/p>\n\n\n\n<p class=\"has-light-blue-background-color has-background wp-block-paragraph\">This is where I belong<\/p>\n\n\n\n<p class=\"has-light-blue-background-color has-background wp-block-paragraph\">&#8220;&#8221;&#8221;&nbsp; # or write your own lyrics; &#8220;[Instrumental]&#8221; = no vocals<\/p>\n\n\n\n<p class=\"has-light-blue-background-color has-background wp-block-paragraph\">VOCAL_LANGUAGE = &#8220;en&#8221;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; # &#8220;en&#8221;, &#8220;pt&#8221;, &#8220;es&#8221;, &#8220;ja&#8221;&#8230; or &#8220;unknown&#8221; (automatic)<\/p>\n\n\n\n<p class=\"has-light-blue-background-color has-background wp-block-paragraph\">DURATION = 30&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; # seconds: trims the track to this length (with fade-out); -1 = no trimming<\/p>\n\n\n\n<p class=\"has-light-blue-background-color has-background wp-block-paragraph\">BPM = 85&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; # None = automatic<\/p>\n\n\n\n<p class=\"has-light-blue-background-color has-background wp-block-paragraph\">KEYSCALE = &#8220;A Major&#8221;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; # e.g. &#8220;C Major&#8221;; &#8220;&#8221; = automatic<\/p>\n\n\n\n<p class=\"has-light-blue-background-color has-background wp-block-paragraph\">BATCH_SIZE = 1&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; # how many variations to generate<\/p>\n\n\n\n<p class=\"has-light-blue-background-color has-background wp-block-paragraph\">AUDIO_FORMAT = &#8220;wav&#8221;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; # flac, mp3, opus, aac, wav, wav32<\/p>\n\n\n\n<p class=\"has-light-blue-background-color has-background wp-block-paragraph\">SEED = -1&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; # -1 = random<\/p>\n\n\n\n<p class=\"has-light-blue-background-color has-background wp-block-paragraph\">USE_LM = True&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; # True = full melody and chord planning (cot=&#8221;full&#8221;)<\/p>\n\n\n\n<p class=\"has-light-blue-background-color has-background wp-block-paragraph\">PROJECT_ROOT = &#8220;\/content\/YuE2&#8221;&nbsp;&nbsp; # only used if it exists: added to sys.path<\/p>\n\n\n\n<p class=\"has-light-blue-background-color has-background wp-block-paragraph\">OUTPUT_DIR = &#8220;\/content\/generated_songs&#8221;<\/p>\n\n\n\n<p class=\"has-light-blue-background-color has-background wp-block-paragraph\">CONFIG_OVERRIDE = None&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; # e.g. &#8220;m-a-p\/YuE2-3B&#8221; (main model)<\/p>\n\n\n\n<p class=\"has-light-blue-background-color has-background wp-block-paragraph\">LM_OVERRIDE = None&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; # separate planning model, if the pipeline accepts one<\/p>\n\n\n\n<p class=\"has-light-blue-background-color has-background wp-block-paragraph\"># ==========================================================<\/p>\n\n\n\n<p class=\"has-light-blue-background-color has-background wp-block-paragraph\">DEFAULT_MODEL = &#8220;m-a-p\/YuE2-3B&#8221;<\/p>\n\n\n\n<p class=\"has-light-blue-background-color has-background wp-block-paragraph\">def run(cmd):<\/p>\n\n\n\n<p class=\"has-light-blue-background-color has-background wp-block-paragraph\">&nbsp;&nbsp;&nbsp; subprocess.run(cmd, shell=True, check=True)<\/p>\n\n\n\n<p class=\"has-light-blue-background-color has-background wp-block-paragraph\"># &#8212; 1. GPU &#8212;<\/p>\n\n\n\n<p class=\"has-light-blue-background-color has-background wp-block-paragraph\">if torch is not None:<\/p>\n\n\n\n<p class=\"has-light-blue-background-color has-background wp-block-paragraph\">&nbsp;&nbsp;&nbsp; if not torch.cuda.is_available():<\/p>\n\n\n\n<p class=\"has-light-blue-background-color has-background wp-block-paragraph\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; sys.exit(&#8220;No GPU found. In Colab: Runtime &gt; Change runtime type &gt; GPU.&#8221;)<\/p>\n\n\n\n<p class=\"has-light-blue-background-color has-background wp-block-paragraph\">&nbsp;&nbsp;&nbsp; props = torch.cuda.get_device_properties(0)<\/p>\n\n\n\n<p class=\"has-light-blue-background-color has-background wp-block-paragraph\">&nbsp;&nbsp;&nbsp; print(f&#8221;GPU: {props.name} | VRAM: {props.total_memory \/ 1024**3:.1f} GB&#8221;)<\/p>\n\n\n\n<p class=\"has-light-blue-background-color has-background wp-block-paragraph\">else:<\/p>\n\n\n\n<p class=\"has-light-blue-background-color has-background wp-block-paragraph\">&nbsp;&nbsp;&nbsp; info = subprocess.run(&#8220;nvidia-smi &#8211;query-gpu=name,memory.total &#8211;format=csv,noheader&#8221;,<\/p>\n\n\n\n<p class=\"has-light-blue-background-color has-background wp-block-paragraph\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; shell=True, capture_output=True, text=True).stdout.strip()<\/p>\n\n\n\n<p class=\"has-light-blue-background-color has-background wp-block-paragraph\">&nbsp;&nbsp;&nbsp; if not info:<\/p>\n\n\n\n<p class=\"has-light-blue-background-color has-background wp-block-paragraph\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; sys.exit(&#8220;No GPU found. In Colab: Runtime &gt; Change runtime type &gt; GPU.&#8221;)<\/p>\n\n\n\n<p class=\"has-light-blue-background-color has-background wp-block-paragraph\">&nbsp;&nbsp;&nbsp; print(f&#8221;GPU: {info}&#8221;)<\/p>\n\n\n\n<p class=\"has-light-blue-background-color has-background wp-block-paragraph\">model_id = CONFIG_OVERRIDE or DEFAULT_MODEL<\/p>\n\n\n\n<p class=\"has-light-blue-background-color has-background wp-block-paragraph\">print(f&#8221;Python: {sys.executable}&#8221;)<\/p>\n\n\n\n<p class=\"has-light-blue-background-color has-background wp-block-paragraph\">print(f&#8221;Modelo: {model_id} | planning (cot): {&#8216;on&#8217; if USE_LM else &#8216;off&#8217;}&#8221;)<\/p>\n\n\n\n<p class=\"has-light-blue-background-color has-background wp-block-paragraph\"># &#8212; 2. Import YuE2 (installed in the venv) &#8212;<\/p>\n\n\n\n<p class=\"has-light-blue-background-color has-background wp-block-paragraph\">if os.path.isdir(PROJECT_ROOT):<\/p>\n\n\n\n<p class=\"has-light-blue-background-color has-background wp-block-paragraph\">&nbsp;&nbsp;&nbsp; sys.path.insert(0, PROJECT_ROOT)<\/p>\n\n\n\n<p class=\"has-light-blue-background-color has-background wp-block-paragraph\">try:<\/p>\n\n\n\n<p class=\"has-light-blue-background-color has-background wp-block-paragraph\">&nbsp;&nbsp;&nbsp; from yue2 import YuE2Pipeline<\/p>\n\n\n\n<p class=\"has-light-blue-background-color has-background wp-block-paragraph\">except ImportError:<\/p>\n\n\n\n<p class=\"has-light-blue-background-color has-background wp-block-paragraph\">&nbsp;&nbsp;&nbsp; sys.exit(&#8220;The &#8216;yue2&#8217; module was not found. Run cells 1 and 2 first &#8220;<\/p>\n\n\n\n<p class=\"has-light-blue-background-color has-background wp-block-paragraph\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &#8220;(create the venv \/content\/yue2_env and install yue2_infer) and try again.&#8221;)<\/p>\n\n\n\n<p class=\"has-light-blue-background-color has-background wp-block-paragraph\">Path(OUTPUT_DIR).mkdir(parents=True, exist_ok=True)<\/p>\n\n\n\n<p class=\"has-light-blue-background-color has-background wp-block-paragraph\"># &#8212; 3. Load the model on the GPU &#8212;<\/p>\n\n\n\n<p class=\"has-light-blue-background-color has-background wp-block-paragraph\">print(&#8220;Loading the YuE2Pipeline on the GPU&#8230;&#8221;)<\/p>\n\n\n\n<p class=\"has-light-blue-background-color has-background wp-block-paragraph\">load_kwargs = {&#8220;device&#8221;: &#8220;cuda&#8221;}<\/p>\n\n\n\n<p class=\"has-light-blue-background-color has-background wp-block-paragraph\">if LM_OVERRIDE:<\/p>\n\n\n\n<p class=\"has-light-blue-background-color has-background wp-block-paragraph\">&nbsp;&nbsp;&nbsp; if &#8220;lm_model&#8221; in inspect.signature(YuE2Pipeline.from_pretrained).parameters:<\/p>\n\n\n\n<p class=\"has-light-blue-background-color has-background wp-block-paragraph\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; load_kwargs[&#8220;lm_model&#8221;] = LM_OVERRIDE<\/p>\n\n\n\n<p class=\"has-light-blue-background-color has-background wp-block-paragraph\">&nbsp;&nbsp;&nbsp; else:<\/p>\n\n\n\n<p class=\"has-light-blue-background-color has-background wp-block-paragraph\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; print(&#8220;Warning: from_pretrained does not accept &#8216;lm_model&#8217;; LM_OVERRIDE ignored.&#8221;)<\/p>\n\n\n\n<p class=\"has-light-blue-background-color has-background wp-block-paragraph\">pipe = YuE2Pipeline.from_pretrained(model_id, **load_kwargs)<\/p>\n\n\n\n<p class=\"has-light-blue-background-color has-background wp-block-paragraph\"># &#8212; 4. Build the style and lyrics &#8212;<\/p>\n\n\n\n<p class=\"has-light-blue-background-color has-background wp-block-paragraph\">instrumental = LYRICS.strip().lower() in (&#8220;[instrumental]&#8221;, &#8220;&#8221;)<\/p>\n\n\n\n<p class=\"has-light-blue-background-color has-background wp-block-paragraph\">style_parts = [CAPTION.strip()]<\/p>\n\n\n\n<p class=\"has-light-blue-background-color has-background wp-block-paragraph\">if instrumental:<\/p>\n\n\n\n<p class=\"has-light-blue-background-color has-background wp-block-paragraph\">&nbsp;&nbsp;&nbsp; style_parts += [&#8220;Instrumental&#8221;, &#8220;no vocals&#8221;]<\/p>\n\n\n\n<p class=\"has-light-blue-background-color has-background wp-block-paragraph\">if BPM:<\/p>\n\n\n\n<p class=\"has-light-blue-background-color has-background wp-block-paragraph\">&nbsp;&nbsp;&nbsp; style_parts.append(f&#8221;{BPM} bpm&#8221;)<\/p>\n\n\n\n<p class=\"has-light-blue-background-color has-background wp-block-paragraph\">if KEYSCALE:<\/p>\n\n\n\n<p class=\"has-light-blue-background-color has-background wp-block-paragraph\">&nbsp;&nbsp;&nbsp; style_parts.append(f&#8221;{KEYSCALE} key&#8221;)<\/p>\n\n\n\n<p class=\"has-light-blue-background-color has-background wp-block-paragraph\">if VOCAL_LANGUAGE and VOCAL_LANGUAGE.lower() != &#8220;unknown&#8221; and not instrumental:<\/p>\n\n\n\n<p class=\"has-light-blue-background-color has-background wp-block-paragraph\">&nbsp;&nbsp;&nbsp; style_parts.append(f&#8221;{VOCAL_LANGUAGE} vocals&#8221;)<\/p>\n\n\n\n<p class=\"has-light-blue-background-color has-background wp-block-paragraph\">style = &#8220;. &#8220;.join(style_parts)<\/p>\n\n\n\n<p class=\"has-light-blue-background-color has-background wp-block-paragraph\">lyrics = (&#8220;[Intro &#8211; instrumental]\\n\\n[verse &#8211; instrumental, no vocals]\\n\\n&#8221;<\/p>\n\n\n\n<p class=\"has-light-blue-background-color has-background wp-block-paragraph\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &#8220;[chorus &#8211; instrumental, no vocals]\\n\\n[outro &#8211; instrumental, final chord resolution]\\n&#8221;<\/p>\n\n\n\n<p class=\"has-light-blue-background-color has-background wp-block-paragraph\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if instrumental else LYRICS)<\/p>\n\n\n\n<p class=\"has-light-blue-background-color has-background wp-block-paragraph\">print(f&#8221;Final style: {style}&#8221;)<\/p>\n\n\n\n<p class=\"has-light-blue-background-color has-background wp-block-paragraph\"># &#8212; 5. Post-processing (format and length) with ffmpeg &#8212;<\/p>\n\n\n\n<p class=\"has-light-blue-background-color has-background wp-block-paragraph\">CODECS = {&nbsp; # format: (extension, ffmpeg arguments)<\/p>\n\n\n\n<p class=\"has-light-blue-background-color has-background wp-block-paragraph\">&nbsp;&nbsp;&nbsp; &#8220;wav&#8221;:&nbsp;&nbsp; (&#8220;wav&#8221;,&nbsp; &#8220;-c:a pcm_s16le&#8221;),<\/p>\n\n\n\n<p class=\"has-light-blue-background-color has-background wp-block-paragraph\">&nbsp;&nbsp;&nbsp; &#8220;wav32&#8221;: (&#8220;wav&#8221;,&nbsp; &#8220;-c:a pcm_f32le&#8221;),<\/p>\n\n\n\n<p class=\"has-light-blue-background-color has-background wp-block-paragraph\">&nbsp;&nbsp;&nbsp; &#8220;flac&#8221;:&nbsp; (&#8220;flac&#8221;, &#8220;-c:a flac&#8221;),<\/p>\n\n\n\n<p class=\"has-light-blue-background-color has-background wp-block-paragraph\">&nbsp;&nbsp;&nbsp; &#8220;mp3&#8221;:&nbsp;&nbsp; (&#8220;mp3&#8221;,&nbsp; &#8220;-c:a libmp3lame -q:a 2&#8221;),<\/p>\n\n\n\n<p class=\"has-light-blue-background-color has-background wp-block-paragraph\">&nbsp;&nbsp;&nbsp; &#8220;opus&#8221;:&nbsp; (&#8220;opus&#8221;, &#8220;-c:a libopus -b:a 128k&#8221;),<\/p>\n\n\n\n<p class=\"has-light-blue-background-color has-background wp-block-paragraph\">&nbsp;&nbsp;&nbsp; &#8220;aac&#8221;:&nbsp;&nbsp; (&#8220;aac&#8221;,&nbsp; &#8220;-c:a aac -b:a 192k&#8221;),<\/p>\n\n\n\n<p class=\"has-light-blue-background-color has-background wp-block-paragraph\">}<\/p>\n\n\n\n<p class=\"has-light-blue-background-color has-background wp-block-paragraph\">fmt = AUDIO_FORMAT.lower()<\/p>\n\n\n\n<p class=\"has-light-blue-background-color has-background wp-block-paragraph\">if fmt not in CODECS:<\/p>\n\n\n\n<p class=\"has-light-blue-background-color has-background wp-block-paragraph\">&nbsp;&nbsp;&nbsp; sys.exit(f&#8221;Invalid AUDIO_FORMAT: {AUDIO_FORMAT}. Use: {&#8216;, &#8216;.join(CODECS)}&#8221;)<\/p>\n\n\n\n<p class=\"has-light-blue-background-color has-background wp-block-paragraph\">ext, codec_args = CODECS[fmt]<\/p>\n\n\n\n<p class=\"has-light-blue-background-color has-background wp-block-paragraph\">def audio_length(path):<\/p>\n\n\n\n<p class=\"has-light-blue-background-color has-background wp-block-paragraph\">&nbsp;&nbsp;&nbsp; out = subprocess.run(<\/p>\n\n\n\n<p class=\"has-light-blue-background-color has-background wp-block-paragraph\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; f&#8217;ffprobe -v error -show_entries format=duration -of csv=p=0 &#8220;{path}&#8221;&#8216;,<\/p>\n\n\n\n<p class=\"has-light-blue-background-color has-background wp-block-paragraph\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; shell=True, capture_output=True, text=True).stdout.strip()<\/p>\n\n\n\n<p class=\"has-light-blue-background-color has-background wp-block-paragraph\">&nbsp;&nbsp;&nbsp; return float(out) if out else None<\/p>\n\n\n\n<p class=\"has-light-blue-background-color has-background wp-block-paragraph\">def convert(src, dst, max_seconds=None):<\/p>\n\n\n\n<p class=\"has-light-blue-background-color has-background wp-block-paragraph\">&nbsp;&nbsp;&nbsp; &#8220;&#8221;&#8221;Converts to the requested format and, if longer than the limit, trims with a fade-out.&#8221;&#8221;&#8221;<\/p>\n\n\n\n<p class=\"has-light-blue-background-color has-background wp-block-paragraph\">&nbsp;&nbsp;&nbsp; cut = &#8220;&#8221;<\/p>\n\n\n\n<p class=\"has-light-blue-background-color has-background wp-block-paragraph\">&nbsp;&nbsp;&nbsp; length = audio_length(src)<\/p>\n\n\n\n<p class=\"has-light-blue-background-color has-background wp-block-paragraph\">&nbsp;&nbsp;&nbsp; if max_seconds and length and length &gt; max_seconds + 0.5:<\/p>\n\n\n\n<p class=\"has-light-blue-background-color has-background wp-block-paragraph\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; fade_start = max(max_seconds &#8211; 1.5, 0)<\/p>\n\n\n\n<p class=\"has-light-blue-background-color has-background wp-block-paragraph\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; cut = f&#8217;-t {max_seconds} -af &#8220;afade=t=out:st={fade_start}:d=1.5&#8243;&#8216;<\/p>\n\n\n\n<p class=\"has-light-blue-background-color has-background wp-block-paragraph\">&nbsp;&nbsp;&nbsp; run(f&#8217;ffmpeg -y -loglevel error -i &#8220;{src}&#8221; {cut} {codec_args} &#8220;{dst}&#8221;&#8216;)<\/p>\n\n\n\n<p class=\"has-light-blue-background-color has-background wp-block-paragraph\"># &#8212; 6. Generate (one variation per iteration) &#8212;<\/p>\n\n\n\n<p class=\"has-light-blue-background-color has-background wp-block-paragraph\">stamp = time.strftime(&#8220;%Y%m%d_%H%M%S&#8221;)<\/p>\n\n\n\n<p class=\"has-light-blue-background-color has-background wp-block-paragraph\">saved = []<\/p>\n\n\n\n<p class=\"has-light-blue-background-color has-background wp-block-paragraph\">for i in range(BATCH_SIZE):<\/p>\n\n\n\n<p class=\"has-light-blue-background-color has-background wp-block-paragraph\">&nbsp;&nbsp;&nbsp; seed = random.randint(0, 2**31 &#8211; 1) if SEED == -1 else SEED + i<\/p>\n\n\n\n<p class=\"has-light-blue-background-color has-background wp-block-paragraph\">&nbsp;&nbsp;&nbsp; name = f&#8221;song_{stamp}_v{i + 1}_seed{seed}&#8221;<\/p>\n\n\n\n<p class=\"has-light-blue-background-color has-background wp-block-paragraph\">&nbsp;&nbsp;&nbsp; print(f&#8221;\\nGenerating variation {i + 1}\/{BATCH_SIZE} (seed {seed})&#8230;&#8221;)<\/p>\n\n\n\n<p class=\"has-light-blue-background-color has-background wp-block-paragraph\">&nbsp;&nbsp;&nbsp; t0 = time.time()<\/p>\n\n\n\n<p class=\"has-light-blue-background-color has-background wp-block-paragraph\">&nbsp;&nbsp;&nbsp; gen_kwargs = dict(style=style, lyrics=lyrics, seed=seed)<\/p>\n\n\n\n<p class=\"has-light-blue-background-color has-background wp-block-paragraph\">&nbsp;&nbsp;&nbsp; if USE_LM:<\/p>\n\n\n\n<p class=\"has-light-blue-background-color has-background wp-block-paragraph\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; gen_kwargs[&#8220;cot&#8221;] = &#8220;full&#8221;&nbsp;&nbsp; # full melody and chord planning<\/p>\n\n\n\n<p class=\"has-light-blue-background-color has-background wp-block-paragraph\">&nbsp;&nbsp;&nbsp; song = pipe(**gen_kwargs)<\/p>\n\n\n\n<p class=\"has-light-blue-background-color has-background wp-block-paragraph\">&nbsp;&nbsp;&nbsp; raw = os.path.join(OUTPUT_DIR, f&#8221;{name}_raw.flac&#8221;)<\/p>\n\n\n\n<p class=\"has-light-blue-background-color has-background wp-block-paragraph\">&nbsp;&nbsp;&nbsp; song.save(raw)<\/p>\n\n\n\n<p class=\"has-light-blue-background-color has-background wp-block-paragraph\">&nbsp;&nbsp;&nbsp; song.save_artifacts(os.path.join(OUTPUT_DIR, f&#8221;{name}_artifacts&#8221;))<\/p>\n\n\n\n<p class=\"has-light-blue-background-color has-background wp-block-paragraph\">&nbsp;&nbsp;&nbsp; final = os.path.join(OUTPUT_DIR, f&#8221;{name}.{ext}&#8221;)<\/p>\n\n\n\n<p class=\"has-light-blue-background-color has-background wp-block-paragraph\">&nbsp;&nbsp;&nbsp; convert(raw, final, max_seconds=DURATION if DURATION and DURATION &gt; 0 else None)<\/p>\n\n\n\n<p class=\"has-light-blue-background-color has-background wp-block-paragraph\">&nbsp;&nbsp;&nbsp; if os.path.abspath(raw) != os.path.abspath(final):<\/p>\n\n\n\n<p class=\"has-light-blue-background-color has-background wp-block-paragraph\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; os.remove(raw)<\/p>\n\n\n\n<p class=\"has-light-blue-background-color has-background wp-block-paragraph\">&nbsp;&nbsp;&nbsp; saved.append(final)<\/p>\n\n\n\n<p class=\"has-light-blue-background-color has-background wp-block-paragraph\">&nbsp;&nbsp;&nbsp; print(f&#8221;Variation {i + 1} ready in {time.time() &#8211; t0:.1f}s&#8221;)<\/p>\n\n\n\n<p class=\"has-light-blue-background-color has-background wp-block-paragraph\">&nbsp;&nbsp;&nbsp; if torch is not None:<\/p>\n\n\n\n<p class=\"has-light-blue-background-color has-background wp-block-paragraph\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; torch.cuda.empty_cache()<\/p>\n\n\n\n<p class=\"has-light-blue-background-color has-background wp-block-paragraph\"># &#8212; 7. Summary &#8212;<\/p>\n\n\n\n<p class=\"has-light-blue-background-color has-background wp-block-paragraph\">print(&#8220;\\nGeneration complete! Audio files:&#8221;)<\/p>\n\n\n\n<p class=\"has-light-blue-background-color has-background wp-block-paragraph\">for f in saved:<\/p>\n\n\n\n<p class=\"has-light-blue-background-color has-background wp-block-paragraph\">&nbsp;&nbsp;&nbsp; print(&#8221;&nbsp; &#8220;, f)<\/p>\n\n\n\n<p class=\"has-light-blue-background-color has-background wp-block-paragraph\">print(f&#8221;Artifacts (per variation) in: {OUTPUT_DIR}\/*_artifacts&#8221;)<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The rest of the script handles the behind-the-scenes work: it checks that the GPU is active, makes sure it is running inside the venv, builds the style text (adding BPM, key and language), loads the model, generates each variation, converts the audio and prints a summary with the path of the files. Each variation also gets an artifacts folder with the melody and chord plan.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Step 5: generate and listen<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Run the cell below. The first run downloads the model and may take a while, and later runs are faster. Watch for the message \u201cGenerating variation 1\/1\u201d and wait a few minutes.<\/p>\n\n\n\n<p class=\"has-light-blue-background-color has-background wp-block-paragraph\"># Cell 6: Run the generation<\/p>\n\n\n\n<p class=\"has-light-blue-background-color has-background wp-block-paragraph\">!\/content\/yue2_env\/bin\/python \/content\/generate_music.py<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">When it finishes, the next cell plays the latest generated songs right there in the notebook, with no need to download anything.<\/p>\n\n\n\n<p class=\"has-light-blue-background-color has-background has-medium-font-size wp-block-paragraph\"># Cell 7: Listen to the latest generated songs<\/p>\n\n\n\n<p class=\"has-light-blue-background-color has-background wp-block-paragraph\">import glob, os<\/p>\n\n\n\n<p class=\"has-light-blue-background-color has-background wp-block-paragraph\">from IPython.display import Audio, display<\/p>\n\n\n\n<p class=\"has-light-blue-background-color has-background wp-block-paragraph\">exts = (&#8220;.wav&#8221;, &#8220;.flac&#8221;, &#8220;.mp3&#8221;, &#8220;.opus&#8221;, &#8220;.aac&#8221;)<\/p>\n\n\n\n<p class=\"has-light-blue-background-color has-background wp-block-paragraph\">files = [f for f in glob.glob(&#8220;\/content\/generated_songs\/*&#8221;) if f.lower().endswith(exts)]<\/p>\n\n\n\n<p class=\"has-light-blue-background-color has-background wp-block-paragraph\">for f in sorted(files, key=os.path.getmtime)[-4:]:<\/p>\n\n\n\n<p class=\"has-light-blue-background-color has-background wp-block-paragraph\">&nbsp;&nbsp;&nbsp; print(f)<\/p>\n\n\n\n<p class=\"has-light-blue-background-color has-background wp-block-paragraph\">&nbsp;&nbsp;&nbsp; display(Audio(f))<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">If you see a message saying that no GPU was found, go back to the Runtime menu and confirm the accelerator you chose. If the warning says the yue2 module was not found, run cells 1 and 2 again, because the virtual environment disappears when the session is restarted. And remember: every generation spends computing units, so test first with BATCH_SIZE = 1 and a short DURATION, and only then generate in larger quantities.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">How to write the style and the lyrics<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">The code is only half of the work. The other half is writing good requests. A few principles that work well:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Short, specific style:<\/strong> genre, instruments, mood and tempo. For example: &#8220;blues with piano, cello, double bass, sax and soft drums&#8221;.<\/li>\n\n\n\n<li><strong>Clear structure:<\/strong> use sections such as [Intro], [Verse], [Chorus] and [Outro], with short lines and one idea per line, thinking about how they would be sung.<\/li>\n\n\n\n<li><strong>Instrumental:<\/strong> with LYRICS = &#8220;[Instrumental]&#8221;, the script already adds \u201cno vocals\u201d to the style and builds the structure by itself.<\/li>\n\n\n\n<li><strong>Variations:<\/strong> generate several versions with different seeds and pick the best one, the way you would choose among takes.<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">To control the dynamics of an instrumental track, you can describe what happens inside each section. Try pasting the block below in place of CAPTION, LYRICS and VOCAL_LANGUAGE in the script. Changing the language to &#8220;unknown&#8221; prevents the script from adding \u201cen vocals\u201d to the style of a piece that has no voice.<\/p>\n\n\n\n<p class=\"has-light-pink-background-color has-background wp-block-paragraph\">CAPTION = &#8220;Orchestral instrumental in cinematic movie style, complete orchestra, strictly instrumental, clear production&#8221;<\/p>\n\n\n\n<p class=\"has-light-pink-background-color has-background wp-block-paragraph\">LYRICS = &#8220;&#8221;&#8221;[Intro &#8211; instrumental]<\/p>\n\n\n\n<p class=\"has-light-pink-background-color has-background wp-block-paragraph\">[instrumental &#8211; verse 1]<\/p>\n\n\n\n<p class=\"has-light-pink-background-color has-background wp-block-paragraph\">dynamics increasing until climax, starting with woodwind until full orchestra, strictly instrumental, no vocals<\/p>\n\n\n\n<p class=\"has-light-pink-background-color has-background wp-block-paragraph\">[instrumental &#8211; chorus]<\/p>\n\n\n\n<p class=\"has-light-pink-background-color has-background wp-block-paragraph\">strings, brass and timpani, with energy, strictly instrumental, no vocals<\/p>\n\n\n\n<p class=\"has-light-pink-background-color has-background wp-block-paragraph\">[instrumental &#8211; verse 2]<\/p>\n\n\n\n<p class=\"has-light-pink-background-color has-background wp-block-paragraph\">dynamics decreasing in volume, cello solo, strictly instrumental, no vocals<\/p>\n\n\n\n<p class=\"has-light-pink-background-color has-background wp-block-paragraph\">[instrumental &#8211; ending]<\/p>\n\n\n\n<p class=\"has-light-pink-background-color has-background wp-block-paragraph\">full orchestra, strictly instrumental, no vocals<\/p>\n\n\n\n<p class=\"has-light-pink-background-color has-background wp-block-paragraph\">&#8220;&#8221;&#8221;<\/p>\n\n\n\n<p class=\"has-light-pink-background-color has-background wp-block-paragraph\">VOCAL_LANGUAGE = &#8220;unknown&#8221;<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Save your songs before ending the session<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Everything in the \/content folder disappears when the session ends. Before disconnecting, download your files from the file panel (the folder icon on the left side; click the three dots next to the file and choose Download). Another option is to mount Google Drive with the cell below, run before the generation, and point OUTPUT_DIR to a folder inside \/content\/drive\/MyDrive\/. Drive will ask for authorization from your Google account.<\/p>\n\n\n\n<p class=\"has-light-blue-background-color has-background wp-block-paragraph\"># Optional: mount Google Drive to keep your songs (remove the # from the two lines)<\/p>\n\n\n\n<p class=\"has-light-blue-background-color has-background wp-block-paragraph\">from google.colab import drive<\/p>\n\n\n\n<p class=\"has-light-blue-background-color has-background wp-block-paragraph\">drive.mount(&#8216;\/content\/drive&#8217;)<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Conclusion<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Generating music with an open model takes a little more work than clicking a button, but it gives back something valuable: clarity about the rules of the game. You know which license applies, where your files are and how much you are paying per hour of studio time. Just remember that the YuE2-3B weights are for non-commercial use and that the debate over training data is still open.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">YuE2 can also create covers from a melody in ABC notation, apply LoRA adapters for instrumental music and run everything in a graphical interface in ComfyUI. Those are topics for upcoming posts. And you, what do you plan to create first: a song with your own lyrics or an instrumental soundtrack? Tell us in the comments.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Further reading<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/huggingface.co\/M-A-P\/YuE2-3B\">Official YuE2-3B model page on Hugging Face<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/link.amazon\/B05sg9iDL\" target=\"_blank\" rel=\"noopener\">The Science of AI Music: A Beginner\u2019s Guide to AI Songwriting, Production &amp; Music Creation (English Edition)<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/link.amazon\/B08DphY4x\" target=\"_blank\" rel=\"noopener\">AI Music Prompts: EDM: 1000+ Copy-Paste Prompts for Suno, Udio &amp; AI Music Generators: 4<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/suno.com\/blog\/suno-updates-tos\">Suno: update to the downloads policy and Terms of Service<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/colab.research.google.com\/signup\">Google Colab: plans and pricing<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/colab.research.google.com\">Google Colab<\/a><\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Who owns the song you created with artificial intelligence? The question sounds simple, but the answer can change depending on the plan you pay for, the version of the terms of service and even the month in which you accepted the rules. Picture the scene. You spend an afternoon polishing a set of lyrics, choosing &hellip; <a href=\"https:\/\/makingmusic4ever.com\/index.php\/2026\/10\/22\/how-to-generate-music-with-the-open-source-yue2-3b-model-on-google-colab\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">How to Generate Music with the Open-Source YuE2-3B Model on Google Colab<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":2110,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_feature_clip_id":0,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2},"jetpack_post_was_ever_published":false},"categories":[6,5,4],"tags":[10,9,30,1166,1165,1163,1164],"class_list":["post-2107","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-ai","category-artificial-intelligence","category-music","tag-ai","tag-artificial-intelligence","tag-music","tag-music-with-ai","tag-open-source","tag-suno","tag-yue-2-model"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v28.7 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>How to Generate Music with the Open-Source YuE2-3B Model on Google Colab - Making Music 4 Ever<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/makingmusic4ever.com\/index.php\/2026\/10\/22\/how-to-generate-music-with-the-open-source-yue2-3b-model-on-google-colab\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to Generate Music with the Open-Source YuE2-3B Model on Google Colab - Making Music 4 Ever\" \/>\n<meta property=\"og:description\" content=\"Who owns the song you created with artificial intelligence? The question sounds simple, but the answer can change depending on the plan you pay for, the version of the terms of service and even the month in which you accepted the rules. Picture the scene. You spend an afternoon polishing a set of lyrics, choosing &hellip; Continue reading How to Generate Music with the Open-Source YuE2-3B Model on Google Colab\" \/>\n<meta property=\"og:url\" content=\"https:\/\/makingmusic4ever.com\/index.php\/2026\/10\/22\/how-to-generate-music-with-the-open-source-yue2-3b-model-on-google-colab\/\" \/>\n<meta property=\"og:site_name\" content=\"Making Music 4 Ever\" \/>\n<meta property=\"article:published_time\" content=\"2026-10-22T15:43:33+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2026-10-22T15:43:35+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/makingmusic4ever.com\/wp-content\/uploads\/2026\/10\/Vinyl_record_with_binary_code_20261022123849.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1376\" \/>\n\t<meta property=\"og:image:height\" content=\"768\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"editor\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"editor\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"18 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/makingmusic4ever.com\\\/index.php\\\/2026\\\/10\\\/22\\\/how-to-generate-music-with-the-open-source-yue2-3b-model-on-google-colab\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/makingmusic4ever.com\\\/index.php\\\/2026\\\/10\\\/22\\\/how-to-generate-music-with-the-open-source-yue2-3b-model-on-google-colab\\\/\"},\"author\":{\"name\":\"editor\",\"@id\":\"https:\\\/\\\/makingmusic4ever.com\\\/#\\\/schema\\\/person\\\/90746a5c76f42922c409876f713df7e8\"},\"headline\":\"How to Generate Music with the Open-Source YuE2-3B Model on Google Colab\",\"datePublished\":\"2026-10-22T15:43:33+00:00\",\"dateModified\":\"2026-10-22T15:43:35+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/makingmusic4ever.com\\\/index.php\\\/2026\\\/10\\\/22\\\/how-to-generate-music-with-the-open-source-yue2-3b-model-on-google-colab\\\/\"},\"wordCount\":4771,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/makingmusic4ever.com\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/makingmusic4ever.com\\\/index.php\\\/2026\\\/10\\\/22\\\/how-to-generate-music-with-the-open-source-yue2-3b-model-on-google-colab\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/i0.wp.com\\\/makingmusic4ever.com\\\/wp-content\\\/uploads\\\/2026\\\/10\\\/Vinyl_record_with_binary_code_20261022123849.jpg?fit=1376%2C768&ssl=1\",\"keywords\":[\"ai\",\"artificial intelligence\",\"music\",\"music with ai\",\"open-source\",\"suno\",\"yuE-2 model\"],\"articleSection\":[\"ai\",\"artificial intelligence\",\"music\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/makingmusic4ever.com\\\/index.php\\\/2026\\\/10\\\/22\\\/how-to-generate-music-with-the-open-source-yue2-3b-model-on-google-colab\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/makingmusic4ever.com\\\/index.php\\\/2026\\\/10\\\/22\\\/how-to-generate-music-with-the-open-source-yue2-3b-model-on-google-colab\\\/\",\"url\":\"https:\\\/\\\/makingmusic4ever.com\\\/index.php\\\/2026\\\/10\\\/22\\\/how-to-generate-music-with-the-open-source-yue2-3b-model-on-google-colab\\\/\",\"name\":\"How to Generate Music with the Open-Source YuE2-3B Model on Google Colab - Making Music 4 Ever\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/makingmusic4ever.com\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/makingmusic4ever.com\\\/index.php\\\/2026\\\/10\\\/22\\\/how-to-generate-music-with-the-open-source-yue2-3b-model-on-google-colab\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/makingmusic4ever.com\\\/index.php\\\/2026\\\/10\\\/22\\\/how-to-generate-music-with-the-open-source-yue2-3b-model-on-google-colab\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/i0.wp.com\\\/makingmusic4ever.com\\\/wp-content\\\/uploads\\\/2026\\\/10\\\/Vinyl_record_with_binary_code_20261022123849.jpg?fit=1376%2C768&ssl=1\",\"datePublished\":\"2026-10-22T15:43:33+00:00\",\"dateModified\":\"2026-10-22T15:43:35+00:00\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/makingmusic4ever.com\\\/index.php\\\/2026\\\/10\\\/22\\\/how-to-generate-music-with-the-open-source-yue2-3b-model-on-google-colab\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/makingmusic4ever.com\\\/index.php\\\/2026\\\/10\\\/22\\\/how-to-generate-music-with-the-open-source-yue2-3b-model-on-google-colab\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/makingmusic4ever.com\\\/index.php\\\/2026\\\/10\\\/22\\\/how-to-generate-music-with-the-open-source-yue2-3b-model-on-google-colab\\\/#primaryimage\",\"url\":\"https:\\\/\\\/i0.wp.com\\\/makingmusic4ever.com\\\/wp-content\\\/uploads\\\/2026\\\/10\\\/Vinyl_record_with_binary_code_20261022123849.jpg?fit=1376%2C768&ssl=1\",\"contentUrl\":\"https:\\\/\\\/i0.wp.com\\\/makingmusic4ever.com\\\/wp-content\\\/uploads\\\/2026\\\/10\\\/Vinyl_record_with_binary_code_20261022123849.jpg?fit=1376%2C768&ssl=1\",\"width\":1376,\"height\":768,\"caption\":\"AI Music\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/makingmusic4ever.com\\\/index.php\\\/2026\\\/10\\\/22\\\/how-to-generate-music-with-the-open-source-yue2-3b-model-on-google-colab\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/makingmusic4ever.com\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How to Generate Music with the Open-Source YuE2-3B Model on Google Colab\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/makingmusic4ever.com\\\/#website\",\"url\":\"https:\\\/\\\/makingmusic4ever.com\\\/\",\"name\":\"Making Music 4 Ever\",\"description\":\"Music for everyone\",\"publisher\":{\"@id\":\"https:\\\/\\\/makingmusic4ever.com\\\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/makingmusic4ever.com\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/makingmusic4ever.com\\\/#organization\",\"name\":\"Making Music 4 Ever\",\"url\":\"https:\\\/\\\/makingmusic4ever.com\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/makingmusic4ever.com\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/i0.wp.com\\\/makingmusic4ever.com\\\/wp-content\\\/uploads\\\/2019\\\/04\\\/cropped-MakinMusicLogo.aiRed_-2.jpg?fit=248%2C248&ssl=1\",\"contentUrl\":\"https:\\\/\\\/i0.wp.com\\\/makingmusic4ever.com\\\/wp-content\\\/uploads\\\/2019\\\/04\\\/cropped-MakinMusicLogo.aiRed_-2.jpg?fit=248%2C248&ssl=1\",\"width\":248,\"height\":248,\"caption\":\"Making Music 4 Ever\"},\"image\":{\"@id\":\"https:\\\/\\\/makingmusic4ever.com\\\/#\\\/schema\\\/logo\\\/image\\\/\"}},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/makingmusic4ever.com\\\/#\\\/schema\\\/person\\\/90746a5c76f42922c409876f713df7e8\",\"name\":\"editor\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/40a180061deabb68d04bd9f812bde2b372b5d57984baf7dd947ee866377d90fb?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/40a180061deabb68d04bd9f812bde2b372b5d57984baf7dd947ee866377d90fb?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/40a180061deabb68d04bd9f812bde2b372b5d57984baf7dd947ee866377d90fb?s=96&d=mm&r=g\",\"caption\":\"editor\"},\"url\":\"https:\\\/\\\/makingmusic4ever.com\\\/index.php\\\/author\\\/editor\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"How to Generate Music with the Open-Source YuE2-3B Model on Google Colab - Making Music 4 Ever","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/makingmusic4ever.com\/index.php\/2026\/10\/22\/how-to-generate-music-with-the-open-source-yue2-3b-model-on-google-colab\/","og_locale":"en_US","og_type":"article","og_title":"How to Generate Music with the Open-Source YuE2-3B Model on Google Colab - Making Music 4 Ever","og_description":"Who owns the song you created with artificial intelligence? The question sounds simple, but the answer can change depending on the plan you pay for, the version of the terms of service and even the month in which you accepted the rules. Picture the scene. You spend an afternoon polishing a set of lyrics, choosing &hellip; Continue reading How to Generate Music with the Open-Source YuE2-3B Model on Google Colab","og_url":"https:\/\/makingmusic4ever.com\/index.php\/2026\/10\/22\/how-to-generate-music-with-the-open-source-yue2-3b-model-on-google-colab\/","og_site_name":"Making Music 4 Ever","article_published_time":"2026-10-22T15:43:33+00:00","article_modified_time":"2026-10-22T15:43:35+00:00","og_image":[{"width":1376,"height":768,"url":"https:\/\/makingmusic4ever.com\/wp-content\/uploads\/2026\/10\/Vinyl_record_with_binary_code_20261022123849.jpg","type":"image\/jpeg"}],"author":"editor","twitter_card":"summary_large_image","twitter_misc":{"Written by":"editor","Est. reading time":"18 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/makingmusic4ever.com\/index.php\/2026\/10\/22\/how-to-generate-music-with-the-open-source-yue2-3b-model-on-google-colab\/#article","isPartOf":{"@id":"https:\/\/makingmusic4ever.com\/index.php\/2026\/10\/22\/how-to-generate-music-with-the-open-source-yue2-3b-model-on-google-colab\/"},"author":{"name":"editor","@id":"https:\/\/makingmusic4ever.com\/#\/schema\/person\/90746a5c76f42922c409876f713df7e8"},"headline":"How to Generate Music with the Open-Source YuE2-3B Model on Google Colab","datePublished":"2026-10-22T15:43:33+00:00","dateModified":"2026-10-22T15:43:35+00:00","mainEntityOfPage":{"@id":"https:\/\/makingmusic4ever.com\/index.php\/2026\/10\/22\/how-to-generate-music-with-the-open-source-yue2-3b-model-on-google-colab\/"},"wordCount":4771,"commentCount":0,"publisher":{"@id":"https:\/\/makingmusic4ever.com\/#organization"},"image":{"@id":"https:\/\/makingmusic4ever.com\/index.php\/2026\/10\/22\/how-to-generate-music-with-the-open-source-yue2-3b-model-on-google-colab\/#primaryimage"},"thumbnailUrl":"https:\/\/i0.wp.com\/makingmusic4ever.com\/wp-content\/uploads\/2026\/10\/Vinyl_record_with_binary_code_20261022123849.jpg?fit=1376%2C768&ssl=1","keywords":["ai","artificial intelligence","music","music with ai","open-source","suno","yuE-2 model"],"articleSection":["ai","artificial intelligence","music"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/makingmusic4ever.com\/index.php\/2026\/10\/22\/how-to-generate-music-with-the-open-source-yue2-3b-model-on-google-colab\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/makingmusic4ever.com\/index.php\/2026\/10\/22\/how-to-generate-music-with-the-open-source-yue2-3b-model-on-google-colab\/","url":"https:\/\/makingmusic4ever.com\/index.php\/2026\/10\/22\/how-to-generate-music-with-the-open-source-yue2-3b-model-on-google-colab\/","name":"How to Generate Music with the Open-Source YuE2-3B Model on Google Colab - Making Music 4 Ever","isPartOf":{"@id":"https:\/\/makingmusic4ever.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/makingmusic4ever.com\/index.php\/2026\/10\/22\/how-to-generate-music-with-the-open-source-yue2-3b-model-on-google-colab\/#primaryimage"},"image":{"@id":"https:\/\/makingmusic4ever.com\/index.php\/2026\/10\/22\/how-to-generate-music-with-the-open-source-yue2-3b-model-on-google-colab\/#primaryimage"},"thumbnailUrl":"https:\/\/i0.wp.com\/makingmusic4ever.com\/wp-content\/uploads\/2026\/10\/Vinyl_record_with_binary_code_20261022123849.jpg?fit=1376%2C768&ssl=1","datePublished":"2026-10-22T15:43:33+00:00","dateModified":"2026-10-22T15:43:35+00:00","breadcrumb":{"@id":"https:\/\/makingmusic4ever.com\/index.php\/2026\/10\/22\/how-to-generate-music-with-the-open-source-yue2-3b-model-on-google-colab\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/makingmusic4ever.com\/index.php\/2026\/10\/22\/how-to-generate-music-with-the-open-source-yue2-3b-model-on-google-colab\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/makingmusic4ever.com\/index.php\/2026\/10\/22\/how-to-generate-music-with-the-open-source-yue2-3b-model-on-google-colab\/#primaryimage","url":"https:\/\/i0.wp.com\/makingmusic4ever.com\/wp-content\/uploads\/2026\/10\/Vinyl_record_with_binary_code_20261022123849.jpg?fit=1376%2C768&ssl=1","contentUrl":"https:\/\/i0.wp.com\/makingmusic4ever.com\/wp-content\/uploads\/2026\/10\/Vinyl_record_with_binary_code_20261022123849.jpg?fit=1376%2C768&ssl=1","width":1376,"height":768,"caption":"AI Music"},{"@type":"BreadcrumbList","@id":"https:\/\/makingmusic4ever.com\/index.php\/2026\/10\/22\/how-to-generate-music-with-the-open-source-yue2-3b-model-on-google-colab\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/makingmusic4ever.com\/"},{"@type":"ListItem","position":2,"name":"How to Generate Music with the Open-Source YuE2-3B Model on Google Colab"}]},{"@type":"WebSite","@id":"https:\/\/makingmusic4ever.com\/#website","url":"https:\/\/makingmusic4ever.com\/","name":"Making Music 4 Ever","description":"Music for everyone","publisher":{"@id":"https:\/\/makingmusic4ever.com\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/makingmusic4ever.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/makingmusic4ever.com\/#organization","name":"Making Music 4 Ever","url":"https:\/\/makingmusic4ever.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/makingmusic4ever.com\/#\/schema\/logo\/image\/","url":"https:\/\/i0.wp.com\/makingmusic4ever.com\/wp-content\/uploads\/2019\/04\/cropped-MakinMusicLogo.aiRed_-2.jpg?fit=248%2C248&ssl=1","contentUrl":"https:\/\/i0.wp.com\/makingmusic4ever.com\/wp-content\/uploads\/2019\/04\/cropped-MakinMusicLogo.aiRed_-2.jpg?fit=248%2C248&ssl=1","width":248,"height":248,"caption":"Making Music 4 Ever"},"image":{"@id":"https:\/\/makingmusic4ever.com\/#\/schema\/logo\/image\/"}},{"@type":"Person","@id":"https:\/\/makingmusic4ever.com\/#\/schema\/person\/90746a5c76f42922c409876f713df7e8","name":"editor","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/40a180061deabb68d04bd9f812bde2b372b5d57984baf7dd947ee866377d90fb?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/40a180061deabb68d04bd9f812bde2b372b5d57984baf7dd947ee866377d90fb?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/40a180061deabb68d04bd9f812bde2b372b5d57984baf7dd947ee866377d90fb?s=96&d=mm&r=g","caption":"editor"},"url":"https:\/\/makingmusic4ever.com\/index.php\/author\/editor\/"}]}},"jetpack_publicize_connections":[],"jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/pamHgp-xZ","jetpack-related-posts":[{"id":114,"url":"https:\/\/makingmusic4ever.com\/index.php\/2019\/04\/12\/artificial-intelligence-impacts-music-market\/","url_meta":{"origin":2107,"position":0},"title":"Artificial Intelligence impacts Music Market","author":"editor","date":"April 12, 2019","format":false,"excerpt":"A new Technology More and more technological innovation affects most different businesses including the music market. In the past, the use of computerized harmonization caused discussions and resistance from traditional musicians, but at the same time creating new opportunities for those who embraced the new technology. The music distribution industry\u2026","rel":"","context":"In &quot;ai&quot;","block_context":{"text":"ai","link":"https:\/\/makingmusic4ever.com\/index.php\/category\/ai\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/makingmusic4ever.com\/wp-content\/uploads\/2019\/04\/musicAI.001.jpeg?fit=825%2C510&ssl=1&resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/makingmusic4ever.com\/wp-content\/uploads\/2019\/04\/musicAI.001.jpeg?fit=825%2C510&ssl=1&resize=350%2C200 1x, https:\/\/i0.wp.com\/makingmusic4ever.com\/wp-content\/uploads\/2019\/04\/musicAI.001.jpeg?fit=825%2C510&ssl=1&resize=525%2C300 1.5x, https:\/\/i0.wp.com\/makingmusic4ever.com\/wp-content\/uploads\/2019\/04\/musicAI.001.jpeg?fit=825%2C510&ssl=1&resize=700%2C400 2x"},"classes":[]},{"id":131,"url":"https:\/\/makingmusic4ever.com\/index.php\/2019\/04\/16\/what-is-a-diminished-chord-and-how-to-use-it\/","url_meta":{"origin":2107,"position":1},"title":"What is a diminished chord and how to use it","author":"editor","date":"April 16, 2019","format":false,"excerpt":"Definition The diminished chord can be used in many ways and there are many questions about how to apply them. One of the applications is to use it as a passage chord to give harmony a color. It can also be used in modulations (changes of tonalities, chromatic approximations, the\u2026","rel":"","context":"In &quot;chords&quot;","block_context":{"text":"chords","link":"https:\/\/makingmusic4ever.com\/index.php\/category\/chords\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/makingmusic4ever.com\/wp-content\/uploads\/2019\/04\/DiminishedChord.jpg?fit=680%2C330&ssl=1&resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/makingmusic4ever.com\/wp-content\/uploads\/2019\/04\/DiminishedChord.jpg?fit=680%2C330&ssl=1&resize=350%2C200 1x, https:\/\/i0.wp.com\/makingmusic4ever.com\/wp-content\/uploads\/2019\/04\/DiminishedChord.jpg?fit=680%2C330&ssl=1&resize=525%2C300 1.5x"},"classes":[]},{"id":1031,"url":"https:\/\/makingmusic4ever.com\/index.php\/2023\/09\/06\/how-to-create-and-sell-copyrighted-musical-scores-arrangements-on-the-internet\/","url_meta":{"origin":2107,"position":2},"title":"How to create and sell copyrighted musical scores arrangements on the internet.","author":"editor","date":"September 6, 2023","format":false,"excerpt":"Remember that arrangement you wrote for your band and it's still stored on your computer's hard drive? Did you know that you can sell it and still make some extra money? Or maybe, it can even become a business. Do you want to know how? Stay with me on this\u2026","rel":"","context":"In &quot;arrangement&quot;","block_context":{"text":"arrangement","link":"https:\/\/makingmusic4ever.com\/index.php\/category\/arrangement\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/makingmusic4ever.com\/wp-content\/uploads\/2023\/09\/sheet-music-4121936_1280.jpg?fit=1200%2C800&ssl=1&resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/makingmusic4ever.com\/wp-content\/uploads\/2023\/09\/sheet-music-4121936_1280.jpg?fit=1200%2C800&ssl=1&resize=350%2C200 1x, https:\/\/i0.wp.com\/makingmusic4ever.com\/wp-content\/uploads\/2023\/09\/sheet-music-4121936_1280.jpg?fit=1200%2C800&ssl=1&resize=525%2C300 1.5x, https:\/\/i0.wp.com\/makingmusic4ever.com\/wp-content\/uploads\/2023\/09\/sheet-music-4121936_1280.jpg?fit=1200%2C800&ssl=1&resize=700%2C400 2x, https:\/\/i0.wp.com\/makingmusic4ever.com\/wp-content\/uploads\/2023\/09\/sheet-music-4121936_1280.jpg?fit=1200%2C800&ssl=1&resize=1050%2C600 3x"},"classes":[]},{"id":1061,"url":"https:\/\/makingmusic4ever.com\/index.php\/2023\/10\/11\/how-to-link-the-tablature-with-the-score-in-musescore-4\/","url_meta":{"origin":2107,"position":3},"title":"How to Link the Tablature with the Score in Musescore 4.","author":"editor","date":"October 11, 2023","format":false,"excerpt":"Musescore 4 has a very useful function for guitarists, bassists, mandolinists or any string instrument that you want to set up the tablature synchronized automatically with the score. In previous versions of this software, it was necessary to create an independent tablature and then copy the notes from the score\u2026","rel":"","context":"In &quot;arrangement&quot;","block_context":{"text":"arrangement","link":"https:\/\/makingmusic4ever.com\/index.php\/category\/arrangement\/"},"img":{"alt_text":"linked tablature","src":"https:\/\/i0.wp.com\/makingmusic4ever.com\/wp-content\/uploads\/2023\/10\/Tablatura-sincronizada-2.png?fit=1200%2C675&ssl=1&resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/makingmusic4ever.com\/wp-content\/uploads\/2023\/10\/Tablatura-sincronizada-2.png?fit=1200%2C675&ssl=1&resize=350%2C200 1x, https:\/\/i0.wp.com\/makingmusic4ever.com\/wp-content\/uploads\/2023\/10\/Tablatura-sincronizada-2.png?fit=1200%2C675&ssl=1&resize=525%2C300 1.5x, https:\/\/i0.wp.com\/makingmusic4ever.com\/wp-content\/uploads\/2023\/10\/Tablatura-sincronizada-2.png?fit=1200%2C675&ssl=1&resize=700%2C400 2x, https:\/\/i0.wp.com\/makingmusic4ever.com\/wp-content\/uploads\/2023\/10\/Tablatura-sincronizada-2.png?fit=1200%2C675&ssl=1&resize=1050%2C600 3x"},"classes":[]},{"id":1229,"url":"https:\/\/makingmusic4ever.com\/index.php\/2024\/08\/24\/chords-outside-the-scale-how-modal-borrowing-can-boost-your-harmonic-progressions\/","url_meta":{"origin":2107,"position":4},"title":"Chords Outside the Scale: How Modal Borrowing Can Boost Your Harmonic Progressions","author":"editor","date":"August 24, 2024","format":false,"excerpt":"Have you ever wondered how some songs surprise our ears with unexpected and exciting harmonies? Welcome to the fascinating world of modal borrowing! In this post, we'll dive deep into this musical concept that has the power to transform common progressions into unique sonic experiences. Whether you're a beginner musician\u2026","rel":"","context":"In &quot;arrangement&quot;","block_context":{"text":"arrangement","link":"https:\/\/makingmusic4ever.com\/index.php\/category\/arrangement\/"},"img":{"alt_text":"Musical Notes Puzzle","src":"https:\/\/i0.wp.com\/makingmusic4ever.com\/wp-content\/uploads\/2024\/08\/MusicalNotesPuzzle.jpeg?fit=1024%2C1024&ssl=1&resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/makingmusic4ever.com\/wp-content\/uploads\/2024\/08\/MusicalNotesPuzzle.jpeg?fit=1024%2C1024&ssl=1&resize=350%2C200 1x, https:\/\/i0.wp.com\/makingmusic4ever.com\/wp-content\/uploads\/2024\/08\/MusicalNotesPuzzle.jpeg?fit=1024%2C1024&ssl=1&resize=525%2C300 1.5x, https:\/\/i0.wp.com\/makingmusic4ever.com\/wp-content\/uploads\/2024\/08\/MusicalNotesPuzzle.jpeg?fit=1024%2C1024&ssl=1&resize=700%2C400 2x"},"classes":[]},{"id":691,"url":"https:\/\/makingmusic4ever.com\/index.php\/2022\/04\/24\/historia-de-un-amor-score-and-tab\/","url_meta":{"origin":2107,"position":5},"title":"Historia de un Amor &#8211; Score and Tab","author":"editor","date":"April 24, 2022","format":false,"excerpt":"Looking for a good guitar score for Historia de un Amor? I have good news for you. Stay with me and I'll show you a good video, score and Tab for this song. Historia de un amor in English means \"the story of a love\" and tells about a man's\u2026","rel":"","context":"In &quot;chords&quot;","block_context":{"text":"chords","link":"https:\/\/makingmusic4ever.com\/index.php\/category\/chords\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/makingmusic4ever.com\/wp-content\/uploads\/2022\/04\/historiadeun-amor.png?fit=809%2C398&ssl=1&resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/makingmusic4ever.com\/wp-content\/uploads\/2022\/04\/historiadeun-amor.png?fit=809%2C398&ssl=1&resize=350%2C200 1x, https:\/\/i0.wp.com\/makingmusic4ever.com\/wp-content\/uploads\/2022\/04\/historiadeun-amor.png?fit=809%2C398&ssl=1&resize=525%2C300 1.5x, https:\/\/i0.wp.com\/makingmusic4ever.com\/wp-content\/uploads\/2022\/04\/historiadeun-amor.png?fit=809%2C398&ssl=1&resize=700%2C400 2x"},"classes":[]}],"jetpack_featured_media_url":"https:\/\/i0.wp.com\/makingmusic4ever.com\/wp-content\/uploads\/2026\/10\/Vinyl_record_with_binary_code_20261022123849.jpg?fit=1376%2C768&ssl=1","_links":{"self":[{"href":"https:\/\/makingmusic4ever.com\/index.php\/wp-json\/wp\/v2\/posts\/2107","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/makingmusic4ever.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/makingmusic4ever.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/makingmusic4ever.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/makingmusic4ever.com\/index.php\/wp-json\/wp\/v2\/comments?post=2107"}],"version-history":[{"count":3,"href":"https:\/\/makingmusic4ever.com\/index.php\/wp-json\/wp\/v2\/posts\/2107\/revisions"}],"predecessor-version":[{"id":2111,"href":"https:\/\/makingmusic4ever.com\/index.php\/wp-json\/wp\/v2\/posts\/2107\/revisions\/2111"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/makingmusic4ever.com\/index.php\/wp-json\/wp\/v2\/media\/2110"}],"wp:attachment":[{"href":"https:\/\/makingmusic4ever.com\/index.php\/wp-json\/wp\/v2\/media?parent=2107"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/makingmusic4ever.com\/index.php\/wp-json\/wp\/v2\/categories?post=2107"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/makingmusic4ever.com\/index.php\/wp-json\/wp\/v2\/tags?post=2107"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}