ashishk1331 commited on
Commit
c2543b7
·
verified ·
1 Parent(s): 02bdb20

debug scripts

Browse files
scripts/__pycache__/ccd_decode.cpython-312.pyc CHANGED
Binary files a/scripts/__pycache__/ccd_decode.cpython-312.pyc and b/scripts/__pycache__/ccd_decode.cpython-312.pyc differ
 
scripts/__pycache__/run_eval.cpython-312.pyc CHANGED
Binary files a/scripts/__pycache__/run_eval.cpython-312.pyc and b/scripts/__pycache__/run_eval.cpython-312.pyc differ
 
scripts/check_budget_bound.py ADDED
@@ -0,0 +1,118 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """A structural bound on CCD-DS's throughput, and an empirical test of it.
2
+
3
+ THE BOUND
4
+ ---------
5
+ Let S_u be the top-V confident position set at iteration u (|S_u| = V), and
6
+ I^c_u = S_u ∩ S_{u-1} ∩ ... ∩ S_{u-d} (Eq. 16 + Eq. 17)
7
+ CCD-DS decodes J_u ⊆ I^c_u, so k_u := |J_u| tokens leave the masked set at step u.
8
+
9
+ Claim: once the buffer is full, for every u in {t-d, ..., t-1} we have
10
+ I^c_u ⊆ S_{t-d}.
11
+ Proof: I^c_u intersects the top-V sets of iterations u-d .. u. Since
12
+ t-d ∈ [u-d, u] for every u ∈ [t-d, t-1], the set S_{t-d} is one of the
13
+ sets being intersected, hence I^c_u ⊆ S_{t-d}.
14
+
15
+ So every token decoded during the last d steps was a member of S_{t-d}, and those
16
+ positions are distinct (a decoded position never returns to the masked set).
17
+ Therefore
18
+
19
+ |I^c_t| <= |S_{t-d} ∩ K_t| <= V - sum_{j=1..d} k_{t-j}
20
+
21
+ and in steady state (k_u = k for all u):
22
+
23
+ k <= V - d*k => k <= V / (d + 1) (*)
24
+
25
+ Since CCD-DS's speedup over the uniform b_t=1 schedule is exactly the mean number
26
+ of tokens decoded per step, (*) caps the achievable speedup at V/(d+1).
27
+
28
+ CONSEQUENCE FOR THE PAPER'S NUMBERS
29
+ -----------------------------------
30
+ The paper sets V=4 and d=3 for Dream (Sec. 4.2), giving V/(d+1) = 4/4 = 1.0:
31
+ CCD-DS cannot decode more than 1 token per step on average, i.e. **no speedup at
32
+ all** -- yet Table 1 reports 3.48x on Trip Plan and 3.04x on HumanEval.
33
+
34
+ This script verifies (*) exactly by simulation (no model required) and reports the
35
+ V that each headline speedup would actually need.
36
+ """
37
+ import numpy as np
38
+ import json, os
39
+
40
+ rng = np.random.default_rng(0)
41
+
42
+
43
+ def simulate(V, d, N=256, n_masked_pool=256, trials=200):
44
+ """Simulate CCD-DS position bookkeeping with an adversarially *favourable*
45
+ model: the top-V set is as stable as it can possibly be (the confidence
46
+ ranking never reshuffles). This gives CCD-DS the best case."""
47
+ max_ic, ks = 0, []
48
+ for _ in range(trials):
49
+ masked = list(range(n_masked_pool))
50
+ hist = [] # recent top-V sets, newest last
51
+ steps = 0
52
+ decoded_total = 0
53
+ while masked and steps < N:
54
+ S = set(masked[:V]) # best case: stable ranking
55
+ ic = set(S)
56
+ for h in hist:
57
+ ic &= h
58
+ ic &= set(masked)
59
+ if len(ic) == 0:
60
+ k = 1 # fallback: baseline decodes b_t=1
61
+ dec = [masked[0]]
62
+ else:
63
+ k = len(ic) # best case: decode ALL of I^c_t
64
+ dec = list(ic)
65
+ max_ic = max(max_ic, len(ic))
66
+ for p in dec:
67
+ masked.remove(p)
68
+ decoded_total += k
69
+ hist.append(S)
70
+ if len(hist) > d:
71
+ hist.pop(0)
72
+ steps += 1
73
+ ks.append(k)
74
+ # note: steps ends when everything decoded
75
+ return float(np.mean(ks)), max_ic
76
+
77
+
78
+ results = {"bound": "k <= V/(d+1)", "sim": [], "required_V": {}}
79
+ print("=" * 78)
80
+ print("STRUCTURAL BOUND ON CCD-DS THROUGHPUT: k <= V / (d + 1)")
81
+ print("=" * 78)
82
+ print(f"{'V':>3} {'d':>3} {'V/(d+1)':>9} {'simulated mean k':>18} {'max |I^c_t|':>12} status")
83
+ ok = True
84
+ for V, d in [(4, 3), (4, 2), (4, 1), (4, 0), (8, 3), (16, 3), (24, 3), (6, 3), (2, 3)]:
85
+ k, mx = simulate(V, d)
86
+ bound = V / (d + 1)
87
+ good = k <= bound + 1e-9
88
+ ok &= good
89
+ star = "paper's Dream config" if (V, d) == (4, 3) else ""
90
+ print(f"{V:>3} {d:>3} {bound:>9.2f} {k:>18.3f} {mx:>12} "
91
+ f"{'OK' if good else 'VIOLATED'} {star}")
92
+ results["sim"].append({"V": V, "d": d, "bound": bound, "sim_mean_k": k, "max_ic": mx})
93
+
94
+ print(f"\nBound respected in every simulated configuration: {ok}")
95
+ print("(The simulation gives CCD-DS its best case: a perfectly stable confidence")
96
+ print(" ranking and decoding *all* of I^c_t every step. Real runs can only be worse.)")
97
+
98
+ print()
99
+ print("=" * 78)
100
+ print("WHAT V WOULD THE PAPER'S REPORTED SPEEDUPS REQUIRE? (d = 3 for Dream)")
101
+ print("=" * 78)
102
+ print(f"{'benchmark':<12} {'reported speedup':>17} {'needed k':>9} {'needed V = k*(d+1)':>20}")
103
+ for name, sp in [("Trip Plan", 3.48), ("HumanEval", 3.04), ("MBPP", 3.78),
104
+ ("GSM8K", 1.82), ("MATH", 1.58)]:
105
+ need_V = sp * 4
106
+ print(f"{name:<12} {sp:>16.2f}x {sp:>9.2f} {need_V:>20.1f}")
107
+ results["required_V"][name] = {"speedup": sp, "needed_V": need_V}
108
+
109
+ print(f"\nThe paper states V = 4 (Sec. 4.2, 'Unless otherwise stated, we set V=4').")
110
+ print(f"With V=4, d=3 the cap is k <= 1.00, i.e. speedup <= 1.00x.")
111
+ print(f"Reproducing 3.48x on Trip Plan would need V >= 13.9 at d=3.")
112
+ print(f"\nNote the cap is independent of the model, the benchmark and the")
113
+ print(f"stability heuristic -- it follows from the position bookkeeping alone.")
114
+
115
+ os.makedirs("outputs", exist_ok=True)
116
+ with open("outputs/budget_bound_check.json", "w") as f:
117
+ json.dump(results, f, indent=1)
118
+ print("\nwrote outputs/budget_bound_check.json")
scripts/job_debug_he.sh ADDED
@@ -0,0 +1,46 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/bin/bash
2
+ # Why is the HumanEval response empty? Dump raw generated ids for ONE example.
3
+ set -uo pipefail
4
+ pip install -q "transformers==4.46.2" "huggingface_hub<1.0" "datasets<4" "accelerate" 2>&1 | tail -1
5
+ python -c "
6
+ from huggingface_hub import snapshot_download
7
+ snapshot_download('ashishk1331/ccd-repro-code', repo_type='dataset', local_dir='/work')"
8
+ cd /work
9
+
10
+ python - <<'EOF'
11
+ import sys, torch
12
+ sys.path.insert(0, "scripts")
13
+ from transformers import AutoModel, AutoTokenizer
14
+ from datasets import load_dataset
15
+ import ccd_decode
16
+ from run_eval import humaneval_prompt
17
+
18
+ M = "Dream-org/Dream-v0-Instruct-7B"
19
+ tok = AutoTokenizer.from_pretrained(M, trust_remote_code=True)
20
+ model = AutoModel.from_pretrained(M, torch_dtype=torch.bfloat16,
21
+ trust_remote_code=True).to("cuda").eval()
22
+ doc = load_dataset("openai/openai_humaneval", split="test")[0]
23
+ p = humaneval_prompt(tok, doc)
24
+ enc = tok(p, return_tensors="pt")
25
+ print("prompt tokens:", enc.input_ids.shape)
26
+ print("prompt tail ids:", enc.input_ids[0, -8:].tolist())
27
+ print("prompt tail dec:", repr(tok.decode(enc.input_ids[0, -8:].tolist())))
28
+
29
+ # short generation so this is quick
30
+ x, st = ccd_decode.generate(
31
+ model, enc.input_ids.to("cuda"), attention_mask=enc.attention_mask.to("cuda"),
32
+ max_new_tokens=256, steps=256, temperature=0.1, top_p=0.9,
33
+ mask_token_id=model.config.mask_token_id, method="baseline")
34
+ gen = x[0, enc.input_ids.shape[1]:]
35
+ ids = gen.tolist()
36
+ print("\nfirst 24 generated ids:", ids[:24])
37
+ print("unique ids (count):", len(set(ids)))
38
+ from collections import Counter
39
+ print("most common ids:", Counter(ids).most_common(6))
40
+ print("\nRAW decode (no split), first 400 chars:")
41
+ print(repr(tok.decode(ids)[:400]))
42
+ print("\nDecode skip_special_tokens=True, first 400:")
43
+ print(repr(tok.decode(ids, skip_special_tokens=True)[:400]))
44
+ print("\neos_token:", repr(tok.eos_token), tok.eos_token_id)
45
+ print("split-on-eos result (first 200):", repr(tok.decode(ids).split(tok.eos_token)[0][:200]))
46
+ EOF