2026/2/23 4:33:30
网站建设
项目流程
利用百度网盘自动播放做视频网站,wordpress研究机构主题,网站推广软件信息,网站设计软件培训文章目录【问题解决】DockerError: Container exited with code 1: Error loading model: GPU sm_86 is not supported by the compiled kernel问题描述问题原因解决方案方案 1#xff1a;使用支持多种 GPU 架构的容器镜像方案 2#xff1a;在容器中重新编译内核方案 3#…文章目录【问题解决】DockerError: Container exited with code 1: Error loading model: GPU sm_86 is not supported by the compiled kernel问题描述问题原因解决方案方案 1使用支持多种 GPU 架构的容器镜像方案 2在容器中重新编译内核方案 3指定 GPU 架构运行容器方案 4更新主机 GPU 驱动程序方案 5使用不同的量化方法方案 6构建自定义容器镜像Dockerfile 示例方案 7检查并更新 CUDA 版本示例代码完整的 Docker 容器配置和运行示例1. 构建支持 sm_86 的容器镜像2. 创建应用程序 app.py3. 构建和运行容器常见问题Q: 什么是 GPU 架构代码Q: 如何确定我的 GPU 架构Q: 为什么容器中的内核不支持我的 GPU 架构Q: 重新编译内核需要多长时间Q: 除了重新编译内核还有其他方法吗总结【问题解决】DockerError: Container exited with code 1: Error loading model: GPU sm_86 is not supported by the compiled kernel问题描述在 Docker 容器中运行模型时遇到以下错误DockerError: Container exited with code 1: Error loading model: GPU sm_86 is not supported by the compiled kernel问题原因这个错误通常由以下原因引起GPU 架构不支持容器中编译的内核不支持当前 GPU 的架构sm_86 对应 NVIDIA Ampere 架构如 RTX 30 系列CUDA 版本不匹配容器中使用的 CUDA 版本与 GPU 架构不兼容内核编译问题容器中的内核是为特定 GPU 架构编译的不支持其他架构驱动程序问题主机的 GPU 驱动程序版本过低不支持当前 GPU 架构容器镜像问题使用的容器镜像没有正确配置以支持多种 GPU 架构量化库问题使用的量化库如 GPTQ、AWQ编译时没有支持当前 GPU 架构解决方案方案 1使用支持多种 GPU 架构的容器镜像选择支持多种 GPU 架构的容器镜像特别是包含针对不同架构预编译内核的镜像# 使用官方 PyTorch 镜像它支持多种 GPU 架构dockerpull pytorch/pytorch:latest# 或使用包含量化库的镜像dockerpull thebloke/cuda11.8.0-runtime-ubuntu20.04方案 2在容器中重新编译内核进入容器并重新编译支持当前 GPU 架构的内核# 进入运行中的容器dockerexec-it container_namebash# 安装必要的依赖pipinstall--upgrade auto-gptq# 重新编译内核针对 sm_86python -cfrom auto_gptq import exllama_kernels; exllama_kernels.build_kernels(arch86)方案 3指定 GPU 架构运行容器在运行容器时指定当前 GPU 的架构# 运行容器并设置 GPU 架构环境变量dockerrun --gpus all -eTORCH_CUDA_ARCH_LIST8.6your-image方案 4更新主机 GPU 驱动程序确保主机的 GPU 驱动程序支持当前 GPU 架构# 检查当前驱动版本nvidia-smi# 访问 NVIDIA 官网下载最新驱动# https://www.nvidia.com/Download/index.aspx方案 5使用不同的量化方法如果是量化库的问题可以尝试使用不同的量化方法# 使用 GPTQ 量化需要支持 sm_86fromtransformersimportAutoModelForCausalLM modelAutoModelForCausalLM.from_pretrained(TheBloke/Llama-2-7B-GPTQ,device_mapauto,trust_remote_codeTrue)# 或使用 FP16 而不是量化modelAutoModelForCausalLM.from_pretrained(meta-llama/Llama-2-7b-hf,device_mapauto,torch_dtypeauto)方案 6构建自定义容器镜像构建支持当前 GPU 架构的自定义容器镜像Dockerfile 示例FROM pytorch/pytorch:2.0.0-cuda11.7-cudnn8-runtime # 安装必要的依赖 RUN pip install --upgrade pip \npip install transformers auto-gptq # 设置环境变量 ENV TORCH_CUDA_ARCH_LIST8.6 # 重新编译内核 RUN python -c from auto_gptq import exllama_kernels; exllama_kernels.build_kernels() # 设置工作目录 WORKDIR /app # 复制应用程序 COPY . /app # 运行命令 CMD [python, app.py]方案 7检查并更新 CUDA 版本确保容器中使用的 CUDA 版本支持当前 GPU 架构# 检查容器中的 CUDA 版本dockerexeccontainer_name nvcc --version# 检查 GPU 架构dockerexeccontainer_name nvidia-smi --query-gpucompute_cap --formatcsv示例代码完整的 Docker 容器配置和运行示例1. 构建支持 sm_86 的容器镜像创建DockerfileFROM pytorch/pytorch:2.0.0-cuda11.7-cudnn8-runtime # 安装系统依赖 RUN apt-get update apt-get install -y --no-install-recommends \ git \ rm -rf /var/lib/apt/lists/* # 安装 Python 依赖 RUN pip install --upgrade pip \npip install \ transformers \ auto-gptq[triton] \ accelerate \ datasets # 设置环境变量 ENV TORCH_CUDA_ARCH_LIST8.6 ENV PYTHONUNBUFFERED1 # 重新编译内核以支持 sm_86 RUN python -c from auto_gptq import exllama_kernels; exllama_kernels.build_kernels(arch86) # 设置工作目录 WORKDIR /app # 复制应用程序 COPY app.py /app/ # 运行应用 CMD [python, app.py]2. 创建应用程序app.pyfromtransformersimportAutoTokenizerfromauto_gptqimportAutoGPTQForCausalLMimporttorchprint( Initializing )print(fCUDA available:{torch.cuda.is_available()})iftorch.cuda.is_available():print(fCUDA version:{torch.version.cuda})print(fGPU:{torch.cuda.get_device_name(0)})print(fGPU arch:{torch.cuda.get_device_capability(0)})print(\n Loading model )# 加载 GPTQ 量化模型tokenizerAutoTokenizer.from_pretrained(TheBloke/Llama-2-7B-GPTQ)modelAutoGPTQForCausalLM.from_quantized(TheBloke/Llama-2-7B-GPTQ,device_mapauto,use_safetensorsTrue,trust_remote_codeTrue)print(\n Model loaded successfully )print(fModel type:{type(model)})print(\n Testing model )# 测试生成promptHello, how are you?inputstokenizer(prompt,return_tensorspt).to(model.device)withtorch.no_grad():outputsmodel.generate(**inputs,max_new_tokens50,temperature0.7,top_p0.95)generated_texttokenizer.decode(outputs[0],skip_special_tokensTrue)print(fPrompt:{prompt})print(fGenerated:{generated_text})print(\n Done )3. 构建和运行容器# 构建镜像dockerbuild -t gptq-sm86.# 运行容器dockerrun --gpus all gptq-sm86常见问题Q: 什么是 GPU 架构代码A: GPU 架构代码如 sm_86是 NVIDIA 对不同 GPU 架构的标识。sm_86 对应 NVIDIA Ampere 架构用于 RTX 30 系列、A100 等 GPU。Q: 如何确定我的 GPU 架构A: 可以使用nvidia-smi --query-gpucompute_cap --formatcsv命令查看 GPU 的计算能力然后参考 NVIDIA 文档映射到架构代码。Q: 为什么容器中的内核不支持我的 GPU 架构A: 容器中的内核通常是为特定架构编译的以提高性能。如果容器是为旧架构如 sm_75编译的它可能不支持新架构如 sm_86。Q: 重新编译内核需要多长时间A: 重新编译内核通常需要几分钟时间具体取决于容器的计算资源。Q: 除了重新编译内核还有其他方法吗A: 可以尝试使用不同的容器镜像或使用 FP16 精度而不是量化这样就不需要依赖特定架构的内核。总结遇到DockerError: Container exited with code 1: Error loading model: GPU sm_86 is not supported by the compiled kernel错误时主要需要使用支持多种 GPU 架构的容器镜像在容器中重新编译支持当前 GPU 架构的内核指定 GPU 架构运行容器更新主机 GPU 驱动程序尝试使用不同的量化方法或精度构建自定义容器镜像以支持特定 GPU 架构通过以上解决方案大部分情况下都能成功解决 GPU 架构不支持的问题顺利在 Docker 容器中运行模型。