Skip to content

_normalize_distr function bug in entropy calibrator #4384

@PT0X0E

Description

@PT0X0E

Description

In pytorch-quantization package, the _normalize_distr(distr) function in entropy calibrator is not right.

def _normalize_distr(distr):
    summ = np.sum(distr)
    if summ != 0:
        distr = distr / summ

This won't actually normalize the input distr as expected. The distr = is a new array. To achieve in-place, it should be distr /= summ.

The reason this calibrator still works is that in scipy's entropy function, scipy also performs normalization. But we better fix it here in case scipy changes its implementation.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Module:QuantizationIssues related to QuantizationduplicateThis issue or pull request already existstriagedIssue has been triaged by maintainers

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions