analyze: load the bundled detector metrics file - #2004
Conversation
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
left a comment
There was a problem hiding this comment.
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>
|
Thanks, both points taken. Renamed the directory to On the guard, I kept it, and try:
audio_achilles_data_dir = data_path / "audio_achilles"
except GarakException:
...
|
Closes #2003.
DetectorMetrics._load_metricsnever found the bundled metrics file, soget_detector_se_spreturned the(1.0, 1.0)fallback for every detector andci_calculatorcomputed 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.pathis aLocalDataPaththat searches the data dir then the package dir on each/. Wrapping it inPath(...)pinned the lookup to the data dir, where nothing ships.detectors_eval; the data ships asdetectors-eval, which is also what_plugins.pyanddocs/source/detector_metrics.rstuse.Resolving through
LocalDataPathalso means a genuinely missing resource raisesGarakExceptionrather than surfacing asFileNotFoundError, 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_loadedis True anddan.DANreports 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.