mirror of
https://github.com/ml-explore/mlx-examples.git
synced 2025-10-24 22:58:08 +08:00
MusicGen (#1020)
* Add MusicGen model * add benchmarks * change to from_pretrained * symlinks * add readme and requirements * fix readme * readme
This commit is contained in:
28
musicgen/benchmarks/bench_mx.py
Normal file
28
musicgen/benchmarks/bench_mx.py
Normal file
@@ -0,0 +1,28 @@
|
||||
# Copyright © 2024 Apple Inc.
|
||||
|
||||
import sys
|
||||
import time
|
||||
from pathlib import Path
|
||||
|
||||
import mlx.core as mx
|
||||
|
||||
cur_path = Path(__file__).parents[1].resolve()
|
||||
sys.path.append(str(cur_path))
|
||||
|
||||
from musicgen import MusicGen
|
||||
|
||||
text = "folk ballad"
|
||||
model = MusicGen.from_pretrained("facebook/musicgen-medium")
|
||||
|
||||
max_steps = 100
|
||||
|
||||
audio = model.generate(text, max_steps=10)
|
||||
mx.eval(audio)
|
||||
|
||||
tic = time.time()
|
||||
audio = model.generate(text, max_steps=max_steps)
|
||||
mx.eval(audio)
|
||||
toc = time.time()
|
||||
|
||||
ms = 1000 * (toc - tic) / max_steps
|
||||
print(f"Time (ms) per step: {ms:.3f}")
|
||||
Reference in New Issue
Block a user