m-a-p/MuPT-v0-8192-190M
<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:
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.
# 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=trueWe recommend using the latest version of NGC's PyTorch container for SMuPT inference. See more details in Megatron-LM
# 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/bashOnce 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.
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=250<n>M:3/4<n>K:A<n>EF |\"A\""], "tokens_to_generate":4096}'Processed Output:
X:1
L:1/8
Q:1/8=250
M:3/4
K:A
EF |"A" A3 AGF | E3 F A2 | Aa a2 gf |"E" ef ef ed |"A" c2 A2 A2 |"A" E3 FEF |"E" G2 Ea gf |
"E" e4 ef | ga g2 f2 | ec c2 e2 |"D" a2 gf ed |"A" c2 A2 A2 |"A" E4 EF |"A" A3 AGF |
"E" E3 F A2 =G2 |"D" FA de fa |"D" g2 f2 g2 |"A" a2 e2 e2 |"Bm" f2 d2 d2 |"E" ef ga b2- |
b2 g2 g2 | a4 a2 |"D" a2 ba gf |"A" e2 c2 c2 |"D" f4 f2 |"A" e4 a2 |"D" a2 ba gf |"E" e2 fe d=c |
"E" B2 e2 e2 |"E" E4 EF |"A" A3 AGF | E3 F A2 | Aa a2 A2 |"F#m" =G2 F2 EF |"A" A4 A2 |"E" E3 FEF |
"A" C3 D E2 |"E" B2 E2 E2 |"A" A4 ||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/Zv-IrolrVQAEIEYSX9iBz.mpga"></audio>
