Spaces:
Build error
Build error
Update app.py
Browse files43 unmodified lines444546474849507 unmodified lines585960616263646566671 unmodified line697071727374757 unmodified lines8384858687888943 unmodified linestorch.cuda.set_per_process_memory_fraction(safe_fraction)self.force_memory_release()def optimize_memory(self):gc.collect()torch.cuda.empty_cache()7 unmodified linestorch.cuda.synchronize()torch.cuda.reset_peak_memory_stats()for obj in gc.get_objects():try:if torch.is_tensor(obj):del objexcept Exception:pass1 unmodified lineif not torch.cuda.is_available():return Truefree_memory = torch.cuda.get_device_properties(0).total_memory - torch.cuda.memory_allocated()free_memory_mb = free_memory / (1024 * 1024)return free_memory_mb >= required_memory_mb7 unmodified lines"cached": torch.cuda.memory_reserved() / (1024 * 1024),"max_allocated": torch.cuda.max_memory_allocated() / (1024 * 1024)}class RoleLearningManager:def __init__(self, checkpoint_dir: str = "./role_checkpoints"):self.checkpoint_dir = checkpoint_dir43 unmodified lines444546474849507 unmodified lines5859606162636465666768691 unmodified line7172737475767778798081827 unmodified lines9091929394959643 unmodified linestorch.cuda.set_per_process_memory_fraction(safe_fraction)self.force_memory_release()def optimize_memory(self):gc.collect()torch.cuda.empty_cache()7 unmodified linestorch.cuda.synchronize()torch.cuda.reset_peak_memory_stats()# More thorough tensor cleanupfor obj in gc.get_objects():try:if torch.is_tensor(obj):if obj.is_cuda:del objexcept Exception:pass1 unmodified lineif not torch.cuda.is_available():return True# More accurate memory availability checkallocated = torch.cuda.memory_allocated()cached = torch.cuda.memory_reserved()total = torch.cuda.get_device_properties(0).total_memoryfree_memory = total - allocated - cachedfree_memory_mb = free_memory / (1024 * 1024)return free_memory_mb >= required_memory_mb7 unmodified lines"cached": torch.cuda.memory_reserved() / (1024 * 1024),"max_allocated": torch.cuda.max_memory_allocated() / (1024 * 1024)}class RoleLearningManager:def __init__(self, checkpoint_dir: str = "./role_checkpoints"):self.checkpoint_dir = checkpoint_dir
app.py+11-4