这个问题我在linux系统上也碰到了,我通过重新编译解决了
rm -rf /tmp/BigVGAN/cuda/
// ... existing code ...
def load():
# Check CUDA version and set appropriate compute capabilities
_, bare_metal_major, bare_metal_minor = _get_cuda_bare_metal_version(cpp_extension.CUDA_HOME)
cuda_version = float(f"{bare_metal_major}.{bare_metal_minor}")
# Set compute capabilities based on CUDA version
cc_flags = []
if cuda_version >= 11.0:
cc_flags.extend([
"-gencode", "arch=compute_70,code=sm_70",
"-gencode", "arch=compute_75,code=sm_75",
"-gencode", "arch=compute_80,code=sm_80"
])
else:
cc_flags.extend([
"-gencode", "arch=compute_70,code=sm_70",
"-gencode", "arch=compute_75,code=sm_75"
])
# Build path
srcpath = pathlib.Path(__file__).parent.absolute()
buildpath = srcpath / "build"
_create_build_dir(buildpath)
# Helper function to build the kernels with optimized flags
def _cpp_extention_load_helper(name, sources, extra_cuda_flags):
return cpp_extension.load(
name=name,
sources=sources,
build_directory=buildpath,
extra_cflags=["-O3"],
extra_cuda_cflags=[
"-O3",
"--use_fast_math",
"-lineinfo" # Add debug info for better error messages
] + extra_cuda_flags + cc_flags,
verbose=True,
)
extra_cuda_flags = [
"-U__CUDA_NO_HALF_OPERATORS__",
"-U__CUDA_NO_HALF_CONVERSIONS__",
"--expt-relaxed-constexpr",
"--expt-extended-lambda",
]
sources = [
srcpath / "anti_alias_activation.cpp",
srcpath / "anti_alias_activation_cuda.cu",
]
# Handle special characters in path
buildpath = chinese_path_compile_support(sources, buildpath)
try:
anti_alias_activation_cuda = _cpp_extention_load_helper(
"anti_alias_activation_cuda", sources, extra_cuda_flags
)
return anti_alias_activation_cuda
except Exception as e:
print(f"CUDA compilation failed with error: {str(e)}")
raise
// ... existing code ...
#!/usr/bin/env python3
# 自动修复BigVGAN的CUDA扩展导入路径问题
import os
import sys
import re
from pathlib import Path
def patch_import_paths():
"""修复BigVGAN中的CUDA扩展导入路径问题"""
print("正在修复BigVGAN CUDA扩展导入路径...")
# 获取项目根目录
project_root = Path('/workspace')
bigvgan_path = project_root / 'index-tts' / 'indextts' / 'BigVGAN' / 'bigvgan.py'
if not bigvgan_path.exists():
print(f"错误: 找不到文件 {bigvgan_path}")
return False
# 读取文件内容
with open(bigvgan_path, 'r', encoding='utf-8') as f:
content = f.read()
# 替换导入路径
pattern = r'from alias_free_activation\.cuda\.activation1d import'
replacement = r'from indextts.BigVGAN.alias_free_activation.cuda.activation1d import'
new_content = re.sub(pattern, replacement, content)
if new_content == content:
print("无需修复: 导入路径已经正确")
return True
# 备份原文件
backup_path = str(bigvgan_path) + '.bak'
with open(backup_path, 'w', encoding='utf-8') as f:
f.write(content)
# 写入修复后的内容
with open(bigvgan_path, 'w', encoding='utf-8') as f:
f.write(new_content)
print(f"已修复导入路径并备份原文件到 {backup_path}")
return True
def compile_cuda_extension():
"""编译CUDA扩展"""
print("正在编译BigVGAN CUDA扩展...")
try:
# 获取项目根目录
project_root = Path('/workspace')
cuda_dir = project_root / 'index-tts' / 'indextts' / 'BigVGAN' / 'alias_free_activation' / 'cuda'
# 切换到CUDA目录
os.chdir(cuda_dir)
# 确保环境变量设置正确
os.environ['PYTHONPATH'] = f"{project_root}/index-tts:{os.environ.get('PYTHONPATH', '')}"
# 导入并运行编译函数
sys.path.insert(0, str(project_root / 'index-tts'))
from indextts.BigVGAN.alias_free_activation.cuda.load import load
# 编译CUDA扩展
result = load()
print("CUDA扩展编译成功!")
return True
except Exception as e:
print(f"编译CUDA扩展时出错: {e}")
import traceback
traceback.print_exc()
return False
if __name__ == "__main__":
print("开始修复BigVGAN CUDA扩展...")
# 修复导入路径
if patch_import_paths():
# 编译CUDA扩展
if compile_cuda_extension():
print("所有修复已完成!")
else:
print("CUDA扩展编译失败。")
else:
print("导入路径修复失败。")