Spaces:
Running on Zero
Running on Zero
Vansh Chugh
cleanup: remove dead MAGNeT/MBD loader code, drop redundant dbn=False, remove loopgen-repo reference copy
a80fd99 Download src/audiocraft/models/magnet.py from teamup-tech/LoopGen: direct link, hf CLI and curl.
- Browser
- Download file 2.61 kB
-
https://huggingface.co/spaces/teamup-tech/LoopGen/resolve/main/src/audiocraft/models/magnet.py
- Command line
-
hf download hf://spaces/teamup-tech/LoopGen/src/audiocraft/models/magnet.py
-
curl -L -o magnet.py https://huggingface.co/spaces/teamup-tech/LoopGen/resolve/main/src/audiocraft/models/magnet.py
2.61 kB
| # Copyright (c) Meta Platforms, Inc. and affiliates. | |
| # All rights reserved. | |
| # | |
| # This source code is licensed under the license found in the | |
| # LICENSE file in the root directory of this source tree. | |
| """ | |
| Main model for using MAGNeT. This will combine all the required components | |
| and provide easy access to the generation API. | |
| """ | |
| import typing as tp | |
| from .genmodel import BaseGenModel | |
| class MAGNeT(BaseGenModel): | |
| """MAGNeT main model with convenient generation API. | |
| Args: | |
| See MusicGen class. | |
| """ | |
| def __init__(self, **kwargs): | |
| super().__init__(**kwargs) | |
| # MAGNeT operates over a fixed sequence length defined in it's config. | |
| self.duration = self.lm.cfg.dataset.segment_duration | |
| self.set_generation_params() | |
| def set_generation_params(self, use_sampling: bool = True, top_k: int = 0, | |
| top_p: float = 0.9, temperature: float = 3.0, | |
| max_cfg_coef: float = 10.0, min_cfg_coef: float = 1.0, | |
| decoding_steps: tp.List[int] = [20, 10, 10, 10], | |
| span_arrangement: str = 'nonoverlap'): | |
| """Set the generation parameters for MAGNeT. | |
| Args: | |
| use_sampling (bool, optional): Use sampling if True, else do argmax decoding. Defaults to True. | |
| top_k (int, optional): top_k used for sampling. Defaults to 0. | |
| top_p (float, optional): top_p used for sampling, when set to 0 top_k is used. Defaults to 0.9. | |
| temperature (float, optional): Initial softmax temperature parameter. Defaults to 3.0. | |
| max_cfg_coef (float, optional): Coefficient used for classifier free guidance. Defaults to 10.0. | |
| min_cfg_coef (float, optional): End coefficient of classifier free guidance annealing. Defaults to 1.0. | |
| decoding_steps (list of n_q ints, optional): The number of iterative decoding steps, | |
| for each of the n_q RVQ codebooks. | |
| span_arrangement (str, optional): Use either non-overlapping spans ('nonoverlap') | |
| or overlapping spans ('stride1') in the masking scheme. | |
| """ | |
| self.generation_params = { | |
| 'use_sampling': use_sampling, | |
| 'temp': temperature, | |
| 'top_k': top_k, | |
| 'top_p': top_p, | |
| 'max_cfg_coef': max_cfg_coef, | |
| 'min_cfg_coef': min_cfg_coef, | |
| 'decoding_steps': [int(s) for s in decoding_steps], | |
| 'span_arrangement': span_arrangement | |
| } | |