Views
No views yet

| Name | Parameters | Training Data(Music Pieces) | Seq Length | Hidden Size | Layers | Heads |
|---|---|---|---|---|---|---|
| MuPT-v1-8192-110M | 110M | 7M x 8 epochs | 8192 | 768 | 12 | 12 |
| MuPT-v1-8192-345M | 345M | 7M x 6 epochs | 8192 | 1024 | 24 | 16 |
| MuPT-v1-8192-770M | 770M | 7M x 5 epochs | 8192 | 1280 | 36 | 20 |
| MuPT-v1-8192-1.3B | 1.3B | 7M x 8 epochs | 8192 | 1536 | 48 | 24 |
1from transformers import AutoModelForCausalLM, AutoModel, AutoTokenizer
2
3tokenizer = AutoTokenizer.from_pretrained("m-a-p/MuPT_v1_8192_345M",
4 trust_remote_code=True,
5 use_fast=False)
6model = AutoModelForCausalLM.from_pretrained("m-a-p/MuPT_v1_8192_345M").eval().half().cuda()
7
8prefix = "X:1<n>L:1/8<n>Q:1/8=200<n>M:4/4<n>K:Gmin<n>|:\"Gm\" BGdB" # replace "\n" with "<n>" for all the MuPT-8192 models, but not for MuPT-4096 models
9inputs = tokenizer(prefix, return_tensors="pt").to(model.device)
10
11max_length = 256
12outputs = model.generate(
13 inputs.input_ids,
14 max_length=max_length
15)
16outputs = tokenizer.decode(outputs[0])
17print(outputs)1import re
2
3SEPARATORS = ['|', '|]', '||', '[|', '|:', ':|', '::']
4SEP_DICT = {}
5for i, sep in enumerate(SEPARATORS, start=1):
6 # E.g. ' | ': ' <1>'
7 SEP_DICT[' '+sep+' '] = f' <{i}>'
8NEWSEP = '<|>'
9
10def sep2tok(row):
11 for sep, tok in SEP_DICT.items():
12 row = row.replace(sep, tok+'<=> ')
13 return row
14
15def tok2sep(bar):
16 for sep, tok in SEP_DICT.items():
17 bar = bar.replace(tok, sep)
18 return bar
19
20
21def spacing(row):
22
23 for sep in SEPARATORS:
24
25 def subfunc(match):
26 symbol = [':', '|', ']']
27 if match.group(1) is None:
28 return f' {sep}'
29 elif match.group(1) in symbol:
30 return f' {sep}{match.group(1)}'
31 else:
32 return ' '+sep+' '+match.group(1)
33
34 pattern = r' ' + re.escape(sep) + r'(.{1})'
35 row = re.sub(pattern, subfunc, row)
36 row = row.replace('\n'+sep+'"', '\n '+sep+' "') # B \n|"A -> B \n | "A
37 row = row.replace(' '+sep+'\n', ' '+sep+' \n') # B |\n -> B | \n
38 return row
39
40 def decode(piece):
41 dec_piece = ''
42 idx = piece.find(' '+NEWSEP+' ')
43 heads = piece[:idx]
44 scores = piece[idx:]
45 scores_lst = re.split(' <\|>', scores)
46
47 all_bar_lst = []
48 for bar in scores_lst:
49 if bar == '':
50 continue
51 bar = sep2tok(bar)
52 bar_lst = re.split('<=>', bar)
53 bar_lst = list(map(tok2sep, bar_lst))
54 if len(all_bar_lst) == 0:
55 all_bar_lst = [[] for _ in range(len(bar_lst))]
56 for i in range(len(bar_lst)):
57 all_bar_lst[i].append(bar_lst[i])
58
59 if len(all_bar_lst) > 1:
60 # There might be the bar number like %30 at the end
61 # which need to be specially handled.
62 if len(all_bar_lst[0]) > len(all_bar_lst[1]):
63 last_bar_lst = all_bar_lst[0][-1].split()
64 all_bar_lst[0].pop()
65 for i in range(len(all_bar_lst)):
66 all_bar_lst[i].append(last_bar_lst[i])
67 # Add the remaining symbols to the last row.
68 if i == len(all_bar_lst) - 1:
69 for j in range(i+1, len(last_bar_lst)):
70 all_bar_lst[i][-1] += ' ' + last_bar_lst[j]
71 # Ensure the lengths are consistent.
72 length = len(all_bar_lst[0])
73 for lst in all_bar_lst[1:]:
74 # assert len(lst) == length
75 pass
76
77 dec_piece += heads
78 for i in range(len(all_bar_lst)):
79 if len(all_bar_lst) > 1:
80 dec_piece += f'V:{i+1}\n'
81 dec_piece += ''.join(all_bar_lst[i])
82 dec_piece += '\n'
83 # Remove redundant spaces.
84 dec_piece = re.sub(' {2,}', ' ', dec_piece)
85
86 return dec_piece1X:1
2L:1/8
3Q:1/8=200
4M:4/4<n>K:Gmin
5|:\"Gm\" BGdB fdBG |\"F\" AFcF dFcF |\"Gm\" BGdG gFBF |\"F\" AFAG AF F2 |\"Gm\" BGBd fffd |\"F\" cdcB cdeg |
6\"Gm\" fdcB\"Eb\" AFcA |1 BGFG\"F\" AFGc :|2 BGFG\"F\" AF F2 ||1# pull Megatron-LM codebase
2mkdir -p /path/to/workspace && cd /path/to/workspace
3git clone https://github.com/NVIDIA/Megatron-LM.git
4# download the pre-trained MuPT models checkpoint and vocab files from Huggingface page
5mkdir -p /models/MuPT_v0_8192_1.3B && cd /models/MuPT_v0_8192_1.3B
6wget -O model_optim_rng.pt https://huggingface.co/m-a-p/MuPT_v0_8192_1.3B/resolve/main/model_optim_rng.pt?download=true
7wget -O newline.vocab https://huggingface.co/m-a-p/MuPT_v0_8192_1.3B/resolve/main/newline.vocab?download=true
8wget -O newline.txt https://huggingface.co/m-a-p/MuPT_v0_8192_1.3B/resolve/main/newline.txt?download=true1# pull the latest NGC's PyTorch container, mount the workspace directory and enter the container
2docker run --gpus all -it --name megatron --shm-size=16g -v $PWD:/workspace -p 5000:5000 nvcr.io/nvidia/pytorch:23.11-py3 /bin/bash#!/bin/bash
# This example will start serving the 1.3B model.
export CUDA_DEVICE_MAX_CONNECTIONS=1
DISTRIBUTED_ARGS="--nproc_per_node 1 \
--nnodes 1 \
--node_rank 0 \
--master_addr localhost \
--master_port 6000"
CHECKPOINT=/path/to/model/checkpoint/folder
VOCAB_FILE=/path/to/vocab/file
MERGE_FILE=/path/to/merge/file
MODEL_SIZE="1.3B"
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;
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;
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;
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;
else echo "invalid MODEL_SIZE: ${MODEL_SIZE}"; exit 1
fi
MAX_SEQ_LEN=8192
MAX_POSITION_EMBEDDINGS=8192
pip install flask-restful
torchrun $DISTRIBUTED_ARGS tools/run_text_generation_server.py \
--tensor-model-parallel-size 1 \
--pipeline-model-parallel-size 1 \
--num-layers ${NUM_LAYERS} \
--hidden-size ${HIDDEN_SIZE} \
--ffn-hidden-size ${FFN_HIDDEN_SIZE} \
--load ${CHECKPOINT} \
--group-query-attention \
--num-query-groups ${NUM_QUERY_GROUP} \
--position-embedding-type rope \
--num-attention-heads ${NUM_HEAD} \
--max-position-embeddings ${MAX_POSITION_EMBEDDINGS} \
--tokenizer-type GPT2BPETokenizer \
--normalization RMSNorm \
--norm-epsilon ${NORM_EPS} \
--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 ${MAX_SEQ_LEN} \
--vocab-file $VOCAB_FILE \
--merge-file $MERGE_FILE \
--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\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=200<n>M:4/4<n>K:Gmin<n>|:\"Gm\" BGdB"], "tokens_to_generate":4096}'1X:1
2L:1/8
3Q:1/8=200
4M:4/4<n>K:Gmin
5|:\"Gm\" BGdB fdBG |\"F\" AFcF dFcF |\"Gm\" BGdG gFBF |\"F\" AFAG AF F2 |\"Gm\" BGBd fffd |\"F\" cdcB cdeg |
6\"Gm\" fdcB\"Eb\" AFcA |1 BGFG\"F\" AFGc :|2 BGFG\"F\" AF F2 ||