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

weight2metis scale is zero if there are identical weight values #392

Open
johanesmikhael opened this issue Nov 25, 2024 · 1 comment
Open

Comments

@johanesmikhael
Copy link

The weight2metis function may encounter issues when min_diff == 0, which can result from consecutive identical values in the input tensor. Is it the expected behavior?

@johanesmikhael
Copy link
Author

I propose below change:

def weight2metis(weight):
    sorted_weight = weight.sort()[0].unique() # add unique() to avoid min_diff == 0
    diff = sorted_weight[1:] - sorted_weight[:-1]
    if diff.sum() == 0:
        return None
    weight_min, weight_max = sorted_weight[0], sorted_weight[-1]
    srange = weight_max - weight_min
    min_diff = diff.min()
    scale = (min_diff / srange).item()
    tick, arange = scale.as_integer_ratio()
    weight_ratio = (weight - weight_min).div_(srange).mul_(arange).add_(tick)
    return weight_ratio.to(torch.long)

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