{"record":{"id":"488fd0dc92aa158d","repo":"hpcaitech/Open-Sora","slug":"dtype-dtype","errorCode":null,"errorMessage":"dtype: {dtype}","messagePattern":"dtype: (.+?)","errorType":"exception","errorClass":"NotImplementedError","httpStatus":null,"severity":"error","filePath":"opensora/models/vae/losses.py","lineNumber":105,"sourceCode":"    def __init__(\n        self,\n        logvar_init=0.0,\n        perceptual_loss_weight=1.0,\n        kl_loss_weight=5e-4,\n        device=\"cpu\",\n        dtype=\"bf16\",\n    ):\n        super().__init__()\n\n        if type(dtype) == str:\n            if dtype == \"bf16\":\n                dtype = torch.bfloat16\n            elif dtype == \"fp16\":\n                dtype = torch.float16\n            elif dtype == \"fp32\":\n                dtype = torch.float32\n            else:\n                raise NotImplementedError(f\"dtype: {dtype}\")\n\n        # KL Loss\n        self.kl_weight = kl_loss_weight\n        # Perceptual Loss\n        self.perceptual_loss_fn = LPIPS().eval().to(device, dtype)\n        self.perceptual_loss_fn.requires_grad_(False)\n        self.perceptual_loss_weight = perceptual_loss_weight\n        self.logvar = nn.Parameter(torch.ones(size=()) * logvar_init)\n\n    def forward(\n        self,\n        video,\n        recon_video,\n        posterior,\n    ) -> dict:\n        video.size(0)\n        video = rearrange(video, \"b c t h w -> (b t) c h w\").contiguous()\n        recon_video = rearrange(recon_video, \"b c t h w -> (b t) c h w\").contiguous()","sourceCodeStart":87,"sourceCodeEnd":123,"githubUrl":"https://github.com/hpcaitech/Open-Sora/blob/7ad6a96a135feb81f755c84fb391818718f6beb2/opensora/models/vae/losses.py#L87-L123","documentation":"When the VAE loss module receives dtype as a string, it maps 'bf16'→torch.bfloat16, 'fp16'→torch.float16, 'fp32'→torch.float32. Any other string (or a numeric dtype code passed as a string like 'float32' or '16') hits the else and raises NotImplementedError.","triggerScenarios":"Constructing the loss with dtype=\"float32\" (with the 'float' prefix), dtype='16', or any string outside {'bf16','fp16','fp32'}. Note passing a real torch.dtype object skips the string parsing entirely.","commonSituations":"Config files using numpy-style names ('float16', 'float32') instead of the short codes; generated configs that stringify numeric dtypes.","solutions":["Use the exact short strings: 'bf16', 'fp16', or 'fp32'","Or pass the torch dtype object directly, e.g. torch.float16 instead of a string","Fix the config generator/normalizer that produces 'float16'-style names"],"exampleFix":"# before\nloss = VAELoss(..., dtype=\"float16\")\n# after\nloss = VAELoss(..., dtype=\"fp16\")  # or dtype=torch.float16","handlingStrategy":"validation","validationCode":"DTYPE_MAP = {\"bf16\": torch.bfloat16, \"fp16\": torch.float16, \"fp32\": torch.float32}\ndtype = DTYPE_MAP.get(dtype_str, dtype_str) if isinstance(dtype_str, str) else dtype_str\nassert isinstance(dtype, torch.dtype), f\"bad dtype {dtype_str!r}\"","typeGuard":"def resolve_dtype(d):\n    return {\"bf16\": torch.bfloat16, \"fp16\": torch.float16, \"fp32\": torch.float32}.get(d, d) if isinstance(d, str) else d","tryCatchPattern":null,"preventionTips":["Normalize dtype strings at config load","Prefer torch.dtype objects over strings in new code","Ban 'float16'-style names in config linters"],"tags":["dtype","training","loss","config"],"backgroundTag":"unsupported-enum-value","analyzedSha":"7ad6a96a135feb81f755c84fb391818718f6beb2","analyzedAt":"2026-08-28T16:58:37.171Z","schemaVersion":2},"datasetVersion":"2026-08-28T21:17:43.275Z"}