{"record":{"id":"0e9a840aca00c1db","repo":"sgl-project/sglang","slug":"minimax-h3-adaln-cache-must-be-built-on-cuda","errorCode":null,"errorMessage":"MiniMax H3 AdaLN cache must be built on CUDA","messagePattern":"MiniMax H3 AdaLN cache must be built on CUDA","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/sglang/multimodal_gen/tools/build_minimax_h3_adaln_cache.py","lineNumber":159,"sourceCode":"    *,\n    weight_map: dict[str, str],\n    files: dict[str, Any],\n    device: torch.device,\n) -> torch.Tensor:\n    tensor_file = files[weight_map[name]]\n    return tensor_file.get_tensor(name).to(device)\n\n\ndef main() -> None:\n    args = _parse_args()\n    if args.num_inference_steps < 2 and args.timesteps is None:\n        raise ValueError(\"--num-inference-steps must be at least 2\")\n    mode_variant = _MODE_VARIANTS[args.mode]\n    if args.model_variant != mode_variant:\n        raise ValueError(f\"--mode {args.mode} requires {mode_variant}\")\n    device = torch.device(args.device)\n    if device.type != \"cuda\" or not torch.cuda.is_available():\n        raise ValueError(\"MiniMax H3 AdaLN cache must be built on CUDA\")\n\n    index_path = args.transformer_path / \"model.safetensors.index.json\"\n    with index_path.open() as f:\n        weight_map = json.load(f)[\"weight_map\"]\n\n    plans = _cache_timestep_plans(args)\n    if not plans or any(plan.numel() == 0 for plan in plans):\n        raise ValueError(\"AdaLN cache must cover at least one timestep plan\")\n    max_plan_length = max(plan.numel() for plan in plans)\n    plan_timesteps = torch.zeros((len(plans), max_plan_length), dtype=torch.float32)\n    plan_lengths = torch.tensor([plan.numel() for plan in plans], dtype=torch.int64)\n    block_params = torch.empty(\n        (len(plans), max_plan_length, _NUM_BLOCKS, _BLOCK_PARAM_WIDTH),\n        dtype=torch.bfloat16,\n    )\n    final_params = torch.empty(\n        (len(plans), max_plan_length, _FINAL_PARAM_WIDTH), dtype=torch.bfloat16\n    )","sourceCodeStart":141,"sourceCodeEnd":177,"githubUrl":"https://github.com/sgl-project/sglang/blob/0132848349585cfe6aae51c4941cbae872505f8a/python/sglang/multimodal_gen/tools/build_minimax_h3_adaln_cache.py#L141-L177","documentation":"The AdaLN cache precomputation kernels require CUDA; the tool refuses to run when --device is not a CUDA device or when torch.cuda.is_available() is False, even if the device string itself says cuda.","triggerScenarios":"Running the tool with --device cpu, or on a machine/container where no usable CUDA device is visible.","commonSituations":"Building the cache on a CPU-only box or inside a container without GPU passthrough; CUDA driver mismatch making torch.cuda.is_available() False; typo in the device string.","solutions":["Run on a machine with a working GPU and CUDA toolchain","Pass --device cuda (or a specific cuda:N)","If GPU is present, fix the environment (driver, CUDA-visible-devices, container runtime) so torch.cuda.is_available() returns True"],"exampleFix":"# before\n--device cpu\n# after\n--device cuda","handlingStrategy":"validation","validationCode":"import torch\nif not torch.cuda.is_available():\n    raise SystemExit(\"CUDA required; no GPU visible\")","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Gate GPU-only tooling behind an availability check in wrappers","Verify nvidia-smi and container GPU passthrough before launching"],"tags":["cuda","environment","cli"],"backgroundTag":"cuda-unavailable","analyzedSha":"0132848349585cfe6aae51c4941cbae872505f8a","analyzedAt":"2026-08-28T05:10:05.995Z","schemaVersion":2},"datasetVersion":"2026-08-28T06:17:29.519Z"}