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

Fix: Utils error in mochi finetuning script #218

Merged
merged 1 commit into from
Jan 14, 2025
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
4 changes: 0 additions & 4 deletions training/mochi-1/text_to_video_lora.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,6 @@
from dataset_simple import LatentEmbedDataset

import sys


sys.path.append("..")

from utils import print_memory, reset_memory # isort:skip


Expand Down
22 changes: 22 additions & 0 deletions training/mochi-1/utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import gc
import inspect
from typing import Optional, Tuple, Union

import torch

logger = get_logger(__name__)

def reset_memory(device: Union[str, torch.device]) -> None:
gc.collect()
torch.cuda.empty_cache()
torch.cuda.reset_peak_memory_stats(device)
torch.cuda.reset_accumulated_memory_stats(device)


def print_memory(device: Union[str, torch.device]) -> None:
memory_allocated = torch.cuda.memory_allocated(device) / 1024**3
max_memory_allocated = torch.cuda.max_memory_allocated(device) / 1024**3
max_memory_reserved = torch.cuda.max_memory_reserved(device) / 1024**3
print(f"{memory_allocated=:.3f} GB")
print(f"{max_memory_allocated=:.3f} GB")
print(f"{max_memory_reserved=:.3f} GB")