Skip to content

analyze: load the bundled detector metrics file - #2004

Open
immu4989 wants to merge 2 commits into
NVIDIA:mainfrom
immu4989:fix-2003-detector-metrics-path
Open

analyze: load the bundled detector metrics file#2004
immu4989 wants to merge 2 commits into
NVIDIA:mainfrom
immu4989:fix-2003-detector-metrics-path

Conversation

@immu4989

Copy link
Copy Markdown

Closes #2003.

DetectorMetrics._load_metrics never found the bundled metrics file, so get_detector_se_sp returned the (1.0, 1.0) fallback for every detector and ci_calculator computed intervals as if each detector were perfect. The failure was only logged at debug level.

Two things were wrong, and the name alone is not sufficient:

  • garak.data.path is a LocalDataPath that searches the data dir then the package dir on each /. Wrapping it in Path(...) pinned the lookup to the data dir, where nothing ships.
  • The directory was spelled detectors_eval; the data ships as detectors-eval, which is also what _plugins.py and docs/source/detector_metrics.rst use.

Resolving through LocalDataPath also means a genuinely missing resource raises GarakException rather than surfacing as FileNotFoundError, so that is caught to keep the existing graceful fallback.

Verification

  • Run the tests and ensure they pass python -m pytest tests/analyze/

    160 passed.

  • Verify the thing does what it should

    Two tests added to tests/analyze/test_detector_metrics.py. Before this change both fail; after it, metrics_loaded is True and dan.DAN reports its measured Se 1.0 / Sp 0.75 instead of the fallback.

  • Verify the thing does not do what it should not

    A detector absent from the file still returns (1.0, 1.0), and a missing file still degrades gracefully rather than raising.

  • Supporting configuration such as a generator configuration file

    Not applicable.

  • garak -t <target_type> -n <model_name>

    Not applicable; the change is in report analysis and is covered by unit tests.

DetectorMetrics._load_metrics never found the bundled metrics summary, so
get_detector_se_sp returned the (1.0, 1.0) fallback for every detector and
ci_calculator computed intervals as if each detector were perfect. The
failure was only logged at debug level.

garak.data.path is a LocalDataPath that searches the data dir then the
package dir on each join. Wrapping it in Path() pinned the lookup to the
data dir, where nothing ships, and the directory was spelled
detectors_eval while the data ships as detectors-eval.

Resolve through LocalDataPath and use the shipped directory name. A
genuinely missing resource raises GarakException rather than surfacing as
FileNotFoundError, so catch it to keep the graceful fallback.

Closes NVIDIA#2003

Signed-off-by: Imran Ahamed <immu4989@gmail.com>

@jmartin-tech jmartin-tech left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The project file name conventions actually prefer _ to - in directory names to align with the python file structure. This should rename the directory to be more consistent for with other file paths.

I would also hazard that the try block is not necessary to the fix as removing the extra Path() object should be enough for a valid install and enable a user provided override. Though I can see leaving it as an extra guard.

Per review, align the data directory with the project convention of
underscores in directory names; detectors-eval was the only hyphenated
directory under garak/data. The loader keeps the name it already used and
_plugins.py and the detector metrics doc move to the new name.

Refs NVIDIA#2003

Signed-off-by: Imran Ahamed <immu4989@gmail.com>
@immu4989

Copy link
Copy Markdown
Author

Thanks, both points taken.

Renamed the directory to detectors_eval rather than changing the loader. You are right on the convention: it was the only hyphenated directory under garak/data, against adaptive_attacks, agent_breaker and sysprompt_extraction. _plugins.py and docs/source/detector_metrics.rst move with it, so the directory, both code references and the doc now agree.

On the guard, I kept it, and probes/audio.py is the precedent I was going from:

try:
    audio_achilles_data_dir = data_path / "audio_achilles"
except GarakException:
    ...

LocalDataPath raises GarakException for an absent resource rather than yielding a path that later fails to open, and _load_metrics is called from __init__, so without a catch a missing file would turn graceful degradation into a constructor raise, and change the behaviour test_instantiate_missing_file describes. Happy to drop it if you would still rather have the simpler form.

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.

detector metrics never load: analyze/detector_metrics.py reads detectors_eval, shipped dir is detectors-eval

2 participants