Enable conv-direct in the default native speed profile

Measured on the fresh linux x64 prebuilt (z-image Q8_0, sd-cli, 192 CPU
threads, 512x512, 9 steps, steady state): sampling 56.1s vs 51.3s (about
9 percent faster), VAE decode unchanged, peak RSS identical. The sd.cpp
engine only serves the no-GPU tier, so the default profile now matches
max: --diffusion-fa plus --diffusion-conv-direct.
This commit is contained in:
Daniel Han 2026-07-04 13:46:59 +00:00
commit 24de50062c
2 changed files with 11 additions and 8 deletions

View file

@ -120,10 +120,13 @@ class SdCppUpscaleParams:
# Native (sd.cpp) speed profiles, the engine-side analogue of diffusion_speed's
# modes. off: nothing (default). default: --diffusion-fa (flash attention; upstream
# reports it usually speeds CUDA and cuts attention memory, near-lossless). max: also
# --diffusion-conv-direct (direct conv; helps some backends, but measured +45% on
# CUDA here, so it stays opt-in/experimental, never auto-on for CUDA).
# modes. off: nothing (default). default: --diffusion-fa (flash attention;
# near-lossless attention speed/memory win) + --diffusion-conv-direct. Direct conv
# is numerically exact (no quality tradeoff) and, on the CPU tier this engine
# actually serves (Studio routes to sd.cpp only on no-GPU hosts), the A/B on the
# master-741-484baa4 linux build measured z-image Q8_0 sampling 56.1s -> 51.3s
# (~9%) with decode and peak RSS unchanged, so it belongs in the default profile
# rather than opt-in. max keeps it too (the profiles stay a superset chain).
NATIVE_SPEED_OFF = "off"
NATIVE_SPEED_DEFAULT = "default"
NATIVE_SPEED_MAX = "max"
@ -140,9 +143,7 @@ def native_speed_flags(speed_mode: Optional[str]) -> list[str]:
mode = (speed_mode or NATIVE_SPEED_OFF).strip().lower()
if mode in ("", NATIVE_SPEED_OFF):
return []
if mode == NATIVE_SPEED_DEFAULT:
return ["--diffusion-fa"]
if mode == NATIVE_SPEED_MAX:
if mode in (NATIVE_SPEED_DEFAULT, NATIVE_SPEED_MAX):
return ["--diffusion-fa", "--diffusion-conv-direct"]
raise ValueError(f"native speed_mode must be one of {NATIVE_SPEED_MODES}, got '{speed_mode}'")

View file

@ -54,7 +54,9 @@ def test_native_speed_flags():
assert native_speed_flags(None) == []
assert native_speed_flags("off") == []
assert native_speed_flags("") == []
assert native_speed_flags("default") == ["--diffusion-fa"]
# default now includes conv-direct: measured ~9% faster sampling on CPU
# (z-image Q8_0, 192 threads) with identical RSS and unchanged decode.
assert native_speed_flags("default") == ["--diffusion-fa", "--diffusion-conv-direct"]
assert native_speed_flags("max") == ["--diffusion-fa", "--diffusion-conv-direct"]
with pytest.raises(ValueError):
native_speed_flags("ludicrous")