ktransformers icon indicating copy to clipboard operation
ktransformers copied to clipboard

[Bug] `KT-SFT/csrc/ktransformers_ext` 缺失 CMakeLists.txt 导致无法构建

Open yuxuan-z19 opened this issue 2 months ago • 2 comments

检查清单

  • [x] 1. 我已经搜索过相关问题,但未能获得预期的帮助
  • [x] 2. 该问题在最新版本中尚未修复
  • [x] 3. 请注意,如果您提交的BUG相关 issue 缺少对应环境信息和最小可复现示例,我们将难以复现和定位问题,降低获得反馈的可能性
  • [x] 4. 如果您提出的不是bug而是问题,请在讨论区发起讨论 https://github.com/kvcache-ai/ktransformers/discussions。否则该 issue 将被关闭
  • [x] 5. 为方便社区交流,我将使用中文/英文或附上中文/英文翻译(如使用其他语言)。未附带翻译的非中文/英语内容可能会被关闭

问题描述

我在如下环境中成功从 main 分支编译并安装 ktransformers==0.3.2+cu122torch26fancy,不过它目前不包含 sft 子模块 我尝试在 KT-SFT 下从源编译遇到如下问题:

CMake Error: The source directory "/data/zyx/LLaMA-Factory/ktransformers/KT-SFT/csrc/ktransformers_ext" does not appear to contain CMakeLists.txt.

完整 stderr 如下:

[stderr]
      /data/zyx/LLaMA-Factory/.venv/lib/python3.12/site-packages/setuptools/config/_apply_pyprojecttoml.py:82: SetuptoolsWarning: `install_requires` overwritten in
      `pyproject.toml` (dependencies)
        corresp(dist, value, root_dir)
      warning: no directories found matching 'third_party'
      warning: no directories found matching 'local_chat.py'
      no previously-included directories found matching 'ktransformers/logs'
      no previously-included directories found matching 'third_party/llama.cpp/models'
      warning: no directories found matching 'ktransformers/website/dist'
      warning: no previously-included files matching '__pycache__' found anywhere in distribution
      warning: no files found matching 'KTransformersOps.*.so'
      warning: no files found matching 'cpuinfer_ext.*.so'
      /data/zyx/LLaMA-Factory/.venv/lib/python3.12/site-packages/torch/utils/cpp_extension.py:448: UserWarning: The detected CUDA version (12.2) has a minor version
      mismatch with the version that was used to compile PyTorch (12.4). Most likely this shouldn't be a problem.
        warnings.warn(CUDA_MISMATCH_WARN.format(cuda_str_version, torch.version.cuda))
      /data/zyx/LLaMA-Factory/.venv/lib/python3.12/site-packages/torch/utils/cpp_extension.py:458: UserWarning: There are no x86_64-linux-gnu-g++ version bounds defined
      for CUDA version 12.2
        warnings.warn(f'There are no {compiler_name} version bounds defined for CUDA version {cuda_str_version}')
      CMake Warning:
        Ignoring extra path from command line:

         "/data/zyx/LLaMA-Factory/ktransformers/KT-SFT/csrc/ktransformers_ext"


      CMake Error: The source directory "/data/zyx/LLaMA-Factory/ktransformers/KT-SFT/csrc/ktransformers_ext" does not appear to contain CMakeLists.txt.
      Specify --help for usage, or press the help button on the CMake GUI.
      Traceback (most recent call last):
        File "<string>", line 11, in <module>
        File "/data/zyx/LLaMA-Factory/.venv/lib/python3.12/site-packages/setuptools/build_meta.py", line 435, in build_wheel
          return _build(['bdist_wheel', '--dist-info-dir', str(metadata_directory)])
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        File "/data/zyx/LLaMA-Factory/.venv/lib/python3.12/site-packages/setuptools/build_meta.py", line 423, in _build
          return self._build_with_temp_dir(
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^
        File "/data/zyx/LLaMA-Factory/.venv/lib/python3.12/site-packages/setuptools/build_meta.py", line 404, in _build_with_temp_dir
          self.run_setup()
        File "/data/zyx/LLaMA-Factory/.venv/lib/python3.12/site-packages/setuptools/build_meta.py", line 317, in run_setup
          exec(code, locals())
        File "<string>", line 700, in <module>
        File "/data/zyx/LLaMA-Factory/.venv/lib/python3.12/site-packages/setuptools/__init__.py", line 115, in setup
          return distutils.core.setup(**attrs)
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        File "/data/zyx/LLaMA-Factory/.venv/lib/python3.12/site-packages/setuptools/_distutils/core.py", line 186, in setup
          return run_commands(dist)
                 ^^^^^^^^^^^^^^^^^^
        File "/data/zyx/LLaMA-Factory/.venv/lib/python3.12/site-packages/setuptools/_distutils/core.py", line 202, in run_commands
          dist.run_commands()
        File "/data/zyx/LLaMA-Factory/.venv/lib/python3.12/site-packages/setuptools/_distutils/dist.py", line 1002, in run_commands
          self.run_command(cmd)
        File "/data/zyx/LLaMA-Factory/.venv/lib/python3.12/site-packages/setuptools/dist.py", line 1102, in run_command
          super().run_command(command)
        File "/data/zyx/LLaMA-Factory/.venv/lib/python3.12/site-packages/setuptools/_distutils/dist.py", line 1021, in run_command
          cmd_obj.run()
        File "<string>", line 295, in run
        File "/data/zyx/LLaMA-Factory/.venv/lib/python3.12/site-packages/setuptools/command/bdist_wheel.py", line 370, in run
          self.run_command("build")
        File "/data/zyx/LLaMA-Factory/.venv/lib/python3.12/site-packages/setuptools/_distutils/cmd.py", line 357, in run_command
          self.distribution.run_command(command)
        File "/data/zyx/LLaMA-Factory/.venv/lib/python3.12/site-packages/setuptools/dist.py", line 1102, in run_command
          super().run_command(command)
        File "/data/zyx/LLaMA-Factory/.venv/lib/python3.12/site-packages/setuptools/_distutils/dist.py", line 1021, in run_command
          cmd_obj.run()
        File "/data/zyx/LLaMA-Factory/.venv/lib/python3.12/site-packages/setuptools/_distutils/command/build.py", line 135, in run
          self.run_command(cmd_name)
        File "/data/zyx/LLaMA-Factory/.venv/lib/python3.12/site-packages/setuptools/_distutils/cmd.py", line 357, in run_command
          self.distribution.run_command(command)
        File "/data/zyx/LLaMA-Factory/.venv/lib/python3.12/site-packages/setuptools/dist.py", line 1102, in run_command
          super().run_command(command)
        File "/data/zyx/LLaMA-Factory/.venv/lib/python3.12/site-packages/setuptools/_distutils/dist.py", line 1021, in run_command
          cmd_obj.run()
        File "/data/zyx/LLaMA-Factory/.venv/lib/python3.12/site-packages/setuptools/command/build_ext.py", line 96, in run
          _build_ext.run(self)
        File "/data/zyx/LLaMA-Factory/.venv/lib/python3.12/site-packages/setuptools/_distutils/command/build_ext.py", line 368, in run
          self.build_extensions()
        File "/data/zyx/LLaMA-Factory/.venv/lib/python3.12/site-packages/torch/utils/cpp_extension.py", line 900, in build_extensions
          build_ext.build_extensions(self)
        File "/data/zyx/LLaMA-Factory/.venv/lib/python3.12/site-packages/setuptools/_distutils/command/build_ext.py", line 484, in build_extensions
          self._build_extensions_serial()
        File "/data/zyx/LLaMA-Factory/.venv/lib/python3.12/site-packages/setuptools/_distutils/command/build_ext.py", line 510, in _build_extensions_serial
          self.build_extension(ext)
        File "<string>", line 623, in build_extension
        File "<string>", line 402, in run_command_with_live_tail
        File "/usr/lib/python3.12/subprocess.py", line 571, in run
          raise CalledProcessError(retcode, process.args,
      subprocess.CalledProcessError: Command '['cmake', '/data/zyx/LLaMA-Factory/ktransformers/KT-SFT/csrc/ktransformers_ext',
      '-DCMAKE_LIBRARY_OUTPUT_DIRECTORY=/data/zyx/LLaMA-Factory/ktransformers/KT-SFT/build/lib.linux-x86_64-cpython-312/',
      '-DPYTHON_EXECUTABLE=/data/zyx/LLaMA-Factory/.venv/bin/python3', '-DCMAKE_BUILD_TYPE=Release', '-DKTRANSFORMERS_USE_CUDA=ON', '-D_GLIBCXX_USE_CXX11_ABI=0',
      '-DLLAMA_NATIVE=ON', '-DEXAMPLE_VERSION_INFO=0.4.1+cu124torch26fancy']' returned non-zero exit status 1.

      hint: This usually indicates a problem with the package or the build environment.
DEBUG Released lock at `/data/zyx/LLaMA-Factory/.venv/.lock`
DEBUG Released lock at `/data/zyx/.cache/uv/.lock`

复现步骤

我使用以下命令成功构建了 ktransformers

uv venv && source .venv/bin/activate
uv pip install torch==2.6.0 torchvision==0.21.0 torchaudio==2.6.0 --index-url https://download.pytorch.org/whl/cu124
uv pip install -r requirements-local_chat.txt
uv pip install -r ktransformers/server/requirements.txt
MAX_JOBS=$(nproc) KTRANSFORMERS_FORCE_BUILD=TRUE uv pip install -v . --no-build-isolation
uv pip install third_party/custom_flashinfer/

在切换到 KT-SFT 子目录下,注释了 pyproject.tomllicense-files 部分以保证 setuptools 能正确识别

readme = "README.md"
license = "Apache-2.0"
# license-files = ["LICENSE"]
uv pip install -r requirements-sft.txt
MAX_JOBS=$(nproc) KTRANSFORMERS_FORCE_BUILD=TRUE uv pip install -v . --no-build-isolation

环境信息

PyTorch version: 2.6.0+cu124 Is debug build: False CUDA used to build PyTorch: 12.4 ROCM used to build PyTorch: N/A

OS: Ubuntu 24.04.2 LTS (x86_64) GCC version: (Ubuntu 13.3.0-6ubuntu2~24.04) 13.3.0 Clang version: 18.1.3 (1ubuntu1) CMake version: version 3.28.3 Libc version: glibc-2.39

Python version: 3.12.3 (main, Aug 14 2025, 17:47:21) [GCC 13.3.0] (64-bit runtime) Python platform: Linux-6.8.0-71-generic-x86_64-with-glibc2.39 Is CUDA available: True CUDA runtime version: 12.2.91 CUDA_MODULE_LOADING set to: LAZY GPU models and configuration: GPU 0: NVIDIA GeForce RTX 4090 GPU 1: NVIDIA GeForce RTX 4090 GPU 2: NVIDIA GeForce RTX 4090 GPU 3: NVIDIA GeForce RTX 4090 GPU 4: NVIDIA GeForce RTX 4090 GPU 5: NVIDIA GeForce RTX 4090 GPU 6: NVIDIA GeForce RTX 4090 GPU 7: NVIDIA GeForce RTX 4090

Nvidia driver version: 550.144.03 cuDNN version: Could not collect Is XPU available: False 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: 46 bits physical, 57 bits virtual Byte Order: Little Endian CPU(s): 128 On-line CPU(s) list: 0-127 Vendor ID: GenuineIntel Model name: Intel(R) Xeon(R) Platinum 8358P CPU @ 2.60GHz CPU family: 6 Model: 106 Thread(s) per core: 2 Core(s) per socket: 32 Socket(s): 2 Stepping: 6 CPU(s) scaling MHz: 80% CPU max MHz: 3400.0000 CPU min MHz: 800.0000 BogoMIPS: 5200.00 Flags: fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc art arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc cpuid aperfmperf pni pclmulqdq dtes64 monitor ds_cpl smx est tm2 ssse3 sdbg fma cx16 xtpr pdcm pcid dca sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm abm 3dnowprefetch cpuid_fault epb cat_l3 intel_ppin ssbd mba ibrs ibpb stibp ibrs_enhanced fsgsbase tsc_adjust bmi1 avx2 smep bmi2 erms invpcid cqm rdt_a avx512f avx512dq rdseed adx smap avx512ifma clflushopt clwb intel_pt avx512cd sha_ni avx512bw avx512vl xsaveopt xsavec xgetbv1 xsaves cqm_llc cqm_occup_llc cqm_mbm_total cqm_mbm_local split_lock_detect wbnoinvd dtherm ida arat pln pts avx512vbmi umip pku ospke avx512_vbmi2 gfni vaes vpclmulqdq avx512_vnni avx512_bitalg tme avx512_vpopcntdq la57 rdpid fsrm md_clear pconfig flush_l1d arch_capabilities L1d cache: 3 MiB (64 instances) L1i cache: 2 MiB (64 instances) L2 cache: 80 MiB (64 instances) L3 cache: 96 MiB (2 instances) NUMA node(s): 4 NUMA node0 CPU(s): 0-15,64-79 NUMA node1 CPU(s): 16-31,80-95 NUMA node2 CPU(s): 32-47,96-111 NUMA node3 CPU(s): 48-63,112-127 Vulnerability Gather data sampling: Mitigation; Microcode Vulnerability Itlb multihit: Not affected Vulnerability L1tf: Not affected Vulnerability Mds: Not affected Vulnerability Meltdown: Not affected Vulnerability Mmio stale data: Mitigation; Clear CPU buffers; SMT vulnerable Vulnerability Reg file data sampling: Not affected Vulnerability Retbleed: Not affected Vulnerability Spec rstack overflow: Not affected 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; Enhanced / Automatic IBRS; IBPB conditional; RSB filling; PBRSB-eIBRS SW sequence; BHI SW loop, KVM SW loop Vulnerability Srbds: Not affected Vulnerability Tsx async abort: Not affected

Versions of relevant libraries: [pip3] ktransformers==0.3.2+cu122torch26fancy [pip3] numpy==1.26.4 [pip3] nvidia-cublas-cu12==12.4.5.8 [pip3] nvidia-cuda-cupti-cu12==12.4.127 [pip3] nvidia-cuda-nvrtc-cu12==12.4.127 [pip3] nvidia-cuda-runtime-cu12==12.4.127 [pip3] nvidia-cudnn-cu12==9.1.0.70 [pip3] nvidia-cufft-cu12==11.2.1.3 [pip3] nvidia-curand-cu12==10.3.5.147 [pip3] nvidia-cusolver-cu12==11.6.1.9 [pip3] nvidia-cusparse-cu12==12.3.1.170 [pip3] nvidia-cusparselt-cu12==0.6.2 [pip3] nvidia-nccl-cu12==2.21.5 [pip3] nvidia-nvjitlink-cu12==12.4.127 [pip3] nvidia-nvtx-cu12==12.4.127 [pip3] torch==2.6.0+cu124 [pip3] torchaudio==2.6.0+cu124 [pip3] torchvision==0.21.0+cu124 [pip3] torchviz==0.0.3 [pip3] triton==3.2.0 [conda] Could not collect

yuxuan-z19 avatar Nov 06 '25 10:11 yuxuan-z19

如果你希望重新编译SFT部分,我之前是只编译KT-SFT文件夹

JimmyPeilinLi avatar Nov 08 '25 07:11 JimmyPeilinLi

@JimmyPeilinLi 感谢,我补充了 CMakeLists.txt 就能正确编译了,见 #1576

yuxuan-z19 avatar Nov 08 '25 13:11 yuxuan-z19