Skip to content
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

Update dependencies in requirements.txt #1

Merged
merged 1 commit into from
Nov 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions logs/api.log
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
2024-11-09 07:49:24.302 | INFO | __main__:<module>:271 - Starting server on port 8000
2024-11-09 08:14:16.781 | INFO | __main__:<module>:271 - Starting server on port 8000
2024-11-09 08:19:05.939 | INFO | __main__:<module>:271 - Starting server on port 8000
2024-11-09 08:31:58.329 | INFO | __main__:<module>:271 - Starting server on port 8000
2024-11-09 08:41:50.867 | INFO | __main__:<module>:271 - Starting server on port 8000
3 changes: 3 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,6 @@ wandb
setuptools
pydantic-settings
boto3
prometheus-client
loguru
bitsandbytes
8 changes: 5 additions & 3 deletions src/api/mochi_serve.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ def predict(self, inputs: List[Dict[str, Any]]) -> List[Dict[str, Any]]:

# Upload to S3
with open(temp_video_path, "rb") as video_file:
s3_response = mp4_to_s3_json(video_file, "video.mp4")
s3_response = mp4_to_s3_json(video_file, f"mochi_{int(time.time())}.mp4")

result = {
"status": "success",
Expand Down Expand Up @@ -241,7 +241,7 @@ def encode_response(self, output: Union[Dict[str, Any], List[Any]]) -> Dict[str,
if __name__ == "__main__":
import sys
prometheus_logger = PrometheusLogger()
prometheus_logger.mount(path="/metrics", app=make_asgi_app(registry=registry))
prometheus_logger.mount(path="/api/v1/metrics", app=make_asgi_app(registry=registry))
# Configure logging
logger.remove()
logger.add(
Expand All @@ -266,7 +266,9 @@ def encode_response(self, output: Union[Dict[str, Any], List[Any]]) -> Dict[str,
devices="auto",
max_batch_size=1,
track_requests=True,
loggers=prometheus_logger
loggers=prometheus_logger,
generate_client_file=False

)
logger.info("Starting server on port 8000")
server.run(port=8000)
Expand Down
11 changes: 5 additions & 6 deletions src/configs/mochi_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,21 +38,20 @@ class MochiSettings(BaseSettings):
model_name: str = 'Genmo-Mochi'
transformer_path: str = "imnotednamode/mochi-1-preview-mix-nf4"
pipeline_path: str = "VikramSingh178/mochi-diffuser-bf16"
dtype: torch.dtype = torch.bfloat16
dtype: torch.dtype = torch.float16
device: str = "cuda"

# Optimization Settings
enable_vae_tiling: bool = True
enable_model_cpu_offload: bool = True
enable_attention_slicing: bool = False
attention_slice_size: Optional[int] = None


# Video Generation Settings
num_inference_steps: int = 20
guidance_scale: float = 7.5
height: int = 480
width: int = 848
num_frames: int = 150
height: int = 640
width: int = 480
num_frames: int = 60
fps: int = 10

class Config:
Expand Down
38 changes: 37 additions & 1 deletion src/scripts/mochi_diffusers.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,4 +170,40 @@ def clear_memory(self) -> None:
if torch.cuda.is_available():
logger.info("Clearing CUDA memory cache")
torch.cuda.empty_cache()
torch.cuda.reset_peak_memory_stats()
torch.cuda.reset_peak_memory_stats()

if __name__ == "__main__":
from configs.mochi_settings import MochiSettings

settings = MochiSettings()

# Initialize inference class
mochi_inference = MochiInference(settings)

# Define prompt and output path
prompt = "Close-up of a chameleon's eye, with its scaly skin changing color. Ultra high resolution 4k."
output_path = "/home/ubuntu/Minimochi/outputs/output.mp4"

# Generate video
try:
video_path = mochi_inference.generate(
prompt=prompt,
negative_prompt='((((ugly)))), (((duplicate))), ((morbid)), ((mutilated)), out of frame, extra fingers, mutated hands, ((poorly drawn hands)), ((poorly drawn face)), (((mutation))), (((deformed))), ((ugly)), blurry, ((bad anatomy)), (((bad proportions))), ((extra limbs)), cloned face, (((disfigured))), out of frame, ugly, extra limbs, (bad anatomy), gross proportions, (malformed limbs), ((missing arms)), ((missing legs)), (((extra arms))), (((extra legs))), mutated hands, (fused fingers), (too many fingers), (((long neck)))',
output_path=output_path,
num_inference_steps=30,
guidance_scale=3.5,
height=480,
width=848,
num_frames=150,
fps=30,
)
print(f"Video saved to: {video_path}")
except RuntimeError as e:
print(f"Failed to generate video: {e}")

# Display GPU memory usage for debugging
allocated, max_allocated = mochi_inference.get_memory_usage()
print(f"Memory usage: {allocated:.2f}GB (peak: {max_allocated:.2f}GB)")

# Clear memory cache after inference
mochi_inference.clear_memory()
Loading