Spaces:
Running
on
Zero
Running
on
Zero
chong.zhang
commited on
Commit
·
19e7dfa
1
Parent(s):
c1e0f6f
add model downloads
Browse files
inspiremusic/cli/frontend.py
CHANGED
@@ -12,8 +12,14 @@
|
|
12 |
# See the License for the specific language governing permissions and
|
13 |
# limitations under the License.
|
14 |
from functools import partial
|
|
|
15 |
import torch
|
|
|
|
|
16 |
from typing import Callable
|
|
|
|
|
|
|
17 |
import re
|
18 |
import inflect
|
19 |
from inspiremusic.cli.model import InspireMusicModel
|
|
|
12 |
# See the License for the specific language governing permissions and
|
13 |
# limitations under the License.
|
14 |
from functools import partial
|
15 |
+
import onnxruntime
|
16 |
import torch
|
17 |
+
import numpy as np
|
18 |
+
import whisper
|
19 |
from typing import Callable
|
20 |
+
import torchaudio.compliance.kaldi as kaldi
|
21 |
+
import torchaudio
|
22 |
+
import os
|
23 |
import re
|
24 |
import inflect
|
25 |
from inspiremusic.cli.model import InspireMusicModel
|
inspiremusic/cli/inference.py
CHANGED
@@ -49,15 +49,14 @@ class InspireMusicUnified:
|
|
49 |
fp16: bool = True,
|
50 |
gpu: int = 0,
|
51 |
result_dir: str = None,
|
52 |
-
hub
|
53 |
os.environ['CUDA_VISIBLE_DEVICES'] = str(gpu)
|
54 |
|
55 |
# Set model_dir or default to downloading if it doesn't exist
|
56 |
if model_dir is None:
|
57 |
model_dir = f"../../pretrained_models/{model_name}"
|
58 |
-
|
59 |
download_model_dir = os.path.dirname(model_dir)
|
60 |
-
print(download_model_dir)
|
61 |
if not os.path.isfile(f"{model_dir}/llm.pt"):
|
62 |
if hub == "modelscope":
|
63 |
from modelscope import snapshot_download
|
@@ -68,9 +67,7 @@ class InspireMusicUnified:
|
|
68 |
elif hub == "huggingface":
|
69 |
from huggingface_hub import snapshot_download
|
70 |
model_dir_tmp = snapshot_download(repo_id=f"FunAudioLLM/{model_name}", cache_dir=download_model_dir)
|
71 |
-
print(download_model_dir, model_dir_tmp, model_dir)
|
72 |
shutil.move(model_dir_tmp, model_dir)
|
73 |
-
# shutil.rmtree(model_dir_tmp)
|
74 |
|
75 |
self.model_dir = model_dir
|
76 |
|
@@ -88,6 +85,7 @@ class InspireMusicUnified:
|
|
88 |
use_cuda = gpu >= 0 and torch.cuda.is_available()
|
89 |
self.device = torch.device('cuda' if use_cuda else 'cpu')
|
90 |
self.model = InspireMusic(self.model_dir, load_jit=load_jit, load_onnx=load_onnx, fast=fast, fp16=fp16)
|
|
|
91 |
|
92 |
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
|
93 |
|
@@ -202,10 +200,6 @@ class InspireMusicUnified:
|
|
202 |
|
203 |
else:
|
204 |
logging.error(f"Generated audio length is shorter than minimum required audio length.")
|
205 |
-
if music_fn:
|
206 |
-
return music_fn
|
207 |
-
else:
|
208 |
-
return None
|
209 |
|
210 |
def get_args():
|
211 |
parser = argparse.ArgumentParser(description='Run inference with your model')
|
|
|
49 |
fp16: bool = True,
|
50 |
gpu: int = 0,
|
51 |
result_dir: str = None,
|
52 |
+
hub="modelscope"):
|
53 |
os.environ['CUDA_VISIBLE_DEVICES'] = str(gpu)
|
54 |
|
55 |
# Set model_dir or default to downloading if it doesn't exist
|
56 |
if model_dir is None:
|
57 |
model_dir = f"../../pretrained_models/{model_name}"
|
58 |
+
|
59 |
download_model_dir = os.path.dirname(model_dir)
|
|
|
60 |
if not os.path.isfile(f"{model_dir}/llm.pt"):
|
61 |
if hub == "modelscope":
|
62 |
from modelscope import snapshot_download
|
|
|
67 |
elif hub == "huggingface":
|
68 |
from huggingface_hub import snapshot_download
|
69 |
model_dir_tmp = snapshot_download(repo_id=f"FunAudioLLM/{model_name}", cache_dir=download_model_dir)
|
|
|
70 |
shutil.move(model_dir_tmp, model_dir)
|
|
|
71 |
|
72 |
self.model_dir = model_dir
|
73 |
|
|
|
85 |
use_cuda = gpu >= 0 and torch.cuda.is_available()
|
86 |
self.device = torch.device('cuda' if use_cuda else 'cpu')
|
87 |
self.model = InspireMusic(self.model_dir, load_jit=load_jit, load_onnx=load_onnx, fast=fast, fp16=fp16)
|
88 |
+
self.model.model.llm = self.model.model.llm.to(torch.float16)
|
89 |
|
90 |
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
|
91 |
|
|
|
200 |
|
201 |
else:
|
202 |
logging.error(f"Generated audio length is shorter than minimum required audio length.")
|
|
|
|
|
|
|
|
|
203 |
|
204 |
def get_args():
|
205 |
parser = argparse.ArgumentParser(description='Run inference with your model')
|
inspiremusic/cli/inspiremusic.py
CHANGED
@@ -39,14 +39,9 @@ class InspireMusic:
|
|
39 |
elif hub == "huggingface":
|
40 |
from huggingface_hub import snapshot_download
|
41 |
model_dir_tmp = snapshot_download(repo_id=f"FunAudioLLM/{model_name}", cache_dir=download_model_dir)
|
42 |
-
print(model_dir_tmp, model_dir)
|
43 |
shutil.move(model_dir_tmp, model_dir)
|
44 |
-
# shutil.rmtree(model_dir_tmp)
|
45 |
-
|
46 |
-
self.model_dir = model_dir
|
47 |
|
48 |
assert os.path.exists(f'{model_dir}/inspiremusic.yaml')
|
49 |
-
|
50 |
with open('{}/inspiremusic.yaml'.format(model_dir), 'r') as f:
|
51 |
configs = load_hyperpyyaml(f)
|
52 |
|
|
|
39 |
elif hub == "huggingface":
|
40 |
from huggingface_hub import snapshot_download
|
41 |
model_dir_tmp = snapshot_download(repo_id=f"FunAudioLLM/{model_name}", cache_dir=download_model_dir)
|
|
|
42 |
shutil.move(model_dir_tmp, model_dir)
|
|
|
|
|
|
|
43 |
|
44 |
assert os.path.exists(f'{model_dir}/inspiremusic.yaml')
|
|
|
45 |
with open('{}/inspiremusic.yaml'.format(model_dir), 'r') as f:
|
46 |
configs = load_hyperpyyaml(f)
|
47 |
|
inspiremusic/llm/llm.py
CHANGED
@@ -35,7 +35,7 @@ class SinusoidalEmbedding(nn.Module):
|
|
35 |
emb = torch.tensor(log(10000) / (half_dim - 1), device=device)
|
36 |
emb = torch.exp(torch.arange(half_dim, device=device) * -emb)
|
37 |
emb = rearrange(x, "i -> i 1") * rearrange(emb, "j -> 1 j")
|
38 |
-
return torch.cat((emb.sin(), emb.cos()), dim=-1).to(torch.
|
39 |
|
40 |
class LLM(torch.nn.Module):
|
41 |
def __init__(
|
|
|
35 |
emb = torch.tensor(log(10000) / (half_dim - 1), device=device)
|
36 |
emb = torch.exp(torch.arange(half_dim, device=device) * -emb)
|
37 |
emb = rearrange(x, "i -> i 1") * rearrange(emb, "j -> 1 j")
|
38 |
+
return torch.cat((emb.sin(), emb.cos()), dim=-1).to(torch.float16)
|
39 |
|
40 |
class LLM(torch.nn.Module):
|
41 |
def __init__(
|