xai-org/x-algorithm · error · ValueError

Unknown kernel: {kernel!r}

Error message

Unknown kernel: {kernel!r}

What it means

_cyclic_kernel_weights selects the smoothing kernel for cyclic time-phase embeddings: 'box' (default path returning _box_kernel), 'triangle', and 'cosine' are implemented. Any other kernel string falls through to ValueError, so misspelled or unsupported kernel names fail fast before embedding computation.

Source

Thrown at phoenix/xrex/models/recsys_feature_prep.py:98


def _box_kernel(u: jax.Array) -> jax.Array:
    return ((u >= -0.5) & (u < 0.5)).astype(jnp.float32)


def _triangle_kernel(u: jax.Array) -> jax.Array:
    return jnp.maximum(1.0 - jnp.abs(u), 0.0)


def _cyclic_kernel_weights(u: jax.Array, kernel: str, width: float) -> jax.Array:
    if kernel == "box":
        return _box_kernel(u)
    half_width = width / 2.0
    if kernel == "triangle":
        return _triangle_kernel(u / half_width)
    if kernel == "cosine":
        return _cosine_compact_kernel(u / half_width)
    raise ValueError(f"Unknown kernel: {kernel!r}")


def _compute_cyclic_time_phase(
    impr_ts_sec: jax.Array,
    period_seconds: int,
) -> tuple[jax.Array, jax.Array]:
    sec_in_period = jnp.mod(impr_ts_sec.astype(jnp.int32), period_seconds).astype(jnp.float32)
    phase = sec_in_period / float(period_seconds)
    valid_mask = impr_ts_sec > 0
    phase = jnp.where(valid_mask, phase, 0.0)
    return phase, valid_mask


def _compute_cyclic_kernel_embedding(
    phase: jax.Array,
    valid_mask: jax.Array,
    embedding_table: jax.Array,
    fprop_dtype: jnp.dtype,

View on GitHub (pinned to 24c60942c5)

Solutions

  1. Use 'box', 'triangle', or 'cosine'.
  2. Fix typos/casing in the kernel config string.
  3. Add a new kernel function and an if-branch if a different shape is required.

Example fix

# before
kernel: triangular

# after
kernel: triangle
Defensive patterns

Strategy: validation

Validate before calling

assert kernel in {"box", "triangle", "cosine"}, kernel

Type guard

def is_supported_kernel(k: str) -> bool:
    return k in {"box", "triangle", "cosine"}

Prevention

When it happens

Trigger: Calling _compute_cyclic_kernel_embedding with kernel="gaussian", "tri", or "COSINE" (case-sensitive) via the feature-prep config.

Common situations: Feature configs ported from pipelines with more kernels; typos and casing mistakes in YAML.

Understand the failure class

Background: "Invalid value" and "allowed values are" config errors: what your library rejected and how to fix it — this error's family across 41 libraries.

Related errors


AI-assisted analysis of xai-org/x-algorithm@24c60942c5 (2026-08-28). Data as JSON: /api/errors/7a8f7e3c03cddc61. Report an issue: GitHub.