mrfakename commited on
Commit
dd7a8ed
·
1 Parent(s): cd5cb58

Use portable Sol-Attn backend

Browse files
Files changed (3) hide show
  1. README.md +3 -2
  2. h3_nvfp4.py +14 -11
  3. requirements.txt +2 -8
README.md CHANGED
@@ -28,7 +28,7 @@ Blackwell-native ComfyUI optimization path:
28
  high-signal change probe before deciding whether blocks 2–50 can reuse their previous joint residual. An optional
29
  Ultra Fast mode forecasts between exact anchors, while Exact evaluates every requested step. This is not
30
  prompt-to-video output caching.
31
- - NVIDIA Sol-Attn's native SM120 kernel sparsifies target-video attention after a dense warmup while retaining text,
32
  conditioning-video and generated-audio rows as an exact KV sink with dense prefix queries.
33
  - Segment-wise in-place AdaLN modulation and gated residual accumulation.
34
  - Each block converts its complete AdaLN table in one launch instead of six, and the final RMSNorm runs only on
@@ -103,7 +103,7 @@ does not install or launch the ComfyUI application. The small adapter uses only
103
  1. Dynamic NVFP4 activation quantization and native FP4 matrix multiplication.
104
  2. Fused in-place Q/K RMSNorm and three-axis split-half rotary embedding.
105
 
106
- Attention uses NVIDIA Sol-Attn's SM120 CuTe kernel on eligible target-video calls and keeps diffusers'
107
  `_native_cudnn` backend for the first ten denoising steps, the first two blocks, Exact mode, short sequences and any
108
  safe fallback. The MLP uses one fused QKV-style gate/up matrix, in-place SiLU×up, and the NVFP4 down projection.
109
 
@@ -156,6 +156,7 @@ exact original denoiser, set `H3_ENGINE=bf16`; this restores the 61.7 GiB unquan
156
  | `H3_FORECAST_BLEND` | `0.65` | Ultra Fast linear-trend strength; lower values stay closer to last-residual reuse. |
157
  | `H3_FUSED_ADALN` | `0` | Opt in to fused AdaLN kernels; compilation is expensive on fresh ZeroGPU workers. |
158
  | `H3_SOL_ATTN` | `1` | Use NVIDIA Sol-Attn outside Exact mode, with automatic dense fallback. |
 
159
  | `H3_SOL_ATTN_TAU` | `1.0` | Official H3 sparse-routing threshold. |
160
  | `H3_SOL_ATTN_DENSE_STEPS` | `10` | Initial denoising steps kept on exact dense attention. |
161
  | `H3_SOL_ATTN_DENSE_LAYERS` | `2` | Initial transformer blocks kept on exact dense attention. |
 
28
  high-signal change probe before deciding whether blocks 2–50 can reuse their previous joint residual. An optional
29
  Ultra Fast mode forecasts between exact anchors, while Exact evaluates every requested step. This is not
30
  prompt-to-video output caching.
31
+ - NVIDIA Sol-Attn's released Triton kernel sparsifies target-video attention after a dense warmup while retaining text,
32
  conditioning-video and generated-audio rows as an exact KV sink with dense prefix queries.
33
  - Segment-wise in-place AdaLN modulation and gated residual accumulation.
34
  - Each block converts its complete AdaLN table in one launch instead of six, and the final RMSNorm runs only on
 
103
  1. Dynamic NVFP4 activation quantization and native FP4 matrix multiplication.
104
  2. Fused in-place Q/K RMSNorm and three-axis split-half rotary embedding.
105
 
106
+ Attention uses NVIDIA Sol-Attn's portable Triton kernel on eligible target-video calls and keeps diffusers'
107
  `_native_cudnn` backend for the first ten denoising steps, the first two blocks, Exact mode, short sequences and any
108
  safe fallback. The MLP uses one fused QKV-style gate/up matrix, in-place SiLU×up, and the NVFP4 down projection.
109
 
 
156
  | `H3_FORECAST_BLEND` | `0.65` | Ultra Fast linear-trend strength; lower values stay closer to last-residual reuse. |
157
  | `H3_FUSED_ADALN` | `0` | Opt in to fused AdaLN kernels; compilation is expensive on fresh ZeroGPU workers. |
158
  | `H3_SOL_ATTN` | `1` | Use NVIDIA Sol-Attn outside Exact mode, with automatic dense fallback. |
159
+ | `H3_SOL_ATTN_BACKEND` | `triton` | Released portable backend; `auto` tries CuTe when its rapidly moving DSL/FFI ABI matches. |
160
  | `H3_SOL_ATTN_TAU` | `1.0` | Official H3 sparse-routing threshold. |
161
  | `H3_SOL_ATTN_DENSE_STEPS` | `10` | Initial denoising steps kept on exact dense attention. |
162
  | `H3_SOL_ATTN_DENSE_LAYERS` | `2` | Initial transformer blocks kept on exact dense attention. |
h3_nvfp4.py CHANGED
@@ -60,6 +60,7 @@ FIRST_BLOCK_DENSE_END = max(1, int(os.environ.get("H3_FIRST_BLOCK_DENSE_END", "2
60
  FORECAST_BLEND = min(1.0, max(0.0, float(os.environ.get("H3_FORECAST_BLEND", "0.65"))))
61
  FUSED_ADALN = os.environ.get("H3_FUSED_ADALN", "0") == "1" and triton is not None
62
  SOL_ATTN = os.environ.get("H3_SOL_ATTN", "1") == "1"
 
63
  SOL_ATTN_TAU = float(os.environ.get("H3_SOL_ATTN_TAU", "1.0"))
64
  SOL_ATTN_DENSE_STEPS = max(0, int(os.environ.get("H3_SOL_ATTN_DENSE_STEPS", "10")))
65
  SOL_ATTN_DENSE_LAYERS = max(0, int(os.environ.get("H3_SOL_ATTN_DENSE_LAYERS", "2")))
@@ -360,19 +361,21 @@ class H3SolAttention:
360
  self.dense_calls += 1
361
  return None
362
  try:
363
- from sol_attn import sol_attn
 
 
 
364
 
365
  q, k, v = (tensor.contiguous() for tensor in (query, key, value))
366
- attended = sol_attn(
367
- q,
368
- k,
369
- v,
370
- tau=SOL_ATTN_TAU,
371
- thresh_type="diag",
372
- kv_splits=1,
373
- sink_start=0,
374
- sink_tokens=self.video_start,
375
- )
376
  # An exact KV sink does not make the prefix's own queries dense. H3 jointly generates audio in that
377
  # prefix, so reproduce those rows with exact attention as NVIDIA's H3 integration does.
378
  prefix = self.video_start
 
60
  FORECAST_BLEND = min(1.0, max(0.0, float(os.environ.get("H3_FORECAST_BLEND", "0.65"))))
61
  FUSED_ADALN = os.environ.get("H3_FUSED_ADALN", "0") == "1" and triton is not None
62
  SOL_ATTN = os.environ.get("H3_SOL_ATTN", "1") == "1"
63
+ SOL_ATTN_BACKEND = os.environ.get("H3_SOL_ATTN_BACKEND", "triton").lower()
64
  SOL_ATTN_TAU = float(os.environ.get("H3_SOL_ATTN_TAU", "1.0"))
65
  SOL_ATTN_DENSE_STEPS = max(0, int(os.environ.get("H3_SOL_ATTN_DENSE_STEPS", "10")))
66
  SOL_ATTN_DENSE_LAYERS = max(0, int(os.environ.get("H3_SOL_ATTN_DENSE_LAYERS", "2")))
 
361
  self.dense_calls += 1
362
  return None
363
  try:
364
+ if SOL_ATTN_BACKEND == "triton":
365
+ from sol_attn.triton_ref import sol_attn
366
+ else:
367
+ from sol_attn import sol_attn
368
 
369
  q, k, v = (tensor.contiguous() for tensor in (query, key, value))
370
+ kwargs = {
371
+ "tau": SOL_ATTN_TAU,
372
+ "thresh_type": "diag",
373
+ "sink_start": 0,
374
+ "sink_tokens": self.video_start,
375
+ }
376
+ if SOL_ATTN_BACKEND != "triton":
377
+ kwargs["kv_splits"] = 1
378
+ attended = sol_attn(q, k, v, **kwargs)
 
379
  # An exact KV sink does not make the prefix's own queries dense. H3 jointly generates audio in that
380
  # prefix, so reproduce those rows with exact attention as NVIDIA's H3 integration does.
381
  prefix = self.video_start
requirements.txt CHANGED
@@ -19,15 +19,9 @@ spaces==0.51.1
19
  # Blackwell-native NVFP4 GEMMs and the fused Q/K RMSNorm + split-half RoPE kernel used by h3_nvfp4.py.
20
  # CUDA 13 is mandatory: older builds emulate this path and are slower than BF16.
21
  comfy-kitchen==0.2.26
22
- # NVIDIA Sol-Engine's released sparse-attention package, pinned to the H3 release. The native SM120 path uses
23
- # CuTe DSL; the package retains its portable Triton fallback if that optional backend cannot initialize.
24
  sol-attn @ git+https://github.com/NVlabs/Sana.git@46031940ba8af5d18054217e571149579424c0b1#subdirectory=techniques/sparse_backends
25
- # Sol-Engine's Aug-03 H3 kernel targets the 4.5 `cute.math.fmax` signature; 4.6 changed that API.
26
- nvidia-cutlass-dsl==4.5.3
27
- cuda-python>=13.0
28
- # Sol-Attn compiles its CuTe callable with `--enable-tvm-ffi`, but its package currently leaves this transitive
29
- # runtime undeclared. Without it the SM120 path compiles up to dispatch and then falls back to dense attention.
30
- apache-tvm-ffi>=0.1.12
31
  # No `kernels` pin on purpose: the Hub attention backends want `kernels>=0.12.3`, and that version breaks
32
  # transformers 5.8.0 at import.
33
  # PyAV muxes the generated soundtrack onto the frames (`encode_video`).
 
19
  # Blackwell-native NVFP4 GEMMs and the fused Q/K RMSNorm + split-half RoPE kernel used by h3_nvfp4.py.
20
  # CUDA 13 is mandatory: older builds emulate this path and are slower than BF16.
21
  comfy-kitchen==0.2.26
22
+ # NVIDIA Sol-Engine's released sparse-attention package, pinned to the H3 release. The Space selects its portable
23
+ # Triton backend because the separately released CuTe DSL/TVM-FFI packages currently have an incompatible ABI.
24
  sol-attn @ git+https://github.com/NVlabs/Sana.git@46031940ba8af5d18054217e571149579424c0b1#subdirectory=techniques/sparse_backends
 
 
 
 
 
 
25
  # No `kernels` pin on purpose: the Hub attention backends want `kernels>=0.12.3`, and that version breaks
26
  # transformers 5.8.0 at import.
27
  # PyAV muxes the generated soundtrack onto the frames (`encode_video`).