Duplicate from awkyu/audiogen-medium
Browse filesCo-authored-by: Alexander Kyu <awkyu@users.noreply.huggingface.co>
- .gitattributes +35 -0
- README.md +49 -0
- compression_state_dict.bin +3 -0
- config.json +298 -0
- handler.py +38 -0
- requirements.txt +2 -0
- state_dict.bin +3 -0
.gitattributes
ADDED
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
*.7z filter=lfs diff=lfs merge=lfs -text
|
2 |
+
*.arrow filter=lfs diff=lfs merge=lfs -text
|
3 |
+
*.bin filter=lfs diff=lfs merge=lfs -text
|
4 |
+
*.bz2 filter=lfs diff=lfs merge=lfs -text
|
5 |
+
*.ckpt filter=lfs diff=lfs merge=lfs -text
|
6 |
+
*.ftz filter=lfs diff=lfs merge=lfs -text
|
7 |
+
*.gz filter=lfs diff=lfs merge=lfs -text
|
8 |
+
*.h5 filter=lfs diff=lfs merge=lfs -text
|
9 |
+
*.joblib filter=lfs diff=lfs merge=lfs -text
|
10 |
+
*.lfs.* filter=lfs diff=lfs merge=lfs -text
|
11 |
+
*.mlmodel filter=lfs diff=lfs merge=lfs -text
|
12 |
+
*.model filter=lfs diff=lfs merge=lfs -text
|
13 |
+
*.msgpack filter=lfs diff=lfs merge=lfs -text
|
14 |
+
*.npy filter=lfs diff=lfs merge=lfs -text
|
15 |
+
*.npz filter=lfs diff=lfs merge=lfs -text
|
16 |
+
*.onnx filter=lfs diff=lfs merge=lfs -text
|
17 |
+
*.ot filter=lfs diff=lfs merge=lfs -text
|
18 |
+
*.parquet filter=lfs diff=lfs merge=lfs -text
|
19 |
+
*.pb filter=lfs diff=lfs merge=lfs -text
|
20 |
+
*.pickle filter=lfs diff=lfs merge=lfs -text
|
21 |
+
*.pkl filter=lfs diff=lfs merge=lfs -text
|
22 |
+
*.pt filter=lfs diff=lfs merge=lfs -text
|
23 |
+
*.pth filter=lfs diff=lfs merge=lfs -text
|
24 |
+
*.rar filter=lfs diff=lfs merge=lfs -text
|
25 |
+
*.safetensors filter=lfs diff=lfs merge=lfs -text
|
26 |
+
saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
27 |
+
*.tar.* filter=lfs diff=lfs merge=lfs -text
|
28 |
+
*.tar filter=lfs diff=lfs merge=lfs -text
|
29 |
+
*.tflite filter=lfs diff=lfs merge=lfs -text
|
30 |
+
*.tgz filter=lfs diff=lfs merge=lfs -text
|
31 |
+
*.wasm filter=lfs diff=lfs merge=lfs -text
|
32 |
+
*.xz filter=lfs diff=lfs merge=lfs -text
|
33 |
+
*.zip filter=lfs diff=lfs merge=lfs -text
|
34 |
+
*.zst filter=lfs diff=lfs merge=lfs -text
|
35 |
+
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
README.md
ADDED
@@ -0,0 +1,49 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
license: cc-by-nc-4.0
|
3 |
+
---
|
4 |
+
|
5 |
+
# AudioGen - Medium - 1.5B
|
6 |
+
|
7 |
+
AudioGen is an autoregressive transformer LM that synthesizes general audio conditioned on text (Text-to-Audio).
|
8 |
+
Internally, AudioGen operates over discrete representations learnt from the raw waveform, using an EnCodec tokenizer.
|
9 |
+
|
10 |
+
AudioGen was presented at [AudioGen: Textually Guided Audio Generation](https://arxiv.org/abs/2209.15352) by *Felix Kreuk, Gabriel Synnaeve, Adam Polyak, Uriel Singer, Alexandre Défossez, Jade Copet, Devi Parikh, Yaniv Taigman, Yossi Adi*.
|
11 |
+
|
12 |
+
AudioGen 1.5B is a variant of the original AudioGen model that follows [MusicGen](https://arxiv.org/abs/2306.05284) architecture.
|
13 |
+
More specifically, it is trained over a 16kHz EnCodec tokenizer with 4 codebooks sampled at 50 Hz with a delay pattern between the codebooks.
|
14 |
+
Having only 50 auto-regressive steps per second of audio, this AudioGen model allows faster generation while reaching similar performances to the original AudioGen model introduced in the paper.
|
15 |
+
|
16 |
+
## Audiocraft Usage
|
17 |
+
|
18 |
+
You can run AudioGen locally through the original [Audiocraft library]((https://github.com/facebookresearch/audiocraft):
|
19 |
+
|
20 |
+
1. First install the [`audiocraft` library](https://github.com/facebookresearch/audiocraft)
|
21 |
+
```
|
22 |
+
pip install git+https://github.com/facebookresearch/audiocraft.git
|
23 |
+
```
|
24 |
+
|
25 |
+
2. Make sure to have [`ffmpeg`](https://ffmpeg.org/download.html) installed:
|
26 |
+
```
|
27 |
+
apt get install ffmpeg
|
28 |
+
```
|
29 |
+
|
30 |
+
3. Run the following Python code:
|
31 |
+
|
32 |
+
```py
|
33 |
+
import torchaudio
|
34 |
+
from audiocraft.models import AudioGen
|
35 |
+
from audiocraft.data.audio import audio_write
|
36 |
+
|
37 |
+
model = AudioGen.get_pretrained('facebook/audiogen-medium')
|
38 |
+
model.set_generation_params(duration=5) # generate 5 seconds.
|
39 |
+
descriptions = ['dog barking', 'sirenes of an emergency vehicule', 'footsteps in a corridor']
|
40 |
+
wav = model.generate(descriptions) # generates 3 samples.
|
41 |
+
|
42 |
+
for idx, one_wav in enumerate(wav):
|
43 |
+
# Will save under {idx}.wav, with loudness normalization at -14 db LUFS.
|
44 |
+
audio_write(f'{idx}', one_wav.cpu(), model.sample_rate, strategy="loudness", loudness_compressor=True)
|
45 |
+
```
|
46 |
+
|
47 |
+
## Model details
|
48 |
+
|
49 |
+
See [AudioGen's model card](https://github.com/facebookresearch/audiocraft/blob/main/model_cards/AUDIOGEN_MODEL_CARD.md).
|
compression_state_dict.bin
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:5a520e64ca99226a9956f83b06df0617b713183fcdc384779883a6bb46dc1095
|
3 |
+
size 235740815
|
config.json
ADDED
@@ -0,0 +1,298 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"_commit_hash": null,
|
3 |
+
"architectures": [
|
4 |
+
"MusicgenForConditionalGeneration"
|
5 |
+
],
|
6 |
+
"audio_encoder": {
|
7 |
+
"_name_or_path": "facebook/encodec_32khz",
|
8 |
+
"add_cross_attention": false,
|
9 |
+
"architectures": [
|
10 |
+
"EncodecModel"
|
11 |
+
],
|
12 |
+
"audio_channels": 1,
|
13 |
+
"bad_words_ids": null,
|
14 |
+
"begin_suppress_tokens": null,
|
15 |
+
"bos_token_id": null,
|
16 |
+
"chunk_length_s": null,
|
17 |
+
"chunk_size_feed_forward": 0,
|
18 |
+
"codebook_dim": 128,
|
19 |
+
"codebook_size": 2048,
|
20 |
+
"compress": 2,
|
21 |
+
"cross_attention_hidden_size": null,
|
22 |
+
"decoder_start_token_id": null,
|
23 |
+
"dilation_growth_rate": 2,
|
24 |
+
"diversity_penalty": 0.0,
|
25 |
+
"do_sample": false,
|
26 |
+
"early_stopping": false,
|
27 |
+
"encoder_no_repeat_ngram_size": 0,
|
28 |
+
"eos_token_id": null,
|
29 |
+
"exponential_decay_length_penalty": null,
|
30 |
+
"finetuning_task": null,
|
31 |
+
"forced_bos_token_id": null,
|
32 |
+
"forced_eos_token_id": null,
|
33 |
+
"hidden_size": 128,
|
34 |
+
"id2label": {
|
35 |
+
"0": "LABEL_0",
|
36 |
+
"1": "LABEL_1"
|
37 |
+
},
|
38 |
+
"is_decoder": false,
|
39 |
+
"is_encoder_decoder": false,
|
40 |
+
"kernel_size": 7,
|
41 |
+
"label2id": {
|
42 |
+
"LABEL_0": 0,
|
43 |
+
"LABEL_1": 1
|
44 |
+
},
|
45 |
+
"last_kernel_size": 7,
|
46 |
+
"length_penalty": 1.0,
|
47 |
+
"max_length": 20,
|
48 |
+
"min_length": 0,
|
49 |
+
"model_type": "encodec",
|
50 |
+
"no_repeat_ngram_size": 0,
|
51 |
+
"norm_type": "weight_norm",
|
52 |
+
"normalize": false,
|
53 |
+
"num_beam_groups": 1,
|
54 |
+
"num_beams": 1,
|
55 |
+
"num_filters": 64,
|
56 |
+
"num_lstm_layers": 2,
|
57 |
+
"num_residual_layers": 1,
|
58 |
+
"num_return_sequences": 1,
|
59 |
+
"output_attentions": false,
|
60 |
+
"output_hidden_states": false,
|
61 |
+
"output_scores": false,
|
62 |
+
"overlap": null,
|
63 |
+
"pad_mode": "reflect",
|
64 |
+
"pad_token_id": null,
|
65 |
+
"prefix": null,
|
66 |
+
"problem_type": null,
|
67 |
+
"pruned_heads": {},
|
68 |
+
"remove_invalid_values": false,
|
69 |
+
"repetition_penalty": 1.0,
|
70 |
+
"residual_kernel_size": 3,
|
71 |
+
"return_dict": true,
|
72 |
+
"return_dict_in_generate": false,
|
73 |
+
"sampling_rate": 32000,
|
74 |
+
"sep_token_id": null,
|
75 |
+
"suppress_tokens": null,
|
76 |
+
"target_bandwidths": [
|
77 |
+
2.2
|
78 |
+
],
|
79 |
+
"task_specific_params": null,
|
80 |
+
"temperature": 1.0,
|
81 |
+
"tf_legacy_loss": false,
|
82 |
+
"tie_encoder_decoder": false,
|
83 |
+
"tie_word_embeddings": true,
|
84 |
+
"tokenizer_class": null,
|
85 |
+
"top_k": 50,
|
86 |
+
"top_p": 1.0,
|
87 |
+
"torch_dtype": "float32",
|
88 |
+
"torchscript": false,
|
89 |
+
"transformers_version": "4.31.0.dev0",
|
90 |
+
"trim_right_ratio": 1.0,
|
91 |
+
"typical_p": 1.0,
|
92 |
+
"upsampling_ratios": [
|
93 |
+
8,
|
94 |
+
5,
|
95 |
+
4,
|
96 |
+
4
|
97 |
+
],
|
98 |
+
"use_bfloat16": false,
|
99 |
+
"use_causal_conv": false,
|
100 |
+
"use_conv_shortcut": false
|
101 |
+
},
|
102 |
+
"decoder": {
|
103 |
+
"_name_or_path": "",
|
104 |
+
"activation_dropout": 0.0,
|
105 |
+
"activation_function": "gelu",
|
106 |
+
"add_cross_attention": false,
|
107 |
+
"architectures": null,
|
108 |
+
"attention_dropout": 0.0,
|
109 |
+
"bad_words_ids": null,
|
110 |
+
"begin_suppress_tokens": null,
|
111 |
+
"bos_token_id": 2048,
|
112 |
+
"chunk_size_feed_forward": 0,
|
113 |
+
"classifier_dropout": 0.0,
|
114 |
+
"cross_attention_hidden_size": null,
|
115 |
+
"decoder_start_token_id": null,
|
116 |
+
"diversity_penalty": 0.0,
|
117 |
+
"do_sample": false,
|
118 |
+
"dropout": 0.1,
|
119 |
+
"early_stopping": false,
|
120 |
+
"encoder_no_repeat_ngram_size": 0,
|
121 |
+
"eos_token_id": null,
|
122 |
+
"exponential_decay_length_penalty": null,
|
123 |
+
"ffn_dim": 4096,
|
124 |
+
"finetuning_task": null,
|
125 |
+
"forced_bos_token_id": null,
|
126 |
+
"forced_eos_token_id": null,
|
127 |
+
"hidden_size": 1024,
|
128 |
+
"id2label": {
|
129 |
+
"0": "LABEL_0",
|
130 |
+
"1": "LABEL_1"
|
131 |
+
},
|
132 |
+
"initializer_factor": 0.02,
|
133 |
+
"is_decoder": false,
|
134 |
+
"is_encoder_decoder": false,
|
135 |
+
"label2id": {
|
136 |
+
"LABEL_0": 0,
|
137 |
+
"LABEL_1": 1
|
138 |
+
},
|
139 |
+
"layerdrop": 0.0,
|
140 |
+
"length_penalty": 1.0,
|
141 |
+
"max_length": 20,
|
142 |
+
"max_position_embeddings": 2048,
|
143 |
+
"min_length": 0,
|
144 |
+
"model_type": "musicgen_decoder",
|
145 |
+
"no_repeat_ngram_size": 0,
|
146 |
+
"num_attention_heads": 16,
|
147 |
+
"num_beam_groups": 1,
|
148 |
+
"num_beams": 1,
|
149 |
+
"num_codebooks": 4,
|
150 |
+
"num_hidden_layers": 24,
|
151 |
+
"num_return_sequences": 1,
|
152 |
+
"output_attentions": false,
|
153 |
+
"output_hidden_states": false,
|
154 |
+
"output_scores": false,
|
155 |
+
"pad_token_id": 2048,
|
156 |
+
"prefix": null,
|
157 |
+
"problem_type": null,
|
158 |
+
"pruned_heads": {},
|
159 |
+
"remove_invalid_values": false,
|
160 |
+
"repetition_penalty": 1.0,
|
161 |
+
"return_dict": true,
|
162 |
+
"return_dict_in_generate": false,
|
163 |
+
"scale_embedding": false,
|
164 |
+
"sep_token_id": null,
|
165 |
+
"suppress_tokens": null,
|
166 |
+
"task_specific_params": null,
|
167 |
+
"temperature": 1.0,
|
168 |
+
"tf_legacy_loss": false,
|
169 |
+
"tie_encoder_decoder": false,
|
170 |
+
"tie_word_embeddings": false,
|
171 |
+
"tokenizer_class": null,
|
172 |
+
"top_k": 50,
|
173 |
+
"top_p": 1.0,
|
174 |
+
"torch_dtype": null,
|
175 |
+
"torchscript": false,
|
176 |
+
"transformers_version": "4.31.0.dev0",
|
177 |
+
"typical_p": 1.0,
|
178 |
+
"use_bfloat16": false,
|
179 |
+
"use_cache": true,
|
180 |
+
"vocab_size": 2048
|
181 |
+
},
|
182 |
+
"is_encoder_decoder": true,
|
183 |
+
"model_type": "musicgen",
|
184 |
+
"text_encoder": {
|
185 |
+
"_name_or_path": "t5-base",
|
186 |
+
"add_cross_attention": false,
|
187 |
+
"architectures": [
|
188 |
+
"T5ForConditionalGeneration"
|
189 |
+
],
|
190 |
+
"bad_words_ids": null,
|
191 |
+
"begin_suppress_tokens": null,
|
192 |
+
"bos_token_id": null,
|
193 |
+
"chunk_size_feed_forward": 0,
|
194 |
+
"cross_attention_hidden_size": null,
|
195 |
+
"d_ff": 3072,
|
196 |
+
"d_kv": 64,
|
197 |
+
"d_model": 768,
|
198 |
+
"decoder_start_token_id": 0,
|
199 |
+
"dense_act_fn": "relu",
|
200 |
+
"diversity_penalty": 0.0,
|
201 |
+
"do_sample": false,
|
202 |
+
"dropout_rate": 0.1,
|
203 |
+
"early_stopping": false,
|
204 |
+
"encoder_no_repeat_ngram_size": 0,
|
205 |
+
"eos_token_id": 1,
|
206 |
+
"exponential_decay_length_penalty": null,
|
207 |
+
"feed_forward_proj": "relu",
|
208 |
+
"finetuning_task": null,
|
209 |
+
"forced_bos_token_id": null,
|
210 |
+
"forced_eos_token_id": null,
|
211 |
+
"id2label": {
|
212 |
+
"0": "LABEL_0",
|
213 |
+
"1": "LABEL_1"
|
214 |
+
},
|
215 |
+
"initializer_factor": 1.0,
|
216 |
+
"is_decoder": false,
|
217 |
+
"is_encoder_decoder": true,
|
218 |
+
"is_gated_act": false,
|
219 |
+
"label2id": {
|
220 |
+
"LABEL_0": 0,
|
221 |
+
"LABEL_1": 1
|
222 |
+
},
|
223 |
+
"layer_norm_epsilon": 1e-06,
|
224 |
+
"length_penalty": 1.0,
|
225 |
+
"max_length": 20,
|
226 |
+
"min_length": 0,
|
227 |
+
"model_type": "t5",
|
228 |
+
"n_positions": 512,
|
229 |
+
"no_repeat_ngram_size": 0,
|
230 |
+
"num_beam_groups": 1,
|
231 |
+
"num_beams": 1,
|
232 |
+
"num_decoder_layers": 12,
|
233 |
+
"num_heads": 12,
|
234 |
+
"num_layers": 12,
|
235 |
+
"num_return_sequences": 1,
|
236 |
+
"output_attentions": false,
|
237 |
+
"output_hidden_states": false,
|
238 |
+
"output_past": true,
|
239 |
+
"output_scores": false,
|
240 |
+
"pad_token_id": 0,
|
241 |
+
"prefix": null,
|
242 |
+
"problem_type": null,
|
243 |
+
"pruned_heads": {},
|
244 |
+
"relative_attention_max_distance": 128,
|
245 |
+
"relative_attention_num_buckets": 32,
|
246 |
+
"remove_invalid_values": false,
|
247 |
+
"repetition_penalty": 1.0,
|
248 |
+
"return_dict": true,
|
249 |
+
"return_dict_in_generate": false,
|
250 |
+
"sep_token_id": null,
|
251 |
+
"suppress_tokens": null,
|
252 |
+
"task_specific_params": {
|
253 |
+
"summarization": {
|
254 |
+
"early_stopping": true,
|
255 |
+
"length_penalty": 2.0,
|
256 |
+
"max_length": 200,
|
257 |
+
"min_length": 30,
|
258 |
+
"no_repeat_ngram_size": 3,
|
259 |
+
"num_beams": 4,
|
260 |
+
"prefix": "summarize: "
|
261 |
+
},
|
262 |
+
"translation_en_to_de": {
|
263 |
+
"early_stopping": true,
|
264 |
+
"max_length": 300,
|
265 |
+
"num_beams": 4,
|
266 |
+
"prefix": "translate English to German: "
|
267 |
+
},
|
268 |
+
"translation_en_to_fr": {
|
269 |
+
"early_stopping": true,
|
270 |
+
"max_length": 300,
|
271 |
+
"num_beams": 4,
|
272 |
+
"prefix": "translate English to French: "
|
273 |
+
},
|
274 |
+
"translation_en_to_ro": {
|
275 |
+
"early_stopping": true,
|
276 |
+
"max_length": 300,
|
277 |
+
"num_beams": 4,
|
278 |
+
"prefix": "translate English to Romanian: "
|
279 |
+
}
|
280 |
+
},
|
281 |
+
"temperature": 1.0,
|
282 |
+
"tf_legacy_loss": false,
|
283 |
+
"tie_encoder_decoder": false,
|
284 |
+
"tie_word_embeddings": true,
|
285 |
+
"tokenizer_class": null,
|
286 |
+
"top_k": 50,
|
287 |
+
"top_p": 1.0,
|
288 |
+
"torch_dtype": null,
|
289 |
+
"torchscript": false,
|
290 |
+
"transformers_version": "4.31.0.dev0",
|
291 |
+
"typical_p": 1.0,
|
292 |
+
"use_bfloat16": false,
|
293 |
+
"use_cache": true,
|
294 |
+
"vocab_size": 32128
|
295 |
+
},
|
296 |
+
"torch_dtype": "float32",
|
297 |
+
"transformers_version": null
|
298 |
+
}
|
handler.py
ADDED
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from typing import Dict, List, Any
|
2 |
+
from transformers import AutoProcessor, MusicgenForConditionalGeneration
|
3 |
+
import torch
|
4 |
+
|
5 |
+
class EndpointHandler:
|
6 |
+
def __init__(self, path=""):
|
7 |
+
# load model and processor from path
|
8 |
+
self.processor = AutoProcessor.from_pretrained(path)
|
9 |
+
self.model = MusicgenForConditionalGeneration.from_pretrained(path, torch_dtype=torch.float16).to("cuda")
|
10 |
+
|
11 |
+
def __call__(self, data: Dict[str, Any]) -> Dict[str, str]:
|
12 |
+
"""
|
13 |
+
Args:
|
14 |
+
data (:dict:):
|
15 |
+
The payload with the text prompt and generation parameters.
|
16 |
+
"""
|
17 |
+
# process input
|
18 |
+
inputs = data.pop("inputs", data)
|
19 |
+
parameters = data.pop("parameters", None)
|
20 |
+
|
21 |
+
# preprocess
|
22 |
+
inputs = self.processor(
|
23 |
+
text=[inputs],
|
24 |
+
padding=True,
|
25 |
+
return_tensors="pt",).to("cuda")
|
26 |
+
|
27 |
+
# pass inputs with all kwargs in data
|
28 |
+
if parameters is not None:
|
29 |
+
with torch.autocast("cuda"):
|
30 |
+
outputs = self.model.generate(**inputs, **parameters)
|
31 |
+
else:
|
32 |
+
with torch.autocast("cuda"):
|
33 |
+
outputs = self.model.generate(**inputs,)
|
34 |
+
|
35 |
+
# postprocess the prediction
|
36 |
+
prediction = outputs[0].cpu().numpy().tolist()
|
37 |
+
|
38 |
+
return [{"generated_audio": prediction}]
|
requirements.txt
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
1 |
+
transformers==4.31.0
|
2 |
+
accelerate>=0.20.3
|
state_dict.bin
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:f3b20997834de1ca47d6a31d00a5dc37019b279c7c8f250fd482d56def04faaa
|
3 |
+
size 3678455287
|