Skip to main content

omnibias.keras.activations.registry

0.0.2a1AlphaPython >=3.10Apache-2.0

Keras 3 operator layers and activation paths implemented with keras.ops for TensorFlow, JAX, or Torch.

import omnibias.keras.activations.registry
Module contract & mathematical conventions

Activation registry (Keras backend): ActivationSpec and lookup.

The ActivationSpec dataclass is defined generically in omnibias.core.spec; this module re-exports it and maintains a process-wide registry so get_activation can resolve string names like "tanh" to their full spec. The kernels stored in each spec are written against keras.ops so they run on any Keras backend.

Shared formulas do not imply universal floating-point identity. Verify dtype, shape, derivative-order support, and the stated numerical assumptions for the path you use.

Imports & aliases​

These names share a definition with another public module. Follow a name for its full contract, parameters, and examples.

Import from this moduleCanonical reference
ActivationSpecomnibias.core.ActivationSpec
FUNCTION

get_activation​

omnibias.keras.get_activationSource ↗
get_activation(name: str | ActivationSpec[Any]) -> ActivationSpec[Any]

Resolve a name (or pass-through spec) to an ActivationSpec.

Parameters

NameType & defaultContract
namepositional-or-keywordstr | ActivationSpec[Any]RequiredSee the operation contract and implementation below.
ReturnsActivationSpec[Any]
Explicit validation & failure cases
  • When not isinstance(name, str), raises TypeError(f'Expected str or ActivationSpec, got {type(name).__name__}: {name!r}').
  • When key not in _REGISTRY, raises KeyError(f'Unknown activation {name!r}. Known: {known}.').

These are explicit source guards. Backend operations may also raise for invalid shapes, dtypes, or unsupported devices.

Executed regression · tempered rejects bad scale

Recorded coverage confirms this test executed the API body. This example belongs to the pinned upstream test suite. It may use fixtures and imports from its full file. Run it from that checkout with its test dependencies installed.

def test_tempered_rejects_bad_scale() -> None:
    with pytest.raises(ValueError):
        TemperedActivation("softplus", beta=1.0, scale="bogus")
python -m pytest "packages/omnibias-keras/tests/test_tempered_blocks.py::test_tempered_rejects_bad_scale" -q
Regression example · fastpath negative order raises

This example belongs to the pinned upstream test suite. It may use fixtures and imports from its full file. Run it from that checkout with its test dependencies installed.

def test_fastpath_negative_order_raises() -> None:
    z = ops.convert_to_tensor(np.zeros(3))
    with pytest.raises(ValueError):
        get_activation("tanh").fastpath(z, -1)
python -m pytest packages/omnibias-keras/tests/test_activations.py -k test_fastpath_negative_order_raises -q
Read the implementation
def get_activation(name: str | ActivationSpec[Any]) -> ActivationSpec[Any]:
    """Resolve a name (or pass-through spec) to an :class:`ActivationSpec`."""
    if isinstance(name, ActivationSpec):
        return name
    if not isinstance(name, str):
        raise TypeError(
            f"Expected str or ActivationSpec, got {type(name).__name__}: {name!r}"
        )
    key = name.lower()
    if key not in _REGISTRY:
        known = ", ".join(sorted(set(_REGISTRY.keys())))
        raise KeyError(f"Unknown activation {name!r}. Known: {known}.")
    return _REGISTRY[key]
Other public import paths
  • omnibias.keras.get_activation
  • omnibias.keras.activations.get_activation
  • omnibias.keras.activations.registry.get_activation
FUNCTION

is_registered​

omnibias.keras.is_registeredSource ↗
is_registered(name: str) -> bool

True if name (or one of its aliases) is in the registry.

Parameters

NameType & defaultContract
namepositional-or-keywordstrRequiredSee the operation contract and implementation below.
Returnsbool
Read the implementation
def is_registered(name: str) -> bool:
    """True if ``name`` (or one of its aliases) is in the registry."""
    return isinstance(name, str) and name.lower() in _REGISTRY
Other public import paths
  • omnibias.keras.is_registered
  • omnibias.keras.activations.is_registered
  • omnibias.keras.activations.registry.is_registered
FUNCTION

list_activations​

omnibias.keras.list_activationsSource ↗
list_activations() -> list[str]

Return the canonical (non-alias) activation names, sorted.

Returnslist[str]
Executed regression · all piecewise registered

Recorded coverage confirms this test executed the API body. This example belongs to the pinned upstream test suite. It may use fixtures and imports from its full file. Run it from that checkout with its test dependencies installed.

def test_all_piecewise_registered() -> None:
    registered = set(list_activations())
    for name in _PIECEWISE_NAMES:
        assert name in registered, f"{name!r} not registered"
python -m pytest "packages/omnibias-keras/tests/test_piecewise.py::test_all_piecewise_registered" -q
Regression example · all expected activations registered

This example belongs to the pinned upstream test suite. It may use fixtures and imports from its full file. Run it from that checkout with its test dependencies installed.

def test_all_expected_activations_registered() -> None:
    registered = set(list_activations())
    for name in _NAMES:
        assert name in registered, f"{name!r} not registered"
python -m pytest packages/omnibias-keras/tests/test_activations.py -k test_all_expected_activations_registered -q
Read the implementation
def list_activations() -> list[str]:
    """Return the canonical (non-alias) activation names, sorted."""
    return sorted({spec.name for spec in _REGISTRY.values()})
Other public import paths
  • omnibias.keras.list_activations
  • omnibias.keras.activations.list_activations
  • omnibias.keras.activations.registry.list_activations
FUNCTION

register_activation​

omnibias.keras.register_activationSource ↗
register_activation(spec: ActivationSpec[Any]) -> ActivationSpec[Any]

Register an ActivationSpec under its name and aliases.

Parameters

NameType & defaultContract
specpositional-or-keywordActivationSpec[Any]RequiredSee the operation contract and implementation below.
ReturnsActivationSpec[Any]
Explicit validation & failure cases
  • When not spec.name, raises ValueError('ActivationSpec.name must be a non-empty string.').
  • When name in _REGISTRY and _REGISTRY[name] is not spec, raises ValueError(f'Activation {name!r} is already registered with a different spec.').
  • When akey in _REGISTRY and _REGISTRY[akey] is not spec, raises ValueError(f'Alias {alias!r} for activation {name!r} clashes with an existing entry.').

These are explicit source guards. Backend operations may also raise for invalid shapes, dtypes, or unsupported devices.

Read the implementation
def register_activation(spec: ActivationSpec[Any]) -> ActivationSpec[Any]:
    """Register an :class:`ActivationSpec` under its name and aliases."""
    if not spec.name:
        raise ValueError("ActivationSpec.name must be a non-empty string.")
    name = spec.name.lower()
    if name in _REGISTRY and _REGISTRY[name] is not spec:
        raise ValueError(
            f"Activation {name!r} is already registered with a different spec."
        )
    _REGISTRY[name] = spec
    for alias in spec.aliases:
        akey = alias.lower()
        if akey in _REGISTRY and _REGISTRY[akey] is not spec:
            raise ValueError(
                f"Alias {alias!r} for activation {name!r} clashes with an existing entry."
            )
        _REGISTRY[akey] = spec
    return spec
Other public import paths
  • omnibias.keras.register_activation
  • omnibias.keras.activations.register_activation
  • omnibias.keras.activations.registry.register_activation