{"record":{"id":"53a99aa99c71c0b7","repo":"xai-org/x-algorithm","slug":"beam-width-must-be-1-got-beam-width","errorCode":null,"errorMessage":"beam_width must be >= 1, got {beam_width}","messagePattern":"beam_width must be >= 1, got (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"phoenix/xrex/models/recsys_sid_retrieval_model.py","lineNumber":351,"sourceCode":"        )\n        return ln\n\n    @hk.transparent\n    def _decode_hidden(self, emb, mask, level, apply_ln):\n        hidden = self._run_transformer(emb, mask, is_training=False)\n        h_last = apply_ln(hidden[:, -1:, :])[:, 0, :]\n        return self._predict_sid_level(h_last, level)\n\n    @hk.transparent\n    def generate(\n        self,\n        batch: RecsysFeaturesBatch,\n        recsys_embeddings: RecsysEmbeddingsParameter,\n        beam_width: int = 1,\n        decode_levels: int | None = None,\n    ) -> tuple[jax.Array, jax.Array]:\n        if beam_width < 1:\n            raise ValueError(f\"beam_width must be >= 1, got {beam_width}\")\n        return self.generate_parallel(\n            batch,\n            recsys_embeddings,\n            beam_width=beam_width,\n            decode_levels=decode_levels,\n        )\n\n    @hk.transparent\n    def _build_block_causal_mask(self, B: int, H: int, K: int, level: int) -> jax.Array:\n        T = H + K * level\n        q = jnp.arange(T)[:, None]\n        kv = jnp.arange(T)[None, :]\n        q_hist, kv_hist = q < H, kv < H\n        hist_causal = q_hist & kv_hist & (kv <= q)\n        beam_to_hist = (~q_hist) & kv_hist\n        same_beam = ((q - H) // level) == ((kv - H) // level)\n        beam_causal = (~q_hist) & (~kv_hist) & same_beam & (kv <= q)\n        base = hist_causal | beam_to_hist | beam_causal","sourceCodeStart":333,"sourceCodeEnd":369,"githubUrl":"https://github.com/xai-org/x-algorithm/blob/24c60942c5c5fdad3a6addffb4c6e6d2f228f04f/phoenix/xrex/models/recsys_sid_retrieval_model.py#L333-L369","documentation":"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.","triggerScenarios":"Calling model.generate(batch, embeddings, beam_width=0) directly, or wiring a config/sweep value that computes to 0 into the generate call.","commonSituations":"beam_width=0 used to mean 'greedy/off' in older code; programmatic sweeps starting at 0; config default of 0.","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."],"exampleFix":"# before\nscores, beams = model.generate(batch, emb, beam_width=0)\n\n# after\nscores, beams = model.generate(batch, emb, beam_width=1)","handlingStrategy":"validation","validationCode":"beam_width = max(1, int(beam_width))\nresult = model.generate(batch, emb, beam_width=beam_width)","typeGuard":"def is_valid_beam_width(bw) -> bool:\n    return isinstance(bw, int) and not isinstance(bw, bool) and bw >= 1","tryCatchPattern":null,"preventionTips":["Treat 1 (not 0) as the greedy/off value throughout sweep configs."],"tags":["sid-retrieval","beam-search","argument-validation","inference"],"backgroundTag":"invalid-argument-value","analyzedSha":"24c60942c5c5fdad3a6addffb4c6e6d2f228f04f","analyzedAt":"2026-08-28T11:40:14.686Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}