update reforge
Browse files- modules/sd_models.py +21 -7
modules/sd_models.py
CHANGED
|
@@ -649,15 +649,29 @@ def force_memory_deallocation():
|
|
| 649 |
def on_delete(ref):
|
| 650 |
tracked_objects.remove(ref)
|
| 651 |
|
| 652 |
-
# Track large objects for collection
|
| 653 |
-
large_objects = [
|
| 654 |
-
|
| 655 |
-
|
| 656 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 657 |
|
| 658 |
for obj in large_objects:
|
| 659 |
-
|
| 660 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 661 |
|
| 662 |
# Force collection
|
| 663 |
del large_objects
|
|
|
|
| 649 |
def on_delete(ref):
|
| 650 |
tracked_objects.remove(ref)
|
| 651 |
|
| 652 |
+
# Track large objects for collection - FIXED: Added try-except to handle garbage collected objects
|
| 653 |
+
large_objects = []
|
| 654 |
+
for obj in gc.get_objects():
|
| 655 |
+
try:
|
| 656 |
+
# Check if object is still valid before accessing its properties
|
| 657 |
+
if (isinstance(obj, torch.Tensor) and
|
| 658 |
+
hasattr(obj, 'is_cuda') and not obj.is_cuda and
|
| 659 |
+
hasattr(obj, 'numel') and obj.numel() > 1e6):
|
| 660 |
+
large_objects.append(obj)
|
| 661 |
+
except ReferenceError:
|
| 662 |
+
# Object was garbage collected during iteration, skip it
|
| 663 |
+
continue
|
| 664 |
+
except Exception:
|
| 665 |
+
# Any other exception, just skip this object
|
| 666 |
+
continue
|
| 667 |
|
| 668 |
for obj in large_objects:
|
| 669 |
+
try:
|
| 670 |
+
ref = weakref.ref(obj, on_delete)
|
| 671 |
+
tracked_objects.append(ref)
|
| 672 |
+
except:
|
| 673 |
+
# If we can't create a weak reference, just skip it
|
| 674 |
+
pass
|
| 675 |
|
| 676 |
# Force collection
|
| 677 |
del large_objects
|