Spaces:
Sleeping
Sleeping
Upload 4 files
Browse files
audiocraft/grids/magnet/audio_magnet_16khz.py
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Copyright (c) Meta Platforms, Inc. and affiliates.
|
| 2 |
+
# All rights reserved.
|
| 3 |
+
#
|
| 4 |
+
# This source code is licensed under the license found in the
|
| 5 |
+
# LICENSE file in the root directory of this source tree.
|
| 6 |
+
|
| 7 |
+
from ..musicgen._explorers import LMExplorer
|
| 8 |
+
from ...environment import AudioCraftEnvironment
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
@LMExplorer
|
| 12 |
+
def explorer(launcher):
|
| 13 |
+
partitions = AudioCraftEnvironment.get_slurm_partitions(['team', 'global'])
|
| 14 |
+
launcher.slurm_(gpus=32, partition=partitions)
|
| 15 |
+
launcher.bind_(solver='magnet/audio_magnet_16khz')
|
| 16 |
+
# replace this by the desired environmental sound dataset
|
| 17 |
+
launcher.bind_(dset='internal/sounds_16khz')
|
| 18 |
+
|
| 19 |
+
fsdp = {'autocast': False, 'fsdp.use': True}
|
| 20 |
+
medium = {'model/lm/model_scale': 'medium'}
|
| 21 |
+
|
| 22 |
+
# Small model (300M)
|
| 23 |
+
launcher.slurm_(gpus=32).bind_(label='32gpus')
|
| 24 |
+
with launcher.job_array():
|
| 25 |
+
sub = launcher.bind()
|
| 26 |
+
sub()
|
| 27 |
+
|
| 28 |
+
# Medium model (1.5B)
|
| 29 |
+
launcher.slurm_(gpus=64).bind_(label='64gpus')
|
| 30 |
+
with launcher.job_array():
|
| 31 |
+
sub = launcher.bind()
|
| 32 |
+
sub(medium, fsdp)
|
audiocraft/grids/magnet/audio_magnet_pretrained_16khz_eval.py
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Copyright (c) Meta Platforms, Inc. and affiliates.
|
| 2 |
+
# All rights reserved.
|
| 3 |
+
#
|
| 4 |
+
# This source code is licensed under the license found in the
|
| 5 |
+
# LICENSE file in the root directory of this source tree.
|
| 6 |
+
|
| 7 |
+
"""
|
| 8 |
+
Evaluation with objective metrics for the pretrained audio-MAGNeT models.
|
| 9 |
+
This grid takes signature from the training grid and runs evaluation-only stage.
|
| 10 |
+
|
| 11 |
+
When running the grid for the first time, please use:
|
| 12 |
+
REGEN=1 dora grid magnet.audio_magnet_pretrained_16khz_eval
|
| 13 |
+
and re-use the REGEN=1 option when the grid is changed to force regenerating it.
|
| 14 |
+
|
| 15 |
+
Note that you need the proper metrics external libraries setup to use all
|
| 16 |
+
the objective metrics activated in this grid. Refer to the README for more information.
|
| 17 |
+
"""
|
| 18 |
+
|
| 19 |
+
import os
|
| 20 |
+
|
| 21 |
+
from ..musicgen._explorers import GenerationEvalExplorer
|
| 22 |
+
from ...environment import AudioCraftEnvironment
|
| 23 |
+
from ... import train
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
def eval(launcher, batch_size: int = 32):
|
| 27 |
+
opts = {
|
| 28 |
+
'dset': 'audio/audiocaps_16khz',
|
| 29 |
+
'solver/audiogen/evaluation': 'objective_eval',
|
| 30 |
+
'execute_only': 'evaluate',
|
| 31 |
+
'+dataset.evaluate.batch_size': batch_size,
|
| 32 |
+
'+metrics.fad.tf.batch_size': 32,
|
| 33 |
+
}
|
| 34 |
+
# binary for FAD computation: replace this path with your own path
|
| 35 |
+
metrics_opts = {
|
| 36 |
+
'metrics.fad.tf.bin': '/data/home/jadecopet/local/usr/opt/google-research'
|
| 37 |
+
}
|
| 38 |
+
|
| 39 |
+
sub = launcher.bind(opts)
|
| 40 |
+
sub.bind_(metrics_opts)
|
| 41 |
+
|
| 42 |
+
# base objective metrics
|
| 43 |
+
sub()
|
| 44 |
+
|
| 45 |
+
|
| 46 |
+
@GenerationEvalExplorer
|
| 47 |
+
def explorer(launcher):
|
| 48 |
+
partitions = AudioCraftEnvironment.get_slurm_partitions(['team', 'global'])
|
| 49 |
+
launcher.slurm_(gpus=4, partition=partitions)
|
| 50 |
+
|
| 51 |
+
if 'REGEN' not in os.environ:
|
| 52 |
+
folder = train.main.dora.dir / 'grids' / __name__.split('.', 2)[-1]
|
| 53 |
+
with launcher.job_array():
|
| 54 |
+
for sig in folder.iterdir():
|
| 55 |
+
if not sig.is_symlink():
|
| 56 |
+
continue
|
| 57 |
+
xp = train.main.get_xp_from_sig(sig.name)
|
| 58 |
+
launcher(xp.argv)
|
| 59 |
+
return
|
| 60 |
+
|
| 61 |
+
with launcher.job_array():
|
| 62 |
+
audio_magnet = launcher.bind(solver="magnet/audio_magnet_16khz")
|
| 63 |
+
|
| 64 |
+
fsdp = {'autocast': False, 'fsdp.use': True}
|
| 65 |
+
|
| 66 |
+
# Small audio-MAGNeT model (300M)
|
| 67 |
+
audio_magnet_small = audio_magnet.bind({'continue_from': '//pretrained/facebook/audio-magnet-small'})
|
| 68 |
+
eval(audio_magnet_small, batch_size=128)
|
| 69 |
+
|
| 70 |
+
# Medium audio-MAGNeT model (1.5B)
|
| 71 |
+
audio_magnet_medium = audio_magnet.bind({'continue_from': '//pretrained/facebook/audio-magnet-medium'})
|
| 72 |
+
audio_magnet_medium.bind_({'model/lm/model_scale': 'medium'})
|
| 73 |
+
audio_magnet_medium.bind_(fsdp)
|
| 74 |
+
eval(audio_magnet_medium, batch_size=128)
|
audiocraft/grids/magnet/magnet_32khz.py
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Copyright (c) Meta Platforms, Inc. and affiliates.
|
| 2 |
+
# All rights reserved.
|
| 3 |
+
#
|
| 4 |
+
# This source code is licensed under the license found in the
|
| 5 |
+
# LICENSE file in the root directory of this source tree.
|
| 6 |
+
|
| 7 |
+
from ..musicgen._explorers import LMExplorer
|
| 8 |
+
from ...environment import AudioCraftEnvironment
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
@LMExplorer
|
| 12 |
+
def explorer(launcher):
|
| 13 |
+
partitions = AudioCraftEnvironment.get_slurm_partitions(['team', 'global'])
|
| 14 |
+
launcher.slurm_(gpus=32, partition=partitions)
|
| 15 |
+
launcher.bind_(solver='magnet/magnet_32khz')
|
| 16 |
+
# replace this by the desired music dataset
|
| 17 |
+
launcher.bind_(dset='internal/music_400k_32khz')
|
| 18 |
+
|
| 19 |
+
fsdp = {'autocast': False, 'fsdp.use': True}
|
| 20 |
+
medium = {'model/lm/model_scale': 'medium'}
|
| 21 |
+
adam = {'optim.optimizer': 'adamw', 'optim.lr': 1e-4}
|
| 22 |
+
segdur_10secs = {'dataset.segment_duration': 10,
|
| 23 |
+
'dataset.batch_size': 576,
|
| 24 |
+
'generate.lm.decoding_steps': [20, 10, 10, 10]}
|
| 25 |
+
|
| 26 |
+
# Small models (300M)
|
| 27 |
+
launcher.slurm_(gpus=32).bind_(label='32gpus')
|
| 28 |
+
with launcher.job_array():
|
| 29 |
+
# 30 seconds
|
| 30 |
+
sub = launcher.bind()
|
| 31 |
+
sub()
|
| 32 |
+
|
| 33 |
+
# 10 seconds
|
| 34 |
+
sub = launcher.bind()
|
| 35 |
+
sub(segdur_10secs)
|
| 36 |
+
|
| 37 |
+
# Medium models (1.5B)
|
| 38 |
+
launcher.bind_(fsdp)
|
| 39 |
+
launcher.slurm_(gpus=64).bind_(label='64gpus')
|
| 40 |
+
with launcher.job_array():
|
| 41 |
+
# 30 seconds
|
| 42 |
+
sub = launcher.bind()
|
| 43 |
+
sub(medium, adam)
|
| 44 |
+
|
| 45 |
+
# 10 seconds
|
| 46 |
+
sub = launcher.bind()
|
| 47 |
+
sub(segdur_10secs)
|
audiocraft/grids/magnet/magnet_pretrained_32khz_eval.py
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Copyright (c) Meta Platforms, Inc. and affiliates.
|
| 2 |
+
# All rights reserved.
|
| 3 |
+
#
|
| 4 |
+
# This source code is licensed under the license found in the
|
| 5 |
+
# LICENSE file in the root directory of this source tree.
|
| 6 |
+
|
| 7 |
+
"""
|
| 8 |
+
Evaluation with objective metrics for the pretrained MAGNeT models.
|
| 9 |
+
This grid takes signature from the training grid and runs evaluation-only stage.
|
| 10 |
+
|
| 11 |
+
When running the grid for the first time, please use:
|
| 12 |
+
REGEN=1 dora grid magnet.magnet_pretrained_32khz_eval
|
| 13 |
+
and re-use the REGEN=1 option when the grid is changed to force regenerating it.
|
| 14 |
+
|
| 15 |
+
Note that you need the proper metrics external libraries setup to use all
|
| 16 |
+
the objective metrics activated in this grid. Refer to the README for more information.
|
| 17 |
+
"""
|
| 18 |
+
|
| 19 |
+
import os
|
| 20 |
+
|
| 21 |
+
from ..musicgen._explorers import GenerationEvalExplorer
|
| 22 |
+
from ...environment import AudioCraftEnvironment
|
| 23 |
+
from ... import train
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
def eval(launcher, batch_size: int = 32):
|
| 27 |
+
opts = {
|
| 28 |
+
'dset': 'audio/musiccaps_32khz',
|
| 29 |
+
'solver/musicgen/evaluation': 'objective_eval',
|
| 30 |
+
'execute_only': 'evaluate',
|
| 31 |
+
'+dataset.evaluate.batch_size': batch_size,
|
| 32 |
+
'+metrics.fad.tf.batch_size': 16,
|
| 33 |
+
}
|
| 34 |
+
# binary for FAD computation: replace this path with your own path
|
| 35 |
+
metrics_opts = {
|
| 36 |
+
'metrics.fad.tf.bin': '/data/home/jadecopet/local/usr/opt/google-research'
|
| 37 |
+
}
|
| 38 |
+
|
| 39 |
+
sub = launcher.bind(opts)
|
| 40 |
+
sub.bind_(metrics_opts)
|
| 41 |
+
|
| 42 |
+
# base objective metrics
|
| 43 |
+
sub()
|
| 44 |
+
|
| 45 |
+
|
| 46 |
+
@GenerationEvalExplorer
|
| 47 |
+
def explorer(launcher):
|
| 48 |
+
partitions = AudioCraftEnvironment.get_slurm_partitions(['team', 'global'])
|
| 49 |
+
launcher.slurm_(gpus=4, partition=partitions)
|
| 50 |
+
|
| 51 |
+
if 'REGEN' not in os.environ:
|
| 52 |
+
folder = train.main.dora.dir / 'grids' / __name__.split('.', 2)[-1]
|
| 53 |
+
with launcher.job_array():
|
| 54 |
+
for sig in folder.iterdir():
|
| 55 |
+
if not sig.is_symlink():
|
| 56 |
+
continue
|
| 57 |
+
xp = train.main.get_xp_from_sig(sig.name)
|
| 58 |
+
launcher(xp.argv)
|
| 59 |
+
return
|
| 60 |
+
|
| 61 |
+
with launcher.job_array():
|
| 62 |
+
magnet = launcher.bind(solver="magnet/magnet_32khz")
|
| 63 |
+
|
| 64 |
+
fsdp = {'autocast': False, 'fsdp.use': True}
|
| 65 |
+
|
| 66 |
+
segdur_10secs = {'dataset.segment_duration': 10,
|
| 67 |
+
'generate.lm.decoding_steps': [20, 10, 10, 10]}
|
| 68 |
+
|
| 69 |
+
# 10-second magnet models
|
| 70 |
+
magnet_small_10secs = magnet.bind({'continue_from': '//pretrained/facebook/magnet-small-10secs'})
|
| 71 |
+
magnet_small_10secs.bind_(segdur_10secs)
|
| 72 |
+
eval(magnet_small_10secs, batch_size=128)
|
| 73 |
+
|
| 74 |
+
magnet_medium_10secs = magnet.bind({'continue_from': '//pretrained/facebook/magnet-medium-10secs'})
|
| 75 |
+
magnet_medium_10secs.bind_(segdur_10secs)
|
| 76 |
+
magnet_medium_10secs.bind_({'model/lm/model_scale': 'medium'})
|
| 77 |
+
magnet_medium_10secs.bind_(fsdp)
|
| 78 |
+
eval(magnet_medium_10secs, batch_size=128)
|
| 79 |
+
|
| 80 |
+
# 30-second magnet models
|
| 81 |
+
magnet_small_30secs = magnet.bind({'continue_from': '//pretrained/facebook/magnet-small-30secs'})
|
| 82 |
+
eval(magnet_small_30secs, batch_size=128)
|
| 83 |
+
|
| 84 |
+
magnet_medium_30secs = magnet.bind({'continue_from': '//pretrained/facebook/magnet-medium-30secs'})
|
| 85 |
+
magnet_medium_30secs.bind_({'model/lm/model_scale': 'medium'})
|
| 86 |
+
magnet_medium_30secs.bind_(fsdp)
|
| 87 |
+
eval(magnet_medium_30secs, batch_size=128)
|