[Python] How to create background process with smallest GPU memory consumption

Discussão em 'Python' iniciado por Stack, Junho 6, 2025.

  1. Stack

    Stack Membro Participativo

    I am trying to create a simple script that will be reserving small amount of gpu memory on each GPU. Process will be running in the background and if you run nvidia-smi you can see that it consumes GPUs. However the simple code below consumes quite a lot, about 522mb, on each GPUs. Is it possible to rewrite the script and reduce gpu memory consumption? Ideally I want the process to only consume 1mb from each gpu?

    import torch
    import time

    if torch.cuda.is_available():
    n = torch.cuda.device_count()

    print(f"Total cuda devices {n}")
    vars = []
    for i in range(n):
    a = torch.tensor(True).to(f'cuda:{i}')
    vars.append(a)


    while True:
    time.sleep(60)


    [​IMG]

    Continue reading...

Compartilhe esta Página