gpu-zombie-test/scenario-1-nofix/gpu_worker.py

25 lines
622 B
Python

import torch
import time
import os
import signal
# SIGTERM 무시 — 잘못 작성된 코드 시뮬레이션
signal.signal(signal.SIGTERM, signal.SIG_IGN)
print(f"[Worker] PID: {os.getpid()}, PPID: {os.getppid()}")
# GPU 메모리 할당 (~2GB)
device = torch.device('cuda:0')
tensors = []
for i in range(8):
t = torch.randn(1024, 1024, 64, device=device)
tensors.append(t)
allocated = torch.cuda.memory_allocated() / 1024**3
print(f"[Worker] GPU 메모리 할당 완료: {allocated:.2f} GB")
# 무한 대기
while True:
time.sleep(5)
print(f"[Worker] alive, PID={os.getpid()}, PPID={os.getppid()}")