Skip to content

synsql.compute_score runs model SQL on a writable connection, so a rollout's DROP TABLE changes the reward of later rollouts #34

Open

Description

@damienen

get_cursor_from_path in verl/utils/reward_score/exec_eval.py opens the training database with plain sqlite3.connect(path), and compute_score (verl/utils/reward_score/synsql.py) runs the model's SQL on it. A rollout that emits DROP TABLE, ALTER TABLE and similar statements changes the shared .sqlite file immediately. From then on, correct answers for that database are scored as unexecutable (-1 here instead of about 6.6), until the file is restored.

The destructive statement itself can also score well. If the gold query returns no rows, DROP TABLE log returns no rows too, so it counts as a match.

Reproduction

Needs func_timeout==4.3.5 sqlparse==0.5.3. Run with SRC set to a checkout of the repo. The script builds a one-table SQLite file under the path layout compute_score expects, scores a correct answer, scores a DROP TABLE rollout, then scores the same correct answer again.

import os, sys, types, sqlite3, tempfile, io, contextlib, re, importlib
SRC = os.environ.get("SRC", "src")
pkg = types.ModuleType("rs"); pkg.__path__ = [os.path.join(SRC, "verl/utils/reward_score")]
sys.modules["rs"] = pkg
synsql = importlib.import_module("rs.synsql")

os.chdir(tempfile.mkdtemp())
d = "data/NL2SQL/SynSQL-2.5M/databases/school"
os.makedirs(d)
p = os.path.join(d, "school.sqlite")
c = sqlite3.connect(p); c.execute("create table log(x int)"); c.execute("insert into log values(1)"); c.commit(); c.close()

def resp(sql):
    return f"<|im_start|>assistant\n<think>t</think><answer>\n```sql\n{sql}\n```\n</answer>"
gt = {"db_id": "school", "sql": "SELECT x FROM log"}
def score(sql):
    with contextlib.redirect_stdout(io.StringIO()):
        return synsql.compute_score(resp(sql), gt)

a = score("SELECT x FROM log")
score("DROP TABLE log")
c = score("SELECT x FROM log")
print("correct answer before DROP rollout:", a, "expected same after:", a)
print("same answer after DROP rollout     :", c)
if c != a:
    print("REPRODUCED"); sys.exit(1)

Expected: the correct answer gets the same score both times.
Actual on main:

correct answer before DROP rollout: 6.614222935267857 expected same after: 6.614222935267857
same answer after DROP rollout     : -1
REPRODUCED

(exit code 1.) A second check with the gold query SELECT x FROM log WHERE x < 0 scored the DROP TABLE log completion 6.57 (a match), left the table missing, and then scored the correct query -1. I did not run a training job, so how often a policy produces such statements is not measured.

Reproduces on main at ccfb511e81fdb3a8e87bd3da7f3d71882cedd532.

Related

#28 discussed empty results matching on the small SynSQL databases, which is why a DROP TABLE can score as a match here. This issue is about the connection being writable: one rollout's DROP TABLE or ALTER TABLE changes the database file, so later correct answers on that database score as unexecutable.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions