{"record":{"id":"6747785900edbefa","repo":"sgl-project/sglang","slug":"refined-prompt-embeddings-must-have-hidden-width","errorCode":null,"errorMessage":"refined prompt embeddings must have hidden width {self.hidden_size}, got {int(text_embed.shape[-1])}","messagePattern":"refined prompt embeddings must have hidden width (.+?), got (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/sglang/multimodal_gen/runtime/models/dits/minimax_h3.py","lineNumber":2260,"sourceCode":"            # BCG turns this request-varying host constant into a scalar input\n            # so different live lengths can replay one padded-text signature.\n            # _embed is an eager graph break, so this value is read outside\n            # captured CUDA graphs.\n            text_len = int(refined_prompt_embeds_length.item())\n        else:\n            text_len = int(refined_prompt_embeds_length)\n        if text_len <= 0 or text_len > int(text_embeddings_selected.shape[0]):\n            raise ValueError(\n                \"refiner cu_seqlens live text length must be in \"\n                f\"[1, {int(text_embeddings_selected.shape[0])}], got {text_len}\"\n            )\n        text_pos = text_pos[:text_len]\n        if refined_prompt_embeds_length is not None:\n            text_embed = text_embeddings_selected[:text_len].to(\n                device=device, dtype=_BF16_DTYPE\n            )\n            if int(text_embed.shape[-1]) != self.hidden_size:\n                raise ValueError(\n                    \"refined prompt embeddings must have hidden width \"\n                    f\"{self.hidden_size}, got {int(text_embed.shape[-1])}\"\n                )\n        else:\n            text_embed = self.refine_prompt_embeds(\n                text_embeddings_selected,\n                refiner_cu_seqlens,\n                device=device,\n            )\n\n        local_seq_len = row_stop - row_start\n        trusted_layout = local_embedding_layout is not None\n        if trusted_layout:\n            used_len = text_len + int(img_pos.numel()) + int(audio_pos.numel())\n            local_live_rows = min(max(used_len - row_start, 0), local_seq_len)\n            embeddings = torch.empty(\n                (local_seq_len, self.hidden_size), device=device, dtype=_BF16_DTYPE\n            )","sourceCodeStart":2242,"sourceCodeEnd":2278,"githubUrl":"https://github.com/sgl-project/sglang/blob/0132848349585cfe6aae51c4941cbae872505f8a/python/sglang/multimodal_gen/runtime/models/dits/minimax_h3.py#L2242-L2278","documentation":"Raised when externally supplied refined prompt embeddings have a last-dimension (hidden width) that does not equal self.hidden_size of the DiT. The refiner path requires embeddings already in the model's hidden size before slicing/casting to bfloat16.","triggerScenarios":"Passing refined_prompt_embeds (via packed sequence params) whose feature dimension differs from the model's configured hidden_size, e.g. raw encoder output width instead of projected embeddings.","commonSituations":"Swapping in a different text encoder or refiner checkpoint whose output width differs; passing unprojected CLIP/T5 outputs directly instead of the refine_prompt_embeds projection output.","solutions":["Project the external embeddings to hidden_size before passing them (or use the model's internal refine_prompt_embeds by omitting the length so the else-branch runs)","Check the config's hidden_size against the embedding producer's output dim","Re-derive embeddings with the matching refiner checkpoint"],"exampleFix":"// before\nemb = text_encoder(x)            # width != model.hidden_size\nmodel.forward(..., refined_prompt_embeds=emb, ...)\n// after\nemb = projector(text_encoder(x))  # width == model.hidden_size\nmodel.forward(..., refined_prompt_embeds=emb, ...)","handlingStrategy":"validation","validationCode":"if refined_prompt_embeds is not None:\n    assert refined_prompt_embeds.shape[-1] == model.hidden_size, refined_prompt_embeds.shape","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Project embeddings to model.hidden_size at the producer side","Pin encoder/refiner checkpoints that match the DiT config"],"tags":["minimax-h3","hidden-size","embedding-width"],"backgroundTag":"embedding-dimension-mismatch","analyzedSha":"0132848349585cfe6aae51c4941cbae872505f8a","analyzedAt":"2026-08-28T05:10:05.995Z","schemaVersion":2},"datasetVersion":"2026-08-28T06:17:29.519Z"}