Eq20 budget diagnostics
Browse files- scripts/__pycache__/ccd_decode.cpython-312.pyc +0 -0
- scripts/__pycache__/run_eval.cpython-312.pyc +0 -0
- scripts/__pycache__/sanitize_utils.cpython-312.pyc +0 -0
- scripts/__pycache__/trip_metric.cpython-312.pyc +0 -0
- scripts/ccd_decode.py +7 -1
- scripts/check_propositions.py +182 -0
- scripts/job_diag.sh +32 -0
- scripts/job_main.sh +92 -0
- scripts/run_eval.py +4 -0
scripts/__pycache__/ccd_decode.cpython-312.pyc
ADDED
|
Binary file (12.3 kB). View file
|
|
|
scripts/__pycache__/run_eval.cpython-312.pyc
ADDED
|
Binary file (14.3 kB). View file
|
|
|
scripts/__pycache__/sanitize_utils.cpython-312.pyc
ADDED
|
Binary file (6.53 kB). View file
|
|
|
scripts/__pycache__/trip_metric.cpython-312.pyc
ADDED
|
Binary file (5.47 kB). View file
|
|
|
scripts/ccd_decode.py
CHANGED
|
@@ -134,7 +134,9 @@ def generate(
|
|
| 134 |
# sliding-window historical buffer: list of (positions[V], probs[V, |X|]),
|
| 135 |
# most recent last, at most `history_d` entries.
|
| 136 |
buffer = []
|
| 137 |
-
stats = {"steps": 0, "budgets": [], "fallbacks": 0
|
|
|
|
|
|
|
| 138 |
|
| 139 |
for i in range(steps):
|
| 140 |
mask_index = (x == mask_token_id)
|
|
@@ -178,6 +180,8 @@ def generate(
|
|
| 178 |
if len(ic_t) == 0:
|
| 179 |
# fallback -> baseline rule (Eq. 1)
|
| 180 |
stats["fallbacks"] += 1
|
|
|
|
|
|
|
| 181 |
k = min(b_t, num_mask)
|
| 182 |
sel = torch.topk(conf_cur, k).indices
|
| 183 |
x[0, mask_pos[sel]] = _pick_token(probs_cur[sel], temperature)
|
|
@@ -197,6 +201,8 @@ def generate(
|
|
| 197 |
# Sec. 4.2 stability heuristic standing in for H(p_bar) < eps
|
| 198 |
argmaxes = stacked.argmax(dim=-1)
|
| 199 |
stable.append(bool((argmaxes == argmaxes[0]).all()) and stacked.shape[0] > 1)
|
|
|
|
|
|
|
| 200 |
p_bar = torch.stack(p_bars, dim=0) # [|I^c_t|, |X|]
|
| 201 |
marg_conf = _neg_entropy(p_bar) # -H(p_bar)
|
| 202 |
ic_pos = torch.tensor(ic_t, device=device)
|
|
|
|
| 134 |
# sliding-window historical buffer: list of (positions[V], probs[V, |X|]),
|
| 135 |
# most recent last, at most `history_d` entries.
|
| 136 |
buffer = []
|
| 137 |
+
stats = {"steps": 0, "budgets": [], "fallbacks": 0,
|
| 138 |
+
# diagnostics: what actually gates the adaptive budget (Eq. 20)
|
| 139 |
+
"ic_sizes": [], "n_stable": []}
|
| 140 |
|
| 141 |
for i in range(steps):
|
| 142 |
mask_index = (x == mask_token_id)
|
|
|
|
| 180 |
if len(ic_t) == 0:
|
| 181 |
# fallback -> baseline rule (Eq. 1)
|
| 182 |
stats["fallbacks"] += 1
|
| 183 |
+
stats["ic_sizes"].append(0)
|
| 184 |
+
stats["n_stable"].append(0)
|
| 185 |
k = min(b_t, num_mask)
|
| 186 |
sel = torch.topk(conf_cur, k).indices
|
| 187 |
x[0, mask_pos[sel]] = _pick_token(probs_cur[sel], temperature)
|
|
|
|
| 201 |
# Sec. 4.2 stability heuristic standing in for H(p_bar) < eps
|
| 202 |
argmaxes = stacked.argmax(dim=-1)
|
| 203 |
stable.append(bool((argmaxes == argmaxes[0]).all()) and stacked.shape[0] > 1)
|
| 204 |
+
stats["ic_sizes"].append(len(ic_t))
|
| 205 |
+
stats["n_stable"].append(int(sum(stable)))
|
| 206 |
p_bar = torch.stack(p_bars, dim=0) # [|I^c_t|, |X|]
|
| 207 |
marg_conf = _neg_entropy(p_bar) # -H(p_bar)
|
| 208 |
ic_pos = torch.tensor(ic_t, device=device)
|
scripts/check_propositions.py
ADDED
|
@@ -0,0 +1,182 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Claim 2: numerically audit Proposition 1 and Proposition 2 of arXiv:2512.02044.
|
| 2 |
+
|
| 3 |
+
Everything here is exact discrete-probability arithmetic on small synthetic joints
|
| 4 |
+
p(x, c | s), so each statement is either verified to machine precision or refuted
|
| 5 |
+
with an explicit counterexample. No model needed.
|
| 6 |
+
|
| 7 |
+
Checks
|
| 8 |
+
------
|
| 9 |
+
P1a H(x|s) = H(x|c,s) + I(x;c|s) -- the identity in Eq. (10)
|
| 10 |
+
P1b I(x;c|s)=0 => CCD's marginal == the single-step distribution (Eq. 8 claim
|
| 11 |
+
that the method "naturally degrades to the existing single-context method")
|
| 12 |
+
P1c H(x|c,s) ~= H(x|c_.,i,s): the "sufficiently representative sample" step that
|
| 13 |
+
turns the identity into Eq. (8). Is a single context representative?
|
| 14 |
+
P2a Is the trajectory-averaged MI (1/(T-t+1)) sum_k I(x_i; c_{T-k,i}|s) equal to
|
| 15 |
+
I(x_i; x_-i|s)? Eq. (12) replaces the latter with the former under "~=".
|
| 16 |
+
P2b Does the replacement preserve the direction of the <= in Lemma 1?
|
| 17 |
+
P2c Does the sampler influence the RHS of the bound at all (the "governance" claim)?
|
| 18 |
+
"""
|
| 19 |
+
import numpy as np
|
| 20 |
+
import json, os
|
| 21 |
+
|
| 22 |
+
rng = np.random.default_rng(0)
|
| 23 |
+
EPS = 1e-12
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
def H(p):
|
| 27 |
+
p = np.asarray(p, dtype=float)
|
| 28 |
+
p = p[p > 0]
|
| 29 |
+
return float(-(p * np.log2(p)).sum())
|
| 30 |
+
|
| 31 |
+
|
| 32 |
+
def mutual_info(joint):
|
| 33 |
+
"""I(X;C) for a joint p(x,c) given as a [X, C] matrix."""
|
| 34 |
+
px = joint.sum(1)
|
| 35 |
+
pc = joint.sum(0)
|
| 36 |
+
return H(px) + H(pc) - H(joint.ravel())
|
| 37 |
+
|
| 38 |
+
|
| 39 |
+
def cond_entropy(joint):
|
| 40 |
+
"""H(X|C) = sum_c p(c) H(X|c)."""
|
| 41 |
+
pc = joint.sum(0)
|
| 42 |
+
tot = 0.0
|
| 43 |
+
for j, pcj in enumerate(pc):
|
| 44 |
+
if pcj > EPS:
|
| 45 |
+
tot += pcj * H(joint[:, j] / pcj)
|
| 46 |
+
return tot
|
| 47 |
+
|
| 48 |
+
|
| 49 |
+
results = {}
|
| 50 |
+
print("=" * 74)
|
| 51 |
+
print("PROPOSITION 1")
|
| 52 |
+
print("=" * 74)
|
| 53 |
+
|
| 54 |
+
# ---- P1a: the identity itself, over many random joints
|
| 55 |
+
worst = 0.0
|
| 56 |
+
for _ in range(2000):
|
| 57 |
+
nx, nc = rng.integers(2, 7), rng.integers(2, 7)
|
| 58 |
+
joint = rng.random((nx, nc)) ** rng.integers(1, 4)
|
| 59 |
+
joint /= joint.sum()
|
| 60 |
+
lhs = H(joint.sum(1)) # H(x|s)
|
| 61 |
+
rhs = cond_entropy(joint) + mutual_info(joint) # H(x|c,s) + I(x;c|s)
|
| 62 |
+
worst = max(worst, abs(lhs - rhs))
|
| 63 |
+
print(f"P1a H(x|s) == H(x|c,s) + I(x;c|s) max |LHS-RHS| over 2000 joints: {worst:.2e}")
|
| 64 |
+
print(" -> HOLDS exactly (textbook identity; the paper's proof in Eq. 9-10 is correct).")
|
| 65 |
+
results["P1a_max_abs_err"] = worst
|
| 66 |
+
results["P1a_verdict"] = "holds exactly"
|
| 67 |
+
|
| 68 |
+
# ---- P1b: degeneracy when x _||_ c
|
| 69 |
+
px = rng.random(6); px /= px.sum()
|
| 70 |
+
pc = rng.random(4); pc /= pc.sum()
|
| 71 |
+
indep = np.outer(px, pc)
|
| 72 |
+
mi = mutual_info(indep)
|
| 73 |
+
# CCD's marginal = average of p(x|c) over contexts; under independence every
|
| 74 |
+
# conditional equals px, so the average equals the single-step distribution.
|
| 75 |
+
avg = sum(pc[j] * (indep[:, j] / pc[j]) for j in range(4))
|
| 76 |
+
print(f"\nP1b independence: I(x;c|s) = {mi:.2e}; "
|
| 77 |
+
f"max|CCD_marginal - single_step| = {np.abs(avg - px).max():.2e}")
|
| 78 |
+
print(" -> HOLDS: with I=0 the marginalisation is a no-op, as the paper claims.")
|
| 79 |
+
results["P1b_verdict"] = "holds"
|
| 80 |
+
|
| 81 |
+
# ---- P1c: is one context "sufficiently representative"?
|
| 82 |
+
# Eq. (8) needs H(x|c,s) ~= H(x|c_.,i,s) for the *specific* decoding-time context.
|
| 83 |
+
gaps = []
|
| 84 |
+
for _ in range(2000):
|
| 85 |
+
nx, nc = 5, 4
|
| 86 |
+
joint = rng.random((nx, nc)) ** rng.integers(1, 5)
|
| 87 |
+
joint /= joint.sum()
|
| 88 |
+
pc = joint.sum(0)
|
| 89 |
+
per_ctx = np.array([H(joint[:, j] / pc[j]) for j in range(nc)])
|
| 90 |
+
gaps.append(per_ctx.max() - per_ctx.min())
|
| 91 |
+
gaps = np.array(gaps)
|
| 92 |
+
print(f"\nP1c spread of H(x|c=c_j,s) across contexts (bits): "
|
| 93 |
+
f"mean={gaps.mean():.3f} p95={np.percentile(gaps,95):.3f} max={gaps.max():.3f}")
|
| 94 |
+
print(" -> APPROXIMATION, not an identity. A single context is representative only")
|
| 95 |
+
print(" if the conditional entropy barely varies with c -- exactly the regime")
|
| 96 |
+
print(" where CCD would be unnecessary. Eq. (8)'s '∝' hides this.")
|
| 97 |
+
results["P1c_mean_entropy_spread_bits"] = float(gaps.mean())
|
| 98 |
+
results["P1c_verdict"] = "approximation, not identity"
|
| 99 |
+
|
| 100 |
+
print()
|
| 101 |
+
print("=" * 74)
|
| 102 |
+
print("PROPOSITION 2")
|
| 103 |
+
print("=" * 74)
|
| 104 |
+
|
| 105 |
+
# Build an explicit decoding trajectory. Context grows monotonically:
|
| 106 |
+
# c_k reveals the first k coordinates of x_-i. x_i is a deterministic-ish function
|
| 107 |
+
# of all of x_-i, so MI with the context grows as the trajectory proceeds.
|
| 108 |
+
n_bits = 4 # x_-i = 4 bits
|
| 109 |
+
xs = np.arange(2) # x_i in {0,1}
|
| 110 |
+
states = np.arange(2 ** n_bits)
|
| 111 |
+
p_state = rng.random(2 ** n_bits); p_state /= p_state.sum()
|
| 112 |
+
|
| 113 |
+
def bits(s):
|
| 114 |
+
return [(s >> b) & 1 for b in range(n_bits)]
|
| 115 |
+
|
| 116 |
+
# p(x_i = 1 | x_-i) = parity-ish with noise -> strong dependence on the FULL context
|
| 117 |
+
p_xi_given = np.array([0.5 + 0.45 * (-1) ** sum(bits(s)) for s in states])
|
| 118 |
+
|
| 119 |
+
def mi_with_prefix(k):
|
| 120 |
+
"""I(x_i ; c_k | s) where c_k = first k revealed bits of x_-i."""
|
| 121 |
+
if k == 0:
|
| 122 |
+
return 0.0
|
| 123 |
+
ctxs = 2 ** k
|
| 124 |
+
joint = np.zeros((2, ctxs))
|
| 125 |
+
for s in states:
|
| 126 |
+
c = s & ((1 << k) - 1)
|
| 127 |
+
joint[1, c] += p_state[s] * p_xi_given[s]
|
| 128 |
+
joint[0, c] += p_state[s] * (1 - p_xi_given[s])
|
| 129 |
+
return mutual_info(joint)
|
| 130 |
+
|
| 131 |
+
traj = [mi_with_prefix(k) for k in range(n_bits + 1)] # k=0..4 contexts
|
| 132 |
+
I_full = traj[-1] # I(x_i ; x_-i | s)
|
| 133 |
+
avg_traj = float(np.mean(traj))
|
| 134 |
+
|
| 135 |
+
print(f"P2a I(x_i; c_k|s) along the trajectory (k=0..{n_bits}): "
|
| 136 |
+
+ ", ".join(f"{v:.4f}" for v in traj))
|
| 137 |
+
print(f" I(x_i; x_-i|s) (the bound's true RHS term) = {I_full:.4f} bits")
|
| 138 |
+
print(f" trajectory average (Eq. 12's replacement) = {avg_traj:.4f} bits")
|
| 139 |
+
print(f" ratio avg/full = {avg_traj / I_full:.3f}")
|
| 140 |
+
print(" -> The average is STRICTLY SMALLER than the quantity it replaces.")
|
| 141 |
+
results["P2a_traj_mi"] = [float(v) for v in traj]
|
| 142 |
+
results["P2a_I_full"] = float(I_full)
|
| 143 |
+
results["P2a_avg_traj"] = avg_traj
|
| 144 |
+
results["P2a_ratio"] = float(avg_traj / I_full)
|
| 145 |
+
|
| 146 |
+
print(f"\nP2b Lemma 1 states E[KL] <= (G/T) * sum_i I(x_i; x_-i|s) + eps_train.")
|
| 147 |
+
print(f" Eq. (12) rewrites the RHS with the trajectory average under '~='.")
|
| 148 |
+
print(f" Since avg ({avg_traj:.4f}) < true ({I_full:.4f}), the rewritten RHS is")
|
| 149 |
+
print(f" smaller, so 'E[KL] <= (G/T) * sum_i avg_k I(x_i;c_k|s)' does NOT follow")
|
| 150 |
+
print(f" from Lemma 1. Replacing an upper bound's RHS by a strictly smaller")
|
| 151 |
+
print(f" quantity while keeping '<=' is invalid.")
|
| 152 |
+
print(f" The paper itself calls the average a 'lower-bound estimate' (Sec. 3.2,")
|
| 153 |
+
print(f" proof of Prop. 2) -- which is precisely the wrong direction for a bound.")
|
| 154 |
+
results["P2b_verdict"] = "invalid: replaces bound RHS with strictly smaller quantity, keeps <="
|
| 155 |
+
|
| 156 |
+
print(f"\nP2c Does the sampler move the RHS? RHS = (G/T) * sum_i I(x_i; x_-i|s) + eps_train.")
|
| 157 |
+
print(f" I(x_i; x_-i|s) is a property of the DATA distribution and eps_train of the")
|
| 158 |
+
print(f" trained model; neither depends on how tokens are selected. The only")
|
| 159 |
+
print(f" sampler-controlled term is T (number of iterations), and it appears as G/T:")
|
| 160 |
+
for T in (256, 128, 75):
|
| 161 |
+
print(f" T={T:4d} -> bound factor G/T = G/{T} = {1/T:.5f}*G "
|
| 162 |
+
f"({256/T:.2f}x looser than T=256)")
|
| 163 |
+
print(" -> CCD (fixed budget) leaves T unchanged, so it does not move the bound at all.")
|
| 164 |
+
print(" CCD-DS *reduces* T (256 -> ~75 on Trip Plan), which makes this bound")
|
| 165 |
+
print(" ~3.4x LOOSER. The theory therefore does not predict CCD-DS's measured")
|
| 166 |
+
print(" quality gain; if anything it points the other way.")
|
| 167 |
+
results["P2c_verdict"] = "RHS is sampler-independent except via G/T; CCD-DS loosens it ~3.4x"
|
| 168 |
+
|
| 169 |
+
print()
|
| 170 |
+
print("=" * 74)
|
| 171 |
+
print("SUMMARY")
|
| 172 |
+
print("=" * 74)
|
| 173 |
+
print("Prop 1 identity (Eq. 9-10) : CORRECT (exact, verified to 1e-15)")
|
| 174 |
+
print("Prop 1 single-context step (Eq. 8): APPROXIMATION stated as '∝'; unquantified")
|
| 175 |
+
print("Prop 2 (Eq. 12) : DOES NOT FOLLOW -- direction-of-inequality error")
|
| 176 |
+
print("Prop 2 'governs' the error bound : NOT SUPPORTED -- RHS is sampler-independent;")
|
| 177 |
+
print(" CCD-DS's fewer steps make the bound looser")
|
| 178 |
+
|
| 179 |
+
os.makedirs("outputs", exist_ok=True)
|
| 180 |
+
with open("outputs/propositions_check.json", "w") as f:
|
| 181 |
+
json.dump(results, f, indent=1)
|
| 182 |
+
print("\nwrote outputs/propositions_check.json")
|
scripts/job_diag.sh
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/bash
|
| 2 |
+
# Diagnose why CCD-DS shows no speedup: measure |I^c_t| and the stability rate
|
| 3 |
+
# that together decide Eq. (20)'s budget. 3 Trip examples only -- a few GPU minutes.
|
| 4 |
+
set -uo pipefail
|
| 5 |
+
pip install -q "transformers==4.46.2" "huggingface_hub<1.0" "datasets<4" "accelerate" 2>&1 | tail -1
|
| 6 |
+
python -c "
|
| 7 |
+
from huggingface_hub import snapshot_download
|
| 8 |
+
snapshot_download('ashishk1331/ccd-repro-code', repo_type='dataset', local_dir='/work')"
|
| 9 |
+
cd /work && mkdir -p outputs
|
| 10 |
+
|
| 11 |
+
python scripts/run_eval.py --task trip --method ccd_ds --limit 3 --out outputs/diag_ds.json
|
| 12 |
+
|
| 13 |
+
python - <<'EOF'
|
| 14 |
+
import json
|
| 15 |
+
import numpy as np
|
| 16 |
+
r = json.load(open("outputs/diag_ds.json"))
|
| 17 |
+
print("\n=============== Eq. (20) BUDGET DIAGNOSTICS ===============")
|
| 18 |
+
print(f"mean steps {r['mean_steps']:.1f} (uniform baseline = 256) speedup {r['speedup_vs_uniform']:.2f}x")
|
| 19 |
+
print(f"fallback steps (|I^c_t| = 0): {r['fallback_steps']}")
|
| 20 |
+
ic = np.array(sum(r["ic_sizes"], []))
|
| 21 |
+
st = np.array(sum(r["n_stable"], []))
|
| 22 |
+
bud = np.array(sum(r["budgets"], []))
|
| 23 |
+
print(f"\n|I^c_t| : mean={ic.mean():.2f} hist={np.bincount(ic, minlength=5)[:5]} (V=4)")
|
| 24 |
+
print(f"n_stable : mean={st.mean():.2f} hist={np.bincount(st, minlength=5)[:5]}")
|
| 25 |
+
print(f"budget : mean={bud.mean():.2f} hist={np.bincount(bud, minlength=5)[:5]}")
|
| 26 |
+
nz = ic > 0
|
| 27 |
+
print(f"\nAmong steps with |I^c_t|>0: mean |I^c_t| = {ic[nz].mean():.2f}, "
|
| 28 |
+
f"mean stable = {st[nz].mean():.2f}, stable fraction = {st[nz].sum()/ic[nz].sum():.3f}")
|
| 29 |
+
print("\nIf |I^c_t| is large but n_stable ~ 0, the argmax-stability heuristic is the")
|
| 30 |
+
print("bottleneck. If |I^c_t| itself is ~1, the top-V intersection is the bottleneck.")
|
| 31 |
+
print("===========================================================")
|
| 32 |
+
EOF
|
scripts/job_main.sh
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/bash
|
| 2 |
+
# Consolidated CCD reproduction run: all four empirical claims in ONE job so the
|
| 3 |
+
# 14GB model is downloaded and loaded once. Results are uploaded to the Hub after
|
| 4 |
+
# every config, so a timeout/cancel still preserves everything finished so far.
|
| 5 |
+
set -uo pipefail
|
| 6 |
+
pip install -q "transformers==4.46.2" "huggingface_hub<1.0" "datasets<4" "accelerate" 2>&1 | tail -1
|
| 7 |
+
|
| 8 |
+
python -c "
|
| 9 |
+
from huggingface_hub import snapshot_download
|
| 10 |
+
snapshot_download('ashishk1331/ccd-repro-code', repo_type='dataset', local_dir='/work')
|
| 11 |
+
"
|
| 12 |
+
cd /work
|
| 13 |
+
mkdir -p outputs
|
| 14 |
+
nvidia-smi --query-gpu=name,memory.total --format=csv
|
| 15 |
+
|
| 16 |
+
: "${N_TRIP:=60}"
|
| 17 |
+
: "${N_HE:=40}"
|
| 18 |
+
: "${N_ABL:=40}"
|
| 19 |
+
: "${N_TEMP:=25}"
|
| 20 |
+
|
| 21 |
+
push () { # upload whatever exists so far; never fail the job over an upload
|
| 22 |
+
python - <<'EOF' 2>&1 | tail -1 || true
|
| 23 |
+
from huggingface_hub import HfApi
|
| 24 |
+
HfApi().upload_folder(folder_path="outputs", path_in_repo="outputs",
|
| 25 |
+
repo_id="ashishk1331/ccd-repro-results", repo_type="dataset")
|
| 26 |
+
print("pushed")
|
| 27 |
+
EOF
|
| 28 |
+
}
|
| 29 |
+
|
| 30 |
+
run () { # run() <outfile> <args...>; skip if already done
|
| 31 |
+
out="outputs/$1"; shift
|
| 32 |
+
if [ -f "$out" ]; then echo "SKIP $out (exists)"; return; fi
|
| 33 |
+
echo "=========== RUN $out : $* ==========="
|
| 34 |
+
python scripts/run_eval.py "$@" --out "$out" || echo "!!!!! FAILED: $out"
|
| 35 |
+
push
|
| 36 |
+
}
|
| 37 |
+
|
| 38 |
+
python - <<'EOF'
|
| 39 |
+
# Make the job resumable: pull any results a previous attempt already finished,
|
| 40 |
+
# so a relaunch after a timeout/cancel never pays for the same config twice.
|
| 41 |
+
from huggingface_hub import HfApi, snapshot_download
|
| 42 |
+
api = HfApi()
|
| 43 |
+
api.create_repo('ashishk1331/ccd-repro-results', repo_type='dataset', exist_ok=True)
|
| 44 |
+
try:
|
| 45 |
+
snapshot_download('ashishk1331/ccd-repro-results', repo_type='dataset',
|
| 46 |
+
local_dir='/work/_prev')
|
| 47 |
+
import glob, shutil, os
|
| 48 |
+
n = 0
|
| 49 |
+
for f in glob.glob('/work/_prev/outputs/*.json'):
|
| 50 |
+
shutil.copy(f, '/work/outputs/'); n += 1
|
| 51 |
+
print(f'resumed {n} finished configs')
|
| 52 |
+
except Exception as e:
|
| 53 |
+
print('no previous results:', e)
|
| 54 |
+
EOF
|
| 55 |
+
|
| 56 |
+
############ Claim 3 — Trip Plan (paper: baseline 15.10 / CCD 16.93 / CCD-DS 19.01 @ 3.48x)
|
| 57 |
+
for m in baseline ccd ccd_ds; do
|
| 58 |
+
run "c3_trip_${m}.json" --task trip --method $m --limit $N_TRIP
|
| 59 |
+
done
|
| 60 |
+
|
| 61 |
+
############ Claim 4 — HumanEval (paper: 52.66 / 57.31 / 56.71 @ 3.04x)
|
| 62 |
+
for m in baseline ccd ccd_ds; do
|
| 63 |
+
run "c4_he_${m}.json" --task humaneval --method $m --limit $N_HE
|
| 64 |
+
done
|
| 65 |
+
|
| 66 |
+
############ Claim 5 — buffer-size ablation on the Trip City=3 subset
|
| 67 |
+
# The paper's "buffer size" axis is ambiguous: the buffer holds d iterations x
|
| 68 |
+
# top-V tokens. We sweep BOTH axes and report which (if either) reproduces the
|
| 69 |
+
# reported shape (accuracy peaking at 4; steps falling monotonically).
|
| 70 |
+
run "c5_abl_baseline.json" --task trip --method baseline --limit $N_ABL --num-cities 3
|
| 71 |
+
for d in 1 2 3 4 5 6; do
|
| 72 |
+
run "c5_abl_d${d}.json" --task trip --method ccd_ds --limit $N_ABL --num-cities 3 --history-d $d --buffer-V 4
|
| 73 |
+
done
|
| 74 |
+
for V in 1 2 3 5 6; do
|
| 75 |
+
run "c5_abl_V${V}.json" --task trip --method ccd_ds --limit $N_ABL --num-cities 3 --history-d 3 --buffer-V $V
|
| 76 |
+
done
|
| 77 |
+
|
| 78 |
+
############ Claim 6 — temperature robustness on HumanEval (temp 0.1 reuses Claim 4)
|
| 79 |
+
for t in 0.0 0.4 0.7 1.0; do
|
| 80 |
+
run "c6_he_baseline_t${t}.json" --task humaneval --method baseline --limit $N_TEMP --temperature $t
|
| 81 |
+
run "c6_he_ccd_ds_t${t}.json" --task humaneval --method ccd_ds --limit $N_TEMP --temperature $t
|
| 82 |
+
done
|
| 83 |
+
|
| 84 |
+
echo "=================== ALL DONE ==================="
|
| 85 |
+
python - <<'EOF'
|
| 86 |
+
import json, glob
|
| 87 |
+
for f in sorted(glob.glob("outputs/*.json")):
|
| 88 |
+
r = json.load(open(f))
|
| 89 |
+
print(f"{f.split('/')[-1]:28s} score={r['score']:6.2f} steps={r['mean_steps']:7.2f} "
|
| 90 |
+
f"speedup={r['speedup_vs_uniform']:5.2f}x n={r['n_examples']}")
|
| 91 |
+
EOF
|
| 92 |
+
push
|
scripts/run_eval.py
CHANGED
|
@@ -171,6 +171,7 @@ def main():
|
|
| 171 |
prompts = [humaneval_prompt(tok, d) for d in items]
|
| 172 |
|
| 173 |
responses, all_steps, all_budgets, n_fallback = [], [], [], 0
|
|
|
|
| 174 |
t0 = time.time()
|
| 175 |
for n, prompt in enumerate(prompts):
|
| 176 |
enc = tok(prompt, return_tensors="pt")
|
|
@@ -188,6 +189,8 @@ def main():
|
|
| 188 |
responses.append(text)
|
| 189 |
all_steps.append(st["steps"])
|
| 190 |
all_budgets.append(st["budgets"])
|
|
|
|
|
|
|
| 191 |
n_fallback += st["fallbacks"]
|
| 192 |
if n == 0:
|
| 193 |
print(f"--- example 0 response ---\n{text[:600]}\n---", flush=True)
|
|
@@ -213,6 +216,7 @@ def main():
|
|
| 213 |
"per_example_score": per_ex, "per_example_steps": all_steps,
|
| 214 |
"responses": responses,
|
| 215 |
"budgets": all_budgets,
|
|
|
|
| 216 |
}
|
| 217 |
os.makedirs(os.path.dirname(args.out) or ".", exist_ok=True)
|
| 218 |
with open(args.out, "w") as f:
|
|
|
|
| 171 |
prompts = [humaneval_prompt(tok, d) for d in items]
|
| 172 |
|
| 173 |
responses, all_steps, all_budgets, n_fallback = [], [], [], 0
|
| 174 |
+
all_ic, all_stable = [], []
|
| 175 |
t0 = time.time()
|
| 176 |
for n, prompt in enumerate(prompts):
|
| 177 |
enc = tok(prompt, return_tensors="pt")
|
|
|
|
| 189 |
responses.append(text)
|
| 190 |
all_steps.append(st["steps"])
|
| 191 |
all_budgets.append(st["budgets"])
|
| 192 |
+
all_ic.append(st["ic_sizes"])
|
| 193 |
+
all_stable.append(st["n_stable"])
|
| 194 |
n_fallback += st["fallbacks"]
|
| 195 |
if n == 0:
|
| 196 |
print(f"--- example 0 response ---\n{text[:600]}\n---", flush=True)
|
|
|
|
| 216 |
"per_example_score": per_ex, "per_example_steps": all_steps,
|
| 217 |
"responses": responses,
|
| 218 |
"budgets": all_budgets,
|
| 219 |
+
"ic_sizes": all_ic, "n_stable": all_stable,
|
| 220 |
}
|
| 221 |
os.makedirs(os.path.dirname(args.out) or ".", exist_ok=True)
|
| 222 |
with open(args.out, "w") as f:
|