File size: 3,833 Bytes
64cdbf6 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 | #!/bin/bash
# Dream's published HumanEval recipe (temperature=0.1, top_p=0.9, alg=entropy)
# produces all-EOS. Hypothesis: temperature<1 SCALES UP the logits, then top_p=0.9
# keeps only the argmax -> the filtered distribution is one-hot -> neg-entropy is
# exactly 0 at EVERY masked position -> all confidences tie -> "pick the most
# confident token" degenerates into an arbitrary (index-order) choice.
#
# Measure the confidence signal directly across (temperature, top_p), and check
# which combinations still generate code.
set -uo pipefail
pip install -q "transformers==4.46.2" "huggingface_hub<1.0" "datasets<4" "accelerate" 2>&1 | tail -1
python -c "
from huggingface_hub import snapshot_download
snapshot_download('ashishk1331/ccd-repro-code', repo_type='dataset', local_dir='/work')"
cd /work && mkdir -p outputs
python - <<'EOF'
import sys, torch, json
sys.path.insert(0, "scripts")
from transformers import AutoModel, AutoTokenizer
from datasets import load_dataset
import ccd_decode
from run_eval import humaneval_prompt
M = "Dream-org/Dream-v0-Instruct-7B"
tok = AutoTokenizer.from_pretrained(M, trust_remote_code=True)
model = AutoModel.from_pretrained(M, torch_dtype=torch.bfloat16,
trust_remote_code=True).to("cuda").eval()
doc = load_dataset("openai/openai_humaneval", split="test")[0]
enc = tok(humaneval_prompt(tok, doc), return_tensors="pt")
ids, attn = enc.input_ids.to("cuda"), enc.attention_mask.to("cuda")
mask_id = model.config.mask_token_id
# ---- Part 1: the confidence signal at step 0, for each (temp, top_p)
x = torch.nn.functional.pad(ids, (0, 256), value=mask_id)
with torch.no_grad():
logits = model(x, "full", None).logits
logits = torch.cat([logits[:, :1], logits[:, :-1]], dim=1)
mask_pos = (x[0] == mask_id).nonzero(as_tuple=True)[0]
ml = logits[0, mask_pos]
print("\n=========== CONFIDENCE SIGNAL AT STEP 0 (256 masked positions) ===========")
print(f"{'temp':>5} {'top_p':>6} {'#conf exactly 0':>16} {'distinct conf values':>21} {'conf std':>10}")
res = {}
for temp in [0.0, 0.1, 0.4, 0.7, 1.0]:
for tp in [0.9, 1.0]:
probs = ccd_decode._apply_filters(ml, temperature=temp, top_p=tp)
conf = ccd_decode._neg_entropy(probs)
n_zero = int((conf.abs() < 1e-6).sum())
n_uniq = int(torch.unique(conf).numel())
print(f"{temp:>5} {tp:>6} {n_zero:>16} {n_uniq:>21} {conf.std().item():>10.4f}")
res[f"t{temp}_p{tp}"] = dict(n_zero=n_zero, n_unique=n_uniq, std=conf.std().item())
print("\n#conf exactly 0 == 256 means EVERY position is one-hot after filtering, so")
print("the entropy-based ranking carries NO information and ties are broken by index.")
# ---- Part 2: does it still generate code?
print("\n=========== GENERATION (baseline, 256 steps) ===========")
for temp, tp in [(0.0, 1.0), (0.0, 0.9), (0.1, 0.9), (0.1, 1.0), (0.4, 0.9), (1.0, 0.9)]:
torch.manual_seed(0)
xo, st = ccd_decode.generate(model, ids, attention_mask=attn, max_new_tokens=256,
steps=256, temperature=temp, top_p=tp,
mask_token_id=mask_id, method="baseline")
g = xo[0, ids.shape[1]:].tolist()
n_eos = sum(1 for i in g if i == tok.eos_token_id)
txt = tok.decode(g).split(tok.eos_token)[0]
print(f"\n temp={temp} top_p={tp} eos={n_eos}/256")
print(f" {repr(txt[:150])}")
res[f"gen_t{temp}_p{tp}"] = dict(n_eos=n_eos, text=txt[:300])
json.dump(res, open("outputs/temp_toppy_diagnostic.json", "w"), indent=1)
from huggingface_hub import HfApi
HfApi().upload_file(path_or_fileobj="outputs/temp_toppy_diagnostic.json",
path_in_repo="outputs/temp_toppy_diagnostic.json",
repo_id="ashishk1331/ccd-repro-results", repo_type="dataset")
print("\nuploaded outputs/temp_toppy_diagnostic.json")
EOF
|