{"record":{"id":"b2edf9f3c602a979","repo":"sgl-project/sglang","slug":"missing-required-argument-for-sparsevideogen2atten","errorCode":null,"errorMessage":"Missing required argument for SparseVideoGen2Attention: {name}","messagePattern":"Missing required argument for SparseVideoGen2Attention: (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/sglang/multimodal_gen/runtime/layers/attention/backends/sparse_video_gen_2_attn.py","lineNumber":112,"sourceCode":"    top_p_kmeans: float\n    min_kc_ratio: float\n    kmeans_iter_init: int\n    kmeans_iter_step: int\n    zero_step_kmeans_init: bool\n    first_layers_fp: float\n    first_times_fp: float\n    context_length: int\n    num_frame: int\n    frame_size: int\n    cache: Svg2Cache\n    prompt_length: int | None = None\n    max_seqlen_q: int | None = None\n    max_seqlen_k: int | None = None\n\n\ndef _require_kwarg(kwargs: dict[str, Any], name: str) -> Any:\n    if name not in kwargs:\n        raise ValueError(\n            f\"Missing required argument for SparseVideoGen2Attention: {name}\"\n        )\n    return kwargs[name]\n\n\nclass SparseVideoGen2AttentionMetadataBuilder(AttentionMetadataBuilder):\n\n    def __init__(self) -> None:\n        pass\n\n    def prepare(self) -> None:\n        pass\n\n    def build(  # type: ignore[override]\n        self,\n        current_timestep: int,\n        raw_latent_shape: tuple[int, ...],\n        patch_size: tuple[int, int, int],","sourceCodeStart":94,"sourceCodeEnd":130,"githubUrl":"https://github.com/sgl-project/sglang/blob/0132848349585cfe6aae51c4941cbae872505f8a/python/sglang/multimodal_gen/runtime/layers/attention/backends/sparse_video_gen_2_attn.py#L94-L130","documentation":"The SparseVideoGen2 attention metadata builder uses _require_kwarg to pull mandatory arguments out of the kwargs dict. If a required key (e.g. raw_latent_shape, patch_size, cu_seqlens, etc.) is absent, it raises ValueError naming the missing argument.","triggerScenarios":"Calling the builder's build/metadata path with a kwargs dict that omits one of the required keys consumed via _require_kwarg — e.g. forgetting raw_latent_shape or patch_size when constructing attention metadata for a Sparse Video Gen 2 (SVG2) DiT layer.","commonSituations":"Integrating SVG2 attention into a new model pipeline where the model's forward doesn't forward all metadata keys; partial refactors that rename kwargs (raw_shape vs raw_latent_shape); or a model variant that doesn't compute patch grids.","solutions":["Inspect _require_kwarg call sites in the file to get the exact required key list, and pass every one in the kwargs dict.","Fix naming mismatches between what your model passes and what the builder expects (e.g. raw_latent_shape, not latent_shape).","Update the calling model code to always include the video latent geometry metadata when this backend is selected."],"exampleFix":"# before\nmeta = builder.build(kwargs={\"cu_seqlens\": cu})  # ValueError: Missing required argument ... raw_latent_shape\n\n# after\nmeta = builder.build(kwargs={\n    \"cu_seqlens\": cu,\n    \"raw_latent_shape\": (T, H, W),\n    \"patch_size\": (pt, ph, pw),\n})","handlingStrategy":"validation","validationCode":"REQUIRED = {\"raw_latent_shape\", \"patch_size\"}  # from _require_kwarg call sites\nmissing = REQUIRED - kwargs.keys()\nassert not missing, f\"missing kwargs: {missing}\"\nmeta = builder.build(kwargs=kwargs)","typeGuard":"def has_required_kwargs(kwargs: dict, required: set[str]) -> bool:\n    return required.issubset(kwargs.keys())","tryCatchPattern":"try:\n    meta = builder.build(kwargs=kwargs)\nexcept ValueError as e:\n    if \"Missing required argument\" in str(e):\n        raise TypeError(f\"bad metadata for SVG2: {e}\") from e\n    raise","preventionTips":["Centralize the SVG2 metadata dict construction in one helper so keys can't be dropped.","Use TypedDict/dataclasses for attention metadata instead of loose dicts.","Fail fast on missing keys at pipeline setup, not per-layer forward."],"tags":["kwargs","metadata","attention-backend","validation"],"backgroundTag":"missing-required-argument","analyzedSha":"0132848349585cfe6aae51c4941cbae872505f8a","analyzedAt":"2026-08-28T05:10:05.995Z","schemaVersion":2},"datasetVersion":"2026-08-28T06:17:29.519Z"}