Skip to content

How can I enable warnings and unavailable? memory_efficient_attention.ckF #1244

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
amDosion opened this issue Apr 14, 2025 · 6 comments
Open

Comments

@amDosion
Copy link

❓ Questions and Help

`# ==================================================

🔧 [6.3] Ninja + xformers 编译安装(适配 CUDA 12.8)

==================================================

INSTALL_XFORMERS="${INSTALL_XFORMERS:-true}"

MAIN_REPO_DIR="/app/webui/sd-webui-forge"
XFORMERS_DIR="${MAIN_REPO_DIR}/xformers-src"

TORCH_VER="2.8.0.dev20250326+cu128"
VISION_VER="0.22.0.dev20250326+cu128"
AUDIO_VER="2.6.0.dev20250326+cu128"
TORCH_COMMAND="pip install --pre torch==${TORCH_VER} torchvision==${VISION_VER} torchaudio==${AUDIO_VER} --extra-index-url https://download.pytorch.org/whl/nightly/cu128"

if [[ "$INSTALL_XFORMERS" == "true" ]]; then
echo "⚙️ [6.3] 正在编译并安装 xformers(适配 CUDA 12.8)"
echo "🐍 当前 Python 路径: $(which python)"

echo "🔍 检查 xformers 是否已正确安装..."
if python -c "import xformers" >/dev/null 2>&1 && python -m xformers.info | grep -q "available"; then
echo "✅ 已检测到 xformers 且扩展已启用,版本: $(python -c 'import xformers; print(xformers.version)')"
echo "📦 当前环境无需重新编译 xformers"
fi

echo "📦 检查 PyTorch 是否为指定版本..."
torch_ver=$(pip show torch 2>/dev/null | awk '/^Version:/{print $2}')
vision_ver=$(pip show torchvision 2>/dev/null | awk '/^Version:/{print $2}')
audio_ver=$(pip show torchaudio 2>/dev/null | awk '/^Version:/{print $2}')

if [[ "$torch_ver" != "$TORCH_VER" || "$vision_ver" != "$VISION_VER" || "$audio_ver" != "$AUDIO_VER" ]]; then
echo "🔧 安装指定版本的 PyTorch 组件..."
echo " ➤ $TORCH_COMMAND"
$TORCH_COMMAND && echo " ✅ PyTorch 安装成功" || { echo " ❌ PyTorch 安装失败"; exit 1; }
else
echo " ✅ 已存在所需版本 torch/vision/audio,跳过安装"
fi

echo "📦 检查并安装 pip 构建依赖..."
for pkg in pip wheel setuptools cmake ninja; do
ver=$(pip show "$pkg" 2>/dev/null | awk '/^Version:/{print $2}')
if [[ -n "$ver" ]]; then
echo " ✅ $pkg 已安装: v$ver"
else
echo " ❌ $pkg 未安装,尝试安装中..."
pip install "$pkg" --no-cache-dir || echo " ⚠️ 安装 $pkg 失败,请检查网络或 PyPI"
fi
done

✅ 检查系统依赖(仅 root 用户可自动安装)

if [ "$(id -u)" -eq 0 ]; then
echo "🔧 检查系统构建依赖是否已安装..."
MISSING=()
command -v g++ >/dev/null && echo " ✅ g++ 已安装: $(g++ --version | head -n 1)" || MISSING+=("g++")
command -v zip >/dev/null && echo " ✅ zip 已安装: $(zip -v | head -n 1)" || MISSING+=("zip")
command -v unzip >/dev/null && echo " ✅ unzip 已安装: $(unzip -v | head -n 1)" || MISSING+=("unzip")
if [ "${#MISSING[@]}" -eq 0 ]; then
echo "🎉 所有系统构建依赖已满足,无需安装。"
else
echo "⚠️ 缺失依赖: ${MISSING[*]},尝试安装..."
apt-get update && apt-get install -y "${MISSING[@]}"
fi
else
echo "⚠️ 当前非 root 用户,跳过系统依赖安装"
fi

✅ 准备源码

echo "📁 准备 xformers 源码..."
if [ ! -d "$XFORMERS_DIR/.git" ]; then
echo " - 克隆 xformers 仓库..."
git clone --recursive https://github.com/facebookresearch/xformers.git "$XFORMERS_DIR"
else
echo " - 已存在源码目录,执行 pull..."
cd "$XFORMERS_DIR"
git pull --ff-only || echo "⚠️ 仓库更新失败,跳过"
cd "$MAIN_REPO_DIR"
fi

echo "🔄 初始化子模块(包含 Flash-Attention)..."
cd "$XFORMERS_DIR"
git submodule update --init --recursive || {
echo "❌ 子模块拉取失败,请检查 .gitmodules 或网络连接"
exit 1
}

echo "🔧 开始构建 xformers..."
export XFORMERS_FORCE_CUDA=1
export XFORMERS_BUILD_CPP=1
export TORCH_CUDA_ARCH_LIST="${TORCH_CUDA_ARCH_LIST:-8.9}"
export MAX_JOBS=8
echo " ➤ CUDA 架构: $TORCH_CUDA_ARCH_LIST"
echo " ➤ 并行编译线程数: $MAX_JOBS"

pip install -v -e . --no-build-isolation
build_result=$?

unset XFORMERS_FORCE_CUDA
unset XFORMERS_BUILD_CPP
unset TORCH_CUDA_ARCH_LIST
unset MAX_JOBS

if [ $build_result -ne 0 ]; then
echo "❌ xformers 编译失败,尝试输出诊断信息..."
python -m pip list | grep -E 'torch|xformers|ninja|wheel|cmake|setuptools'
exit 1
fi

echo "✅ xformers 安装完成(已启用 C++ 扩展)"

echo "📋 运行 torch 环境收集..."
python -m torch.utils.collect_env | tee ../torch_env.txt

echo "🧩 运行 xformers.info 检查模块状态..."
python -m xformers.info | tee ../xformers_info.txt || echo "⚠️ 无法执行 xformers.info"

if grep -q "unavailable" ../xformers_info.txt; then
echo "⚠️ 以下模块未启用:"
grep "unavailable" ../xformers_info.txt | sed 's/^/ - /'
else
echo "✅ 所有 C++ 扩展模块可用 ✅"
fi

echo "📁 xformers 源码目录: $(realpath "$XFORMERS_DIR")"
echo "🐍 当前 Python: $(which python)"
cd "$MAIN_REPO_DIR"
else
echo "⏭️ [6.3] 跳过 xformers 编译安装(INSTALL_XFORMERS=false)"
fi

log:
[6.3] 正在编译并安装 xformers(适配 CUDA 12.8)
🐍 当前 Python 路径: /app/webui/sd-webui-forge/venv/bin/python
🔍 检查 xformers 是否已正确安装...
✅ 已检测到 xformers 且扩展已启用,版本: 0.0.30+c5c0720c.d20250414
📦 当前环境无需重新编译 xformers
📦 检查 PyTorch 是否为指定版本...
✅ 已存在所需版本 torch/vision/audio,跳过安装
📦 检查并安装 pip 构建依赖...
✅ pip 已安装: v25.0.1
✅ wheel 已安装: v0.45.1
✅ setuptools 已安装: v78.1.0
✅ cmake 已安装: v4.0.0
✅ ninja 已安装: v1.11.1.4
🔧 检查系统构建依赖是否已安装...
✅ g++ 已安装: g++ (GCC) 12.4.0
✅ zip 已安装: Copyright (c) 1990-2008 Info-ZIP - Type 'zip "-L"' for software license.
✅ unzip 已安装: UnZip 6.00 of 20 April 2009, by Debian. Original by Info-ZIP.
🎉 所有系统构建依赖已满足,无需安装。
📁 准备 xformers 源码...

  • 已存在源码目录,执行 pull...
    Already up to date.
    🔄 初始化子模块(包含 Flash-Attention)...
    🔧 开始构建 xformers...
    ➤ CUDA 架构: 8.9
    ➤ 并行编译线程数: 8
    Using pip 25.0.1 from /app/webui/sd-webui-forge/venv/lib/python3.11/site-packages/pip (python 3.11)
    Looking in indexes: https://pypi.org/simple, https://download.pytorch.org/whl/nightly/cu128
    Obtaining file:///app/webui/sd-webui-forge/xformers-src
    Preparing metadata (setup.py): started
    Running command python setup.py egg_info
    /app/webui/sd-webui-forge/venv/lib/python3.11/site-packages/setuptools/dist.py:759: SetuptoolsDeprecationWarning: License classifiers are deprecated.
    !!

      ********************************************************************************
      Please consider removing the following classifiers in favor of a SPDX license expression:
    
      License :: OSI Approved :: BSD License
    
      See https://packaging.python.org/en/latest/guides/writing-pyproject-toml/#license for details.
      ********************************************************************************
    

!!
self._finalize_license_expression()
running egg_info
creating /tmp/pip-pip-egg-info-9e4nfg6i/xformers.egg-info
writing /tmp/pip-pip-egg-info-9e4nfg6i/xformers.egg-info/PKG-INFO
writing dependency_links to /tmp/pip-pip-egg-info-9e4nfg6i/xformers.egg-info/dependency_links.txt
writing top-level names to /tmp/pip-pip-egg-info-9e4nfg6i/xformers.egg-info/top_level.txt
writing manifest file '/tmp/pip-pip-egg-info-9e4nfg6i/xformers.egg-info/SOURCES.txt'
reading manifest file '/tmp/pip-pip-egg-info-9e4nfg6i/xformers.egg-info/SOURCES.txt'
reading manifest template 'MANIFEST.in'
warning: no files found matching 'third_party/flash-attention/version.txt'
adding license file 'LICENSE'
writing manifest file '/tmp/pip-pip-egg-info-9e4nfg6i/xformers.egg-info/SOURCES.txt'
Preparing metadata (setup.py): finished with status 'done'
Installing collected packages: xformers
Attempting uninstall: xformers
Found existing installation: xformers 0.0.30+c5c0720c.d20250414
Uninstalling xformers-0.0.30+c5c0720c.d20250414:
Removing file or directory /app/webui/sd-webui-forge/venv/lib/python3.11/site-packages/xformers.egg-link
Removing pth entries from /app/webui/sd-webui-forge/venv/lib/python3.11/site-packages/easy-install.pth:
Removing entry: /app/webui/sd-webui-forge/xformers-src
Successfully uninstalled xformers-0.0.30+c5c0720c.d20250414
DEPRECATION: Legacy editable install of xformers==0.0.30+c5c0720c.d20250414 from file:///app/webui/sd-webui-forge/xformers-src (setup.py develop) is deprecated. pip 25.1 will enforce this behaviour change. A possible replacement is to add a pyproject.toml or enable --use-pep517, and use setuptools >= 64. If the resulting installation is not behaving as expected, try using --config-settings editable_mode=compat. Please consult the setuptools documentation for more information. Discussion can be found at pypa/pip#11457
Running setup.py develop for xformers
Running command python setup.py develop
/app/webui/sd-webui-forge/venv/lib/python3.11/site-packages/setuptools/dist.py:759: SetuptoolsDeprecationWarning: License classifiers are deprecated.
!!

        ********************************************************************************
        Please consider removing the following classifiers in favor of a SPDX license expression:

        License :: OSI Approved :: BSD License

        See https://packaging.python.org/en/latest/guides/writing-pyproject-toml/#license for details.
        ********************************************************************************

!!
  self._finalize_license_expression()
running develop
/app/webui/sd-webui-forge/venv/lib/python3.11/site-packages/setuptools/command/develop.py:41: EasyInstallDeprecationWarning: easy_install command is deprecated.
!!

        ********************************************************************************
        Please avoid running ``setup.py`` and ``easy_install``.
        Instead, use pypa/build, pypa/installer or other
        standards-based tools.

        See https://github.com/pypa/setuptools/issues/917 for details.
        ********************************************************************************

!!
  easy_install.initialize_options(self)
/app/webui/sd-webui-forge/venv/lib/python3.11/site-packages/setuptools/_distutils/cmd.py:90: SetuptoolsDeprecationWarning: setup.py install is deprecated.
!!

        ********************************************************************************
        Please avoid running ``setup.py`` directly.
        Instead, use pypa/build, pypa/installer or other
        standards-based tools.

        See https://blog.ganssle.io/articles/2021/10/setup-py-deprecated.html for details.
        ********************************************************************************

!!
  self.initialize_options()
running egg_info
writing xformers.egg-info/PKG-INFO
writing dependency_links to xformers.egg-info/dependency_links.txt
writing top-level names to xformers.egg-info/top_level.txt
reading manifest file 'xformers.egg-info/SOURCES.txt'
reading manifest template 'MANIFEST.in'
warning: no files found matching 'third_party/flash-attention/version.txt'
adding license file 'LICENSE'
writing manifest file 'xformers.egg-info/SOURCES.txt'
running build_ext
/app/webui/sd-webui-forge/venv/lib/python3.11/site-packages/torch/utils/cpp_extension.py:489: UserWarning: There are no x86_64-linux-gnu-g++ version bounds defined for CUDA version 12.8
  warnings.warn(f'There are no {compiler_name} version bounds defined for CUDA version {cuda_str_version}')
building 'xformers._C' extension
Emitting ninja build file /app/webui/sd-webui-forge/xformers-src/build/temp.linux-x86_64-cpython-311/build.ninja...
Compiling objects...
Using envvar MAX_JOBS (8) as the number of workers...
ninja: no work to do.
x86_64-linux-gnu-g++ -Wsign-compare -DNDEBUG -g -fwrapv -O2 -Wall -g -fstack-protector-strong -Wformat -Werror=format-security -g -fwrapv -O2 -shared -Wl,-O1 -Wl,-Bsymbolic-functions /app/webui/sd-webui-forge/xformers-src/build/temp.linux-x86_64-cpython-311/xformers/csrc/attention/attention.o /app/webui/sd-webui-forge/xformers-src/build/temp.linux-x86_64-cpython-311/xformers/csrc/attention/autograd/matmul.o /app/webui/sd-webui-forge/xformers-src/build/temp.linux-x86_64-cpython-311/xformers/csrc/attention/cpu/matmul.o /app/webui/sd-webui-forge/xformers-src/build/temp.linux-x86_64-cpython-311/xformers/csrc/attention/cpu/sddmm.o /app/webui/sd-webui-forge/xformers-src/build/temp.linux-x86_64-cpython-311/xformers/csrc/attention/cpu/sparse_softmax.o /app/webui/sd-webui-forge/xformers-src/build/temp.linux-x86_64-cpython-311/xformers/csrc/attention/cpu/spmm.o /app/webui/sd-webui-forge/xformers-src/build/temp.linux-x86_64-cpython-311/xformers/csrc/attention/cuda/matmul.o /app/webui/sd-webui-forge/xformers-src/build/temp.linux-x86_64-cpython-311/xformers/csrc/attention/cuda/sddmm.o /app/webui/sd-webui-forge/xformers-src/build/temp.linux-x86_64-cpython-311/xformers/csrc/attention/cuda/sddmm2_cuda.o /app/webui/sd-webui-forge/xformers-src/build/temp.linux-x86_64-cpython-311/xformers/csrc/attention/cuda/sparse_softmax.o /app/webui/sd-webui-forge/xformers-src/build/temp.linux-x86_64-cpython-311/xformers/csrc/attention/cuda/spmm.o /app/webui/sd-webui-forge/xformers-src/build/temp.linux-x86_64-cpython-311/xformers/csrc/attention/matmul.o /app/webui/sd-webui-forge/xformers-src/build/temp.linux-x86_64-cpython-311/xformers/csrc/attention/sddmm.o /app/webui/sd-webui-forge/xformers-src/build/temp.linux-x86_64-cpython-311/xformers/csrc/attention/sparse_softmax.o /app/webui/sd-webui-forge/xformers-src/build/temp.linux-x86_64-cpython-311/xformers/csrc/attention/spmm.o /app/webui/sd-webui-forge/xformers-src/build/temp.linux-x86_64-cpython-311/xformers/csrc/nvcc_info.o /app/webui/sd-webui-forge/xformers-src/build/temp.linux-x86_64-cpython-311/xformers/csrc/sparse24/gemm.o /app/webui/sd-webui-forge/xformers-src/build/temp.linux-x86_64-cpython-311/xformers/csrc/sparse24/meta_utils.o /app/webui/sd-webui-forge/xformers-src/build/temp.linux-x86_64-cpython-311/xformers/csrc/sparse24/sparse24.o /app/webui/sd-webui-forge/xformers-src/build/temp.linux-x86_64-cpython-311/xformers/csrc/sparse24/sparse24_apply.o /app/webui/sd-webui-forge/xformers-src/build/temp.linux-x86_64-cpython-311/xformers/csrc/sparse24/sparse24_apply_dense_output.o /app/webui/sd-webui-forge/xformers-src/build/temp.linux-x86_64-cpython-311/xformers/csrc/sparse24/sparse24_gemm_sm90.o /app/webui/sd-webui-forge/xformers-src/build/temp.linux-x86_64-cpython-311/xformers/csrc/sparse24/sparse24_largest_mask_2d.o /app/webui/sd-webui-forge/xformers-src/build/temp.linux-x86_64-cpython-311/xformers/csrc/sparse24/sparse24_pack.o /app/webui/sd-webui-forge/xformers-src/build/temp.linux-x86_64-cpython-311/xformers/csrc/sparse24/sparse24_pack_test.o /app/webui/sd-webui-forge/xformers-src/build/temp.linux-x86_64-cpython-311/xformers/csrc/sparse24/sparseNM_dense.o /app/webui/sd-webui-forge/xformers-src/build/temp.linux-x86_64-cpython-311/xformers/csrc/swiglu/cuda/dual_gemm_silu_identity_mul.o /app/webui/sd-webui-forge/xformers-src/build/temp.linux-x86_64-cpython-311/xformers/csrc/swiglu/cuda/gemm_fused_operand_sum.o /app/webui/sd-webui-forge/xformers-src/build/temp.linux-x86_64-cpython-311/xformers/csrc/swiglu/cuda/silu_bw_fused.o /app/webui/sd-webui-forge/xformers-src/build/temp.linux-x86_64-cpython-311/xformers/csrc/swiglu/swiglu_op.o /app/webui/sd-webui-forge/xformers-src/build/temp.linux-x86_64-cpython-311/xformers/csrc/swiglu/swiglu_packedw.o -L/app/webui/sd-webui-forge/venv/lib/python3.11/site-packages/torch/lib -L/usr/local/cuda/lib64 -L/usr/lib/x86_64-linux-gnu -lc10 -ltorch -ltorch_cpu -ltorch_python -lcudart -lc10_cuda -ltorch_cuda -o build/lib.linux-x86_64-cpython-311/xformers/_C.so
copying build/lib.linux-x86_64-cpython-311/xformers/cpp_lib.json -> xformers
copying build/lib.linux-x86_64-cpython-311/xformers/version.py -> xformers
copying build/lib.linux-x86_64-cpython-311/xformers/_C.so -> xformers
Creating /app/webui/sd-webui-forge/venv/lib/python3.11/site-packages/xformers.egg-link (link to .)
Adding xformers 0.0.30+c5c0720c.d20250414 to easy-install.pth file

Installed /app/webui/sd-webui-forge/xformers-src

Successfully installed xformers
✅ xformers 安装完成(已启用 C++ 扩展)
📋 运行 torch 环境收集...
:128: RuntimeWarning: 'torch.utils.collect_env' found in sys.modules after import of package 'torch.utils', but prior to execution of 'torch.utils.collect_env'; this may result in unpredictable behaviour
Collecting environment information...
PyTorch version: 2.8.0.dev20250326+cu128
Is debug build: False
CUDA used to build PyTorch: 12.8
ROCM used to build PyTorch: N/A

OS: Ubuntu 22.04.5 LTS (x86_64)
GCC version: (GCC) 12.4.0
Clang version: 20.1.2 (++20250401083310+e7406753caf3-1exp120250401203329.93)
CMake version: version 4.0.0
Libc version: glibc-2.35

Python version: 3.11.0rc1 (main, Aug 12 2022, 10:02:14) [GCC 11.2.0] (64-bit runtime)
Python platform: Linux-6.12.22-Unraid-x86_64-with-glibc2.35
Is CUDA available: True
CUDA runtime version: 12.8.93
CUDA_MODULE_LOADING set to: LAZY
GPU models and configuration: GPU 0: NVIDIA GeForce RTX 4090
Nvidia driver version: 570.133.07
cuDNN version: Probably one of the following:
/usr/lib/x86_64-linux-gnu/libcudnn.so.9.8.0
/usr/lib/x86_64-linux-gnu/libcudnn_adv.so.9.8.0
/usr/lib/x86_64-linux-gnu/libcudnn_cnn.so.9.8.0
/usr/lib/x86_64-linux-gnu/libcudnn_engines_precompiled.so.9.8.0
/usr/lib/x86_64-linux-gnu/libcudnn_engines_runtime_compiled.so.9.8.0
/usr/lib/x86_64-linux-gnu/libcudnn_graph.so.9.8.0
/usr/lib/x86_64-linux-gnu/libcudnn_heuristic.so.9.8.0
/usr/lib/x86_64-linux-gnu/libcudnn_ops.so.9.8.0
HIP runtime version: N/A
MIOpen runtime version: N/A
Is XNNPACK available: True

CPU:
Architecture: x86_64
CPU op-mode(s): 32-bit, 64-bit
Address sizes: 43 bits physical, 48 bits virtual
Byte Order: Little Endian
CPU(s): 32
On-line CPU(s) list: 0-31
Vendor ID: AuthenticAMD
Model name: AMD EPYC 7302 16-Core Processor
CPU family: 23
Model: 49
Thread(s) per core: 2
Core(s) per socket: 16
Socket(s): 1
Stepping: 0
Frequency boost: enabled
CPU max MHz: 3310.5459
CPU min MHz: 1500.0000
BogoMIPS: 5999.79
Flags: fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ht syscall nx mmxext fxsr_opt pdpe1gb rdtscp lm constant_tsc rep_good nopl xtopology nonstop_tsc cpuid extd_apicid aperfmperf rapl pni pclmulqdq monitor ssse3 fma cx16 sse4_1 sse4_2 movbe popcnt aes xsave avx f16c rdrand lahf_lm cmp_legacy svm extapic cr8_legacy abm sse4a misalignsse 3dnowprefetch osvw ibs skinit wdt tce topoext perfctr_core perfctr_nb bpext perfctr_llc mwaitx cpb cat_l3 cdp_l3 hw_pstate ssbd mba ibrs ibpb stibp vmmcall fsgsbase bmi1 avx2 smep bmi2 cqm rdt_a rdseed adx smap clflushopt clwb sha_ni xsaveopt xsavec xgetbv1 xsaves cqm_llc cqm_occup_llc cqm_mbm_total cqm_mbm_local clzero irperf xsaveerptr rdpru wbnoinvd amd_ppin arat npt lbrv svm_lock nrip_save tsc_scale vmcb_clean flushbyasid decodeassists pausefilter pfthreshold avic v_vmsave_vmload vgif v_spec_ctrl umip rdpid overflow_recov succor smca sev sev_es
Virtualization: AMD-V
L1d cache: 512 KiB (16 instances)
L1i cache: 512 KiB (16 instances)
L2 cache: 8 MiB (16 instances)
L3 cache: 128 MiB (8 instances)
NUMA node(s): 1
NUMA node0 CPU(s): 0-31
Vulnerability Gather data sampling: Not affected
Vulnerability Itlb multihit: Not affected
Vulnerability L1tf: Not affected
Vulnerability Mds: Not affected
Vulnerability Meltdown: Not affected
Vulnerability Mmio stale data: Not affected
Vulnerability Reg file data sampling: Not affected
Vulnerability Retbleed: Mitigation; untrained return thunk; SMT enabled with STIBP protection
Vulnerability Spec rstack overflow: Mitigation; Safe RET
Vulnerability Spec store bypass: Mitigation; Speculative Store Bypass disabled via prctl
Vulnerability Spectre v1: Mitigation; usercopy/swapgs barriers and __user pointer sanitization
Vulnerability Spectre v2: Mitigation; Retpolines; IBPB conditional; STIBP always-on; RSB filling; PBRSB-eIBRS Not affected; BHI Not affected
Vulnerability Srbds: Not affected
Vulnerability Tsx async abort: Not affected

Versions of relevant libraries:
[pip3] numpy==2.1.3
[pip3] nvidia-cublas-cu12==12.8.3.14
[pip3] nvidia-cuda-cupti-cu12==12.8.57
[pip3] nvidia-cuda-nvrtc-cu12==12.8.61
[pip3] nvidia-cuda-runtime-cu12==12.8.57
[pip3] nvidia-cudnn-cu12==9.8.0.87
[pip3] nvidia-cufft-cu12==11.3.3.41
[pip3] nvidia-curand-cu12==10.3.9.55
[pip3] nvidia-cusolver-cu12==11.7.2.55
[pip3] nvidia-cusparse-cu12==12.5.7.53
[pip3] nvidia-cusparselt-cu12==0.6.3
[pip3] nvidia-nccl-cu12==2.26.2
[pip3] nvidia-nvjitlink-cu12==12.8.61
[pip3] nvidia-nvtx-cu12==12.8.55
[pip3] open_clip_torch==2.32.0
[pip3] optree==0.15.0
[pip3] pytorch-lightning==2.5.1
[pip3] pytorch-triton==3.3.0+git96316ce5
[pip3] torch==2.8.0.dev20250326+cu128
[pip3] torchaudio==2.6.0.dev20250326+cu128
[pip3] torchdiffeq==0.2.5
[pip3] torchmetrics==1.7.1
[pip3] torchsde==0.2.6
[pip3] torchvision==0.22.0.dev20250326+cu128
[conda] Could not collect
🧩 运行 xformers.info 检查模块状态...
xFormers 0.0.30+c5c0720c.d20250414
memory_efficient_attention.ckF: unavailable
memory_efficient_attention.ckB: unavailable
memory_efficient_attention.ck_decoderF: unavailable
memory_efficient_attention.ck_splitKF: unavailable
memory_efficient_attention.cutlassF-pt: available
memory_efficient_attention.cutlassB-pt: available
[email protected]: available
[email protected]: available
[email protected]: unavailable
[email protected]: unavailable
memory_efficient_attention.triton_splitKF: available
indexing.scaled_index_addF: available
indexing.scaled_index_addB: available
indexing.index_select: available
sp24.sparse24_sparsify_both_ways: available
sp24.sparse24_apply: available
sp24.sparse24_apply_dense_output: available
sp24._sparse24_gemm: available
[email protected]: available
[email protected]: available
swiglu.dual_gemm_silu: available
swiglu.gemm_fused_operand_sum: available
swiglu.fused.p.cpp: available
is_triton_available: True
pytorch.version: 2.8.0.dev20250326+cu128
pytorch.cuda: available
gpu.compute_capability: 8.9
gpu.name: NVIDIA GeForce RTX 4090
dcgm_profiler: unavailable
build.info: available
build.cuda_version: 1208
build.hip_version: None
build.python_version: 3.11.0rc1
build.torch_version: 2.8.0.dev20250326+cu128
build.env.TORCH_CUDA_ARCH_LIST: 8.9
build.env.PYTORCH_ROCM_ARCH: None
build.env.XFORMERS_BUILD_TYPE: None
build.env.XFORMERS_ENABLE_DEBUG_ASSERTIONS: None
build.env.NVCC_FLAGS: None
build.env.XFORMERS_PACKAGE_FROM: None
build.nvcc_version: 12.8.93
source.privacy: open source
⚠️ 以下模块未启用:
- memory_efficient_attention.ckF: unavailable
- memory_efficient_attention.ckB: unavailable
- memory_efficient_attention.ck_decoderF: unavailable
- memory_efficient_attention.ck_splitKF: unavailable
- [email protected]: unavailable
- [email protected]: unavailable
- dcgm_profiler: unavailable
📁 xformers 源码目录: /app/webui/sd-webui-forge/xformers-src`
How can I enable warnings and unavailable?

@lw
Copy link
Contributor

lw commented Apr 14, 2025

I'm not sure I understand the issue. Are you asking about why some of the backends for memory_efficient_attention are disabled?

All the ones starting with ck are intended for AMD GPUs, hence if you have an NVIDIA one it's normal that you don't have them.

The "odd" one is the fa3 one. I suspect this is because you have a GPU with a 8.9 compute capability, whereas we gate fa3 for compute capabilities of at least 9.0:

CUDA_MINIMUM_COMPUTE_CAPABILITY = (9, 0)

It's quite likely that fa3 might work fine on your GPU, hence if you want to try to manually override those checks please feel free. We might accept a PR if you feel like it, but since we don't have any 8.9 hardware ourselves we won't be able to do it on our own.

@amDosion
Copy link
Author

I'm not sure I understand the issue. Are you asking about why some of the backends for memory_efficient_attention are disabled?

All the ones starting with ck are intended for AMD GPUs, hence if you have an NVIDIA one it's normal that you don't have them.

The "odd" one is the fa3 one. I suspect this is because you have a GPU with a 8.9 compute capability, whereas we gate fa3 for compute capabilities of at least 9.0:

xformers/xformers/ops/fmha/flash3.py

Line 567 in c5c0720

CUDA_MINIMUM_COMPUTE_CAPABILITY = (9, 0)
It's quite likely that fa3 might work fine on your GPU, hence if you want to try to manually override those checks please feel free. We might accept a PR if you feel like it, but since we don't have any 8.9 hardware ourselves we won't be able to do it on our own.

How can I override CUDA_MINIMUM_COMPUTE_CAPABILITY = (9, 0) to CUDA_MINIMUM_COMPUTE_CAPABILITY = (8.9, 0) ?
Using edge variables?

@lw
Copy link
Contributor

lw commented Apr 15, 2025

You would have to modify the source code and reinstall. Also, you would have to set it to (8, 9), not (8.9, 0).

@amDosion
Copy link
Author

``> You would have to modify the source code and reinstall. Also, you would have to set it to (8, 9), not `(8.9, 0)`.

(https://github.com/amDosion/xformers/blob/main/xformers/ops/fmha/flash3.py)

I forked the code and modified it to: CUDA_MINIMUM_COMPUTE_CAPABILITY = (8, 9)
It still doesn't seem to work. I don't know if I compiled it the wrong way.

`# ==================================================
# 🔧 [6.3] Ninja + xformers 编译安装(适配 CUDA 12.8)
# ==================================================
# --- 配置 ---
INSTALL_XFORMERS="${INSTALL_XFORMERS:-true}" # 设置为 false 以显式禁用
MAIN_REPO_DIR="/app/webui/sd-webui-forge"    # 如果你的主仓库位置不同,请调整
XFORMERS_SRC_DIR="${MAIN_REPO_DIR}/xformers-src"
XFORMERS_REPO_URL="https://github.com/amDosion/xformers.git" # 官方仓库 - 如果使用 fork,请更改

# 目标 PyTorch 版本 (CUDA 12.8 的 Nightly 版本示例)
# 注意: 确保这些与你的设置所需的*精确*版本匹配。
TORCH_VER="2.8.0.dev20250326+cu128"
VISION_VER="0.22.0.dev20250326+cu128"
AUDIO_VER="2.6.0.dev20250326+cu128"
TORCH_INSTALL_CMD="pip install --pre torch==${TORCH_VER} torchvision==${VISION_VER} torchaudio==${AUDIO_VER} --extra-index-url https://download.pytorch.org/whl/nightly/cu128 --no-cache-dir"

# 构建配置
TARGET_CUDA_ARCH="${TORCH_CUDA_ARCH_LIST:-8.9}" # 默认为 8.9 (例如,RTX 3090/4090),如果外部未设置
MAX_BUILD_JOBS="${MAX_JOBS:-$(nproc)}"         # 默认使用所有可用核心,如果需要,稍后限制
# 如果需要,限制 MAX_JOBS (例如,限制为 8)
# MAX_BUILD_JOBS=$((${MAX_BUILD_JOBS} > 8 ? 8 : ${MAX_BUILD_JOBS}))

# --- 辅助函数 ---
log_info() { echo "✅ INFO: $1"; }
log_warn() { echo "⚠️ WARN: $1"; }
log_error() { echo "❌ ERROR: $1"; }
log_step() { echo -e "\n🚀 STEP: $1"; }
log_detail() { echo "  ➤ $1"; }

check_command() {
  command -v "$1" >/dev/null 2>&1
}

# --- 主脚本逻辑 ---
if [[ "$INSTALL_XFORMERS" != "true" ]]; then
  log_info "[6.3] 跳过 xformers 安装,因为 INSTALL_XFORMERS 不是 'true'。"
  exit 0
fi

log_info "[6.3] 启动 xformers 构建/安装过程 (目标 CUDA: ${TARGET_CUDA_ARCH})"
log_detail "主仓库目录: ${MAIN_REPO_DIR}"
log_detail "xformers 源码目录: ${XFORMERS_SRC_DIR}"
log_detail "目标 PyTorch 版本: ${TORCH_VER}"
log_detail "当前 Python: $(which python)"

# --- 预先检查: xformers 是否已经安装且功能正常? ---
log_step "检查是否存在可用的 xformers 安装..."
XFORMERS_CHECK_PASS=false
XFORMERS_VERSION_INFO="N/A"
if python -c "import xformers" >/dev/null 2>&1; then
  log_detail "xformers 模块可导入。"
  XFORMERS_VERSION_INFO=$(python -c "import xformers; print(xformers.__version__)" 2>/dev/null || echo "unknown")
  # 检查核心 CUDA 操作是否可用 (如果需要,根据 xformers.info 的输出调整 grep 模式)
  if python -m xformers.info | grep -E 'available.*(cutlass|flash)' > /dev/null 2>&1; then
     log_info "现有 xformers 安装 (v${XFORMERS_VERSION_INFO}) 看起来功能正常,带有核心 CUDA 组件。"
     XFORMERS_CHECK_PASS=true
  else
     log_warn "xformers 可导入 (v${XFORMERS_VERSION_INFO}),但核心 CUDA 组件可能缺失或不可用。继续构建。"
     log_detail "xformers.info 的输出:"
     python -m xformers.info || log_warn "无法执行 xformers.info"
  fi
else
  log_warn "未找到 xformers 模块。继续安装。"
fi

if [[ "$XFORMERS_CHECK_PASS" == "true" ]]; then
  log_info "[6.3] 跳过构建过程,因为已存在可用的 xformers (v${XFORMERS_VERSION_INFO})。"
  # 可选: 在这里添加一个检查,以确保已安装的 xformers 的*版本*满足需求 (如果需要)
  exit 0
fi

# --- 依赖检查和安装 ---
# 1. PyTorch 检查
log_step "检查 PyTorch 版本要求..."
torch_ok=false
vision_ok=false
audio_ok=false
current_torch_ver=$(pip show torch 2>/dev/null | awk '/^Version:/{print $2}')
current_vision_ver=$(pip show torchvision 2>/dev/null | awk '/^Version:/{print $2}')
current_audio_ver=$(pip show torchaudio 2>/dev/null | awk '/^Version:/{print $2}')

[[ "$current_torch_ver" == "$TORCH_VER" ]] && torch_ok=true
[[ "$current_vision_ver" == "$VISION_VER" ]] && vision_ok=true
[[ "$current_audio_ver" == "$AUDIO_VER" ]] && audio_ok=true

if [[ "$torch_ok" != "true" || "$vision_ok" != "true" || "$audio_ok" != "true" ]]; then
  log_warn "未满足所需的 PyTorch 组件版本。"
  log_detail "需要: torch==${TORCH_VER}, torchvision==${VISION_VER}, torchaudio==${AUDIO_VER}"
  log_detail "找到:    torch==${current_torch_ver:-Not Installed}, torchvision==${current_vision_ver:-Not Installed}, torchaudio==${current_audio_ver:-Not Installed}"
  log_detail "执行 PyTorch 安装命令:"
  log_detail "$TORCH_INSTALL_CMD"
  if ! $TORCH_INSTALL_CMD; then
    log_error "PyTorch 安装失败。正在中止。"
    exit 1
  fi
  log_info "PyTorch 安装/更新成功。"
else
  log_info "已满足所需的 PyTorch 版本。"
fi

# 2. Pip 构建依赖检查
log_step "检查 Pip 构建依赖 (wheel, setuptools, cmake, ninja)..."
MISSING_PIP_DEPS=()
for pkg in wheel setuptools cmake ninja; do
  if ! pip show "$pkg" > /dev/null 2>&1; then
    log_warn "$pkg 未安装。"
    MISSING_PIP_DEPS+=("$pkg")
  else
     log_detail "$pkg 找到: $(pip show "$pkg" | awk '/^Version:/{print $2}')"
  fi
done

if [ ${#MISSING_PIP_DEPS[@]} -ne 0 ]; then
  log_info "安装缺失的 pip 依赖: ${MISSING_PIP_DEPS[*]}"
  if ! pip install --upgrade "${MISSING_PIP_DEPS[@]}" --no-cache-dir; then
      log_error "未能安装 pip 依赖: ${MISSING_PIP_DEPS[*]}。正在中止。"
      exit 1
  fi
  log_info "Pip 依赖安装成功。"
else
  log_info "所有必需的 pip 构建依赖都已存在。"
fi

# 确保 pip 本身是最新的
log_detail "升级 pip..."
pip install --upgrade pip --no-cache-dir

# 3. 系统构建依赖检查 (g++, zip, unzip)
log_step "检查系统构建依赖 (g++, zip, unzip)..."
MISSING_SYSTEM_DEPS=()
check_command g++ || MISSING_SYSTEM_DEPS+=("g++")
check_command zip || MISSING_SYSTEM_DEPS+=("zip")
check_command unzip || MISSING_SYSTEM_DEPS+=("unzip")

# 通过 g++ 间接检查 build-essential
if [[ ! " ${MISSING_SYSTEM_DEPS[@]} " =~ " g++ " ]]; then
    log_detail "g++ 找到: $(g++ --version | head -n 1)"
else
    log_warn "g++ 未找到。可能缺少 build-essential 包。"
fi
if [[ ! " ${MISSING_SYSTEM_DEPS[@]} " =~ " zip " ]]; then
    log_detail "zip 找到。" # Zip 版本输出很详细
else
    log_warn "zip 未找到。"
fi
if [[ ! " ${MISSING_SYSTEM_DEPS[@]} " =~ " unzip " ]]; then
    log_detail "unzip 找到。" # unzip 版本输出很详细
else
    log_warn "unzip 未找到。"
fi

if [ ${#MISSING_SYSTEM_DEPS[@]} -ne 0 ]; then
  log_warn "缺失的系统依赖: ${MISSING_SYSTEM_DEPS[*]}"
  if [ "$(id -u)" -eq 0 ]; then
    log_info "尝试以 root 用户安装缺失的系统依赖..."
    export DEBIAN_FRONTEND=noninteractive
    if apt-get update && apt-get install -y --no-install-recommends "${MISSING_SYSTEM_DEPS[@]}"; then
       log_info "系统依赖安装成功。"
    else
       log_error "未能通过 apt-get 安装系统依赖。请手动安装它们。正在中止。"
       exit 1
    fi
  else
    log_error "以非 root 用户身份运行。请手动安装以下系统包: ${MISSING_SYSTEM_DEPS[*]}。正在中止。"
    log_detail "示例命令 (Debian/Ubuntu): sudo apt-get install -y ${MISSING_SYSTEM_DEPS[*]}"
    exit 1
  fi
else
  log_info "所有必需的系统构建依赖都已存在。"
fi

# --- 源码准备 ---
log_step "准备 xformers 源码..."
if [ ! -d "$XFORMERS_SRC_DIR/.git" ]; then
  log_detail "从 ${XFORMERS_REPO_URL} 克隆 xformers 仓库..."
  # 如果不需要历史记录,使用 --depth 1 可以加快克隆速度,但如果构建特定标签/提交需要历史记录,请删除它
  if ! git clone --recursive ${XFORMERS_REPO_URL} "$XFORMERS_SRC_DIR"; then
     log_error "未能克隆 xformers 仓库。检查 URL 和网络连接。正在中止。"
     exit 1
  fi
  log_info "仓库克隆成功。"
else
  log_detail "找到现有源码目录。更新仓库和子模块..."
  cd "$XFORMERS_SRC_DIR" || { log_error "无法进入源码目录 ${XFORMERS_SRC_DIR}。正在中止。"; exit 1; }
  # 存储本地更改 (如果有),以避免 pull 冲突 (可选,谨慎使用)
  # git stash push -m "Auto-stash before update"
  git fetch origin
  # 首先尝试快速 forward pull
  if ! git pull --ff-only origin main; then # 假设 'main' 分支,如果需要,请调整
      log_warn "快速 forward pull 失败。尝试合并 pull (可能出现冲突)。"
      if ! git pull origin main; then
          log_warn "Git pull 失败。构建将使用当前的本地版本继续。"
          # 如果始终想要最新版本,覆盖更改,考虑在此处添加 'git reset --hard origin/main'
      fi
  fi
  # 更新子模块
  log_detail "更新子模块 (包括 flash-attention)..."
  if ! git submodule update --init --recursive; then
      log_error "未能更新子模块。检查 '.gitmodules' 和网络连接。正在中止。"
      cd "$MAIN_REPO_DIR" # 确保在中止之前退出 src 目录
      exit 1
  fi
  # 应用存储 (如果使用)
  # git stash pop || log_warn "Could not pop stash"
  cd "$MAIN_REPO_DIR" || { log_error "无法返回主目录 ${MAIN_REPO_DIR}。"; exit 1; } # 返回到原始目录
  log_info "仓库和子模块已更新。"
fi

# --- 构建 xformers ---
log_step "开始 xformers 构建过程..."
cd "$XFORMERS_SRC_DIR" || { log_error "无法进入源码目录 ${XFORMERS_SRC_DIR} 进行构建。正在中止。"; exit 1; }

# 设置构建环境变量
export TORCH_CUDA_ARCH_LIST="${TARGET_CUDA_ARCH}"
export MAX_BUILD_JOBS="${MAX_JOBS:-16}"  # 设置并行编译线程数为16,确保没有设置时默认使用16
export XFORMERS_BUILD_CPP=1 
export XFORMERS_FORCE_CUDA=1         # 强制 CUDA 构建,即使在构建时未检测到 GPU
export XFORMERS_BUILD_TYPE="Release" # 构建优化的发布版本
export XFORMERS_ENABLE_DEBUG_ASSERTIONS=0 # 在发布版本中禁用调试断言

# 启用 Flash Attention 和 Triton 组件 (确保你的环境支持它们)
export USE_FLASH_ATTENTION=1
# export USE_TRITON=1 # 如果你安装了 triton 并且想使用它,请取消注释

# 如果需要,设置 CMAKE 参数,例如,用于特定的 CUDA 架构确认
export CMAKE_ARGS="-DCMAKE_CUDA_ARCHITECTURES=${TARGET_CUDA_ARCH//./}" # 格式如 '89'

log_detail "构建环境变量已设置:"
log_detail "  TORCH_CUDA_ARCH_LIST=${TORCH_CUDA_ARCH_LIST}"
log_detail "  MAX_JOBS=${MAX_JOBS}"
log_detail "  XFORMERS_FORCE_CUDA=${XFORMERS_FORCE_CUDA}"
log_detail "  XFORMERS_BUILD_TYPE=${XFORMERS_BUILD_TYPE}"
log_detail "  USE_FLASH_ATTENTION=${USE_FLASH_ATTENTION}"
# log_detail "  USE_TRITON=${USE_TRITON}" # 如果启用了 USE_TRITON,请取消注释
log_detail "  CMAKE_ARGS=${CMAKE_ARGS}"

# 清理之前的构建工件 (可选,但建议用于干净的构建)
# log_detail "清理之前的构建工件..."
# python setup.py clean || log_warn "未能清理之前的构建工件。"
# find . -name "*.so" -type f -delete
# rm -rf build dist *.egg-info

log_info "执行构建命令: pip install -v -e . --no-build-isolation"
if ! pip install -v -e . --no-build-isolation; then
    log_error "xformers 构建失败。"
    log_detail "检查上面的详细构建日志,查找特定的 C++/CUDA 编译错误。"
    log_detail "确保 CUDA 工具包、驱动程序和 PyTorch 版本与目标架构 (${TARGET_CUDA_ARCH}) 兼容。"
    python -m pip list | grep -E 'torch|xformers|ninja|wheel|cmake|setuptools' # 显示相关的包版本
    build_success=false
else
    log_info "xformers 构建成功。"
    build_success=true
fi

# 取消设置构建环境变量
unset TORCH_CUDA_ARCH_LIST
unset MAX_JOBS
unset XFORMERS_FORCE_CUDA
unset XFORMERS_BUILD_TYPE
unset XFORMERS_ENABLE_DEBUG_ASSERTIONS
unset USE_FLASH_ATTENTION
unset CMAKE_ARGS

cd "$MAIN_REPO_DIR" || log_warn "无法返回主目录 ${MAIN_REPO_DIR}。"

# --- 构建后验证 ---
if [[ "$build_success" != "true" ]]; then
    log_error "[6.3] xformers 安装过程在构建期间失败。"
    exit 1
fi

log_step "验证安装..."
log_detail "运行 torch.utils.collect_env..."
python -m torch.utils.collect_env > "${MAIN_REPO_DIR}/torch_env_$(date +%Y%m%d_%H%M%S).txt" || log_warn "未能收集 torch 环境信息。"

log_detail "运行 xformers.info..."
XFORMERS_INFO_OUTPUT_FILE="${MAIN_REPO_DIR}/xformers_info_$(date +%Y%m%d_%H%M%S).txt"
if python -m xformers.info > "$XFORMERS_INFO_OUTPUT_FILE"; then
  log_info "xformers.info 执行成功。输出保存到 ${XFORMERS_INFO_OUTPUT_FILE}"
  if grep -q "unavailable" "$XFORMERS_INFO_OUTPUT_FILE"; then
    log_warn "一些 xformers 组件报告为不可用:"
    grep "unavailable" "$XFORMERS_INFO_OUTPUT_FILE" | sed 's/^/    - /'
    log_warn "潜在原因: 缺少运行时依赖项,特定内核 (如 Flash Attention) 的硬件/CUDA 版本不兼容,或者之前未捕获的构建问题。"
    log_warn "查看 ${XFORMERS_INFO_OUTPUT_FILE} 获取详细信息。"
  else
    log_info "检测到的所有 xformers 组件似乎都可用。"
  fi
else
  log_error "未能执行 'python -m xformers.info'。安装可能不完整或已损坏。"
  log_error "[6.3] xformers 安装过程完成,存在潜在问题。"
  exit 1
fi

log_info "[6.3] xformers 安装过程成功完成。"
log_detail "最终 Python 可执行文件: $(which python)"
log_detail "xformers 源码位置: $(realpath "$XFORMERS_SRC_DIR" 2>/dev/null || echo $XFORMERS_SRC_DIR)" # 如果目录被删除,realpath 可能会失败
`

@lw
Copy link
Contributor

lw commented Apr 17, 2025

BTW, why do you specifically need FlashAttention3?

@amDosion
Copy link
Author

BTW, why do you specifically need FlashAttention3?

It is not particularly necessary, but I just hope that the compilation can be successful, so that if it is needed later, there is no need to recompile.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants