Nodes/ComfyUI-MusicGen-HF/MusicGen (Hugging Face)
ComfyUI Node

MusicGen (Hugging Face)

Real music from a text box — locally, no API key

By ebrinz·Created about a year ago·Updated 10 months ago· 11
MusicGen (Hugging Face)
  • conditioning_audio
  • audio
  • info
model_sizesmall
duration10.0000
guidance_scale3.0
do_sampletrue
max_new_tokens256
seed42
promptupbeat electronic music with drums and synth
temperature1.0
duration_override0.0

This is the node you came for. HuggingFaceMusicGen runs Facebook/Meta's MusicGen - the actual transformer model from the 2023 paper - entirely inside ComfyUI via Hugging Face Transformers. Despite the name, it calls no API and needs no key. It downloads real model weights to your disk and generates music on your GPU (or your Mac's MPS, or your CPU if you're patient). Text-to-music in ComfyUI is surprisingly underserved and hard to find tutorials for, so this pack quietly fills a real gap.

The workflow is dead simple: type a prompt, pick a model size, hit Queue. Wire its audio output into the pack's SaveAudioStandalone node and you're done.

How it works

Under the hood it's AutoProcessor + MusicgenForConditionalGeneration from transformers, loading facebook/musicgen-small, -medium, or -large. MusicGen generates at 32kHz and produces roughly 50 tokens per second, with a hard model cap of 1503 tokens - that's why duration tops out at 30 seconds. The clever bit: the node ignores the literal max_new_tokens you set and computes tokens from duration itself (min(duration * 50, 1503)), so a 10s generation uses ~500 tokens. Set max_new_tokens if you want a ceiling; don't fight it.

The node auto-detects device on load: CUDA, then MPS, then CPU. Two quirks worth knowing because they're baked into the code. On Apple Silicon it forces float32 - MusicGen gets numerically unstable in float16 on MPS, and bfloat16 isn't supported at all (there's literally a test_bfloat16_issue.json in the repo). And if the known MPS torch.multinomial sampling bug trips during generation, it reloads the model on CPU and stays there. Slow, but it produces audio instead of an error.

The inputs that matter

  • prompt - the only thing most people touch. "80s pop track with bassy drums and synth" works; a blank prompt quietly falls back to the default.
  • duration - 1–30s. Keep it short first run; generation isn't instant.
  • model_size - small (~1.5GB), medium (~3.3GB), large (~3.3GB). Start small, go up when it sounds thin.
  • guidance_scale - default 3.0. Higher follows the prompt harder; too high gets weird.
  • seed - reproducible generations. Same prompt + seed + settings = same track.
  • do_sample / temperature - sampling on (default) gives variety; turn sampling off for cleaner, less creative output.
  • conditioning_audio - optional AUDIO in. Feed it an existing clip and the model continues it, resampled to MusicGen's 32kHz. This is the continuation feature.
  • duration_override - 0 by default. Plug the duration output of the pack's BPMDurationInput here to generate in whole musical bars instead of guessed seconds.

Outputs: audio (a ComfyUI AUDIO dict - waveform plus sample rate) and an info string with duration, device, and settings. On a generation error it returns silence and the error message in info, so an empty audio widget means read the info string.

Install

ComfyUI Manager → search "ComfyUI-MusicGen-HF" → install, or:

cd ComfyUI/custom_nodes
git clone https://github.com/ebrinz/ComfyUI-MusicGen-HF
cd ComfyUI-MusicGen-HF
pip install -r requirements.txt

Then restart ComfyUI. Note the README's clone snippet says "your-username" - copy-paste README; use the ebrinz URL above. Dependencies: torch, torchaudio, transformers, accelerate, scipy, and av (PyAV). The model downloads on first generation to ComfyUI/models/musicgen/huggingface_cache/, so the first run needs internet and a few GB of disk.

Troubleshooting

First run downloads the weights - be patient, watch the console for progress. Out of memory? Drop to small, shorten duration. Nothing but silence? Read the info output; the node reports its own errors there. If you're on MPS and generation crawls, that's the CPU fallback doing its job. Model caches accumulate across size switches, so don't be surprised when the cache folder grows past your expectations.

Like all custom nodes, it's not sandboxed - only install packs you trust, and this one's worth reading before you clone.

Categoryaudio/musicgen

Inputs (10)

NameTypeDefaultDescription
model_sizeCOMBOsmall3 options: small, medium, large
durationFLOAT10.00001–30
guidance_scaleFLOAT3.01–10
do_sampleBOOLEANtrue
max_new_tokensINT25650–1503
seedINT420–999999999
promptoptSTRINGupbeat electronic music with drums and synth
conditioning_audiooptAUDIO
temperatureoptFLOAT1.00.1–2
duration_overrideoptFLOAT0.00–30Override duration parameter with value from BPMDurationInput node

Outputs (2)

NameTypeDescription
audioAUDIO
infoSTRING