{"record":{"id":"814e17bbdaf80a8b","repo":"sgl-project/sglang","slug":"invalid-direction-direction","errorCode":null,"errorMessage":"Invalid direction: {direction}","messagePattern":"Invalid direction: (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/sglang/multimodal_gen/runtime/models/bridges/mova_dual_tower.py","lineNumber":607,"sourceCode":"        primary_hidden_states: torch.Tensor,\n        condition_hidden_states: torch.Tensor,\n        x_freqs: Optional[Tuple[torch.Tensor, torch.Tensor]] = None,\n        y_freqs: Optional[Tuple[torch.Tensor, torch.Tensor]] = None,\n        condition_scale: Optional[float] = None,\n        video_grid_size: Optional[Tuple[int, int, int]] = None,\n    ) -> torch.Tensor:\n        \"\"\"Applies conditional control at the DiT hidden states level.\"\"\"\n        if not self.controller.should_interact(\n            layer_idx, direction, self.interaction_mapping\n        ):\n            return primary_hidden_states\n\n        if direction == \"a2v\":\n            conditioner = self.audio_to_video_conditioners[str(layer_idx)]\n        elif direction == \"v2a\":\n            conditioner = self.video_to_audio_conditioners[str(layer_idx)]\n        else:\n            raise ValueError(f\"Invalid direction: {direction}\")\n\n        conditioned_features = conditioner(\n            x=primary_hidden_states,\n            y=condition_hidden_states,\n            x_freqs=x_freqs,\n            y_freqs=y_freqs,\n            video_grid_size=video_grid_size,\n        )\n\n        if self.trainable_condition_scale and condition_scale is not None:\n            logger.warning(\n                \"The current model has a trainable condition_scale, but condition_scale \"\n                \"was passed externally. Ignoring the trainable condition_scale and \"\n                \"using the external condition_scale=%s.\",\n                condition_scale,\n            )\n\n        scale = condition_scale if condition_scale is not None else self.condition_scale","sourceCodeStart":589,"sourceCodeEnd":625,"githubUrl":"https://github.com/sgl-project/sglang/blob/0132848349585cfe6aae51c4941cbae872505f8a/python/sglang/multimodal_gen/runtime/models/bridges/mova_dual_tower.py#L589-L625","documentation":"apply_conditional_control routes conditioning between the audio and vision towers based on a direction string ('a2v' or 'v2a'); any other string falls through to the else and raises. It is called from forward, so a bad direction surfaces at inference time, not init.","triggerScenarios":"Calling forward on the dual tower (or apply_conditional_control directly) with direction set to something like 'both', 'av', 'A2V', or an unset/None variable.","commonSituations":"A config field that defaults to a sentinel value; string interpolation building the direction dynamically and producing an empty or malformed value; new feature branches adding bidirectional conditioning without extending this router.","solutions":["Set direction to exactly 'a2v' or 'v2v'-style supported values — check the elif chain: 'a2v' or 'v2a'","Validate/normalize direction (lowercase, strip) before calling forward","Type it as Literal['a2v','v2a'] in your calling code so mistakes surface at type-check time","If you need a new mode, extend apply_conditional_control rather than passing an unknown string"],"exampleFix":"# before\nout = tower(hidden_states, direction=cfg.mode)  # cfg.mode == \"both\"\n# after\nfrom typing import Literal\nmode: Literal[\"a2v\", \"v2a\"] = \"a2v\"\nout = tower(hidden_states, direction=mode)","handlingStrategy":"type-guard","validationCode":"direction = direction.strip().lower()\nassert direction in (\"a2v\", \"v2a\"), f\"invalid direction: {direction}\"","typeGuard":"from typing import Literal\nDirection = Literal[\"a2v\", \"v2a\"]\ndef is_direction(d: str) -> bool:\n    return d in (\"a2v\", \"v2a\")","tryCatchPattern":"try:\n    out = tower(hidden_states, direction=direction)\nexcept ValueError as e:\n    if \"Invalid direction\" in str(e):\n        direction = \"a2v\"  # safe default\n        out = tower(hidden_states, direction=direction)\n    else:\n        raise","preventionTips":["Type direction fields as Literal['a2v','v2a'] in configs and function signatures","Normalize strings (strip/lower) at the config boundary"],"tags":["enum-value","routing","dual-tower","forward-pass"],"backgroundTag":"invalid-argument-value","analyzedSha":"0132848349585cfe6aae51c4941cbae872505f8a","analyzedAt":"2026-08-28T05:10:05.995Z","schemaVersion":2},"datasetVersion":"2026-08-28T06:17:29.519Z"}