Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RuntimeError: The size of tensor a (2048) must match the size of tensor b (1024) at non-singleton dimension 0 #4

Open
ClancyCC opened this issue Jul 28, 2024 · 0 comments

Comments

@ClancyCC
Copy link

Hello! I got RuntimeError as follow. I found the shapes of factor_best.reshape(-1, 256, 1) and absmax are respectively [2048,256,1] and [1024,256,1].

RuntimeError: The size of tensor a (2048) must match the size of tensor b (1024) at non-singleton dimension 0
  File "utils.py", line 82, in search
    tau = factor_best.reshape(-1, 256, 1) * absmax + tau0

And this is because of the cat operation, so could you explain the detail about entropy calculation? (By the way, I don‘t know why calculate entropy like these), Thanks!

# utils.py, line53, torch.cat operation, why?
def evaluate_entropy(weight_int8, blocksize):
    device = weight_int8.device
    _weight_int8 = weight_int8.reshape(-1, 1)
    weight_nf4 = torch.cat((_weight_int8//16, _weight_int8%16), 1).reshape(1, -1, blocksize)
    weight_nf4_repeat = weight_nf4.repeat(16, 1, 1).to(device)
    values = torch.tensor(range(16)).reshape(16, 1, 1).to(device)
    freqs = (weight_nf4_repeat==values).sum(dim=-1, keepdim=True) / blocksize
    entropy = -freqs * torch.log2(freqs)
    entropy = torch.where(torch.isnan(entropy), 0, entropy)
    entropy = entropy.sum(dim=0)
    return entropy
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

No branches or pull requests

1 participant