|
import os |
|
import time |
|
import wandb |
|
import nvidia_smi |
|
import os |
|
import time |
|
import threading |
|
import wandb |
|
os.system("pip install nvidia-ml-py3") |
|
|
|
os.system('wandb login 6cdd066d56acd416b1c1680133e37589511d81f7') |
|
nvidia_smi.nvmlInit() |
|
|
|
wandb.init(project="GPU-使用率-温度检测") |
|
def monitor_gpu(): |
|
while True: |
|
try: |
|
|
|
handle = nvidia_smi.nvmlDeviceGetHandleByIndex(0) |
|
gpu_temperature = nvidia_smi.nvmlDeviceGetTemperature(handle, nvidia_smi.NVML_TEMPERATURE_GPU) |
|
|
|
|
|
utilization = nvidia_smi.nvmlDeviceGetUtilizationRates(handle) |
|
gpu_usage = utilization.gpu |
|
|
|
|
|
wandb.log({"GPU 温度": gpu_temperature, "GPU 使用率": gpu_usage}) |
|
|
|
except Exception as e: |
|
print(f"Error: {e}") |
|
|
|
time.sleep(60) |
|
monitor_gpu() |