Spaces:
Sleeping
Sleeping
Remove 'Why base-model gradients predict memorization' panel + dead helper code
Browse files
app.py
CHANGED
|
@@ -40,14 +40,6 @@ DIST = {ds: {"mem": LOOKUP[(LOOKUP.dataset == ds) & LOOKUP.memorized],
|
|
| 40 |
GREEN, RED = "#2e7d32", "#c62828" # generation highlight
|
| 41 |
MEMCLR, NONCLR = "#f58518", "#4c78a8" # memorized (orange) vs not-memorized (blue)
|
| 42 |
|
| 43 |
-
# Headline ablation result (paper: dedup, mean +/- std over 3 training seeds), demo datasets only.
|
| 44 |
-
HEADLINE = {
|
| 45 |
-
"FineWeb": {"text-only": (0.628, 0.011), "gradient-only": (0.994, 0.003), "all": (0.997, 0.002)},
|
| 46 |
-
"PG-19": {"text-only": (0.640, 0.035), "gradient-only": (0.998, 0.001), "all": (0.996, 0.003)},
|
| 47 |
-
"The Stack": {"text-only": (0.765, 0.001), "gradient-only": (0.965, 0.001), "all": (0.971, 0.001)},
|
| 48 |
-
"OpenWebMath": {"text-only": (0.837, 0.001), "gradient-only": (0.976, 0.002), "all": (0.992, 0.001)},
|
| 49 |
-
}
|
| 50 |
-
|
| 51 |
# ZeroGPU: place the base model on cuda at module level (a CUDA-emulation mode makes
|
| 52 |
# this valid at startup; a real GPU is attached only inside @spaces.GPU functions).
|
| 53 |
_ON_ZEROGPU = bool(os.environ.get("SPACES_ZERO_GPU"))
|
|
@@ -66,25 +58,6 @@ def _compute_features(text):
|
|
| 66 |
|
| 67 |
|
| 68 |
# ------------------------------- graphics ----------------------------------
|
| 69 |
-
def headline_figure():
|
| 70 |
-
tiers = ["text-only", "gradient-only", "all"]
|
| 71 |
-
colors = {"text-only": "#9aa0a6", "gradient-only": GREEN, "all": "#1f4e79"}
|
| 72 |
-
datasets = list(HEADLINE.keys())
|
| 73 |
-
x = np.arange(len(datasets)); w = 0.26
|
| 74 |
-
fig, ax = plt.subplots(figsize=(7.2, 3.6))
|
| 75 |
-
for i, t in enumerate(tiers):
|
| 76 |
-
vals = [HEADLINE[d][t][0] for d in datasets]
|
| 77 |
-
errs = [HEADLINE[d][t][1] for d in datasets]
|
| 78 |
-
ax.bar(x + (i - 1) * w, vals, w, yerr=errs, capsize=3, label=t, color=colors[t])
|
| 79 |
-
ax.set_xticks(x); ax.set_xticklabels(datasets)
|
| 80 |
-
ax.set_ylim(0.5, 1.02); ax.set_ylabel("ROC-AUC")
|
| 81 |
-
ax.set_title("Gradient-only features ≈ full model (mean ± std over 3 seeds)")
|
| 82 |
-
ax.axhline(0.5, color="k", lw=0.7, ls=":")
|
| 83 |
-
ax.legend(loc="lower right", ncol=3, fontsize=8, framealpha=0.9)
|
| 84 |
-
fig.tight_layout()
|
| 85 |
-
return fig
|
| 86 |
-
|
| 87 |
-
|
| 88 |
def dist_figure(feats, dataset):
|
| 89 |
"""Six panels: where this example's feature values fall relative to the memorized
|
| 90 |
and not-memorized populations of the chosen dataset. Model-free."""
|
|
@@ -187,19 +160,9 @@ fine-tuned model will memorize. **Explore** verifies this against ground truth o
|
|
| 187 |
a fresh fine-tuning run; **Score your own text** applies the same classifier to a passage you provide.
|
| 188 |
"""
|
| 189 |
|
| 190 |
-
WHY = """The classifier reads six features of the **base** model, measured **before** any fine-tuning.
|
| 191 |
-
Three come from a single gradient step on the sequence (**gradient norm** and the **one-step loss change**);
|
| 192 |
-
the rest are text and base-loss statistics. On the datasets shown here, the three **gradient-only** features
|
| 193 |
-
alone reach ROC-AUC 0.965–0.998, essentially matching the full feature set, while text-only features lag far
|
| 194 |
-
behind. (On conversational text, not shown here, the non-gradient features contribute more.)
|
| 195 |
-
"""
|
| 196 |
-
|
| 197 |
with gr.Blocks(title="Predicting Memorization Before Fine-Tuning") as demo:
|
| 198 |
gr.Markdown(INTRO)
|
| 199 |
with gr.Tab("Explore held-out examples"):
|
| 200 |
-
with gr.Accordion("Why base-model gradients predict memorization", open=False):
|
| 201 |
-
gr.Markdown(WHY)
|
| 202 |
-
gr.Plot(headline_figure())
|
| 203 |
gr.Markdown("Pick a real Pythia-1.4B fine-tuning sequence and compare the classifier's "
|
| 204 |
"pre-fine-tuning risk score with what the fine-tuned model actually generated.")
|
| 205 |
with gr.Row():
|
|
|
|
| 40 |
GREEN, RED = "#2e7d32", "#c62828" # generation highlight
|
| 41 |
MEMCLR, NONCLR = "#f58518", "#4c78a8" # memorized (orange) vs not-memorized (blue)
|
| 42 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 43 |
# ZeroGPU: place the base model on cuda at module level (a CUDA-emulation mode makes
|
| 44 |
# this valid at startup; a real GPU is attached only inside @spaces.GPU functions).
|
| 45 |
_ON_ZEROGPU = bool(os.environ.get("SPACES_ZERO_GPU"))
|
|
|
|
| 58 |
|
| 59 |
|
| 60 |
# ------------------------------- graphics ----------------------------------
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 61 |
def dist_figure(feats, dataset):
|
| 62 |
"""Six panels: where this example's feature values fall relative to the memorized
|
| 63 |
and not-memorized populations of the chosen dataset. Model-free."""
|
|
|
|
| 160 |
a fresh fine-tuning run; **Score your own text** applies the same classifier to a passage you provide.
|
| 161 |
"""
|
| 162 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 163 |
with gr.Blocks(title="Predicting Memorization Before Fine-Tuning") as demo:
|
| 164 |
gr.Markdown(INTRO)
|
| 165 |
with gr.Tab("Explore held-out examples"):
|
|
|
|
|
|
|
|
|
|
| 166 |
gr.Markdown("Pick a real Pythia-1.4B fine-tuning sequence and compare the classifier's "
|
| 167 |
"pre-fine-tuning risk score with what the fine-tuned model actually generated.")
|
| 168 |
with gr.Row():
|