Upload 3 files
Browse files- README.md +145 -0
- Yi_logo.svg +7 -0
- m-a-p.png +0 -0
README.md
ADDED
@@ -0,0 +1,145 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
license: apache-2.0
|
3 |
+
language:
|
4 |
+
- en
|
5 |
+
pipeline_tag: text-generation
|
6 |
+
tags:
|
7 |
+
- music
|
8 |
+
- art
|
9 |
+
---
|
10 |
+
|
11 |
+
<div align="center">
|
12 |
+
<img src="Yi_logo.svg" width="150px" style="display: inline-block;">
|
13 |
+
<img src="m-a-p.png" width="150px" style="display: inline-block;">
|
14 |
+
</div>
|
15 |
+
|
16 |
+
## SMuPT: Symbolic Music Generative Pre-trained Transformer
|
17 |
+
|
18 |
+
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.
|
19 |
+
|
20 |
+
- 09/01/2024: a series of pre-trained SMuPT models are released, with parameters ranging from 110M to 1.3B.
|
21 |
+
|
22 |
+
## Model architecture
|
23 |
+
|
24 |
+
The details of model architecture of SMuPT-v0 are listed below:
|
25 |
+
|
26 |
+
| Name | Parameters | Training Data(Music Pieces) | Seq Length | Hidden Size | Layers | Heads |
|
27 |
+
| :--- | :---: | :---: | :---: | :---: | :---: | :---: |
|
28 |
+
| SMuPT-v0-8192-110M | 110M | 7M x 5.8 epochs | 8192 | 768 | 12 | 12 |
|
29 |
+
| SMuPT-v0-8192-345M | 345M | 7M x 4 epochs | 8192 | 1024 | 24 | 16 |
|
30 |
+
| SMuPT-v0-8192-770M | 770M | 7M x 3 epochs | 8192 | 1280 | 36 | 20 |
|
31 |
+
| SMuPT-v0-8192-1.3B | 1.3B | 7M x 2.2 epochs | 8192 | 1536 | 48 | 24 |
|
32 |
+
|
33 |
+
## Model Usage
|
34 |
+
|
35 |
+
There are several ways to use our pre-trained SMuPT models, we now the usage based on [Megatron-LM](https://github.com/NVIDIA/Megatron-LM/tree/main). Huggingface format will be supported soon.
|
36 |
+
|
37 |
+
Before starting, make sure you have setup the relevant environment and codebase.
|
38 |
+
|
39 |
+
```shell
|
40 |
+
# pull Megatron-LM codebase
|
41 |
+
mkdir -p /path/to/workspace && cd /path/to/workspace
|
42 |
+
git clone https://github.com/NVIDIA/Megatron-LM.git
|
43 |
+
|
44 |
+
# download the pre-trained SMuPT models checkpoint and vocab files from Huggingface page
|
45 |
+
mkdir -p /models/SMuPT_v0_8192_1.3B && cd /models/SMuPT_v0_8192_1.3B
|
46 |
+
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
|
47 |
+
wget -O newline.vocab https://huggingface.co/m-a-p/SMuPT_v0_8192_1.3B/resolve/main/newline.vocab?download=true
|
48 |
+
wget -O newline.txt https://huggingface.co/m-a-p/SMuPT_v0_8192_1.3B/resolve/main/newline.txt?download=true
|
49 |
+
```
|
50 |
+
|
51 |
+
We recommend using the latest version of [NGC's PyTorch container](https://catalog.ngc.nvidia.com/orgs/nvidia/containers/pytorch) for SMuPT inference. See more details in [Megatron-LM](https://github.com/NVIDIA/Megatron-LM/tree/main)
|
52 |
+
|
53 |
+
```shell
|
54 |
+
# pull the latest NGC's PyTorch container, mount the workspace directory and enter the container
|
55 |
+
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
|
56 |
+
```
|
57 |
+
|
58 |
+
Once you enter the container, you can start a REST server for inference.
|
59 |
+
|
60 |
+
<details>
|
61 |
+
<summary>Click to expand the example script</summary>
|
62 |
+
|
63 |
+
#!/bin/bash
|
64 |
+
# This example will start serving the 1.3B model.
|
65 |
+
export CUDA_DEVICE_MAX_CONNECTIONS=1
|
66 |
+
|
67 |
+
DISTRIBUTED_ARGS="--nproc_per_node 1 \
|
68 |
+
--nnodes 1 \
|
69 |
+
--node_rank 0 \
|
70 |
+
--master_addr localhost \
|
71 |
+
--master_port 6000"
|
72 |
+
|
73 |
+
CHECKPOINT=/path/to/model/checkpoint/folder
|
74 |
+
VOCAB_FILE=/path/to/vocab/file
|
75 |
+
MERGE_FILE=/path/to/merge/file
|
76 |
+
|
77 |
+
MODEL_SIZE="1.3B"
|
78 |
+
if [[ ${MODEL_SIZE} == "110M" ]]; then HIDDEN_SIZE=768; NUM_HEAD=12; NUM_QUERY_GROUP=12; NUM_LAYERS=12; FFN_HIDDEN_SIZE=3072; NORM_EPS=1e-5;
|
79 |
+
elif [[ ${MODEL_SIZE} == "345M" ]]; then HIDDEN_SIZE=1024; NUM_HEAD=16; NUM_QUERY_GROUP=16; NUM_LAYERS=24; FFN_HIDDEN_SIZE=4096; NORM_EPS=1e-5;
|
80 |
+
elif [[ ${MODEL_SIZE} == "770M" ]]; then HIDDEN_SIZE=1280; NUM_HEAD=20; NUM_QUERY_GROUP=20; NUM_LAYERS=36; FFN_HIDDEN_SIZE=5120; NORM_EPS=1e-5;
|
81 |
+
elif [[ ${MODEL_SIZE} == "1.3B" ]]; then HIDDEN_SIZE=1536; NUM_HEAD=24; NUM_QUERY_GROUP=24; NUM_LAYERS=48; FFN_HIDDEN_SIZE=6144; NORM_EPS=1e-5;
|
82 |
+
else echo "invalid MODEL_SIZE: ${MODEL_SIZE}"; exit 1
|
83 |
+
fi
|
84 |
+
MAX_SEQ_LEN=8192
|
85 |
+
MAX_POSITION_EMBEDDINGS=8192
|
86 |
+
|
87 |
+
pip install flask-restful
|
88 |
+
|
89 |
+
torchrun $DISTRIBUTED_ARGS tools/run_text_generation_server.py \
|
90 |
+
--tensor-model-parallel-size 1 \
|
91 |
+
--pipeline-model-parallel-size 1 \
|
92 |
+
--num-layers ${NUM_LAYERS} \
|
93 |
+
--hidden-size ${HIDDEN_SIZE} \
|
94 |
+
--ffn-hidden-size ${FFN_HIDDEN_SIZE} \
|
95 |
+
--load ${CHECKPOINT} \
|
96 |
+
--group-query-attention \
|
97 |
+
--num-query-groups ${NUM_QUERY_GROUP} \
|
98 |
+
--position-embedding-type rope \
|
99 |
+
--num-attention-heads ${NUM_HEAD} \
|
100 |
+
--max-position-embeddings ${MAX_POSITION_EMBEDDINGS} \
|
101 |
+
--tokenizer-type GPT2BPETokenizer \
|
102 |
+
--normalization RMSNorm \
|
103 |
+
--norm-epsilon ${NORM_EPS} \
|
104 |
+
--make-vocab-size-divisible-by 1 \
|
105 |
+
--swiglu \
|
106 |
+
--use-flash-attn \
|
107 |
+
--bf16 \
|
108 |
+
--micro-batch-size 1 \
|
109 |
+
--disable-bias-linear \
|
110 |
+
--no-bias-gelu-fusion \
|
111 |
+
--untie-embeddings-and-output-weights \
|
112 |
+
--seq-length ${MAX_SEQ_LEN} \
|
113 |
+
--vocab-file $VOCAB_FILE \
|
114 |
+
--merge-file $MERGE_FILE \
|
115 |
+
--attention-dropout 0.0 \
|
116 |
+
--hidden-dropout 0.0 \
|
117 |
+
--weight-decay 1e-1 \
|
118 |
+
--clip-grad 1.0 \
|
119 |
+
--adam-beta1 0.9 \
|
120 |
+
--adam-beta2 0.95 \
|
121 |
+
--adam-eps 1e-8 \
|
122 |
+
--seed 42
|
123 |
+
|
124 |
+
</details>
|
125 |
+
|
126 |
+
|
127 |
+
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.
|
128 |
+
|
129 |
+
```shell
|
130 |
+
curl 'http://localhost:6000/api' -X 'PUT' -H 'Content-Type: application/json; charset=UTF-8' -d '{"prompts":["X:1<n>L:1/8<n>M:4/4<n>K:G<n>GA"], "tokens_to_generate":4096}'
|
131 |
+
```
|
132 |
+
Processed Output:
|
133 |
+
```shell
|
134 |
+
X:1
|
135 |
+
L:1/8
|
136 |
+
M:4/4
|
137 |
+
K:G
|
138 |
+
GA | B2 B2 B2 (cd) | B2 A2 z2 AB | c2 c2 c2 (de) | d4 z2 B2 | d2 d2 d2 e>d | c2 B2 z2 dB |
|
139 |
+
A2 A2 A2 B2 | G4 z2 GA | B2 B2 B2 cd | B2 A2 z2 AB | c2 c2 e2 dc | d4 z2 GA | B2 B2 B2 cd |
|
140 |
+
B2 A2 z2 dB | A3 G A2 B2 | G4 z2 |]
|
141 |
+
```
|
142 |
+
|
143 |
+
Once you encode the generated tokens into audio, you will hear the following music.
|
144 |
+
|
145 |
+
<audio controls src="https://cdn-uploads.huggingface.co/production/uploads/640701cb4dc5f2846c91d4eb/Ows-HvaSuZfqAZvOjT4LX.mpga"></audio>
|
Yi_logo.svg
ADDED
m-a-p.png
ADDED