diff --git a/docs/api/index.md b/docs/api/index.md index 144669b8d..8210c64a9 100644 --- a/docs/api/index.md +++ b/docs/api/index.md @@ -53,7 +53,6 @@ runtime :nosignatures: kernel - set_default_settings Config Settings ``` diff --git a/docs/api/settings.md b/docs/api/settings.md index 469f3e219..a9a28c0f4 100644 --- a/docs/api/settings.md +++ b/docs/api/settings.md @@ -34,7 +34,8 @@ Settings can be configured via: 1. **Environment variables** 2. **Keyword arguments to `@helion.kernel`** -3. **Global defaults via `helion.set_default_settings()`** + +If both are provided, decorator arguments take precedence. ## Configuration Examples @@ -62,24 +63,6 @@ def my_kernel(x: torch.Tensor) -> torch.Tensor: return result ``` -### Global Configuration - -```python -import logging -import helion - -# Set global defaults -with helion.set_default_settings( - ignore_warnings=[helion.exc.TensorOperationInWrapper], - autotune_log_level=logging.WARNING -): - # All kernels in this block use these settings - @helion.kernel - def kernel1(x): ... - - @helion.kernel - def kernel2(x): ... -``` ## Settings Reference @@ -231,9 +214,7 @@ Built-in values for ``HELION_AUTOTUNER`` include ``"PatternSearch"``, ``"Differe ## Functions ```{eval-rst} -.. autofunction:: set_default_settings -.. automethod:: Settings.default ``` ## Environment Variable Reference diff --git a/helion/__init__.py b/helion/__init__.py index 508b0bd9b..b02e42e47 100644 --- a/helion/__init__.py +++ b/helion/__init__.py @@ -14,7 +14,6 @@ from .runtime import kernel as jit # alias from .runtime.settings import RefMode from .runtime.settings import Settings -from .runtime.settings import set_default_settings __all__ = [ "Config", @@ -28,7 +27,6 @@ "language", "next_power_of_2", "runtime", - "set_default_settings", ] _logging.init_logs() diff --git a/helion/runtime/kernel.py b/helion/runtime/kernel.py index b875caebf..b905850e3 100644 --- a/helion/runtime/kernel.py +++ b/helion/runtime/kernel.py @@ -79,7 +79,7 @@ def __init__( Args: fn: The function to be compiled as a Helion kernel. configs: A list of configurations to use for the kernel. - settings: The settings to be used by the Kernel. If None, default settings are used. + settings: The settings to be used by the Kernel. If None, a new `Settings()` instance is created. key: Optional callable that returns an extra hashable component for specialization. """ super().__init__() @@ -88,7 +88,7 @@ def __init__( self.name: str = fn.__name__ self.fn: types.FunctionType = fn self.signature: inspect.Signature = inspect.signature(fn) - self.settings: Settings = settings or Settings.default() + self.settings: Settings = settings or Settings() self._key_fn: Callable[..., Hashable] | None = key self.configs: list[Config] = [ Config(**c) if isinstance(c, dict) else c # pyright: ignore[reportArgumentType] diff --git a/helion/runtime/settings.py b/helion/runtime/settings.py index 2a9484d88..d4e4315d5 100644 --- a/helion/runtime/settings.py +++ b/helion/runtime/settings.py @@ -3,7 +3,6 @@ import dataclasses import logging import os -import threading import time from typing import TYPE_CHECKING from typing import Literal @@ -20,47 +19,15 @@ from .ref_mode import RefMode if TYPE_CHECKING: - from contextlib import AbstractContextManager - from ..autotuner.base_search import BaseAutotuner from .kernel import BoundKernel - class _TLS(Protocol): - default_settings: Settings | None - class AutotunerFunction(Protocol): def __call__( self, bound_kernel: BoundKernel, args: Sequence[object], **kwargs: object ) -> BaseAutotuner: ... -_tls: _TLS = cast("_TLS", threading.local()) - - -def set_default_settings(settings: Settings) -> AbstractContextManager[None, None]: - """ - Set the default settings for the current thread and return a context manager - that restores the previous settings upon exit. - - Args: - settings: The Settings object to set as the default. - - Returns: - AbstractContextManager[None, None]: A context manager that restores the previous settings upon exit. - """ - prior = getattr(_tls, "default_settings", None) - _tls.default_settings = settings - - class _RestoreContext: - def __enter__(self) -> None: - pass - - def __exit__(self, *args: object) -> None: - _tls.default_settings = prior - - return _RestoreContext() - - def default_autotuner_fn( bound_kernel: BoundKernel, args: Sequence[object], **kwargs: object ) -> BaseAutotuner: @@ -254,15 +221,8 @@ class Settings(_Settings): def __init__(self, **settings: object) -> None: """ Initialize the Settings object with the provided dictionary of settings. - If no settings are provided, the default settings are used (see `set_default_settings`). - - Args: - settings: Keyword arguments representing various settings. """ - if defaults := getattr(_tls, "default_settings", None): - settings = {**defaults.to_dict(), **settings} - super().__init__(**settings) # pyright: ignore[reportArgumentType] self._check_ref_eager_mode_before_print_output_code() @@ -323,16 +283,3 @@ def _check_ref_eager_mode_before_print_output_code(self) -> None: """ if self.ref_mode == RefMode.EAGER and self.print_output_code: raise exc.RefEagerModeCodePrintError - - @staticmethod - def default() -> Settings: - """ - Get the default Settings object. If no default settings are set, create a new one. - - Returns: - Settings: The default Settings object. - """ - result = getattr(_tls, "default_settings", None) - if result is None: - _tls.default_settings = result = Settings() - return result