From db697f1ccb10629caca91a8b963101ff1b1eb950 Mon Sep 17 00:00:00 2001 From: John Pollock Date: Fri, 22 Aug 2025 21:50:09 -0500 Subject: [PATCH] Updating allocation logic based on exact placement and not the DistorchV1 methodology of CPU overrun. From lowvram_fix branch. --- distorch_2.py | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/distorch_2.py b/distorch_2.py index e475dbe..8777e7b 100644 --- a/distorch_2.py +++ b/distorch_2.py @@ -351,7 +351,7 @@ def calculate_safetensor_vvram_allocation(model_patcher, virtual_vram_str): logger.info(fmt_assign.format(recipient_device, 'recip', f"{recipient_vram:.2f}GB",f"{recipient_virtual:.2f}GB", f"+{virtual_vram_gb:.2f}GB")) # Handle donor devices - ram_donors = [d for d in donors.split(',') if d != 'cpu'] + ram_donors = [d for d in donors.split(',')] remaining_vram_needed = virtual_vram_gb donor_device_info = {} @@ -359,7 +359,7 @@ def calculate_safetensor_vvram_allocation(model_patcher, virtual_vram_str): for donor in ram_donors: donor_vram = mm.get_total_memory(torch.device(donor)) / (1024**3) - max_donor_capacity = donor_vram * 0.9 # Use 90% max + max_donor_capacity = donor_vram donation = min(remaining_vram_needed, max_donor_capacity) donor_virtual = donor_vram - donation @@ -369,12 +369,6 @@ def calculate_safetensor_vvram_allocation(model_patcher, virtual_vram_str): donor_device_info[donor] = (donor_vram, donor_virtual) logger.info(fmt_assign.format(donor, 'donor', f"{donor_vram:.2f}GB", f"{donor_virtual:.2f}GB", f"-{donation:.2f}GB")) - # CPU gets the rest - system_dram_gb = mm.get_total_memory(torch.device('cpu')) / (1024**3) - cpu_donation = remaining_vram_needed - cpu_virtual = system_dram_gb - cpu_donation - donor_allocations['cpu'] = cpu_donation - logger.info(fmt_assign.format('cpu', 'donor', f"{system_dram_gb:.2f}GB", f"{cpu_virtual:.2f}GB", f"-{cpu_donation:.2f}GB")) logger.info(dash_line) @@ -412,9 +406,6 @@ def calculate_safetensor_vvram_allocation(model_patcher, virtual_vram_str): donor_percent = donor_allocations[donor] / donor_vram allocation_parts.append(f"{donor},{donor_percent:.4f}") - cpu_percent = donor_allocations['cpu'] / system_dram_gb - allocation_parts.append(f"cpu,{cpu_percent:.4f}") - allocation_string = ";".join(allocation_parts) fmt_mem = "{:<20}{:>20}"