如何为whichllm贡献新硬件支持?开发者贡献指南与API文档
【免费下载链接】whichllmFind the local LLM that actually runs and performs best on your hardware. Ranked by real, recency-aware benchmarks, not parameter count. One command, run it instantly.项目地址: https://gitcode.com/GitHub_Trending/wh/whichllm
想要让whichllm这个强大的本地LLM硬件检测工具支持更多设备吗?作为一款开源项目,whichllm依赖于社区贡献来不断完善硬件支持。本文将为你提供完整的开发者贡献指南,帮助你了解如何添加新的GPU、CPU或其他硬件支持,让更多用户能够准确评估他们的设备性能。💻
📊 whichllm硬件检测架构解析
whichllm的硬件检测系统采用模块化设计,支持多种硬件厂商和操作系统。核心架构包括:
硬件信息数据结构
在 hardware/types.py 中定义了核心数据结构:
@dataclass class GPUInfo: name: str vendor: str # "nvidia" | "amd" | "apple" | "intel" vram_bytes: int compute_capability: tuple[int, int] | None # NVIDIA only memory_bandwidth_gbps: float | None shared_memory: bool = False @dataclass class HardwareInfo: gpus: list[GPUInfo] cpu_name: str cpu_cores: int has_avx2: bool has_avx512: bool ram_bytes: int disk_free_bytes: int os: str硬件检测流程
whichllm的检测流程从 hardware/detector.py 开始,按操作系统调用相应的检测模块:
- NVIDIA GPU:通过NVML API或nvidia-smi命令行检测
- AMD GPU:通过rocm-smi或lspci检测
- Intel GPU:通过系统PCI信息检测
- Apple Silicon:通过system_profiler检测
- CPU和内存:通过系统调用获取
🔧 添加新的GPU支持:三步指南
第一步:更新GPU规格数据库
所有GPU规格数据存储在 src/whichllm/data/gpu.py 中。要添加新的GPU,你需要更新三个关键字典:
# GPU内存带宽数据库(GB/s) GPU_BANDWIDTH: dict[str, float] = { "RTX 5090": 1792.0, "RTX 5080": 960.0, # ... 添加你的新GPU } # NVIDIA计算能力查找表 NVIDIA_COMPUTE_CAPABILITY: dict[str, tuple[int, int]] = { "RTX 5090": (10, 0), "RTX 5080": (10, 0), # ... 添加你的新GPU } # 共享内存APU标记 AMD_SHARED_MEMORY_APU_MARKERS: tuple[str, ...] = ( "STRIX HALO", "RADEON 890M", # ... 添加新的共享内存GPU )第二步:实现硬件检测逻辑
根据GPU厂商,选择对应的检测模块进行扩展:
- NVIDIA GPU:编辑 hardware/nvidia.py
- AMD GPU:编辑 hardware/amd.py
- Intel GPU:编辑 hardware/intel.py
- Apple GPU:编辑 hardware/apple.py
以NVIDIA为例,检测逻辑包括:
- 尝试使用pynvml库(NVML API)
- 回退到nvidia-smi命令行
- 解析GPU名称和显存信息
第三步:编写测试用例
所有硬件检测功能都需要相应的测试。查看 tests/test_nvidia_detection.py 获取测试示例:
def test_new_gpu_detection(monkeypatch): # 模拟硬件检测 def fake_run(*args, **kwargs): return SimpleNamespace(stdout="NVIDIA New GPU Model, 16384 MiB\n") # 执行检测 gpus = detect_nvidia_gpus() # 验证结果 assert len(gpus) == 1 assert gpus[0].name == "NVIDIA New GPU Model" assert gpus[0].memory_bandwidth_gbps == 1024.0 # 预期带宽🚀 开发者贡献流程
环境搭建
git clone https://gitcode.com/GitHub_Trending/wh/whichllm cd whichllm uv sync --dev测试你的修改
uv run pytest tests/test_nvidia_detection.py uv run pytest tests/test_amd_detection.py uv run pytest tests/test_intel_gpu.py提交贡献
- Fork项目并创建功能分支
- 实现硬件支持
- 添加测试用例
- 运行完整测试套件
- 提交Pull Request
📈 硬件检测最佳实践
1. 处理边缘情况
- 统一内存设备:如Apple Silicon和AMD APU,需要标记为
shared_memory=True - 未知显存:某些设备(如NVIDIA GB10)可能报告
[N/A],需使用系统内存 - 多GPU系统:whichllm会汇总所有GPU的显存用于容量检查
2. 性能数据来源
- 理论带宽:从厂商规格表中获取
- 实际基准:参考TechPowerUp等权威数据库
- 计算能力:NVIDIA官方文档
3. 向后兼容性
- 保持现有API不变
- 添加新功能时不影响现有检测
- 提供适当的回退机制
🎯 贡献示例:添加RTX 5060 Ti支持
让我们通过一个具体示例,展示如何为新的NVIDIA GPU添加支持:
1. 更新GPU数据库
在 src/whichllm/data/gpu.py 中添加:
GPU_BANDWIDTH["RTX 5060 Ti"] = 448.0 NVIDIA_COMPUTE_CAPABILITY["RTX 5060 Ti"] = (10, 0)2. 验证检测逻辑
现有的NVIDIA检测逻辑会自动识别新GPU,因为whichllm使用子字符串匹配。只要GPU名称包含"RTX 5060 Ti",就能正确识别。
3. 添加测试用例
在测试文件中添加针对新GPU的测试:
def test_rtx_5060_ti_detection(monkeypatch): # 测试代码...🔍 调试与验证
使用whichllm硬件命令
whichllm hardware模拟硬件配置
whichllm --gpu "RTX 5060 Ti" --vram 16查看详细输出
whichllm --json📚 相关API文档
核心API接口
detect_hardware():主检测函数,返回HardwareInfo对象GPUInfo类:包含GPU所有属性HardwareInfo类:完整的系统硬件信息
工具函数
resolve_detected_bandwidth():解析GPU内存带宽_lookup_compute_capability():查找NVIDIA计算能力_is_unified_memory_nvidia_gpu():判断是否为统一内存GPU
🎉 开始你的贡献之旅
现在你已经掌握了为whichllm添加新硬件支持的所有知识!无论是最新的消费级GPU、专业计算卡,还是特殊的嵌入式设备,你的贡献都能帮助更多用户准确评估他们的硬件性能。
记住,开源社区的力量在于协作。如果你在贡献过程中遇到任何问题,可以参考现有的硬件检测文档,或者查看其他厂商的检测实现作为参考。
准备好为whichllm的硬件支持添砖加瓦了吗?开始你的第一个贡献吧!🌟
【免费下载链接】whichllmFind the local LLM that actually runs and performs best on your hardware. Ranked by real, recency-aware benchmarks, not parameter count. One command, run it instantly.项目地址: https://gitcode.com/GitHub_Trending/wh/whichllm
创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考