Open-source inference server and production cluster for all the models your agent needs.
Python bgecolbertdata-pipelinedeep-learningembeddingsinferenceinference-serverinformation-retrievalllmmlmlopsnatural-language-processingnlppythonrerankingretrievalretrieval-augmented-generationsemantic-searchspladevector-search
fix(server): allow opting out of TF32 at startup (#825)
svonavac296b9620aa4
diff --git a/packages/sie_server/README.md b/packages/sie_server/README.mdindex 663a8984b..391ad2a1a 100644--- a/packages/sie_server/README.md+++ b/packages/sie_server/README.md@@ -1310,11 +1310,24 @@ advertise the declared allowlist, including cold adapters.|--|--|--|| `SIE_DEFAULT_COMPUTE_PRECISION` | `float16` | One of `float16`, `bfloat16`, `float32`. || `SIE_ATTENTION_BACKEND` | `auto` | One of `auto`, `flash_attention_2`, `sdpa`, `eager`. |+| `SIE_DISABLE_TF32` | unset (off) | Set `1` to disable Torch CUDA matmul and cuDNN TF32 at Python worker startup. Unset or `0` enables both, preserving SIE's default policy. || `SIE_DISABLE_CUDNN_SDP` | unset (off) | Set `1` to disable cuDNN for Torch scaled dot-product attention at Python worker startup. Unset or `0` leaves the current backend policy alone. |-This startup policy applies throughout the Python worker process, across all-models that use Torch SDPA. Other eligible SDPA backends remain available; it-does not guarantee Flash attention or better performance and does not disable+TF32 can accelerate float32 operations at reduced precision, and its numerical+effects depend on the model and batch shape. `SIE_DISABLE_TF32=1` applies before+model loading throughout the Python worker process. It does not convert model+weights: select a model profile with `compute_precision: float32` when assessing+float32 output consistency. Disabling TF32 can reduce throughput and does not+guarantee identical outputs across batch shapes or higher task accuracy.+cuDNN autotuning and the SDPA backend policy remain unchanged. The effective+TF32 flags are included in profile identity. Use separate worker processes for+different TF32 policies; changing the environment of a running worker does not+reconfigure it. The policy is not restored at shutdown; a fresh worker started+with the variable unset or `0` enables TF32 again.++The `SIE_DISABLE_CUDNN_SDP` startup policy applies throughout the Python worker+process, across all models that use Torch SDPA. Other eligible SDPA backends+remain available; it does not guarantee Flash attention or better performance and does not disablecuDNN generally. The policy is applied before model loading and readiness andis not restored at shutdown. Start a fresh worker process with the variableunset or `0` to restore Torch's defaults; unset or `0` does not reset a backenddiff --git a/packages/sie_server/src/sie_server/app/app_factory.py b/packages/sie_server/src/sie_server/app/app_factory.pyindex a66a21a70..e6a39e3d8 100644--- a/packages/sie_server/src/sie_server/app/app_factory.py+++ b/packages/sie_server/src/sie_server/app/app_factory.py@@ -416,18 +416,19 @@ class AppFactory:@staticmethoddef _configure_cuda_defaults() -> None:- """Enable TF32 and cudnn autotuning for faster matmuls on Ampere+ GPUs.+ """Configure process-wide CUDA math policy before loading models.- TF32 uses 19-bit precision for float32 matmuls — negligible accuracy- impact for inference, but up to 3x faster on A100/L4/H100.+ TF32 accelerates float32 operations but can change model scores.+ SIE_DISABLE_TF32 opts out without changing model compute precision.cudnn.benchmark auto-tunes convolution algorithms for static input shapes."""if not torch.cuda.is_available():return- torch.backends.cuda.matmul.allow_tf32 = True- torch.backends.cudnn.allow_tf32 = True+ allow_tf32 = not _env_flag("SIE_DISABLE_TF32")+ torch.backends.cuda.matmul.allow_tf32 = allow_tf32+ torch.backends.cudnn.allow_tf32 = allow_tf32torch.backends.cudnn.benchmark = True- logger.info("CUDA defaults: TF32 enabled, cudnn.benchmark enabled")+ logger.info("CUDA defaults: TF32 %s, cudnn.benchmark enabled", "enabled" if allow_tf32 else "disabled")@staticmethoddef _configure_sdpa_backends() -> None:diff --git a/packages/sie_server/tests/app/test_app_factory.py b/packages/sie_server/tests/app/test_app_factory.pyindex ebf5a3a59..29c6913ac 100644--- a/packages/sie_server/tests/app/test_app_factory.py+++ b/packages/sie_server/tests/app/test_app_factory.py@@ -9,6 +9,7 @@ from concurrent.futures import ThreadPoolExecutorfrom contextlib import asynccontextmanagerfrom importlib.metadata import versionfrom pathlib import Path+from types import SimpleNamespacefrom typing import Anyfrom unittest.mock import AsyncMock, MagicMock@@ -616,6 +617,61 @@ class TestModelRegistryConfig:assert created_kwargs["pinned_models"] == ["model-x", "model-y"]+class TestConfigureCudaDefaults:+ @pytest.mark.asyncio+ @pytest.mark.parametrize(+ ("flag", "expected"), [(None, True), ("0", True), ("off", True), ("1", False), (" TRUE ", False)]+ )+ async def test_policy_applies_before_registry_and_readiness(+ self, monkeypatch: pytest.MonkeyPatch, flag: str | None, expected: bool+ ) -> None:+ monkeypatch.delenv("SIE_DISABLE_TF32", raising=False)+ monkeypatch.delenv("SIE_DISABLE_CUDNN_SDP", raising=False)+ if flag is not None:+ monkeypatch.setenv("SIE_DISABLE_TF32", flag)+ matmul = SimpleNamespace(allow_tf32=not expected)+ cudnn = SimpleNamespace(allow_tf32=not expected, benchmark=False)+ fake_torch = SimpleNamespace(+ cuda=SimpleNamespace(is_available=lambda: True),+ backends=SimpleNamespace(cuda=SimpleNamespace(matmul=matmul), cudnn=cudnn),+ )+ monkeypatch.setattr("sie_server.app.app_factory.torch", fake_torch)+ monkeypatch.setattr(AppFactory, "_configure_torch_threads", MagicMock())+ for name in ("_tracing", "_metrics", "_nvml", "_ipc_server", "_graceful_shutdown"):+ monkeypatch.setattr(AppFactory, name, lambda *_args: _async_value(MagicMock()))+ monkeypatch.setattr("sie_server.app.app_factory.telemetry_sender", _async_value)+ monkeypatch.setattr("sie_server.app.app_factory.setup_tracing", MagicMock())+ monkeypatch.setattr("sie_server.app.app_factory.setup_worker_telemetry", MagicMock())+ events: list[tuple[str, bool, bool, bool]] = []++ @asynccontextmanager+ async def registry(_config: AppStateConfig) -> AsyncGenerator[MagicMock, None]:+ events.append(("registry", matmul.allow_tf32, cudnn.allow_tf32, cudnn.benchmark))+ yield MagicMock()++ @asynccontextmanager+ async def ready() -> AsyncGenerator[None, None]:+ events.append(("ready", matmul.allow_tf32, cudnn.allow_tf32, cudnn.benchmark))+ yield++ monkeypatch.setattr(AppFactory, "_model_registry", registry)+ monkeypatch.setattr(AppFactory, "_readiness_handling", ready)+ app = AppFactory.create_app(AppStateConfig())++ async with app.router.lifespan_context(app):+ assert events == [("registry", expected, expected, True), ("ready", expected, expected, True)]+ assert (matmul.allow_tf32, cudnn.allow_tf32, cudnn.benchmark) == (expected, expected, True)++ def test_cpu_startup_does_not_access_cuda_backends(self, monkeypatch: pytest.MonkeyPatch) -> None:+ monkeypatch.setenv("SIE_DISABLE_TF32", "1")+ monkeypatch.setattr(+ "sie_server.app.app_factory.torch",+ SimpleNamespace(cuda=SimpleNamespace(is_available=lambda: False)),+ )++ AppFactory._configure_cuda_defaults()++class TestConfigureSdpaBackends:_ENV_NAMES = ("SIE_DISABLE_CUDNN_SDP",