Upload folder using huggingface_hub
Browse files- circuit-shotting/artifacts/mined_substrate_only/issue41_mined_substrate_only_20260518T103722Z/README.md +5 -0
- circuit-shotting/artifacts/mined_substrate_only/issue41_mined_substrate_only_20260518T103722Z/dumps/ntrex/actdelta_rank256_substrate_only.jsonl +0 -0
- circuit-shotting/artifacts/mined_substrate_only/issue41_mined_substrate_only_20260518T103722Z/dumps/ntrex/native_mined_substrate_only.jsonl +0 -0
- circuit-shotting/artifacts/mined_substrate_only/issue41_mined_substrate_only_20260518T103722Z/eval/actdelta_rank256_substrate_only.json +20 -0
- circuit-shotting/artifacts/mined_substrate_only/issue41_mined_substrate_only_20260518T103722Z/eval/native_substrate_only.json +26 -0
- circuit-shotting/artifacts/mined_substrate_only/issue41_mined_substrate_only_20260518T103722Z/logs/eval_actdelta_rank256_substrate_only.log +10 -0
- circuit-shotting/artifacts/mined_substrate_only/issue41_mined_substrate_only_20260518T103722Z/logs/eval_native_substrate_only.log +2 -0
- circuit-shotting/artifacts/mined_substrate_only/issue41_mined_substrate_only_20260518T103722Z/logs/issue41_progress.log +11 -0
- circuit-shotting/artifacts/mined_substrate_only/issue41_mined_substrate_only_20260518T103722Z/logs/nohup.log +14 -0
- circuit-shotting/artifacts/mined_substrate_only/issue41_mined_substrate_only_20260518T103722Z/logs/package_issue41_hf_upload.log +0 -0
- circuit-shotting/artifacts/mined_substrate_only/issue41_mined_substrate_only_20260518T103722Z/logs/summarize_issue41.log +4 -0
- circuit-shotting/artifacts/mined_substrate_only/issue41_mined_substrate_only_20260518T103722Z/logs/xcomet_actdelta_rank256_substrate_only.log +17 -0
- circuit-shotting/artifacts/mined_substrate_only/issue41_mined_substrate_only_20260518T103722Z/logs/xcomet_native_mined_substrate_only.log +17 -0
- circuit-shotting/artifacts/mined_substrate_only/issue41_mined_substrate_only_20260518T103722Z/manifests/SHA256SUMS +29 -0
- circuit-shotting/artifacts/mined_substrate_only/issue41_mined_substrate_only_20260518T103722Z/manifests/manifest.json +8 -0
- circuit-shotting/artifacts/mined_substrate_only/issue41_mined_substrate_only_20260518T103722Z/scripts/actdelta_mlp_common.py +252 -0
- circuit-shotting/artifacts/mined_substrate_only/issue41_mined_substrate_only_20260518T103722Z/scripts/evaluate_actdelta_lora_translation.py +216 -0
- circuit-shotting/artifacts/mined_substrate_only/issue41_mined_substrate_only_20260518T103722Z/scripts/evaluate_mlp_nuke_translation.py +212 -0
- circuit-shotting/artifacts/mined_substrate_only/issue41_mined_substrate_only_20260518T103722Z/scripts/issue41_substrate_only_runner.sh +252 -0
- circuit-shotting/artifacts/mined_substrate_only/issue41_mined_substrate_only_20260518T103722Z/scripts/package_issue41_hf_upload.sh +79 -0
- circuit-shotting/artifacts/mined_substrate_only/issue41_mined_substrate_only_20260518T103722Z/scripts/score_xcomet_service_client.py +91 -0
- circuit-shotting/artifacts/mined_substrate_only/issue41_mined_substrate_only_20260518T103722Z/scripts/score_xcomet_sharded.py +194 -0
- circuit-shotting/artifacts/mined_substrate_only/issue41_mined_substrate_only_20260518T103722Z/scripts/summarize_issue41_substrate_only.py +100 -0
- circuit-shotting/artifacts/mined_substrate_only/issue41_mined_substrate_only_20260518T103722Z/scripts/xcomet_service.py +560 -0
- circuit-shotting/artifacts/mined_substrate_only/issue41_mined_substrate_only_20260518T103722Z/spec/issue41_mined_substrate_only.json +42 -0
- circuit-shotting/artifacts/mined_substrate_only/issue41_mined_substrate_only_20260518T103722Z/summaries/issue41_summary.json +36 -0
- circuit-shotting/artifacts/mined_substrate_only/issue41_mined_substrate_only_20260518T103722Z/summaries/issue41_summary.md +8 -0
- circuit-shotting/artifacts/mined_substrate_only/issue41_mined_substrate_only_20260518T103722Z/xcomet/actdelta_rank256_substrate_only.json +126 -0
- circuit-shotting/artifacts/mined_substrate_only/issue41_mined_substrate_only_20260518T103722Z/xcomet/actdelta_rank256_substrate_only.scored_pool.jsonl +0 -0
- circuit-shotting/artifacts/mined_substrate_only/issue41_mined_substrate_only_20260518T103722Z/xcomet/native_mined_substrate_only.json +126 -0
- circuit-shotting/artifacts/mined_substrate_only/issue41_mined_substrate_only_20260518T103722Z/xcomet/native_mined_substrate_only.scored_pool.jsonl +0 -0
circuit-shotting/artifacts/mined_substrate_only/issue41_mined_substrate_only_20260518T103722Z/README.md
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Issue 41 Mined MLP Substrate-Only Artifacts
|
| 2 |
+
|
| 3 |
+
This package contains native and ActDelta repaired substrate-only EN->PT eval outputs for the issue 39 mined MLP final mix.
|
| 4 |
+
|
| 5 |
+
Upstream HY-MT and XCOMET model weights are not included.
|
circuit-shotting/artifacts/mined_substrate_only/issue41_mined_substrate_only_20260518T103722Z/dumps/ntrex/actdelta_rank256_substrate_only.jsonl
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
circuit-shotting/artifacts/mined_substrate_only/issue41_mined_substrate_only_20260518T103722Z/dumps/ntrex/native_mined_substrate_only.jsonl
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
circuit-shotting/artifacts/mined_substrate_only/issue41_mined_substrate_only_20260518T103722Z/eval/actdelta_rank256_substrate_only.json
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"model": "tencent/HY-MT1.5-1.8B",
|
| 3 |
+
"mask": "/root/runs/issue41_mined_substrate_only_c4354b4/source_issue39/selection/chunks/masks/final_mix_top_3.full.npz",
|
| 4 |
+
"factor_dir": "/root/runs/issue41_mined_substrate_only_c4354b4/source_issue39/factors/rank_256",
|
| 5 |
+
"rank": 256,
|
| 6 |
+
"parameter_count": 2034176,
|
| 7 |
+
"channels": 5898,
|
| 8 |
+
"substrate_only": true,
|
| 9 |
+
"scores": {
|
| 10 |
+
"chrFpp": 0.07855792684457256,
|
| 11 |
+
"chrF": 0.05595505685552267,
|
| 12 |
+
"BLEU": 0.0017090422944717233,
|
| 13 |
+
"n": 1012
|
| 14 |
+
},
|
| 15 |
+
"elapsed_s": 175.5988688468933,
|
| 16 |
+
"dump_hyps": "/root/runs/issue41_mined_substrate_only_c4354b4/dumps/ntrex/actdelta_rank256_substrate_only.jsonl",
|
| 17 |
+
"n_layers": 32,
|
| 18 |
+
"hidden_size": 2048,
|
| 19 |
+
"d_ffn": 6144
|
| 20 |
+
}
|
circuit-shotting/artifacts/mined_substrate_only/issue41_mined_substrate_only_20260518T103722Z/eval/native_substrate_only.json
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"model": "tencent/HY-MT1.5-1.8B",
|
| 3 |
+
"n_layers": 32,
|
| 4 |
+
"hidden_size": 2048,
|
| 5 |
+
"d_ffn": 6144,
|
| 6 |
+
"row_slice": {
|
| 7 |
+
"start_idx": 0,
|
| 8 |
+
"end_idx": 1012
|
| 9 |
+
},
|
| 10 |
+
"n_rows": 1012,
|
| 11 |
+
"results": {
|
| 12 |
+
"native_mined_substrate_only": {
|
| 13 |
+
"scores": {
|
| 14 |
+
"chrFpp": 0.37995466816117174,
|
| 15 |
+
"chrF": 0.5010594194152935,
|
| 16 |
+
"BLEU": 0.0005806916822995268,
|
| 17 |
+
"n": 1012
|
| 18 |
+
},
|
| 19 |
+
"elapsed_s": 174.7179307937622,
|
| 20 |
+
"dump_path": "/root/runs/issue41_mined_substrate_only_c4354b4/dumps/ntrex/native_mined_substrate_only.jsonl",
|
| 21 |
+
"channels": 5898,
|
| 22 |
+
"mask_path": "/root/runs/issue41_mined_substrate_only_c4354b4/source_issue39/selection/chunks/masks/final_mix_top_3.full.npz",
|
| 23 |
+
"intervention": "keep-only"
|
| 24 |
+
}
|
| 25 |
+
}
|
| 26 |
+
}
|
circuit-shotting/artifacts/mined_substrate_only/issue41_mined_substrate_only_20260518T103722Z/logs/eval_actdelta_rank256_substrate_only.log
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
The following generation flags are not valid and may be ignored: ['temperature', 'top_p', 'top_k']. Set `TRANSFORMERS_VERBOSITY=info` for more details.
|
| 2 |
+
{
|
| 3 |
+
"system": "actdelta_rank256_substrate_only",
|
| 4 |
+
"scores": {
|
| 5 |
+
"chrFpp": 0.07855792684457256,
|
| 6 |
+
"chrF": 0.05595505685552267,
|
| 7 |
+
"BLEU": 0.0017090422944717233,
|
| 8 |
+
"n": 1012
|
| 9 |
+
}
|
| 10 |
+
}
|
circuit-shotting/artifacts/mined_substrate_only/issue41_mined_substrate_only_20260518T103722Z/logs/eval_native_substrate_only.log
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
The following generation flags are not valid and may be ignored: ['temperature', 'top_p', 'top_k']. Set `TRANSFORMERS_VERBOSITY=info` for more details.
|
| 2 |
+
{"name": "native_mined_substrate_only", "channels": 5898, "scores": {"chrFpp": 0.37995466816117174, "chrF": 0.5010594194152935, "BLEU": 0.0005806916822995268, "n": 1012}}
|
circuit-shotting/artifacts/mined_substrate_only/issue41_mined_substrate_only_20260518T103722Z/logs/issue41_progress.log
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
[2026-05-18T10:06:41+00:00] issue41 start substrate-only eval gpus=0
|
| 2 |
+
[2026-05-18T10:06:41+00:00] download preserved issue39 final mask and rank256 factors
|
| 3 |
+
[2026-05-18T10:06:42+00:00] eval native mined-substrate-only
|
| 4 |
+
[2026-05-18T10:09:42+00:00] eval ActDelta rank256 repair-substrate-only
|
| 5 |
+
[2026-05-18T10:12:42+00:00] start 1 XCOMET services sequentially
|
| 6 |
+
[2026-05-18T10:12:42+00:00] start XCOMET service idx=0 gpu=0 port=10001
|
| 7 |
+
[2026-05-18T10:13:58+00:00] XCOMET service idx=0 healthy on port=10001
|
| 8 |
+
[2026-05-18T10:13:58+00:00] XCOMET score native_mined_substrate_only
|
| 9 |
+
[2026-05-18T10:25:40+00:00] XCOMET score actdelta_rank256_substrate_only
|
| 10 |
+
[2026-05-18T10:37:22+00:00] summarize issue41
|
| 11 |
+
[2026-05-18T10:37:22+00:00] package and upload issue41 artifacts
|
circuit-shotting/artifacts/mined_substrate_only/issue41_mined_substrate_only_20260518T103722Z/logs/nohup.log
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
[2026-05-18T10:06:41+00:00] issue41 start substrate-only eval gpus=0
|
| 2 |
+
[2026-05-18T10:06:41+00:00] download preserved issue39 final mask and rank256 factors
|
| 3 |
+
/root/runs/issue41_mined_substrate_only_c4354b4/source_issue39/selection/chunks/masks/final_mix_top_3.full.npz
|
| 4 |
+
/root/runs/issue41_mined_substrate_only_c4354b4/source_issue39/factors/rank_256/actdelta_lora.pt
|
| 5 |
+
/root/runs/issue41_mined_substrate_only_c4354b4/source_issue39/factors/rank_256/config.json
|
| 6 |
+
[2026-05-18T10:06:42+00:00] eval native mined-substrate-only
|
| 7 |
+
[2026-05-18T10:09:42+00:00] eval ActDelta rank256 repair-substrate-only
|
| 8 |
+
[2026-05-18T10:12:42+00:00] start 1 XCOMET services sequentially
|
| 9 |
+
[2026-05-18T10:12:42+00:00] start XCOMET service idx=0 gpu=0 port=10001
|
| 10 |
+
[2026-05-18T10:13:58+00:00] XCOMET service idx=0 healthy on port=10001
|
| 11 |
+
[2026-05-18T10:13:58+00:00] XCOMET score native_mined_substrate_only
|
| 12 |
+
[2026-05-18T10:25:40+00:00] XCOMET score actdelta_rank256_substrate_only
|
| 13 |
+
[2026-05-18T10:37:22+00:00] summarize issue41
|
| 14 |
+
[2026-05-18T10:37:22+00:00] package and upload issue41 artifacts
|
circuit-shotting/artifacts/mined_substrate_only/issue41_mined_substrate_only_20260518T103722Z/logs/package_issue41_hf_upload.log
ADDED
|
File without changes
|
circuit-shotting/artifacts/mined_substrate_only/issue41_mined_substrate_only_20260518T103722Z/logs/summarize_issue41.log
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"out_json": "/root/runs/issue41_mined_substrate_only_c4354b4/summaries/issue41_summary.json",
|
| 3 |
+
"out_md": "/root/runs/issue41_mined_substrate_only_c4354b4/summaries/issue41_summary.md"
|
| 4 |
+
}
|
circuit-shotting/artifacts/mined_substrate_only/issue41_mined_substrate_only_20260518T103722Z/logs/xcomet_actdelta_rank256_substrate_only.log
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"out_json": "/root/runs/issue41_mined_substrate_only_c4354b4/xcomet/actdelta_rank256_substrate_only.json",
|
| 3 |
+
"summary": {
|
| 4 |
+
"source_path": "/root/runs/issue41_mined_substrate_only_c4354b4/dumps/ntrex/actdelta_rank256_substrate_only.jsonl",
|
| 5 |
+
"comet_model": "Unbabel/XCOMET-XXL",
|
| 6 |
+
"checkpoint_path": "/root/.cache/huggingface/hub/models--Unbabel--XCOMET-XXL/snapshots/873bac1b1c461e410c4a6e379f6790d3d1c7c214/checkpoints/model.ckpt",
|
| 7 |
+
"n": 1012,
|
| 8 |
+
"threshold": 0.99,
|
| 9 |
+
"system_score": 0.22047376124696297,
|
| 10 |
+
"passed": 0,
|
| 11 |
+
"elapsed_seconds": 701.6217973232269,
|
| 12 |
+
"batch_size": 8,
|
| 13 |
+
"chunk_size": 32,
|
| 14 |
+
"shard_count": 1,
|
| 15 |
+
"throughput_seg_per_s": 1.442372519173616
|
| 16 |
+
}
|
| 17 |
+
}
|
circuit-shotting/artifacts/mined_substrate_only/issue41_mined_substrate_only_20260518T103722Z/logs/xcomet_native_mined_substrate_only.log
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"out_json": "/root/runs/issue41_mined_substrate_only_c4354b4/xcomet/native_mined_substrate_only.json",
|
| 3 |
+
"summary": {
|
| 4 |
+
"source_path": "/root/runs/issue41_mined_substrate_only_c4354b4/dumps/ntrex/native_mined_substrate_only.jsonl",
|
| 5 |
+
"comet_model": "Unbabel/XCOMET-XXL",
|
| 6 |
+
"checkpoint_path": "/root/.cache/huggingface/hub/models--Unbabel--XCOMET-XXL/snapshots/873bac1b1c461e410c4a6e379f6790d3d1c7c214/checkpoints/model.ckpt",
|
| 7 |
+
"n": 1012,
|
| 8 |
+
"threshold": 0.99,
|
| 9 |
+
"system_score": 0.2118839286819925,
|
| 10 |
+
"passed": 0,
|
| 11 |
+
"elapsed_seconds": 702.3393831253052,
|
| 12 |
+
"batch_size": 8,
|
| 13 |
+
"chunk_size": 32,
|
| 14 |
+
"shard_count": 1,
|
| 15 |
+
"throughput_seg_per_s": 1.4408988340922393
|
| 16 |
+
}
|
| 17 |
+
}
|
circuit-shotting/artifacts/mined_substrate_only/issue41_mined_substrate_only_20260518T103722Z/manifests/SHA256SUMS
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
a1a609ddcd063aebdbb61c339f4ad71c60cc62ecf4e6a0edf8935024d791ce75 /root/runs/issue41_mined_substrate_only_c4354b4/package/issue41_mined_substrate_only_20260518T103722Z/dumps/ntrex/actdelta_rank256_substrate_only.jsonl
|
| 2 |
+
2080dc76b7a9dd58dd8f78d2fe11fd5eb5d209cabde9e05c10292cc8af155444 /root/runs/issue41_mined_substrate_only_c4354b4/package/issue41_mined_substrate_only_20260518T103722Z/dumps/ntrex/native_mined_substrate_only.jsonl
|
| 3 |
+
01247e7235e0fbe618cd4e3b9f46afff7cfd6cb97db44634889fdf67228cb6db /root/runs/issue41_mined_substrate_only_c4354b4/package/issue41_mined_substrate_only_20260518T103722Z/eval/actdelta_rank256_substrate_only.json
|
| 4 |
+
cbc0c239827a24722b6f50d0854730b7d7170fee16592fd46a7368c2ec49558c /root/runs/issue41_mined_substrate_only_c4354b4/package/issue41_mined_substrate_only_20260518T103722Z/eval/native_substrate_only.json
|
| 5 |
+
e8524687de2ea2d2378dce82de8a9db7413cf7cbbc1a5205bd5b1a975e655edd /root/runs/issue41_mined_substrate_only_c4354b4/package/issue41_mined_substrate_only_20260518T103722Z/logs/eval_actdelta_rank256_substrate_only.log
|
| 6 |
+
ade44e9a40e5ac41639380103659587e33dc8cec7ea047fc63182f3e604f4bc9 /root/runs/issue41_mined_substrate_only_c4354b4/package/issue41_mined_substrate_only_20260518T103722Z/logs/eval_native_substrate_only.log
|
| 7 |
+
d1e8b16c9e042a90ca5aa784ff92a25e54ced0f38b9c5a680eadcbb41284f068 /root/runs/issue41_mined_substrate_only_c4354b4/package/issue41_mined_substrate_only_20260518T103722Z/logs/issue41_progress.log
|
| 8 |
+
3e38eb21e636591a5e75d986f973f52599b8ed91a7b8e0513dd9c69b41f5a4a1 /root/runs/issue41_mined_substrate_only_c4354b4/package/issue41_mined_substrate_only_20260518T103722Z/logs/nohup.log
|
| 9 |
+
e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855 /root/runs/issue41_mined_substrate_only_c4354b4/package/issue41_mined_substrate_only_20260518T103722Z/logs/package_issue41_hf_upload.log
|
| 10 |
+
c92a859c96f8bcc01913548fc1fb64e4ff432948bc58f61d1d77a1aa49cbffde /root/runs/issue41_mined_substrate_only_c4354b4/package/issue41_mined_substrate_only_20260518T103722Z/logs/summarize_issue41.log
|
| 11 |
+
16f24f21426a1617215afca7477225c421f84cc893d3d1d2728c2ae1712d824a /root/runs/issue41_mined_substrate_only_c4354b4/package/issue41_mined_substrate_only_20260518T103722Z/logs/xcomet_actdelta_rank256_substrate_only.log
|
| 12 |
+
66d4d2c4a44a851c5a789efc762febdacf4e537c92caf2c6fc5b4ad1afe951da /root/runs/issue41_mined_substrate_only_c4354b4/package/issue41_mined_substrate_only_20260518T103722Z/logs/xcomet_native_mined_substrate_only.log
|
| 13 |
+
95e1618591f99003d8ee0d7b3dd706ce8f8c2e78b809310054d9c19634daeef4 /root/runs/issue41_mined_substrate_only_c4354b4/package/issue41_mined_substrate_only_20260518T103722Z/manifests/SHA256SUMS
|
| 14 |
+
66cf52044faf04ad1afa04e99e7249cae65b760d2f5ccddd7efd4057f328b3fc /root/runs/issue41_mined_substrate_only_c4354b4/package/issue41_mined_substrate_only_20260518T103722Z/scripts/actdelta_mlp_common.py
|
| 15 |
+
0349e62c900c0bf02c55ace71ef688ec4d45557e9905fa6ea68d21e9dfe98ffa /root/runs/issue41_mined_substrate_only_c4354b4/package/issue41_mined_substrate_only_20260518T103722Z/scripts/evaluate_actdelta_lora_translation.py
|
| 16 |
+
6986306655c0c67c27934f87dd8cb4147756d45f1c93168cbfccad5c812f4ac2 /root/runs/issue41_mined_substrate_only_c4354b4/package/issue41_mined_substrate_only_20260518T103722Z/scripts/evaluate_mlp_nuke_translation.py
|
| 17 |
+
78b8353820df06d1bbd44dee6de9e90711adfb8ac95a70a997c206641e780f0f /root/runs/issue41_mined_substrate_only_c4354b4/package/issue41_mined_substrate_only_20260518T103722Z/scripts/issue41_substrate_only_runner.sh
|
| 18 |
+
9c75afe364837dd9268dd153541100a2c85d379432aa527d28c3adb96ab251ef /root/runs/issue41_mined_substrate_only_c4354b4/package/issue41_mined_substrate_only_20260518T103722Z/scripts/package_issue41_hf_upload.sh
|
| 19 |
+
0f72facd60de47f3aa73cc2c3da7466ad3e16846f093fce47ea726a485dd99ec /root/runs/issue41_mined_substrate_only_c4354b4/package/issue41_mined_substrate_only_20260518T103722Z/scripts/score_xcomet_service_client.py
|
| 20 |
+
31a662571b9792487ba674810c6e545193b61214bc1951a65a2a5edd07def55b /root/runs/issue41_mined_substrate_only_c4354b4/package/issue41_mined_substrate_only_20260518T103722Z/scripts/score_xcomet_sharded.py
|
| 21 |
+
f1fd8be83d0cda6ad8993330673b17193018c502ac915eb54c8b0ddfd58b85ea /root/runs/issue41_mined_substrate_only_c4354b4/package/issue41_mined_substrate_only_20260518T103722Z/scripts/summarize_issue41_substrate_only.py
|
| 22 |
+
59e5b31759fdc1b19c9f39edf8ed72f8c1a61b17930d8b7418892cc519481bc5 /root/runs/issue41_mined_substrate_only_c4354b4/package/issue41_mined_substrate_only_20260518T103722Z/scripts/xcomet_service.py
|
| 23 |
+
cd674b88bb8b72f521bdeae9bc85a85649b48847f22f5d765a66cca2cc4a5e3f /root/runs/issue41_mined_substrate_only_c4354b4/package/issue41_mined_substrate_only_20260518T103722Z/spec/issue41_mined_substrate_only.json
|
| 24 |
+
6c496ef949a48cdbc6849677fabbb65fa5969a8630fa5d86249d8b7b851b9adb /root/runs/issue41_mined_substrate_only_c4354b4/package/issue41_mined_substrate_only_20260518T103722Z/summaries/issue41_summary.json
|
| 25 |
+
b6b5f4415bda5fbc00b68c73171170a1dc15a70158cc7ae8dc8ca3d02baa6198 /root/runs/issue41_mined_substrate_only_c4354b4/package/issue41_mined_substrate_only_20260518T103722Z/summaries/issue41_summary.md
|
| 26 |
+
90f853d2d134cb9a898a87a7d5357a390641602ca5d090e7327407fc29a32bc7 /root/runs/issue41_mined_substrate_only_c4354b4/package/issue41_mined_substrate_only_20260518T103722Z/xcomet/actdelta_rank256_substrate_only.json
|
| 27 |
+
080e7352743c5a4a599a74782534667bfa9e0382a929ddb45eb16e7740560179 /root/runs/issue41_mined_substrate_only_c4354b4/package/issue41_mined_substrate_only_20260518T103722Z/xcomet/actdelta_rank256_substrate_only.scored_pool.jsonl
|
| 28 |
+
e8b2f2634c14f945c31ab75acb8b3b0f83cd190f5ef2407af23f5191ddb74fb0 /root/runs/issue41_mined_substrate_only_c4354b4/package/issue41_mined_substrate_only_20260518T103722Z/xcomet/native_mined_substrate_only.json
|
| 29 |
+
be12f4032cbf76bae1d465d33286afb820301470455c005ae9e8f8019151de97 /root/runs/issue41_mined_substrate_only_c4354b4/package/issue41_mined_substrate_only_20260518T103722Z/xcomet/native_mined_substrate_only.scored_pool.jsonl
|
circuit-shotting/artifacts/mined_substrate_only/issue41_mined_substrate_only_20260518T103722Z/manifests/manifest.json
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"upload_prefix": "issue41_mined_substrate_only_20260518T103722Z",
|
| 3 |
+
"run_root": "/root/runs/issue41_mined_substrate_only_c4354b4",
|
| 4 |
+
"file_count": 29,
|
| 5 |
+
"bytes": 13001442,
|
| 6 |
+
"source_issue39_artifacts": "TokenBender/circuit-discovery:circuit-shotting/artifacts/actdelta_lora_mlp_mvc/issue39_actdelta_lora_mlp_mvc_20260518T011201Z",
|
| 7 |
+
"weights_policy": "Includes generated hypotheses, scores, summaries, scripts, and logs. Excludes upstream HY-MT/XCOMET model weights, HF caches, API keys, and service tokens."
|
| 8 |
+
}
|
circuit-shotting/artifacts/mined_substrate_only/issue41_mined_substrate_only_20260518T103722Z/scripts/actdelta_mlp_common.py
ADDED
|
@@ -0,0 +1,252 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
"""Shared helpers for ActDeltaLoRA MLP MVC experiments."""
|
| 3 |
+
|
| 4 |
+
from __future__ import annotations
|
| 5 |
+
|
| 6 |
+
import json
|
| 7 |
+
from dataclasses import dataclass
|
| 8 |
+
from pathlib import Path
|
| 9 |
+
from typing import Any, Iterable
|
| 10 |
+
|
| 11 |
+
import numpy as np
|
| 12 |
+
import torch
|
| 13 |
+
import torch.nn.functional as F
|
| 14 |
+
|
| 15 |
+
from translation_io import DEFAULT_PROMPT_STYLE, Pair, load_flores_devtest_any
|
| 16 |
+
from translation_region_student import (
|
| 17 |
+
collate_translation,
|
| 18 |
+
decoder_root,
|
| 19 |
+
encode_supervised_row,
|
| 20 |
+
load_mask_npz,
|
| 21 |
+
save_mask_npz,
|
| 22 |
+
text_config,
|
| 23 |
+
)
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
@dataclass(frozen=True)
|
| 27 |
+
class Candidate:
|
| 28 |
+
name: str
|
| 29 |
+
ranges: tuple[tuple[int, int], ...]
|
| 30 |
+
meta: dict[str, Any]
|
| 31 |
+
|
| 32 |
+
|
| 33 |
+
def dtype_from_name(name: str) -> torch.dtype:
|
| 34 |
+
return {
|
| 35 |
+
"float32": torch.float32,
|
| 36 |
+
"float16": torch.float16,
|
| 37 |
+
"bfloat16": torch.bfloat16,
|
| 38 |
+
}[name]
|
| 39 |
+
|
| 40 |
+
|
| 41 |
+
def mlp_total(n_layers: int, d_ffn: int) -> int:
|
| 42 |
+
return int(n_layers) * int(d_ffn)
|
| 43 |
+
|
| 44 |
+
|
| 45 |
+
def flat_to_layer_channel(flat_idx: int, d_ffn: int) -> tuple[int, int]:
|
| 46 |
+
return int(flat_idx) // int(d_ffn), int(flat_idx) % int(d_ffn)
|
| 47 |
+
|
| 48 |
+
|
| 49 |
+
def sector_ranges(total: int, sectors: int) -> list[tuple[int, int]]:
|
| 50 |
+
return [
|
| 51 |
+
(int(total * i // sectors), int(total * (i + 1) // sectors))
|
| 52 |
+
for i in range(sectors)
|
| 53 |
+
]
|
| 54 |
+
|
| 55 |
+
|
| 56 |
+
def split_range(start: int, end: int, parts: int) -> list[tuple[int, int]]:
|
| 57 |
+
size = end - start
|
| 58 |
+
return [
|
| 59 |
+
(start + int(size * i // parts), start + int(size * (i + 1) // parts))
|
| 60 |
+
for i in range(parts)
|
| 61 |
+
]
|
| 62 |
+
|
| 63 |
+
|
| 64 |
+
def normalize_ranges(ranges: Iterable[tuple[int, int]]) -> tuple[tuple[int, int], ...]:
|
| 65 |
+
out = []
|
| 66 |
+
for start, end in ranges:
|
| 67 |
+
start = int(start)
|
| 68 |
+
end = int(end)
|
| 69 |
+
if end > start:
|
| 70 |
+
out.append((start, end))
|
| 71 |
+
return tuple(out)
|
| 72 |
+
|
| 73 |
+
|
| 74 |
+
def mask_from_ranges(ranges: Iterable[tuple[int, int]], n_layers: int,
|
| 75 |
+
d_ffn: int) -> dict[int, torch.Tensor]:
|
| 76 |
+
mask = {layer: torch.zeros(d_ffn, dtype=torch.bool) for layer in range(n_layers)}
|
| 77 |
+
total = mlp_total(n_layers, d_ffn)
|
| 78 |
+
for raw_start, raw_end in ranges:
|
| 79 |
+
start = max(0, int(raw_start))
|
| 80 |
+
end = min(total, int(raw_end))
|
| 81 |
+
for flat in range(start, end):
|
| 82 |
+
layer, channel = flat_to_layer_channel(flat, d_ffn)
|
| 83 |
+
mask[layer][channel] = True
|
| 84 |
+
return mask
|
| 85 |
+
|
| 86 |
+
|
| 87 |
+
def count_mask(mask: dict[int, torch.Tensor]) -> int:
|
| 88 |
+
return int(sum(int(v.sum().item()) for v in mask.values()))
|
| 89 |
+
|
| 90 |
+
|
| 91 |
+
def mask_to_ranges(mask: dict[int, torch.Tensor], d_ffn: int) -> list[tuple[int, int]]:
|
| 92 |
+
flats: list[int] = []
|
| 93 |
+
for layer, values in sorted(mask.items()):
|
| 94 |
+
idx = torch.nonzero(values.cpu(), as_tuple=False).flatten().tolist()
|
| 95 |
+
flats.extend([int(layer) * d_ffn + int(i) for i in idx])
|
| 96 |
+
if not flats:
|
| 97 |
+
return []
|
| 98 |
+
flats.sort()
|
| 99 |
+
ranges: list[tuple[int, int]] = []
|
| 100 |
+
start = prev = flats[0]
|
| 101 |
+
for flat in flats[1:]:
|
| 102 |
+
if flat == prev + 1:
|
| 103 |
+
prev = flat
|
| 104 |
+
continue
|
| 105 |
+
ranges.append((start, prev + 1))
|
| 106 |
+
start = prev = flat
|
| 107 |
+
ranges.append((start, prev + 1))
|
| 108 |
+
return ranges
|
| 109 |
+
|
| 110 |
+
|
| 111 |
+
def load_candidate_jsonl(path: str | Path) -> list[dict[str, Any]]:
|
| 112 |
+
rows: list[dict[str, Any]] = []
|
| 113 |
+
with Path(path).open() as f:
|
| 114 |
+
for line in f:
|
| 115 |
+
if line.strip():
|
| 116 |
+
rows.append(json.loads(line))
|
| 117 |
+
return rows
|
| 118 |
+
|
| 119 |
+
|
| 120 |
+
def write_jsonl(path: str | Path, rows: Iterable[dict[str, Any]]) -> None:
|
| 121 |
+
out = Path(path)
|
| 122 |
+
out.parent.mkdir(parents=True, exist_ok=True)
|
| 123 |
+
with out.open("w") as f:
|
| 124 |
+
for row in rows:
|
| 125 |
+
f.write(json.dumps(row, ensure_ascii=False) + "\n")
|
| 126 |
+
|
| 127 |
+
|
| 128 |
+
def load_pairs(path: str | None, *, src_lang: str = "eng_Latn",
|
| 129 |
+
tgt_lang: str = "por_Latn", max_rows: int | None = None) -> list[Pair]:
|
| 130 |
+
if path is None:
|
| 131 |
+
return load_flores_devtest_any(
|
| 132 |
+
src_lang=src_lang,
|
| 133 |
+
tgt_lang=tgt_lang,
|
| 134 |
+
max_examples=max_rows,
|
| 135 |
+
)
|
| 136 |
+
rows: list[Pair] = []
|
| 137 |
+
with Path(path).open() as f:
|
| 138 |
+
for line in f:
|
| 139 |
+
if not line.strip():
|
| 140 |
+
continue
|
| 141 |
+
raw = json.loads(line)
|
| 142 |
+
src = (raw.get("en") or raw.get("src") or "").strip()
|
| 143 |
+
tgt = (raw.get("model_hyp") or raw.get("pt") or raw.get("tgt") or "").strip()
|
| 144 |
+
if src and tgt:
|
| 145 |
+
rows.append(Pair(src=src, tgt=tgt))
|
| 146 |
+
if max_rows is not None and len(rows) >= max_rows:
|
| 147 |
+
break
|
| 148 |
+
return rows
|
| 149 |
+
|
| 150 |
+
|
| 151 |
+
def build_supervised_examples(pairs: list[Pair], tokenizer, *, target_language: str,
|
| 152 |
+
prompt_style: str = DEFAULT_PROMPT_STYLE,
|
| 153 |
+
max_seq_length: int = 1024) -> list[dict[str, Any]]:
|
| 154 |
+
examples: list[dict[str, Any]] = []
|
| 155 |
+
for pair in pairs:
|
| 156 |
+
row = {"en": pair.src, "target": pair.tgt, "raw": {"en": pair.src, "pt": pair.tgt}}
|
| 157 |
+
enc = encode_supervised_row(
|
| 158 |
+
row,
|
| 159 |
+
tokenizer,
|
| 160 |
+
target_language=target_language,
|
| 161 |
+
prompt_style=prompt_style,
|
| 162 |
+
max_seq_length=max_seq_length,
|
| 163 |
+
kl_on="answer",
|
| 164 |
+
)
|
| 165 |
+
if enc is not None:
|
| 166 |
+
examples.append(enc)
|
| 167 |
+
return examples
|
| 168 |
+
|
| 169 |
+
|
| 170 |
+
def iter_batches(examples: list[dict[str, Any]], *, batch_size: int, pad_id: int):
|
| 171 |
+
for start in range(0, len(examples), batch_size):
|
| 172 |
+
yield collate_translation(examples[start:start + batch_size], pad_id)
|
| 173 |
+
|
| 174 |
+
|
| 175 |
+
def move_batch(batch: dict[str, Any], device: str) -> dict[str, Any]:
|
| 176 |
+
return {k: v.to(device) if torch.is_tensor(v) else v for k, v in batch.items()}
|
| 177 |
+
|
| 178 |
+
|
| 179 |
+
def tokenwise_kl(teacher_logits: torch.Tensor, student_logits: torch.Tensor,
|
| 180 |
+
logit_mask: torch.Tensor) -> tuple[torch.Tensor, torch.Tensor]:
|
| 181 |
+
mask = logit_mask[:, :-1]
|
| 182 |
+
t_logits = teacher_logits[:, :-1, :]
|
| 183 |
+
s_logits = student_logits[:, :-1, :]
|
| 184 |
+
log_t = F.log_softmax(t_logits, dim=-1)
|
| 185 |
+
prob_t = log_t.exp()
|
| 186 |
+
log_s = F.log_softmax(s_logits, dim=-1)
|
| 187 |
+
kl = (prob_t * (log_t - log_s)).sum(dim=-1)
|
| 188 |
+
return kl, mask
|
| 189 |
+
|
| 190 |
+
|
| 191 |
+
def sentence_kl_values(teacher_logits: torch.Tensor, student_logits: torch.Tensor,
|
| 192 |
+
logit_mask: torch.Tensor) -> list[float]:
|
| 193 |
+
kl, mask = tokenwise_kl(teacher_logits, student_logits, logit_mask)
|
| 194 |
+
values: list[float] = []
|
| 195 |
+
for row_idx in range(kl.shape[0]):
|
| 196 |
+
row_mask = mask[row_idx]
|
| 197 |
+
if bool(row_mask.any().item()):
|
| 198 |
+
values.append(float(kl[row_idx][row_mask].mean().detach().cpu().item()))
|
| 199 |
+
else:
|
| 200 |
+
values.append(0.0)
|
| 201 |
+
return values
|
| 202 |
+
|
| 203 |
+
|
| 204 |
+
def install_mlp_nuke_hooks(model, nuke_mask: dict[int, torch.Tensor],
|
| 205 |
+
*, device: str, dtype: torch.dtype) -> list[Any]:
|
| 206 |
+
hooks: list[Any] = []
|
| 207 |
+
root = decoder_root(model)
|
| 208 |
+
for layer_idx, layer in enumerate(root.layers):
|
| 209 |
+
selected = nuke_mask[layer_idx].to(device)
|
| 210 |
+
if not bool(selected.any().item()):
|
| 211 |
+
continue
|
| 212 |
+
keep = (~selected).to(dtype=dtype).view(1, 1, -1)
|
| 213 |
+
|
| 214 |
+
def make_hook(keep: torch.Tensor):
|
| 215 |
+
def hook_fn(module, hook_args):
|
| 216 |
+
act = hook_args[0]
|
| 217 |
+
return (act * keep,) + hook_args[1:]
|
| 218 |
+
return hook_fn
|
| 219 |
+
|
| 220 |
+
hooks.append(layer.mlp.down_proj.register_forward_pre_hook(make_hook(keep)))
|
| 221 |
+
return hooks
|
| 222 |
+
|
| 223 |
+
|
| 224 |
+
def install_mlp_keep_only_hooks(model, keep_mask: dict[int, torch.Tensor],
|
| 225 |
+
*, device: str, dtype: torch.dtype) -> list[Any]:
|
| 226 |
+
"""Keep selected MLP down-proj input channels and zero every other MLP channel."""
|
| 227 |
+
hooks: list[Any] = []
|
| 228 |
+
root = decoder_root(model)
|
| 229 |
+
for layer_idx, layer in enumerate(root.layers):
|
| 230 |
+
keep = keep_mask[layer_idx].to(device=device, dtype=dtype).view(1, 1, -1)
|
| 231 |
+
|
| 232 |
+
def make_hook(keep: torch.Tensor):
|
| 233 |
+
def hook_fn(module, hook_args):
|
| 234 |
+
act = hook_args[0]
|
| 235 |
+
return (act * keep,) + hook_args[1:]
|
| 236 |
+
return hook_fn
|
| 237 |
+
|
| 238 |
+
hooks.append(layer.mlp.down_proj.register_forward_pre_hook(make_hook(keep)))
|
| 239 |
+
return hooks
|
| 240 |
+
|
| 241 |
+
|
| 242 |
+
def save_mask_for_candidate(out_dir: Path, candidate: Candidate, n_layers: int,
|
| 243 |
+
d_ffn: int) -> str:
|
| 244 |
+
mask = mask_from_ranges(candidate.ranges, n_layers, d_ffn)
|
| 245 |
+
path = out_dir / f"{candidate.name}.full.npz"
|
| 246 |
+
save_mask_npz(path, mask)
|
| 247 |
+
return str(path)
|
| 248 |
+
|
| 249 |
+
|
| 250 |
+
def model_mlp_shape(model) -> tuple[int, int, int]:
|
| 251 |
+
cfg = text_config(model)
|
| 252 |
+
return int(cfg.num_hidden_layers), int(cfg.hidden_size), int(cfg.intermediate_size)
|
circuit-shotting/artifacts/mined_substrate_only/issue41_mined_substrate_only_20260518T103722Z/scripts/evaluate_actdelta_lora_translation.py
ADDED
|
@@ -0,0 +1,216 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
"""Evaluate ActDeltaLoRA restoration for a nuked MLP final mix."""
|
| 3 |
+
|
| 4 |
+
from __future__ import annotations
|
| 5 |
+
|
| 6 |
+
import argparse
|
| 7 |
+
import json
|
| 8 |
+
import time
|
| 9 |
+
from pathlib import Path
|
| 10 |
+
from typing import Any
|
| 11 |
+
|
| 12 |
+
import sacrebleu
|
| 13 |
+
import torch
|
| 14 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 15 |
+
|
| 16 |
+
from actdelta_mlp_common import count_mask, dtype_from_name, load_pairs, model_mlp_shape
|
| 17 |
+
from translation_io import DEFAULT_PROMPT_STYLE, generate_translations
|
| 18 |
+
from translation_region_student import decoder_root, load_mask_npz
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
def parse_args() -> argparse.Namespace:
|
| 22 |
+
p = argparse.ArgumentParser(description=__doc__)
|
| 23 |
+
p.add_argument("--model", default="tencent/HY-MT1.5-1.8B")
|
| 24 |
+
p.add_argument("--mask", required=True)
|
| 25 |
+
p.add_argument("--factor-dir", required=True)
|
| 26 |
+
p.add_argument("--out-json", required=True)
|
| 27 |
+
p.add_argument("--dump-hyps", required=True)
|
| 28 |
+
p.add_argument("--input-jsonl", default=None)
|
| 29 |
+
p.add_argument("--max-rows", type=int, default=None)
|
| 30 |
+
p.add_argument("--start-idx", type=int, default=0)
|
| 31 |
+
p.add_argument("--end-idx", type=int, default=None)
|
| 32 |
+
p.add_argument("--batch-size", type=int, default=32)
|
| 33 |
+
p.add_argument("--max-new-tokens", type=int, default=384)
|
| 34 |
+
p.add_argument("--target-language", default="Portuguese")
|
| 35 |
+
p.add_argument("--prompt-style", default=DEFAULT_PROMPT_STYLE)
|
| 36 |
+
p.add_argument("--src-lang", default="eng_Latn")
|
| 37 |
+
p.add_argument("--tgt-lang", default="por_Latn")
|
| 38 |
+
p.add_argument("--device", default="cuda")
|
| 39 |
+
p.add_argument("--dtype", default="bfloat16", choices=["float32", "float16", "bfloat16"])
|
| 40 |
+
p.add_argument("--category", default="actdelta_eval")
|
| 41 |
+
p.add_argument("--tag", default="heldout")
|
| 42 |
+
p.add_argument("--system-name", default=None)
|
| 43 |
+
p.add_argument("--substrate-only", action="store_true",
|
| 44 |
+
help="Write reconstructed selected channels and zero every other MLP channel.")
|
| 45 |
+
return p.parse_args()
|
| 46 |
+
|
| 47 |
+
|
| 48 |
+
class ActDeltaController:
|
| 49 |
+
def __init__(self, payload: dict[str, Any], *, device: str, dtype: torch.dtype):
|
| 50 |
+
self.selected_indices = {
|
| 51 |
+
int(layer): torch.tensor(indices, dtype=torch.long)
|
| 52 |
+
for layer, indices in payload["selected_indices"].items()
|
| 53 |
+
}
|
| 54 |
+
self.layers = {}
|
| 55 |
+
for layer, data in payload["layers"].items():
|
| 56 |
+
self.layers[int(layer)] = {
|
| 57 |
+
"P": data["P"].to(device=device, dtype=torch.float32),
|
| 58 |
+
"B": data["B"].to(device=device, dtype=torch.float32),
|
| 59 |
+
}
|
| 60 |
+
self.device = device
|
| 61 |
+
self.dtype = dtype
|
| 62 |
+
|
| 63 |
+
def install(self, model, *, substrate_only: bool = False):
|
| 64 |
+
hooks = []
|
| 65 |
+
root = decoder_root(model)
|
| 66 |
+
hidden_cache: dict[int, torch.Tensor] = {}
|
| 67 |
+
layer_indices = range(len(root.layers)) if substrate_only else self.layers.keys()
|
| 68 |
+
for layer_idx in layer_indices:
|
| 69 |
+
layer = root.layers[layer_idx]
|
| 70 |
+
factors = self.layers.get(layer_idx)
|
| 71 |
+
selected_cpu = self.selected_indices.get(layer_idx)
|
| 72 |
+
|
| 73 |
+
def make_mlp_pre(idx: int):
|
| 74 |
+
def hook_fn(module, hook_args):
|
| 75 |
+
hidden_cache[idx] = hook_args[0].detach()
|
| 76 |
+
return hook_fn
|
| 77 |
+
|
| 78 |
+
def make_zero_down_pre():
|
| 79 |
+
def hook_fn(module, hook_args):
|
| 80 |
+
return (torch.zeros_like(hook_args[0]),) + hook_args[1:]
|
| 81 |
+
return hook_fn
|
| 82 |
+
|
| 83 |
+
def make_down_pre(idx: int, selected_cpu: torch.Tensor, p: torch.Tensor,
|
| 84 |
+
b: torch.Tensor, substrate_only: bool):
|
| 85 |
+
def hook_fn(module, hook_args):
|
| 86 |
+
act = hook_args[0]
|
| 87 |
+
hidden = hidden_cache.get(idx)
|
| 88 |
+
if hidden is None:
|
| 89 |
+
raise RuntimeError(f"missing MLP input cache for layer {idx}")
|
| 90 |
+
selected = selected_cpu.to(act.device)
|
| 91 |
+
coeff = hidden.to(torch.float32) @ p
|
| 92 |
+
delta = (coeff @ b).to(dtype=act.dtype)
|
| 93 |
+
patched = torch.zeros_like(act) if substrate_only else act.clone()
|
| 94 |
+
patched[..., selected] = delta
|
| 95 |
+
return (patched,) + hook_args[1:]
|
| 96 |
+
return hook_fn
|
| 97 |
+
|
| 98 |
+
if factors is None or selected_cpu is None:
|
| 99 |
+
hooks.append(layer.mlp.down_proj.register_forward_pre_hook(make_zero_down_pre()))
|
| 100 |
+
continue
|
| 101 |
+
|
| 102 |
+
hooks.append(layer.mlp.register_forward_pre_hook(make_mlp_pre(layer_idx)))
|
| 103 |
+
hooks.append(layer.mlp.down_proj.register_forward_pre_hook(
|
| 104 |
+
make_down_pre(layer_idx, selected_cpu, factors["P"], factors["B"], substrate_only)
|
| 105 |
+
))
|
| 106 |
+
return hooks
|
| 107 |
+
|
| 108 |
+
|
| 109 |
+
def score(hyps: list[str], refs: list[str]) -> dict:
|
| 110 |
+
return {
|
| 111 |
+
"chrFpp": float(sacrebleu.corpus_chrf(hyps, [refs], word_order=2).score),
|
| 112 |
+
"chrF": float(sacrebleu.corpus_chrf(hyps, [refs], word_order=0).score),
|
| 113 |
+
"BLEU": float(sacrebleu.corpus_bleu(hyps, [refs]).score),
|
| 114 |
+
"n": len(hyps),
|
| 115 |
+
}
|
| 116 |
+
|
| 117 |
+
|
| 118 |
+
def main() -> None:
|
| 119 |
+
args = parse_args()
|
| 120 |
+
dtype = dtype_from_name(args.dtype)
|
| 121 |
+
out_path = Path(args.out_json)
|
| 122 |
+
dump_path = Path(args.dump_hyps)
|
| 123 |
+
out_path.parent.mkdir(parents=True, exist_ok=True)
|
| 124 |
+
dump_path.parent.mkdir(parents=True, exist_ok=True)
|
| 125 |
+
|
| 126 |
+
tokenizer = AutoTokenizer.from_pretrained(args.model)
|
| 127 |
+
if tokenizer.pad_token_id is None:
|
| 128 |
+
tokenizer.pad_token = tokenizer.eos_token
|
| 129 |
+
model = AutoModelForCausalLM.from_pretrained(
|
| 130 |
+
args.model,
|
| 131 |
+
dtype=dtype,
|
| 132 |
+
attn_implementation="eager",
|
| 133 |
+
).to(args.device).eval()
|
| 134 |
+
model.config.use_cache = True
|
| 135 |
+
for param in model.parameters():
|
| 136 |
+
param.requires_grad_(False)
|
| 137 |
+
|
| 138 |
+
n_layers, hidden_size, d_ffn = model_mlp_shape(model)
|
| 139 |
+
mask = load_mask_npz(args.mask, n_layers, d_ffn)
|
| 140 |
+
payload = torch.load(Path(args.factor_dir) / "actdelta_lora.pt", map_location="cpu")
|
| 141 |
+
cfg = json.load(open(Path(args.factor_dir) / "config.json"))
|
| 142 |
+
controller = ActDeltaController(payload, device=args.device, dtype=dtype)
|
| 143 |
+
|
| 144 |
+
all_pairs = load_pairs(
|
| 145 |
+
args.input_jsonl,
|
| 146 |
+
src_lang=args.src_lang,
|
| 147 |
+
tgt_lang=args.tgt_lang,
|
| 148 |
+
max_rows=None,
|
| 149 |
+
)
|
| 150 |
+
end_idx = args.end_idx if args.end_idx is not None else len(all_pairs)
|
| 151 |
+
pairs = all_pairs[args.start_idx:end_idx]
|
| 152 |
+
if args.max_rows is not None:
|
| 153 |
+
pairs = pairs[:args.max_rows]
|
| 154 |
+
sources = [pair.src for pair in pairs]
|
| 155 |
+
refs = [pair.tgt for pair in pairs]
|
| 156 |
+
|
| 157 |
+
t0 = time.time()
|
| 158 |
+
hooks = controller.install(model, substrate_only=args.substrate_only)
|
| 159 |
+
try:
|
| 160 |
+
hyps = generate_translations(
|
| 161 |
+
model,
|
| 162 |
+
tokenizer,
|
| 163 |
+
sources,
|
| 164 |
+
target_language=args.target_language,
|
| 165 |
+
prompt_style=args.prompt_style,
|
| 166 |
+
batch_size=args.batch_size,
|
| 167 |
+
max_new_tokens=args.max_new_tokens,
|
| 168 |
+
do_sample=False,
|
| 169 |
+
device=args.device,
|
| 170 |
+
)
|
| 171 |
+
finally:
|
| 172 |
+
for hook in hooks:
|
| 173 |
+
hook.remove()
|
| 174 |
+
scores = score(hyps, refs)
|
| 175 |
+
elapsed_s = time.time() - t0
|
| 176 |
+
|
| 177 |
+
system_name = args.system_name or f"actdelta_rank_{cfg.get('rank')}"
|
| 178 |
+
method = "actdelta_lora_mlp_substrate_only" if args.substrate_only else "actdelta_lora_mlp_restore"
|
| 179 |
+
with dump_path.open("w") as f:
|
| 180 |
+
for idx, (pair, hyp) in enumerate(zip(pairs, hyps)):
|
| 181 |
+
f.write(json.dumps({
|
| 182 |
+
"id": args.start_idx + idx,
|
| 183 |
+
"en": pair.src,
|
| 184 |
+
"pt": pair.tgt,
|
| 185 |
+
"model_hyp": hyp,
|
| 186 |
+
"category": args.category,
|
| 187 |
+
"tag": args.tag,
|
| 188 |
+
"mask_name": system_name,
|
| 189 |
+
"method": method,
|
| 190 |
+
"substrate_only": args.substrate_only,
|
| 191 |
+
"rank": cfg.get("rank"),
|
| 192 |
+
"channels": count_mask(mask),
|
| 193 |
+
"factor_dir": args.factor_dir,
|
| 194 |
+
}, ensure_ascii=False) + "\n")
|
| 195 |
+
|
| 196 |
+
out = {
|
| 197 |
+
"model": args.model,
|
| 198 |
+
"mask": args.mask,
|
| 199 |
+
"factor_dir": args.factor_dir,
|
| 200 |
+
"rank": cfg.get("rank"),
|
| 201 |
+
"parameter_count": cfg.get("parameter_count"),
|
| 202 |
+
"channels": count_mask(mask),
|
| 203 |
+
"substrate_only": args.substrate_only,
|
| 204 |
+
"scores": scores,
|
| 205 |
+
"elapsed_s": elapsed_s,
|
| 206 |
+
"dump_hyps": str(dump_path),
|
| 207 |
+
"n_layers": n_layers,
|
| 208 |
+
"hidden_size": hidden_size,
|
| 209 |
+
"d_ffn": d_ffn,
|
| 210 |
+
}
|
| 211 |
+
out_path.write_text(json.dumps(out, indent=2, ensure_ascii=False) + "\n")
|
| 212 |
+
print(json.dumps({"system": system_name, "scores": scores}, indent=2), flush=True)
|
| 213 |
+
|
| 214 |
+
|
| 215 |
+
if __name__ == "__main__":
|
| 216 |
+
main()
|
circuit-shotting/artifacts/mined_substrate_only/issue41_mined_substrate_only_20260518T103722Z/scripts/evaluate_mlp_nuke_translation.py
ADDED
|
@@ -0,0 +1,212 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
"""Evaluate HY-MT EN->PT generation with selected MLP channels zero-nuked."""
|
| 3 |
+
|
| 4 |
+
from __future__ import annotations
|
| 5 |
+
|
| 6 |
+
import argparse
|
| 7 |
+
import json
|
| 8 |
+
import time
|
| 9 |
+
from pathlib import Path
|
| 10 |
+
|
| 11 |
+
import sacrebleu
|
| 12 |
+
import torch
|
| 13 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 14 |
+
|
| 15 |
+
from actdelta_mlp_common import (
|
| 16 |
+
count_mask,
|
| 17 |
+
dtype_from_name,
|
| 18 |
+
install_mlp_keep_only_hooks,
|
| 19 |
+
install_mlp_nuke_hooks,
|
| 20 |
+
load_pairs,
|
| 21 |
+
model_mlp_shape,
|
| 22 |
+
)
|
| 23 |
+
from translation_io import DEFAULT_PROMPT_STYLE, generate_translations
|
| 24 |
+
from translation_region_student import load_mask_npz
|
| 25 |
+
|
| 26 |
+
|
| 27 |
+
def parse_args() -> argparse.Namespace:
|
| 28 |
+
p = argparse.ArgumentParser(description=__doc__)
|
| 29 |
+
p.add_argument("--model", default="tencent/HY-MT1.5-1.8B")
|
| 30 |
+
p.add_argument("--mask", action="append", default=[], metavar="NAME:PATH")
|
| 31 |
+
p.add_argument("--out-json", required=True)
|
| 32 |
+
p.add_argument("--dump-dir", required=True)
|
| 33 |
+
p.add_argument("--input-jsonl", default=None)
|
| 34 |
+
p.add_argument("--max-rows", type=int, default=None)
|
| 35 |
+
p.add_argument("--start-idx", type=int, default=0)
|
| 36 |
+
p.add_argument("--end-idx", type=int, default=None)
|
| 37 |
+
p.add_argument("--batch-size", type=int, default=32)
|
| 38 |
+
p.add_argument("--max-new-tokens", type=int, default=384)
|
| 39 |
+
p.add_argument("--target-language", default="Portuguese")
|
| 40 |
+
p.add_argument("--prompt-style", default=DEFAULT_PROMPT_STYLE)
|
| 41 |
+
p.add_argument("--src-lang", default="eng_Latn")
|
| 42 |
+
p.add_argument("--tgt-lang", default="por_Latn")
|
| 43 |
+
p.add_argument("--device", default="cuda")
|
| 44 |
+
p.add_argument("--dtype", default="bfloat16", choices=["float32", "float16", "bfloat16"])
|
| 45 |
+
p.add_argument("--include-no-mask", action="store_true")
|
| 46 |
+
p.add_argument("--intervention", default="nuke-zero", choices=["nuke-zero", "keep-only"],
|
| 47 |
+
help="nuke-zero zeros selected channels; keep-only zeros every non-selected MLP channel.")
|
| 48 |
+
p.add_argument("--category", default="actdelta_eval")
|
| 49 |
+
p.add_argument("--tag", default="heldout")
|
| 50 |
+
return p.parse_args()
|
| 51 |
+
|
| 52 |
+
|
| 53 |
+
def parse_mask_specs(values: list[str]) -> list[tuple[str, Path]]:
|
| 54 |
+
out = []
|
| 55 |
+
for value in values:
|
| 56 |
+
if ":" not in value:
|
| 57 |
+
raise ValueError(f"--mask must be NAME:PATH, got {value!r}")
|
| 58 |
+
name, path = value.split(":", 1)
|
| 59 |
+
out.append((name, Path(path)))
|
| 60 |
+
return out
|
| 61 |
+
|
| 62 |
+
|
| 63 |
+
def dump_hyps(path: Path, pairs, hyps: list[str], *, mask_name: str, extra: dict) -> None:
|
| 64 |
+
path.parent.mkdir(parents=True, exist_ok=True)
|
| 65 |
+
with path.open("w") as f:
|
| 66 |
+
for idx, (pair, hyp) in enumerate(zip(pairs, hyps)):
|
| 67 |
+
f.write(json.dumps({
|
| 68 |
+
"id": idx,
|
| 69 |
+
"en": pair.src,
|
| 70 |
+
"pt": pair.tgt,
|
| 71 |
+
"model_hyp": hyp,
|
| 72 |
+
"category": extra.get("category", "actdelta_eval"),
|
| 73 |
+
"tag": extra.get("tag", "heldout"),
|
| 74 |
+
"mask_name": mask_name,
|
| 75 |
+
**{k: v for k, v in extra.items() if k not in {"category", "tag"}},
|
| 76 |
+
}, ensure_ascii=False) + "\n")
|
| 77 |
+
|
| 78 |
+
|
| 79 |
+
def score(hyps: list[str], refs: list[str]) -> dict:
|
| 80 |
+
return {
|
| 81 |
+
"chrFpp": float(sacrebleu.corpus_chrf(hyps, [refs], word_order=2).score),
|
| 82 |
+
"chrF": float(sacrebleu.corpus_chrf(hyps, [refs], word_order=0).score),
|
| 83 |
+
"BLEU": float(sacrebleu.corpus_bleu(hyps, [refs]).score),
|
| 84 |
+
"n": len(hyps),
|
| 85 |
+
}
|
| 86 |
+
|
| 87 |
+
|
| 88 |
+
def main() -> None:
|
| 89 |
+
args = parse_args()
|
| 90 |
+
dtype = dtype_from_name(args.dtype)
|
| 91 |
+
out_path = Path(args.out_json)
|
| 92 |
+
dump_dir = Path(args.dump_dir)
|
| 93 |
+
out_path.parent.mkdir(parents=True, exist_ok=True)
|
| 94 |
+
dump_dir.mkdir(parents=True, exist_ok=True)
|
| 95 |
+
|
| 96 |
+
tokenizer = AutoTokenizer.from_pretrained(args.model)
|
| 97 |
+
if tokenizer.pad_token_id is None:
|
| 98 |
+
tokenizer.pad_token = tokenizer.eos_token
|
| 99 |
+
model = AutoModelForCausalLM.from_pretrained(
|
| 100 |
+
args.model,
|
| 101 |
+
dtype=dtype,
|
| 102 |
+
attn_implementation="eager",
|
| 103 |
+
).to(args.device).eval()
|
| 104 |
+
model.config.use_cache = True
|
| 105 |
+
for param in model.parameters():
|
| 106 |
+
param.requires_grad_(False)
|
| 107 |
+
|
| 108 |
+
n_layers, hidden_size, d_ffn = model_mlp_shape(model)
|
| 109 |
+
all_pairs = load_pairs(
|
| 110 |
+
args.input_jsonl,
|
| 111 |
+
src_lang=args.src_lang,
|
| 112 |
+
tgt_lang=args.tgt_lang,
|
| 113 |
+
max_rows=None,
|
| 114 |
+
)
|
| 115 |
+
end_idx = args.end_idx if args.end_idx is not None else len(all_pairs)
|
| 116 |
+
pairs = all_pairs[args.start_idx:end_idx]
|
| 117 |
+
if args.max_rows is not None:
|
| 118 |
+
pairs = pairs[:args.max_rows]
|
| 119 |
+
sources = [pair.src for pair in pairs]
|
| 120 |
+
refs = [pair.tgt for pair in pairs]
|
| 121 |
+
|
| 122 |
+
results = {}
|
| 123 |
+
if args.include_no_mask:
|
| 124 |
+
t0 = time.time()
|
| 125 |
+
hyps = generate_translations(
|
| 126 |
+
model,
|
| 127 |
+
tokenizer,
|
| 128 |
+
sources,
|
| 129 |
+
target_language=args.target_language,
|
| 130 |
+
prompt_style=args.prompt_style,
|
| 131 |
+
batch_size=args.batch_size,
|
| 132 |
+
max_new_tokens=args.max_new_tokens,
|
| 133 |
+
do_sample=False,
|
| 134 |
+
device=args.device,
|
| 135 |
+
)
|
| 136 |
+
scores = score(hyps, refs)
|
| 137 |
+
dump_path = dump_dir / "no_mask.jsonl"
|
| 138 |
+
dump_hyps(dump_path, pairs, hyps, mask_name="no_mask",
|
| 139 |
+
extra={"category": args.category, "tag": args.tag, "method": "no_mask"})
|
| 140 |
+
results["no_mask"] = {
|
| 141 |
+
"scores": scores,
|
| 142 |
+
"elapsed_s": time.time() - t0,
|
| 143 |
+
"dump_path": str(dump_path),
|
| 144 |
+
"channels": 0,
|
| 145 |
+
}
|
| 146 |
+
print(json.dumps({"name": "no_mask", "scores": scores}), flush=True)
|
| 147 |
+
|
| 148 |
+
for name, mask_path in parse_mask_specs(args.mask):
|
| 149 |
+
mask = load_mask_npz(mask_path, n_layers, d_ffn)
|
| 150 |
+
channels = count_mask(mask)
|
| 151 |
+
t0 = time.time()
|
| 152 |
+
if args.intervention == "nuke-zero":
|
| 153 |
+
hooks = install_mlp_nuke_hooks(model, mask, device=args.device, dtype=dtype)
|
| 154 |
+
method = "mlp_nuke_zero"
|
| 155 |
+
else:
|
| 156 |
+
hooks = install_mlp_keep_only_hooks(model, mask, device=args.device, dtype=dtype)
|
| 157 |
+
method = "mlp_keep_only_zero"
|
| 158 |
+
try:
|
| 159 |
+
hyps = generate_translations(
|
| 160 |
+
model,
|
| 161 |
+
tokenizer,
|
| 162 |
+
sources,
|
| 163 |
+
target_language=args.target_language,
|
| 164 |
+
prompt_style=args.prompt_style,
|
| 165 |
+
batch_size=args.batch_size,
|
| 166 |
+
max_new_tokens=args.max_new_tokens,
|
| 167 |
+
do_sample=False,
|
| 168 |
+
device=args.device,
|
| 169 |
+
)
|
| 170 |
+
finally:
|
| 171 |
+
for hook in hooks:
|
| 172 |
+
hook.remove()
|
| 173 |
+
scores = score(hyps, refs)
|
| 174 |
+
dump_path = dump_dir / f"{name}.jsonl"
|
| 175 |
+
dump_hyps(
|
| 176 |
+
dump_path,
|
| 177 |
+
pairs,
|
| 178 |
+
hyps,
|
| 179 |
+
mask_name=name,
|
| 180 |
+
extra={
|
| 181 |
+
"category": args.category,
|
| 182 |
+
"tag": args.tag,
|
| 183 |
+
"method": method,
|
| 184 |
+
"intervention": args.intervention,
|
| 185 |
+
"channels": channels,
|
| 186 |
+
"mask_path": str(mask_path),
|
| 187 |
+
},
|
| 188 |
+
)
|
| 189 |
+
results[name] = {
|
| 190 |
+
"scores": scores,
|
| 191 |
+
"elapsed_s": time.time() - t0,
|
| 192 |
+
"dump_path": str(dump_path),
|
| 193 |
+
"channels": channels,
|
| 194 |
+
"mask_path": str(mask_path),
|
| 195 |
+
"intervention": args.intervention,
|
| 196 |
+
}
|
| 197 |
+
print(json.dumps({"name": name, "channels": channels, "scores": scores}), flush=True)
|
| 198 |
+
|
| 199 |
+
payload = {
|
| 200 |
+
"model": args.model,
|
| 201 |
+
"n_layers": n_layers,
|
| 202 |
+
"hidden_size": hidden_size,
|
| 203 |
+
"d_ffn": d_ffn,
|
| 204 |
+
"row_slice": {"start_idx": args.start_idx, "end_idx": end_idx},
|
| 205 |
+
"n_rows": len(pairs),
|
| 206 |
+
"results": results,
|
| 207 |
+
}
|
| 208 |
+
out_path.write_text(json.dumps(payload, indent=2, ensure_ascii=False) + "\n")
|
| 209 |
+
|
| 210 |
+
|
| 211 |
+
if __name__ == "__main__":
|
| 212 |
+
main()
|
circuit-shotting/artifacts/mined_substrate_only/issue41_mined_substrate_only_20260518T103722Z/scripts/issue41_substrate_only_runner.sh
ADDED
|
@@ -0,0 +1,252 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env bash
|
| 2 |
+
# Issue #41 native and ActDelta substrate-only EN->PT eval runner.
|
| 3 |
+
set -euo pipefail
|
| 4 |
+
|
| 5 |
+
export TOKENIZERS_PARALLELISM="${TOKENIZERS_PARALLELISM:-false}"
|
| 6 |
+
export TORCH_ALLOW_TF32_CUBLAS_OVERRIDE="${TORCH_ALLOW_TF32_CUBLAS_OVERRIDE:-1}"
|
| 7 |
+
|
| 8 |
+
REPO_DIR="${REPO_DIR:-/root/work/circuit-shotting}"
|
| 9 |
+
cd "$REPO_DIR"
|
| 10 |
+
|
| 11 |
+
MODEL="${MODEL:-tencent/HY-MT1.5-1.8B}"
|
| 12 |
+
RUN_ROOT="${RUN_ROOT:-/root/runs/issue41_mined_substrate_only}"
|
| 13 |
+
ARTIFACT_REPO="${ARTIFACT_REPO:-TokenBender/circuit-discovery}"
|
| 14 |
+
ARTIFACT_PREFIX="${ARTIFACT_PREFIX:-circuit-shotting/artifacts/actdelta_lora_mlp_mvc/issue39_actdelta_lora_mlp_mvc_20260518T011201Z}"
|
| 15 |
+
ARTIFACT_DIR="${ARTIFACT_DIR:-$RUN_ROOT/source_issue39}"
|
| 16 |
+
NTREX_JSONL="${NTREX_JSONL:-/root/runs/ntrex_eval/ntrex_en2pt.jsonl}"
|
| 17 |
+
GPU_LIST="${GPU_LIST:-}"
|
| 18 |
+
EVAL_MAX_ROWS="${EVAL_MAX_ROWS:-}"
|
| 19 |
+
BATCH_SIZE_GEN="${BATCH_SIZE_GEN:-32}"
|
| 20 |
+
XCOMET_SERVICE_BASE_PORT="${XCOMET_SERVICE_BASE_PORT:-10001}"
|
| 21 |
+
XCOMET_BATCH_SIZE="${XCOMET_BATCH_SIZE:-4}"
|
| 22 |
+
XCOMET_CHUNK_SIZE="${XCOMET_CHUNK_SIZE:-16}"
|
| 23 |
+
XCOMET_SERVICE_LOAD_TIMEOUT_S="${XCOMET_SERVICE_LOAD_TIMEOUT_S:-1800}"
|
| 24 |
+
BASELINE_XCOMET="${BASELINE_XCOMET:-0.9287162019683438}"
|
| 25 |
+
UPLOAD_AFTER="${UPLOAD_AFTER:-0}"
|
| 26 |
+
|
| 27 |
+
mkdir -p "$RUN_ROOT"/{logs,eval,dumps,xcomet,xcomet_shards,services,summaries,package}
|
| 28 |
+
|
| 29 |
+
mark() {
|
| 30 |
+
echo "[$(date -Iseconds)] $*" | tee -a "$RUN_ROOT/logs/issue41_progress.log"
|
| 31 |
+
}
|
| 32 |
+
|
| 33 |
+
detect_gpus() {
|
| 34 |
+
if [[ -n "$GPU_LIST" ]]; then
|
| 35 |
+
echo "$GPU_LIST" | tr ',' ' '
|
| 36 |
+
return
|
| 37 |
+
fi
|
| 38 |
+
nvidia-smi --query-gpu=index --format=csv,noheader | tr '\n' ' '
|
| 39 |
+
}
|
| 40 |
+
|
| 41 |
+
read -r -a GPU_ARRAY <<<"$(detect_gpus)"
|
| 42 |
+
GPU_COUNT="${#GPU_ARRAY[@]}"
|
| 43 |
+
if ((GPU_COUNT < 1)); then
|
| 44 |
+
echo "no GPUs found" >&2
|
| 45 |
+
exit 2
|
| 46 |
+
fi
|
| 47 |
+
|
| 48 |
+
MASK="$ARTIFACT_DIR/selection/chunks/masks/final_mix_top_3.full.npz"
|
| 49 |
+
FACTOR_DIR="$ARTIFACT_DIR/factors/rank_256"
|
| 50 |
+
|
| 51 |
+
download_artifacts() {
|
| 52 |
+
if [[ -f "$MASK" && -f "$FACTOR_DIR/actdelta_lora.pt" && -f "$FACTOR_DIR/config.json" ]]; then
|
| 53 |
+
return 0
|
| 54 |
+
fi
|
| 55 |
+
mark "download preserved issue39 final mask and rank256 factors"
|
| 56 |
+
python3 - "$ARTIFACT_REPO" "$ARTIFACT_PREFIX" "$ARTIFACT_DIR" <<'PY'
|
| 57 |
+
import shutil
|
| 58 |
+
import sys
|
| 59 |
+
from pathlib import Path
|
| 60 |
+
from huggingface_hub import hf_hub_download
|
| 61 |
+
|
| 62 |
+
repo, prefix, artifact_dir = sys.argv[1], sys.argv[2], Path(sys.argv[3])
|
| 63 |
+
files = [
|
| 64 |
+
"selection/chunks/masks/final_mix_top_3.full.npz",
|
| 65 |
+
"factors/rank_256/actdelta_lora.pt",
|
| 66 |
+
"factors/rank_256/config.json",
|
| 67 |
+
]
|
| 68 |
+
for rel in files:
|
| 69 |
+
src = Path(hf_hub_download(repo_id=repo, repo_type="dataset", filename=f"{prefix}/{rel}"))
|
| 70 |
+
dst = artifact_dir / rel
|
| 71 |
+
dst.parent.mkdir(parents=True, exist_ok=True)
|
| 72 |
+
shutil.copy2(src, dst)
|
| 73 |
+
print(dst)
|
| 74 |
+
PY
|
| 75 |
+
}
|
| 76 |
+
|
| 77 |
+
build_ntrex() {
|
| 78 |
+
if [[ -f "$NTREX_JSONL" ]]; then
|
| 79 |
+
return 0
|
| 80 |
+
fi
|
| 81 |
+
mark "build NTREX EN->PT held-out jsonl"
|
| 82 |
+
python3 build_ntrex_en2pt_jsonl.py > "$RUN_ROOT/logs/build_ntrex.log" 2>&1
|
| 83 |
+
}
|
| 84 |
+
|
| 85 |
+
eval_native() {
|
| 86 |
+
if [[ -s "$RUN_ROOT/eval/native_substrate_only.json" ]]; then
|
| 87 |
+
return 0
|
| 88 |
+
fi
|
| 89 |
+
mark "eval native mined-substrate-only"
|
| 90 |
+
CUDA_VISIBLE_DEVICES="${GPU_ARRAY[0]}" python3 evaluate_mlp_nuke_translation.py \
|
| 91 |
+
--model "$MODEL" \
|
| 92 |
+
--input-jsonl "$NTREX_JSONL" \
|
| 93 |
+
--out-json "$RUN_ROOT/eval/native_substrate_only.json" \
|
| 94 |
+
--dump-dir "$RUN_ROOT/dumps/ntrex" \
|
| 95 |
+
--mask "native_mined_substrate_only:$MASK" \
|
| 96 |
+
--intervention keep-only \
|
| 97 |
+
${EVAL_MAX_ROWS:+--max-rows "$EVAL_MAX_ROWS"} \
|
| 98 |
+
--batch-size "$BATCH_SIZE_GEN" \
|
| 99 |
+
--category "ntrex_test" \
|
| 100 |
+
--tag "heldout" \
|
| 101 |
+
> "$RUN_ROOT/logs/eval_native_substrate_only.log" 2>&1
|
| 102 |
+
}
|
| 103 |
+
|
| 104 |
+
eval_actdelta() {
|
| 105 |
+
if [[ -s "$RUN_ROOT/eval/actdelta_rank256_substrate_only.json" ]]; then
|
| 106 |
+
return 0
|
| 107 |
+
fi
|
| 108 |
+
mark "eval ActDelta rank256 repair-substrate-only"
|
| 109 |
+
CUDA_VISIBLE_DEVICES="${GPU_ARRAY[0]}" python3 evaluate_actdelta_lora_translation.py \
|
| 110 |
+
--model "$MODEL" \
|
| 111 |
+
--mask "$MASK" \
|
| 112 |
+
--factor-dir "$FACTOR_DIR" \
|
| 113 |
+
--input-jsonl "$NTREX_JSONL" \
|
| 114 |
+
--out-json "$RUN_ROOT/eval/actdelta_rank256_substrate_only.json" \
|
| 115 |
+
--dump-hyps "$RUN_ROOT/dumps/ntrex/actdelta_rank256_substrate_only.jsonl" \
|
| 116 |
+
${EVAL_MAX_ROWS:+--max-rows "$EVAL_MAX_ROWS"} \
|
| 117 |
+
--batch-size "$BATCH_SIZE_GEN" \
|
| 118 |
+
--category "ntrex_test" \
|
| 119 |
+
--tag "heldout" \
|
| 120 |
+
--system-name "actdelta_rank256_substrate_only" \
|
| 121 |
+
--substrate-only \
|
| 122 |
+
> "$RUN_ROOT/logs/eval_actdelta_rank256_substrate_only.log" 2>&1
|
| 123 |
+
}
|
| 124 |
+
|
| 125 |
+
start_xcomet_service() {
|
| 126 |
+
local service_idx="$1"
|
| 127 |
+
local gpu="$2"
|
| 128 |
+
local port="$3"
|
| 129 |
+
local service_root="$RUN_ROOT/services/xcomet_${service_idx}"
|
| 130 |
+
mkdir -p "$service_root"
|
| 131 |
+
if [[ ! -s "$service_root/service.token" ]]; then
|
| 132 |
+
python3 - "$service_root/service.token" <<'PY'
|
| 133 |
+
import secrets, sys
|
| 134 |
+
from pathlib import Path
|
| 135 |
+
p = Path(sys.argv[1])
|
| 136 |
+
p.write_text(secrets.token_urlsafe(32))
|
| 137 |
+
p.chmod(0o600)
|
| 138 |
+
PY
|
| 139 |
+
fi
|
| 140 |
+
if [[ -s "$service_root/service.pid" ]] && kill -0 "$(cat "$service_root/service.pid")" 2>/dev/null; then
|
| 141 |
+
return 0
|
| 142 |
+
fi
|
| 143 |
+
mark "start XCOMET service idx=$service_idx gpu=$gpu port=$port"
|
| 144 |
+
CUDA_VISIBLE_DEVICES="$gpu" XCOMET_SERVICE_TOKEN="$(cat "$service_root/service.token")" \
|
| 145 |
+
nohup python3 xcomet_service.py \
|
| 146 |
+
--host 0.0.0.0 --port "$port" \
|
| 147 |
+
--comet-model "${XCOMET_MODEL:-Unbabel/XCOMET-XXL}" \
|
| 148 |
+
--run-root "$service_root" \
|
| 149 |
+
--default-batch-size "$XCOMET_BATCH_SIZE" \
|
| 150 |
+
--default-chunk-size "$XCOMET_CHUNK_SIZE" \
|
| 151 |
+
--max-worker-batch-size "$XCOMET_BATCH_SIZE" \
|
| 152 |
+
--max-batch-rows "$XCOMET_CHUNK_SIZE" \
|
| 153 |
+
--max-batch-wait-ms 100 \
|
| 154 |
+
--max-queue-rows 4096 \
|
| 155 |
+
--queue-timeout-s 7200 \
|
| 156 |
+
--float32-matmul-precision high \
|
| 157 |
+
--load-on-start \
|
| 158 |
+
> "$service_root/service.log" 2>&1 &
|
| 159 |
+
echo "$!" > "$service_root/service.pid"
|
| 160 |
+
}
|
| 161 |
+
|
| 162 |
+
wait_xcomet_service() {
|
| 163 |
+
local service_idx="$1"
|
| 164 |
+
local port="$2"
|
| 165 |
+
local service_root="$RUN_ROOT/services/xcomet_${service_idx}"
|
| 166 |
+
local start_ts now elapsed
|
| 167 |
+
start_ts="$(date +%s)"
|
| 168 |
+
while true; do
|
| 169 |
+
if [[ -s "$service_root/service.pid" ]] && ! kill -0 "$(cat "$service_root/service.pid")" 2>/dev/null; then
|
| 170 |
+
tail -n 200 "$service_root/service.log" >&2 || true
|
| 171 |
+
return 1
|
| 172 |
+
fi
|
| 173 |
+
if curl -fsS -H "Authorization: Bearer $(cat "$service_root/service.token")" \
|
| 174 |
+
"http://127.0.0.1:${port}/health" > "$service_root/health.json" 2>/dev/null; then
|
| 175 |
+
if grep -q '"model_loaded": true' "$service_root/health.json"; then
|
| 176 |
+
mark "XCOMET service idx=$service_idx healthy on port=$port"
|
| 177 |
+
return 0
|
| 178 |
+
fi
|
| 179 |
+
fi
|
| 180 |
+
now="$(date +%s)"
|
| 181 |
+
elapsed=$((now - start_ts))
|
| 182 |
+
if ((elapsed > XCOMET_SERVICE_LOAD_TIMEOUT_S)); then
|
| 183 |
+
tail -n 200 "$service_root/service.log" >&2 || true
|
| 184 |
+
return 1
|
| 185 |
+
fi
|
| 186 |
+
sleep 15
|
| 187 |
+
done
|
| 188 |
+
}
|
| 189 |
+
|
| 190 |
+
start_xcomet_services() {
|
| 191 |
+
mark "start $GPU_COUNT XCOMET services sequentially"
|
| 192 |
+
for ((j=0; j<GPU_COUNT; j++)); do
|
| 193 |
+
start_xcomet_service "$j" "${GPU_ARRAY[$j]}" "$((XCOMET_SERVICE_BASE_PORT + j))"
|
| 194 |
+
wait_xcomet_service "$j" "$((XCOMET_SERVICE_BASE_PORT + j))"
|
| 195 |
+
done
|
| 196 |
+
}
|
| 197 |
+
|
| 198 |
+
score_xcomet_name() {
|
| 199 |
+
local name="$1"
|
| 200 |
+
local hyps="$2"
|
| 201 |
+
local out="$RUN_ROOT/xcomet/${name}.json"
|
| 202 |
+
if [[ -s "$out" ]]; then
|
| 203 |
+
return 0
|
| 204 |
+
fi
|
| 205 |
+
service_args=()
|
| 206 |
+
for ((j=0; j<GPU_COUNT; j++)); do
|
| 207 |
+
service_args+=(--service "$j,http://127.0.0.1:$((XCOMET_SERVICE_BASE_PORT + j)),$RUN_ROOT/services/xcomet_${j}/service.token")
|
| 208 |
+
done
|
| 209 |
+
mark "XCOMET score $name"
|
| 210 |
+
python3 score_xcomet_sharded.py \
|
| 211 |
+
--hyps-jsonl "$hyps" \
|
| 212 |
+
--out-json "$out" \
|
| 213 |
+
--out-jsonl "$RUN_ROOT/xcomet/${name}.scored_pool.jsonl" \
|
| 214 |
+
--shard-dir "$RUN_ROOT/xcomet_shards/$name" \
|
| 215 |
+
--request-id "issue41_${name}" \
|
| 216 |
+
--system-name "issue41_${name}" \
|
| 217 |
+
--batch-size "$XCOMET_BATCH_SIZE" \
|
| 218 |
+
--chunk-size "$XCOMET_CHUNK_SIZE" \
|
| 219 |
+
--timeout-s 7200 \
|
| 220 |
+
"${service_args[@]}" \
|
| 221 |
+
> "$RUN_ROOT/logs/xcomet_${name}.log" 2>&1
|
| 222 |
+
}
|
| 223 |
+
|
| 224 |
+
score_xcomet() {
|
| 225 |
+
start_xcomet_services
|
| 226 |
+
score_xcomet_name "native_mined_substrate_only" "$RUN_ROOT/dumps/ntrex/native_mined_substrate_only.jsonl"
|
| 227 |
+
score_xcomet_name "actdelta_rank256_substrate_only" "$RUN_ROOT/dumps/ntrex/actdelta_rank256_substrate_only.jsonl"
|
| 228 |
+
}
|
| 229 |
+
|
| 230 |
+
summarize() {
|
| 231 |
+
mark "summarize issue41"
|
| 232 |
+
python3 summarize_issue41_substrate_only.py \
|
| 233 |
+
--run-root "$RUN_ROOT" \
|
| 234 |
+
--baseline-xcomet "$BASELINE_XCOMET" \
|
| 235 |
+
--out-json "$RUN_ROOT/summaries/issue41_summary.json" \
|
| 236 |
+
--out-md "$RUN_ROOT/summaries/issue41_summary.md" \
|
| 237 |
+
> "$RUN_ROOT/logs/summarize_issue41.log" 2>&1
|
| 238 |
+
}
|
| 239 |
+
|
| 240 |
+
mark "issue41 start substrate-only eval gpus=${GPU_ARRAY[*]}"
|
| 241 |
+
download_artifacts
|
| 242 |
+
build_ntrex
|
| 243 |
+
eval_native
|
| 244 |
+
eval_actdelta
|
| 245 |
+
score_xcomet
|
| 246 |
+
summarize
|
| 247 |
+
if [[ "$UPLOAD_AFTER" == "1" || "$UPLOAD_AFTER" == "true" ]]; then
|
| 248 |
+
mark "package and upload issue41 artifacts"
|
| 249 |
+
RUN_ROOT="$RUN_ROOT" REPO_DIR="$REPO_DIR" bash scripts/package_issue41_hf_upload.sh \
|
| 250 |
+
> "$RUN_ROOT/logs/package_issue41_hf_upload.log" 2>&1
|
| 251 |
+
fi
|
| 252 |
+
mark "issue41 done"
|
circuit-shotting/artifacts/mined_substrate_only/issue41_mined_substrate_only_20260518T103722Z/scripts/package_issue41_hf_upload.sh
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env bash
|
| 2 |
+
# Package and upload issue #41 substrate-only artifacts.
|
| 3 |
+
set -euo pipefail
|
| 4 |
+
|
| 5 |
+
RUN_ROOT="${RUN_ROOT:-/root/runs/issue41_mined_substrate_only}"
|
| 6 |
+
REPO_DIR="${REPO_DIR:-/root/work/circuit-shotting}"
|
| 7 |
+
STAMP="$(date -u +%Y%m%dT%H%M%SZ)"
|
| 8 |
+
UPLOAD_PREFIX="${UPLOAD_PREFIX:-issue41_mined_substrate_only_$STAMP}"
|
| 9 |
+
SYNTH_HF_REPO="${SYNTH_HF_REPO:-TokenBender/synth-data-en-pt-circuit}"
|
| 10 |
+
CIRCUIT_HF_REPO="${CIRCUIT_HF_REPO:-TokenBender/circuit-discovery}"
|
| 11 |
+
UPLOAD_DIR="$RUN_ROOT/package/$UPLOAD_PREFIX"
|
| 12 |
+
|
| 13 |
+
rm -rf "$UPLOAD_DIR"
|
| 14 |
+
mkdir -p "$UPLOAD_DIR"/{spec,scripts,eval,dumps,xcomet,summaries,logs,manifests}
|
| 15 |
+
|
| 16 |
+
copy_if_present() {
|
| 17 |
+
local src="$1"
|
| 18 |
+
local dst="$2"
|
| 19 |
+
if [[ -e "$src" ]]; then
|
| 20 |
+
mkdir -p "$(dirname "$dst")"
|
| 21 |
+
cp -a "$src" "$dst"
|
| 22 |
+
fi
|
| 23 |
+
}
|
| 24 |
+
|
| 25 |
+
copy_if_present "$REPO_DIR/configs/issue41_mined_substrate_only.json" "$UPLOAD_DIR/spec/issue41_mined_substrate_only.json"
|
| 26 |
+
|
| 27 |
+
for path in \
|
| 28 |
+
actdelta_mlp_common.py \
|
| 29 |
+
evaluate_mlp_nuke_translation.py \
|
| 30 |
+
evaluate_actdelta_lora_translation.py \
|
| 31 |
+
summarize_issue41_substrate_only.py \
|
| 32 |
+
issue41_substrate_only_runner.sh \
|
| 33 |
+
score_xcomet_sharded.py \
|
| 34 |
+
score_xcomet_service_client.py \
|
| 35 |
+
xcomet_service.py \
|
| 36 |
+
scripts/package_issue41_hf_upload.sh; do
|
| 37 |
+
copy_if_present "$REPO_DIR/$path" "$UPLOAD_DIR/scripts/$(basename "$path")"
|
| 38 |
+
done
|
| 39 |
+
|
| 40 |
+
cp -a "$RUN_ROOT/eval"/* "$UPLOAD_DIR/eval/" 2>/dev/null || true
|
| 41 |
+
cp -a "$RUN_ROOT/xcomet"/* "$UPLOAD_DIR/xcomet/" 2>/dev/null || true
|
| 42 |
+
cp -a "$RUN_ROOT/summaries"/* "$UPLOAD_DIR/summaries/" 2>/dev/null || true
|
| 43 |
+
cp -a "$RUN_ROOT/logs"/* "$UPLOAD_DIR/logs/" 2>/dev/null || true
|
| 44 |
+
|
| 45 |
+
find "$RUN_ROOT/dumps" -maxdepth 3 -type f -name '*.jsonl' -print0 2>/dev/null \
|
| 46 |
+
| while IFS= read -r -d '' file; do
|
| 47 |
+
rel="${file#$RUN_ROOT/dumps/}"
|
| 48 |
+
copy_if_present "$file" "$UPLOAD_DIR/dumps/$rel"
|
| 49 |
+
done
|
| 50 |
+
|
| 51 |
+
find "$UPLOAD_DIR" -type f -print0 | sort -z | xargs -0 sha256sum > "$UPLOAD_DIR/manifests/SHA256SUMS"
|
| 52 |
+
python3 - "$UPLOAD_DIR" "$RUN_ROOT" "$UPLOAD_PREFIX" <<'PY'
|
| 53 |
+
import json, sys
|
| 54 |
+
from pathlib import Path
|
| 55 |
+
upload = Path(sys.argv[1])
|
| 56 |
+
run_root = Path(sys.argv[2])
|
| 57 |
+
prefix = sys.argv[3]
|
| 58 |
+
files = [p for p in upload.rglob("*") if p.is_file()]
|
| 59 |
+
manifest = {
|
| 60 |
+
"upload_prefix": prefix,
|
| 61 |
+
"run_root": str(run_root),
|
| 62 |
+
"file_count": len(files),
|
| 63 |
+
"bytes": sum(p.stat().st_size for p in files),
|
| 64 |
+
"source_issue39_artifacts": "TokenBender/circuit-discovery:circuit-shotting/artifacts/actdelta_lora_mlp_mvc/issue39_actdelta_lora_mlp_mvc_20260518T011201Z",
|
| 65 |
+
"weights_policy": "Includes generated hypotheses, scores, summaries, scripts, and logs. Excludes upstream HY-MT/XCOMET model weights, HF caches, API keys, and service tokens.",
|
| 66 |
+
}
|
| 67 |
+
(upload / "manifests" / "manifest.json").write_text(json.dumps(manifest, indent=2) + "\n")
|
| 68 |
+
(upload / "README.md").write_text(
|
| 69 |
+
"# Issue 41 Mined MLP Substrate-Only Artifacts\n\n"
|
| 70 |
+
"This package contains native and ActDelta repaired substrate-only EN->PT eval outputs "
|
| 71 |
+
"for the issue 39 mined MLP final mix.\n\n"
|
| 72 |
+
"Upstream HY-MT and XCOMET model weights are not included.\n"
|
| 73 |
+
)
|
| 74 |
+
PY
|
| 75 |
+
|
| 76 |
+
hf upload "$SYNTH_HF_REPO" "$UPLOAD_DIR" "$UPLOAD_PREFIX" --repo-type dataset
|
| 77 |
+
hf upload "$CIRCUIT_HF_REPO" "$UPLOAD_DIR" "circuit-shotting/artifacts/mined_substrate_only/$UPLOAD_PREFIX" --repo-type dataset
|
| 78 |
+
|
| 79 |
+
echo "$UPLOAD_PREFIX"
|
circuit-shotting/artifacts/mined_substrate_only/issue41_mined_substrate_only_20260518T103722Z/scripts/score_xcomet_service_client.py
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
"""Score a hypothesis JSONL through the XCOMET HTTP service."""
|
| 3 |
+
|
| 4 |
+
from __future__ import annotations
|
| 5 |
+
|
| 6 |
+
import argparse
|
| 7 |
+
import json
|
| 8 |
+
import os
|
| 9 |
+
import urllib.error
|
| 10 |
+
import urllib.request
|
| 11 |
+
from pathlib import Path
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
def parse_args() -> argparse.Namespace:
|
| 15 |
+
p = argparse.ArgumentParser(description=__doc__)
|
| 16 |
+
p.add_argument("--base-url", default=os.environ.get("XCOMET_SERVICE_BASE_URL", "http://127.0.0.1:20000"))
|
| 17 |
+
p.add_argument("--token", default=os.environ.get("XCOMET_SERVICE_TOKEN"))
|
| 18 |
+
p.add_argument("--token-file", default=os.environ.get("XCOMET_SERVICE_TOKEN_FILE"))
|
| 19 |
+
p.add_argument("--hyps-jsonl", required=True)
|
| 20 |
+
p.add_argument("--out-json", required=True)
|
| 21 |
+
p.add_argument("--out-dir", default=None)
|
| 22 |
+
p.add_argument("--request-id", default=None)
|
| 23 |
+
p.add_argument("--system-name", default=None)
|
| 24 |
+
p.add_argument("--batch-size", type=int, default=8)
|
| 25 |
+
p.add_argument("--chunk-size", type=int, default=128)
|
| 26 |
+
p.add_argument("--timeout-s", type=float, default=3600)
|
| 27 |
+
p.add_argument("--return-rows", action=argparse.BooleanOptionalAction, default=False)
|
| 28 |
+
return p.parse_args()
|
| 29 |
+
|
| 30 |
+
|
| 31 |
+
def resolve_token(args: argparse.Namespace) -> str:
|
| 32 |
+
if args.token:
|
| 33 |
+
return args.token
|
| 34 |
+
if args.token_file:
|
| 35 |
+
return Path(args.token_file).read_text().strip()
|
| 36 |
+
raise SystemExit("set --token, --token-file, XCOMET_SERVICE_TOKEN, or XCOMET_SERVICE_TOKEN_FILE")
|
| 37 |
+
|
| 38 |
+
|
| 39 |
+
def request_json(method: str, url: str, token: str, payload: dict | None,
|
| 40 |
+
timeout: float) -> dict:
|
| 41 |
+
body = None if payload is None else json.dumps(payload).encode("utf-8")
|
| 42 |
+
req = urllib.request.Request(url, data=body, method=method)
|
| 43 |
+
req.add_header("Authorization", f"Bearer {token}")
|
| 44 |
+
if body is not None:
|
| 45 |
+
req.add_header("Content-Type", "application/json")
|
| 46 |
+
try:
|
| 47 |
+
with urllib.request.urlopen(req, timeout=timeout) as resp:
|
| 48 |
+
return json.loads(resp.read())
|
| 49 |
+
except urllib.error.HTTPError as exc:
|
| 50 |
+
text = exc.read().decode("utf-8", errors="replace")
|
| 51 |
+
raise SystemExit(f"{url} failed {exc.code}: {text}") from exc
|
| 52 |
+
|
| 53 |
+
|
| 54 |
+
def main() -> None:
|
| 55 |
+
args = parse_args()
|
| 56 |
+
token = resolve_token(args)
|
| 57 |
+
base = args.base_url.rstrip("/")
|
| 58 |
+
health = request_json("GET", f"{base}/health", token, None, timeout=30)
|
| 59 |
+
payload = {
|
| 60 |
+
"hyps_jsonl": args.hyps_jsonl,
|
| 61 |
+
"out_dir": args.out_dir,
|
| 62 |
+
"request_id": args.request_id,
|
| 63 |
+
"system_name": args.system_name or Path(args.hyps_jsonl).stem,
|
| 64 |
+
"batch_size": args.batch_size,
|
| 65 |
+
"chunk_size": args.chunk_size,
|
| 66 |
+
"timeout_s": args.timeout_s,
|
| 67 |
+
"return_rows": args.return_rows,
|
| 68 |
+
}
|
| 69 |
+
payload = {k: v for k, v in payload.items() if v is not None}
|
| 70 |
+
result = request_json("POST", f"{base}/score-dataset", token, payload, timeout=args.timeout_s + 60)
|
| 71 |
+
out_path = Path(args.out_json)
|
| 72 |
+
out_path.parent.mkdir(parents=True, exist_ok=True)
|
| 73 |
+
with out_path.open("w") as f:
|
| 74 |
+
json.dump({
|
| 75 |
+
"health": {
|
| 76 |
+
"model_loaded": health.get("model_loaded"),
|
| 77 |
+
"comet_model": health.get("comet_model"),
|
| 78 |
+
"cuda": health.get("cuda"),
|
| 79 |
+
},
|
| 80 |
+
**result,
|
| 81 |
+
}, f, indent=2, ensure_ascii=False)
|
| 82 |
+
print(json.dumps({
|
| 83 |
+
"out_json": str(out_path),
|
| 84 |
+
"model_loaded": health.get("model_loaded"),
|
| 85 |
+
"summary": result.get("summary"),
|
| 86 |
+
"outputs": result.get("outputs"),
|
| 87 |
+
}, indent=2, ensure_ascii=False), flush=True)
|
| 88 |
+
|
| 89 |
+
|
| 90 |
+
if __name__ == "__main__":
|
| 91 |
+
main()
|
circuit-shotting/artifacts/mined_substrate_only/issue41_mined_substrate_only_20260518T103722Z/scripts/score_xcomet_sharded.py
ADDED
|
@@ -0,0 +1,194 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
"""Score one hypothesis file by sharding it across all XCOMET services."""
|
| 3 |
+
|
| 4 |
+
from __future__ import annotations
|
| 5 |
+
|
| 6 |
+
import argparse
|
| 7 |
+
from concurrent.futures import ThreadPoolExecutor, as_completed
|
| 8 |
+
import json
|
| 9 |
+
import statistics
|
| 10 |
+
import time
|
| 11 |
+
import urllib.error
|
| 12 |
+
import urllib.request
|
| 13 |
+
from pathlib import Path
|
| 14 |
+
from typing import Any
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
def parse_args() -> argparse.Namespace:
|
| 18 |
+
p = argparse.ArgumentParser(description=__doc__)
|
| 19 |
+
p.add_argument("--hyps-jsonl", required=True)
|
| 20 |
+
p.add_argument("--out-json", required=True)
|
| 21 |
+
p.add_argument("--out-jsonl", required=True)
|
| 22 |
+
p.add_argument("--shard-dir", required=True)
|
| 23 |
+
p.add_argument("--service", action="append", required=True,
|
| 24 |
+
help="Service spec idx,base_url,token_file. Repeat once per GPU.")
|
| 25 |
+
p.add_argument("--request-id", default=None)
|
| 26 |
+
p.add_argument("--system-name", default=None)
|
| 27 |
+
p.add_argument("--batch-size", type=int, default=1)
|
| 28 |
+
p.add_argument("--chunk-size", type=int, default=16)
|
| 29 |
+
p.add_argument("--timeout-s", type=float, default=7200)
|
| 30 |
+
p.add_argument("--threshold", type=float, default=0.99)
|
| 31 |
+
return p.parse_args()
|
| 32 |
+
|
| 33 |
+
|
| 34 |
+
def load_jsonl(path: Path) -> list[dict[str, Any]]:
|
| 35 |
+
rows = []
|
| 36 |
+
with path.open() as f:
|
| 37 |
+
for idx, line in enumerate(f):
|
| 38 |
+
if not line.strip():
|
| 39 |
+
continue
|
| 40 |
+
row = json.loads(line)
|
| 41 |
+
row.setdefault("id", idx)
|
| 42 |
+
rows.append(row)
|
| 43 |
+
return rows
|
| 44 |
+
|
| 45 |
+
|
| 46 |
+
def write_jsonl(path: Path, rows: list[dict[str, Any]]) -> None:
|
| 47 |
+
path.parent.mkdir(parents=True, exist_ok=True)
|
| 48 |
+
with path.open("w") as f:
|
| 49 |
+
for row in rows:
|
| 50 |
+
f.write(json.dumps(row, ensure_ascii=False) + "\n")
|
| 51 |
+
|
| 52 |
+
|
| 53 |
+
def parse_service(spec: str) -> dict[str, Any]:
|
| 54 |
+
parts = spec.split(",", 2)
|
| 55 |
+
if len(parts) != 3:
|
| 56 |
+
raise ValueError(f"bad --service {spec!r}; expected idx,base_url,token_file")
|
| 57 |
+
idx, base_url, token_file = parts
|
| 58 |
+
return {
|
| 59 |
+
"idx": int(idx),
|
| 60 |
+
"base_url": base_url.rstrip("/"),
|
| 61 |
+
"token_file": token_file,
|
| 62 |
+
"token": Path(token_file).read_text().strip(),
|
| 63 |
+
}
|
| 64 |
+
|
| 65 |
+
|
| 66 |
+
def request_json(method: str, url: str, token: str, payload: dict[str, Any] | None,
|
| 67 |
+
timeout: float) -> dict[str, Any]:
|
| 68 |
+
body = None if payload is None else json.dumps(payload).encode("utf-8")
|
| 69 |
+
req = urllib.request.Request(url, data=body, method=method)
|
| 70 |
+
req.add_header("Authorization", f"Bearer {token}")
|
| 71 |
+
if body is not None:
|
| 72 |
+
req.add_header("Content-Type", "application/json")
|
| 73 |
+
try:
|
| 74 |
+
with urllib.request.urlopen(req, timeout=timeout) as resp:
|
| 75 |
+
return json.loads(resp.read())
|
| 76 |
+
except urllib.error.HTTPError as exc:
|
| 77 |
+
text = exc.read().decode("utf-8", errors="replace")
|
| 78 |
+
raise RuntimeError(f"{url} failed {exc.code}: {text}") from exc
|
| 79 |
+
|
| 80 |
+
|
| 81 |
+
def score_shard(service: dict[str, Any], shard_path: Path, *, request_id: str,
|
| 82 |
+
system_name: str, batch_size: int, chunk_size: int,
|
| 83 |
+
timeout_s: float) -> dict[str, Any]:
|
| 84 |
+
base = service["base_url"]
|
| 85 |
+
token = service["token"]
|
| 86 |
+
health = request_json("GET", f"{base}/health", token, None, timeout=30)
|
| 87 |
+
payload = {
|
| 88 |
+
"hyps_jsonl": str(shard_path),
|
| 89 |
+
"request_id": request_id,
|
| 90 |
+
"system_name": system_name,
|
| 91 |
+
"batch_size": batch_size,
|
| 92 |
+
"chunk_size": chunk_size,
|
| 93 |
+
"timeout_s": timeout_s,
|
| 94 |
+
"return_rows": False,
|
| 95 |
+
}
|
| 96 |
+
result = request_json("POST", f"{base}/score-dataset", token, payload, timeout=timeout_s + 60)
|
| 97 |
+
return {
|
| 98 |
+
"service": {
|
| 99 |
+
"idx": service["idx"],
|
| 100 |
+
"base_url": base,
|
| 101 |
+
"health": {
|
| 102 |
+
"model_loaded": health.get("model_loaded"),
|
| 103 |
+
"comet_model": health.get("comet_model"),
|
| 104 |
+
"cuda": health.get("cuda"),
|
| 105 |
+
},
|
| 106 |
+
},
|
| 107 |
+
"shard_path": str(shard_path),
|
| 108 |
+
**result,
|
| 109 |
+
}
|
| 110 |
+
|
| 111 |
+
|
| 112 |
+
def main() -> None:
|
| 113 |
+
args = parse_args()
|
| 114 |
+
services = [parse_service(spec) for spec in args.service]
|
| 115 |
+
if not services:
|
| 116 |
+
raise ValueError("at least one --service is required")
|
| 117 |
+
rows = load_jsonl(Path(args.hyps_jsonl))
|
| 118 |
+
if not rows:
|
| 119 |
+
raise ValueError(f"no rows in {args.hyps_jsonl}")
|
| 120 |
+
|
| 121 |
+
shard_dir = Path(args.shard_dir)
|
| 122 |
+
shard_dir.mkdir(parents=True, exist_ok=True)
|
| 123 |
+
request_root = args.request_id or Path(args.hyps_jsonl).stem
|
| 124 |
+
system_name = args.system_name or Path(args.hyps_jsonl).stem
|
| 125 |
+
|
| 126 |
+
shard_paths: list[Path] = []
|
| 127 |
+
for shard_idx, service in enumerate(services):
|
| 128 |
+
shard_rows = rows[shard_idx::len(services)]
|
| 129 |
+
shard_path = shard_dir / f"shard_{shard_idx:03d}.jsonl"
|
| 130 |
+
write_jsonl(shard_path, shard_rows)
|
| 131 |
+
shard_paths.append(shard_path)
|
| 132 |
+
|
| 133 |
+
t0 = time.time()
|
| 134 |
+
shard_results: list[dict[str, Any]] = []
|
| 135 |
+
with ThreadPoolExecutor(max_workers=len(services)) as executor:
|
| 136 |
+
futures = []
|
| 137 |
+
for shard_idx, (service, shard_path) in enumerate(zip(services, shard_paths)):
|
| 138 |
+
futures.append(executor.submit(
|
| 139 |
+
score_shard,
|
| 140 |
+
service,
|
| 141 |
+
shard_path,
|
| 142 |
+
request_id=f"{request_root}_shard{shard_idx:03d}",
|
| 143 |
+
system_name=f"{system_name}_shard{shard_idx:03d}",
|
| 144 |
+
batch_size=args.batch_size,
|
| 145 |
+
chunk_size=args.chunk_size,
|
| 146 |
+
timeout_s=args.timeout_s,
|
| 147 |
+
))
|
| 148 |
+
for future in as_completed(futures):
|
| 149 |
+
shard_results.append(future.result())
|
| 150 |
+
|
| 151 |
+
scored_rows: list[dict[str, Any]] = []
|
| 152 |
+
for result in shard_results:
|
| 153 |
+
out_jsonl = result.get("outputs", {}).get("out_jsonl")
|
| 154 |
+
if not out_jsonl:
|
| 155 |
+
raise ValueError(f"shard result missing outputs.out_jsonl: {result}")
|
| 156 |
+
for row in load_jsonl(Path(out_jsonl)):
|
| 157 |
+
row["system"] = system_name
|
| 158 |
+
scored_rows.append(row)
|
| 159 |
+
scored_rows.sort(key=lambda row: int(row.get("row_id", row.get("id", 0))))
|
| 160 |
+
|
| 161 |
+
scores = [float(row["score"]) for row in scored_rows]
|
| 162 |
+
out_jsonl = Path(args.out_jsonl)
|
| 163 |
+
write_jsonl(out_jsonl, scored_rows)
|
| 164 |
+
summary = {
|
| 165 |
+
"source_path": args.hyps_jsonl,
|
| 166 |
+
"comet_model": shard_results[0].get("summary", {}).get("comet_model"),
|
| 167 |
+
"checkpoint_path": shard_results[0].get("summary", {}).get("checkpoint_path"),
|
| 168 |
+
"n": len(scored_rows),
|
| 169 |
+
"threshold": args.threshold,
|
| 170 |
+
"system_score": statistics.fmean(scores),
|
| 171 |
+
"passed": sum(1 for score in scores if score >= args.threshold),
|
| 172 |
+
"elapsed_seconds": time.time() - t0,
|
| 173 |
+
"batch_size": args.batch_size,
|
| 174 |
+
"chunk_size": args.chunk_size,
|
| 175 |
+
"shard_count": len(services),
|
| 176 |
+
"throughput_seg_per_s": len(scored_rows) / max(time.time() - t0, 1e-9),
|
| 177 |
+
}
|
| 178 |
+
payload = {
|
| 179 |
+
"health": [result["service"] for result in sorted(shard_results, key=lambda row: row["service"]["idx"])],
|
| 180 |
+
"summary": summary,
|
| 181 |
+
"outputs": {
|
| 182 |
+
"out_jsonl": str(out_jsonl),
|
| 183 |
+
"shard_dir": str(shard_dir),
|
| 184 |
+
},
|
| 185 |
+
"shards": sorted(shard_results, key=lambda row: row["service"]["idx"]),
|
| 186 |
+
}
|
| 187 |
+
out_json = Path(args.out_json)
|
| 188 |
+
out_json.parent.mkdir(parents=True, exist_ok=True)
|
| 189 |
+
out_json.write_text(json.dumps(payload, indent=2, ensure_ascii=False) + "\n")
|
| 190 |
+
print(json.dumps({"out_json": str(out_json), "summary": summary}, indent=2), flush=True)
|
| 191 |
+
|
| 192 |
+
|
| 193 |
+
if __name__ == "__main__":
|
| 194 |
+
main()
|
circuit-shotting/artifacts/mined_substrate_only/issue41_mined_substrate_only_20260518T103722Z/scripts/summarize_issue41_substrate_only.py
ADDED
|
@@ -0,0 +1,100 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
"""Summarize issue #41 substrate-only sufficiency evals."""
|
| 3 |
+
|
| 4 |
+
from __future__ import annotations
|
| 5 |
+
|
| 6 |
+
import argparse
|
| 7 |
+
import json
|
| 8 |
+
from pathlib import Path
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
def parse_args() -> argparse.Namespace:
|
| 12 |
+
p = argparse.ArgumentParser(description=__doc__)
|
| 13 |
+
p.add_argument("--run-root", required=True)
|
| 14 |
+
p.add_argument("--baseline-xcomet", type=float, default=0.9287162019683438)
|
| 15 |
+
p.add_argument("--out-json", required=True)
|
| 16 |
+
p.add_argument("--out-md", required=True)
|
| 17 |
+
return p.parse_args()
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
def maybe_json(path: Path):
|
| 21 |
+
if path.exists():
|
| 22 |
+
return json.load(open(path))
|
| 23 |
+
return None
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
def xcomet_score(path: Path):
|
| 27 |
+
payload = maybe_json(path)
|
| 28 |
+
if not payload:
|
| 29 |
+
return None
|
| 30 |
+
return payload.get("summary", {}).get("system_score")
|
| 31 |
+
|
| 32 |
+
|
| 33 |
+
def main() -> None:
|
| 34 |
+
args = parse_args()
|
| 35 |
+
root = Path(args.run_root)
|
| 36 |
+
rows = []
|
| 37 |
+
|
| 38 |
+
native_eval = maybe_json(root / "eval" / "native_substrate_only.json")
|
| 39 |
+
native_result = (native_eval or {}).get("results", {}).get("native_mined_substrate_only")
|
| 40 |
+
native_xcomet = xcomet_score(root / "xcomet" / "native_mined_substrate_only.json")
|
| 41 |
+
if native_result:
|
| 42 |
+
rows.append({
|
| 43 |
+
"system": "native_mined_substrate_only",
|
| 44 |
+
"rank": None,
|
| 45 |
+
"channels": native_result.get("channels"),
|
| 46 |
+
"params": None,
|
| 47 |
+
"scores": native_result.get("scores", {}),
|
| 48 |
+
"xcomet": native_xcomet,
|
| 49 |
+
"recovery": native_xcomet / args.baseline_xcomet if native_xcomet is not None else None,
|
| 50 |
+
"method": "native selected MLP channels only; all other MLP channels zeroed",
|
| 51 |
+
})
|
| 52 |
+
|
| 53 |
+
actdelta_eval = maybe_json(root / "eval" / "actdelta_rank256_substrate_only.json")
|
| 54 |
+
actdelta_xcomet = xcomet_score(root / "xcomet" / "actdelta_rank256_substrate_only.json")
|
| 55 |
+
if actdelta_eval:
|
| 56 |
+
rows.append({
|
| 57 |
+
"system": "actdelta_rank256_substrate_only",
|
| 58 |
+
"rank": actdelta_eval.get("rank"),
|
| 59 |
+
"channels": actdelta_eval.get("channels"),
|
| 60 |
+
"params": actdelta_eval.get("parameter_count"),
|
| 61 |
+
"scores": actdelta_eval.get("scores", {}),
|
| 62 |
+
"xcomet": actdelta_xcomet,
|
| 63 |
+
"recovery": actdelta_xcomet / args.baseline_xcomet if actdelta_xcomet is not None else None,
|
| 64 |
+
"method": "rank-256 ActDelta reconstruction of selected channels only; all other MLP channels zeroed",
|
| 65 |
+
})
|
| 66 |
+
|
| 67 |
+
summary = {
|
| 68 |
+
"run_root": str(root),
|
| 69 |
+
"baseline_xcomet": args.baseline_xcomet,
|
| 70 |
+
"systems": rows,
|
| 71 |
+
}
|
| 72 |
+
out_json = Path(args.out_json)
|
| 73 |
+
out_md = Path(args.out_md)
|
| 74 |
+
out_json.parent.mkdir(parents=True, exist_ok=True)
|
| 75 |
+
out_md.parent.mkdir(parents=True, exist_ok=True)
|
| 76 |
+
out_json.write_text(json.dumps(summary, indent=2, ensure_ascii=False) + "\n")
|
| 77 |
+
|
| 78 |
+
lines = [
|
| 79 |
+
"# Issue 41 Mined MLP Substrate-Only Summary",
|
| 80 |
+
"",
|
| 81 |
+
f"- Baseline XCOMET: `{args.baseline_xcomet}`",
|
| 82 |
+
"",
|
| 83 |
+
"| system | rank | channels | params | chrF++ | BLEU | XCOMET | recovery |",
|
| 84 |
+
"|---|---:|---:|---:|---:|---:|---:|---:|",
|
| 85 |
+
]
|
| 86 |
+
for row in rows:
|
| 87 |
+
scores = row.get("scores") or {}
|
| 88 |
+
rank = "-" if row.get("rank") is None else row["rank"]
|
| 89 |
+
params = "-" if row.get("params") is None else row["params"]
|
| 90 |
+
lines.append(
|
| 91 |
+
f"| `{row['system']}` | `{rank}` | `{row.get('channels')}` | `{params}` | "
|
| 92 |
+
f"`{scores.get('chrFpp')}` | `{scores.get('BLEU')}` | "
|
| 93 |
+
f"`{row.get('xcomet')}` | `{row.get('recovery')}` |"
|
| 94 |
+
)
|
| 95 |
+
out_md.write_text("\n".join(lines) + "\n")
|
| 96 |
+
print(json.dumps({"out_json": str(out_json), "out_md": str(out_md)}, indent=2), flush=True)
|
| 97 |
+
|
| 98 |
+
|
| 99 |
+
if __name__ == "__main__":
|
| 100 |
+
main()
|
circuit-shotting/artifacts/mined_substrate_only/issue41_mined_substrate_only_20260518T103722Z/scripts/xcomet_service.py
ADDED
|
@@ -0,0 +1,560 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
"""Long-running HTTP service for XCOMET/COMET scoring and dataset export."""
|
| 3 |
+
|
| 4 |
+
from __future__ import annotations
|
| 5 |
+
|
| 6 |
+
import argparse
|
| 7 |
+
from dataclasses import dataclass
|
| 8 |
+
import json
|
| 9 |
+
import os
|
| 10 |
+
import queue
|
| 11 |
+
import statistics
|
| 12 |
+
import threading
|
| 13 |
+
import time
|
| 14 |
+
import uuid
|
| 15 |
+
from http import HTTPStatus
|
| 16 |
+
from http.server import BaseHTTPRequestHandler, ThreadingHTTPServer
|
| 17 |
+
from pathlib import Path
|
| 18 |
+
from types import SimpleNamespace
|
| 19 |
+
from typing import Any
|
| 20 |
+
|
| 21 |
+
import torch
|
| 22 |
+
|
| 23 |
+
from build_xcomet_ft_dataset import (
|
| 24 |
+
build_preferences,
|
| 25 |
+
build_repairs,
|
| 26 |
+
build_sft,
|
| 27 |
+
load_jsonl,
|
| 28 |
+
normalize_pool,
|
| 29 |
+
score_distribution,
|
| 30 |
+
write_jsonl,
|
| 31 |
+
)
|
| 32 |
+
from score_xcomet_pool import prediction_extras, resolve_checkpoint
|
| 33 |
+
|
| 34 |
+
|
| 35 |
+
def parse_args() -> argparse.Namespace:
|
| 36 |
+
p = argparse.ArgumentParser(description=__doc__)
|
| 37 |
+
p.add_argument("--host", default="0.0.0.0")
|
| 38 |
+
p.add_argument("--port", type=int, default=20000)
|
| 39 |
+
p.add_argument("--comet-model", default=os.environ.get("COMET_MODEL", "Unbabel/XCOMET-XXL"))
|
| 40 |
+
p.add_argument("--checkpoint-path", default=os.environ.get("XCOMET_CKPT_PATH"))
|
| 41 |
+
p.add_argument("--run-root", default=os.environ.get("RUN_ROOT", "/root/runs/xcomet_service"))
|
| 42 |
+
p.add_argument("--default-batch-size", type=int, default=int(os.environ.get("XCOMET_BATCH", "4")))
|
| 43 |
+
p.add_argument("--default-chunk-size", type=int, default=int(os.environ.get("XCOMET_CHUNK", "32")))
|
| 44 |
+
p.add_argument("--max-worker-batch-size", type=int, default=int(os.environ.get("XCOMET_MAX_WORKER_BATCH", os.environ.get("XCOMET_BATCH", "4"))))
|
| 45 |
+
p.add_argument("--max-batch-rows", type=int, default=int(os.environ.get("XCOMET_MAX_BATCH_ROWS", os.environ.get("XCOMET_CHUNK", "32"))))
|
| 46 |
+
p.add_argument("--max-batch-wait-ms", type=int, default=int(os.environ.get("XCOMET_MAX_BATCH_WAIT_MS", "100")))
|
| 47 |
+
p.add_argument("--max-queue-rows", type=int, default=int(os.environ.get("XCOMET_MAX_QUEUE_ROWS", "4096")))
|
| 48 |
+
p.add_argument("--queue-timeout-s", type=float, default=float(os.environ.get("XCOMET_QUEUE_TIMEOUT_S", "1800")))
|
| 49 |
+
p.add_argument("--float32-matmul-precision", choices=["highest", "high", "medium"], default=os.environ.get("XCOMET_FLOAT32_MATMUL_PRECISION", "high"))
|
| 50 |
+
p.add_argument("--threshold", type=float, default=float(os.environ.get("XCOMET_THRESHOLD", "0.99")))
|
| 51 |
+
p.add_argument("--auth-token", default=os.environ.get("XCOMET_SERVICE_TOKEN"))
|
| 52 |
+
p.add_argument("--load-on-start", action="store_true")
|
| 53 |
+
return p.parse_args()
|
| 54 |
+
|
| 55 |
+
|
| 56 |
+
@dataclass(frozen=True)
|
| 57 |
+
class ScoreResult:
|
| 58 |
+
score: float
|
| 59 |
+
extra: dict[str, Any]
|
| 60 |
+
|
| 61 |
+
|
| 62 |
+
@dataclass(frozen=True)
|
| 63 |
+
class ScoreUnit:
|
| 64 |
+
job: "ScoreJob"
|
| 65 |
+
index: int
|
| 66 |
+
data: dict[str, Any]
|
| 67 |
+
batch_size: int
|
| 68 |
+
enqueued_at: float
|
| 69 |
+
|
| 70 |
+
|
| 71 |
+
class ScoreJob:
|
| 72 |
+
def __init__(self, size: int):
|
| 73 |
+
self.results: list[ScoreResult | None] = [None] * size
|
| 74 |
+
self.remaining = size
|
| 75 |
+
self.error: BaseException | None = None
|
| 76 |
+
self.event = threading.Event()
|
| 77 |
+
self.lock = threading.Lock()
|
| 78 |
+
|
| 79 |
+
def record(self, index: int, result: ScoreResult) -> None:
|
| 80 |
+
with self.lock:
|
| 81 |
+
if self.error is not None:
|
| 82 |
+
return
|
| 83 |
+
self.results[index] = result
|
| 84 |
+
self.remaining -= 1
|
| 85 |
+
if self.remaining == 0:
|
| 86 |
+
self.event.set()
|
| 87 |
+
|
| 88 |
+
def fail(self, exc: BaseException) -> None:
|
| 89 |
+
with self.lock:
|
| 90 |
+
if self.error is None:
|
| 91 |
+
self.error = exc
|
| 92 |
+
self.event.set()
|
| 93 |
+
|
| 94 |
+
|
| 95 |
+
class ScoringBatcher:
|
| 96 |
+
"""Single GPU worker with dynamic row batching across HTTP callers."""
|
| 97 |
+
|
| 98 |
+
def __init__(self, state: "ServiceState"):
|
| 99 |
+
self.state = state
|
| 100 |
+
self.work: queue.Queue[ScoreUnit] = queue.Queue(maxsize=state.args.max_queue_rows)
|
| 101 |
+
self.max_rows = max(1, state.args.max_batch_rows)
|
| 102 |
+
self.max_worker_batch_size = max(1, state.args.max_worker_batch_size)
|
| 103 |
+
self.max_wait_seconds = max(0.0, state.args.max_batch_wait_ms / 1000.0)
|
| 104 |
+
self.stats_lock = threading.Lock()
|
| 105 |
+
self.active_batch_rows = 0
|
| 106 |
+
self.completed_batches = 0
|
| 107 |
+
self.completed_rows = 0
|
| 108 |
+
self.failed_batches = 0
|
| 109 |
+
self.last_batch_rows = 0
|
| 110 |
+
self.last_batch_seconds: float | None = None
|
| 111 |
+
self.last_batch_started_at: float | None = None
|
| 112 |
+
self.last_error: str | None = None
|
| 113 |
+
self.worker = threading.Thread(target=self._worker_loop, name="xcomet-gpu-worker", daemon=True)
|
| 114 |
+
self.worker.start()
|
| 115 |
+
|
| 116 |
+
def status(self) -> dict[str, Any]:
|
| 117 |
+
with self.stats_lock:
|
| 118 |
+
return {
|
| 119 |
+
"pending_rows": self.work.qsize(),
|
| 120 |
+
"active_batch_rows": self.active_batch_rows,
|
| 121 |
+
"completed_batches": self.completed_batches,
|
| 122 |
+
"completed_rows": self.completed_rows,
|
| 123 |
+
"failed_batches": self.failed_batches,
|
| 124 |
+
"last_batch_rows": self.last_batch_rows,
|
| 125 |
+
"last_batch_seconds": self.last_batch_seconds,
|
| 126 |
+
"last_batch_started_at": self.last_batch_started_at,
|
| 127 |
+
"last_error": self.last_error,
|
| 128 |
+
"max_batch_rows": self.max_rows,
|
| 129 |
+
"max_worker_batch_size": self.max_worker_batch_size,
|
| 130 |
+
"max_batch_wait_ms": int(self.max_wait_seconds * 1000),
|
| 131 |
+
"max_queue_rows": self.work.maxsize,
|
| 132 |
+
}
|
| 133 |
+
|
| 134 |
+
def score(self, data: list[dict[str, Any]], batch_size: int, timeout_s: float | None) -> list[ScoreResult]:
|
| 135 |
+
job = ScoreJob(len(data))
|
| 136 |
+
deadline = None if timeout_s is None else time.time() + timeout_s
|
| 137 |
+
for index, item in enumerate(data):
|
| 138 |
+
remaining = None if deadline is None else max(0.0, deadline - time.time())
|
| 139 |
+
try:
|
| 140 |
+
self.work.put(
|
| 141 |
+
ScoreUnit(job=job, index=index, data=item, batch_size=batch_size, enqueued_at=time.time()),
|
| 142 |
+
timeout=remaining,
|
| 143 |
+
)
|
| 144 |
+
except queue.Full as exc:
|
| 145 |
+
job.fail(TimeoutError("timed out while queueing rows for scoring"))
|
| 146 |
+
raise TimeoutError("timed out while queueing rows for scoring") from exc
|
| 147 |
+
|
| 148 |
+
wait_timeout = None if deadline is None else max(0.0, deadline - time.time())
|
| 149 |
+
if not job.event.wait(wait_timeout):
|
| 150 |
+
job.fail(TimeoutError("timed out while waiting for scoring"))
|
| 151 |
+
raise TimeoutError("timed out while waiting for scoring")
|
| 152 |
+
if job.error is not None:
|
| 153 |
+
raise job.error
|
| 154 |
+
results = [result for result in job.results if result is not None]
|
| 155 |
+
if len(results) != len(data):
|
| 156 |
+
raise RuntimeError("scoring worker returned an incomplete result set")
|
| 157 |
+
return results
|
| 158 |
+
|
| 159 |
+
def _worker_loop(self) -> None:
|
| 160 |
+
while True:
|
| 161 |
+
first = self.work.get()
|
| 162 |
+
units = [first]
|
| 163 |
+
deadline = time.time() + self.max_wait_seconds
|
| 164 |
+
while len(units) < self.max_rows:
|
| 165 |
+
timeout = max(0.0, deadline - time.time())
|
| 166 |
+
if timeout == 0.0:
|
| 167 |
+
break
|
| 168 |
+
try:
|
| 169 |
+
units.append(self.work.get(timeout=timeout))
|
| 170 |
+
except queue.Empty:
|
| 171 |
+
break
|
| 172 |
+
self._predict_units(units)
|
| 173 |
+
for _ in units:
|
| 174 |
+
self.work.task_done()
|
| 175 |
+
|
| 176 |
+
def _predict_units(self, units: list[ScoreUnit]) -> None:
|
| 177 |
+
started = time.time()
|
| 178 |
+
with self.stats_lock:
|
| 179 |
+
self.active_batch_rows = len(units)
|
| 180 |
+
self.last_batch_started_at = started
|
| 181 |
+
try:
|
| 182 |
+
self.state.load_model()
|
| 183 |
+
batch_size = min(max(unit.batch_size for unit in units), self.max_worker_batch_size)
|
| 184 |
+
preds = self.state.model.predict(
|
| 185 |
+
[unit.data for unit in units],
|
| 186 |
+
batch_size=batch_size,
|
| 187 |
+
gpus=1,
|
| 188 |
+
progress_bar=False,
|
| 189 |
+
)
|
| 190 |
+
scores = [float(s) for s in preds["scores"]]
|
| 191 |
+
extras = prediction_extras(preds, 0, len(units))
|
| 192 |
+
for unit, score, extra in zip(units, scores, extras, strict=True):
|
| 193 |
+
unit.job.record(unit.index, ScoreResult(score=score, extra=extra or {}))
|
| 194 |
+
elapsed = time.time() - started
|
| 195 |
+
with self.stats_lock:
|
| 196 |
+
self.completed_batches += 1
|
| 197 |
+
self.completed_rows += len(units)
|
| 198 |
+
self.last_batch_rows = len(units)
|
| 199 |
+
self.last_batch_seconds = elapsed
|
| 200 |
+
self.last_error = None
|
| 201 |
+
except Exception as exc: # noqa: BLE001 - return scoring failures to callers
|
| 202 |
+
with self.stats_lock:
|
| 203 |
+
self.failed_batches += 1
|
| 204 |
+
self.last_error = f"{type(exc).__name__}: {exc}"
|
| 205 |
+
for unit in units:
|
| 206 |
+
unit.job.fail(exc)
|
| 207 |
+
finally:
|
| 208 |
+
with self.stats_lock:
|
| 209 |
+
self.active_batch_rows = 0
|
| 210 |
+
if torch.cuda.is_available():
|
| 211 |
+
torch.cuda.empty_cache()
|
| 212 |
+
|
| 213 |
+
|
| 214 |
+
class ServiceState:
|
| 215 |
+
def __init__(self, args: argparse.Namespace):
|
| 216 |
+
self.args = args
|
| 217 |
+
self.run_root = Path(args.run_root)
|
| 218 |
+
self.run_root.mkdir(parents=True, exist_ok=True)
|
| 219 |
+
self.model = None
|
| 220 |
+
self.checkpoint_path: str | None = None
|
| 221 |
+
self.loaded_at: float | None = None
|
| 222 |
+
self.load_error: str | None = None
|
| 223 |
+
self.load_lock = threading.Lock()
|
| 224 |
+
self.scoring_batcher = ScoringBatcher(self)
|
| 225 |
+
|
| 226 |
+
def load_model(self) -> dict[str, Any]:
|
| 227 |
+
with self.load_lock:
|
| 228 |
+
if self.model is not None:
|
| 229 |
+
return self.status()
|
| 230 |
+
try:
|
| 231 |
+
from comet import load_from_checkpoint
|
| 232 |
+
|
| 233 |
+
ckpt = resolve_checkpoint(self.args.comet_model, self.args.checkpoint_path)
|
| 234 |
+
model = load_from_checkpoint(ckpt)
|
| 235 |
+
self.model = model
|
| 236 |
+
self.checkpoint_path = ckpt
|
| 237 |
+
self.loaded_at = time.time()
|
| 238 |
+
self.load_error = None
|
| 239 |
+
except Exception as exc: # noqa: BLE001 - report service-load failures
|
| 240 |
+
self.load_error = f"{type(exc).__name__}: {exc}"
|
| 241 |
+
raise
|
| 242 |
+
return self.status()
|
| 243 |
+
|
| 244 |
+
def status(self) -> dict[str, Any]:
|
| 245 |
+
cuda = {
|
| 246 |
+
"available": torch.cuda.is_available(),
|
| 247 |
+
"device_count": torch.cuda.device_count(),
|
| 248 |
+
}
|
| 249 |
+
if torch.cuda.is_available():
|
| 250 |
+
cuda["device_name"] = torch.cuda.get_device_name(0)
|
| 251 |
+
cuda["memory_allocated"] = torch.cuda.memory_allocated(0)
|
| 252 |
+
cuda["memory_reserved"] = torch.cuda.memory_reserved(0)
|
| 253 |
+
return {
|
| 254 |
+
"ok": self.load_error is None,
|
| 255 |
+
"model_loaded": self.model is not None,
|
| 256 |
+
"comet_model": self.args.comet_model,
|
| 257 |
+
"checkpoint_path": self.checkpoint_path,
|
| 258 |
+
"loaded_at": self.loaded_at,
|
| 259 |
+
"run_root": str(self.run_root),
|
| 260 |
+
"float32_matmul_precision": self.args.float32_matmul_precision,
|
| 261 |
+
"cuda": cuda,
|
| 262 |
+
"load_error": self.load_error,
|
| 263 |
+
"queue": self.scoring_batcher.status(),
|
| 264 |
+
}
|
| 265 |
+
|
| 266 |
+
|
| 267 |
+
def rows_from_request(payload: dict[str, Any]) -> tuple[list[dict[str, Any]], str]:
|
| 268 |
+
max_rows = payload.get("max_rows")
|
| 269 |
+
if payload.get("rows") is not None:
|
| 270 |
+
rows = list(payload["rows"])
|
| 271 |
+
if max_rows is not None:
|
| 272 |
+
rows = rows[: int(max_rows)]
|
| 273 |
+
return rows, payload.get("source_path", "request_rows")
|
| 274 |
+
if payload.get("hyps_jsonl"):
|
| 275 |
+
path = Path(payload["hyps_jsonl"])
|
| 276 |
+
rows = load_jsonl(path)
|
| 277 |
+
if max_rows is not None:
|
| 278 |
+
rows = rows[: int(max_rows)]
|
| 279 |
+
return rows, str(path)
|
| 280 |
+
raise ValueError("request needs either rows or hyps_jsonl")
|
| 281 |
+
|
| 282 |
+
|
| 283 |
+
def score_payload(state: ServiceState, payload: dict[str, Any]) -> tuple[list[dict[str, Any]], dict[str, Any]]:
|
| 284 |
+
state.load_model()
|
| 285 |
+
rows, source_path = rows_from_request(payload)
|
| 286 |
+
|
| 287 |
+
src_field = payload.get("src_field", "en")
|
| 288 |
+
ref_field = payload.get("ref_field", "pt")
|
| 289 |
+
hyp_field = payload.get("hyp_field", "model_hyp")
|
| 290 |
+
id_field = payload.get("id_field", "id")
|
| 291 |
+
batch_size = int(payload.get("batch_size", state.args.default_batch_size))
|
| 292 |
+
chunk_size = int(payload.get("chunk_size", state.args.default_chunk_size))
|
| 293 |
+
timeout_s = float(payload.get("timeout_s", state.args.queue_timeout_s))
|
| 294 |
+
threshold = float(payload.get("threshold", state.args.threshold))
|
| 295 |
+
system_name = payload.get("system_name") or Path(source_path).stem
|
| 296 |
+
|
| 297 |
+
data = []
|
| 298 |
+
valid_rows = []
|
| 299 |
+
for row in rows:
|
| 300 |
+
src = row.get(src_field)
|
| 301 |
+
hyp = row.get(hyp_field)
|
| 302 |
+
ref = row.get(ref_field)
|
| 303 |
+
if src is None or hyp is None:
|
| 304 |
+
continue
|
| 305 |
+
item = {"src": src, "mt": hyp}
|
| 306 |
+
if ref is not None:
|
| 307 |
+
item["ref"] = ref
|
| 308 |
+
data.append(item)
|
| 309 |
+
valid_rows.append(row)
|
| 310 |
+
if not data:
|
| 311 |
+
raise ValueError("no scoreable rows found")
|
| 312 |
+
|
| 313 |
+
t0 = time.time()
|
| 314 |
+
scored_rows: list[dict[str, Any]] = []
|
| 315 |
+
seg_scores: list[float] = []
|
| 316 |
+
results = state.scoring_batcher.score(data, batch_size=batch_size, timeout_s=timeout_s)
|
| 317 |
+
for i, result in enumerate(results):
|
| 318 |
+
src_row = valid_rows[i]
|
| 319 |
+
scored = {
|
| 320 |
+
"row_id": src_row.get(id_field, i),
|
| 321 |
+
"source_path": source_path,
|
| 322 |
+
"system": system_name,
|
| 323 |
+
"metric": state.args.comet_model,
|
| 324 |
+
"score": result.score,
|
| 325 |
+
"src": src_row[src_field],
|
| 326 |
+
"ref": src_row.get(ref_field),
|
| 327 |
+
"mt": src_row[hyp_field],
|
| 328 |
+
"category": src_row.get("category"),
|
| 329 |
+
"tag": src_row.get("tag"),
|
| 330 |
+
"metadata": {
|
| 331 |
+
k: v for k, v in src_row.items()
|
| 332 |
+
if k not in {src_field, ref_field, hyp_field}
|
| 333 |
+
},
|
| 334 |
+
}
|
| 335 |
+
if result.extra:
|
| 336 |
+
scored["metric_metadata"] = result.extra
|
| 337 |
+
scored_rows.append(scored)
|
| 338 |
+
seg_scores.append(result.score)
|
| 339 |
+
|
| 340 |
+
summary = {
|
| 341 |
+
"source_path": source_path,
|
| 342 |
+
"comet_model": state.args.comet_model,
|
| 343 |
+
"checkpoint_path": state.checkpoint_path,
|
| 344 |
+
"n": len(scored_rows),
|
| 345 |
+
"threshold": threshold,
|
| 346 |
+
"system_score": statistics.fmean(seg_scores),
|
| 347 |
+
"passed": sum(1 for s in seg_scores if s >= threshold),
|
| 348 |
+
"elapsed_seconds": time.time() - t0,
|
| 349 |
+
"batch_size": batch_size,
|
| 350 |
+
"chunk_size": chunk_size,
|
| 351 |
+
"max_worker_batch_size": state.scoring_batcher.max_worker_batch_size,
|
| 352 |
+
"max_batch_rows": state.scoring_batcher.max_rows,
|
| 353 |
+
"max_batch_wait_ms": int(state.scoring_batcher.max_wait_seconds * 1000),
|
| 354 |
+
"throughput_seg_per_s": len(scored_rows) / max(time.time() - t0, 1e-9),
|
| 355 |
+
}
|
| 356 |
+
return scored_rows, summary
|
| 357 |
+
|
| 358 |
+
|
| 359 |
+
def write_score_outputs(payload: dict[str, Any], rows: list[dict[str, Any]], summary: dict[str, Any]) -> dict[str, Any]:
|
| 360 |
+
out: dict[str, Any] = {}
|
| 361 |
+
out_jsonl = payload.get("out_jsonl")
|
| 362 |
+
if out_jsonl:
|
| 363 |
+
path = Path(out_jsonl)
|
| 364 |
+
path.parent.mkdir(parents=True, exist_ok=True)
|
| 365 |
+
write_jsonl(path, rows)
|
| 366 |
+
out["out_jsonl"] = str(path)
|
| 367 |
+
|
| 368 |
+
summary_json = payload.get("summary_json")
|
| 369 |
+
if summary_json:
|
| 370 |
+
path = Path(summary_json)
|
| 371 |
+
path.parent.mkdir(parents=True, exist_ok=True)
|
| 372 |
+
with path.open("w") as f:
|
| 373 |
+
json.dump(summary, f, indent=2, ensure_ascii=False)
|
| 374 |
+
out["summary_json"] = str(path)
|
| 375 |
+
return out
|
| 376 |
+
|
| 377 |
+
|
| 378 |
+
def build_dataset_payload(payload: dict[str, Any]) -> dict[str, Any]:
|
| 379 |
+
if payload.get("scored_rows") is not None:
|
| 380 |
+
scored_rows = normalize_pool(list(payload["scored_rows"]))
|
| 381 |
+
source = payload.get("source", "request_scored_rows")
|
| 382 |
+
elif payload.get("scored_jsonl"):
|
| 383 |
+
source_path = Path(payload["scored_jsonl"])
|
| 384 |
+
scored_rows = normalize_pool(load_jsonl(source_path))
|
| 385 |
+
source = str(source_path)
|
| 386 |
+
else:
|
| 387 |
+
raise ValueError("request needs either scored_rows or scored_jsonl")
|
| 388 |
+
if not scored_rows:
|
| 389 |
+
raise ValueError("no valid scored rows")
|
| 390 |
+
|
| 391 |
+
out_dir = Path(payload["out_dir"])
|
| 392 |
+
out_dir.mkdir(parents=True, exist_ok=True)
|
| 393 |
+
args = SimpleNamespace(
|
| 394 |
+
target_language=payload.get("target_language", "Portuguese"),
|
| 395 |
+
sft_min_score=float(payload.get("sft_min_score", 0.85)),
|
| 396 |
+
preference_min_gap=float(payload.get("preference_min_gap", 0.05)),
|
| 397 |
+
repair_max_score=float(payload.get("repair_max_score", 0.80)),
|
| 398 |
+
max_pairs_per_source=int(payload.get("max_pairs_per_source", 3)),
|
| 399 |
+
)
|
| 400 |
+
|
| 401 |
+
rows_by_source: dict[str, list[dict[str, Any]]] = {}
|
| 402 |
+
for row in scored_rows:
|
| 403 |
+
rows_by_source.setdefault(row["src"], []).append(row)
|
| 404 |
+
|
| 405 |
+
sft_rows, sft_rejects = build_sft(rows_by_source, args)
|
| 406 |
+
pref_rows, pref_rejects = build_preferences(rows_by_source, args)
|
| 407 |
+
repair_rows, repair_rejects = build_repairs(scored_rows, args)
|
| 408 |
+
|
| 409 |
+
write_jsonl(out_dir / "scored_pool.jsonl", scored_rows)
|
| 410 |
+
write_jsonl(out_dir / "sft.jsonl", sft_rows)
|
| 411 |
+
write_jsonl(out_dir / "preferences.jsonl", pref_rows)
|
| 412 |
+
write_jsonl(out_dir / "repair_triples.jsonl", repair_rows)
|
| 413 |
+
|
| 414 |
+
from collections import Counter
|
| 415 |
+
|
| 416 |
+
manifest = {
|
| 417 |
+
"source": source,
|
| 418 |
+
"target_language": args.target_language,
|
| 419 |
+
"thresholds": {
|
| 420 |
+
"sft_min_score": args.sft_min_score,
|
| 421 |
+
"preference_min_gap": args.preference_min_gap,
|
| 422 |
+
"repair_max_score": args.repair_max_score,
|
| 423 |
+
"max_pairs_per_source": args.max_pairs_per_source,
|
| 424 |
+
},
|
| 425 |
+
"counts": {
|
| 426 |
+
"scored_pool": len(scored_rows),
|
| 427 |
+
"unique_sources": len(rows_by_source),
|
| 428 |
+
"sft": len(sft_rows),
|
| 429 |
+
"preferences": len(pref_rows),
|
| 430 |
+
"repair_triples": len(repair_rows),
|
| 431 |
+
},
|
| 432 |
+
"splits": dict(Counter(row["split"] for row in scored_rows)),
|
| 433 |
+
"systems": dict(Counter(row.get("system", "?") for row in scored_rows)),
|
| 434 |
+
"categories": dict(Counter(row.get("category", "?") for row in scored_rows)),
|
| 435 |
+
"score_distribution": score_distribution(scored_rows),
|
| 436 |
+
"rejections": {
|
| 437 |
+
"sft": dict(sft_rejects),
|
| 438 |
+
"preferences": dict(pref_rejects),
|
| 439 |
+
"repair_triples": dict(repair_rejects),
|
| 440 |
+
},
|
| 441 |
+
"artifacts": {
|
| 442 |
+
"scored_pool": str(out_dir / "scored_pool.jsonl"),
|
| 443 |
+
"sft": str(out_dir / "sft.jsonl"),
|
| 444 |
+
"preferences": str(out_dir / "preferences.jsonl"),
|
| 445 |
+
"repair_triples": str(out_dir / "repair_triples.jsonl"),
|
| 446 |
+
},
|
| 447 |
+
}
|
| 448 |
+
with (out_dir / "curriculum_manifest.json").open("w") as f:
|
| 449 |
+
json.dump(manifest, f, indent=2, ensure_ascii=False)
|
| 450 |
+
return manifest
|
| 451 |
+
|
| 452 |
+
|
| 453 |
+
def make_handler(state: ServiceState):
|
| 454 |
+
class Handler(BaseHTTPRequestHandler):
|
| 455 |
+
server_version = "XCOMETService/0.1"
|
| 456 |
+
|
| 457 |
+
def log_message(self, fmt: str, *args: Any) -> None:
|
| 458 |
+
print(f"[{self.log_date_time_string()}] {self.address_string()} {fmt % args}", flush=True)
|
| 459 |
+
|
| 460 |
+
def authenticated(self) -> bool:
|
| 461 |
+
token = state.args.auth_token
|
| 462 |
+
if not token:
|
| 463 |
+
return True
|
| 464 |
+
auth = self.headers.get("Authorization", "")
|
| 465 |
+
header_token = self.headers.get("X-XCOMET-Token")
|
| 466 |
+
return auth == f"Bearer {token}" or header_token == token
|
| 467 |
+
|
| 468 |
+
def read_json(self) -> dict[str, Any]:
|
| 469 |
+
n = int(self.headers.get("Content-Length", "0"))
|
| 470 |
+
if n <= 0:
|
| 471 |
+
return {}
|
| 472 |
+
return json.loads(self.rfile.read(n))
|
| 473 |
+
|
| 474 |
+
def send_json(self, status: HTTPStatus, payload: dict[str, Any]) -> None:
|
| 475 |
+
body = json.dumps(payload, ensure_ascii=False).encode("utf-8")
|
| 476 |
+
self.send_response(status)
|
| 477 |
+
self.send_header("Content-Type", "application/json; charset=utf-8")
|
| 478 |
+
self.send_header("Content-Length", str(len(body)))
|
| 479 |
+
self.end_headers()
|
| 480 |
+
self.wfile.write(body)
|
| 481 |
+
|
| 482 |
+
def do_GET(self) -> None:
|
| 483 |
+
if self.path in {"/", "/health"}:
|
| 484 |
+
self.send_json(HTTPStatus.OK, state.status() | {
|
| 485 |
+
"endpoints": ["/health", "/load", "/score", "/dataset", "/score-dataset"],
|
| 486 |
+
})
|
| 487 |
+
return
|
| 488 |
+
self.send_json(HTTPStatus.NOT_FOUND, {"error": "not found"})
|
| 489 |
+
|
| 490 |
+
def do_POST(self) -> None:
|
| 491 |
+
if not self.authenticated():
|
| 492 |
+
self.send_json(HTTPStatus.UNAUTHORIZED, {"error": "unauthorized"})
|
| 493 |
+
return
|
| 494 |
+
try:
|
| 495 |
+
payload = self.read_json()
|
| 496 |
+
if self.path == "/load":
|
| 497 |
+
self.send_json(HTTPStatus.OK, state.load_model())
|
| 498 |
+
return
|
| 499 |
+
if self.path == "/score":
|
| 500 |
+
rows, summary = score_payload(state, payload)
|
| 501 |
+
outputs = write_score_outputs(payload, rows, summary)
|
| 502 |
+
response = {"summary": summary, "outputs": outputs}
|
| 503 |
+
if payload.get("return_rows", True):
|
| 504 |
+
response["rows"] = rows
|
| 505 |
+
self.send_json(HTTPStatus.OK, response)
|
| 506 |
+
return
|
| 507 |
+
if self.path == "/dataset":
|
| 508 |
+
self.send_json(HTTPStatus.OK, {"manifest": build_dataset_payload(payload)})
|
| 509 |
+
return
|
| 510 |
+
if self.path == "/score-dataset":
|
| 511 |
+
request_id = payload.get("request_id") or uuid.uuid4().hex[:12]
|
| 512 |
+
root = state.run_root / request_id
|
| 513 |
+
payload.setdefault("out_jsonl", str(root / "scored_pool.jsonl"))
|
| 514 |
+
payload.setdefault("summary_json", str(root / "scored_pool.summary.json"))
|
| 515 |
+
payload.setdefault("out_dir", str(root / "dataset"))
|
| 516 |
+
rows, summary = score_payload(state, payload)
|
| 517 |
+
outputs = write_score_outputs(payload, rows, summary)
|
| 518 |
+
manifest = build_dataset_payload({
|
| 519 |
+
**payload,
|
| 520 |
+
"scored_rows": rows,
|
| 521 |
+
"source": outputs.get("out_jsonl", "inline_scored_rows"),
|
| 522 |
+
})
|
| 523 |
+
self.send_json(HTTPStatus.OK, {
|
| 524 |
+
"summary": summary,
|
| 525 |
+
"outputs": outputs,
|
| 526 |
+
"manifest": manifest,
|
| 527 |
+
})
|
| 528 |
+
return
|
| 529 |
+
self.send_json(HTTPStatus.NOT_FOUND, {"error": "not found"})
|
| 530 |
+
except Exception as exc: # noqa: BLE001 - return JSON errors to callers
|
| 531 |
+
self.send_json(HTTPStatus.INTERNAL_SERVER_ERROR, {
|
| 532 |
+
"error": type(exc).__name__,
|
| 533 |
+
"message": str(exc),
|
| 534 |
+
})
|
| 535 |
+
|
| 536 |
+
return Handler
|
| 537 |
+
|
| 538 |
+
|
| 539 |
+
def main() -> None:
|
| 540 |
+
args = parse_args()
|
| 541 |
+
if torch.cuda.is_available():
|
| 542 |
+
torch.set_float32_matmul_precision(args.float32_matmul_precision)
|
| 543 |
+
state = ServiceState(args)
|
| 544 |
+
if args.load_on_start:
|
| 545 |
+
state.load_model()
|
| 546 |
+
server = ThreadingHTTPServer((args.host, args.port), make_handler(state))
|
| 547 |
+
print(json.dumps({
|
| 548 |
+
"event": "xcomet_service_start",
|
| 549 |
+
"host": args.host,
|
| 550 |
+
"port": args.port,
|
| 551 |
+
"comet_model": args.comet_model,
|
| 552 |
+
"run_root": args.run_root,
|
| 553 |
+
"auth_enabled": bool(args.auth_token),
|
| 554 |
+
"load_on_start": args.load_on_start,
|
| 555 |
+
}), flush=True)
|
| 556 |
+
server.serve_forever()
|
| 557 |
+
|
| 558 |
+
|
| 559 |
+
if __name__ == "__main__":
|
| 560 |
+
main()
|
circuit-shotting/artifacts/mined_substrate_only/issue41_mined_substrate_only_20260518T103722Z/spec/issue41_mined_substrate_only.json
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"issue": 41,
|
| 3 |
+
"title": "Evaluate mined MLP substrate-only sufficiency for EN->PT",
|
| 4 |
+
"source_issue": 39,
|
| 5 |
+
"model": "tencent/HY-MT1.5-1.8B",
|
| 6 |
+
"task": "EN->PT translation",
|
| 7 |
+
"heldout_eval": "NTREX EN->PT, 1012 rows",
|
| 8 |
+
"judge": "Unbabel/XCOMET-XXL",
|
| 9 |
+
"baseline_xcomet": 0.9287162019683438,
|
| 10 |
+
"source_artifacts": {
|
| 11 |
+
"repo": "TokenBender/circuit-discovery",
|
| 12 |
+
"repo_type": "dataset",
|
| 13 |
+
"prefix": "circuit-shotting/artifacts/actdelta_lora_mlp_mvc/issue39_actdelta_lora_mlp_mvc_20260518T011201Z",
|
| 14 |
+
"mask": "selection/chunks/masks/final_mix_top_3.full.npz",
|
| 15 |
+
"rank256_factors": "factors/rank_256"
|
| 16 |
+
},
|
| 17 |
+
"substrate": {
|
| 18 |
+
"name": "final_mix_top_3",
|
| 19 |
+
"channels": 5898,
|
| 20 |
+
"mlp_channel_universe": 196608,
|
| 21 |
+
"fraction": 0.0299993896484375
|
| 22 |
+
},
|
| 23 |
+
"systems": [
|
| 24 |
+
{
|
| 25 |
+
"name": "native_mined_substrate_only",
|
| 26 |
+
"intervention": "At every MLP down_proj input, keep only final_mix_top_3 native channels and zero every other MLP channel."
|
| 27 |
+
},
|
| 28 |
+
{
|
| 29 |
+
"name": "actdelta_rank256_substrate_only",
|
| 30 |
+
"intervention": "At every MLP down_proj input, write rank-256 ActDelta reconstructed selected channels and zero every other MLP channel."
|
| 31 |
+
}
|
| 32 |
+
],
|
| 33 |
+
"fixed_surfaces": [
|
| 34 |
+
"attention remains intact",
|
| 35 |
+
"residual stream remains intact",
|
| 36 |
+
"embeddings remain intact",
|
| 37 |
+
"layer norms remain intact",
|
| 38 |
+
"output head remains intact"
|
| 39 |
+
],
|
| 40 |
+
"runner": "issue41_substrate_only_runner.sh",
|
| 41 |
+
"summary_script": "summarize_issue41_substrate_only.py"
|
| 42 |
+
}
|
circuit-shotting/artifacts/mined_substrate_only/issue41_mined_substrate_only_20260518T103722Z/summaries/issue41_summary.json
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"run_root": "/root/runs/issue41_mined_substrate_only_c4354b4",
|
| 3 |
+
"baseline_xcomet": 0.9287162019683438,
|
| 4 |
+
"systems": [
|
| 5 |
+
{
|
| 6 |
+
"system": "native_mined_substrate_only",
|
| 7 |
+
"rank": null,
|
| 8 |
+
"channels": 5898,
|
| 9 |
+
"params": null,
|
| 10 |
+
"scores": {
|
| 11 |
+
"chrFpp": 0.37995466816117174,
|
| 12 |
+
"chrF": 0.5010594194152935,
|
| 13 |
+
"BLEU": 0.0005806916822995268,
|
| 14 |
+
"n": 1012
|
| 15 |
+
},
|
| 16 |
+
"xcomet": 0.2118839286819925,
|
| 17 |
+
"recovery": 0.22814712205183943,
|
| 18 |
+
"method": "native selected MLP channels only; all other MLP channels zeroed"
|
| 19 |
+
},
|
| 20 |
+
{
|
| 21 |
+
"system": "actdelta_rank256_substrate_only",
|
| 22 |
+
"rank": 256,
|
| 23 |
+
"channels": 5898,
|
| 24 |
+
"params": 2034176,
|
| 25 |
+
"scores": {
|
| 26 |
+
"chrFpp": 0.07855792684457256,
|
| 27 |
+
"chrF": 0.05595505685552267,
|
| 28 |
+
"BLEU": 0.0017090422944717233,
|
| 29 |
+
"n": 1012
|
| 30 |
+
},
|
| 31 |
+
"xcomet": 0.22047376124696297,
|
| 32 |
+
"recovery": 0.23739626893520915,
|
| 33 |
+
"method": "rank-256 ActDelta reconstruction of selected channels only; all other MLP channels zeroed"
|
| 34 |
+
}
|
| 35 |
+
]
|
| 36 |
+
}
|
circuit-shotting/artifacts/mined_substrate_only/issue41_mined_substrate_only_20260518T103722Z/summaries/issue41_summary.md
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Issue 41 Mined MLP Substrate-Only Summary
|
| 2 |
+
|
| 3 |
+
- Baseline XCOMET: `0.9287162019683438`
|
| 4 |
+
|
| 5 |
+
| system | rank | channels | params | chrF++ | BLEU | XCOMET | recovery |
|
| 6 |
+
|---|---:|---:|---:|---:|---:|---:|---:|
|
| 7 |
+
| `native_mined_substrate_only` | `-` | `5898` | `-` | `0.37995466816117174` | `0.0005806916822995268` | `0.2118839286819925` | `0.22814712205183943` |
|
| 8 |
+
| `actdelta_rank256_substrate_only` | `256` | `5898` | `2034176` | `0.07855792684457256` | `0.0017090422944717233` | `0.22047376124696297` | `0.23739626893520915` |
|
circuit-shotting/artifacts/mined_substrate_only/issue41_mined_substrate_only_20260518T103722Z/xcomet/actdelta_rank256_substrate_only.json
ADDED
|
@@ -0,0 +1,126 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"health": [
|
| 3 |
+
{
|
| 4 |
+
"idx": 0,
|
| 5 |
+
"base_url": "http://127.0.0.1:10001",
|
| 6 |
+
"health": {
|
| 7 |
+
"model_loaded": true,
|
| 8 |
+
"comet_model": "Unbabel/XCOMET-XXL",
|
| 9 |
+
"cuda": {
|
| 10 |
+
"available": true,
|
| 11 |
+
"device_count": 1,
|
| 12 |
+
"device_name": "NVIDIA RTX PRO 6000 Blackwell Workstation Edition",
|
| 13 |
+
"memory_allocated": 0,
|
| 14 |
+
"memory_reserved": 0
|
| 15 |
+
}
|
| 16 |
+
}
|
| 17 |
+
}
|
| 18 |
+
],
|
| 19 |
+
"summary": {
|
| 20 |
+
"source_path": "/root/runs/issue41_mined_substrate_only_c4354b4/dumps/ntrex/actdelta_rank256_substrate_only.jsonl",
|
| 21 |
+
"comet_model": "Unbabel/XCOMET-XXL",
|
| 22 |
+
"checkpoint_path": "/root/.cache/huggingface/hub/models--Unbabel--XCOMET-XXL/snapshots/873bac1b1c461e410c4a6e379f6790d3d1c7c214/checkpoints/model.ckpt",
|
| 23 |
+
"n": 1012,
|
| 24 |
+
"threshold": 0.99,
|
| 25 |
+
"system_score": 0.22047376124696297,
|
| 26 |
+
"passed": 0,
|
| 27 |
+
"elapsed_seconds": 701.6217973232269,
|
| 28 |
+
"batch_size": 8,
|
| 29 |
+
"chunk_size": 32,
|
| 30 |
+
"shard_count": 1,
|
| 31 |
+
"throughput_seg_per_s": 1.442372519173616
|
| 32 |
+
},
|
| 33 |
+
"outputs": {
|
| 34 |
+
"out_jsonl": "/root/runs/issue41_mined_substrate_only_c4354b4/xcomet/actdelta_rank256_substrate_only.scored_pool.jsonl",
|
| 35 |
+
"shard_dir": "/root/runs/issue41_mined_substrate_only_c4354b4/xcomet_shards/actdelta_rank256_substrate_only"
|
| 36 |
+
},
|
| 37 |
+
"shards": [
|
| 38 |
+
{
|
| 39 |
+
"service": {
|
| 40 |
+
"idx": 0,
|
| 41 |
+
"base_url": "http://127.0.0.1:10001",
|
| 42 |
+
"health": {
|
| 43 |
+
"model_loaded": true,
|
| 44 |
+
"comet_model": "Unbabel/XCOMET-XXL",
|
| 45 |
+
"cuda": {
|
| 46 |
+
"available": true,
|
| 47 |
+
"device_count": 1,
|
| 48 |
+
"device_name": "NVIDIA RTX PRO 6000 Blackwell Workstation Edition",
|
| 49 |
+
"memory_allocated": 0,
|
| 50 |
+
"memory_reserved": 0
|
| 51 |
+
}
|
| 52 |
+
}
|
| 53 |
+
},
|
| 54 |
+
"shard_path": "/root/runs/issue41_mined_substrate_only_c4354b4/xcomet_shards/actdelta_rank256_substrate_only/shard_000.jsonl",
|
| 55 |
+
"summary": {
|
| 56 |
+
"source_path": "/root/runs/issue41_mined_substrate_only_c4354b4/xcomet_shards/actdelta_rank256_substrate_only/shard_000.jsonl",
|
| 57 |
+
"comet_model": "Unbabel/XCOMET-XXL",
|
| 58 |
+
"checkpoint_path": "/root/.cache/huggingface/hub/models--Unbabel--XCOMET-XXL/snapshots/873bac1b1c461e410c4a6e379f6790d3d1c7c214/checkpoints/model.ckpt",
|
| 59 |
+
"n": 1012,
|
| 60 |
+
"threshold": 0.99,
|
| 61 |
+
"system_score": 0.22047376124696297,
|
| 62 |
+
"passed": 0,
|
| 63 |
+
"elapsed_seconds": 701.5416388511658,
|
| 64 |
+
"batch_size": 8,
|
| 65 |
+
"chunk_size": 32,
|
| 66 |
+
"max_worker_batch_size": 8,
|
| 67 |
+
"max_batch_rows": 32,
|
| 68 |
+
"max_batch_wait_ms": 100,
|
| 69 |
+
"throughput_seg_per_s": 1.4425373184610868
|
| 70 |
+
},
|
| 71 |
+
"outputs": {
|
| 72 |
+
"out_jsonl": "/root/runs/issue41_mined_substrate_only_c4354b4/services/xcomet_0/issue41_actdelta_rank256_substrate_only_shard000/scored_pool.jsonl",
|
| 73 |
+
"summary_json": "/root/runs/issue41_mined_substrate_only_c4354b4/services/xcomet_0/issue41_actdelta_rank256_substrate_only_shard000/scored_pool.summary.json"
|
| 74 |
+
},
|
| 75 |
+
"manifest": {
|
| 76 |
+
"source": "/root/runs/issue41_mined_substrate_only_c4354b4/services/xcomet_0/issue41_actdelta_rank256_substrate_only_shard000/scored_pool.jsonl",
|
| 77 |
+
"target_language": "Portuguese",
|
| 78 |
+
"thresholds": {
|
| 79 |
+
"sft_min_score": 0.85,
|
| 80 |
+
"preference_min_gap": 0.05,
|
| 81 |
+
"repair_max_score": 0.8,
|
| 82 |
+
"max_pairs_per_source": 3
|
| 83 |
+
},
|
| 84 |
+
"counts": {
|
| 85 |
+
"scored_pool": 1012,
|
| 86 |
+
"unique_sources": 1012,
|
| 87 |
+
"sft": 0,
|
| 88 |
+
"preferences": 0,
|
| 89 |
+
"repair_triples": 1012
|
| 90 |
+
},
|
| 91 |
+
"splits": {
|
| 92 |
+
"train": 788,
|
| 93 |
+
"test": 104,
|
| 94 |
+
"dev": 120
|
| 95 |
+
},
|
| 96 |
+
"systems": {
|
| 97 |
+
"issue41_actdelta_rank256_substrate_only_shard000": 1012
|
| 98 |
+
},
|
| 99 |
+
"categories": {
|
| 100 |
+
"ntrex_test": 1012
|
| 101 |
+
},
|
| 102 |
+
"score_distribution": {
|
| 103 |
+
"min": 0.16411660611629486,
|
| 104 |
+
"mean": 0.22047376124696297,
|
| 105 |
+
"median": 0.21810869127511978,
|
| 106 |
+
"max": 0.2613651752471924
|
| 107 |
+
},
|
| 108 |
+
"rejections": {
|
| 109 |
+
"sft": {
|
| 110 |
+
"below_sft_min_score": 1012
|
| 111 |
+
},
|
| 112 |
+
"preferences": {
|
| 113 |
+
"single_candidate_source": 1012
|
| 114 |
+
},
|
| 115 |
+
"repair_triples": {}
|
| 116 |
+
},
|
| 117 |
+
"artifacts": {
|
| 118 |
+
"scored_pool": "/root/runs/issue41_mined_substrate_only_c4354b4/services/xcomet_0/issue41_actdelta_rank256_substrate_only_shard000/dataset/scored_pool.jsonl",
|
| 119 |
+
"sft": "/root/runs/issue41_mined_substrate_only_c4354b4/services/xcomet_0/issue41_actdelta_rank256_substrate_only_shard000/dataset/sft.jsonl",
|
| 120 |
+
"preferences": "/root/runs/issue41_mined_substrate_only_c4354b4/services/xcomet_0/issue41_actdelta_rank256_substrate_only_shard000/dataset/preferences.jsonl",
|
| 121 |
+
"repair_triples": "/root/runs/issue41_mined_substrate_only_c4354b4/services/xcomet_0/issue41_actdelta_rank256_substrate_only_shard000/dataset/repair_triples.jsonl"
|
| 122 |
+
}
|
| 123 |
+
}
|
| 124 |
+
}
|
| 125 |
+
]
|
| 126 |
+
}
|
circuit-shotting/artifacts/mined_substrate_only/issue41_mined_substrate_only_20260518T103722Z/xcomet/actdelta_rank256_substrate_only.scored_pool.jsonl
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
circuit-shotting/artifacts/mined_substrate_only/issue41_mined_substrate_only_20260518T103722Z/xcomet/native_mined_substrate_only.json
ADDED
|
@@ -0,0 +1,126 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"health": [
|
| 3 |
+
{
|
| 4 |
+
"idx": 0,
|
| 5 |
+
"base_url": "http://127.0.0.1:10001",
|
| 6 |
+
"health": {
|
| 7 |
+
"model_loaded": true,
|
| 8 |
+
"comet_model": "Unbabel/XCOMET-XXL",
|
| 9 |
+
"cuda": {
|
| 10 |
+
"available": true,
|
| 11 |
+
"device_count": 1,
|
| 12 |
+
"device_name": "NVIDIA RTX PRO 6000 Blackwell Workstation Edition",
|
| 13 |
+
"memory_allocated": 0,
|
| 14 |
+
"memory_reserved": 0
|
| 15 |
+
}
|
| 16 |
+
}
|
| 17 |
+
}
|
| 18 |
+
],
|
| 19 |
+
"summary": {
|
| 20 |
+
"source_path": "/root/runs/issue41_mined_substrate_only_c4354b4/dumps/ntrex/native_mined_substrate_only.jsonl",
|
| 21 |
+
"comet_model": "Unbabel/XCOMET-XXL",
|
| 22 |
+
"checkpoint_path": "/root/.cache/huggingface/hub/models--Unbabel--XCOMET-XXL/snapshots/873bac1b1c461e410c4a6e379f6790d3d1c7c214/checkpoints/model.ckpt",
|
| 23 |
+
"n": 1012,
|
| 24 |
+
"threshold": 0.99,
|
| 25 |
+
"system_score": 0.2118839286819925,
|
| 26 |
+
"passed": 0,
|
| 27 |
+
"elapsed_seconds": 702.3393831253052,
|
| 28 |
+
"batch_size": 8,
|
| 29 |
+
"chunk_size": 32,
|
| 30 |
+
"shard_count": 1,
|
| 31 |
+
"throughput_seg_per_s": 1.4408988340922393
|
| 32 |
+
},
|
| 33 |
+
"outputs": {
|
| 34 |
+
"out_jsonl": "/root/runs/issue41_mined_substrate_only_c4354b4/xcomet/native_mined_substrate_only.scored_pool.jsonl",
|
| 35 |
+
"shard_dir": "/root/runs/issue41_mined_substrate_only_c4354b4/xcomet_shards/native_mined_substrate_only"
|
| 36 |
+
},
|
| 37 |
+
"shards": [
|
| 38 |
+
{
|
| 39 |
+
"service": {
|
| 40 |
+
"idx": 0,
|
| 41 |
+
"base_url": "http://127.0.0.1:10001",
|
| 42 |
+
"health": {
|
| 43 |
+
"model_loaded": true,
|
| 44 |
+
"comet_model": "Unbabel/XCOMET-XXL",
|
| 45 |
+
"cuda": {
|
| 46 |
+
"available": true,
|
| 47 |
+
"device_count": 1,
|
| 48 |
+
"device_name": "NVIDIA RTX PRO 6000 Blackwell Workstation Edition",
|
| 49 |
+
"memory_allocated": 0,
|
| 50 |
+
"memory_reserved": 0
|
| 51 |
+
}
|
| 52 |
+
}
|
| 53 |
+
},
|
| 54 |
+
"shard_path": "/root/runs/issue41_mined_substrate_only_c4354b4/xcomet_shards/native_mined_substrate_only/shard_000.jsonl",
|
| 55 |
+
"summary": {
|
| 56 |
+
"source_path": "/root/runs/issue41_mined_substrate_only_c4354b4/xcomet_shards/native_mined_substrate_only/shard_000.jsonl",
|
| 57 |
+
"comet_model": "Unbabel/XCOMET-XXL",
|
| 58 |
+
"checkpoint_path": "/root/.cache/huggingface/hub/models--Unbabel--XCOMET-XXL/snapshots/873bac1b1c461e410c4a6e379f6790d3d1c7c214/checkpoints/model.ckpt",
|
| 59 |
+
"n": 1012,
|
| 60 |
+
"threshold": 0.99,
|
| 61 |
+
"system_score": 0.2118839286819925,
|
| 62 |
+
"passed": 0,
|
| 63 |
+
"elapsed_seconds": 702.2706558704376,
|
| 64 |
+
"batch_size": 8,
|
| 65 |
+
"chunk_size": 32,
|
| 66 |
+
"max_worker_batch_size": 8,
|
| 67 |
+
"max_batch_rows": 32,
|
| 68 |
+
"max_batch_wait_ms": 100,
|
| 69 |
+
"throughput_seg_per_s": 1.4410398427928701
|
| 70 |
+
},
|
| 71 |
+
"outputs": {
|
| 72 |
+
"out_jsonl": "/root/runs/issue41_mined_substrate_only_c4354b4/services/xcomet_0/issue41_native_mined_substrate_only_shard000/scored_pool.jsonl",
|
| 73 |
+
"summary_json": "/root/runs/issue41_mined_substrate_only_c4354b4/services/xcomet_0/issue41_native_mined_substrate_only_shard000/scored_pool.summary.json"
|
| 74 |
+
},
|
| 75 |
+
"manifest": {
|
| 76 |
+
"source": "/root/runs/issue41_mined_substrate_only_c4354b4/services/xcomet_0/issue41_native_mined_substrate_only_shard000/scored_pool.jsonl",
|
| 77 |
+
"target_language": "Portuguese",
|
| 78 |
+
"thresholds": {
|
| 79 |
+
"sft_min_score": 0.85,
|
| 80 |
+
"preference_min_gap": 0.05,
|
| 81 |
+
"repair_max_score": 0.8,
|
| 82 |
+
"max_pairs_per_source": 3
|
| 83 |
+
},
|
| 84 |
+
"counts": {
|
| 85 |
+
"scored_pool": 1012,
|
| 86 |
+
"unique_sources": 1012,
|
| 87 |
+
"sft": 0,
|
| 88 |
+
"preferences": 0,
|
| 89 |
+
"repair_triples": 1012
|
| 90 |
+
},
|
| 91 |
+
"splits": {
|
| 92 |
+
"train": 788,
|
| 93 |
+
"test": 104,
|
| 94 |
+
"dev": 120
|
| 95 |
+
},
|
| 96 |
+
"systems": {
|
| 97 |
+
"issue41_native_mined_substrate_only_shard000": 1012
|
| 98 |
+
},
|
| 99 |
+
"categories": {
|
| 100 |
+
"ntrex_test": 1012
|
| 101 |
+
},
|
| 102 |
+
"score_distribution": {
|
| 103 |
+
"min": 0.03281227871775627,
|
| 104 |
+
"mean": 0.2118839286819925,
|
| 105 |
+
"median": 0.2136721983551979,
|
| 106 |
+
"max": 0.2972782850265503
|
| 107 |
+
},
|
| 108 |
+
"rejections": {
|
| 109 |
+
"sft": {
|
| 110 |
+
"below_sft_min_score": 1012
|
| 111 |
+
},
|
| 112 |
+
"preferences": {
|
| 113 |
+
"single_candidate_source": 1012
|
| 114 |
+
},
|
| 115 |
+
"repair_triples": {}
|
| 116 |
+
},
|
| 117 |
+
"artifacts": {
|
| 118 |
+
"scored_pool": "/root/runs/issue41_mined_substrate_only_c4354b4/services/xcomet_0/issue41_native_mined_substrate_only_shard000/dataset/scored_pool.jsonl",
|
| 119 |
+
"sft": "/root/runs/issue41_mined_substrate_only_c4354b4/services/xcomet_0/issue41_native_mined_substrate_only_shard000/dataset/sft.jsonl",
|
| 120 |
+
"preferences": "/root/runs/issue41_mined_substrate_only_c4354b4/services/xcomet_0/issue41_native_mined_substrate_only_shard000/dataset/preferences.jsonl",
|
| 121 |
+
"repair_triples": "/root/runs/issue41_mined_substrate_only_c4354b4/services/xcomet_0/issue41_native_mined_substrate_only_shard000/dataset/repair_triples.jsonl"
|
| 122 |
+
}
|
| 123 |
+
}
|
| 124 |
+
}
|
| 125 |
+
]
|
| 126 |
+
}
|
circuit-shotting/artifacts/mined_substrate_only/issue41_mined_substrate_only_20260518T103722Z/xcomet/native_mined_substrate_only.scored_pool.jsonl
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|