xai-org/x-algorithm · error · ValueError
beam_width must be >= 1, got {beam_width}
Error message
beam_width must be >= 1, got {beam_width} What it means
RecsysSIDRetrievalModel.generate validates beam_width before delegating to generate_parallel: beam search requires at least one candidate, so beam_width < 1 raises ValueError immediately. Unlike the runner-side error (sid_retrieval_runner), this is the model-level API check with no flag hint.
Source
Thrown at phoenix/xrex/models/recsys_sid_retrieval_model.py:351
)
return ln
@hk.transparent
def _decode_hidden(self, emb, mask, level, apply_ln):
hidden = self._run_transformer(emb, mask, is_training=False)
h_last = apply_ln(hidden[:, -1:, :])[:, 0, :]
return self._predict_sid_level(h_last, level)
@hk.transparent
def generate(
self,
batch: RecsysFeaturesBatch,
recsys_embeddings: RecsysEmbeddingsParameter,
beam_width: int = 1,
decode_levels: int | None = None,
) -> tuple[jax.Array, jax.Array]:
if beam_width < 1:
raise ValueError(f"beam_width must be >= 1, got {beam_width}")
return self.generate_parallel(
batch,
recsys_embeddings,
beam_width=beam_width,
decode_levels=decode_levels,
)
@hk.transparent
def _build_block_causal_mask(self, B: int, H: int, K: int, level: int) -> jax.Array:
T = H + K * level
q = jnp.arange(T)[:, None]
kv = jnp.arange(T)[None, :]
q_hist, kv_hist = q < H, kv < H
hist_causal = q_hist & kv_hist & (kv <= q)
beam_to_hist = (~q_hist) & kv_hist
same_beam = ((q - H) // level) == ((kv - H) // level)
beam_causal = (~q_hist) & (~kv_hist) & same_beam & (kv <= q)
base = hist_causal | beam_to_hist | beam_causalView on GitHub (pinned to 24c60942c5)
Solutions
- Pass beam_width=1 for greedy decoding or a larger value for beam search.
- Clamp sweep/config values: beam_width = max(1, int(beam_width)).
- Use generate_parallel directly only if you also enforce the same bound.
Example fix
# before scores, beams = model.generate(batch, emb, beam_width=0) # after scores, beams = model.generate(batch, emb, beam_width=1)
Defensive patterns
Strategy: validation
Validate before calling
beam_width = max(1, int(beam_width)) result = model.generate(batch, emb, beam_width=beam_width)
Type guard
def is_valid_beam_width(bw) -> bool:
return isinstance(bw, int) and not isinstance(bw, bool) and bw >= 1 Prevention
- Treat 1 (not 0) as the greedy/off value throughout sweep configs.
When it happens
Trigger: Calling model.generate(batch, embeddings, beam_width=0) directly, or wiring a config/sweep value that computes to 0 into the generate call.
Common situations: beam_width=0 used to mean 'greedy/off' in older code; programmatic sweeps starting at 0; config default of 0.
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
- beam_width must be >= 1, got {self.beam_width}. Use --beam_w
- k ({k}) must be <= n ({n})
- valid_block_upper and valid_block_lower must be provided tog
- {name}_block_cnt and {name}_block_idx must both be provided
- window_ms must be >= 0, got {window_ms}
AI-assisted analysis of xai-org/x-algorithm@24c60942c5 (2026-08-28).
Data as JSON: /api/errors/53a99aa99c71c0b7.
Report an issue: GitHub.