Skip to content

fix: resolve SamplingMetric string normalize argument - #1366

Open
Abelo9996 wants to merge 1 commit into
huggingface:mainfrom
Abelo9996:fix-samplingmetric-normalize-str
Open

fix: resolve SamplingMetric string normalize argument#1366
Abelo9996 wants to merge 1 commit into
huggingface:mainfrom
Abelo9996:fix-samplingmetric-normalize-str

Conversation

@Abelo9996

Copy link
Copy Markdown

What

Fix the string form of the normalize argument on sampling metrics (AvgAtN, MajAtN, PassAtK, GPassAtK).

Why

SamplingMetric.__init__ resolved a string normalize via inspect.getmembers(...), which returns a list of (name, function) tuples, but treated it as a dict. So normalize in allowed_normalizations compared the string against tuples and was always False, and every valid normalizer name raised ValueError: Unknown normalization function. A standalone repro is in #1365.

Change

  • Build a dict from the members, so normalize in allowed_normalizations checks names and allowed_normalizations[normalize] returns the function.
  • Add unit tests for the string (valid name), unknown-name, callable, and None cases.

Fixes #1365

inspect.getmembers() returns a list of (name, function) tuples, but
SamplingMetric.__init__ treated it as a dict, so a string normalize argument
was compared against tuples (always False) and every valid normalizer name
raised "Unknown normalization function". Build a dict from the members so names
resolve to functions. Add unit tests for the string, callable, unknown-name and
None cases.

Fixes huggingface#1365
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.

SamplingMetric string normalize argument always raises: getmembers() list treated as a dict

1 participant