Repository navigation
FIX: reject a SeedDatasetFilter axis given an empty set - #2907
Conversation
None means "this axis is not requested"; an empty set does not. In _match_single_criterion an empty set is only skipped when it is None, so harm_categories=set() matches nothing without strict_match (no overlap) and every dataset with it (nothing can be outside the empty set) - the same filter, one flag apart, returning either nothing or everything. _validate already rejects the other impossible strict_match configuration at construction time, so reject this one there too, and say which value to pass instead: None leaves the axis unfiltered.
The empty-axis check ran before `if not self.has_all_tag: return`, so a
criterion carrying the 'all' tag still had its other fields validated. That
contradicts what 'all' documents itself to do -- bypass all filtering --
and there is no ambiguous matching to protect against here: the caller asked
for every dataset.
SeedDatasetFilter(tags={"all"}, harm_categories=set())
raised `ValueError: Filter axes ['harm_categories'] were given an empty set`
on the previous head and constructs now. Same for composed criteria where
one criterion has 'all' and another has an empty axis, under either value
of strict_match.
Skip the empty-axis check when any criterion has 'all'; the existing
warnings below still run, so combining 'all' with other fields is still
reported. Tests cover both construction paths.
Reported by @romanlutz.
|
Good catch, and you are right that there is no ambiguous matching to protect against here — the caller asked for every dataset, so an empty axis beside Confirmed the mechanism before changing it: the empty-axis check sat above Done in Tests for both construction paths you named:
All three new cases fail on On your second question — whether rejecting ignored axes might be an intentional contract change — I do not think it can be, because |
…he message Follow-up to the review on microsoft#2907. `all` now skips the strict_match/singular-field check as well as the empty-axis check. Both reject a field the tag has already bypassed, and the warning further down says strict_match has no effect with `all`, so raising first contradicted it. The empty-axis message no longer claims an empty set "matches no dataset" unconditionally: with strict_match it matches every dataset that declares the axis, which is the whole reason the guard exists.
|
Both remaining points are addressed in Hoisting The wording. Correct, and thanks for catching that the split is the reason the guard exists at all. It now reads: New tests, both failing on
The three existing empty-axis tests match on |
|
Both should-fixes from Roman Lutz (@romanlutz) and the wording follow-up are now in c376fb0:
hannahwestra25 re the earlier "all skips the empty-axis check... hoist has_all_tag over both": yes — now the empty-axes scan itself returns |
hannahwestra25
left a comment
There was a problem hiding this comment.
thanks for contributing !
Description
SeedDatasetFilterreadsNoneon a filter axis as "this axis is not requested", but an empty set is something else, and the two matching modes read it in opposite ways: withoutstrict_matchnothing can overlap withset(), so an empty axis matches no dataset; withstrict_matchnothing can be outsideset(), so the same axis matches every dataset. One flag decides whether a filter returns nothing or the whole catalogue, with no error either way.SeedDatasetFilter._validatealready rejects the other logically impossiblestrict_matchconfiguration at construction time (size={"small", "large"}), so this one belongs there too:now raises
ValueErrornaming the axis and telling the caller to passNoneto leave it unfiltered.Nonekeeps its meaning, and the matching code is unchanged.If you would rather have an empty set mean "no constraint on this axis" — the other reading, and a one-liner in
_match_single_criterion— say so and I will switch it; I went with the error because both current readings surprise, and a red-teaming run that silently loads the whole catalogue is the expensive one.Tests and Documentation
Four cases in
tests/unit/datasets/test_seed_dataset_metadata.py: an empty set is rejected for a flat filter, understrict_match, and insidecriteria=[](the first three fail onmainwithDID NOT RAISE), andNoneis still accepted as "axis not requested".pytest tests/unit/datasets/ -qgives 4874 passed, 1 failed; the failure istest_local_prompt_dataset_semantics.py::test_airt_fairness_builds_coherent_attack_parameters, which fails the same way with this change reverted (PackageNotFoundErrorfromimportlib.metadata).ruff checkandruff format --checkare clean on both files.