Skip to content

Maya Fast Api deployment on Modal#3

Open
raccoon641 wants to merge 1 commit intoMayaResearch:masterfrom
raccoon641:master
Open

Maya Fast Api deployment on Modal#3
raccoon641 wants to merge 1 commit intoMayaResearch:masterfrom
raccoon641:master

Conversation

@raccoon641
Copy link

@raccoon641 raccoon641 commented Nov 16, 2025

If you want to deploy api FastAPI-based server on modal, you can do "modal deploy maya_deploy.py", and you will get an endpoint that you can use to call your fast api server.

Summary by CodeRabbit

  • New Features
    • Enabled text-to-speech service deployment with GPU acceleration support. The application now provides ASGI-compatible web service endpoints with automatic environment initialization and customizable model path configuration. Includes integrated container orchestration with intelligent workload scaling, configurable execution timeouts, and comprehensive runtime dependency bundling for streamlined production deployment.

@coderabbitai
Copy link

coderabbitai bot commented Nov 16, 2025

Walkthrough

A new Modal-based ASGI application is introduced in modal_app.py that configures a containerized Python environment with GPU support (A10G). The maya1_tts_app function loads environment variables from .env, sets a default model path, and exposes the FastAPI application from maya1.api_v2 for serverless deployment.

Changes

Cohort / File(s) Summary
Modal ASGI Application
modal_app.py
Added new function maya1_tts_app() decorated with Modal's @app.function() and @modal.asgi_app(). Configures Debian Slim Python image with pip dependencies, loads environment variables via dotenv, sets default MAYA1_MODEL_PATH to "maya-research/maya1", and returns FastAPI app from maya1.api_v2 as ASGI application. Specifies GPU type A10G, 600-second timeout, and 1 container instance.

Sequence Diagram

sequenceDiagram
    participant Modal Runtime
    participant modal_app.py
    participant .env File
    participant maya1.api_v2

    Modal Runtime->>modal_app.py: Invoke maya1_tts_app()
    modal_app.py->>+.env File: Load environment variables
    .env File-->>-modal_app.py: Variables loaded
    modal_app.py->>modal_app.py: Check MAYA1_MODEL_PATH
    Note over modal_app.py: If not set, default to<br/>"maya-research/maya1"
    modal_app.py->>+maya1.api_v2: Import FastAPI app
    maya1.api_v2-->>-modal_app.py: Return app instance
    modal_app.py-->>Modal Runtime: Return ASGI app
    Note over Modal Runtime: App ready for requests
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

  • Verify Modal decorator configuration (app.function parameters: GPU type, timeout, container bounds)
  • Confirm environment variable loading and .env file path handling
  • Validate default model path assignment logic
  • Ensure maya1.api_v2.app is correctly exposed as ASGI application
  • Check that FastAPI app is properly imported and callable

Poem

🐰✨ Hops through the cloud with Modal's might,
A containerized app, configured just right—
With GPU whispers and env-laden care,
FastAPI's magic now floating through air! 🚀

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'Maya Fast Api deployment on Modal' accurately summarizes the main change: adding Modal deployment capability for a FastAPI application.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Tip

📝 Customizable high-level summaries are now available!

You can now customize how CodeRabbit generates the high-level summary in your pull requests — including its content, structure, tone, and formatting.

  • Provide custom instructions to shape the summary (bullet lists, tables, contributor stats, etc.).
  • Use high_level_summary_in_walkthrough to move the summary from the description to the walkthrough section.

Example:

"Create a concise high-level summary as a bullet-point list. Then include a Markdown table showing lines added and removed by each contributing author."


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (4)
maya_modal.py (4)

4-4: Consider a more descriptive app name.

The app name "sub1" is generic and doesn't reflect the purpose of this deployment. A more descriptive name like "maya1-tts-fastapi" would make it easier to identify in the Modal dashboard.

-app = modal.App("sub1")
+app = modal.App("maya1-tts-fastapi")

9-33: Consider pinning dependency versions more strictly.

Using >= for all dependencies allows any future version to be installed, which can lead to unexpected breaking changes or dependency conflicts. For production deployments, consider using more specific version constraints (e.g., ~= for compatible releases or exact versions with ==).

For example:

-        "torch>=2.5.0",
-        "transformers>=4.57.0",
+        "torch~=2.5.0",
+        "transformers~=4.57.0",

46-47: Review container scaling configuration for cost and performance implications.

The current configuration sets min_containers=1 and max_containers=1, which means:

  • Cost: The container will run continuously 24/7, even with no traffic, incurring ongoing GPU costs.
  • Performance: The service cannot scale horizontally under load, potentially causing request queuing or timeouts during high traffic.

Consider whether these constraints are intentional for your use case:

  • If you need instant response times without cold starts, keep min_containers=1.
  • If you expect variable load, increase max_containers to allow scaling (e.g., max_containers=5).
  • If cost optimization is important and cold starts are acceptable, reduce min_containers=0.

50-71: Add error handling for imports and initialization.

The function lacks error handling around the import of maya1.api_v2.app. If the import fails (e.g., due to missing dependencies or initialization errors in the FastAPI app), the error won't be caught, making debugging difficult.

Consider adding basic error handling:

 def maya1_tts_app():
     """
     Runs inside the Modal container.
 
     - Loads env (.env) if present
     - Sets default model path
     - Imports FastAPI `app` from maya1.api_v2
     - Returns it as the ASGI app
     """
     import os
-    from dotenv import load_dotenv
-
-    load_dotenv()
-
-    # If not overridden, use HF repo as model path
     os.environ.setdefault("MAYA1_MODEL_PATH", "maya-research/maya1")
-
-    # If the model is gated and you need auth, you can also set:
-    # os.environ.setdefault("HUGGINGFACE_HUB_TOKEN", "<your_hf_token>")
-
-    from maya1.api_v2 import app as fastapi_app
+    
+    try:
+        from maya1.api_v2 import app as fastapi_app
+    except Exception as e:
+        print(f"Failed to import FastAPI app: {e}")
+        raise
+    
     return fastapi_app
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 63099d9 and e832f9c.

⛔ Files ignored due to path filters (1)
  • maya1_test.wav is excluded by !**/*.wav
📒 Files selected for processing (1)
  • maya_modal.py (1 hunks)
🔇 Additional comments (1)
maya_modal.py (1)

9-33: Do not add flashinfer-python—it's incompatible with the specified PyTorch version.

The requirements.txt file does list flashinfer-python, but it explicitly documents: "Currently incompatible with PyTorch 2.5+". Since maya_modal.py specifies torch>=2.5.0, the intentional exclusion of flashinfer-python is correct. The codebase contains no flashinfer imports, confirming it is unused. Adding this dependency would introduce a version conflict.

Likely an incorrect or invalid review comment.

import os
from dotenv import load_dotenv

load_dotenv()
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical

Critical: .env file won't be available in Modal containers.

The load_dotenv() call will fail silently because .env files are not automatically copied to Modal containers. Environment variables configured via load_dotenv() will not be set, potentially causing the application to fail or use incorrect defaults.

Use Modal Secrets to manage environment variables instead.

Apply this approach:

  1. Create Modal secrets for your environment variables:
# Set secrets via Modal CLI
modal secret create maya1-secrets \
  MAYA1_MODEL_PATH="maya-research/maya1" \
  HUGGINGFACE_HUB_TOKEN="your_token_here"
  1. Update the function decorator to use the secrets:
 @app.function(
     image=image,
     gpu="A10G",
     timeout=600,
     min_containers=1,
     max_containers=1,
+    secrets=[modal.Secret.from_name("maya1-secrets")],
 )
 @modal.asgi_app()
 def maya1_tts_app():
  1. Remove or simplify the dotenv logic:
-    import os
-    from dotenv import load_dotenv
-
-    load_dotenv()
-
-    # If not overridden, use HF repo as model path
-    os.environ.setdefault("MAYA1_MODEL_PATH", "maya-research/maya1")
-
-    # If the model is gated and you need auth, you can also set:
-    # os.environ.setdefault("HUGGINGFACE_HUB_TOKEN", "<your_hf_token>")
+    import os
+    
+    # Secrets are automatically injected as environment variables
+    # Set defaults only if not provided
+    os.environ.setdefault("MAYA1_MODEL_PATH", "maya-research/maya1")
🤖 Prompt for AI Agents
In maya_modal.py around line 62, the call to load_dotenv() is inappropriate
because Modal containers won’t have a .env file; replace this with Modal
Secrets: remove or disable load_dotenv() and any reliance on dotenv, create
Modal secrets for the required variables (e.g., MAYA1_MODEL_PATH,
HUGGINGFACE_HUB_TOKEN), update the Modal function decorator to include
secrets=<your_secret_name> so the secrets are injected into the container, and
read values from os.environ at runtime; also remove the dotenv import if no
longer used.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant