xai-org/x-algorithm · error · ValueError

unknown scaling role: {role!r}

Error message

unknown scaling role: {role!r}

What it means

_feature_scale_spec computes per-role init scales and LR multipliers for exactly two roles: 'hidden_proj' (eis / sqrt(dim)) and 'input_proj' (eis / sqrt(dim * D)). Callers (_get_proj, _get_emb_table, _get_learned_vector, _embed_entity_sid_scaled) pass the role string; anything else is an unknown scaling role and raises ValueError.

Source

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

def _feature_scale_spec(
    scale_config: ScaleConfig | None,
    embed_init_scale: float,
    model_width: int,
    role: Literal["embedding", "hidden_proj", "input_proj"],
    dim: int,
) -> tuple[float, float]:
    eis = embed_init_scale
    D = model_width
    if role == "embedding":
        lr = scale_config.emb_lr_multiplier(dim) if scale_config is not None else 1.0
        return eis / math.sqrt(dim), lr
    if role == "hidden_proj":
        lr = scale_config.hidden_lr_multiplier(dim) if scale_config is not None else 1.0
        return eis / math.sqrt(dim), lr
    if role == "input_proj":
        lr = scale_config.emb_lr_multiplier(D) if scale_config is not None else 1.0
        return eis / math.sqrt(dim * D), lr
    raise ValueError(f"unknown scaling role: {role!r}")


def _get_proj(
    name: str,
    in_dim: int,
    out_dim: int,
    config: FeaturePrepConfig,
    *,
    role: Literal["hidden_proj", "input_proj"],
) -> jax.Array:
    embed_init = hk.initializers.VarianceScaling(1.0, mode="fan_out")
    _, lr_multiplier = _feature_scale_spec(
        config.scale_config, config.embed_init_scale, config.emb_size, role, in_dim
    )
    return typing.cast(
        jax.Array,
        get_parameter(
            name,

View on GitHub (pinned to 24c60942c5)

Solutions

  1. Use role='hidden_proj' or 'input_proj' as appropriate for your call site.
  2. Fix typos in the role string at the caller.
  3. Extend _feature_scale_spec with the new role and its scale/LR formulas before using it.

Example fix

# before
_feature_scale_spec("hiddenproj", dim, D, eis, scale_config)

# after
_feature_scale_spec("hidden_proj", dim, D, eis, scale_config)
Defensive patterns

Strategy: validation

Validate before calling

assert role in {"hidden_proj", "input_proj"}, role

Type guard

def is_valid_scaling_role(r: str) -> bool:
    return r in {"hidden_proj", "input_proj"}

Prevention

When it happens

Trigger: Adding a new projection/embedding path that calls _feature_scale_spec with role="output_proj" or similar without extending the function; typos like "hiddenproj".

Common situations: Extending the recsys feature-prep code with new towers; refactors that rename roles in one place but not the spec table.

Understand the failure class

Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.

Related errors


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