MusicGen Small
Meta's MusicGen Small text-to-music model, exported for loom.cpp. Family 14: a text description in, EnCodec tokens out -- pair it with encodec-32khz-loom for audio.
This is a loom.cpp export: a single self-describing GGUF that carries its own graph topologies, tokenizer (if any) and driver script, produced by loom-exporter.
Original model
Exported from facebook/musicgen-small. Weights are unmodified; this repo packages the same parameters into
loom.cpp's GGUF format.
License
cc-by-nc-4.0, inherited from the base model above.
Language(s)
en
Usage
Run it with loom-py -- loom-py-rt on PyPI:
pip install -U "loom-py-rt[hub]"
import loom
model = loom.Model.from_pretrained("loom-ai-org/musicgen-small-loom")
# The prompt DESCRIBES the music -- genre, instruments, mood. What comes back is EnCodec TOKENS, not
# audio: frame-major, 4 codebooks wide, 50 frames per second, so max_new_tokens=250 is five seconds.
codes = model.text2codes.infer("80s pop track with bassy drums and synth", max_new_tokens=250, seed=1)
print(len(codes), "frames x", len(codes[0]), "codebooks")
# The second half of the pair, in a repo of its own: the codec this model was trained with.
codec = loom.Model.from_pretrained("loom-ai-org/encodec-32khz-loom")
audio = codec.codes2speech.infer(codes)
print(len(audio), "samples at", audio.sample_rate, "Hz =", round(audio.duration, 2), "s")
audio.save("out.wav")
# Nothing goes between those two calls. Both files declare the width of a frame:
print(model.hparam("codec.n_codebooks"), "==", codec.hparam("codec.n_codebooks"))
# This model SAMPLES by default, with classifier-free guidance; `seed=` pins a take, and
# temperature=0 decodes greedily (transformers' generate(do_sample=False), code for code).
print(model.hparam("sampling.top_k"), model.hparam("sampling.guidance_scale", "f32"))
The layer underneath
The call above is the high-level door: one per task, named for the modality pair it maps between, with
the windowing, sampling and assembly this model needs already applied. Under it, model.infer(...)
passes your arguments straight to the driver this GGUF embeds -- which is where you go for a knob the
door does not name.
model.driver_source prints that driver, including a header comment documenting every argument it
accepts for this model, and is the authority on it. See loom-py for the API and
loom.cpp for what the engine does between the two.
Known limitations
This model does not produce audio. It emits four streams of EnCodec tokens, and encodec-32khz-loom -- the codec it was trained with -- turns them into 32 kHz mono audio. The usage snippet above is the whole of the joining.
The prompt describes the music; it is not lyrics. Genre, instruments, tempo and mood in English, through the T5 vocabulary this file carries. MusicGen Small makes no vocals.
It samples, at the settings transformers uses for this checkpoint: top_k 50 and classifier-free guidance at 3.0. (Meta's own audiocraft library samples with top_k 250; this file follows the checkpoint's Hugging Face generation config.) Two runs give two takes; seed= pins one, and temperature=0 decodes greedily, which reproduces transformers' generate(do_sample=False) code for code.
max_new_tokens counts audio frames at 50 per second, so 250 is five seconds. The default is 1496 frames, about 30 s, which is the checkpoint's own generation length and its training clip length. The decoder's 2048 positions cap one call at 2045 frames (40.9 s).
Guidance costs a second decoder pass at every step, so it roughly doubles the work. guidance_scale=1.0 turns it off: faster, and the music follows the prompt less closely. On a 4-thread laptop-class CPU, two seconds of music took about 27 s with guidance and 14 s without; a GPU or more cores helps.
Expect lo-fi sound; that comes from the model, not from this export. MusicGen generates music as a 2.2 kbps EnCodec stream: four 2048-entry codebooks at 50 frames a second. That is enough for style, rhythm and instrumentation, and it sounds about like an old radio. This file's codes match transformers exactly, and the codec matches it to 3e-5, so a sharper result would have to come from a larger MusicGen checkpoint, not a different runtime.
Mono and text-conditioned only. The melody-conditioned and stereo MusicGen checkpoints are different models and are not covered by this file. 2.1 GB, F32.
Files
musicgen-small.gguf-- the model, exported with loom-exporter.