inspect_evals_utils.ids¶
Stable sample ids, duplicate and known-broken sample filters, optional-dependency checks.
DuplicateIdError
¶
Bases: ValueError
Samples sharing an id are not duplicates, or there are more than acknowledged.
KnownBrokenSampleError
¶
Bases: ValueError
A sample listed as known-broken is not in the dataset.
require_optional_dependency
¶
require_optional_dependency(
module: str,
uv_group: str,
pip_target: str,
display_name: str | None = None,
) -> None
Ensure an optional dependency is available, otherwise raise with an actionable message.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
module
|
str
|
Importable module name to check (e.g., "mlebench"). |
required |
uv_group
|
str
|
Required uv dependency-group name to suggest (e.g., "mle_bench"). |
required |
pip_target
|
str
|
Required pip target to install (package name, VCS/URL), e.g., "git+https://github.com/openai/mle-bench.git". |
required |
display_name
|
str | None
|
Optional nice name to show in the message (e.g. "MLE-bench", defaults to |
None
|
create_stable_id
¶
create_stable_id(
*fields: Any, prefix: str = "", length: int = 8
) -> str
Create a stable, deterministic ID from content fields.
This is useful for datasets that don't have a natural ID field and use shuffling. By creating IDs from stable content, samples maintain consistent IDs across shuffles.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
*fields
|
Any
|
One or more fields to hash (typically question, passage, or other unique content) |
()
|
prefix
|
str
|
Optional prefix to identify the dataset (e.g., "boolq", "gsm8k") |
''
|
length
|
int
|
Length of the hash to include in the ID (default: 8) |
8
|
Returns:
| Type | Description |
|---|---|
str
|
A stable ID string like "boolq_a4f3d9e2" (with prefix) or "a4f3d9e2" (without) |
Example
create_stable_id("What is the capital of France?", prefix="boolq") 'boolq_cb0b4aaf'
create_stable_id("What is 2+2?", "4", prefix="gsm8k") 'gsm8k_17f25bba'
create_stable_id("Some question") '76013494'
filter_duplicate_ids
¶
filter_duplicate_ids(
dataset: Dataset,
*,
max_duplicates: int | None = None,
reason: str | None = None,
) -> Dataset
Drop samples whose id repeats an earlier sample's id, if they are true duplicates.
Every dropped sample must match the kept sample on input, choices and target; otherwise the id is under-specified and this raises rather than silently discarding data (see #2506, #2524, #2525 for evals where that happened). Samples that differ only in metadata are dropped with a warning.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dataset
|
Dataset
|
The dataset to filter. |
required |
max_duplicates
|
int | None
|
Upper bound on samples this call may drop, measured
on the full pinned dataset. Exceeding it raises, since more
collisions than expected means the id fields no longer identify
a record or the dataset changed. Fewer is fine, because callers
that subset the dataset before deduplicating see fewer. Omitting
it skips the count check and emits a |
None
|
reason
|
str | None
|
Why the duplicates exist, with the URL of the upstream report.
Recorded in error messages so the acknowledgement is explicit at
the call site. Omitting it emits a |
None
|
Returns:
| Type | Description |
|---|---|
Dataset
|
A filtered dataset keeping the first occurrence of each id. |
Raises:
| Type | Description |
|---|---|
DuplicateIdError
|
If samples sharing an id differ in content, or more
than |
drop_known_broken
¶
drop_known_broken(
dataset: Dataset, *, broken: Mapping[IdT, str]
) -> Dataset
Drop samples whose defects have been reported upstream, by id.
Every listed id must be present in the dataset. A listed id that is not there means the dataset revision moved, the ids changed or the defect was fixed, and in each case the list needs revisiting rather than silently doing nothing.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dataset
|
Dataset
|
The dataset to filter. |
required |
broken
|
Mapping[IdT, str]
|
Sample id to the URL of the upstream report describing the defect. Ids are matched as they appear in the loaded dataset; for positional ids that means they are stable only at the pinned dataset revision. |
required |
Returns:
| Type | Description |
|---|---|
Dataset
|
The dataset without the listed samples, order preserved. |
Raises:
| Type | Description |
|---|---|
KnownBrokenSampleError
|
If a listed id is not in the dataset. |
ValueError
|
If an entry has no report. |