Vansh Chugh commited on
Commit
a80fd99
·
1 Parent(s): 39c9833

cleanup: remove dead MAGNeT/MBD loader code, drop redundant dbn=False, remove loopgen-repo reference copy

Browse files
.gitignore CHANGED
@@ -1,4 +1,3 @@
1
  __pycache__/
2
  *.pyc
3
  .DS_Store
4
- loopgen-repo/
 
1
  __pycache__/
2
  *.pyc
3
  .DS_Store
 
app.py CHANGED
@@ -173,7 +173,7 @@ def process_fn(description: str, min_length: float, max_length: float, seed: int
173
  if loopgen is None:
174
  loopgen = LoopGen.get_pretrained(MAGNET_MODEL, device=DEVICE)
175
  if file2beats is None:
176
- file2beats = File2Beats(checkpoint_path=beat_checkpoint_path, device=DEVICE, dbn=False)
177
 
178
  torch.manual_seed(seed)
179
  np.random.seed(seed)
 
173
  if loopgen is None:
174
  loopgen = LoopGen.get_pretrained(MAGNET_MODEL, device=DEVICE)
175
  if file2beats is None:
176
+ file2beats = File2Beats(checkpoint_path=beat_checkpoint_path, device=DEVICE)
177
 
178
  torch.manual_seed(seed)
179
  np.random.seed(seed)
src/audiocraft/models/loaders.py CHANGED
@@ -119,60 +119,3 @@ def load_lm_model(file_or_url_or_id: tp.Union[Path, str], device='cpu', cache_di
119
  return model
120
 
121
 
122
- def load_lm_model_magnet(file_or_url_or_id: tp.Union[Path, str], compression_model_frame_rate: int,
123
- device='cpu', cache_dir: tp.Optional[str] = None):
124
- pkg = load_lm_model_ckpt(file_or_url_or_id, cache_dir=cache_dir)
125
- cfg = OmegaConf.create(pkg['xp.cfg'])
126
- cfg.device = str(device)
127
- if cfg.device == 'cpu':
128
- cfg.dtype = 'float32'
129
- else:
130
- cfg.dtype = 'float16'
131
- _delete_param(cfg, 'conditioners.args.merge_text_conditions_p')
132
- _delete_param(cfg, 'conditioners.args.drop_desc_p')
133
-
134
- cfg.transformer_lm.compression_model_framerate = compression_model_frame_rate
135
- cfg.transformer_lm.segment_duration = cfg.dataset.segment_duration
136
- cfg.transformer_lm.span_len = cfg.masking.span_len
137
-
138
- # MAGNeT models v1 support only xformers backend.
139
- from src.audiocraft.modules.transformer import set_efficient_attention_backend
140
- if cfg.transformer_lm.memory_efficient:
141
- set_efficient_attention_backend("xformers")
142
-
143
- model = builders.get_lm_model(cfg)
144
- model.load_state_dict(pkg['best_state'])
145
- model.eval()
146
- model.cfg = cfg
147
- return model
148
-
149
-
150
- def load_mbd_ckpt(file_or_url_or_id: tp.Union[Path, str],
151
- filename: tp.Optional[str] = None,
152
- cache_dir: tp.Optional[str] = None):
153
- return _get_state_dict(file_or_url_or_id, filename=filename, cache_dir=cache_dir)
154
-
155
-
156
- def load_diffusion_models(file_or_url_or_id: tp.Union[Path, str],
157
- device='cpu',
158
- filename: tp.Optional[str] = None,
159
- cache_dir: tp.Optional[str] = None):
160
- pkg = load_mbd_ckpt(file_or_url_or_id, filename=filename, cache_dir=cache_dir)
161
- models = []
162
- processors = []
163
- cfgs = []
164
- sample_rate = pkg['sample_rate']
165
- for i in range(pkg['n_bands']):
166
- cfg = pkg[i]['cfg']
167
- model = builders.get_diffusion_model(cfg)
168
- model_dict = pkg[i]['model_state']
169
- model.load_state_dict(model_dict)
170
- model.to(device)
171
- processor = builders.get_processor(cfg=cfg.processor, sample_rate=sample_rate)
172
- processor_dict = pkg[i]['processor_state']
173
- processor.load_state_dict(processor_dict)
174
- processor.to(device)
175
- models.append(model)
176
- processors.append(processor)
177
- cfgs.append(cfg)
178
- return models, processors, cfgs
 
119
  return model
120
 
121
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
src/audiocraft/models/magnet.py CHANGED
@@ -9,10 +9,8 @@ Main model for using MAGNeT. This will combine all the required components
9
  and provide easy access to the generation API.
10
  """
11
  import typing as tp
12
- import torch
13
 
14
  from .genmodel import BaseGenModel
15
- from .loaders import load_compression_model, load_lm_model_magnet
16
 
17
 
18
  class MAGNeT(BaseGenModel):
@@ -26,37 +24,6 @@ class MAGNeT(BaseGenModel):
26
  self.duration = self.lm.cfg.dataset.segment_duration
27
  self.set_generation_params()
28
 
29
- @staticmethod
30
- def get_pretrained(name: str = 'facebook/magnet-small-10secs', device=None):
31
- """Return pretrained model, we provide six models:
32
- - facebook/magnet-small-10secs (300M), text to music, 10-second audio samples.
33
- # see: https://huggingface.co/facebook/magnet-small-10secs
34
- - facebook/magnet-medium-10secs (1.5B), text to music, 10-second audio samples.
35
- # see: https://huggingface.co/facebook/magnet-medium-10secs
36
- - facebook/magnet-small-30secs (300M), text to music, 30-second audio samples.
37
- # see: https://huggingface.co/facebook/magnet-small-30secs
38
- - facebook/magnet-medium-30secs (1.5B), text to music, 30-second audio samples.
39
- # see: https://huggingface.co/facebook/magnet-medium-30secs
40
- - facebook/audio-magnet-small (300M), text to sound-effect (10-second samples).
41
- # see: https://huggingface.co/facebook/audio-magnet-small
42
- - facebook/audio-magnet-medium (1.5B), text to sound-effect (10-second samples).
43
- # see: https://huggingface.co/facebook/audio-magnet-medium
44
- """
45
- if device is None:
46
- if torch.cuda.device_count():
47
- device = 'cuda'
48
- else:
49
- device = 'cpu'
50
-
51
- compression_model = load_compression_model(name, device=device)
52
- lm = load_lm_model_magnet(name, compression_model_frame_rate=int(compression_model.frame_rate), device=device)
53
-
54
- if 'self_wav' in lm.condition_provider.conditioners:
55
- lm.condition_provider.conditioners['self_wav'].match_len_on_eval = True
56
-
57
- kwargs = {'name': name, 'compression_model': compression_model, 'lm': lm}
58
- return MAGNeT(**kwargs)
59
-
60
  def set_generation_params(self, use_sampling: bool = True, top_k: int = 0,
61
  top_p: float = 0.9, temperature: float = 3.0,
62
  max_cfg_coef: float = 10.0, min_cfg_coef: float = 1.0,
 
9
  and provide easy access to the generation API.
10
  """
11
  import typing as tp
 
12
 
13
  from .genmodel import BaseGenModel
 
14
 
15
 
16
  class MAGNeT(BaseGenModel):
 
24
  self.duration = self.lm.cfg.dataset.segment_duration
25
  self.set_generation_params()
26
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
27
  def set_generation_params(self, use_sampling: bool = True, top_k: int = 0,
28
  top_p: float = 0.9, temperature: float = 3.0,
29
  max_cfg_coef: float = 10.0, min_cfg_coef: float = 1.0,