CoolFace
Modelpublic

m-a-p/MuPT-v0-4096-1.97B

sourceHugging Faceapache-2.0updated 3y agoView on Hugging Face
1likes178downloads
Model Card

<div align="center"> <img src="Yi_logo.svg" width="150px" style="display: inline-block;"> <img src="m-a-p.png" width="150px" style="display: inline-block;"> </div>

SMuPT: Symbolic Music Generative Pre-trained Transformer

SMuPT is a series of pre-trained models for symbolic music generation. It was trained on a large-scale dataset of symbolic music, including millions of monophonic and polyphonic pieces from different genres and styles. The models are trained with the LLama2 architecture, and can be further used for downstream music generation tasks such as melody generation, accompaniment generation, and multi-track music generation.

  • 09/01/2024: a series of pre-trained SMuPT models are released, with parameters ranging from 110M to 1.3B.

Model architecture

The details of model architecture of SMuPT-v0 are listed below:

NameParametersTraining Data(Music Pieces)Seq LengthHidden SizeLayersHeads
SMuPT-v0-8192-110M110M7M x 5.8 epochs81927681212
SMuPT-v0-8192-345M345M7M x 4 epochs819210242416
SMuPT-v0-8192-770M770M7M x 3 epochs819212803620
SMuPT-v0-8192-1.3B1.3B7M x 2.2 epochs819215364824

Model Usage

There are several ways to use our pre-trained SMuPT models, we now the usage based on Megatron-LM. Huggingface format will be supported soon.

Before starting, make sure you have setup the relevant environment and codebase.

shell
# pull Megatron-LM codebase
mkdir -p /path/to/workspace && cd /path/to/workspace
git clone https://github.com/NVIDIA/Megatron-LM.git

# download the pre-trained SMuPT models checkpoint and vocab files from Huggingface page
mkdir -p /models/SMuPT_v0_8192_1.3B && cd /models/SMuPT_v0_8192_1.3B
wget -O model_optim_rng.pt https://huggingface.co/m-a-p/SMuPT_v0_8192_1.3B/resolve/main/model_optim_rng.pt?download=true
wget -O newline.vocab https://huggingface.co/m-a-p/SMuPT_v0_8192_1.3B/resolve/main/newline.vocab?download=true
wget -O newline.txt https://huggingface.co/m-a-p/SMuPT_v0_8192_1.3B/resolve/main/newline.txt?download=true

We recommend using the latest version of NGC's PyTorch container for SMuPT inference. See more details in Megatron-LM

shell
# pull the latest NGC's PyTorch container, mount the workspace directory and enter the container
docker run --gpus all -it --name megatron --shm-size=16g -v $PWD:/workspace -p 5000:5000 nvcr.io/nvidia/pytorch:23.11-py3 /bin/bash

Once you enter the container, you can start a REST server for inference.

<details> <summary>Click to expand the example script</summary>

#!/bin/bash # This example will start serving the 1.3B model. export CUDADEVICEMAX_CONNECTIONS=1

DISTRIBUTEDARGS="--nprocpernode 1 \ --nnodes 1 \ --noderank 0 \ --masteraddr localhost \ --masterport 6000"

CHECKPOINT=/path/to/model/checkpoint/folder VOCABFILE=/path/to/vocab/file MERGEFILE=/path/to/merge/file

MODELSIZE="1.3B" if [[ ${MODELSIZE} == "110M" ]]; then HIDDENSIZE=768; NUMHEAD=12; NUMQUERYGROUP=12; NUMLAYERS=12; FFNHIDDENSIZE=3072; NORMEPS=1e-5; elif [[ ${MODELSIZE} == "345M" ]]; then HIDDENSIZE=1024; NUMHEAD=16; NUMQUERYGROUP=16; NUMLAYERS=24; FFNHIDDENSIZE=4096; NORMEPS=1e-5; elif [[ ${MODELSIZE} == "770M" ]]; then HIDDENSIZE=1280; NUMHEAD=20; NUMQUERYGROUP=20; NUMLAYERS=36; FFNHIDDENSIZE=5120; NORMEPS=1e-5; elif [[ ${MODELSIZE} == "1.3B" ]]; then HIDDENSIZE=1536; NUMHEAD=24; NUMQUERYGROUP=24; NUMLAYERS=48; FFNHIDDENSIZE=6144; NORMEPS=1e-5; else echo "invalid MODELSIZE: ${MODELSIZE}"; exit 1 fi MAXSEQLEN=8192 MAXPOSITION_EMBEDDINGS=8192

pip install flask-restful

torchrun $DISTRIBUTEDARGS tools/runtextgenerationserver.py \ --tensor-model-parallel-size 1 \ --pipeline-model-parallel-size 1 \ --num-layers ${NUMLAYERS} \ --hidden-size ${HIDDENSIZE} \ --ffn-hidden-size ${FFNHIDDENSIZE} \ --load ${CHECKPOINT} \ --group-query-attention \ --num-query-groups ${NUMQUERYGROUP} \ --position-embedding-type rope \ --num-attention-heads ${NUMHEAD} \ --max-position-embeddings ${MAXPOSITIONEMBEDDINGS} \ --tokenizer-type GPT2BPETokenizer \ --normalization RMSNorm \ --norm-epsilon ${NORMEPS} \ --make-vocab-size-divisible-by 1 \ --swiglu \ --use-flash-attn \ --bf16 \ --micro-batch-size 1 \ --disable-bias-linear \ --no-bias-gelu-fusion \ --untie-embeddings-and-output-weights \ --seq-length ${MAXSEQLEN} \ --vocab-file $VOCABFILE \ --merge-file $MERGEFILE \ --attention-dropout 0.0 \ --hidden-dropout 0.0 \ --weight-decay 1e-1 \ --clip-grad 1.0 \ --adam-beta1 0.9 \ --adam-beta2 0.95 \ --adam-eps 1e-8 \ --seed 42

</details>

Use CURL to query the server directly, note that the newline token \n is represented by <n> in the vocabulary, so we need to replace the newline token with <n> in both the prompt and the generated tokens.

shell
curl 'http://localhost:6000/api' -X 'PUT' -H 'Content-Type: application/json; charset=UTF-8'  -d '{"prompts":["X:1<n>L:1/8<n>Q:1/8=200<n>M:4/4<n>K:Gmin<n>|:\"Gm\" BGdB"], "tokens_to_generate":4096}'

Processed Output:

shell
X:1
L:1/8
Q:1/8=200
M:4/4<n>K:Gmin
|:\"Gm\" BGdB fdBG |\"F\" AFcF dFcF |\"Gm\" BGdG gFBF |\"F\" AFAG AF F2 |\"Gm\" BGBd fffd |\"F\" cdcB cdeg |
\"Gm\" fdcB\"Eb\" AFcA |1 BGFG\"F\" AFGc :|2 BGFG\"F\" AF F2 ||

Once you encode the generated tokens into audio, you will hear the following music.

<audio controls src="https://cdn-uploads.huggingface.co/production/uploads/640701cb4dc5f2846c91d4eb/gnBULaFjcUyXYzzIwXLZq.mpga"></audio>