fix(retain): parameterize retain mix; Phase 2 EN-only (scripts/smoke_l4.py)
Browse files- scripts/smoke_l4.py +11 -6
scripts/smoke_l4.py
CHANGED
|
@@ -403,6 +403,7 @@ def run_rmu(
|
|
| 403 |
vram_cap_gb: float = 21.0,
|
| 404 |
retain_extra_texts: list[str] | None = None,
|
| 405 |
retain_beta: float = 0.0,
|
|
|
|
| 406 |
) -> dict:
|
| 407 |
timer.check("rmu", need=600)
|
| 408 |
import torch
|
|
@@ -440,12 +441,15 @@ def run_rmu(
|
|
| 440 |
forget_texts = [r["text"] for r in read_jsonl(download_bench_file("arm_a/train.jsonl", bench_repo))]
|
| 441 |
mmlu = read_jsonl(download_bench_file("controls/global_mmlu.jsonl", bench_repo))
|
| 442 |
retain_texts = []
|
| 443 |
-
#
|
| 444 |
-
|
| 445 |
-
|
| 446 |
-
|
| 447 |
-
|
| 448 |
-
|
|
|
|
|
|
|
|
|
|
| 449 |
random.Random(42).shuffle(retain_sample)
|
| 450 |
for rec in retain_sample:
|
| 451 |
retain_texts.append(f"{rec['question']}\nAnswer: {rec['options'][rec['answer_index']]}")
|
|
@@ -529,6 +533,7 @@ def run_rmu(
|
|
| 529 |
"steps_completed": int(steps_done) if utility_batches else max_num_batches,
|
| 530 |
"alpha": alpha,
|
| 531 |
"retain_beta": retain_beta,
|
|
|
|
| 532 |
"utility_retain_weight": utility_retain_weight,
|
| 533 |
"utility_retain_n": len(utility_batches),
|
| 534 |
"loss_trace_head": loss_trace[:3],
|
|
|
|
| 403 |
vram_cap_gb: float = 21.0,
|
| 404 |
retain_extra_texts: list[str] | None = None,
|
| 405 |
retain_beta: float = 0.0,
|
| 406 |
+
retain_langs: tuple[str, ...] = ("en",),
|
| 407 |
) -> dict:
|
| 408 |
timer.check("rmu", need=600)
|
| 409 |
import torch
|
|
|
|
| 441 |
forget_texts = [r["text"] for r in read_jsonl(download_bench_file("arm_a/train.jsonl", bench_repo))]
|
| 442 |
mmlu = read_jsonl(download_bench_file("controls/global_mmlu.jsonl", bench_repo))
|
| 443 |
retain_texts = []
|
| 444 |
+
# Retain mix is configurable: Phase 2 uses the pre-registered English-only
|
| 445 |
+
# stream; Phase 3 adds multilingual utility protection through beta instead.
|
| 446 |
+
retain_langs = tuple(dict.fromkeys(retain_langs or ("en",)))
|
| 447 |
+
per_lang = {lang: [r for r in mmlu if r["lang"] == lang] for lang in retain_langs}
|
| 448 |
+
missing = [lang for lang, rows in per_lang.items() if not rows]
|
| 449 |
+
if missing:
|
| 450 |
+
raise RuntimeError(f"RMU: no retain records for languages {missing}")
|
| 451 |
+
min_count = min(len(rows) for rows in per_lang.values())
|
| 452 |
+
retain_sample = [rec for lang in retain_langs for rec in per_lang[lang][:min_count]]
|
| 453 |
random.Random(42).shuffle(retain_sample)
|
| 454 |
for rec in retain_sample:
|
| 455 |
retain_texts.append(f"{rec['question']}\nAnswer: {rec['options'][rec['answer_index']]}")
|
|
|
|
| 533 |
"steps_completed": int(steps_done) if utility_batches else max_num_batches,
|
| 534 |
"alpha": alpha,
|
| 535 |
"retain_beta": retain_beta,
|
| 536 |
+
"retain_langs": list(retain_langs),
|
| 537 |
"utility_retain_weight": utility_retain_weight,
|
| 538 |
"utility_retain_n": len(utility_batches),
|
| 539 |
"loss_trace_head": loss_trace[:3],
|