Skip to content

Commit 654d764

Browse files
Add --sampling-params to response regeneration script (#724)
<!-- markdownlint-disable --> <!-- PLEASE FILL IN THE PR DESCRIPTION HERE ENSURING ALL CHECKLIST ITEMS (AT THE BOTTOM) HAVE BEEN CONSIDERED. --> ## Purpose Response regeneration requests only set max_tokens, so sampling behavior (temperature, top_p, seed) was stuck on server defaults with no way to customize. Adds a --sampling-params JSON flag merged into each chat-completion request, records it in output metadata for reproducibility, and documents it in the CLI reference. Part of #694. ## Tests - Sanity-checked arg parsing: --sampling-params '{"temperature": 0.6, "top_p": 0.95}' parses to a dict, omitted flag yields {}, non-object JSON errors out ## Checklist I have filled in: - [x] The purpose of the PR, such as "Fix some issue (link existing issues this PR will resolve)". - [x] The test plan/results, such as providing test command and pasting the results. - [ ] (Optional) The necessary documentation update. - [x] I (a human) have written or reviewed the code in this pr to the best of my ability. --------- Signed-off-by: Guan-Ming (Wesley) Chiu <105915352+guan404ming@users.noreply.github.com> Signed-off-by: Guan-Ming Chiu <105915352+guan404ming@users.noreply.github.com> Co-authored-by: Orestis Zambounis <23146389+orestis-z@users.noreply.github.com>
1 parent f9e9685 commit 654d764

3 files changed

Lines changed: 24 additions & 1 deletion

File tree

docs/cli/response_regeneration.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,8 @@ python scripts/response_regeneration/script.py --dataset magpie
8989

9090
- **`--max-tokens`** (int, default: `8192`) Max tokens for generation.
9191

92+
- **`--sampling-params`** (str, default: `None`) JSON object merged into each chat-completion request, e.g. `'{"temperature": 0.6, "top_p": 0.95, "seed": 0}'`. Unset keys use the server defaults.
93+
9294
#### Output Arguments
9395

9496
- **`--outfile`** (str, default: auto-generated) Output JSONL path. If not specified, auto-generated as `{dataset}_{model}.jsonl`.
@@ -133,7 +135,8 @@ Rows are pre-tokenized and ready for training: one row per assistant turn, holdi
133135
"idx": 0,
134136
"finish_reason": "stop",
135137
"usage": {...},
136-
"endpoint": "http://127.0.0.1:8000/v1/chat/completions"
138+
"endpoint": "http://127.0.0.1:8000/v1/chat/completions",
139+
"sampling_params": {...}
137140
}
138141
}
139142
```

scripts/response_regeneration/script.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,14 @@ def parse_args():
8585
default=8192,
8686
help="max_tokens for generation",
8787
)
88+
parser.add_argument(
89+
"--sampling-params",
90+
default=None,
91+
help=(
92+
"JSON object merged into each chat-completion request, "
93+
'e.g. \'{"temperature": 0.6, "top_p": 0.95, "seed": 0}\''
94+
),
95+
)
8896
parser.add_argument(
8997
"--outfile",
9098
default=None,
@@ -112,6 +120,14 @@ def parse_args():
112120
args = parser.parse_args()
113121
if args.max_retries < 0:
114122
parser.error("--max-retries must be >= 0")
123+
try:
124+
args.sampling_params = (
125+
json.loads(args.sampling_params) if args.sampling_params else {}
126+
)
127+
except json.JSONDecodeError as e:
128+
parser.error(f"--sampling-params is not valid JSON: {e}")
129+
if not isinstance(args.sampling_params, dict):
130+
parser.error("--sampling-params must be a JSON object")
115131
return args
116132

117133

@@ -326,6 +342,7 @@ async def worker(
326342
prefix.append({"role": "user", "content": turn["content"]})
327343

328344
payload = {
345+
**args.sampling_params,
329346
"model": args.model,
330347
"messages": prefix,
331348
"max_tokens": args.max_tokens,
@@ -374,6 +391,7 @@ async def worker(
374391
"finish_reason": choice.get("finish_reason"),
375392
"usage": data.get("usage") or {},
376393
"endpoint": endpoint,
394+
"sampling_params": args.sampling_params,
377395
},
378396
}
379397
)

tests/unit/scripts/test_response_regeneration.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import importlib.util
1212
import json
1313
from pathlib import Path
14+
from typing import Any
1415

1516
import pytest
1617

@@ -434,6 +435,7 @@ class _Args:
434435
model = "m"
435436
max_tokens = 16
436437
max_retries = 0
438+
sampling_params: dict[str, Any] = {}
437439

438440

439441
class _NullProgress:

0 commit comments

Comments
 (0)