xai-org/x-algorithm · error · ValueError

Unknown strategy: {strategy!r}

Error message

Unknown strategy: {strategy!r}

What it means

compute_post_age_bucket maps post age (minutes) into buckets using the configured strategy; implemented strategies include (per the source) an earlier branch and 'log1p' (floor(log1p(age)/log1p(max_mins) * n_buckets) + 1). Any other strategy string raises ValueError, and the resulting bucket is clipped to [0, n_buckets + 1] with an overflow bucket.

Source

Thrown at phoenix/xrex/models/recsys_model.py:130

    impr_ts_sec: jax.Array,
    post_creation_ts_sec: jax.Array,
    granularity_mins: int = 60,
    max_mins: int = POST_AGE_MAX_MINUTES,
    strategy: Literal["linear", "log1p"] = "linear",
    num_buckets: int = 80,
) -> jax.Array:
    post_age_minutes = (impr_ts_sec - post_creation_ts_sec) // 60

    if strategy == "linear":
        n_buckets = max_mins // granularity_mins
        bucket = (post_age_minutes // granularity_mins) + 1
    elif strategy == "log1p":
        n_buckets = num_buckets
        log_max = math.log1p(max_mins)
        clamped_age = jnp.maximum(post_age_minutes, 0).astype(jnp.float32)
        bucket = jnp.floor(jnp.log1p(clamped_age) / log_max * n_buckets).astype(jnp.int32) + 1
    else:
        raise ValueError(f"Unknown strategy: {strategy!r}")

    overflow_bucket = n_buckets + 1
    bucket = jnp.clip(bucket, 0, overflow_bucket)

    bucket = jnp.where(
        (post_age_minutes < 0) | (impr_ts_sec == 0) | (post_creation_ts_sec == 0),
        0,
        bucket,
    )
    return bucket.astype(jnp.int32)


ENGAGEMENT_COUNT_NUM_BUCKETS = 32
ENGAGEMENT_COUNT_MAX_BUCKET: dict[CategoricalFeature, int] = {
    CategoricalFeature.favCountBucketSeq: 18,
    CategoricalFeature.replyCountBucketSeq: 13,
    CategoricalFeature.repostCountBucketSeq: 15,
    CategoricalFeature.quoteCountBucketSeq: 13,

View on GitHub (pinned to 24c60942c5)

Solutions

  1. Use a strategy implemented in compute_post_age_bucket (check the branches in recsys_model.py, e.g. 'log1p').
  2. Fix typos/casing in the config string.
  3. Add an elif branch for a new strategy if the bucketing math is known.

Example fix

# before
post_age_bucket_strategy: log

# after
post_age_bucket_strategy: log1p
Defensive patterns

Strategy: validation

Validate before calling

assert strategy in {"linear", "log1p"}, strategy  # mirror implemented branches

Type guard

def is_supported_bucket_strategy(s: str) -> bool:
    return s in {"linear", "log1p"}

Prevention

When it happens

Trigger: Calling build_inputs with post_age_bucket_strategy set to e.g. "sqrt", "linear ", or "Log1P" (case-sensitive) in the model config.

Common situations: Experimenting with bucketing schemes; porting configs between versions where strategy names changed.

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/4851934991ccc858. Report an issue: GitHub.