hpcaitech/Open-Sora · error · NotImplementedError

dtype: {dtype}

Error message

dtype: {dtype}

What it means

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.

Source

Thrown at opensora/models/vae/losses.py:105

    def __init__(
        self,
        logvar_init=0.0,
        perceptual_loss_weight=1.0,
        kl_loss_weight=5e-4,
        device="cpu",
        dtype="bf16",
    ):
        super().__init__()

        if type(dtype) == str:
            if dtype == "bf16":
                dtype = torch.bfloat16
            elif dtype == "fp16":
                dtype = torch.float16
            elif dtype == "fp32":
                dtype = torch.float32
            else:
                raise NotImplementedError(f"dtype: {dtype}")

        # KL Loss
        self.kl_weight = kl_loss_weight
        # Perceptual Loss
        self.perceptual_loss_fn = LPIPS().eval().to(device, dtype)
        self.perceptual_loss_fn.requires_grad_(False)
        self.perceptual_loss_weight = perceptual_loss_weight
        self.logvar = nn.Parameter(torch.ones(size=()) * logvar_init)

    def forward(
        self,
        video,
        recon_video,
        posterior,
    ) -> dict:
        video.size(0)
        video = rearrange(video, "b c t h w -> (b t) c h w").contiguous()
        recon_video = rearrange(recon_video, "b c t h w -> (b t) c h w").contiguous()

View on GitHub (pinned to 7ad6a96a13)

Solutions

  1. Use the exact short strings: 'bf16', 'fp16', or 'fp32'
  2. Or pass the torch dtype object directly, e.g. torch.float16 instead of a string
  3. Fix the config generator/normalizer that produces 'float16'-style names

Example fix

# before
loss = VAELoss(..., dtype="float16")
# after
loss = VAELoss(..., dtype="fp16")  # or dtype=torch.float16
Defensive patterns

Strategy: validation

Validate before calling

DTYPE_MAP = {"bf16": torch.bfloat16, "fp16": torch.float16, "fp32": torch.float32}
dtype = DTYPE_MAP.get(dtype_str, dtype_str) if isinstance(dtype_str, str) else dtype_str
assert isinstance(dtype, torch.dtype), f"bad dtype {dtype_str!r}"

Type guard

def resolve_dtype(d):
    return {"bf16": torch.bfloat16, "fp16": torch.float16, "fp32": torch.float32}.get(d, d) if isinstance(d, str) else d

Prevention

When it happens

Trigger: 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.

Common situations: Config files using numpy-style names ('float16', 'float32') instead of the short codes; generated configs that stringify numeric dtypes.

Related errors


AI-assisted analysis of hpcaitech/Open-Sora@7ad6a96a13 (2026-08-28). Data as JSON: /api/errors/488fd0dc92aa158d. Report an issue: GitHub.