RioShiina commited on
Commit
2edd8e4
Β·
verified Β·
1 Parent(s): b91cf25

Upload folder using huggingface_hub

Browse files
scripts/build_sage_attention.py CHANGED
@@ -1,10 +1,9 @@
1
  import os
2
  import subprocess
3
  import sys
4
- import textwrap
5
 
6
- REPO_URL = "https://github.com/thu-ml/SageAttention.git"
7
- REPO_DIR = "SageAttention"
8
 
9
  def run_command(command, cwd=None, env=None):
10
  print(f"πŸš€ Running command: {' '.join(command)}")
@@ -17,83 +16,42 @@ def run_command(command, cwd=None, env=None):
17
  text=True
18
  )
19
 
20
- if result.returncode != 0:
21
  print(result.stdout)
22
- raise subprocess.CalledProcessError(result.returncode, command)
23
-
24
- def patch_setup_py(setup_py_path):
25
- print(f"--- [SageAttention Build] Applying patches to {setup_py_path} ---")
26
-
27
- with open(setup_py_path, 'r', encoding='utf-8') as f:
28
- content = f.read()
29
-
30
- original_cxx_flags = 'CXX_FLAGS = ["-g", "-O3", "-fopenmp", "-lgomp", "-std=c++17", "-DENABLE_BF16"]'
31
- modified_cxx_flags = 'CXX_FLAGS = ["-g", "-O3", "-std=c++17", "-DENABLE_BF16"]'
32
-
33
- if original_cxx_flags in content:
34
- content = content.replace(original_cxx_flags, modified_cxx_flags)
35
- print("πŸ”§ Patch 1/1: Removed '-fopenmp' and '-lgomp' from CXX_FLAGS.")
36
- else:
37
- print("⚠️ Patch 1/1: CXX_FLAGS line not found as expected. It might have been changed upstream. Skipping.")
38
-
39
- with open(setup_py_path, 'w', encoding='utf-8') as f:
40
- f.write(content)
41
 
42
- print("βœ… Patches applied successfully.")
 
43
 
 
 
44
 
45
  def install_sage_attention():
46
- print("--- [SageAttention Build] Checking environment ---")
 
47
 
48
- if os.path.isdir(REPO_DIR):
49
- print(f"βœ… Directory '{REPO_DIR}' already exists, assuming SageAttention is installed. Skipping build.")
50
  return
51
 
52
- print(f"⏳ Directory '{REPO_DIR}' not found. Starting a fresh installation of SageAttention.")
53
 
54
  try:
55
- print(f"--- [SageAttention Build] Step 1/3: Cloning repository ---")
56
- run_command(["git", "clone", REPO_URL])
57
- print("βœ… Repository cloned successfully.")
58
-
59
- print(f"--- [SageAttention Build] Step 2/3: Patching setup.py ---")
60
- setup_py_path = os.path.join(REPO_DIR, "setup.py")
61
- patch_setup_py(setup_py_path)
62
-
63
- print(f"--- [SageAttention Build] Step 3/3: Compiling and installing ---")
64
 
65
- build_env = os.environ.copy()
66
- build_env.update({
67
- "TORCH_CUDA_ARCH_LIST": "9.0",
68
- "EXT_PARALLEL": "4",
69
- "NVCC_APPEND_FLAGS": "--threads 8",
70
- "MAX_JOBS": "32"
71
- })
72
- print("πŸ”§ Setting build environment variables:")
73
- print(f" - TORCH_CUDA_ARCH_LIST='{build_env['TORCH_CUDA_ARCH_LIST']}'")
74
- print(f" - EXT_PARALLEL={build_env['EXT_PARALLEL']}")
75
- print(f" - NVCC_APPEND_FLAGS='{build_env['NVCC_APPEND_FLAGS']}'")
76
- print(f" - MAX_JOBS={build_env['MAX_JOBS']}")
77
-
78
- install_command = [sys.executable, "setup.py", "install"]
79
 
80
- run_command(install_command, cwd=REPO_DIR, env=build_env)
81
 
82
- print("πŸŽ‰ SageAttention compiled and installed successfully! ---")
83
 
84
- except FileNotFoundError:
85
- print("❌ ERROR: 'git' command not found. Please ensure Git is installed in your environment.")
86
- sys.exit(1)
87
  except subprocess.CalledProcessError as e:
88
  print(f"❌ Command failed with return code: {e.returncode}")
89
  print(f"❌ Command: {' '.join(e.cmd)}")
90
  print("❌ SageAttention installation failed. Please check the logs above for details.")
91
- sys.exit(1)
92
  except Exception as e:
93
- print(f"❌ An unknown error occurred: {e}")
94
- sys.exit(1)
95
 
96
  if __name__ == "__main__":
97
- if os.path.isdir(REPO_DIR):
98
- print(f"Note: To force a rebuild, please delete the '{REPO_DIR}' directory first.")
99
  install_sage_attention()
 
1
  import os
2
  import subprocess
3
  import sys
4
+ import importlib.util
5
 
6
+ WHEEL_URL = "https://huggingface.co/RioShiina/Sage-Attention-ZeroGPU-Space-Build/resolve/main/sageattention-2.2.0-cp310-cp310-linux_x86_64.whl?download=true"
 
7
 
8
  def run_command(command, cwd=None, env=None):
9
  print(f"πŸš€ Running command: {' '.join(command)}")
 
16
  text=True
17
  )
18
 
19
+ if result.stdout:
20
  print(result.stdout)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
21
 
22
+ if result.returncode != 0:
23
+ raise subprocess.CalledProcessError(result.returncode, command)
24
 
25
+ def is_sage_installed():
26
+ return importlib.util.find_spec("sageattention") is not None
27
 
28
  def install_sage_attention():
29
+ package_name = "sageattention"
30
+ print(f"--- [SageAttention Install] Checking for {package_name} ---")
31
 
32
+ if is_sage_installed():
33
+ print(f"βœ… {package_name} package is already installed. Skipping installation.")
34
  return
35
 
36
+ print(f"⏳ {package_name} package not found. Starting installation from pre-built wheel.")
37
 
38
  try:
39
+ print(f"--- [SageAttention Install] Installing from URL: {WHEEL_URL} ---")
 
 
 
 
 
 
 
 
40
 
41
+ pip_command = [sys.executable, "-m", "pip", "install", WHEEL_URL]
 
 
 
 
 
 
 
 
 
 
 
 
 
42
 
43
+ run_command(pip_command)
44
 
45
+ print("πŸŽ‰ SageAttention installed successfully from pre-built wheel! ---")
46
 
 
 
 
47
  except subprocess.CalledProcessError as e:
48
  print(f"❌ Command failed with return code: {e.returncode}")
49
  print(f"❌ Command: {' '.join(e.cmd)}")
50
  print("❌ SageAttention installation failed. Please check the logs above for details.")
51
+ raise e
52
  except Exception as e:
53
+ print(f"❌ An unknown error occurred during installation: {e}")
54
+ raise e
55
 
56
  if __name__ == "__main__":
 
 
57
  install_sage_attention()
yaml/file_list.yaml CHANGED
@@ -416,10 +416,6 @@ file:
416
  source: "hf"
417
  repo_id: "duongve/AnimaYume"
418
  repository_file_path: "split_files/diffusion_models/AnimaYume_tuned_v04.safetensors"
419
- - filename: "anima_pencil-v1.0.safetensors"
420
- source: "hf"
421
- repo_id: "bluepen5805/anima-models"
422
- repository_file_path: "anima_pencil-v1.0.safetensors"
423
  # NewBie-Image
424
  - filename: "NewBie-Image-Exp0.1-bf16.safetensors"
425
  source: "hf"
 
416
  source: "hf"
417
  repo_id: "duongve/AnimaYume"
418
  repository_file_path: "split_files/diffusion_models/AnimaYume_tuned_v04.safetensors"
 
 
 
 
419
  # NewBie-Image
420
  - filename: "NewBie-Image-Exp0.1-bf16.safetensors"
421
  source: "hf"
yaml/model_list.yaml CHANGED
@@ -97,11 +97,6 @@ Checkpoint:
97
  unet: "AnimaYume_tuned_v04.safetensors"
98
  vae: "qwen_image_vae.safetensors"
99
  clip: "qwen_3_06b_base.safetensors"
100
- - display_name: "bluepen5805/Anima-pencil-v1.0"
101
- components:
102
- unet: "anima_pencil-v1.0.safetensors"
103
- vae: "qwen_image_vae.safetensors"
104
- clip: "qwen_3_06b_base.safetensors"
105
  - display_name: "circlestone-labs/Anima-base-v1.0"
106
  components:
107
  unet: "anima-base-v1.0.safetensors"
 
97
  unet: "AnimaYume_tuned_v04.safetensors"
98
  vae: "qwen_image_vae.safetensors"
99
  clip: "qwen_3_06b_base.safetensors"
 
 
 
 
 
100
  - display_name: "circlestone-labs/Anima-base-v1.0"
101
  components:
102
  unet: "anima-base-v1.0.safetensors"