-
Notifications
You must be signed in to change notification settings - Fork 217
fix: improve Apple Silicon compatibility #26
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
kesjam
wants to merge
1
commit into
hkchengrex:main
Choose a base branch
from
kesjam:fix/apple-silicon-compatibility
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ | |
from datetime import datetime | ||
from fractions import Fraction | ||
from pathlib import Path | ||
import os | ||
|
||
import gradio as gr | ||
import torch | ||
|
@@ -15,25 +16,38 @@ | |
from mmaudio.model.sequence_config import SequenceConfig | ||
from mmaudio.model.utils.features_utils import FeaturesUtils | ||
|
||
torch.backends.cuda.matmul.allow_tf32 = True | ||
torch.backends.cudnn.allow_tf32 = True | ||
|
||
# Set up logging | ||
setup_eval_logging() | ||
log = logging.getLogger() | ||
|
||
device = 'cpu' | ||
if torch.cuda.is_available(): | ||
device = 'cuda' | ||
elif torch.backends.mps.is_available(): | ||
device = 'mps' | ||
else: | ||
log.warning('CUDA/MPS are not available, running on CPU') | ||
dtype = torch.bfloat16 | ||
|
||
model: ModelConfig = all_model_cfg['large_44k_v2'] | ||
model.download_if_needed() | ||
output_dir = Path('./output/gradio') | ||
|
||
setup_eval_logging() | ||
# Configure device and model | ||
device = 'cpu' # Force CPU for better compatibility | ||
dtype = torch.float32 # Use float32 instead of bfloat16 for better compatibility | ||
|
||
# Disable MPS/CUDA to ensure consistent behavior | ||
torch.backends.cuda.matmul.allow_tf32 = False | ||
torch.backends.cudnn.allow_tf32 = False | ||
|
||
# Set environment variable for MPS fallback | ||
os.environ['PYTORCH_ENABLE_MPS_FALLBACK'] = '1' | ||
|
||
# Parse arguments | ||
parser = ArgumentParser() | ||
parser.add_argument('--port', type=int, default=7861) | ||
parser.add_argument('--variant', type=str, default='small_44k', choices=list(all_model_cfg.keys())) | ||
args = parser.parse_args() | ||
|
||
# Load model | ||
try: | ||
model: ModelConfig = all_model_cfg[args.variant] | ||
if not model.model_path.exists(): | ||
log.info(f'Downloading model weights for {args.variant}...') | ||
model.download_if_needed() | ||
output_dir = Path('./output/gradio') | ||
output_dir.mkdir(exist_ok=True, parents=True) | ||
except Exception as e: | ||
log.error(f'Error loading model: {e}') | ||
raise | ||
Comment on lines
+41
to
+50
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
||
|
||
def get_model() -> tuple[MMAudio, FeaturesUtils, SequenceConfig]: | ||
|
@@ -330,10 +344,29 @@ def text_to_audio(prompt: str, negative_prompt: str, seed: int, num_steps: int, | |
) | ||
|
||
if __name__ == "__main__": | ||
parser = ArgumentParser() | ||
parser.add_argument('--port', type=int, default=7860) | ||
args = parser.parse_args() | ||
|
||
gr.TabbedInterface([video_to_audio_tab, text_to_audio_tab, image_to_audio_tab], | ||
['Video-to-Audio', 'Text-to-Audio', 'Image-to-Audio (experimental)']).launch( | ||
server_port=args.port, allowed_paths=[output_dir]) | ||
# Basic configuration | ||
import os | ||
os.environ["GRADIO_DEBUG"] = "1" | ||
os.environ["GRADIO_ANALYTICS_ENABLED"] = "false" # Disable analytics | ||
|
||
# Create a simple interface first | ||
with gr.Blocks(css="button {background: #1565c0}") as interface: | ||
gr.Markdown("# MMAudio") | ||
|
||
with gr.Tab("Text-to-Audio"): | ||
text_to_audio_tab.render() | ||
|
||
with gr.Tab("Video-to-Audio"): | ||
video_to_audio_tab.render() | ||
|
||
with gr.Tab("Image-to-Audio"): | ||
image_to_audio_tab.render() | ||
|
||
# Launch with minimal configuration | ||
interface.launch( | ||
server_name="127.0.0.1", # Only local access | ||
server_port=7863, | ||
show_error=True, | ||
allowed_paths=[output_dir], | ||
prevent_thread_lock=True | ||
) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
large_44k_v2
is a better default.