[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"similar-anderskm--gputil":3,"tool-anderskm--gputil":61},[4,18,26,36,44,53],{"id":5,"name":6,"github_repo":7,"description_zh":8,"stars":9,"difficulty_score":10,"last_commit_at":11,"category_tags":12,"status":17},4358,"openclaw","openclaw\u002Fopenclaw","OpenClaw 是一款专为个人打造的本地化 AI 助手，旨在让你在自己的设备上拥有完全可控的智能伙伴。它打破了传统 AI 助手局限于特定网页或应用的束缚，能够直接接入你日常使用的各类通讯渠道，包括微信、WhatsApp、Telegram、Discord、iMessage 等数十种平台。无论你在哪个聊天软件中发送消息，OpenClaw 都能即时响应，甚至支持在 macOS、iOS 和 Android 设备上进行语音交互，并提供实时的画布渲染功能供你操控。\n\n这款工具主要解决了用户对数据隐私、响应速度以及“始终在线”体验的需求。通过将 AI 部署在本地，用户无需依赖云端服务即可享受快速、私密的智能辅助，真正实现了“你的数据，你做主”。其独特的技术亮点在于强大的网关架构，将控制平面与核心助手分离，确保跨平台通信的流畅性与扩展性。\n\nOpenClaw 非常适合希望构建个性化工作流的技术爱好者、开发者，以及注重隐私保护且不愿被单一生态绑定的普通用户。只要具备基础的终端操作能力（支持 macOS、Linux 及 Windows WSL2），即可通过简单的命令行引导完成部署。如果你渴望拥有一个懂你",349277,3,"2026-04-06T06:32:30",[13,14,15,16],"Agent","开发框架","图像","数据工具","ready",{"id":19,"name":20,"github_repo":21,"description_zh":22,"stars":23,"difficulty_score":10,"last_commit_at":24,"category_tags":25,"status":17},3808,"stable-diffusion-webui","AUTOMATIC1111\u002Fstable-diffusion-webui","stable-diffusion-webui 是一个基于 Gradio 构建的网页版操作界面，旨在让用户能够轻松地在本地运行和使用强大的 Stable Diffusion 图像生成模型。它解决了原始模型依赖命令行、操作门槛高且功能分散的痛点，将复杂的 AI 绘图流程整合进一个直观易用的图形化平台。\n\n无论是希望快速上手的普通创作者、需要精细控制画面细节的设计师，还是想要深入探索模型潜力的开发者与研究人员，都能从中获益。其核心亮点在于极高的功能丰富度：不仅支持文生图、图生图、局部重绘（Inpainting）和外绘（Outpainting）等基础模式，还独创了注意力机制调整、提示词矩阵、负向提示词以及“高清修复”等高级功能。此外，它内置了 GFPGAN 和 CodeFormer 等人脸修复工具，支持多种神经网络放大算法，并允许用户通过插件系统无限扩展能力。即使是显存有限的设备，stable-diffusion-webui 也提供了相应的优化选项，让高质量的 AI 艺术创作变得触手可及。",162132,"2026-04-05T11:01:52",[14,15,13],{"id":27,"name":28,"github_repo":29,"description_zh":30,"stars":31,"difficulty_score":32,"last_commit_at":33,"category_tags":34,"status":17},1381,"everything-claude-code","affaan-m\u002Feverything-claude-code","everything-claude-code 是一套专为 AI 编程助手（如 Claude Code、Codex、Cursor 等）打造的高性能优化系统。它不仅仅是一组配置文件，而是一个经过长期实战打磨的完整框架，旨在解决 AI 代理在实际开发中面临的效率低下、记忆丢失、安全隐患及缺乏持续学习能力等核心痛点。\n\n通过引入技能模块化、直觉增强、记忆持久化机制以及内置的安全扫描功能，everything-claude-code 能显著提升 AI 在复杂任务中的表现，帮助开发者构建更稳定、更智能的生产级 AI 代理。其独特的“研究优先”开发理念和针对 Token 消耗的优化策略，使得模型响应更快、成本更低，同时有效防御潜在的攻击向量。\n\n这套工具特别适合软件开发者、AI 研究人员以及希望深度定制 AI 工作流的技术团队使用。无论您是在构建大型代码库，还是需要 AI 协助进行安全审计与自动化测试，everything-claude-code 都能提供强大的底层支持。作为一个曾荣获 Anthropic 黑客大奖的开源项目，它融合了多语言支持与丰富的实战钩子（hooks），让 AI 真正成长为懂上",159636,2,"2026-04-17T23:33:34",[14,13,35],"语言模型",{"id":37,"name":38,"github_repo":39,"description_zh":40,"stars":41,"difficulty_score":32,"last_commit_at":42,"category_tags":43,"status":17},2271,"ComfyUI","Comfy-Org\u002FComfyUI","ComfyUI 是一款功能强大且高度模块化的视觉 AI 引擎，专为设计和执行复杂的 Stable Diffusion 图像生成流程而打造。它摒弃了传统的代码编写模式，采用直观的节点式流程图界面，让用户通过连接不同的功能模块即可构建个性化的生成管线。\n\n这一设计巧妙解决了高级 AI 绘图工作流配置复杂、灵活性不足的痛点。用户无需具备编程背景，也能自由组合模型、调整参数并实时预览效果，轻松实现从基础文生图到多步骤高清修复等各类复杂任务。ComfyUI 拥有极佳的兼容性，不仅支持 Windows、macOS 和 Linux 全平台，还广泛适配 NVIDIA、AMD、Intel 及苹果 Silicon 等多种硬件架构，并率先支持 SDXL、Flux、SD3 等前沿模型。\n\n无论是希望深入探索算法潜力的研究人员和开发者，还是追求极致创作自由度的设计师与资深 AI 绘画爱好者，ComfyUI 都能提供强大的支持。其独特的模块化架构允许社区不断扩展新功能，使其成为当前最灵活、生态最丰富的开源扩散模型工具之一，帮助用户将创意高效转化为现实。",108322,"2026-04-10T11:39:34",[14,15,13],{"id":45,"name":46,"github_repo":47,"description_zh":48,"stars":49,"difficulty_score":32,"last_commit_at":50,"category_tags":51,"status":17},6121,"gemini-cli","google-gemini\u002Fgemini-cli","gemini-cli 是一款由谷歌推出的开源 AI 命令行工具，它将强大的 Gemini 大模型能力直接集成到用户的终端环境中。对于习惯在命令行工作的开发者而言，它提供了一条从输入提示词到获取模型响应的最短路径，无需切换窗口即可享受智能辅助。\n\n这款工具主要解决了开发过程中频繁上下文切换的痛点，让用户能在熟悉的终端界面内直接完成代码理解、生成、调试以及自动化运维任务。无论是查询大型代码库、根据草图生成应用，还是执行复杂的 Git 操作，gemini-cli 都能通过自然语言指令高效处理。\n\n它特别适合广大软件工程师、DevOps 人员及技术研究人员使用。其核心亮点包括支持高达 100 万 token 的超长上下文窗口，具备出色的逻辑推理能力；内置 Google 搜索、文件操作及 Shell 命令执行等实用工具；更独特的是，它支持 MCP（模型上下文协议），允许用户灵活扩展自定义集成，连接如图像生成等外部能力。此外，个人谷歌账号即可享受免费的额度支持，且项目基于 Apache 2.0 协议完全开源，是提升终端工作效率的理想助手。",100752,"2026-04-10T01:20:03",[52,13,15,14],"插件",{"id":54,"name":55,"github_repo":56,"description_zh":57,"stars":58,"difficulty_score":32,"last_commit_at":59,"category_tags":60,"status":17},4721,"markitdown","microsoft\u002Fmarkitdown","MarkItDown 是一款由微软 AutoGen 团队打造的轻量级 Python 工具，专为将各类文件高效转换为 Markdown 格式而设计。它支持 PDF、Word、Excel、PPT、图片（含 OCR）、音频（含语音转录）、HTML 乃至 YouTube 链接等多种格式的解析，能够精准提取文档中的标题、列表、表格和链接等关键结构信息。\n\n在人工智能应用日益普及的今天，大语言模型（LLM）虽擅长处理文本，却难以直接读取复杂的二进制办公文档。MarkItDown 恰好解决了这一痛点，它将非结构化或半结构化的文件转化为模型“原生理解”且 Token 效率极高的 Markdown 格式，成为连接本地文件与 AI 分析 pipeline 的理想桥梁。此外，它还提供了 MCP（模型上下文协议）服务器，可无缝集成到 Claude Desktop 等 LLM 应用中。\n\n这款工具特别适合开发者、数据科学家及 AI 研究人员使用，尤其是那些需要构建文档检索增强生成（RAG）系统、进行批量文本分析或希望让 AI 助手直接“阅读”本地文件的用户。虽然生成的内容也具备一定可读性，但其核心优势在于为机器",93400,"2026-04-06T19:52:38",[52,14],{"id":62,"github_repo":63,"name":64,"description_en":65,"description_zh":66,"ai_summary_zh":67,"readme_en":68,"readme_zh":69,"quickstart_zh":70,"use_case_zh":71,"hero_image_url":72,"owner_login":73,"owner_name":74,"owner_avatar_url":75,"owner_bio":76,"owner_company":77,"owner_location":78,"owner_email":78,"owner_twitter":78,"owner_website":79,"owner_url":80,"languages":81,"stars":86,"forks":87,"last_commit_at":88,"license":89,"difficulty_score":10,"env_os":90,"env_gpu":91,"env_ram":92,"env_deps":93,"category_tags":105,"github_topics":78,"view_count":32,"oss_zip_url":78,"oss_zip_packed_at":78,"status":17,"created_at":106,"updated_at":107,"faqs":108,"releases":137},8753,"anderskm\u002Fgputil","gputil","A Python module for getting the GPU status from NVIDA GPUs using nvidia-smi programmically in Python","gputil 是一款专为 Python 开发者设计的轻量级工具，旨在帮助用户轻松获取和管理 NVIDIA GPU 的状态信息。在深度学习训练或多任务并行计算场景中，手动监控显卡显存占用和负载往往繁琐且容易出错，gputil 通过程序化调用系统底层的 `nvidia-smi` 命令，自动扫描所有可用显卡，并依据当前的显存使用率和计算负载，智能排序并返回最空闲的 GPU 设备列表。\n\n这款工具特别适合人工智能研究人员、数据科学家以及需要调度多卡资源的后端工程师。无论是使用 TensorFlow、PyTorch 还是 Caffe 等框架，用户只需几行代码即可在脚本中自动选择最佳显卡，避免将任务分配到已满负荷的设备上，从而显著提升资源利用率和任务执行效率。\n\ngputil 的技术亮点在于其“无依赖”设计，除了 Python 标准库外无需安装任何额外的重型第三方包，同时兼容 Python 2.x 和 3.x 版本。它不仅提供了获取可用设备列表的核心功能，还内置了实时显示 GPU 利用率、在独立线程中监控状态等辅助函数，让复杂的硬件管理变得简单透明。对于希望在代码层面实现自动化显卡调度的用户来说，","gputil 是一款专为 Python 开发者设计的轻量级工具，旨在帮助用户轻松获取和管理 NVIDIA GPU 的状态信息。在深度学习训练或多任务并行计算场景中，手动监控显卡显存占用和负载往往繁琐且容易出错，gputil 通过程序化调用系统底层的 `nvidia-smi` 命令，自动扫描所有可用显卡，并依据当前的显存使用率和计算负载，智能排序并返回最空闲的 GPU 设备列表。\n\n这款工具特别适合人工智能研究人员、数据科学家以及需要调度多卡资源的后端工程师。无论是使用 TensorFlow、PyTorch 还是 Caffe 等框架，用户只需几行代码即可在脚本中自动选择最佳显卡，避免将任务分配到已满负荷的设备上，从而显著提升资源利用率和任务执行效率。\n\ngputil 的技术亮点在于其“无依赖”设计，除了 Python 标准库外无需安装任何额外的重型第三方包，同时兼容 Python 2.x 和 3.x 版本。它不仅提供了获取可用设备列表的核心功能，还内置了实时显示 GPU 利用率、在独立线程中监控状态等辅助函数，让复杂的硬件管理变得简单透明。对于希望在代码层面实现自动化显卡调度的用户来说，gputil 是一个实用且高效的选择。","# GPUtil\n`GPUtil` is a Python module for getting the GPU status from NVIDA GPUs using `nvidia-smi`.\n`GPUtil` locates all GPUs on the computer, determines their availablity and returns a ordered list of available GPUs.\nAvailablity is based upon the current memory consumption and load of each GPU.\nThe module is written with GPU selection for Deep Learning in mind, but it is not task\u002Flibrary specific and it can be applied to any task, where it may be useful to identify available GPUs.\n\n**Table of Contents**\n\n1. [Requirements](#requirements)\n1. [Installation](#installation)\n1. [Usage](#usage)\n   1. [Main functions](#main-functions)\n   1. [Helper functions](#helper-functions)\n1. [Examples](#examples)\n   1. [Select first available GPU in Caffe](#select-first-available-gpu-in-caffe)\n   1. [Occupy only 1 GPU in TensorFlow](#occupy-only-1-gpu-in-tensorflow)\n   1. [Monitor GPU in a separate thread](#monitor-gpu-in-a-separate-thread)\n1. [License](#license)\n\n## Requirements\nNVIDIA GPU with latest NVIDIA driver installed.\nGPUtil uses the program `nvidia-smi` to get the GPU status of all available NVIDIA GPUs. `nvidia-smi` should be installed automatically, when you install your NVIDIA driver.\n\nSupports both Python 2.X and 3.X.\n\nPython libraries:\n* subprocess ([The Python Standard Library](https:\u002F\u002Fdocs.python.org\u002F3\u002Flibrary\u002Fsubprocess.html))\n* distutils ([The Python Standard Library](https:\u002F\u002Fdocs.python.org\u002F3\u002Flibrary\u002Fdistutils.html))\n* math ([The Python Standard Library](https:\u002F\u002Fdocs.python.org\u002F3\u002Flibrary\u002Fmath.html))\n* random ([The Python Standard Library](https:\u002F\u002Fdocs.python.org\u002F3\u002Flibrary\u002Frandom.html))\n* time ([The Python Standard Library](https:\u002F\u002Fdocs.python.org\u002F3\u002Flibrary\u002Ftime.html))\n* os ([The Python Standard Library](https:\u002F\u002Fdocs.python.org\u002F3\u002Flibrary\u002Fos.html))\n* sys ([The Python Standard Library](https:\u002F\u002Fdocs.python.org\u002F3\u002Flibrary\u002Fsys.html))\n* platform ([The Python Standard Library](https:\u002F\u002Fdocs.python.org\u002F3\u002Flibrary\u002Fplatform.html))\n\nTested on CUDA driver version 390.77 Python 2.7 and 3.5.\n\n## Installation\n\n1. Open a terminal (Ctrl+Shift+T)\n2. Type `pip install gputil`\n3. Test the installation\n   1. Open a terminal in a folder other than the GPUtil folder\n   2. Start a python console by typing `python` in the terminal\n   3. In the newly opened python console, type:\n      ```python\n      import GPUtil\n      GPUtil.showUtilization()\n      ```\n   4. Your output should look something like following, depending on your number of GPUs and their current usage:\n      ```\n       ID  GPU  MEM\n      --------------\n        0    0%   0%\n      ```\n\n### Old way of installation\n\n1. Download or clone repository to your computer\n2. Add GPUtil folder to ~\u002F.bashrc\n   1. Open a new terminal (Press Ctrl+Alt+T)\n   2. Open bashrc:\n      ```\n      gedit ~\u002F.bashrc\n      ```\n   3. Added your GPUtil folder to the environment variable `PYTHONPATH` (replace `\u003Cpath_to_gputil>` with your folder path):\n      ```\n      export PYTHONPATH=\"$PYTHONPATH:\u003Cpath_to_gputil>\"\n\n      Example:\n      export PYTHONPATH=\"$PYTHONPATH:\u002Fhome\u002Fanderskm\u002Fgithub\u002Fgputil\"\n      ```\n   4. Save ~\u002F.bashrc and close gedit\n   5. Restart your terminal\n1. Test the installation\n   1. Open a terminal in a folder other than the GPUtil folder\n   2. Start a python console by typing `python` in the terminal\n   3. In the newly opened python console, type:\n      ```python\n      import GPUtil\n      GPUtil.showUtilization()\n      ```\n   4. Your output should look something like following, depending on your number of GPUs and their current usage:\n      ```\n       ID  GPU  MEM\n      --------------\n        0    0%   0%\n      ```\n\n## Usage\n\nTo include `GPUtil` in your Python code, all you hve to do is included it at the beginning of your script:\n\n```python\nimport GPUtil\n```\n\nOnce included all functions are available. The functions along with a short description of inputs, outputs and their functionality can be found in the following two sections.\n\n### Main functions\n\n```python\ndeviceIDs = GPUtil.getAvailable(order = 'first', limit = 1, maxLoad = 0.5, maxMemory = 0.5, includeNan=False, excludeID=[], excludeUUID=[])\n```\nReturns a list ids of available GPUs. Availablity is determined based on current memory usage and load. The order, maximum number of devices, their maximum load and maximum memory consumption are determined by the input arguments.\n\n* Inputs\n  * `order` - Deterimines the order in which the available GPU device ids are returned. `order` should be specified as one of the following strings:\n    * `'first'` - orders available GPU device ids by ascending id (**defaut**)\n    * `'last'` - orders available GPU device ids by descending id\n    * `'random'` - orders the available GPU device ids randomly\n    * `'load'`- orders the available GPU device ids by ascending load\n    * `'memory'` - orders the available GPU device ids by ascending memory usage\n  * `limit` - limits the number of GPU device ids returned to the specified number. Must be positive integer. (**default = 1**)\n  * `maxLoad` - Maximum current relative load for a GPU to be considered available. GPUs with a load larger than `maxLoad` is not returned. (**default = 0.5**)\n  * `maxMemory` - Maximum current relative memory usage for a GPU to be considered available. GPUs with a current memory usage larger than `maxMemory` is not returned. (**default = 0.5**)\n  * `includeNan` - True\u002Ffalse flag indicating whether to include GPUs where either load or memory usage is NaN (indicating usage could not be retrieved). (**default = False**)\n  * `excludeID` - List of IDs, which should be excluded from the list of available GPUs. See `GPU` class description. (**default = []**)\n  * `excludeUUID` - Same as `excludeID` except it uses the UUID. (**default = []**)\n* Outputs\n  * deviceIDs - list of all available GPU device ids. A GPU is considered available, if the current load and memory usage is less than `maxLoad` and `maxMemory`, respectively. The list is ordered according to `order`. The maximum number of returned device ids is limited by `limit`.\n\n```python\ndeviceID = GPUtil.getFirstAvailable(order = 'first', maxLoad=0.5, maxMemory=0.5, attempts=1, interval=900, verbose=False)\n```\nReturns the first avaiable GPU. Availablity is determined based on current memory usage and load, and the ordering is determined by the specified order.\nIf no available GPU is found, an error is thrown.\nWhen using the default values, it is the same as `getAvailable(order = 'first', limit = 1, maxLoad = 0.5, maxMemory = 0.5)`\n\n* Inputs\n  * `order` - See the description for `GPUtil.getAvailable(...)`\n  * `maxLoad` - Maximum current relative load for a GPU to be considered available. GPUs with a load larger than `maxLoad` is not returned. (**default = 0.5**)\n  * `maxMemory` - Maximum current relative memory usage for a GPU to be considered available. GPUs with a current memory usage larger than `maxMemory` is not returned. (**default = 0.5**)\n  * `attempts` - Number of attempts the function should make before giving up finding an available GPU. (**default = 1**)\n  * `interval` - Interval in seconds between each attempt to find an available GPU. (**default = 900** --> 15 mins)\n  * `verbose` - If `True`, prints the attempt number before each attempt and the GPU id if an available is found.\n  * `includeNan` - See the description for `GPUtil.getAvailable(...)`. (**default = False**)\n  * `excludeID` - See the description for `GPUtil.getAvailable(...)`. (**default = []**)\n  * `excludeUUID` - See the description for `GPUtil.getAvailable(...)`. (**default = []**)\n* Outputs\n  * deviceID - list with 1 element containing the first available GPU device ids. A GPU is considered available, if the current load and memory usage is less than `maxLoad` and `maxMemory`, respectively. The order and limit are fixed to `'first'` and `1`, respectively.\n\n\n```python\nGPUtil.showUtilization(all=False, attrList=None, useOldCode=False)\n```\nPrints the current status (id, memory usage, uuid load) of all GPUs\n* Inputs\n  * `all` - True\u002Ffalse flag indicating if all info on the GPUs should be shown. Overwrites `attrList`.\n  * `attrList` - List of lists of `GPU` attributes to display. See code for more information\u002Fexample.\n  * `useOldCode` - True\u002Ffalse flag indicating if the old code to display GPU utilization should be used.\n* Outputs\n  * _None_\n\n### Helper functions\n```python\n class GPU\n```\nHelper class handle the attributes of each GPU. Quoted descriptions are copied from corresponding descriptions by `nvidia-smi`.\n* Attributes for each `GPU`\n  * `id` - \"Zero based index of the GPU. Can change at each boot.\"\n  * `uuid` - \"This value is the globally unique immutable alphanumeric identifier of the GPU. It does not correspond to any physical label on the board. Does not change across reboots.\"\n  * `load` - Relative GPU load. 0 to 1 (100%, full load). \"Percent of time over the past sample period during which one or more kernels was executing on the GPU. The sample period may be between 1 second and 1\u002F6 second depending on the product.\"\n  * `memoryUtil` - Relative memory usage from 0 to 1 (100%, full usage). \"Percent of time over the past sample period during which global (device) memory was being read or written. The sample period may be between 1 second and 1\u002F6 second depending on the product.\"\n  * `memoryTotal` - \"Total installed GPU memory.\"\n  * `memoryUsed` - \"Total GPU memory allocated by active contexts.\"\n  * `memoryFree` - \"Total free GPU memory.\"\n  * `driver` - \"The version of the installed NVIDIA display driver.\"\n  * `name` - \"The official product name of the GPU.\"\n  * `serial` - This number matches the serial number physically printed on each board. It is a globally unique immutable alphanumeric value.\n  * `display_mode` - \"A flag that indicates whether a physical display (e.g. monitor) is currently connected to any of the GPU's connectors. \"Enabled\" indicates an attached display. \"Disabled\" indicates otherwise.\"\n  * `display_active` - \"A flag that indicates whether a display is initialized on the GPU's (e.g. memory is allocated on the device for display). Display can be active even when no monitor is physically attached. \"Enabled\" indicates an active display. \"Disabled\" indicates otherwise.\"\n\n```python\nGPUs = GPUtil.getGPUs()\n```\n* Inputs\n  * _None_\n* Outputs\n  * `GPUs` - list of all GPUs. Each `GPU` corresponds to one GPU in the computer and contains a device id, relative load and relative memory usage.\n\n```python\nGPUavailability = GPUtil.getAvailability(GPUs, maxLoad = 0.5, maxMemory = 0.5, includeNan=False, excludeID=[], excludeUUID=[])\n```\nGiven a list of `GPUs` (see `GPUtil.getGPUs()`), return a equally sized list of ones and zeroes indicating which corresponding GPUs are available.\n\n* Inputs\n  * `GPUs` - List of `GPUs`. See `GPUtil.getGPUs()`\n  * `maxLoad` - Maximum current relative load for a GPU to be considered available. GPUs with a load larger than `maxLoad` is not returned. (**default = 0.5**)\n  * `maxMemory` - Maximum current relative memory usage for a GPU to be considered available. GPUs with a current memory usage larger than `maxMemory` is not returned. (**default = 0.5**)\n  * `includeNan` - See the description for `GPUtil.getAvailable(...)`. (**default = False**)\n  * `excludeID` - See the description for `GPUtil.getAvailable(...)`. (**default = []**)\n  * `excludeUUID` - See the description for `GPUtil.getAvailable(...)`. (**default = []**)\n* Outputs\n  * GPUavailability - binary list indicating if `GPUs` are available or not. A GPU is considered available, if the current load and memory usage is less than `maxLoad` and `maxMemory`, respectively.\n\n\nSee [demo_GPUtil.py](https:\u002F\u002Fgithub.com\u002Fanderskm\u002Fgputil\u002Fblob\u002Fmaster\u002Fdemo_GPUtil.py) for examples and more details.\n\n## Examples\n\n\n### Select first available GPU in Caffe\nIn the Deep Learning library [Caffe](http:\u002F\u002Fcaffe.berkeleyvision.org\u002F), the user can switch between using the CPU or GPU through their Python interface.\nThis is done by calling the methods `caffe.set_mode_cpu()` and `caffe.set_mode_gpu()`, respectively.\nBelow is a minimum working example for selecting the first available GPU with GPUtil to run a Caffe network.\n\n```python\n# Import caffe and GPUtil\nimport caffe\nimport GPUtil\n\n# Set CUDA_DEVICE_ORDER so the IDs assigned by CUDA match those from nvidia-smi\nos.environ[\"CUDA_DEVICE_ORDER\"] = \"PCI_BUS_ID\"\n\n# Get the first available GPU\nDEVICE_ID_LIST = GPUtil.getFirstAvailable()\nDEVICE_ID = DEVICE_ID_LIST[0] # grab first element from list\n\n# Select GPU mode\ncaffe.set_mode_gpu()\n# Select GPU id\ncaffe.set_device(DEVICE_ID)\n\n# Initialize your network here\n\n```\n\n**Note:** At the time of writing this example, the Caffe Python wrapper only supports 1 GPU, although the underlying code supports multiple GPUs.\nCalling directly Caffe from the terminal allows for using multiple GPUs.\n\n### Occupy only 1 GPU in TensorFlow\nBy default, [TensorFlow](https:\u002F\u002Fwww.tensorflow.org\u002F)  will occupy all available GPUs when using a gpu as a device (e.g. `tf.device('\\gpu:0')`).\nBy setting the environment variable `CUDA_VISIBLE_DEVICES`, the user can mask which GPUs should be visible to TensorFlow via CUDA (See [CUDA_VISIBLE_DEVICES - Masking GPUs](http:\u002F\u002Facceleware.com\u002Fblog\u002Fcudavisibledevices-masking-gpus)). Using GPUtil.py, the CUDA_VISIBLE_DEVICES can be set programmatically based on the available GPUs.\nBelow is a minimum working example of how to occupy only 1 GPU in TensorFlow using GPUtil.\nTo run the code, copy it into a new python file (e.g. `demo_tensorflow_gputil.py`) and run it (e.g. enter `python demo_tensorflow_gputil.py` in a terminal).\n\n**Note:** Even if you set the device you run your code on to a CPU, TensorFlow will occupy all available GPUs. To avoid this, all GPUs can be hidden from TensorFlow with `os.environ[\"CUDA_VISIBLE_DEVICES\"] = ''`.\n\n```python\n# Import os to set the environment variable CUDA_VISIBLE_DEVICES\nimport os\nimport tensorflow as tf\nimport GPUtil\n\n# Set CUDA_DEVICE_ORDER so the IDs assigned by CUDA match those from nvidia-smi\nos.environ[\"CUDA_DEVICE_ORDER\"] = \"PCI_BUS_ID\"\n\n# Get the first available GPU\nDEVICE_ID_LIST = GPUtil.getFirstAvailable()\nDEVICE_ID = DEVICE_ID_LIST[0] # grab first element from list\n\n# Set CUDA_VISIBLE_DEVICES to mask out all other GPUs than the first available device id\nos.environ[\"CUDA_VISIBLE_DEVICES\"] = str(DEVICE_ID)\n\n# Since all other GPUs are masked out, the first available GPU will now be identified as GPU:0\ndevice = '\u002Fgpu:0'\nprint('Device ID (unmasked): ' + str(DEVICE_ID))\nprint('Device ID (masked): ' + str(0))\n\n# Run a minimum working example on the selected GPU\n# Start a session\nwith tf.Session() as sess:\n    # Select the device\n    with tf.device(device):\n        # Declare two numbers and add them together in TensorFlow\n        a = tf.constant(12)\n        b = tf.constant(30)\n        result = sess.run(a+b)\n        print('a+b=' + str(result))\n\n```\n\nYour output should look something like the code block below. Notice how only one of the GPUs are found and created as a tensorflow device.\n\n```\nI tensorflow\u002Fstream_executor\u002Fdso_loader.cc:128] successfully opened CUDA library libcublas.so locally\nI tensorflow\u002Fstream_executor\u002Fdso_loader.cc:128] successfully opened CUDA library libcudnn.so locally\nI tensorflow\u002Fstream_executor\u002Fdso_loader.cc:128] successfully opened CUDA library libcufft.so locally\nI tensorflow\u002Fstream_executor\u002Fdso_loader.cc:128] successfully opened CUDA library libcuda.so.1 locally\nI tensorflow\u002Fstream_executor\u002Fdso_loader.cc:128] successfully opened CUDA library libcurand.so locally\nDevice: \u002Fgpu:0\nI tensorflow\u002Fcore\u002Fcommon_runtime\u002Fgpu\u002Fgpu_device.cc:885] Found device 0 with properties: \nname: TITAN X (Pascal)\nmajor: 6 minor: 1 memoryClockRate (GHz) 1.531\npciBusID 0000:02:00.0\nTotal memory: 11.90GiB\nFree memory: 11.76GiB\nI tensorflow\u002Fcore\u002Fcommon_runtime\u002Fgpu\u002Fgpu_device.cc:906] DMA: 0 \nI tensorflow\u002Fcore\u002Fcommon_runtime\u002Fgpu\u002Fgpu_device.cc:916] 0:   Y \nI tensorflow\u002Fcore\u002Fcommon_runtime\u002Fgpu\u002Fgpu_device.cc:975] Creating TensorFlow device (\u002Fgpu:0) -> (device: 0, name: TITAN X (Pascal), pci bus id: 0000:02:00.0)\na+b=42\n\n```\nComment the `os.environ[\"CUDA_VISIBLE_DEVICES\"] = str(DEVICE_ID)` line and compare the two outputs.\nDepending on your number of GPUs, your output should look something like code block below.\nNotice, how all 4 GPUs are being found and created as a tensorflow device, whereas when `CUDA_VISIBLE_DEVICES` was set, only 1 GPU was found and created.\n\n```\nI tensorflow\u002Fstream_executor\u002Fdso_loader.cc:128] successfully opened CUDA library libcublas.so locally\nI tensorflow\u002Fstream_executor\u002Fdso_loader.cc:128] successfully opened CUDA library libcudnn.so locally\nI tensorflow\u002Fstream_executor\u002Fdso_loader.cc:128] successfully opened CUDA library libcufft.so locally\nI tensorflow\u002Fstream_executor\u002Fdso_loader.cc:128] successfully opened CUDA library libcuda.so.1 locally\nI tensorflow\u002Fstream_executor\u002Fdso_loader.cc:128] successfully opened CUDA library libcurand.so locally\nDevice: \u002Fgpu:0\nI tensorflow\u002Fcore\u002Fcommon_runtime\u002Fgpu\u002Fgpu_device.cc:885] Found device 0 with properties: \nname: TITAN X (Pascal)\nmajor: 6 minor: 1 memoryClockRate (GHz) 1.531\npciBusID 0000:02:00.0\nTotal memory: 11.90GiB\nFree memory: 11.76GiB\nW tensorflow\u002Fstream_executor\u002Fcuda\u002Fcuda_driver.cc:590] creating context when one is currently active; existing: 0x2c8e400\nI tensorflow\u002Fcore\u002Fcommon_runtime\u002Fgpu\u002Fgpu_device.cc:885] Found device 1 with properties: \nname: TITAN X (Pascal)\nmajor: 6 minor: 1 memoryClockRate (GHz) 1.531\npciBusID 0000:03:00.0\nTotal memory: 11.90GiB\nFree memory: 11.76GiB\nW tensorflow\u002Fstream_executor\u002Fcuda\u002Fcuda_driver.cc:590] creating context when one is currently active; existing: 0x2c92040\nI tensorflow\u002Fcore\u002Fcommon_runtime\u002Fgpu\u002Fgpu_device.cc:885] Found device 2 with properties: \nname: TITAN X (Pascal)\nmajor: 6 minor: 1 memoryClockRate (GHz) 1.531\npciBusID 0000:83:00.0\nTotal memory: 11.90GiB\nFree memory: 11.76GiB\nW tensorflow\u002Fstream_executor\u002Fcuda\u002Fcuda_driver.cc:590] creating context when one is currently active; existing: 0x2c95d90\nI tensorflow\u002Fcore\u002Fcommon_runtime\u002Fgpu\u002Fgpu_device.cc:885] Found device 3 with properties: \nname: TITAN X (Pascal)\nmajor: 6 minor: 1 memoryClockRate (GHz) 1.531\npciBusID 0000:84:00.0\nTotal memory: 11.90GiB\nFree memory: 11.76GiB\nI tensorflow\u002Fcore\u002Fcommon_runtime\u002Fgpu\u002Fgpu_device.cc:777] Peer access not supported between device ordinals 0 and 2\nI tensorflow\u002Fcore\u002Fcommon_runtime\u002Fgpu\u002Fgpu_device.cc:777] Peer access not supported between device ordinals 0 and 3\nI tensorflow\u002Fcore\u002Fcommon_runtime\u002Fgpu\u002Fgpu_device.cc:777] Peer access not supported between device ordinals 1 and 2\nI tensorflow\u002Fcore\u002Fcommon_runtime\u002Fgpu\u002Fgpu_device.cc:777] Peer access not supported between device ordinals 1 and 3\nI tensorflow\u002Fcore\u002Fcommon_runtime\u002Fgpu\u002Fgpu_device.cc:777] Peer access not supported between device ordinals 2 and 0\nI tensorflow\u002Fcore\u002Fcommon_runtime\u002Fgpu\u002Fgpu_device.cc:777] Peer access not supported between device ordinals 2 and 1\nI tensorflow\u002Fcore\u002Fcommon_runtime\u002Fgpu\u002Fgpu_device.cc:777] Peer access not supported between device ordinals 3 and 0\nI tensorflow\u002Fcore\u002Fcommon_runtime\u002Fgpu\u002Fgpu_device.cc:777] Peer access not supported between device ordinals 3 and 1\nI tensorflow\u002Fcore\u002Fcommon_runtime\u002Fgpu\u002Fgpu_device.cc:906] DMA: 0 1 2 3 \nI tensorflow\u002Fcore\u002Fcommon_runtime\u002Fgpu\u002Fgpu_device.cc:916] 0:   Y Y N N \nI tensorflow\u002Fcore\u002Fcommon_runtime\u002Fgpu\u002Fgpu_device.cc:916] 1:   Y Y N N \nI tensorflow\u002Fcore\u002Fcommon_runtime\u002Fgpu\u002Fgpu_device.cc:916] 2:   N N Y Y \nI tensorflow\u002Fcore\u002Fcommon_runtime\u002Fgpu\u002Fgpu_device.cc:916] 3:   N N Y Y \nI tensorflow\u002Fcore\u002Fcommon_runtime\u002Fgpu\u002Fgpu_device.cc:975] Creating TensorFlow device (\u002Fgpu:0) -> (device: 0, name: TITAN X (Pascal), pci bus id: 0000:02:00.0)\nI tensorflow\u002Fcore\u002Fcommon_runtime\u002Fgpu\u002Fgpu_device.cc:975] Creating TensorFlow device (\u002Fgpu:1) -> (device: 1, name: TITAN X (Pascal), pci bus id: 0000:03:00.0)\nI tensorflow\u002Fcore\u002Fcommon_runtime\u002Fgpu\u002Fgpu_device.cc:975] Creating TensorFlow device (\u002Fgpu:2) -> (device: 2, name: TITAN X (Pascal), pci bus id: 0000:83:00.0)\nI tensorflow\u002Fcore\u002Fcommon_runtime\u002Fgpu\u002Fgpu_device.cc:975] Creating TensorFlow device (\u002Fgpu:3) -> (device: 3, name: TITAN X (Pascal), pci bus id: 0000:84:00.0)\na+b=42\n```\n\n### Monitor GPU in a separate thread\nIf using GPUtil to monitor GPUs during training, it may show 0% utilization. A way around this is to use a separate monitoring thread.\n```python\nimport GPUtil\nfrom threading import Thread, Event\nimport time\n\nclass Monitor(Thread):\n    def __init__(self, delay):\n        super(Monitor, self).__init__()\n        self.stopped = Event()\n        self.delay = delay # Time between calls to GPUtil\n        self.start()\n\n    def run(self):\n        while not self.stopped.is_set():\n            GPUtil.showUtilization()\n            time.sleep(self.delay)\n\n    def stop(self):\n        self.stopped.set()\n        \n# Instantiate monitor with a 10-second delay between updates\nmonitor = Monitor(10)\n\n# Train, etc.\n\n# Close monitor\nmonitor.stop()\n```\n\n## License\nSee [LICENSE](https:\u002F\u002Fgithub.com\u002Fanderskm\u002Fgputil\u002Fblob\u002Fmaster\u002FLICENSE.txt)\n","# GPUtil\n`GPUtil` 是一个 Python 模块，用于通过 `nvidia-smi` 获取 NVIDIA 显卡的状态。\n`GPUtil` 会查找计算机上的所有 GPU，确定它们的可用性，并返回一个按顺序排列的可用 GPU 列表。\n可用性的判断依据是每块 GPU 当前的显存使用量和负载情况。\n该模块在设计时主要考虑了深度学习中的 GPU 选择需求，但它并不局限于特定的任务或库，可以应用于任何需要识别可用 GPU 的场景。\n\n**目录**\n\n1. [要求](#requirements)\n1. [安装](#installation)\n1. [用法](#usage)\n   1. [主要函数](#main-functions)\n   1. [辅助函数](#helper-functions)\n1. [示例](#examples)\n   1. [在 Caffe 中选择第一个可用的 GPU](#select-first-available-gpu-in-caffe)\n   1. [在 TensorFlow 中只占用 1 块 GPU](#occupy-only-1-gpu-in-tensorflow)\n   1. [在单独的线程中监控 GPU](#monitor-gpu-in-a-separate-thread)\n1. [许可证](#license)\n\n## 要求\n配备最新 NVIDIA 驱动程序的 NVIDIA 显卡。\nGPUtil 使用 `nvidia-smi` 程序来获取所有可用 NVIDIA 显卡的状态。安装 NVIDIA 驱动程序时，通常会自动安装 `nvidia-smi`。\n\n支持 Python 2.X 和 3.X。\n\nPython 库：\n* subprocess（[Python 标准库](https:\u002F\u002Fdocs.python.org\u002F3\u002Flibrary\u002Fsubprocess.html)）\n* distutils（[Python 标准库](https:\u002F\u002Fdocs.python.org\u002F3\u002Flibrary\u002Fdistutils.html)）\n* math（[Python 标准库](https:\u002F\u002Fdocs.python.org\u002F3\u002Flibrary\u002Fmath.html)）\n* random（[Python 标准库](https:\u002F\u002Fdocs.python.org\u002F3\u002Flibrary\u002Frandom.html)）\n* time（[Python 标准库](https:\u002F\u002Fdocs.python.org\u002F3\u002Flibrary\u002Ftime.html)）\n* os（[Python 标准库](https:\u002F\u002Fdocs.python.org\u002F3\u002Flibrary\u002Fos.html)）\n* sys（[Python 标准库](https:\u002F\u002Fdocs.python.org\u002F3\u002Flibrary\u002Fsys.html)）\n* platform（[Python 标准库](https:\u002F\u002Fdocs.python.org\u002F3\u002Flibrary\u002Fplatform.html)）\n\n已在 CUDA 驱动版本 390.77、Python 2.7 和 3.5 上进行测试。\n\n## 安装\n\n1. 打开终端（Ctrl+Shift+T）\n2. 输入 `pip install gputil`\n3. 测试安装\n   1. 在 GPUtil 文件夹之外的其他文件夹中打开终端\n   2. 在终端中输入 `python` 启动 Python 控制台\n   3. 在新打开的 Python 控制台中输入：\n      ```python\n      import GPUtil\n      GPUtil.showUtilization()\n      ```\n   4. 输出应类似于以下内容，具体取决于您的 GPU 数量及其当前使用情况：\n      ```\n       ID  GPU  MEM\n      --------------\n        0    0%   0%\n      ```\n\n### 旧版安装方法\n\n1. 下载或克隆仓库到您的计算机\n2. 将 GPUtil 文件夹添加到 `~\u002F.bashrc`\n   1. 打开一个新的终端（按 Ctrl+Alt+T）\n   2. 打开 `bashrc`：\n      ```\n      gedit ~\u002F.bashrc\n      ```\n   3. 将您的 GPUtil 文件夹添加到环境变量 `PYTHONPATH` 中（将 `\u003Cpath_to_gputil>` 替换为您文件夹的实际路径）：\n      ```\n      export PYTHONPATH=\"$PYTHONPATH:\u003Cpath_to_gputil>\"\n\n      示例：\n      export PYTHONPATH=\"$PYTHONPATH:\u002Fhome\u002Fanderskm\u002Fgithub\u002Fgputil\"\n      ```\n   4. 保存 `~\u002F.bashrc` 并关闭 `gedit`\n   5. 重启终端\n1. 测试安装\n   1. 在 GPUtil 文件夹之外的其他文件夹中打开终端\n   2. 在终端中输入 `python` 启动 Python 控制台\n   3. 在新打开的 Python 控制台中输入：\n      ```python\n      import GPUtil\n      GPUtil.showUtilization()\n      ```\n   4. 输出应类似于以下内容，具体取决于您的 GPU 数量及其当前使用情况：\n      ```\n       ID  GPU  MEM\n      --------------\n        0    0%   0%\n      ```\n\n## 用法\n\n要在您的 Python 代码中使用 `GPUtil`，只需在脚本开头导入即可：\n\n```python\nimport GPUtil\n```\n\n导入后，所有函数即可使用。各函数及其简要说明（包括输入、输出和功能）可在以下两个部分中找到。\n\n### 主要功能\n\n```python\ndeviceIDs = GPUtil.getAvailable(order = 'first', limit = 1, maxLoad = 0.5, maxMemory = 0.5, includeNan=False, excludeID=[], excludeUUID=[])\n```\n返回可用GPU的ID列表。可用性根据当前的显存使用率和负载来判断。返回的顺序、设备的最大数量、最大负载以及最大显存占用均由输入参数决定。\n\n* 输入\n  * `order` - 决定返回可用GPU设备ID的顺序。`order`应指定为以下字符串之一：\n    * `'first'` - 按照GPU ID升序排列（**默认**）\n    * `'last'` - 按照GPU ID降序排列\n    * `'random'` - 随机排列可用GPU设备ID\n    * `'load'` - 按照GPU负载升序排列\n    * `'memory'` - 按照GPU显存使用率升序排列\n  * `limit` - 限制返回的GPU设备ID数量为指定值。必须是正整数。（**默认 = 1**）\n  * `maxLoad` - GPU被认为可用时允许的最大相对负载。负载大于`maxLoad`的GPU不会被返回。（**默认 = 0.5**）\n  * `maxMemory` - GPU被认为可用时允许的最大相对显存使用率。显存使用率大于`maxMemory`的GPU不会被返回。（**默认 = 0.5**）\n  * `includeNan` - 布尔标志，指示是否包含负载或显存使用率为NaN的GPU（表示无法获取使用情况）。（**默认 = False**）\n  * `excludeID` - 需要从可用GPU列表中排除的ID列表。参见`GPU`类的描述。（**默认 = []**）\n  * `excludeUUID` - 与`excludeID`相同，但使用UUID进行排除。（**默认 = []**）\n* 输出\n  * deviceIDs - 所有可用GPU设备ID的列表。如果GPU的当前负载和显存使用率分别低于`maxLoad`和`maxMemory`，则该GPU被视为可用。列表的排序方式由`order`决定。返回的设备ID数量最多不超过`limit`。\n\n```python\ndeviceID = GPUtil.getFirstAvailable(order = 'first', maxLoad=0.5, maxMemory=0.5, attempts=1, interval=900, verbose=False)\n```\n返回第一个可用的GPU。可用性根据当前的显存使用率和负载来判断，排序方式由指定的顺序决定。\n如果未找到可用GPU，则会抛出错误。\n使用默认值时，其效果等同于`getAvailable(order = 'first', limit = 1, maxLoad = 0.5, maxMemory = 0.5)`。\n\n* 输入\n  * `order` - 参见`GPUtil.getAvailable(...)`的描述\n  * `maxLoad` - GPU被认为可用时允许的最大相对负载。负载大于`maxLoad`的GPU不会被返回。（**默认 = 0.5**）\n  * `maxMemory` - GPU被认为可用时允许的最大相对显存使用率。显存使用率大于`maxMemory`的GPU不会被返回。（**默认 = 0.5**）\n  * `attempts` - 函数在放弃寻找可用GPU之前应尝试的次数。（**默认 = 1**）\n  * `interval` - 每次尝试寻找可用GPU之间的时间间隔，单位为秒。（**默认 = 900** --> 15分钟）\n  * `verbose` - 如果为`True`，则会在每次尝试前打印尝试次数，并在找到可用GPU时打印其ID。\n  * `includeNan` - 参见`GPUtil.getAvailable(...)`的描述。（**默认 = False**）\n  * `excludeID` - 参见`GPUtil.getAvailable(...)`的描述。（**默认 = []**）\n  * `excludeUUID` - 参见`GPUtil.getAvailable(...)`的描述。（**默认 = []**）\n* 输出\n  * deviceID - 包含第一个可用GPU设备ID的单元素列表。如果GPU的当前负载和显存使用率分别低于`maxLoad`和`maxMemory`，则该GPU被视为可用。排序方式固定为`'first'`，返回数量固定为1。\n\n\n```python\nGPUtil.showUtilization(all=False, attrList=None, useOldCode=False)\n```\n打印所有GPU的当前状态（ID、显存使用率、UUID、负载）。\n* 输入\n  * `all` - 布尔标志，指示是否显示所有GPU的信息。此参数会覆盖`attrList`。\n  * `attrList` - 需要显示的`GPU`属性列表。更多信息和示例请参见代码。\n  * `useOldCode` - 布尔标志，指示是否使用旧代码来显示GPU利用率。\n* 输出\n  * _无_\n\n### 辅助函数\n```python\n class GPU\n```\n辅助类用于处理每个GPU的属性。引用的描述直接摘自`nvidia-smi`的相关说明。\n* 每个`GPU`的属性\n  * `id` - “GPU的零索引编号。每次启动时可能会发生变化。”\n  * `uuid` - “该值是GPU的全局唯一且不可变的字母数字标识符。它不对应于显卡上的任何物理标签，并且在重启后也不会改变。”\n  * `load` - GPU相对负载，范围为0到1（100%，满负载）。“在过去采样周期内，GPU上有一个或多个内核正在执行的时间百分比。采样周期可能根据产品不同介于1秒到1\u002F6秒之间。”\n  * `memoryUtil` - 相对显存使用率，范围为0到1（100%，满使用）。“在过去采样周期内，全局（设备）内存被读取或写入的时间百分比。采样周期可能根据产品不同介于1秒到1\u002F6秒之间。”\n  * `memoryTotal` - “已安装的GPU总显存容量。”\n  * `memoryUsed` - “由当前活动上下文分配的GPU总显存用量。”\n  * `memoryFree` - “可用的GPU总显存量。”\n  * `driver` - “已安装的NVIDIA显卡驱动程序版本。”\n  * `name` - “GPU的官方产品名称。”\n  * `serial` - 该序列号与每块显卡上物理打印的序列号一致，是一个全局唯一且不可变的字母数字值。\n  * `display_mode` - “一个标志位，指示当前是否有物理显示器（如显示器）连接到GPU的任一接口。‘启用’表示已连接显示器；‘禁用’则表示未连接。”\n  * `display_active` - “一个标志位，指示GPU上是否已初始化显示功能（例如，设备上已为显示分配内存）。即使没有物理显示器连接，显示也可能处于激活状态。‘启用’表示显示已激活；‘禁用’则表示未激活。”\n\n```python\nGPUs = GPUtil.getGPUs()\n```\n* 输入\n  * _无_\n* 输出\n  * `GPUs` - 所有GPU的列表。每个`GPU`对应计算机中的一块GPU，包含设备ID、相对负载和相对显存使用率。\n\n```python\nGPUavailability = GPUtil.getAvailability(GPUs, maxLoad = 0.5, maxMemory = 0.5, includeNan=False, excludeID=[], excludeUUID=[])\n```\n给定一个`GPUs`列表（参见`GPUtil.getGPUs()`），返回一个等长的由1和0组成的列表，指示对应的GPU是否可用。\n\n* 输入\n  * `GPUs` - `GPUs`列表。参见`GPUtil.getGPUs()`\n  * `maxLoad` - 被视为可用的GPU的最大当前相对负载。负载大于`maxLoad`的GPU将不会被返回。（**默认值：0.5**）\n  * `maxMemory` - 被视为可用的GPU的最大当前相对显存使用量。显存使用量大于`maxMemory`的GPU将不会被返回。（**默认值：0.5**）\n  * `includeNan` - 参见`GPUtil.getAvailable(...)`的说明。（**默认值：False**）\n  * `excludeID` - 参见`GPUtil.getAvailable(...)`的说明。（**默认值：[]**）\n  * `excludeUUID` - 参见`GPUtil.getAvailable(...)`的说明。（**默认值：[]**）\n* 输出\n  * GPUavailability - 二进制列表，指示`GPUs`是否可用。如果当前负载和显存使用量分别低于`maxLoad`和`maxMemory`，则认为该GPU可用。\n\n\n更多示例和详细信息，请参阅[demo_GPUtil.py](https:\u002F\u002Fgithub.com\u002Fanderskm\u002Fgputil\u002Fblob\u002Fmaster\u002Fdemo_GPUtil.py)。\n\n## 示例\n\n\n### 在Caffe中选择第一个可用的GPU\n在深度学习库[Caffe](http:\u002F\u002Fcaffe.berkeleyvision.org\u002F)中，用户可以通过其Python接口在CPU和GPU之间切换。\n这可以通过调用`caffe.set_mode_cpu()`和`caffe.set_mode_gpu()`方法来实现。\n以下是使用GPUtil选择第一个可用的GPU运行Caffe网络的最小可运行示例。\n\n```python\n# 导入caffe和GPUtil\nimport caffe\nimport GPUtil\n\n# 设置CUDA_DEVICE_ORDER，使CUDA分配的ID与nvidia-smi中的ID一致\nos.environ[\"CUDA_DEVICE_ORDER\"] = \"PCI_BUS_ID\"\n\n# 获取第一个可用的GPU\nDEVICE_ID_LIST = GPUtil.getFirstAvailable()\nDEVICE_ID = DEVICE_ID_LIST[0] # 取列表中的第一个元素\n\n# 选择GPU模式\ncaffe.set_mode_gpu()\n# 选择GPU编号\ncaffe.set_device(DEVICE_ID)\n\n# 在此处初始化您的网络\n\n```\n\n**注意：** 截至本文编写时，Caffe的Python封装仅支持1个GPU，尽管底层代码支持多GPU。而通过终端直接调用Caffe，则可以使用多个GPU。\n\n### 在TensorFlow中只占用1个GPU\n默认情况下，[TensorFlow](https:\u002F\u002Fwww.tensorflow.org\u002F)在使用GPU作为设备时（例如`tf.device('\\gpu:0')`），会占用所有可用的GPU。\n通过设置环境变量`CUDA_VISIBLE_DEVICES`，用户可以屏蔽哪些GPU对TensorFlow可见（参见[CUDA_VISIBLE_DEVICES - 屏蔽GPU](http:\u002F\u002Facceleware.com\u002Fblog\u002Fcudavisibledevices-masking-gpus)）。利用GPUtil.py，可以根据可用的GPU以编程方式设置`CUDA_VISIBLE_DEVICES`。\n以下是使用GPUtil在TensorFlow中只占用1个GPU的最小可运行示例。\n要运行此代码，将其复制到一个新的Python文件中（例如`demo_tensorflow_gputil.py`），然后在终端中运行（例如输入`python demo_tensorflow_gputil.py`）。\n\n**注意：** 即使您将代码运行的设备设置为CPU，TensorFlow仍会占用所有可用的GPU。为了避免这种情况，您可以将所有GPU从TensorFlow中隐藏，方法是设置`os.environ[\"CUDA_VISIBLE_DEVICES\"] = ''`。\n\n```python\n# 导入os以设置环境变量CUDA_VISIBLE_DEVICES\nimport os\nimport tensorflow as tf\nimport GPUtil\n\n# 设置CUDA_DEVICE_ORDER，使CUDA分配的ID与nvidia-smi中的ID一致\nos.environ[\"CUDA_DEVICE_ORDER\"] = \"PCI_BUS_ID\"\n\n# 获取第一个可用的GPU\nDEVICE_ID_LIST = GPUtil.getFirstAvailable()\nDEVICE_ID = DEVICE_ID_LIST[0] # 取列表中的第一个元素\n\n# 设置CUDA_VISIBLE_DEVICES，屏蔽除第一个可用设备ID之外的所有其他GPU\nos.environ[\"CUDA_VISIBLE_DEVICES\"] = str(DEVICE_ID)\n\n# 由于其他所有GPU已被屏蔽，第一个可用的GPU现在将被识别为GPU:0\ndevice = '\u002Fgpu:0'\nprint('设备ID（未屏蔽）：' + str(DEVICE_ID))\nprint('设备ID（屏蔽后）：' + str(0))\n\n# 在选定的GPU上运行一个最小可运行示例\n\n# 开始会话\nwith tf.Session() as sess:\n    # 选择设备\n    with tf.device(device):\n        # 声明两个数字并在 TensorFlow 中将它们相加\n        a = tf.constant(12)\n        b = tf.constant(30)\n        result = sess.run(a+b)\n        print('a+b=' + str(result))\n\n```\n\n您的输出应该类似于下面的代码块。请注意，只有一块 GPU 被识别并作为 TensorFlow 设备创建。\n\n```\nI tensorflow\u002Fstream_executor\u002Fdso_loader.cc:128] 成功在本地打开 CUDA 库 libcublas.so\nI tensorflow\u002Fstream_executor\u002Fdso_loader.cc:128] 成功在本地打开 CUDA 库 libcudnn.so\nI tensorflow\u002Fstream_executor\u002Fdso_loader.cc:128] 成功在本地打开 CUDA 库 libcufft.so\nI tensorflow\u002Fstream_executor\u002Fdso_loader.cc:128] 成功在本地打开 CUDA 库 libcuda.so.1\nI tensorflow\u002Fstream_executor\u002Fdso_loader.cc:128] 成功在本地打开 CUDA 库 libcurand.so\n设备：\u002Fgpu:0\nI tensorflow\u002Fcore\u002Fcommon_runtime\u002Fgpu\u002Fgpu_device.cc:885] 找到设备 0，其属性如下：\n名称：TITAN X (Pascal)\n主要版本：6 次要版本：1 内存时钟频率 (GHz) 1.531\nPCI 总线 ID 0000:02:00.0\n总内存：11.90GiB\n空闲内存：11.76GiB\nI tensorflow\u002Fcore\u002Fcommon_runtime\u002Fgpu\u002Fgpu_device.cc:906] DMA：0 \nI tensorflow\u002Fcore\u002Fcommon_runtime\u002Fgpu\u002Fgpu_device.cc:916] 0：   Y \nI tensorflow\u002Fcore\u002Fcommon_runtime\u002Fgpu\u002Fgpu_device.cc:975] 创建 TensorFlow 设备 (\u002Fgpu:0) -> (设备：0，名称：TITAN X (Pascal)，PCI 总线 ID：0000:02:00.0)\na+b=42\n\n```\n注释掉 `os.environ[\"CUDA_VISIBLE_DEVICES\"] = str(DEVICE_ID)` 这一行，并比较两种输出。\n根据您拥有的 GPU 数量，您的输出应类似于下面的代码块。\n请注意，当未设置 `CUDA_VISIBLE_DEVICES` 时，所有 4 块 GPU 都被识别并作为 TensorFlow 设备创建；而当设置了 `CUDA_VISIBLE_DEVICES` 时，仅有一块 GPU 被识别和创建。\n\n```\nI tensorflow\u002Fstream_executor\u002Fdso_loader.cc:128] 成功在本地打开 CUDA 库 libcublas.so\nI tensorflow\u002Fstream_executor\u002Fdso_loader.cc:128] 成功在本地打开 CUDA 库 libcudnn.so\nI tensorflow\u002Fstream_executor\u002Fdso_loader.cc:128] 成功在本地打开 CUDA 库 libcufft.so\nI tensorflow\u002Fstream_executor\u002Fdso_loader.cc:128] 成功在本地打开 CUDA 库 libcuda.so.1\nI tensorflow\u002Fstream_executor\u002Fdso_loader.cc:128] 成功在本地打开 CUDA 库 libcurand.so\n设备：\u002Fgpu:0\nI tensorflow\u002Fcore\u002Fcommon_runtime\u002Fgpu\u002Fgpu_device.cc:885] 找到设备 0，其属性如下：\n名称：TITAN X (Pascal)\n主要版本：6 次要版本：1 内存时钟频率 (GHz) 1.531\nPCI 总线 ID 0000:02:00.0\n总内存：11.90GiB\n空闲内存：11.76GiB\nW tensorflow\u002Fstream_executor\u002Fcuda\u002Fcuda_driver.cc:590] 在当前已有上下文的情况下创建新上下文；现有上下文：0x2c8e400\nI tensorflow\u002Fcore\u002Fcommon_runtime\u002Fgpu\u002Fgpu_device.cc:885] 找到设备 1，其属性如下：\n名称：TITAN X (Pascal)\n主要版本：6 次要版本：1 内存时钟频率 (GHz) 1.531\nPCI 总线 ID 0000:03:00.0\n总内存：11.90GiB\n空闲内存：11.76GiB\nW tensorflow\u002Fstream_executor\u002Fcuda\u002Fcuda_driver.cc:590] 在当前已有上下文的情况下创建新上下文；现有上下文：0x2c92040\nI tensorflow\u002Fcore\u002Fcommon_runtime\u002Fgpu\u002Fgpu_device.cc:885] 找到设备 2，其属性如下：\n名称：TITAN X (Pascal)\n主要版本：6 次要版本：1 内存时钟频率 (GHz) 1.531\nPCI 总线 ID 0000:83:00.0\n总内存：11.90GiB\n空闲内存：11.76GiB\nW tensorflow\u002Fstream_executor\u002Fcuda\u002Fcuda_driver.cc:590] 在当前已有上下文的情况下创建新上下文；现有上下文：0x2c95d90\nI tensorflow\u002Fcore\u002Fcommon_runtime\u002Fgpu\u002Fgpu_device.cc:885] 找到设备 3，其属性如下：\n名称：TITAN X (Pascal)\n主要版本：6 次要版本：1 内存时钟频率 (GHz) 1.531\nPCI 总线 ID 0000:84:00.0\n总内存：11.90GiB\n空闲内存：11.76GiB\nI tensorflow\u002Fcore\u002Fcommon_runtime\u002Fgpu\u002Fgpu_device.cc:777] 设备序号 0 和 2 之间不支持对等访问\nI tensorflow\u002Fcore\u002Fcommon_runtime\u002Fgpu\u002Fgpu_device.cc:777] 设备序号 0 和 3 之间不支持对等访问\nI tensorflow\u002Fcore\u002Fcommon_runtime\u002Fgpu\u002Fgpu_device.cc:777] 设备序号 1 和 2 之间不支持对等访问\nI tensorflow\u002Fcore\u002Fcommon_runtime\u002Fgpu\u002Fgpu_device.cc:777] 设备序号 1 和 3 之间不支持对等访问\nI tensorflow\u002Fcore\u002Fcommon_runtime\u002Fgpu\u002Fgpu_device.cc:777] 设备序号 2 和 0 之间不支持对等访问\nI tensorflow\u002Fcore\u002Fcommon_runtime\u002Fgpu\u002Fgpu_device.cc:777] 设备序号 2 和 1 之间不支持对等访问\nI tensorflow\u002Fcore\u002Fcommon_runtime\u002Fgpu\u002Fgpu_device.cc:777] 设备序号 3 和 0 之间不支持对等访问\nI tensorflow\u002Fcore\u002Fcommon_runtime\u002Fgpu\u002Fgpu_device.cc:777] 设备序号 3 和 1 之间不支持对等访问\nI tensorflow\u002Fcore\u002Fcommon_runtime\u002Fgpu\u002Fgpu_device.cc:906] DMA：0 1 2 3 \nI tensorflow\u002Fcore\u002Fcommon_runtime\u002Fgpu\u002Fgpu_device.cc:916] 0：   Y Y N N \nI tensorflow\u002Fcore\u002Fcommon_runtime\u002Fgpu\u002Fgpu_device.cc:916] 1：   Y Y N N \nI tensorflow\u002Fcore\u002Fcommon_runtime\u002Fgpu\u002Fgpu_device.cc:916] 2：   N N Y Y \nI tensorflow\u002Fcore\u002Fcommon_runtime\u002Fgpu\u002Fgpu_device.cc:916] 3：   N N Y Y \nI tensorflow\u002Fcore\u002Fcommon_runtime\u002Fgpu\u002Fgpu_device.cc:975] 创建 TensorFlow 设备 (\u002Fgpu:0) -> (设备：0，名称：TITAN X (Pascal)，PCI 总线 ID：0000:02:00.0)\nI tensorflow\u002Fcore\u002Fcommon_runtime\u002Fgpu\u002Fgpu_device.cc:975] 创建 TensorFlow 设备 (\u002Fgpu:1) -> (设备：1，名称：TITAN X (Pascal)，PCI 总线 ID：0000:03:00.0)\nI tensorflow\u002Fcore\u002Fcommon_runtime\u002Fgpu\u002Fgpu_device.cc:975] 创建 TensorFlow 设备 (\u002Fgpu:2) -> (设备：2，名称：TITAN X (Pascal)，PCI 总线 ID：0000:83:00.0)\nI tensorflow\u002Fcore\u002Fcommon_runtime\u002Fgpu\u002Fgpu_device.cc:975] 创建 TensorFlow 设备 (\u002Fgpu:3) -> (设备：3，名称：TITAN X (Pascal)，PCI 总线 ID：0000:84:00.0)\na+b=42\n```\n\n### 在单独的线程中监控 GPU\n如果在训练过程中使用 GPUtil 监控 GPU，可能会显示 0% 的利用率。解决方法是使用一个单独的监控线程。\n```python\nimport GPUtil\nfrom threading import Thread, Event\nimport time\n\nclass Monitor(Thread):\n    def __init__(self, delay):\n        super(Monitor, self).__init__()\n        self.stopped = Event()\n        self.delay = delay # 调用 GPUtil 的时间间隔\n        self.start()\n\n    def run(self):\n        while not self.stopped.is_set():\n            GPUtil.showUtilization()\n            time.sleep(self.delay)\n\n    def stop(self):\n        self.stopped.set()\n        \n# 实例化监控器，每次更新间隔 10 秒\nmonitor = Monitor(10)\n\n# 训练等操作\n\n# 关闭监控器\nmonitor.stop()\n```\n\n## 许可证\n请参阅 [LICENSE](https:\u002F\u002Fgithub.com\u002Fanderskm\u002Fgputil\u002Fblob\u002Fmaster\u002FLICENSE.txt)","# GPUtil 快速上手指南\n\nGPUtil 是一个用于获取 NVIDIA GPU 状态的 Python 模块。它通过调用 `nvidia-smi` 来定位所有 GPU，并根据当前的显存占用和负载情况，返回可用 GPU 的有序列表。该工具特别适用于深度学习任务中的 GPU 自动选择。\n\n## 环境准备\n\n在使用 GPUtil 之前，请确保满足以下系统要求：\n\n*   **硬件**：必须拥有 NVIDIA GPU。\n*   **驱动**：已安装最新的 NVIDIA 驱动程序（`nvidia-smi` 命令需可用）。\n*   **Python 版本**：支持 Python 2.x 和 3.x。\n*   **依赖库**：仅需 Python 标准库（如 `subprocess`, `os`, `sys` 等），无需额外安装第三方依赖。\n\n## 安装步骤\n\n推荐使用 pip 进行安装。国内开发者建议使用清华或阿里镜像源以加速下载。\n\n### 方法一：使用 pip 安装（推荐）\n\n在终端中执行以下命令：\n\n```bash\n# 使用默认源\npip install gputil\n\n# 或使用国内镜像源（推荐）\npip install gputil -i https:\u002F\u002Fpypi.tuna.tsinghua.edu.cn\u002Fsimple\n```\n\n### 方法二：验证安装\n\n安装完成后，打开终端进入任意非项目目录，启动 Python 控制台并运行以下代码进行测试：\n\n```python\nimport GPUtil\nGPUtil.showUtilization()\n```\n\n如果安装成功，你将看到类似以下的输出（显示 GPU ID、负载和显存占用）：\n\n```text\n ID  GPU  MEM\n--------------\n  0    0%   0%\n```\n\n## 基本使用\n\n在 Python 脚本中引入模块后，即可调用相关函数。最常用的功能是获取当前可用的 GPU ID。\n\n### 1. 获取第一个可用 GPU\n\n这是最简单的用法，返回负载和显存占用均低于默认阈值（50%）的第一个 GPU ID。\n\n```python\nimport GPUtil\n\n# 获取第一个可用 GPU 的 ID\ndeviceID = GPUtil.getFirstAvailable()\n\nprint(f\"选中的 GPU ID: {deviceID}\")\n```\n\n### 2. 自定义筛选条件\n\n你可以根据负载 (`maxLoad`) 和显存 (`maxMemory`) 阈值，以及排序方式 (`order`) 来获取可用 GPU 列表。\n\n```python\nimport GPUtil\n\n# 获取所有负载 \u003C 0.5 且显存占用 \u003C 0.5 的 GPU\n# order='load' 表示按负载从低到高排序\n# limit=2 表示最多返回 2 个结果\navailable_gpus = GPUtil.getAvailable(\n    order='load', \n    limit=2, \n    maxLoad=0.5, \n    maxMemory=0.5\n)\n\nprint(f\"可用 GPU 列表: {available_gpus}\")\n```\n\n### 3. 查看 GPU 详细状态\n\n打印当前所有 GPU 的详细使用情况。\n\n```python\nimport GPUtil\n\n# 打印所有 GPU 的状态\nGPUtil.showUtilization()\n```\n\n### 4. 在深度学习框架中使用示例\n\n获取可用 GPU 后，通常将其设置为环境变量，以便 TensorFlow 或 PyTorch 使用。\n\n```python\nimport os\nimport GPUtil\n\n# 获取第一个可用 GPU\nfirst_gpu = GPUtil.getFirstAvailable()\n\n# 设置环境变量，限制程序只使用该 GPU\nos.environ[\"CUDA_VISIBLE_DEVICES\"] = str(first_gpu)\n\n# 接下来导入 tensorflow 或 torch 即可自动绑定到指定 GPU\n# import tensorflow as tf \n```","某深度学习团队在拥有多张 NVIDIA GPU 的服务器上并行训练多个模型时，常因资源分配不均导致任务失败或效率低下。\n\n### 没有 gputil 时\n- 开发人员只能手动运行 `nvidia-smi` 命令查看显卡状态，无法在 Python 脚本中自动获取实时负载数据。\n- 多任务并发时，不同脚本往往盲目抢占同一张空闲显卡，导致显存溢出（OOM）而中断训练。\n- 缺乏智能调度机制，高负载的 GPU 仍在接收新任务，而空闲 GPU 却被闲置，集群整体利用率极低。\n- 每次提交任务前需人工确认哪张卡可用，繁琐且容易出错，严重拖慢实验迭代速度。\n\n### 使用 gputil 后\n- 脚本通过 `GPUtil.getAvailable()` 自动检测并返回按负载排序的可用 GPU ID 列表，实现程序化资源感知。\n- 训练代码可动态绑定到显存占用最低的设备上，彻底避免因显存不足导致的崩溃，提升任务稳定性。\n- 基于实时负载的智能分配策略让所有 GPU 负载均衡，最大化硬件集群的吞吐量和计算效率。\n- 无需人工干预，自动化流程将任务准备时间从分钟级缩短至秒级，显著加速模型研发周期。\n\ngputil 通过将显卡监控能力嵌入代码逻辑，实现了深度学习任务的智能化、自动化资源调度。","https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fanderskm_gputil_911569c9.png","anderskm","Anders Krogh Mortensen","https:\u002F\u002Foss.gittoolsai.com\u002Favatars\u002Fanderskm_dc92967b.jpg","Freelance Computer Vision engineer","The AI Lab",null,"theailab.dk","https:\u002F\u002Fgithub.com\u002Fanderskm",[82],{"name":83,"color":84,"percentage":85},"Python","#3572A5",100,1211,130,"2026-04-14T16:42:32","MIT","未说明 (基于 nvidia-smi，通常支持 Linux 和 Windows)","必需 NVIDIA GPU 且安装最新驱动 (依赖 nvidia-smi)，无特定型号或显存大小限制","未说明",{"notes":94,"python":95,"dependencies":96},"该工具通过调用系统命令 'nvidia-smi' 获取 GPU 状态，因此必须预先安装 NVIDIA 显卡驱动。它仅依赖 Python 标准库，无需安装额外的第三方包。主要用于深度学习任务中的 GPU 选择，可根据负载和显存使用情况筛选可用 GPU。","2.x 或 3.x (测试版本为 2.7 和 3.5)",[97,98,99,100,101,102,103,104],"subprocess (标准库)","distutils (标准库)","math (标准库)","random (标准库)","time (标准库)","os (标准库)","sys (标准库)","platform (标准库)",[14],"2026-03-27T02:49:30.150509","2026-04-18T09:20:16.649071",[109,114,119,124,129,133],{"id":110,"question_zh":111,"answer_zh":112,"source_url":113},39249,"为什么 showUtilization() 显示的 GPU 利用率为 0%，而 nvidia-smi 显示为 100%？","这通常是因为调用时机或监控线程未正确启动。如果您希望在训练过程中记录利用率，应启动一个监控线程，在开始评估测试数据时启动该线程，结束后停止。这样可以在终端打印利用率。如果要将利用率存储到 TensorFlow summary 中，需要从监控线程中获取数据。由于主线程只读取数据，可以使用全局变量来实现（参考相关 StackOverflow 方案）。","https:\u002F\u002Fgithub.com\u002Fanderskm\u002Fgputil\u002Fissues\u002F11",{"id":115,"question_zh":116,"answer_zh":117,"source_url":118},39250,"遇到 'Values of [Not Supported] are not handled properly' 错误导致 ValueError 怎么办？","该问题已在后续版本中修复。维护者推送了新版本（commit f1aa347），改进了对 '[Not Supported]' 值的处理逻辑。解决方案使用了 list.sort() 的 key 选项以兼容 Python 2 和 3，例如：`GPUs.sort(key=lambda x: np.Inf if np.isnan(x.id) else x.id, reverse=False)`。请确保升级到最新版本以解决此问题。","https:\u002F\u002Fgithub.com\u002Fanderskm\u002Fgputil\u002Fissues\u002F2",{"id":120,"question_zh":121,"answer_zh":122,"source_url":123},39251,"在 Windows 10 + Python 3.6 环境下运行时报错 'NameError: name 'unicode' is not defined' 如何解决？","这是旧版本兼容性问题。维护者已发布 v1.4.0 版本修复了该错误。请执行以下命令更新：\n1. `pip uninstall GPUtil`\n2. `pip install GPUtil`\n如果问题仍然存在，请尝试完全卸载后重新安装。","https:\u002F\u002Fgithub.com\u002Fanderskm\u002Fgputil\u002Fissues\u002F10",{"id":125,"question_zh":126,"answer_zh":127,"source_url":128},39252,"为什么使用 GPUtil 时的 CPU 占用率远高于直接使用 pynvml？","早期版本的 GPUtil 依赖 numpy 库，导致额外的 CPU 开销。维护者已提交修复（commit e81a38c），移除了对 numpy 的导入，从而显著降低了 CPU 使用率。请升级到包含此修复的最新版本，以获得与 pynvml 相近的性能表现。","https:\u002F\u002Fgithub.com\u002Fanderskm\u002Fgputil\u002Fissues\u002F14",{"id":130,"question_zh":131,"answer_zh":132,"source_url":118},39253,"如何在 Python 2 和 Python 3 之间保持排序功能的兼容性？","由于 Python 3 移除了 cmp 参数，建议使用 sort() 函数的 key 选项来替代自定义比较函数。例如，处理可能包含 NaN 值的 ID 排序时，可使用：`GPUs.sort(key=lambda x: np.Inf if np.isnan(x.id) else x.id, reverse=False)`。这种方法在 Py2 和 Py3 环境中均能正常工作。",{"id":134,"question_zh":135,"answer_zh":136,"source_url":123},39254,"pip 安装的版本似乎没有包含最新的修复代码怎么办？","如果通过 pip 安装后问题依旧，可能是因为本地缓存了旧版本或未正确更新。请严格执行以下步骤：\n1. 运行 `pip uninstall GPUtil` 完全卸载当前版本。\n2. 运行 `pip install GPUtil` 重新安装。\n这将确保您从 PyPI 获取包含最新修复（如 v1.4.0）的版本。",[138,143,148,153,158,163,168,173],{"id":139,"version":140,"summary_zh":141,"released_at":142},315196,"v1.4.0","**新增**\n- 添加了在 Windows 上自动检测 nvidia-smi 的功能\n- 添加了 GPU 温度显示\n- 添加了从独立线程监控 GPU 使用率的示例\n\n**移除**\n- 移除了对 NumPy 的依赖\n\n**修复**\n- 修复了当 nvidia-smi 返回 GPU 列表时程序崩溃的问题\n- 修复了调用 nvidia-smi 时可能出现的死锁问题\n- 修复了 Python 2.x 中的 Unicode 问题\n- 修复了 README 中的各种拼写错误\n","2018-12-18T08:58:49",{"id":144,"version":145,"summary_zh":146,"released_at":147},315197,"v1.3.0","* 增加了对 GPU 字段（如显存和负载）的支持，这些字段之前在 GPU 中并不受支持。\n* 为 GPU 添加了 UUID。\n* 增加了根据 ID 或 UUID 排除 GPU 的功能。\n* 添加了 \\_\\_version\\_\\_。\n* 将代码的主要部分从 \\_\\_init\\_\\_.py 移动到 GPUtil.py。\n* 更新了 showUtilization() 函数，使其更加灵活。\n* 更新了 README。","2018-04-09T09:08:11",{"id":149,"version":150,"summary_zh":151,"released_at":152},315198,"v1.2.3","在计算 GPU 内存利用率——用于判断 GPU 是否可用——的过程中，修复了一个虽小但非常重要的 bug。该 bug 导致在 Python 2.x 中，内存利用率始终显示为 0%。而在 Python 3.x 中不存在此问题，因为 Python 3.x 会自动将两个整数相除的结果转换为浮点数。","2017-02-09T13:12:32",{"id":154,"version":155,"summary_zh":156,"released_at":157},315199,"v1.2.2","Python 2 现在已支持！\n","2017-02-09T13:09:40",{"id":159,"version":160,"summary_zh":161,"released_at":162},315200,"v1.2.0","该项目已更名为 GPUtil，以避免与 GitHub 上这个名称略相似的 GPUstats Python 脚本混淆。\n此外，该项目也已准备好发布到 PyPI，因此可以通过 `pip install` 命令轻松安装和升级。","2017-02-09T13:08:44",{"id":164,"version":165,"summary_zh":166,"released_at":167},315201,"v1.1.0","GPUstats\n- 为 `getFirstAvailable(...)` 添加了新功能，支持多次尝试查找可用的 GPU。\n  - 新增 4 个输入参数：\n    - order：指定 GPU 的排序方式，功能与 `getAvailable(...)` 相同。\n    - attempts：查找可用 GPU 的尝试次数。\n    - interval：每次尝试之间的间隔时间（秒）。\n    - verbose：是否打印尝试计数。","2017-02-01T12:54:42",{"id":169,"version":170,"summary_zh":171,"released_at":172},315202,"v1.0.1","GPUstats\n- 使用与[初始版本 v1.0.0](https:\u002F\u002Fgithub.com\u002Fanderskm\u002Fgpustats\u002Freleases\u002Ftag\u002Fv1.0.0)相同的 Python 代码，但改进了文档并添加了示例。\n","2017-01-16T21:13:04",{"id":174,"version":175,"summary_zh":176,"released_at":177},315203,"v1.0.0","GPUstats：\n- 使用 Python（结合 nvidia-smi）获取所有 CUDA 兼容 GPU 的显存使用情况和利用率\n- 从所有可用 GPU 中获取第一个、最后一个以及随机选择的 GPU\n- 示例：展示如何在使用 TensorFlow 时，通过编程方式仅在一台 GPU 上分配显存\n","2017-01-16T14:38:03"]