Skip to content

Commit e2fe35b

Browse files
authored
Prototype of an interface for the scoring science (#1721)
* Prototype of an interface for the scoring science * Remove build artifacts * Add better LLM instructions/rails for adding a scoring function * Remove local vendor package and use git repo for real * Point to new candela-scoring repo * Allow github private repo access
1 parent a23357d commit e2fe35b

25 files changed

Lines changed: 663 additions & 87371 deletions

‎.github/workflows/docker.yml‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,11 @@ jobs:
3434
username: ${{ github.repository_owner }}
3535
password: ${{ secrets.GITHUB_TOKEN }}
3636

37+
- name: Configure SSH for private candela-scoring dependency
38+
uses: webfactory/ssh-agent@v0.9.1
39+
with:
40+
ssh-private-key: ${{ secrets.CANDELA_SSH_KEY }}
41+
3742
- name: Get latest version from registry
3843
id: get_version
3944
run: |
@@ -91,6 +96,7 @@ jobs:
9196
labels: ${{ steps.meta.outputs.labels }}
9297
cache-from: type=gha
9398
cache-to: type=gha,mode=max
99+
ssh: default=${{ env.SSH_AUTH_SOCK }}
94100

95101
- name: Output new version
96102
run: |

‎.github/workflows/python-app.yml‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@ jobs:
2020
- name: Install uv
2121
run: pipx install uv
2222

23+
- name: Configure SSH for private candela-scoring dependency
24+
uses: webfactory/ssh-agent@v0.9.1
25+
with:
26+
ssh-private-key: ${{ secrets.CANDELA_SSH_KEY }}
27+
2328
- name: Check lock file and sync dependencies
2429
run: uv sync --group dev --locked --no-cache
2530

‎Dockerfile‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# syntax=docker/dockerfile:1
12
# Base Stage
23
FROM python:3.12-slim AS base
34

@@ -19,7 +20,7 @@ ENV PATH="/root/.local/bin:${PATH}"
1920
ENV UV_PROJECT_ENVIRONMENT="/venv"
2021

2122
COPY pyproject.toml uv.lock ./
22-
RUN uv sync --frozen --no-install-project
23+
RUN --mount=type=ssh uv sync --frozen --no-install-project
2324

2425
# Final Stage
2526
FROM base AS final

‎pyproject.toml‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ dependencies = [
8585
"airrlogger",
8686
"requests-toolbelt>=1.0.0",
8787
"jsonschema>=4.26.0",
88+
"candela-scoring",
8889
]
8990

9091
[project.urls]
@@ -120,6 +121,9 @@ composer = [
120121

121122
[tool.uv]
122123
package = true
124+
125+
[tool.uv.sources]
126+
candela-scoring = { git = "ssh://git@github.com/mlcommons/candela-scoring.git", tag = "v0.3.0" }
123127
[tool.setuptools]
124128
package-dir = {"" = "src"}
125129

@@ -130,7 +134,6 @@ namespaces = true
130134

131135
[tool.setuptools.package-data]
132136
"modelgauge.config_templates" = ["*.toml"]
133-
"modelbench.external_scoring" = ["*.json"]
134137

135138
[tool.pytest.ini_options]
136139
addopts = [

‎src/modelbench/benchmarks.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88

99
from modelbench.benchmark_runner_items import TestRunItem
1010
from modelbench.benchmark_score import BenchmarkScore, SecurityScore
11-
from modelbench.external_scoring import safety_v_1_2_1_scoring, security_v_1_1_scoring
1211
from modelbench.external_scoring.scoring_adapters import RegressionScorer
1312
from modelbench.hazards import (
1413
HazardDefinition,
@@ -21,6 +20,7 @@
2120
SecurityNaiveHazardV1_0_2,
2221
)
2322
from modelbench.standards import NoStandardsFileError, NullStandards, Standards
23+
from modelbench.scoring_interface import safety_v_1_2_1_scoring, security_v_1_1_scoring
2424
from modelbench.uid import HasUid
2525
from modelgauge.constants import DEFAULT_EVALUATOR, PRIVATE_EVALUATOR
2626
from modelgauge.locales import validate_locale

‎src/modelbench/cli.py‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
summarize_consistency_check_results,
4444
)
4545
from modelbench.record import dump_json
46+
from modelbench.scoring_interface.interface import CONTRACT_MODELS
4647
from modelbench.standards import Standards
4748
from modelgauge.config import load_secrets_from_config, write_default_config
4849
from modelgauge.constants import PRIVATE_EVALUATOR
@@ -174,6 +175,25 @@ def benchmark() -> None:
174175
pass
175176

176177

178+
@cli.command("scoring-schema", help="Print the JSON Schemas of the scoring-interface contract models")
179+
@click.option(
180+
"--output",
181+
"-o",
182+
default=None,
183+
type=click.Path(file_okay=True, dir_okay=False, path_type=pathlib.Path),
184+
help="Write the schemas to this file instead of stdout",
185+
)
186+
def scoring_schema(output):
187+
schemas = {model.__name__: model.model_json_schema() for model in CONTRACT_MODELS}
188+
rendered = json.dumps(schemas, indent=2, sort_keys=True)
189+
if output:
190+
output.parent.mkdir(parents=True, exist_ok=True)
191+
output.write_text(rendered + "\n")
192+
echo(f"Wrote {len(schemas)} contract schemas to {output}")
193+
else:
194+
echo(rendered)
195+
196+
177197
@cli.result_callback()
178198
def at_end(result, **kwargs):
179199
PROMETHEUS.push_metrics()
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
"""
22
3-
This is really external code pasted into our repo for convenience. Do not edit under normal conditions.
3+
Frozen legacy code for the Safety 1.2 regression-scoring path only. Do not
4+
edit; do not add new benchmarks here. New benchmarks score through the
5+
candela-scoring library behind ``modelbench.scoring_interface``.
46
57
"""

0 commit comments

Comments
 (0)