Download scripts/probe_think.py from tysgydke/Qwen3-4B-LoopIntervention: direct link, hf CLI and curl.
- Browser
- Download file 1.08 kB
-
https://huggingface.co/tysgydke/Qwen3-4B-LoopIntervention/resolve/main/scripts/probe_think.py
- Command line
-
hf download hf://tysgydke/Qwen3-4B-LoopIntervention/scripts/probe_think.py
-
curl -L -o probe_think.py https://huggingface.co/tysgydke/Qwen3-4B-LoopIntervention/resolve/main/scripts/probe_think.py
1.08 kB
| # 诊断探针:现有通才网络(intervmix_step4000)在自蒸馏思维链数据上的 CE 改善幅度 | |
| # 与它在 GSM8K 短答案上的表现对比,决定是否需要专门的思考专家 | |
| import json, sys | |
| import torch | |
| from train_interv import LoopModel, probe | |
| CKPT = sys.argv[1] if len(sys.argv) > 1 else '/root/autodl-tmp/loop-exp/ckpt/intervmix_step4000.pt' | |
| DATA = '/root/autodl-tmp/data/selfthink_v1.jsonl' | |
| N_DOCS = 100 | |
| MAX_LEN = 1024 | |
| def main(): | |
| lm = LoopModel() | |
| sd = torch.load(CKPT, map_location='cuda', weights_only=False) | |
| lm.interv.load_state_dict(sd['sd']) | |
| print(f"loaded ckpt step={sd['step']}", flush=True) | |
| docs = [json.loads(l)['text'] for l in open(DATA)][:N_DOCS] | |
| enc = [lm.tok(d, truncation=True, max_length=MAX_LEN)['input_ids'] for d in docs] | |
| enc = [e for e in enc if len(e) > 64] | |
| print(f'docs={len(enc)} 平均token={sum(len(e) for e in enc)/len(enc):.0f}', flush=True) | |
| pr = probe(lm, enc, r=2, n_docs=len(enc)) | |
| print(json.dumps({'probe_think': pr}), flush=True) | |
| if __name__ == '__main__': | |
| main() | |