Skip to content

fix: fix wrong dtype - #359

Open
Freed-Wu wants to merge 3 commits into
InterDigitalInc:masterfrom
ustcivclab:dtype
Open

fix: fix wrong dtype#359
Freed-Wu wants to merge 3 commits into
InterDigitalInc:masterfrom
ustcivclab:dtype

Conversation

@Freed-Wu

@Freed-Wu Freed-Wu commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

Similar as #351

@eeshsaxena eeshsaxena left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change looks right, and it matches the same fix in #351.

There is one more spot with the identical pattern that this PR does not touch: compressai/models/vbr.py:925, inside that model's own _decompress_ar:

rv = (
    torch.Tensor(rv).reshape(1, -1, 1, 1).to(scales_hat.device)
)  # TODO: move rv to gpu ?
...
rv = self.gaussian_conditional.dequantize(rv, means_hat)

torch.Tensor(rv) builds a float32 CPU tensor, and the .to(scales_hat.device) only fixes the device, not the dtype, so this path still hits the same mismatch you are fixing here whenever means_hat is not float32 (for example half-precision inference). The same change works there:

rv = torch.tensor(rv, dtype=means_hat.dtype, device=means_hat.device).reshape(1, -1, 1, 1)

Might be worth folding into this PR so both decode paths are covered.

postprocessing should not occur in neural network interference.
For quantization, it is incorrect to assume the range is [0, 1].
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants