如何获取 TensorFlow 中实际使用的 GPU 内存大小
在使用 TensorFlow 时,可以使用 `tf.config.list_physical_devices('GPU')` 函数来获得系统中可用的 GPU 设备列表。然后,可以使用 `tf.config.experimental.get_memory_usage(python\nimport tensorflow as tf\n\n# 获取可用的 GPU 设备列表\ngpus = tf.config.list_physical_devices('GPU')\nif gpus:\n for gpu in gpus:\n # 获取 GPU 设备的内存使用情况\n mem_usage = tf.config.experimental.get_memory_usage(gpu)\n print(f"GPU memory usage: {mem_usage.current_bytes / 1024**3} GB / {mem_usage.total_bytes / 1024**3} GB")\nelse:\n print("No GPU devices found.")\n\n\n这将输出每个可用 GPU 设备的内存使用情况,包括当前使用的字节数和总字节数。
原文地址: https://www.cveoy.top/t/topic/pqfp 著作权归作者所有。请勿转载和采集!