erew123 / deepspeedpatcher

A graphical tool to simplify building and installing DeepSpeed 0.15.x or later on Windows systems.
1 stars 0 forks source link

奇怪的未知原因问题,以非管理员方式运行py文件。运行以后电脑强行关机 #1

Closed xiezhipeng-git closed 37 minutes ago

xiezhipeng-git commented 2 hours ago

@erew123 windows11 使用vscode 打开工程。点击.py文件,以后,电脑强行关机。直接断电的那种

erew123 commented 2 hours ago

代码中没有任何内容会导致这种情况,所以我怀疑是你的电脑或 VS Code 的安装出现了其他问题

There is nothing in the code that would do that, so I suspect you have some other issue with your computer or your installation of VS code

xiezhipeng-git commented 2 hours ago

我也感到很奇怪。好像是检查是否是管理员的那个弹窗。点了强行断电

xiezhipeng-git commented 2 hours ago

image 用管理员的方式可以打开

xiezhipeng-git commented 2 hours ago

image 本地已经有vs2022了,没有检测到

erew123 commented 2 hours ago

请查看官方的 Microsoft DeepSpeed 网站:https://github.com/microsoft/DeepSpeed/blob/9500ab7d476aaf60ec2c76653c67bf5feb758f9e/build_win.bat

DeepSpeed 编译/构建需要管理员权限。因此,我必须请求管理员权限,这是无法绕过的要求。

如果您有疑虑,可以手动构建 DeepSpeed,相关说明请见此链接:https://github.com/erew123/deepspeedpatcher?tab=readme-ov-file#manual-builds-of-deepspeed-0150-and-later

此外,您也会看到需要以管理员身份打开命令提示符:https://github.com/erew123/deepspeedpatcher?tab=readme-ov-file#manual-build-steps

关于 Visual Studio,我在此列出了所有的前置要求:https://github.com/erew123/deepspeedpatcher?tab=readme-ov-file#before-running-the-tool 我无法确认非英文操作系统上的 Visual Studio 是否会被不同地检测到,因为我对 Microsoft 产品和本地化的了解有限。

Please see here, from the official Microsoft DeepSpeed site, https://github.com/microsoft/DeepSpeed/blob/9500ab7d476aaf60ec2c76653c67bf5feb758f9e/build_win.bat

DeepSpeed requires Administrator privilege to build/compile. As such, I have to request administrator rights, there is no way to work around this requirement.

If you are concerned, you can always build DeepSpeed manually, I include the instructions for doing this here https://github.com/erew123/deepspeedpatcher?tab=readme-ov-file#manual-builds-of-deepspeed-0150-and-later

You will also see that you have to open Command Prompt as the administrator https://github.com/erew123/deepspeedpatcher?tab=readme-ov-file#manual-build-steps

As for Visual Studio, I state all pre-requisites https://github.com/erew123/deepspeedpatcher?tab=readme-ov-file#before-running-the-tool I cannot say if Visual Studio on non-english computers may be detected differently. I dont have that amount of knowledge of Microsoft Products and localisation.

xiezhipeng-git commented 2 hours ago

image @erew123 能看出少了什么吗? 没检测到vs

xiezhipeng-git commented 2 hours ago

@erew123 vs_paths = { "VS2019 BuildTools": "C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools", "VS2019 Community": "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community", "VS2022 BuildTools": "C:\Program Files\Microsoft Visual Studio\2022\BuildTools", "VS2022 Community": "C:\Program Files\Microsoft Visual Studio\2022\Community" }

路径问题?C D path?

erew123 commented 2 hours ago

很难说,我不懂中文,但看起来是正确的。

这段代码会查找 Visual Studio 是否安装在默认路径中。如果需要,您可以更改这些代码行,以指向正确的路径:https://github.com/erew123/deepspeedpatcher/blob/main/builddeepspeed.py#L601-L606

您需要将版本更改为与您的路径匹配:

python

vs_paths = { "VS2019 BuildTools": "C:\Your\Custom\Path\To\Microsoft Visual Studio\2019\BuildTools", "VS2019 Community": "C:\Your\Custom\Path\To\Microsoft Visual Studio\2019\Community", "VS2022 BuildTools": "C:\Your\Custom\Path\To\Microsoft Visual Studio\2022\BuildTools", "VS2022 Community": "C:\Your\Custom\Path\To\Microsoft Visual Studio\2022\Community" }

它正在尝试找到 vcvars64.bat,因为这是编译所需的。

Hard to say, I dont understand chinese, but it looks correct.

The code looks for Visual Studio being installed in the default paths. You can change these lines of code if needed to point it to the correct path https://github.com/erew123/deepspeedpatcher/blob/main/builddeepspeed.py#L601-L606

You would change the version to match your path:

vs_paths = { "VS2019 BuildTools": "C:\Your\Custom\Path\To\Microsoft Visual Studio\2019\BuildTools", "VS2019 Community": "C:\Your\Custom\Path\To\Microsoft Visual Studio\2019\Community", "VS2022 BuildTools": "C:\Your\Custom\Path\To\Microsoft Visual Studio\2022\BuildTools", "VS2022 Community": "C:\Your\Custom\Path\To\Microsoft Visual Studio\2022\Community" }

It is trying to find vcvars64.bat as this is needed to compile.

xiezhipeng-git commented 2 hours ago
        vs_paths = {
            "VS2019 BuildTools": "C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\BuildTools",
            "VS2019 Community": "C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Community",
            "VS2022 BuildTools": "D:\\Program Files\\Microsoft Visual Studio\\2022\\BuildTools",
            # "VS2022 Community": "C:\\Program Files\\Microsoft Visual Studio\\2022\\Community",
            "VS2022 Community": "D:\\Program Files\\Microsoft Visual Studio\\2022\\Community",
        }
        change path also can not finde vs
xiezhipeng-git commented 1 hour ago

if only a bat file.why not copy it's text to project.then run it?

erew123 commented 1 hour ago

代码应该在所有这些路径中查找,然后将 VC\\Auxiliary\\Build\\vcvars64.bat 添加到路径中,以找到 vcvars64.bat 文件。

这在以下行中: https://github.com/erew123/deepspeedpatcher/blob/main/builddeepspeed.py#L610

所以请检查您是否在 D:\\Program Files\\Microsoft Visual Studio\\2022\\Community\\VC\\Auxiliary\\Build\\ 位置中有 vcvars64.bat 文件。

除此之外,我无法判断,这可能是某种本地化问题。

RE: if only a bat file.why not copy it to project.then run it? 我不确定不同版本之间是否存在差异。我没有花时间安装不同版本的 Visual Studio,也没有仔细研究它实际在做什么。我只是写这个来帮助我自己的项目。

The code should look in all those paths, then add VC\\Auxiliary\\Build\\vcvars64.bat onto the path to find the vcvars64.bat file.

This is in line: https://github.com/erew123/deepspeedpatcher/blob/main/builddeepspeed.py#L610

So check you have vcvars64.bat in the D:\\Program Files\\Microsoft Visual Studio\\2022\\CommunityVC\Auxiliary\Build\` location.

Beyond that, I cannot say, it could be a localisation issue of some kind.

erew123 commented 1 hour ago

欢迎您将 bat 文件放在脚本中提到的任意位置,这样应该可以通过检查。不过,我不能确定它是否会运行。

xiezhipeng-git commented 1 hour ago

have two place path position. chang it found vs

xiezhipeng-git commented 1 hour ago

@erew123 There are too more buttons. I need click build and install?

erew123 commented 1 hour ago

https://github.com/erew123/deepspeedpatcher?tab=readme-ov-file#usage-guide

构建选项 仅构建:创建不带安装的轮文件 安装已构建的轮:安装之前构建的轮 构建和安装:执行这两项操作 CUDA_HOME 设置指南:显示 CUDA_HOME 配置说明

Build Options Build Only: Creates wheel file without installation Install Built Wheel: Installs previously built wheel Build and Install: Performs both operations CUDA_HOME Setup Guide: Shows CUDA_HOME configuration instructions

xiezhipeng-git commented 1 hour ago

image Is it download deepspeed source code?can use download project file path?

erew123 commented 1 hour ago

是的,它直接从微软的 GitHub 网站下载 DeepSpeed。如果您无法访问该网站,或者在浏览器的 SSL 证书方面遇到问题,那将是一个问题。

Yes it downloads DeepSpeed directly from Microsoft's Github website. If you are blocked from accessing it, or have issues with your browsers SSL certificates, that would be a problem.

xiezhipeng-git commented 1 hour ago

a zip .I need put the file in Installation Directory?

erew123 commented 1 hour ago

抱歉,我没有构建它以那种方式工作。此时,我建议您执行手动安装。英文说明在以下链接中。我已经为您翻译了它们,但我不能保证翻译的质量。然而,这些说明将指导您如何在 Windows 上手动构建 DeepSpeed 0.15.x。

Sorry, I have not built it to work that way. At this point, I would suggest performing a manual installation. The instructions in english are on the following link. I have translated them for you, but I cannot say if the translation is good or not. The instructions however will guide you all the way through manually building DeepSpeed 0.15.x for Windows.

https://github.com/erew123/deepspeedpatcher?tab=readme-ov-file#manual-builds-of-deepspeed-0150-and-later

https://github.com/erew123/deepspeedpatcher?tab=readme-ov-file#manual-build-steps

DeepSpeed 0.15.0 及后续版本的手动构建 在 Windows 上构建 DeepSpeed - 关键要求和观察 所需软件

Visual Studio Build Tools 或带有“C++ 桌面开发”工作负载的 Visual Studio Community Edition 所需组件: MSVC v142 - VS 2019 C++ x64/x86 构建工具 Windows 10 SDK(10.0.19041.0 或更新版本) C++ 核心功能 - 构建工具 v142 构建工具的 C++/CLI 支持 v142 构建工具的 C++ 模块 Windows 的 C++ CMake 工具 NVIDIA CUDA Toolkit(与您的 PyTorch 安装兼容) 安装了 PyTorch CUDA 构建的 Python(例如,torch==2.4.1+cu121 适用于 CUDA 12.1) Ninja 构建系统(使用 pip 安装 ninja)(CUDA 编译所需) psutil(使用 pip 安装 psutil)(我认为这也是必要的) 注意:如果使用 Visual Studio Code 而不是 Visual Studio,请确保您已单独安装实际的 Visual Studio Build Tools - VS Code 的 C++ 扩展默认选择单独是不够的。

CUDA Toolkit 安装

仅需要特定组件: CUDA > 开发 > 编译器 > nvcc CUDA > 开发 > 库 > CUBLAS CUDA > 运行时 > 库 > CUBLAS 不需要完整安装,以节省下载/安装时间 Visual Studio 环境差异

Visual Studio(完整版本): 开发者命令提示符可从开始菜单中访问 VS 环境变量自动设置 64 位工具链随时可用 Visual Studio Code: 没有内置的开发者命令提示符 必须手动从以下路径运行 vcvars64.bat:C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Auxiliary\Build\vcvars64.bat 重要:必须使用 64 位环境(vcvars64.bat,而不是 vcvars32.bat)。

关键发现和注意事项

环境设置至关重要: 在构建之前,必须正确初始化 Visual Studio 环境 使用错误的架构(32 位与 64 位)会导致编译失败。0.15.0 似乎需要 x64 开发者控制台 CUDA_HOME 和 CUDA_PATH 必须指向与您的 PyTorch CUDA 版本匹配的正确 CUDA 安装 构建过程:

必须以管理员权限运行 应从正确的 x64 开发者命令提示符或环境中运行 如果 Visual Studio x64 工具链未正确初始化,构建将失败,作为 Visual Studio/Visual Studio Code 的一部分 常见问题:

在 Windows 上,可以忽略 aio.lib 和 cufile.lib 错误 dskernels 模块错误通常表示 CUDA 环境设置不正确 在 CUDA 内核编译期间,构建可能会出现挂起现象(请耐心等待,给它几分钟时间) 手动构建步骤 在下载并提取 DeepSpeed 0.15.x(或更高版本)的构建后,作为管理员打开一个 Visual Studio x64 开发者命令提示符(或手动初始化 VS 环境),然后启动您希望构建的 Python 环境。

设置所需的环境变量,指向您的 Nvidia CUDA Toolkit,刚好在 nvcc.exe 所在的 bin 路径之前(例如):

set CUDA_HOME=C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v12.1
set CUDA_PATH=C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v12.1
set DISTUTILS_USE_SDK=1

您可以通过测试 NVCC 以及 CL 来验证环境是否正确设置:

nvcc -V    # 应显示 CUDA 版本
cl         # 应显示 MSVC 版本

将 DeepSpeed 构建选项设置为 0:

set DS_BUILD_AIO=0
set DS_BUILD_CUTLASS_OPS=0
set DS_BUILD_EVOFORMER_ATTN=0
set DS_BUILD_FP_QUANTIZER=0
set DS_BUILD_RAGGED_DEVICE_OPS=0
set DS_BUILD_SPARSE_ATTN=0

如有必要,您可以通过在您所处的命令提示符中运行 set 来检查您的环境变量。

现在,您应该在您的管理员 x64 开发者命令提示符/控制台中,并加载了您希望为其构建 DeepSpeed 的 Python 环境,CUDA_HOME 和 CUDA_PATH 正确设置,以及您的 DeepSpeed 构建选项设置好,您可以进入提取的 DeepSpeed 文件夹并运行:

python setup.py bdist_wheel

当完成后,如果成功,在 DeepSpeed 文件夹中将会有一个 dist 文件夹,包含您编译的轮文件。您可以使用 pip install deepspeed-xxxxxxxxxx.whl 安装它,其中 x 的部分将对您的环境构建是唯一的。

验证 在构建并安装轮文件后,使用 ds_report 或 Python 脚本验证 CUDA 可用性:

import torch
print(torch.cuda.is_available())
import deepspeed
from deepspeed.ops.op_builder import OpBuilder

torch.cuda.is_available() # 应返回 True ds_report # 应显示 CUDA 可用且配置正确 输出中没有关于缺少 CUDA 组件的警告。

附加说明

构建过程需要 VS2019 或更新版本(VS2019 Build Tools 最低要求) CUDA 版本必须与已安装的 PyTorch 版本兼容 轮文件特定于 Python 版本、CUDA 版本和 Windows 架构 在干净的目录中构建可防止潜在的冲突