claude-opus-4-8
nano-gpt-data-curation — graded by the task's verifier against a measured baseline.
- backend
- modal
- variant
- claude claude-opus-4-8
- metric
- held-out multi-domain perplexity
- actions
- 67
- duration
- 1h 1m
- recorded
- 2026-08-04
run iddclm-nano-curation__u8hwsKZ
Everything claude-opus-4-8 did on this task, in order.
download JSON ↗I'll start by understanding my environment, time budget, and the resources available.
args
{
"command": "cat /workspace/.timer/remaining_secs 2>/dev/null; echo \"---\"; ls -la /workspace/; echo \"---\"; ls -la /workspace/data/; echo \"---\"; ls -la /workspace/submission/ 2>/dev/null; echo \"---\"; nvidia-smi 2>/dev/null | head -20",
"description": "Check time budget and workspace layout"
}Bash result
5400
---
total 14
drwxr-xr-x 1 root root 100 Aug 4 03:22 .
drwxr-xr-x 1 root root 160 Aug 4 03:22 ..
drwxr-xr-x 1 root root 60 Aug 4 03:22 .live
drwxr-xr-x 1 root root 100 Aug 4 03:22 .metrics
drwxr-xr-x 1 root root 140 Aug 4 03:22 .timer
drwxr-xr-x 1 root root 57 Aug 3 22:37 data
-rwxrwxr-x 1 root root 714 Aug 3 22:34 dev_eval.sh
-rw-rw-r-- 1 root root 5706 Aug 3 22:34 model.py
-rw-rw-r-- 1 root root 869 Aug 3 22:34 pack_selection.py
drwxr-xr-x 1 root root 10 Aug 3 22:37 submission
-rwxrwxr-x 1 root root 1509 Aug 3 22:34 timer.sh
-rw-rw-r-- 1 root root 2962 Aug 3 22:34 train_nano.py
---
total 792657
drwxr-xr-x 1 root root 57 Aug 3 22:37 .
drwxr-xr-x 1 root root 100 Aug 4 03:22 ..
-r--r--r-- 1 root root 2000128 Aug 3 22:34 multi_dev.npy
-r--r--r-- 1 root root 809679384 Aug 3 22:35 pool.jsonl
---
total 1
drwxr-xr-x 1 root root 10 Aug 3 22:37 .
drwxr-xr-x 1 root root 100 Aug 4 03:22 ..
---
Tue Aug 4 03:22:58 2026
+-----------------------------------------------------------------------------------------+
| NVIDIA-SMI 580.95.05 Driver Version: 580.95.05 CUDA Version: 13.0 |
+-----------------------------------------+------------------------+----------------------+
| GPU Name Persistence-M | Bus-Id Disp.A | Volatile Uncorr. ECC |
| Fan Temp Perf Pwr:Usage/Cap | Memory-Usage | GPU-Util Compute M. |
| | | MIG M. |
|=========================================+========================+======================|
| 0 NVIDIA H100 80GB HBM3 On | 00000000:04:00.0 Off | 0 |
| N/A 40C P0 73W / 700W | 4MiB / 81559MiB | 0% Default |
| | | Disabled |
+-----------------------------------------+------------------------+----------------------+
+-----------------------------------------------------------------------------------------+
| Processes: |
| GPU GI CI PID Type Process name GPU Memory |
| ID ID Usage |
|=========================================================================================|
| No running processes found |
+-----------------------------------------------------------------------------------------+
[stdout]
5400
---
total 14
drwxr-xr-x 1 root root 100 Aug 4 03:22 .
drwxr-xr-x 1 root root 160 Aug 4 03:22 ..
drwxr-xr-x 1 root root 60 Aug 4 03:22 .live
drwxr-xr-x 1 root root 100 Aug 4 03:22 .metrics
drwxr-xr-x 1 root root 140 Aug 4 03:22 .timer
drwxr-xr-x 1 root root 57 Aug 3 22:37 data
-rwxrwxr-x 1 root root 714 Aug 3 22:34 dev_eval.sh
-rw-rw-r-- 1 root root 5706 Aug 3 22:34 model.py
-rw-rw-r-- 1 root root 869 Aug 3 22:34 pack_selection.py
drwxr-xr-x 1 root root 10 Aug 3 22:37 submission
-rwxrwxr-x 1 root root 1509 Aug 3 22:34 timer.sh
-rw-rw-r-- 1 root root 2962 Aug 3 22:34 train_nano.py
---
total 792657
drwxr-xr-x 1 root root 57 Aug 3 22:37 .
drwxr-xr-x 1 root root 100 Aug 4 03:22 ..
-r--r--r-- 1 root root 2000128 Aug 3 22:34 multi_dev.npy
-r--r--r-- 1 root root 809679384 Aug 3 22:35 pool.jsonl
---
total 1
drwxr-xr-x 1 root root 10 Aug 3 22:37 .
drwxr-xr-x 1 root root 100 Aug 4 03:22 ..
---
Tue Aug 4 03:22:58 2026
+-----------------------------------------------------------------------------------------+
| NVIDIA-SMI 580.95.05 Driver Version: 580.95.05 CUDA Version: 13.0 |
+-----------------------------------------+------------------------+----------------------+
| GPU Name Persistence-M | Bus-Id Disp.A | Volatile Uncorr. ECC |
| Fan Temp Perf Pwr:Usage/Cap | Memory-Usage | GPU-Util Compute M. |
| | | MIG M. |
|=========================================+========================+======================|
| 0 NVIDIA H100 80GB HBM3 On | 00000000:04:00.0 Off | 0 |
| N/A 40C P0 73W / 700W | 4MiB / 81559MiB | 0% Default |
| | | Disabled |
+-----------------------------------------+------------------------+----------------------+
+-----------------------------------------------------------------------------------------+
| Processes: |
| GPU GI CI PID Type Process name GPU Memory |
| ID ID Usage |
|=========================================================================================|
| No running processes found |
+-----------------------------------------------------------------------------------------+
[metadata] {"noOutputExpected": false}I have 90 minutes (5400s). Each training run is ~60s. Let me read the key files to understand the pipeline.
args
{
"command": "cd /workspace; echo \"=== train_nano.py ===\"; cat train_nano.py; echo; echo \"=== pack_selection.py ===\"; cat pack_selection.py; echo; echo \"=== dev_eval.sh ===\"; cat dev_eval.sh; echo; echo \"=== timer.sh ===\"; cat timer.sh",
"description": "Read training pipeline scripts"
}Bash result
=== train_nano.py ===
"""From-scratch nano-GPT (30M) LM training on a 1D token .npy; report held-out perplexity.
Frozen recipe — the ONLY thing that varies between runs is the training token set."""
import argparse, math, time, numpy as np, torch
from model import GPT, GPTConfig
ap = argparse.ArgumentParser()
ap.add_argument("--train_npy", required=True)
ap.add_argument("--heldout_npy", required=True)
ap.add_argument("--out_json", required=True)
ap.add_argument("--max_iters", type=int, default=3000)
ap.add_argument("--warmup", type=int, default=150)
ap.add_argument("--batch", type=int, default=32)
ap.add_argument("--block", type=int, default=256)
ap.add_argument("--lr", type=float, default=6e-4)
ap.add_argument("--seed", type=int, default=1337)
a = ap.parse_args()
torch.manual_seed(a.seed); np.random.seed(a.seed)
dev = "cuda"
tr = np.load(a.train_npy); ho = np.load(a.heldout_npy)
tr = torch.from_numpy(tr.astype(np.int64)); ho = torch.from_numpy(ho.astype(np.int64))
rng = np.random.default_rng(a.seed)
model = GPT(GPTConfig(block_size=a.block, vocab_size=50257, n_layer=6, n_head=6,
n_embd=384, dropout=0.0, bias=False)).to(dev)
opt = model.configure_optimizers(0.1, a.lr, (0.9, 0.95), "cuda")
def lr_at(it):
if it < a.warmup: return a.lr * (it + 1) / (a.warmup + 1)
r = (it - a.warmup) / max(1, a.max_iters - a.warmup)
return 0.1 * a.lr + 0.5 * (1 + math.cos(math.pi * r)) * (a.lr - 0.1 * a.lr)
def get_batch(src):
ix = rng.integers(0, len(src) - a.block - 1, size=a.batch)
x = torch.stack([src[i:i+a.block] for i in ix]).to(dev)
y = torch.stack([src[i+1:i+1+a.block] for i in ix]).to(dev)
return x, y
t0 = time.time()
model.train()
for it in range(a.max_iters):
for g in opt.param_groups: g["lr"] = lr_at(it)
x, y = get_batch(tr)
with torch.autocast("cuda", dtype=torch.bfloat16):
_, loss = model(x, y)
opt.zero_grad(set_to_none=True); loss.backward()
torch.nn.utils.clip_grad_norm_(model.parameters(), 1.0); opt.step()
train_s = time.time() - t0
# held-out perplexity: mean next-token CE over non-overlapping windows (window-weighted)
import json
model.eval()
nwin = (len(ho) - 1) // a.block
starts = [j * a.block for j in range(nwin)]
sum_loss, nseen = 0.0, 0
with torch.no_grad():
for i in range(0, nwin, a.batch):
bs = starts[i:i+a.batch]
x = torch.stack([ho[s:s+a.block] for s in bs]).to(dev)
y = torch.stack([ho[s+1:s+1+a.block] for s in bs]).to(dev)
with torch.autocast("cuda", dtype=torch.bfloat16):
_, l = model(x, y)
sum_loss += l.item() * len(bs); nseen += len(bs)
mean_loss = sum_loss / max(1, nseen)
ppl = math.exp(mean_loss)
out = {"train_npy": a.train_npy, "heldout_ppl": ppl, "mean_loss": mean_loss,
"max_iters": a.max_iters, "seed": a.seed, "train_s": round(train_s, 1)}
json.dump(out, open(a.out_json, "w"))
print(f"HELDOUT_PPL {ppl:.3f} loss {mean_loss:.4f} train_s {train_s:.0f} {a.train_npy}")
=== pack_selection.py ===
"""Solver-side: pack a selection.json (ordered ids) into a 12M-token train array from pool.jsonl."""
import json, sys, numpy as np
from transformers import AutoTokenizer
POOL = "/workspace/data/pool.jsonl"
SEL = sys.argv[1] if len(sys.argv) > 1 else "/workspace/submission/selection.json"
OUT = sys.argv[2] if len(sys.argv) > 2 else "/tmp/dev_train.npy"
BUDGET = 12_000_000
tok = AutoTokenizer.from_pretrained("gpt2"); EOS = tok.eos_token_id
text = {}
for line in open(POOL):
r = json.loads(line); text[r["id"]] = r["text"]
sel = json.load(open(SEL))
parts, tot = [], 0
for i in sel:
ids = tok(text[i], add_special_tokens=False).input_ids
parts.extend(ids); parts.append(EOS); tot += len(ids) + 1
if tot >= BUDGET: break
arr = np.array(parts[:BUDGET], dtype=np.uint16)
np.save(OUT, arr)
print(f"packed {len(arr)} tokens from {len(sel)} ids -> {OUT}")
=== dev_eval.sh ===
#!/bin/bash
# Diagnostic: train the frozen 30M GPT on your selection and report DEV perplexity.
# Usage: bash dev_eval.sh [selection.json] (default /workspace/submission/selection.json)
# NOTE: the official target is a DIFFERENT (hidden) sample from the same HQ domain.
set -euo pipefail
export TOKENIZERS_PARALLELISM=false
SEL="${1:-/workspace/submission/selection.json}"
cd /workspace
python3 pack_selection.py "$SEL" /tmp/dev_train.npy
python3 train_nano.py --train_npy /tmp/dev_train.npy --heldout_npy /workspace/data/multi_dev.npy \
--out_json /tmp/dev.json --max_iters 3000 --seed 1337 2>&1 | grep HELDOUT_PPL
echo "(dev PPL on multi_dev; official uses a hidden disjoint sample of the same HQ domain)"
=== timer.sh ===
#!/usr/bin/env bash
# Budget timer daemon — writes /workspace/.timer/remaining_secs every 10s so the
# solver can poll time left instead of doing wall-clock arithmetic.
#
# Budget (seconds) comes from $TASK_BUDGET_SECS (set by the runner to the agent
# timeout). Idempotent via a PID file. On ScaleTrain the trial runner starts its
# own timer; this file is the fallback for the Modal/local harbor backends, which
# bootstrap /workspace/timer.sh on environment start. The fallback default below
# (7200 = 2 h) matches this task's [agent] timeout_sec and is only used if
# $TASK_BUDGET_SECS is unset.
set -u
TIMER_DIR="/workspace/.timer"
PID_FILE="$TIMER_DIR/timer.pid"
mkdir -p "$TIMER_DIR"
if [ -s "$PID_FILE" ] && kill -0 "$(cat "$PID_FILE" 2>/dev/null)" 2>/dev/null; then
exit 0 # already running
fi
echo $$ > "$PID_FILE"
trap 'rm -f "$PID_FILE"' EXIT INT TERM
START=$(date +%s)
BUDGET="${TASK_BUDGET_SECS:-7200}"
echo "$START" > "$TIMER_DIR/start_epoch"
echo "$BUDGET" > "$TIMER_DIR/budget_secs"
while true; do
NOW=$(date +%s)
ELAPSED=$((NOW - START))
REMAINING=$((BUDGET - ELAPSED))
[ "$REMAINING" -lt 0 ] && REMAINING=0
echo "$REMAINING" > "$TIMER_DIR/remaining_secs"
echo "$ELAPSED" > "$TIMER_DIR/elapsed_secs"
[ "$REMAINING" -le 1800 ] && [ ! -f "$TIMER_DIR/alert_30min" ] && touch "$TIMER_DIR/alert_30min"
[ "$REMAINING" -le 600 ] && [ ! -f "$TIMER_DIR/alert_10min" ] && touch "$TIMER_DIR/alert_10min"
[ "$REMAINING" -le 0 ] && break
sleep 10
done
[stdout]
=== train_nano.py ===
"""From-scratch nano-GPT (30M) LM training on a 1D token .npy; report held-out perplexity.
Frozen recipe — the ONLY thing that varies between runs is the training token set."""
import argparse, math, time, numpy as np, torch
from model import GPT, GPTConfig
ap = argparse.ArgumentParser()
ap.add_argument("--train_npy", required=True)
ap.add_argument("--heldout_npy", required=True)
ap.add_argument("--out_json", required=True)
ap.add_argument("--max_iters", type=int, default=3000)
ap.add_argument("--warmup", type=int, default=150)
ap.add_argument("--batch", type=int, default=32)
ap.add_argument("--block", type=int, default=256)
ap.add_argument("--lr", type=float, default=6e-4)
ap.add_argument("--seed", type=int, default=1337)
a = ap.parse_args()
torch.manual_seed(a.seed); np.random.seed(a.seed)
dev = "cuda"
tr = np.load(a.train_npy); ho = np.load(a.heldout_npy)
tr = torch.from_numpy(tr.astype(np.int64)); ho = torch.from_numpy(ho.astype(np.int64))
rng = np.random.default_rng(a.seed)
model = GPT(GPTConfig(block_size=a.block, vocab_size=50257, n_layer=6, n_head=6,
n_embd=384, dropout=0.0, bias=False)).to(dev)
opt = model.configure_optimizers(0.1, a.lr, (0.9, 0.95), "cuda")
def lr_at(it):
if it < a.warmup: return a.lr * (it + 1) / (a.warmup + 1)
r = (it - a.warmup) / max(1, a.max_iters - a.warmup)
return 0.1 * a.lr + 0.5 * (1 + math.cos(math.pi * r)) * (a.lr - 0.1 * a.lr)
def get_batch(src):
ix = rng.integers(0, len(src) - a.block - 1, size=a.batch)
x = torch.stack([src[i:i+a.block] for i in ix]).to(dev)
y = torch.stack([src[i+1:i+1+a.block] for i in ix]).to(dev)
return x, y
t0 = time.time()
model.train()
for it in range(a.max_iters):
for g in opt.param_groups: g["lr"] = lr_at(it)
x, y = get_batch(tr)
with torch.autocast("cuda", dtype=torch.bfloat16):
_, loss = model(x, y)
opt.zero_grad(set_to_none=True); loss.backward()
torch.nn.utils.clip_grad_norm_(model.parameters(), 1.0); opt.step()
train_s = time.time() - t0
# held-out perplexity: mean next-token CE over non-overlapping windows (window-weighted)
import json
model.eval()
nwin = (len(ho) - 1) // a.block
starts = [j * a.block for j in range(nwin)]
sum_loss, nseen = 0.0, 0
with torch.no_grad():
for i in range(0, nwin, a.batch):
bs = starts[i:i+a.batch]
x = torch.stack([ho[s:s+a.block] for s in bs]).to(dev)
y = torch.stack([ho[s+1:s+1+a.block] for s in bs]).to(dev)
with torch.autocast("cuda", dtype=torch.bfloat16):
_, l = model(x, y)
sum_loss += l.item() * len(bs); nseen += len(bs)
mean_loss = sum_loss / max(1, nseen)
ppl = math.exp(mean_loss)
out = {"train_npy": a.train_npy, "heldout_ppl": ppl, "mean_loss": mean_loss,
"max_iters": a.max_iters, "seed": a.seed, "train_s": round(train_s, 1)}
json.dump(out, open(a.out_json, "w"))
print(f"HELDOUT_PPL {ppl:.3f} loss {mean_loss:.4f} train_s {train_s:.0f} {a.train_npy}")
=== pack_selection.py ===
"""Solver-side: pack a selection.json (ordered ids) into a 12M-token train array from pool.jsonl."""
import json, sys, numpy as np
from transformers import AutoTokenizer
POOL = "/workspace/data/pool.jsonl"
SEL = sys.argv[1] if len(sys.argv) > 1 else "/workspace/submission/selection.json"
OUT = sys.argv[2] if len(sys.argv) > 2 else "/tmp/dev_train.npy"
BUDGET = 12_000_000
tok = AutoTokenizer.from_pretrained("gpt2"); EOS = tok.eos_token_id
text = {}
for line in open(POOL):
r = json.loads(line); text[r["id"]] = r["text"]
sel = json.load(open(SEL))
parts, tot = [], 0
for i in sel:
ids = tok(text[i], add_special_tokens=False).input_ids
parts.extend(ids); parts.append(EOS); tot += len(ids) + 1
if tot >= BUDGET: break
arr = np.array(parts[:BUDGET], dtype=np.uint16)
np.save(OUT, arr)
print(f"packed {len(arr)} tokens from {len(sel)} ids -> {OUT}")
=== dev_eval.sh ===
#!/bin/bash
# Diagnostic: train the frozen 30M GPT on your selection and report DEV perplexity.
# Usage: bash dev_eval.sh [selection.json] (default /workspace/submission/selection.json)
# NOTE: the official target is a DIFFERENT (hidden) sample from the same HQ domain.
set -euo pipefail
export TOKENIZERS_PARALLELISM=false
SEL="${1:-/workspace/submission/selection.json}"
cd /workspace
python3 pack_selection.py "$SEL" /tmp/dev_train.npy
python3 train_nano.py --train_npy /tmp/dev_train.npy --heldout_npy /workspace/data/multi_dev.npy \
--out_json /tmp/dev.json --max_iters 3000 --seed 1337 2>&1 | grep HELDOUT_PPL
echo "(dev PPL on multi_dev; official uses a hidden disjoint sample of the same HQ domain)"
=== timer.sh ===
#!/usr/bin/env bash
# Budget timer daemon — writes /workspace/.timer/remaining_secs every 10s so the
# solver can poll time left instead of doing wall-clock arithmetic.
#
# Budget (seconds) comes from $TASK_BUDGET_SECS (set by the runner to the agent
# timeout). Idempotent via a PID file. On ScaleTrain the trial runner starts its
# own timer; this file is the fallback for the Modal/local harbor backends, which
# bootstrap /workspace/timer.sh on environment start. The fallback default below
# (7200 = 2 h) matches this task's [agent] timeout_sec and is only used if
# $TASK_BUDGET_SECS is unset.
set -u
TIMER_DIR="/workspace/.timer"
PID_FILE="$TIMER_DIR/timer.pid"
mkdir -p "$TIMER_DIR"
if [ -s "$PID_FILE" ] && kill -0 "$(cat "$PID_FILE" 2>/dev/null)" 2>/dev/null; then
exit 0 # already running
fi
echo $$ > "$PID_FILE"
trap 'rm -f "$PID_FILE"' EXIT INT TERM
START=$(date +%s)
BUDGET="${TASK_BUDGET_SECS:-7200}"
echo "$START" > "$TIMER_DIR/start_epoch"
echo "$BUDGET" > "$TIMER_DIR/budget_secs"
while true; do
NOW=$(date +%s)
ELAPSED=$((NOW - START))
REMAINING=$((BUDGET - ELAPSED))
[ "$REMAINING" -lt 0 ] && REMAINING=0
echo "$REMAINING" > "$TIMER_DIR/remaining_secs"
echo "$ELAPSED" > "$TIMER_DIR/elapsed_secs"
[ "$REMAINING" -le 1800 ] && [ ! -f "$TIMER_DIR/alert_30min" ] && touch "$TIMER_DIR/alert_30min"
[ "$REMAINING" -le 600 ] && [ ! -f "$TIMER_DIR/alert_10min" ] && touch "$TIMER_DIR/alert_10min"
[ "$REMAINING" -le 0 ] && break
sleep 10
done
[metadata] {"noOutputExpected": false}encrypted chain-of-thought — recorded, not exposed
args
{
"command": "cd /workspace; echo \"=== model.py ===\"; cat model.py; echo \"=== pool head (1 line, truncated) ===\"; head -c 1500 data/pool.jsonl; echo; echo \"=== line count ===\"; wc -l data/pool.jsonl",
"description": "Read model.py and inspect pool format"
}Bash result
=== model.py ===
"""A small GPT (decoder-only Transformer) used as the distillation *student*.
Self-contained re-implementation in this repo's own idiom (no external GPT code).
GPT-2 byte-level BPE vocabulary (50257) so the student shares the teacher's
tokenizer. Standard pre-norm Transformer with weight-tied embeddings.
"""
from dataclasses import dataclass
import math
import torch
import torch.nn as nn
import torch.nn.functional as F
@dataclass
class GPTConfig:
block_size: int = 256
vocab_size: int = 50257
n_layer: int = 6
n_head: int = 6
n_embd: int = 384
dropout: float = 0.0
bias: bool = False
class LayerNorm(nn.Module):
def __init__(self, ndim, bias):
super().__init__()
self.weight = nn.Parameter(torch.ones(ndim))
self.bias = nn.Parameter(torch.zeros(ndim)) if bias else None
def forward(self, x):
return F.layer_norm(x, self.weight.shape, self.weight, self.bias, 1e-5)
class CausalSelfAttention(nn.Module):
def __init__(self, cfg: GPTConfig):
super().__init__()
assert cfg.n_embd % cfg.n_head == 0
self.c_attn = nn.Linear(cfg.n_embd, 3 * cfg.n_embd, bias=cfg.bias)
self.c_proj = nn.Linear(cfg.n_embd, cfg.n_embd, bias=cfg.bias)
self.n_head = cfg.n_head
self.n_embd = cfg.n_embd
self.dropout = cfg.dropout
def forward(self, x):
B, T, C = x.size()
q, k, v = self.c_attn(x).split(self.n_embd, dim=2)
q = q.view(B, T, self.n_head, C // self.n_head).transpose(1, 2)
k = k.view(B, T, self.n_head, C // self.n_head).transpose(1, 2)
v = v.view(B, T, self.n_head, C // self.n_head).transpose(1, 2)
y = F.scaled_dot_product_attention(
q, k, v, dropout_p=self.dropout if self.training else 0.0, is_causal=True
)
y = y.transpose(1, 2).contiguous().view(B, T, C)
return self.c_proj(y)
class MLP(nn.Module):
def __init__(self, cfg: GPTConfig):
super().__init__()
self.c_fc = nn.Linear(cfg.n_embd, 4 * cfg.n_embd, bias=cfg.bias)
self.c_proj = nn.Linear(4 * cfg.n_embd, cfg.n_embd, bias=cfg.bias)
self.dropout = nn.Dropout(cfg.dropout)
def forward(self, x):
return self.dropout(self.c_proj(F.gelu(self.c_fc(x))))
class Block(nn.Module):
def __init__(self, cfg: GPTConfig):
super().__init__()
self.ln_1 = LayerNorm(cfg.n_embd, cfg.bias)
self.attn = CausalSelfAttention(cfg)
self.ln_2 = LayerNorm(cfg.n_embd, cfg.bias)
self.mlp = MLP(cfg)
def forward(self, x):
x = x + self.attn(self.ln_1(x))
x = x + self.mlp(self.ln_2(x))
return x
class GPT(nn.Module):
def __init__(self, cfg: GPTConfig):
super().__init__()
self.cfg = cfg
self.transformer = nn.ModuleDict(dict(
wte=nn.Embedding(cfg.vocab_size, cfg.n_embd),
wpe=nn.Embedding(cfg.block_size, cfg.n_embd),
drop=nn.Dropout(cfg.dropout),
h=nn.ModuleList([Block(cfg) for _ in range(cfg.n_layer)]),
ln_f=LayerNorm(cfg.n_embd, cfg.bias),
))
self.lm_head = nn.Linear(cfg.n_embd, cfg.vocab_size, bias=False)
self.transformer.wte.weight = self.lm_head.weight # weight tying
self.apply(self._init_weights)
# GPT-2 style scaled init on residual projections
for pn, p in self.named_parameters():
if pn.endswith('c_proj.weight'):
nn.init.normal_(p, mean=0.0, std=0.02 / math.sqrt(2 * cfg.n_layer))
def _init_weights(self, module):
if isinstance(module, nn.Linear):
nn.init.normal_(module.weight, mean=0.0, std=0.02)
if module.bias is not None:
nn.init.zeros_(module.bias)
elif isinstance(module, nn.Embedding):
nn.init.normal_(module.weight, mean=0.0, std=0.02)
def forward(self, idx, targets=None):
"""Return (logits, ce_loss). logits: [B, T, vocab]. ce_loss is the plain
next-token cross-entropy if `targets` given, else None. The distillation
loss is computed separately in kd_trainer.kd_loss."""
B, T = idx.size()
pos = torch.arange(0, T, dtype=torch.long, device=idx.device)
x = self.transformer.drop(self.transformer.wte(idx) + self.transformer.wpe(pos))
for block in self.transformer.h:
x = block(x)
x = self.transformer.ln_f(x)
logits = self.lm_head(x)
ce_loss = None
if targets is not None:
ce_loss = F.cross_entropy(
logits.view(-1, logits.size(-1)), targets.reshape(-1), ignore_index=-1
)
return logits, ce_loss
def configure_optimizers(self, weight_decay, lr, betas, device_type):
decay, no_decay = [], []
for n, p in self.named_parameters():
if not p.requires_grad:
continue
(decay if p.dim() >= 2 else no_decay).append(p)
groups = [
{'params': decay, 'weight_decay': weight_decay},
{'params': no_decay, 'weight_decay': 0.0},
]
fused = device_type == 'cuda'
return torch.optim.AdamW(groups, lr=lr, betas=betas, fused=fused)
@torch.no_grad()
def estimate_ppl(self, get_eval_batch, n_batches):
"""Mean per-token NLL over `n_batches` eval batches -> perplexity."""
was_training = self.training
self.eval()
losses = torch.zeros(n_batches)
for i in range(n_batches):
x, y = get_eval_batch()
_, loss = self(x, y)
losses[i] = loss.item()
if was_training:
self.train()
return math.exp(losses.mean().item())
=== pool head (1 line, truncated) ===
{"id": 0, "text": "|Viewing Single Post From: Spoilers for the Week of February 11th|\n|Lil||Feb 1 2013, 09:58 AM|\nDon't care about Chloe/Taniel/Jen-Jen. Don't care about Sami, really, but hoping that we get some good \"SAMANTHA GENE!!\" Marlena Death-Stares out of it. And \"newfound\" feelings. Please. If only.\nSTEFANO!! STEFANO, STEFANO, STEFANO!!!! :cheer:\n|Spoilers for the Week of February 11th \u00b7 DAYS: News, Spoilers & Discussion|"}
{"id": 1, "text": "*sigh* Fundamentalist community, let me pass on some advice to you I learned from the atheistic community:\nIf you have set yourself on fire, do not run.\nOkay? Okay?? Please?\nLook, D, you had two months to say to Harvard in private emails, \"Im sorry, I shouldnt have been using that animation in my paid presentations. I wont use it again. I really do like 'Inner Life', though, and would love to use it in classroom presentations, from the BioVisions site, if that is acceptable.\"\nI sat here, for two months, waiting for that to happen, anything to happen, and it didnt. Two months, on your own terms, you could have written a similar post to yesterdays. I would have given you the benefit of the doubt-- maybe you didnt know the credits werent visible to the audience, and I wouldnt have said a word beyond this, as its Harvards problem, not mine. This would have been a funny joke to those of us involved in dealing with you people, but it would have been a PR non-issue for you.\nBut after you set yourself on fire, you did
=== line count ===
182016 data/pool.jsonl
[stdout]
=== model.py ===
"""A small GPT (decoder-only Transformer) used as the distillation *student*.
Self-contained re-implementation in this repo's own idiom (no external GPT code).
GPT-2 byte-level BPE vocabulary (50257) so the student shares the teacher's
tokenizer. Standard pre-norm Transformer with weight-tied embeddings.
"""
from dataclasses import dataclass
import math
import torch
import torch.nn as nn
import torch.nn.functional as F
@dataclass
class GPTConfig:
block_size: int = 256
vocab_size: int = 50257
n_layer: int = 6
n_head: int = 6
n_embd: int = 384
dropout: float = 0.0
bias: bool = False
class LayerNorm(nn.Module):
def __init__(self, ndim, bias):
super().__init__()
self.weight = nn.Parameter(torch.ones(ndim))
self.bias = nn.Parameter(torch.zeros(ndim)) if bias else None
def forward(self, x):
return F.layer_norm(x, self.weight.shape, self.weight, self.bias, 1e-5)
class CausalSelfAttention(nn.Module):
def __init__(self, cfg: GPTConfig):
super().__init__()
assert cfg.n_embd % cfg.n_head == 0
self.c_attn = nn.Linear(cfg.n_embd, 3 * cfg.n_embd, bias=cfg.bias)
self.c_proj = nn.Linear(cfg.n_embd, cfg.n_embd, bias=cfg.bias)
self.n_head = cfg.n_head
self.n_embd = cfg.n_embd
self.dropout = cfg.dropout
def forward(self, x):
B, T, C = x.size()
q, k, v = self.c_attn(x).split(self.n_embd, dim=2)
q = q.view(B, T, self.n_head, C // self.n_head).transpose(1, 2)
k = k.view(B, T, self.n_head, C // self.n_head).transpose(1, 2)
v = v.view(B, T, self.n_head, C // self.n_head).transpose(1, 2)
y = F.scaled_dot_product_attention(
q, k, v, dropout_p=self.dropout if self.training else 0.0, is_causal=True
)
y = y.transpose(1, 2).contiguous().view(B, T, C)
return self.c_proj(y)
class MLP(nn.Module):
def __init__(self, cfg: GPTConfig):
super().__init__()
self.c_fc = nn.Linear(cfg.n_embd, 4 * cfg.n_embd, bias=cfg.bias)
self.c_proj = nn.Linear(4 * cfg.n_embd, cfg.n_embd, bias=cfg.bias)
self.dropout = nn.Dropout(cfg.dropout)
def forward(self, x):
return self.dropout(self.c_proj(F.gelu(self.c_fc(x))))
class Block(nn.Module):
def __init__(self, cfg: GPTConfig):
super().__init__()
self.ln_1 = LayerNorm(cfg.n_embd, cfg.bias)
self.attn = CausalSelfAttention(cfg)
self.ln_2 = LayerNorm(cfg.n_embd, cfg.bias)
self.mlp = MLP(cfg)
def forward(self, x):
x = x + self.attn(self.ln_1(x))
x = x + self.mlp(self.ln_2(x))
return x
class GPT(nn.Module):
def __init__(self, cfg: GPTConfig):
super().__init__()
self.cfg = cfg
self.transformer = nn.ModuleDict(dict(
wte=nn.Embedding(cfg.vocab_size, cfg.n_embd),
wpe=nn.Embedding(cfg.block_size, cfg.n_embd),
drop=nn.Dropout(cfg.dropout),
h=nn.ModuleList([Block(cfg) for _ in range(cfg.n_layer)]),
ln_f=LayerNorm(cfg.n_embd, cfg.bias),
))
self.lm_head = nn.Linear(cfg.n_embd, cfg.vocab_size, bias=False)
self.transformer.wte.weight = self.lm_head.weight # weight tying
self.apply(self._init_weights)
# GPT-2 style scaled init on residual projections
for pn, p in self.named_parameters():
if pn.endswith('c_proj.weight'):
nn.init.normal_(p, mean=0.0, std=0.02 / math.sqrt(2 * cfg.n_layer))
def _init_weights(self, module):
if isinstance(module, nn.Linear):
nn.init.normal_(module.weight, mean=0.0, std=0.02)
if module.bias is not None:
nn.init.zeros_(module.bias)
elif isinstance(module, nn.Embedding):
nn.init.normal_(module.weight, mean=0.0, std=0.02)
def forward(self, idx, targets=None):
"""Return (logits, ce_loss). logits: [B, T, vocab]. ce_loss is the plain
next-token cross-entropy if `targets` given, else None. The distillation
loss is computed separately in kd_trainer.kd_loss."""
B, T = idx.size()
pos = torch.arange(0, T, dtype=torch.long, device=idx.device)
x = self.transformer.drop(self.transformer.wte(idx) + self.transformer.wpe(pos))
for block in self.transformer.h:
x = block(x)
x = self.transformer.ln_f(x)
logits = self.lm_head(x)
ce_loss = None
if targets is not None:
ce_loss = F.cross_entropy(
logits.view(-1, logits.size(-1)), targets.reshape(-1), ignore_index=-1
)
return logits, ce_loss
def configure_optimizers(self, weight_decay, lr, betas, device_type):
decay, no_decay = [], []
for n, p in self.named_parameters():
if not p.requires_grad:
continue
(decay if p.dim() >= 2 else no_decay).append(p)
groups = [
{'params': decay, 'weight_decay': weight_decay},
{'params': no_decay, 'weight_decay': 0.0},
]
fused = device_type == 'cuda'
return torch.optim.AdamW(groups, lr=lr, betas=betas, fused=fused)
@torch.no_grad()
def estimate_ppl(self, get_eval_batch, n_batches):
"""Mean per-token NLL over `n_batches` eval batches -> perplexity."""
was_training = self.training
self.eval()
losses = torch.zeros(n_batches)
for i in range(n_batches):
x, y = get_eval_batch()
_, loss = self(x, y)
losses[i] = loss.item()
if was_training:
self.train()
return math.exp(losses.mean().item())
=== pool head (1 line, truncated) ===
{"id": 0, "text": "|Viewing Single Post From: Spoilers for the Week of February 11th|\n|Lil||Feb 1 2013, 09:58 AM|\nDon't care about Chloe/Taniel/Jen-Jen. Don't care about Sami, really, but hoping that we get some good \"SAMANTHA GENE!!\" Marlena Death-Stares out of it. And \"newfound\" feelings. Please. If only.\nSTEFANO!! STEFANO, STEFANO, STEFANO!!!! :cheer:\n|Spoilers for the Week of February 11th \u00b7 DAYS: News, Spoilers & Discussion|"}
{"id": 1, "text": "*sigh* Fundamentalist community, let me pass on some advice to you I learned from the atheistic community:\nIf you have set yourself on fire, do not run.\nOkay? Okay?? Please?\nLook, D, you had two months to say to Harvard in private emails, \"Im sorry, I shouldnt have been using that animation in my paid presentations. I wont use it again. I really do like 'Inner Life', though, and would love to use it in classroom presentations, from the BioVisions site, if that is acceptable.\"\nI sat here, for two months, waiting for that to happen, anything to happen, and it didnt. Two months, on your own terms, you could have written a similar post to yesterdays. I would have given you the benefit of the doubt-- maybe you didnt know the credits werent visible to the audience, and I wouldnt have said a word beyond this, as its Harvards problem, not mine. This would have been a funny joke to those of us involved in dealing with you people, but it would have been a PR non-issue for you.\nBut after you set yourself on fire, you did
=== line count ===
182016 data/pool.jsonl
[metadata] {"noOutputExpected": false}I have 90 min and ~60s/run. Let me inspect the dev target (my key signal) and understand token/text scale.
args
{
"command": "cd /workspace; python3 -c \"\nimport numpy as np\nfrom transformers import AutoTokenizer\ntok = AutoTokenizer.from_pretrained('gpt2')\na = np.load('data/multi_dev.npy')\nprint('dev shape', a.shape, 'dtype', a.dtype, 'min', a.min(), 'max', a.max())\neos = tok.eos_token_id\nprint('EOS id', eos, 'count of EOS in dev:', int((a==eos).sum()))\n# decode first 1200 tokens\nprint('==== decoded sample (first 1500 chars) ====')\nprint(tok.decode(a[:400].tolist())[:1500])\nprint('==== another slice ====')\nprint(tok.decode(a[500000:500400].tolist())[:1500])\n\"\n",
"description": "Decode dev target to inspect domain"
}Bash result
dev shape (1000000,) dtype uint16 min 0 max 50256
EOS id 50256 count of EOS in dev: 2704
==== decoded sample (first 1500 chars) ====
Beardmore was sufficiently impressed with Shackleton to offer financial support , but other donations proved hard to come by . Nevertheless , in February 1907 , Shackleton presented to the Royal Geographic Society his plans for an Antarctic expedition , the details of which , under the name British Antarctic Expedition , were published in the Royal Society 's newsletter , Geographic Journal . The aim was the conquest of both the geographical South Pole and the South Magnetic Pole . Shackleton then worked hard to persuade others of his wealthy friends and acquaintances to contribute , including Sir Philip Lee Brocklehurst , who subscribed £ 2 @,@ 000 ( 2011 equivalent £ 157 @,@ 000 ) to secure a place on the expedition ; author Campbell Mackellar ; and Guinness baron Lord Iveagh , whose contribution was secured less than two weeks before the departure of the expedition ship Nimrod . On 4 August 1907 , Shackleton was appointed a Member of the Royal Victorian Order , 4th Class ( MVO ; the present @-@ day grade of Lieutenant ) .
<|endoftext|> On 1 January 1908 , Nimrod sailed for the Antarctic from Lyttelton Harbour , New Zealand . Shackleton 's original plans had envisaged using the old Discovery base in McMurdo Sound to launch his attempts on the South Pole and South Magnetic Pole . However , before leaving England , he had been pressured to give an undertaking to Scott that he would not base himself in the McMurdo area , which Scott was claiming as his own field of work . Sh
==== another slice ====
I fucking hate when he does this shit pic.twitter.com/kpmcHnW4Cz — Miley Ray Cyrus (@MileyCyrus) April 22, 2018
Singer-actress Miley Cyrus has shared a rare video of herself with her partner, actor Liam Hemsworth, on social media. She shared a video of them both in a car, which showed Hemsworth listening to rap music as he drove them to their destination.Cyrus captioned the image: "I f***ing hate it when he does this s**t."In the clip, she was sporting a top which had the word 'Sunday' emblazoned across the front as she sat in the passenger seat. With his music blaring out, she filmed herself dancing and bopping her head to the music. Then all of a sudden, he made Cyrus jump as he suddenly screamed at her, causing to drop her phone in panic.(With IANS inputs)<|endoftext|>Uttar Pradesh chief minister Yogi Adityanath has maintained that 63 children in government-run Gorakhpur hospital died because of their ailments and not oxygen shortage, but grieving parents say their children were fine till the oxygen supply was cut.Some like Mohd Zahid, father of a five-year-old, alleged that BRD hospital authorities refused to declare their children dead, even as their bodies had turned ice cold as this would have further taken up the death toll.Another father said that while his son started bleeding from the nose, the hospital staff dismissed it saying, “Kachra nikal raha hai” (It’s just body waste that is coming out).In a harrowing tragedy exposing the sorry state of medical facilities i
[stdout]
dev shape (1000000,) dtype uint16 min 0 max 50256
EOS id 50256 count of EOS in dev: 2704
==== decoded sample (first 1500 chars) ====
Beardmore was sufficiently impressed with Shackleton to offer financial support , but other donations proved hard to come by . Nevertheless , in February 1907 , Shackleton presented to the Royal Geographic Society his plans for an Antarctic expedition , the details of which , under the name British Antarctic Expedition , were published in the Royal Society 's newsletter , Geographic Journal . The aim was the conquest of both the geographical South Pole and the South Magnetic Pole . Shackleton then worked hard to persuade others of his wealthy friends and acquaintances to contribute , including Sir Philip Lee Brocklehurst , who subscribed £ 2 @,@ 000 ( 2011 equivalent £ 157 @,@ 000 ) to secure a place on the expedition ; author Campbell Mackellar ; and Guinness baron Lord Iveagh , whose contribution was secured less than two weeks before the departure of the expedition ship Nimrod . On 4 August 1907 , Shackleton was appointed a Member of the Royal Victorian Order , 4th Class ( MVO ; the present @-@ day grade of Lieutenant ) .
<|endoftext|> On 1 January 1908 , Nimrod sailed for the Antarctic from Lyttelton Harbour , New Zealand . Shackleton 's original plans had envisaged using the old Discovery base in McMurdo Sound to launch his attempts on the South Pole and South Magnetic Pole . However , before leaving England , he had been pressured to give an undertaking to Scott that he would not base himself in the McMurdo area , which Scott was claiming as his own field of work . Sh
==== another slice ====
I fucking hate when he does this shit pic.twitter.com/kpmcHnW4Cz — Miley Ray Cyrus (@MileyCyrus) April 22, 2018
Singer-actress Miley Cyrus has shared a rare video of herself with her partner, actor Liam Hemsworth, on social media. She shared a video of them both in a car, which showed Hemsworth listening to rap music as he drove them to their destination.Cyrus captioned the image: "I f***ing hate it when he does this s**t."In the clip, she was sporting a top which had the word 'Sunday' emblazoned across the front as she sat in the passenger seat. With his music blaring out, she filmed herself dancing and bopping her head to the music. Then all of a sudden, he made Cyrus jump as he suddenly screamed at her, causing to drop her phone in panic.(With IANS inputs)<|endoftext|>Uttar Pradesh chief minister Yogi Adityanath has maintained that 63 children in government-run Gorakhpur hospital died because of their ailments and not oxygen shortage, but grieving parents say their children were fine till the oxygen supply was cut.Some like Mohd Zahid, father of a five-year-old, alleged that BRD hospital authorities refused to declare their children dead, even as their bodies had turned ice cold as this would have further taken up the death toll.Another father said that while his son started bleeding from the nose, the hospital staff dismissed it saying, “Kachra nikal raha hai” (It’s just body waste that is coming out).In a harrowing tragedy exposing the sorry state of medical facilities i
[metadata] {"noOutputExpected": false}Target = broad HQ mix: Wikipedia (WikiText-103 style), news, web prose. This decoded target text is my key supervision signal. Let me profile pool load time and token statistics.
args
{
"command": "cd /workspace; cat /workspace/.timer/remaining_secs; python3 -c \"\nimport json, time, numpy as np\nt=time.time()\nlens=[]; ids=[]; nchar=[]\nwith open('data/pool.jsonl') as f:\n for line in f:\n r=json.loads(line)\n nchar.append(len(r['text']))\n ids.append(r['id'])\nprint('load+parse pool: %.1fs, n=%d'%(time.time()-t, len(ids)))\nnchar=np.array(nchar)\nprint('char len: min %d p10 %d p50 %d p90 %d max %d mean %.0f'%(nchar.min(),np.percentile(nchar,10),np.percentile(nchar,50),np.percentile(nchar,90),nchar.max(),nchar.mean()))\nprint('id range', min(ids), max(ids), 'contiguous?', sorted(ids)==list(range(len(ids))))\n# rough token estimate: chars/4\nprint('est total tokens (chars/4): %.1fM'%(nchar.sum()/4/1e6))\nprint('docs with <200 chars:', int((nchar<200).sum()), ' <500:', int((nchar<500).sum()))\n\"\n",
"description": "Profile pool load and length stats"
}Bash result
5290
load+parse pool: 4.0s, n=182016
char len: min 2 p10 561 p50 2246 p90 8458 max 522573 mean 4233
id range 0 182015 contiguous? True
est total tokens (chars/4): 192.6M
docs with <200 chars: 2151 <500: 14496
[stdout]
5290
load+parse pool: 4.0s, n=182016
char len: min 2 p10 561 p50 2246 p90 8458 max 522573 mean 4233
id range 0 182015 contiguous? True
est total tokens (chars/4): 192.6M
docs with <200 chars: 2151 <500: 14496
[metadata] {"noOutputExpected": false}Pool loads fast (4s), contiguous ids 0–182K, ~193M tokens total. Now let me verify sklearn availability and check the target's WikiText formatting artifacts that I'll need to normalize.
args
{
"command": "cd /workspace; python3 -c \"import sklearn; print('sklearn', sklearn.__version__)\"; python3 -c \"\nimport numpy as np\nfrom transformers import AutoTokenizer\ntok=AutoTokenizer.from_pretrained('gpt2')\na=np.load('data/multi_dev.npy')\neos=50256\n# split into docs on EOS\nidx=np.where(a==eos)[0]\nprint('num dev docs (EOS-split):', len(idx)+1)\n# sample a few different regions to see domain variety -> look for tech Q&A\nfor s in [200000, 700000, 900000]:\n print('==== region',s,'====')\n print(tok.decode(a[s:s+250].tolist())[:900])\n print()\n\"\n",
"description": "Check sklearn and sample more target regions"
}Bash result
Traceback (most recent call last):
File "<string>", line 1, in <module>
ModuleNotFoundError: No module named 'sklearn'
num dev docs (EOS-split): 2705
==== region 200000 ====
it followed the southern end of the Lodge Freeway . By the middle of 1961 , the Watervliet – Paw Paw and Jackson – Ann Arbor freeway gaps were completed , and the freeway was extended westward to Stevensville ; By the end of the year , I @-@ 94 / US 12 extended all the way to New Buffalo . In January 1962 , the state made the biggest rerouting change of all to US 12 : the designation was removed from the I @-@ 94 freeway from New Buffalo to Detroit and shifted to completely replace US 112 .
<|endoftext|> In 1925 , US 112 was originally proposed to run from Oshkosh to Fremont , Wisconsin , on what later became U.S. Route 110 . When it was initially designated in November 1926 , US 112 made a sharp turn to the southwest to connect to US 20 in Elkhart , Indiana . In 1931 , a new trunkline highway was designated between M @-@ 60 at Niles and US 112 at Union . This highway was numbered M @-
==== region 700000 ====
But what we do know and understand perhaps is that we’re at a loss - a loss of a consolidated identity, a loss of a conscience binding the Sindhis together, a loss of oneness as our mother tongue fades away and a loss of our history as nearly all from migrant population burns to ashes.If one’s well-acquainted with partition memoirs, they’d know that unlike experiences of Punjab, Bihar and Bengal (to a certain extent), the case of Sindh consists of relatively fewer episodes of violence and bloodshed and more of internal distress and the pains of losses. Hindu Sindhis, in entirety, left their homeland behind and moved to an unknown Indian land with a sheer inability to relocate on the new soil due to a lack of a consolidated linguistic state. Zar, zameen, zoru - roughly translating to wealth, land and wife - sum up the major torments of the Sindhi refugee or rather, a Sindhi displaced.Whil
==== region 900000 ====
application (not an applet) that needs to access a web service. Proxies for the web service have been generated with JAX-WS, and seem to work fine. In one scenario it needs to talk through a web proxy server (actually Squid 3.0), which is set to require NTLM authentication.</p>
<p>Running on Sun's JRE 1.6.0_14, everything works fine for accessing HTTP URLs, without requiring any changes: the built-in NTLM authenticator kicks in and it all works seemlessly. If, however, the web service URL is a HTTPS URL, the web service call fails deep inside Sun's code:</p>
<pre><code>com.sun.xml.internal.ws.client.ClientTransportException: HTTP transport error: java.lang.NullPointerException
at com.sun.xml.internal.ws.transport.http.client.HttpClientTransport.getOutput(HttpClientTransport.java:121)
at com.sun.xml.internal.ws.transport.http.client.
[stdout]
Traceback (most recent call last):
File "<string>", line 1, in <module>
ModuleNotFoundError: No module named 'sklearn'
num dev docs (EOS-split): 2705
==== region 200000 ====
it followed the southern end of the Lodge Freeway . By the middle of 1961 , the Watervliet – Paw Paw and Jackson – Ann Arbor freeway gaps were completed , and the freeway was extended westward to Stevensville ; By the end of the year , I @-@ 94 / US 12 extended all the way to New Buffalo . In January 1962 , the state made the biggest rerouting change of all to US 12 : the designation was removed from the I @-@ 94 freeway from New Buffalo to Detroit and shifted to completely replace US 112 .
<|endoftext|> In 1925 , US 112 was originally proposed to run from Oshkosh to Fremont , Wisconsin , on what later became U.S. Route 110 . When it was initially designated in November 1926 , US 112 made a sharp turn to the southwest to connect to US 20 in Elkhart , Indiana . In 1931 , a new trunkline highway was designated between M @-@ 60 at Niles and US 112 at Union . This highway was numbered M @-
==== region 700000 ====
But what we do know and understand perhaps is that we’re at a loss - a loss of a consolidated identity, a loss of a conscience binding the Sindhis together, a loss of oneness as our mother tongue fades away and a loss of our history as nearly all from migrant population burns to ashes.If one’s well-acquainted with partition memoirs, they’d know that unlike experiences of Punjab, Bihar and Bengal (to a certain extent), the case of Sindh consists of relatively fewer episodes of violence and bloodshed and more of internal distress and the pains of losses. Hindu Sindhis, in entirety, left their homeland behind and moved to an unknown Indian land with a sheer inability to relocate on the new soil due to a lack of a consolidated linguistic state. Zar, zameen, zoru - roughly translating to wealth, land and wife - sum up the major torments of the Sindhi refugee or rather, a Sindhi displaced.Whil
==== region 900000 ====
application (not an applet) that needs to access a web service. Proxies for the web service have been generated with JAX-WS, and seem to work fine. In one scenario it needs to talk through a web proxy server (actually Squid 3.0), which is set to require NTLM authentication.</p>
<p>Running on Sun's JRE 1.6.0_14, everything works fine for accessing HTTP URLs, without requiring any changes: the built-in NTLM authenticator kicks in and it all works seemlessly. If, however, the web service URL is a HTTPS URL, the web service call fails deep inside Sun's code:</p>
<pre><code>com.sun.xml.internal.ws.client.ClientTransportException: HTTP transport error: java.lang.NullPointerException
at com.sun.xml.internal.ws.transport.http.client.HttpClientTransport.getOutput(HttpClientTransport.java:121)
at com.sun.xml.internal.ws.transport.http.client.
[metadata] {"noOutputExpected": false}No sklearn, but I have torch/numpy/transformers. Confirmed all 4 registers in target (Wikipedia highways, web essay, StackOverflow HTML Q&A, news). Let me measure GPT-2 tokenization throughput on the pool — tokenizing gives me both features and exact token counts.
args
{
"command": "cd /workspace; export TOKENIZERS_PARALLELISM=true; python3 -c \"\nimport json, time\nfrom transformers import AutoTokenizer\ntok=AutoTokenizer.from_pretrained('gpt2')\ntexts=[]\nwith open('data/pool.jsonl') as f:\n for i,line in enumerate(f):\n if i>=3000: break\n texts.append(json.loads(line)['text'])\nt=time.time()\nenc=tok(texts, add_special_tokens=False)\ndt=time.time()-t\nntok=sum(len(x) for x in enc.input_ids)\nprint('tokenized %d docs, %d tokens in %.2fs -> %.0f docs/s, %.2fM tok/s'%(len(texts),ntok,dt,len(texts)/dt,ntok/dt/1e6))\nprint('=> full pool est: %.0fs for 182016 docs'%(182016/(len(texts)/dt)))\n\"\n",
"description": "Measure GPT-2 tokenization throughput"
}Bash result
Token indices sequence length is longer than the specified maximum sequence length for this model (1048 > 1024). Running this sequence through the model will result in indexing errors
tokenized 3000 docs, 2086327 tokens in 0.94s -> 3202 docs/s, 2.23M tok/s
=> full pool est: 57s for 182016 docs
[stdout]
Token indices sequence length is longer than the specified maximum sequence length for this model (1048 > 1024). Running this sequence through the model will result in indexing errors
tokenized 3000 docs, 2086327 tokens in 0.94s -> 3202 docs/s, 2.23M tok/s
=> full pool est: 57s for 182016 docs
[metadata] {"noOutputExpected": false}Tokenizing the whole pool takes ~57s and gives me integer arrays for fast vectorized featurization plus exact token counts. My plan: DSIR-style importance selection — score each pool doc by mean per-token log(p_target / p_pool) under a hashed n-gram bag-of-words model, where p_target comes from the decoded dev target and p_pool from the whole pool. This is a standard, publishable criterion. Let me set up task tracking and write the curation script.
args
{
"subject": "Write curate.py (DSIR-style importance selection)",
"description": "Tokenize pool, build unigram+bigram log-odds (target vs pool background), score & rank docs, write selection.json",
"activeForm": "Writing curate.py"
}TaskCreate result
Task #1 created successfully: Write curate.py (DSIR-style importance selection)
[metadata] {"task": {"id": "1", "subject": "Write curate.py (DSIR-style importance selection)"}}encrypted chain-of-thought — recorded, not exposed
args
{
"subject": "Validate selection vs random baseline via dev_eval",
"description": "Run dev_eval.sh on curated selection and on a random baseline; compare held-out PPL on multi_dev",
"activeForm": "Validating selection with dev_eval"
}TaskCreate result
Task #2 created successfully: Validate selection vs random baseline via dev_eval
[metadata] {"task": {"id": "2", "subject": "Validate selection vs random baseline via dev_eval"}}encrypted chain-of-thought — recorded, not exposed
args
{
"subject": "Write claim.md deliverable",
"description": "Hypothesis / Mechanism (observable prediction) / Falsification / Transfer",
"activeForm": "Writing claim.md"
}TaskCreate result
Task #3 created successfully: Write claim.md deliverable
[metadata] {"task": {"id": "3", "subject": "Write claim.md deliverable"}}encrypted chain-of-thought — recorded, not exposed
args
{
"taskId": "1",
"status": "in_progress"
}TaskUpdate result
Updated task #1 status
[metadata] {"success": true, "taskId": "1", "updatedFields": ["status"], "statusChange": {"from": "pending", "to": "in_progress"}}encrypted chain-of-thought — recorded, not exposed
args
{
"file_path": "/workspace/submission/curate.py",
"content": "\"\"\"Curate a pretraining subset from a raw web pool by DSIR-style importance ranking.\n\nCriterion (stated, reproducible):\n Score each pool document by its mean per-token log importance weight\n s(doc) = (1/N) * sum_t log p_target(t-gram) - log p_pool(t-gram)\n under a bag-of-n-grams model (unigrams + hashed bigrams). p_target is estimated\n from the disclosed broad multi-domain HQ target (data/multi_dev.npy, GPT-2\n tokens); p_pool is estimated from the whole pool (the background distribution).\n Documents whose token distribution looks more like the HQ target than like the\n average web page get a higher score. We keep documents above a small length\n floor, drop exact duplicates, and emit ids in descending score order (best\n first) until we cover several times the 12M-token training budget.\n\nThis is Data Selection via Importance Resampling (Xie et al. 2023), greedy\ntop-k variant, with the target = the disclosed evaluation domain.\n\nNo labels, no internet: the only supervision is the disclosed target token stream.\n\"\"\"\nimport json, time, numpy as np\nfrom transformers import AutoTokenizer\n\nPOOL = \"/workspace/data/pool.jsonl\"\nDEV = \"/workspace/data/multi_dev.npy\"\nOUT = \"/workspace/submission/selection.json\"\n\nEOS = 50256\nV = 50257 # GPT-2 vocab\nDB = 1 << 20 # hashed bigram buckets\nALPHA = 0.1 # additive smoothing\nMIN_TOK = 100 # length floor: drop fragments\nLAMBDA = 1.0 # weight of bigram term relative to unigram term\nCOVER_TOKENS = 30_000_000 # emit ids covering ~2.5x the 12M budget\n\nt_start = time.time()\ntok = AutoTokenizer.from_pretrained(\"gpt2\")\n\n# ------------------------------------------------------------------ load pool\nids, texts = [], []\nwith open(POOL) as f:\n for line in f:\n r = json.loads(line)\n ids.append(r[\"id\"]); texts.append(r[\"text\"])\nids = np.asarray(ids, dtype=np.int64)\nprint(f\"[{time.time()-t_start:.0f}s] loaded pool: {len(ids)} docs\")\n\n# ------------------------------------------------------ tokenize pool (batched)\ndocs = []\nB = 4000\nfor i in range(0, len(texts), B):\n enc = tok(texts[i:i+B], add_special_tokens=False).input_ids\n docs.extend(np.asarray(x, dtype=np.int32) for x in enc)\nlens = np.fromiter((len(d) for d in docs), dtype=np.int64, count=len(docs))\nprint(f\"[{time.time()-t_start:.0f}s] tokenized pool: {lens.sum()/1e6:.1f}M tokens\")\n\ndef bigram_ids(a):\n \"\"\"Hashed bigram bucket ids for an int token array (length n-1).\"\"\"\n a = a.astype(np.int64)\n return ((a[:-1] * np.int64(1000003) + a[1:]) & (DB - 1))\n\n# ---------------------------------------------------- target (positive) counts\ndev = np.load(DEV).astype(np.int64)\npos_stream = dev[dev != EOS] # drop doc separators\npos_uni = np.bincount(pos_stream, minlength=V).astype(np.float64)\npos_big = np.bincount(bigram_ids(dev), minlength=DB).astype(np.float64) # EOS-crossing negligible\n\n# ------------------------------------------------- pool (background) counts\nneg_uni = np.zeros(V, dtype=np.float64)\nneg_big = np.zeros(DB, dtype=np.float64)\nfor d in docs:\n if len(d) == 0:\n continue\n neg_uni += np.bincount(d.astype(np.int64), minlength=V)\n if len(d) > 1:\n neg_big += np.bincount(bigram_ids(d), minlength=DB)\nprint(f\"[{time.time()-t_start:.0f}s] built count tables\")\n\n# --------------------------------------------------- log importance weights\nuni_w = (np.log(pos_uni + ALPHA) - np.log(pos_uni.sum() + ALPHA * V)) \\\n - (np.log(neg_uni + ALPHA) - np.log(neg_uni.sum() + ALPHA * V))\nbig_w = (np.log(pos_big + ALPHA) - np.log(pos_big.sum() + ALPHA * DB)) \\\n - (np.log(neg_big + ALPHA) - np.log(neg_big.sum() + ALPHA * DB))\n\n# ------------------------------------------------------------ score every doc\nscores = np.full(len(docs), -1e30, dtype=np.float64)\nfor i, d in enumerate(docs):\n n = len(d)\n if n < MIN_TOK:\n continue\n di = d.astype(np.int64)\n s = uni_w[di].sum()\n if n > 1:\n s += LAMBDA * big_w[bigram_ids(d)].sum()\n scores[i] = s / n # length-normalized mean log importance weight\nprint(f\"[{time.time()-t_start:.0f}s] scored docs\")\n\n# ------------------------------------------- rank, dedup, cover the budget\norder = np.argsort(-scores) # best first\nselection, seen, tot = [], set(), 0\nfor j in order:\n if scores[j] <= -1e29: # failed length floor\n break\n h = hash(texts[j]) # exact-duplicate guard\n if h in seen:\n continue\n seen.add(h)\n selection.append(int(ids[j]))\n tot += int(lens[j])\n if tot >= COVER_TOKENS:\n break\n\njson.dump(selection, open(OUT, \"w\"))\nprint(f\"[{time.time()-t_start:.0f}s] wrote {len(selection)} ids covering ~{tot/1e6:.1f}M tokens -> {OUT}\")\nprint(f\"score p50={np.percentile(scores[scores>-1e29],50):.3f} \"\n f\"top={scores[order[0]]:.3f} @12Mcut(kept)={scores[order[len(selection)-1]]:.3f}\")\n"
}Write result
File created successfully at: /workspace/submission/curate.py (file state is current in your context — no need to Read it back)
[metadata] {"type": "create", "filePath": "/workspace/submission/curate.py", "content": "\"\"\"Curate a pretraining subset from a raw web pool by DSIR-style importance ranking.\n\nCriterion (stated, reproducible):\n Score each pool document by its mean per-token log importance weight\n s(doc) = (1/N) * sum_t log p_target(t-gram) - log p_pool(t-gram)\n under a bag-of-n-grams model (unigrams + hashed bigrams). p_target is estimated\n from the disclosed broad multi-domain HQ target (data/multi_dev.npy, GPT-2\n tokens); p_pool is estimated from the whole pool (the background distribution).\n Documents whose token distribution looks more like the HQ target than like the\n average web page get a higher score. We keep documents above a small length\n floor, drop exact duplicates, and emit ids in descending score order (best\n first) until we cover several times the 12M-token training budget.\n\nThis is Data Selection via Importance Resampling (Xie et al. 2023), greedy\ntop-k variant, with the target = the disclosed evaluation domain.\n\nNo labels, no internet: the only supervision is the disclosed target token stream.\n\"\"\"\nimport json, time, numpy as np\nfrom transformers import AutoTokenizer\n\nPOOL = \"/workspace/data/pool.jsonl\"\nDEV = \"/workspace/data/multi_dev.npy\"\nOUT = \"/workspace/submission/selection.json\"\n\nEOS = 50256\nV = 50257 # GPT-2 vocab\nDB = 1 << 20 # hashed bigram buckets\nALPHA = 0.1 # additive smoothing\nMIN_TOK = 100 # length floor: drop fragments\nLAMBDA = 1.0 # weight of bigram term relative to unigram term\nCOVER_TOKENS = 30_000_000 # emit ids covering ~2.5x the 12M budget\n\nt_start = time.time()\ntok = AutoTokenizer.from_pretrained(\"gpt2\")\n\n# ------------------------------------------------------------------ load pool\nids, texts = [], []\nwith open(POOL) as f:\n for line in f:\n r = json.loads(line)\n ids.append(r[\"id\"]); texts.append(r[\"text\"])\nids = np.asarray(ids, dtype=np.int64)\nprint(f\"[{time.time()-t_start:.0f}s] loaded pool: {len(ids)} docs\")\n\n# ------------------------------------------------------ tokenize pool (batched)\ndocs = []\nB = 4000\nfor i in range(0, len(texts), B):\n enc = tok(texts[i:i+B], add_special_tokens=False).input_ids\n docs.extend(np.asarray(x, dtype=np.int32) for x in enc)\nlens = np.fromiter((len(d) for d in docs), dtype=np.int64, count=len(docs))\nprint(f\"[{time.time()-t_start:.0f}s] tokenized pool: {lens.sum()/1e6:.1f}M tokens\")\n\ndef bigram_ids(a):\n \"\"\"Hashed bigram bucket ids for an int token array (length n-1).\"\"\"\n a = a.astype(np.int64)\n return ((a[:-1] * np.int64(1000003) + a[1:]) & (DB - 1))\n\n# ---------------------------------------------------- target (positive) counts\ndev = np.load(DEV).astype(np.int64)\npos_stream = dev[dev != EOS] # drop doc separators\npos_uni = np.bincount(pos_stream, minlength=V).astype(np.float64)\npos_big = np.bincount(bigram_ids(dev), minlength=DB).astype(np.float64) # EOS-crossing negligible\n\n# ------------------------------------------------- pool (background) counts\nneg_uni = np.zeros(V, dtype=np.float64)\nneg_big = np.zeros(DB, dtype=np.float64)\nfor d in docs:\n if len(d) == 0:\n continue\n neg_uni += np.bincount(d.astype(np.int64), minlength=V)\n if len(d) > 1:\n neg_big += np.bincount(bigram_ids(d), minlength=DB)\nprint(f\"[{time.time()-t_start:.0f}s] built count tables\")\n\n# --------------------------------------------------- log importance weights\nuni_w = (np.log(pos_uni + ALPHA) - np.log(pos_uni.sum() + ALPHA * V)) \\\n - (np.log(neg_uni + ALPHA) - np.log(neg_uni.sum() + ALPHA * V))\nbig_w = (np.log(pos_big + ALPHA) - np.log(pos_big.sum() + ALPHA * DB)) \\\n - (np.log(neg_big + ALPHA) - np.log(neg_big.sum() + ALPHA * DB))\n\n# ------------------------------------------------------------ score every doc\nscores = np.full(len(docs), -1e30, dtype=np.float64)\nfor i, d in enumerate(docs):\n n = len(d)\n if n < MIN_TOK:\n continue\n di = d.astype(np.int64)\n s = uni_w[di].sum()\n if n > 1:\n s += LAMBDA * big_w[bigram_ids(d)].sum()\n scores[i] = s / n # length-normalized mean log importance weight\nprint(f\"[{time.time()-t_start:.0f}s] scored docs\")\n\n# ------------------------------------------- rank, dedup, cover the budget\norder = np.argsort(-scores) # best first\nselection, seen, tot = [], set(), 0\nfor j in order:\n if scores[j] <= -1e29: # failed length floor\n break\n h = hash(texts[j]) # exact-duplicate guard\n if h in seen:\n continue\n seen.add(h)\n selection.append(int(ids[j]))\n tot += int(lens[j])\n if tot >= COVER_TOKENS:\n break\n\njson.dump(selection, open(OUT, \"w\"))\nprint(f\"[{time.time()-t_start:.0f}s] wrote {len(selection)} ids covering ~{tot/1e6:.1f}M tokens -> {OUT}\")\nprint(f\"score p50={np.percentile(scores[scores>-1e29],50):.3f} \"\n f\"top={scores[order[0]]:.3f} @12Mcut(kept)={scores[order[len(selection)-1]]:.3f}\")\n", "structuredPatch": [], "originalFile": null, "userModified": false}encrypted chain-of-thought — recorded, not exposed
args
{
"command": "cd /workspace; export TOKENIZERS_PARALLELISM=true; cat /workspace/.timer/remaining_secs; echo \"--- running curate.py ---\"; time python3 submission/curate.py",
"description": "Run curation script"
}Bash result
Command did not complete within its 120s timeout and was moved to the background (ID: briro2fmw). Output is being written to: /tmp/claude-0/-workspace/4bb4d0fa-198e-4747-8902-b67961f6b67a/tasks/briro2fmw.output. You will be notified when it completes. To check interim output, use Read on that file path.
Session cwd remains /workspace; directory changes made by the backgrounded command do not apply to subsequent commands.
[metadata] {"noOutputExpected": false, "backgroundTaskId": "briro2fmw", "timedOutAfterMs": 120000, "backgroundCwdHint": "Session cwd remains /workspace; directory changes made by the backgrounded command do not apply to subsequent commands."}encrypted chain-of-thought — recorded, not exposed
args
{
"command": "sleep 30; cat /tmp/claude-0/-workspace/4bb4d0fa-198e-4747-8902-b67961f6b67a/tasks/briro2fmw.output",
"description": "Check curate.py progress"
}Bash result
5069
--- running curate.py ---
Token indices sequence length is longer than the specified maximum sequence length for this model (1048 > 1024). Running this sequence through the model will result in indexing errors
[stdout]
5069
--- running curate.py ---
Token indices sequence length is longer than the specified maximum sequence length for this model (1048 > 1024). Running this sequence through the model will result in indexing errors
[metadata] {"noOutputExpected": false}Too slow — the per-doc bincount(minlength=1M) allocates a 1M array 182K times. Let me kill it and vectorize with a single concatenated stream + reduceat.
args
{
"command": "kill %1 2>/dev/null; pkill -f curate.py 2>/dev/null; sleep 1; echo killed",
"description": "Kill slow curate run"
}Bash result
killed
[stdout]
killed
[metadata] {"noOutputExpected": false}encrypted chain-of-thought — recorded, not exposed
args
{
"file_path": "/workspace/submission/curate.py",
"content": "\"\"\"Curate a pretraining subset from a raw web pool by DSIR-style importance ranking.\n\nCriterion (stated, reproducible):\n Score each pool document by its mean per-token log importance weight\n s(doc) = (1/N) * sum_t [ log p_target(gram_t) - log p_pool(gram_t) ]\n under a bag-of-n-grams model (unigrams + hashed bigrams). p_target is estimated\n from the disclosed broad multi-domain HQ target (data/multi_dev.npy, GPT-2\n tokens); p_pool is estimated from the whole pool (the background distribution).\n Documents whose token distribution looks more like the HQ target than like the\n average web page score higher. We keep documents above a small length floor,\n drop exact duplicates, and emit ids in descending score order (best first)\n until we cover several times the 12M-token training budget.\n\nThis is Data Selection via Importance Resampling (Xie et al. 2023), greedy\ntop-k variant, with the importance target = the disclosed evaluation domain.\n\nNo labels, no internet: the only supervision is the disclosed target token stream.\n\"\"\"\nimport json, time, numpy as np\nfrom transformers import AutoTokenizer\n\nPOOL = \"/workspace/data/pool.jsonl\"\nDEV = \"/workspace/data/multi_dev.npy\"\nOUT = \"/workspace/submission/selection.json\"\n\nEOS = 50256\nV = 50257 # GPT-2 vocab\nDB = 1 << 20 # hashed bigram buckets\nALPHA = 0.1 # additive smoothing\nMIN_TOK = 100 # length floor: drop fragments\nLAMBDA = 1.0 # weight of bigram term relative to unigram term\nCOVER_TOKENS = 30_000_000 # emit ids covering ~2.5x the 12M budget\n\nt_start = time.time()\ntok = AutoTokenizer.from_pretrained(\"gpt2\")\n\n# ------------------------------------------------------------------ load pool\nids, texts = [], []\nwith open(POOL) as f:\n for line in f:\n r = json.loads(line)\n ids.append(r[\"id\"]); texts.append(r[\"text\"])\nids = np.asarray(ids, dtype=np.int64)\nndoc = len(ids)\nprint(f\"[{time.time()-t_start:.0f}s] loaded pool: {ndoc} docs\", flush=True)\n\n# ------------------------------------------------------ tokenize pool (batched)\ndocs = []\nB = 4000\nfor i in range(0, len(texts), B):\n enc = tok(texts[i:i+B], add_special_tokens=False).input_ids\n docs.extend(np.asarray(x, dtype=np.int32) for x in enc)\ndel texts_ref if False else None # keep texts for dedup below\nlens = np.fromiter((len(d) for d in docs), dtype=np.int64, count=ndoc)\noffsets = np.zeros(ndoc + 1, dtype=np.int64)\nnp.cumsum(lens, out=offsets[1:])\nalltok = np.concatenate([d for d in docs]).astype(np.int64) # one contiguous stream\nprint(f\"[{time.time()-t_start:.0f}s] tokenized pool: {lens.sum()/1e6:.1f}M tokens\", flush=True)\n\ndef bigram_ids(a):\n \"\"\"Hashed bigram bucket ids for an int64 token array -> length len(a)-1.\"\"\"\n return ((a[:-1] * np.int64(1000003) + a[1:]) & np.int64(DB - 1))\n\n# ---------------------------------------------------- target (positive) counts\ndev = np.load(DEV).astype(np.int64)\npos_stream = dev[dev != EOS] # drop doc separators\npos_uni = np.bincount(pos_stream, minlength=V).astype(np.float64)\npos_big = np.bincount(bigram_ids(dev), minlength=DB).astype(np.float64) # EOS-cross negligible\n\n# ------------------------------------------------- pool (background) counts\n# Single bincount over the concatenated stream. Cross-doc boundary bigrams\n# (~ndoc of them out of ~193M) are negligible noise in the background estimate.\nneg_uni = np.bincount(alltok, minlength=V).astype(np.float64)\nall_big = bigram_ids(alltok) # length len(alltok)-1\nneg_big = np.bincount(all_big, minlength=DB).astype(np.float64)\nprint(f\"[{time.time()-t_start:.0f}s] built count tables\", flush=True)\n\n# --------------------------------------------------- log importance weights\nuni_w = (np.log(pos_uni + ALPHA) - np.log(pos_uni.sum() + ALPHA * V)) \\\n - (np.log(neg_uni + ALPHA) - np.log(neg_uni.sum() + ALPHA * V))\nbig_w = (np.log(pos_big + ALPHA) - np.log(pos_big.sum() + ALPHA * DB)) \\\n - (np.log(neg_big + ALPHA) - np.log(neg_big.sum() + ALPHA * DB))\n\n# ------------------------------------------------- vectorized per-doc scoring\n# Per-token unigram weight, summed per doc via reduceat over offsets.\nuni_tokw = uni_w[alltok]\ndoc_uni = np.add.reduceat(uni_tokw, offsets[:-1])\ndoc_uni[lens == 0] = 0.0\n\n# Bigram weight per position in the concatenated stream; zero-out the positions\n# that straddle a document boundary so no doc gets credit for a cross-doc bigram.\nbig_posw = big_w[all_big] # length len(alltok)-1\n# a bigram at global position p spans docs iff p+1 is a document start (in offsets)\nbnd = offsets[1:-1] # internal doc-start positions\nstraddle = bnd - 1 # bigram index that straddles\nstraddle = straddle[(straddle >= 0) & (straddle < big_posw.shape[0])]\nbig_posw[straddle] = 0.0\n# per-doc bigram sum: doc d owns bigram positions [offsets[d], offsets[d+1]-1)\nbig_starts = offsets[:-1].copy()\ndoc_big = np.zeros(ndoc, dtype=np.float64)\nvalid = lens > 1\n# cumulative sum trick for ranges\ncsum = np.concatenate([[0.0], np.cumsum(big_posw)])\n# doc d bigram positions run [offsets[d], offsets[d+1]-1) in big_posw indexing\nlo = offsets[:-1]\nhi = np.maximum(offsets[1:] - 1, offsets[:-1])\ndoc_big = csum[hi] - csum[lo]\n\nscores = np.where(lens >= MIN_TOK,\n (doc_uni + LAMBDA * doc_big) / np.maximum(lens, 1),\n -1e30)\nprint(f\"[{time.time()-t_start:.0f}s] scored docs\", flush=True)\n\n# ------------------------------------------- rank, dedup, cover the budget\norder = np.argsort(-scores)\nselection, seen, tot = [], set(), 0\nfor j in order:\n if scores[j] <= -1e29: # failed length floor\n break\n h = hash(texts[j]) # exact-duplicate guard\n if h in seen:\n continue\n seen.add(h)\n selection.append(int(ids[j]))\n tot += int(lens[j])\n if tot >= COVER_TOKENS:\n break\n\njson.dump(selection, open(OUT, \"w\"))\nvalid_scores = scores[scores > -1e29]\nprint(f\"[{time.time()-t_start:.0f}s] wrote {len(selection)} ids covering ~{tot/1e6:.1f}M tokens -> {OUT}\", flush=True)\nprint(f\"score p10={np.percentile(valid_scores,10):.3f} p50={np.percentile(valid_scores,50):.3f} \"\n f\"p90={np.percentile(valid_scores,90):.3f} top={scores[order[0]]:.3f} \"\n f\"kept_min={scores[order[len(selection)-1]]:.3f}\", flush=True)\n"
}Write result
The file /workspace/submission/curate.py has been updated successfully. (file state is current in your context — no need to Read it back)
[metadata] {"type": "update", "filePath": "/workspace/submission/curate.py", "content": "\"\"\"Curate a pretraining subset from a raw web pool by DSIR-style importance ranking.\n\nCriterion (stated, reproducible):\n Score each pool document by its mean per-token log importance weight\n s(doc) = (1/N) * sum_t [ log p_target(gram_t) - log p_pool(gram_t) ]\n under a bag-of-n-grams model (unigrams + hashed bigrams). p_target is estimated\n from the disclosed broad multi-domain HQ target (data/multi_dev.npy, GPT-2\n tokens); p_pool is estimated from the whole pool (the background distribution).\n Documents whose token distribution looks more like the HQ target than like the\n average web page score higher. We keep documents above a small length floor,\n drop exact duplicates, and emit ids in descending score order (best first)\n until we cover several times the 12M-token training budget.\n\nThis is Data Selection via Importance Resampling (Xie et al. 2023), greedy\ntop-k variant, with the importance target = the disclosed evaluation domain.\n\nNo labels, no internet: the only supervision is the disclosed target token stream.\n\"\"\"\nimport json, time, numpy as np\nfrom transformers import AutoTokenizer\n\nPOOL = \"/workspace/data/pool.jsonl\"\nDEV = \"/workspace/data/multi_dev.npy\"\nOUT = \"/workspace/submission/selection.json\"\n\nEOS = 50256\nV = 50257 # GPT-2 vocab\nDB = 1 << 20 # hashed bigram buckets\nALPHA = 0.1 # additive smoothing\nMIN_TOK = 100 # length floor: drop fragments\nLAMBDA = 1.0 # weight of bigram term relative to unigram term\nCOVER_TOKENS = 30_000_000 # emit ids covering ~2.5x the 12M budget\n\nt_start = time.time()\ntok = AutoTokenizer.from_pretrained(\"gpt2\")\n\n# ------------------------------------------------------------------ load pool\nids, texts = [], []\nwith open(POOL) as f:\n for line in f:\n r = json.loads(line)\n ids.append(r[\"id\"]); texts.append(r[\"text\"])\nids = np.asarray(ids, dtype=np.int64)\nndoc = len(ids)\nprint(f\"[{time.time()-t_start:.0f}s] loaded pool: {ndoc} docs\", flush=True)\n\n# ------------------------------------------------------ tokenize pool (batched)\ndocs = []\nB = 4000\nfor i in range(0, len(texts), B):\n enc = tok(texts[i:i+B], add_special_tokens=False).input_ids\n docs.extend(np.asarray(x, dtype=np.int32) for x in enc)\ndel texts_ref if False else None # keep texts for dedup below\nlens = np.fromiter((len(d) for d in docs), dtype=np.int64, count=ndoc)\noffsets = np.zeros(ndoc + 1, dtype=np.int64)\nnp.cumsum(lens, out=offsets[1:])\nalltok = np.concatenate([d for d in docs]).astype(np.int64) # one contiguous stream\nprint(f\"[{time.time()-t_start:.0f}s] tokenized pool: {lens.sum()/1e6:.1f}M tokens\", flush=True)\n\ndef bigram_ids(a):\n \"\"\"Hashed bigram bucket ids for an int64 token array -> length len(a)-1.\"\"\"\n return ((a[:-1] * np.int64(1000003) + a[1:]) & np.int64(DB - 1))\n\n# ---------------------------------------------------- target (positive) counts\ndev = np.load(DEV).astype(np.int64)\npos_stream = dev[dev != EOS] # drop doc separators\npos_uni = np.bincount(pos_stream, minlength=V).astype(np.float64)\npos_big = np.bincount(bigram_ids(dev), minlength=DB).astype(np.float64) # EOS-cross negligible\n\n# ------------------------------------------------- pool (background) counts\n# Single bincount over the concatenated stream. Cross-doc boundary bigrams\n# (~ndoc of them out of ~193M) are negligible noise in the background estimate.\nneg_uni = np.bincount(alltok, minlength=V).astype(np.float64)\nall_big = bigram_ids(alltok) # length len(alltok)-1\nneg_big = np.bincount(all_big, minlength=DB).astype(np.float64)\nprint(f\"[{time.time()-t_start:.0f}s] built count tables\", flush=True)\n\n# --------------------------------------------------- log importance weights\nuni_w = (np.log(pos_uni + ALPHA) - np.log(pos_uni.sum() + ALPHA * V)) \\\n - (np.log(neg_uni + ALPHA) - np.log(neg_uni.sum() + ALPHA * V))\nbig_w = (np.log(pos_big + ALPHA) - np.log(pos_big.sum() + ALPHA * DB)) \\\n - (np.log(neg_big + ALPHA) - np.log(neg_big.sum() + ALPHA * DB))\n\n# ------------------------------------------------- vectorized per-doc scoring\n# Per-token unigram weight, summed per doc via reduceat over offsets.\nuni_tokw = uni_w[alltok]\ndoc_uni = np.add.reduceat(uni_tokw, offsets[:-1])\ndoc_uni[lens == 0] = 0.0\n\n# Bigram weight per position in the concatenated stream; zero-out the positions\n# that straddle a document boundary so no doc gets credit for a cross-doc bigram.\nbig_posw = big_w[all_big] # length len(alltok)-1\n# a bigram at global position p spans docs iff p+1 is a document start (in offsets)\nbnd = offsets[1:-1] # internal doc-start positions\nstraddle = bnd - 1 # bigram index that straddles\nstraddle = straddle[(straddle >= 0) & (straddle < big_posw.shape[0])]\nbig_posw[straddle] = 0.0\n# per-doc bigram sum: doc d owns bigram positions [offsets[d], offsets[d+1]-1)\nbig_starts = offsets[:-1].copy()\ndoc_big = np.zeros(ndoc, dtype=np.float64)\nvalid = lens > 1\n# cumulative sum trick for ranges\ncsum = np.concatenate([[0.0], np.cumsum(big_posw)])\n# doc d bigram positions run [offsets[d], offsets[d+1]-1) in big_posw indexing\nlo = offsets[:-1]\nhi = np.maximum(offsets[1:] - 1, offsets[:-1])\ndoc_big = csum[hi] - csum[lo]\n\nscores = np.where(lens >= MIN_TOK,\n (doc_uni + LAMBDA * doc_big) / np.maximum(lens, 1),\n -1e30)\nprint(f\"[{time.time()-t_start:.0f}s] scored docs\", flush=True)\n\n# ------------------------------------------- rank, dedup, cover the budget\norder = np.argsort(-scores)\nselection, seen, tot = [], set(), 0\nfor j in order:\n if scores[j] <= -1e29: # failed length floor\n break\n h = hash(texts[j]) # exact-duplicate guard\n if h in seen:\n continue\n seen.add(h)\n selection.append(int(ids[j]))\n tot += int(lens[j])\n if tot >= COVER_TOKENS:\n break\n\njson.dump(selection, open(OUT, \"w\"))\nvalid_scores = scores[scores > -1e29]\nprint(f\"[{time.time()-t_start:.0f}s] wrote {len(selection)} ids covering ~{tot/1e6:.1f}M tokens -> {OUT}\", flush=True)\nprint(f\"score p10={np.percentile(valid_scores,10):.3f} p50={np.percentile(valid_scores,50):.3f} \"\n f\"p90={np.percentile(valid_scores,90):.3f} top={scores[order[0]]:.3f} \"\n f\"kept_min={scores[order[len(selection)-1]]:.3f}\", flush=True)\n", "structuredPatch": [{"oldStart": 2, "oldLines": 17, "newStart": 2, "newLines": 17, "lines": [" ", " Criterion (stated, reproducible):", " Score each pool document by its mean per-token log importance weight", "- s(doc) = (1/N) * sum_t log p_target(t-gram) - log p_pool(t-gram)", "+ s(doc) = (1/N) * sum_t [ log p_target(gram_t) - log p_pool(gram_t) ]", " under a bag-of-n-grams model (unigrams + hashed bigrams). p_target is estimated", " from the disclosed broad multi-domain HQ target (data/multi_dev.npy, GPT-2", " tokens); p_pool is estimated from the whole pool (the background distribution).", " Documents whose token distribution looks more like the HQ target than like the", "- average web page get a higher score. We keep documents above a small length", "- floor, drop exact duplicates, and emit ids in descending score order (best", "- first) until we cover several times the 12M-token training budget.", "+ average web page score higher. We keep documents above a small length floor,", "+ drop exact duplicates, and emit ids in descending score order (best first)", "+ until we cover several times the 12M-token training budget.", " ", " This is Data Selection via Importance Resampling (Xie et al. 2023), greedy", "-top-k variant, with the target = the disclosed evaluation domain.", "+top-k variant, with the importance target = the disclosed evaluation domain.", " ", " No labels, no internet: the only supervision is the disclosed target token stream.", " \"\"\""]}, {"oldStart": 41, "oldLines": 7, "newStart": 41, "newLines": 8, "lines": [" r = json.loads(line)", " ids.append(r[\"id\"]); texts.append(r[\"text\"])", " ids = np.asarray(ids, dtype=np.int64)", "-print(f\"[{time.time()-t_start:.0f}s] loaded pool: {len(ids)} docs\")", "+ndoc = len(ids)", "+print(f\"[{time.time()-t_start:.0f}s] loaded pool: {ndoc} docs\", flush=True)", " ", " # ------------------------------------------------------ tokenize pool (batched)", " docs = []"]}, {"oldStart": 49, "oldLines": 30, "newStart": 50, "newLines": 30, "lines": [" for i in range(0, len(texts), B):", " enc = tok(texts[i:i+B], add_special_tokens=False).input_ids", " docs.extend(np.asarray(x, dtype=np.int32) for x in enc)", "-lens = np.fromiter((len(d) for d in docs), dtype=np.int64, count=len(docs))", "-print(f\"[{time.time()-t_start:.0f}s] tokenized pool: {lens.sum()/1e6:.1f}M tokens\")", "+del texts_ref if False else None # keep texts for dedup below", "+lens = np.fromiter((len(d) for d in docs), dtype=np.int64, count=ndoc)", "+offsets = np.zeros(ndoc + 1, dtype=np.int64)", "+np.cumsum(lens, out=offsets[1:])", "+alltok = np.concatenate([d for d in docs]).astype(np.int64) # one contiguous stream", "+print(f\"[{time.time()-t_start:.0f}s] tokenized pool: {lens.sum()/1e6:.1f}M tokens\", flush=True)", " ", " def bigram_ids(a):", "- \"\"\"Hashed bigram bucket ids for an int token array (length n-1).\"\"\"", "- a = a.astype(np.int64)", "- return ((a[:-1] * np.int64(1000003) + a[1:]) & (DB - 1))", "+ \"\"\"Hashed bigram bucket ids for an int64 token array -> length len(a)-1.\"\"\"", "+ return ((a[:-1] * np.int64(1000003) + a[1:]) & np.int64(DB - 1))", " ", " # ---------------------------------------------------- target (positive) counts", " dev = np.load(DEV).astype(np.int64)", " pos_stream = dev[dev != EOS] # drop doc separators", " pos_uni = np.bincount(pos_stream, minlength=V).astype(np.float64)", "-pos_big = np.bincount(bigram_ids(dev), minlength=DB).astype(np.float64) # EOS-crossing negligible", "+pos_big = np.bincount(bigram_ids(dev), minlength=DB).astype(np.float64) # EOS-cross negligible", " ", " # ------------------------------------------------- pool (background) counts", "-neg_uni = np.zeros(V, dtype=np.float64)", "-neg_big = np.zeros(DB, dtype=np.float64)", "-for d in docs:", "- if len(d) == 0:", "- continue", "- neg_uni += np.bincount(d.astype(np.int64), minlength=V)", "- if len(d) > 1:", "- neg_big += np.bincount(bigram_ids(d), minlength=DB)", "-print(f\"[{time.time()-t_start:.0f}s] built count tables\")", "+# Single bincount over the concatenated stream. Cross-doc boundary bigrams", "+# (~ndoc of them out of ~193M) are negligible noise in the background estimate.", "+neg_uni = np.bincount(alltok, minlength=V).astype(np.float64)", "+all_big = bigram_ids(alltok) # length len(alltok)-1", "+neg_big = np.bincount(all_big, minlength=DB).astype(np.float64)", "+print(f\"[{time.time()-t_start:.0f}s] built count tables\", flush=True)", " ", " # --------------------------------------------------- log importance weights", " uni_w = (np.log(pos_uni + ALPHA) - np.log(pos_uni.sum() + ALPHA * V)) \\"]}, {"oldStart": 80, "oldLines": 26, "newStart": 81, "newLines": 43, "lines": [" big_w = (np.log(pos_big + ALPHA) - np.log(pos_big.sum() + ALPHA * DB)) \\", " - (np.log(neg_big + ALPHA) - np.log(neg_big.sum() + ALPHA * DB))", " ", "-# ------------------------------------------------------------ score every doc", "-scores = np.full(len(docs), -1e30, dtype=np.float64)", "-for i, d in enumerate(docs):", "- n = len(d)", "- if n < MIN_TOK:", "- continue", "- di = d.astype(np.int64)", "- s = uni_w[di].sum()", "- if n > 1:", "- s += LAMBDA * big_w[bigram_ids(d)].sum()", "- scores[i] = s / n # length-normalized mean log importance weight", "-print(f\"[{time.time()-t_start:.0f}s] scored docs\")", "+# ------------------------------------------------- vectorized per-doc scoring", "+# Per-token unigram weight, summed per doc via reduceat over offsets.", "+uni_tokw = uni_w[alltok]", "+doc_uni = np.add.reduceat(uni_tokw, offsets[:-1])", "+doc_uni[lens == 0] = 0.0", " ", "+# Bigram weight per position in the concatenated stream; zero-out the positions", "+# that straddle a document boundary so no doc gets credit for a cross-doc bigram.", "+big_posw = big_w[all_big] # length len(alltok)-1", "+# a bigram at global position p spans docs iff p+1 is a document start (in offsets)", "+bnd = offsets[1:-1] # internal doc-start positions", "+straddle = bnd - 1 # bigram index that straddles", "+straddle = straddle[(straddle >= 0) & (straddle < big_posw.shape[0])]", "+big_posw[straddle] = 0.0", "+# per-doc bigram sum: doc d owns bigram positions [offsets[d], offsets[d+1]-1)", "+big_starts = offsets[:-1].copy()", "+doc_big = np.zeros(ndoc, dtype=np.float64)", "+valid = lens > 1", "+# cumulative sum trick for ranges", "+csum = np.concatenate([[0.0], np.cumsum(big_posw)])", "+# doc d bigram positions run [offsets[d], offsets[d+1]-1) in big_posw indexing", "+lo = offsets[:-1]", "+hi = np.maximum(offsets[1:] - 1, offsets[:-1])", "+doc_big = csum[hi] - csum[lo]", "+", "+scores = np.where(lens >= MIN_TOK,", "+ (doc_uni + LAMBDA * doc_big) / np.maximum(lens, 1),", "+ -1e30)", "+print(f\"[{time.time()-t_start:.0f}s] scored docs\", flush=True)", "+", " # ------------------------------------------- rank, dedup, cover the budget", "-order = np.argsort(-scores) # best first", "+order = np.argsort(-scores)", " selection, seen, tot = [], set(), 0", " for j in order:", "- if scores[j] <= -1e29: # failed length floor", "+ if scores[j] <= -1e29: # failed length floor", " break", "- h = hash(texts[j]) # exact-duplicate guard", "+ h = hash(texts[j]) # exact-duplicate guard", " if h in seen:", " continue", " seen.add(h)"]}, {"oldStart": 109, "oldLines": 6, "newStart": 127, "newLines": 8, "lines": [" break", " ", " json.dump(selection, open(OUT, \"w\"))", "-print(f\"[{time.time()-t_start:.0f}s] wrote {len(selection)} ids covering ~{tot/1e6:.1f}M tokens -> {OUT}\")", "-print(f\"score p50={np.percentile(scores[scores>-1e29],50):.3f} \"", "- f\"top={scores[order[0]]:.3f} @12Mcut(kept)={scores[order[len(selection)-1]]:.3f}\")", "+valid_scores = scores[scores > -1e29]", "+print(f\"[{time.time()-t_start:.0f}s] wrote {len(selection)} ids covering ~{tot/1e6:.1f}M tokens -> {OUT}\", flush=True)", "+print(f\"score p10={np.percentile(valid_scores,10):.3f} p50={np.percentile(valid_scores,50):.3f} \"", "+ f\"p90={np.percentile(valid_scores,90):.3f} top={scores[order[0]]:.3f} \"", "+ f\"kept_min={scores[order[len(selection)-1]]:.3f}\", flush=True)"]}], "originalFile": "\"\"\"Curate a pretraining subset from a raw web pool by DSIR-style importance ranking.\n\nCriterion (stated, reproducible):\n Score each pool document by its mean per-token log importance weight\n s(doc) = (1/N) * sum_t log p_target(t-gram) - log p_pool(t-gram)\n under a bag-of-n-grams model (unigrams + hashed bigrams). p_target is estimated\n from the disclosed broad multi-domain HQ target (data/multi_dev.npy, GPT-2\n tokens); p_pool is estimated from the whole pool (the background distribution).\n Documents whose token distribution looks more like the HQ target than like the\n average web page get a higher score. We keep documents above a small length\n floor, drop exact duplicates, and emit ids in descending score order (best\n first) until we cover several times the 12M-token training budget.\n\nThis is Data Selection via Importance Resampling (Xie et al. 2023), greedy\ntop-k variant, with the target = the disclosed evaluation domain.\n\nNo labels, no internet: the only supervision is the disclosed target token stream.\n\"\"\"\nimport json, time, numpy as np\nfrom transformers import AutoTokenizer\n\nPOOL = \"/workspace/data/pool.jsonl\"\nDEV = \"/workspace/data/multi_dev.npy\"\nOUT = \"/workspace/submission/selection.json\"\n\nEOS = 50256\nV = 50257 # GPT-2 vocab\nDB = 1 << 20 # hashed bigram buckets\nALPHA = 0.1 # additive smoothing\nMIN_TOK = 100 # length floor: drop fragments\nLAMBDA = 1.0 # weight of bigram term relative to unigram term\nCOVER_TOKENS = 30_000_000 # emit ids covering ~2.5x the 12M budget\n\nt_start = time.time()\ntok = AutoTokenizer.from_pretrained(\"gpt2\")\n\n# ------------------------------------------------------------------ load pool\nids, texts = [], []\nwith open(POOL) as f:\n for line in f:\n r = json.loads(line)\n ids.append(r[\"id\"]); texts.append(r[\"text\"])\nids = np.asarray(ids, dtype=np.int64)\nprint(f\"[{time.time()-t_start:.0f}s] loaded pool: {len(ids)} docs\")\n\n# ------------------------------------------------------ tokenize pool (batched)\ndocs = []\nB = 4000\nfor i in range(0, len(texts), B):\n enc = tok(texts[i:i+B], add_special_tokens=False).input_ids\n docs.extend(np.asarray(x, dtype=np.int32) for x in enc)\nlens = np.fromiter((len(d) for d in docs), dtype=np.int64, count=len(docs))\nprint(f\"[{time.time()-t_start:.0f}s] tokenized pool: {lens.sum()/1e6:.1f}M tokens\")\n\ndef bigram_ids(a):\n \"\"\"Hashed bigram bucket ids for an int token array (length n-1).\"\"\"\n a = a.astype(np.int64)\n return ((a[:-1] * np.int64(1000003) + a[1:]) & (DB - 1))\n\n# ---------------------------------------------------- target (positive) counts\ndev = np.load(DEV).astype(np.int64)\npos_stream = dev[dev != EOS] # drop doc separators\npos_uni = np.bincount(pos_stream, minlength=V).astype(np.float64)\npos_big = np.bincount(bigram_ids(dev), minlength=DB).astype(np.float64) # EOS-crossing negligible\n\n# ------------------------------------------------- pool (background) counts\nneg_uni = np.zeros(V, dtype=np.float64)\nneg_big = np.zeros(DB, dtype=np.float64)\nfor d in docs:\n if len(d) == 0:\n continue\n neg_uni += np.bincount(d.astype(np.int64), minlength=V)\n if len(d) > 1:\n neg_big += np.bincount(bigram_ids(d), minlength=DB)\nprint(f\"[{time.time()-t_start:.0f}s] built count tables\")\n\n# --------------------------------------------------- log importance weights\nuni_w = (np.log(pos_uni + ALPHA) - np.log(pos_uni.sum() + ALPHA * V)) \\\n - (np.log(neg_uni + ALPHA) - np.log(neg_uni.sum() + ALPHA * V))\nbig_w = (np.log(pos_big + ALPHA) - np.log(pos_big.sum() + ALPHA * DB)) \\\n - (np.log(neg_big + ALPHA) - np.log(neg_big.sum() + ALPHA * DB))\n\n# ------------------------------------------------------------ score every doc\nscores = np.full(len(docs), -1e30, dtype=np.float64)\nfor i, d in enumerate(docs):\n n = len(d)\n if n < MIN_TOK:\n continue\n di = d.astype(np.int64)\n s = uni_w[di].sum()\n if n > 1:\n s += LAMBDA * big_w[bigram_ids(d)].sum()\n scores[i] = s / n # length-normalized mean log importance weight\nprint(f\"[{time.time()-t_start:.0f}s] scored docs\")\n\n# ------------------------------------------- rank, dedup, cover the budget\norder = np.argsort(-scores) # best first\nselection, seen, tot = [], set(), 0\nfor j in order:\n if scores[j] <= -1e29: # failed length floor\n break\n h = hash(texts[j]) # exact-duplicate guard\n if h in seen:\n continue\n seen.add(h)\n selection.append(int(ids[j]))\n tot += int(lens[j])\n if tot >= COVER_TOKENS:\n break\n\njson.dump(selection, open(OUT, \"w\"))\nprint(f\"[{time.time()-t_start:.0f}s] wrote {len(selection)} ids covering ~{tot/1e6:.1f}M tokens -> {OUT}\")\nprint(f\"score p50={np.percentile(scores[scores>-1e29],50):.3f} \"\n f\"top={scores[order[0]]:.3f} @12Mcut(kept)={scores[order[len(selection)-1]]:.3f}\")\n", "userModified": false}I left a bogus line. Let me fix it.
args
{
"replace_all": false,
"file_path": "/workspace/submission/curate.py",
"old_string": " docs.extend(np.asarray(x, dtype=np.int32) for x in enc)\ndel texts_ref if False else None # keep texts for dedup below\nlens = np.fromiter",
"new_string": " docs.extend(np.asarray(x, dtype=np.int32) for x in enc)\nlens = np.fromiter"
}Edit result
The file /workspace/submission/curate.py has been updated successfully. (file state is current in your context — no need to Read it back)
[metadata] {"filePath": "/workspace/submission/curate.py", "oldString": " docs.extend(np.asarray(x, dtype=np.int32) for x in enc)\ndel texts_ref if False else None # keep texts for dedup below\nlens = np.fromiter", "newString": " docs.extend(np.asarray(x, dtype=np.int32) for x in enc)\nlens = np.fromiter", "originalFile": "\"\"\"Curate a pretraining subset from a raw web pool by DSIR-style importance ranking.\n\nCriterion (stated, reproducible):\n Score each pool document by its mean per-token log importance weight\n s(doc) = (1/N) * sum_t [ log p_target(gram_t) - log p_pool(gram_t) ]\n under a bag-of-n-grams model (unigrams + hashed bigrams). p_target is estimated\n from the disclosed broad multi-domain HQ target (data/multi_dev.npy, GPT-2\n tokens); p_pool is estimated from the whole pool (the background distribution).\n Documents whose token distribution looks more like the HQ target than like the\n average web page score higher. We keep documents above a small length floor,\n drop exact duplicates, and emit ids in descending score order (best first)\n until we cover several times the 12M-token training budget.\n\nThis is Data Selection via Importance Resampling (Xie et al. 2023), greedy\ntop-k variant, with the importance target = the disclosed evaluation domain.\n\nNo labels, no internet: the only supervision is the disclosed target token stream.\n\"\"\"\nimport json, time, numpy as np\nfrom transformers import AutoTokenizer\n\nPOOL = \"/workspace/data/pool.jsonl\"\nDEV = \"/workspace/data/multi_dev.npy\"\nOUT = \"/workspace/submission/selection.json\"\n\nEOS = 50256\nV = 50257 # GPT-2 vocab\nDB = 1 << 20 # hashed bigram buckets\nALPHA = 0.1 # additive smoothing\nMIN_TOK = 100 # length floor: drop fragments\nLAMBDA = 1.0 # weight of bigram term relative to unigram term\nCOVER_TOKENS = 30_000_000 # emit ids covering ~2.5x the 12M budget\n\nt_start = time.time()\ntok = AutoTokenizer.from_pretrained(\"gpt2\")\n\n# ------------------------------------------------------------------ load pool\nids, texts = [], []\nwith open(POOL) as f:\n for line in f:\n r = json.loads(line)\n ids.append(r[\"id\"]); texts.append(r[\"text\"])\nids = np.asarray(ids, dtype=np.int64)\nndoc = len(ids)\nprint(f\"[{time.time()-t_start:.0f}s] loaded pool: {ndoc} docs\", flush=True)\n\n# ------------------------------------------------------ tokenize pool (batched)\ndocs = []\nB = 4000\nfor i in range(0, len(texts), B):\n enc = tok(texts[i:i+B], add_special_tokens=False).input_ids\n docs.extend(np.asarray(x, dtype=np.int32) for x in enc)\ndel texts_ref if False else None # keep texts for dedup below\nlens = np.fromiter((len(d) for d in docs), dtype=np.int64, count=ndoc)\noffsets = np.zeros(ndoc + 1, dtype=np.int64)\nnp.cumsum(lens, out=offsets[1:])\nalltok = np.concatenate([d for d in docs]).astype(np.int64) # one contiguous stream\nprint(f\"[{time.time()-t_start:.0f}s] tokenized pool: {lens.sum()/1e6:.1f}M tokens\", flush=True)\n\ndef bigram_ids(a):\n \"\"\"Hashed bigram bucket ids for an int64 token array -> length len(a)-1.\"\"\"\n return ((a[:-1] * np.int64(1000003) + a[1:]) & np.int64(DB - 1))\n\n# ---------------------------------------------------- target (positive) counts\ndev = np.load(DEV).astype(np.int64)\npos_stream = dev[dev != EOS] # drop doc separators\npos_uni = np.bincount(pos_stream, minlength=V).astype(np.float64)\npos_big = np.bincount(bigram_ids(dev), minlength=DB).astype(np.float64) # EOS-cross negligible\n\n# ------------------------------------------------- pool (background) counts\n# Single bincount over the concatenated stream. Cross-doc boundary bigrams\n# (~ndoc of them out of ~193M) are negligible noise in the background estimate.\nneg_uni = np.bincount(alltok, minlength=V).astype(np.float64)\nall_big = bigram_ids(alltok) # length len(alltok)-1\nneg_big = np.bincount(all_big, minlength=DB).astype(np.float64)\nprint(f\"[{time.time()-t_start:.0f}s] built count tables\", flush=True)\n\n# --------------------------------------------------- log importance weights\nuni_w = (np.log(pos_uni + ALPHA) - np.log(pos_uni.sum() + ALPHA * V)) \\\n - (np.log(neg_uni + ALPHA) - np.log(neg_uni.sum() + ALPHA * V))\nbig_w = (np.log(pos_big + ALPHA) - np.log(pos_big.sum() + ALPHA * DB)) \\\n - (np.log(neg_big + ALPHA) - np.log(neg_big.sum() + ALPHA * DB))\n\n# ------------------------------------------------- vectorized per-doc scoring\n# Per-token unigram weight, summed per doc via reduceat over offsets.\nuni_tokw = uni_w[alltok]\ndoc_uni = np.add.reduceat(uni_tokw, offsets[:-1])\ndoc_uni[lens == 0] = 0.0\n\n# Bigram weight per position in the concatenated stream; zero-out the positions\n# that straddle a document boundary so no doc gets credit for a cross-doc bigram.\nbig_posw = big_w[all_big] # length len(alltok)-1\n# a bigram at global position p spans docs iff p+1 is a document start (in offsets)\nbnd = offsets[1:-1] # internal doc-start positions\nstraddle = bnd - 1 # bigram index that straddles\nstraddle = straddle[(straddle >= 0) & (straddle < big_posw.shape[0])]\nbig_posw[straddle] = 0.0\n# per-doc bigram sum: doc d owns bigram positions [offsets[d], offsets[d+1]-1)\nbig_starts = offsets[:-1].copy()\ndoc_big = np.zeros(ndoc, dtype=np.float64)\nvalid = lens > 1\n# cumulative sum trick for ranges\ncsum = np.concatenate([[0.0], np.cumsum(big_posw)])\n# doc d bigram positions run [offsets[d], offsets[d+1]-1) in big_posw indexing\nlo = offsets[:-1]\nhi = np.maximum(offsets[1:] - 1, offsets[:-1])\ndoc_big = csum[hi] - csum[lo]\n\nscores = np.where(lens >= MIN_TOK,\n (doc_uni + LAMBDA * doc_big) / np.maximum(lens, 1),\n -1e30)\nprint(f\"[{time.time()-t_start:.0f}s] scored docs\", flush=True)\n\n# ------------------------------------------- rank, dedup, cover the budget\norder = np.argsort(-scores)\nselection, seen, tot = [], set(), 0\nfor j in order:\n if scores[j] <= -1e29: # failed length floor\n break\n h = hash(texts[j]) # exact-duplicate guard\n if h in seen:\n continue\n seen.add(h)\n selection.append(int(ids[j]))\n tot += int(lens[j])\n if tot >= COVER_TOKENS:\n break\n\njson.dump(selection, open(OUT, \"w\"))\nvalid_scores = scores[scores > -1e29]\nprint(f\"[{time.time()-t_start:.0f}s] wrote {len(selection)} ids covering ~{tot/1e6:.1f}M tokens -> {OUT}\", flush=True)\nprint(f\"score p10={np.percentile(valid_scores,10):.3f} p50={np.percentile(valid_scores,50):.3f} \"\n f\"p90={np.percentile(valid_scores,90):.3f} top={scores[order[0]]:.3f} \"\n f\"kept_min={scores[order[len(selection)-1]]:.3f}\", flush=True)\n", "structuredPatch": [{"oldStart": 50, "oldLines": 7, "newStart": 50, "newLines": 6, "lines": [" for i in range(0, len(texts), B):", " enc = tok(texts[i:i+B], add_special_tokens=False).input_ids", " docs.extend(np.asarray(x, dtype=np.int32) for x in enc)", "-del texts_ref if False else None # keep texts for dedup below", " lens = np.fromiter((len(d) for d in docs), dtype=np.int64, count=ndoc)", " offsets = np.zeros(ndoc + 1, dtype=np.int64)", " np.cumsum(lens, out=offsets[1:])"]}], "userModified": false, "replaceAll": false}encrypted chain-of-thought — recorded, not exposed
args
{
"command": "cd /workspace; export TOKENIZERS_PARALLELISM=true; cat /workspace/.timer/remaining_secs; echo \"--- running curate.py ---\"; time python3 submission/curate.py 2>&1 | grep -v \"sequence length\"",
"description": "Run optimized curation script"
}Bash result
Command did not complete within its 120s timeout and was moved to the background (ID: blrozy02x). Output is being written to: /tmp/claude-0/-workspace/4bb4d0fa-198e-4747-8902-b67961f6b67a/tasks/blrozy02x.output. You will be notified when it completes. To check interim output, use Read on that file path.
Session cwd remains /workspace; directory changes made by the backgrounded command do not apply to subsequent commands.
[metadata] {"noOutputExpected": false, "backgroundTaskId": "blrozy02x", "timedOutAfterMs": 120000, "backgroundCwdHint": "Session cwd remains /workspace; directory changes made by the backgrounded command do not apply to subsequent commands."}encrypted chain-of-thought — recorded, not exposed
args
{
"command": "sleep 25; cat /tmp/claude-0/-workspace/4bb4d0fa-198e-4747-8902-b67961f6b67a/tasks/blrozy02x.output",
"description": "Check progress"
}Bash result
4869
--- running curate.py ---
[8s] loaded pool: 182016 docs
[110s] tokenized pool: 199.9M tokens
[112s] built count tables
[117s] scored docs
[117s] wrote 31845 ids covering ~30.0M tokens -> /workspace/submission/selection.json
score p10=-3.096 p50=-1.149 p90=-0.431 top=4.018 kept_min=-0.578
real 2m2.377s
user 15m31.840s
sys 0m3.530s
[stdout]
4869
--- running curate.py ---
[8s] loaded pool: 182016 docs
[110s] tokenized pool: 199.9M tokens
[112s] built count tables
[117s] scored docs
[117s] wrote 31845 ids covering ~30.0M tokens -> /workspace/submission/selection.json
score p10=-3.096 p50=-1.149 p90=-0.431 top=4.018 kept_min=-0.578
real 2m2.377s
user 15m31.840s
sys 0m3.530s
[metadata] {"noOutputExpected": false}Curation succeeded: 31,845 ids covering 30M tokens, scores ranging from top=4.0 down to kept_min=−0.58 (well above pool median −1.15). Let me sanity-check what got selected vs rejected, then validate.
args
{
"command": "cd /workspace; python3 -c \"\nimport json, numpy as np\nsel=json.load(open('submission/selection.json'))\nprint('n selected:', len(sel), 'unique:', len(set(sel)), 'in-range:', min(sel)>=0 and max(sel)<182016)\nselset=set(sel[:8])\n# load a few top + a few NOT-selected docs\ntop=set(sel[:5]); worst_candidates=set()\nimport itertools\ntexts={}\nwith open('data/pool.jsonl') as f:\n for line in f:\n r=json.loads(line)\n texts[r['id']]=r['text']\nprint('=== TOP-5 SELECTED (best first) ===')\nfor i in sel[:5]:\n print('--- id',i,'---'); print(texts[i][:350].replace(chr(10),' ')); print()\n# show some low-ranked (near cut) and some never-selected\nnotsel=[i for i in range(182016) if i not in set(sel)]\nprint('=== 3 NOT-SELECTED (rejected) ===')\nfor i in notsel[:3]:\n print('--- id',i,'---'); print(texts[i][:300].replace(chr(10),' ')); print()\n\"\n",
"description": "Inspect selected vs rejected docs"
}Bash result
Command did not complete within its 120s timeout and was moved to the background (ID: b8yv1ek1i). Output is being written to: /tmp/claude-0/-workspace/4bb4d0fa-198e-4747-8902-b67961f6b67a/tasks/b8yv1ek1i.output. You will be notified when it completes. To check interim output, use Read on that file path.
Session cwd remains /workspace; directory changes made by the backgrounded command do not apply to subsequent commands.
[metadata] {"noOutputExpected": false, "backgroundTaskId": "b8yv1ek1i", "timedOutAfterMs": 120000, "backgroundCwdHint": "Session cwd remains /workspace; directory changes made by the backgrounded command do not apply to subsequent commands."}encrypted chain-of-thought — recorded, not exposed
args
{
"command": "sleep 15; cat /tmp/claude-0/-workspace/4bb4d0fa-198e-4747-8902-b67961f6b67a/tasks/b8yv1ek1i.output",
"description": "Check inspection output"
}Bash result
(Bash completed with no output)
[metadata] {"noOutputExpected": false}encrypted chain-of-thought — recorded, not exposed
args
{
"command": "cat /tmp/claude-0/-workspace/4bb4d0fa-198e-4747-8902-b67961f6b67a/tasks/b8yv1ek1i.output",
"description": "Read inspection output file"
}Bash result
(Bash completed with no output)
[metadata] {"noOutputExpected": false}encrypted chain-of-thought — recorded, not exposed
args
{
"command": "ls -la /tmp/claude-0/-workspace/4bb4d0fa-198e-4747-8902-b67961f6b67a/tasks/b8yv1ek1i.output; echo \"---running?\"; pgrep -af \"python3 -c\" | head; sleep 10; echo \"=== output ===\"; cat /tmp/claude-0/-workspace/4bb4d0fa-198e-4747-8902-b67961f6b67a/tasks/b8yv1ek1i.output",
"description": "Check if inspection still running"
}Bash result
-rw-r--r-- 1 root root 0 Aug 4 03:34 /tmp/claude-0/-workspace/4bb4d0fa-198e-4747-8902-b67961f6b67a/tasks/b8yv1ek1i.output
---running?
1223 /bin/bash -c source /logs/agent/sessions/shell-snapshots/snapshot-bash-1785813778825-pa4rq7.sh 2>/dev/null || true && shopt -u extglob 2>/dev/null || true && { \builtin unalias -- 'unsetenv'; \builtin unset -f -- 'unsetenv'; } >/dev/null 2>&1 || true && eval 'cd /workspace; python3 -c " import json, numpy as np sel=json.load(open('"'"'submission/selection.json'"'"')) print('"'"'n selected:'"'"', len(sel), '"'"'unique:'"'"', len(set(sel)), '"'"'in-range:'"'"', min(sel)>=0 and max(sel)<182016) selset=set(sel[:8]) # load a few top + a few NOT-selected docs top=set(sel[:5]); worst_candidates=set() import itertools texts={} with open('"'"'data/pool.jsonl'"'"') as f: for line in f: r=json.loads(line) texts[r['"'"'id'"'"']]=r['"'"'text'"'"'] print('"'"'=== TOP-5 SELECTED (best first) ==='"'"') for i in sel[:5]: print('"'"'--- id'"'"',i,'"'"'---'"'"'); print(texts[i][:350].replace(chr(10),'"'"' '"'"')); print() # show some low-ranked (near cut) and some never-selected notsel=[i for i in range(182016) if i not in set(sel)] print('"'"'=== 3 NOT-SELECTED (rejected) ==='"'"') for i in notsel[:3]: print('"'"'--- id'"'"',i,'"'"'---'"'"'); print(texts[i][:300].replace(chr(10),'"'"' '"'"')); print() " ' < /dev/null && pwd -P >| /tmp/claude-9687-cwd
1225 python3 -c import json, numpy as np sel=json.load(open('submission/selection.json')) print('n selected:', len(sel), 'unique:', len(set(sel)), 'in-range:', min(sel)>=0 and max(sel)<182016) selset=set(sel[:8]) # load a few top + a few NOT-selected docs top=set(sel[:5]); worst_candidates=set() import itertools texts={} with open('data/pool.jsonl') as f: for line in f: r=json.loads(line) texts[r['id']]=r['text'] print('=== TOP-5 SELECTED (best first) ===') for i in sel[:5]: print('--- id',i,'---'); print(texts[i][:350].replace(chr(10),' ')); print() # show some low-ranked (near cut) and some never-selected notsel=[i for i in range(182016) if i not in set(sel)] print('=== 3 NOT-SELECTED (rejected) ===') for i in notsel[:3]: print('--- id',i,'---'); print(texts[i][:300].replace(chr(10),' ')); print()
1416 /bin/bash -c source /logs/agent/sessions/shell-snapshots/snapshot-bash-1785813778825-pa4rq7.sh 2>/dev/null || true && shopt -u extglob 2>/dev/null || true && { \builtin unalias -- 'unsetenv'; \builtin unset -f -- 'unsetenv'; } >/dev/null 2>&1 || true && eval 'ls -la /tmp/claude-0/-workspace/4bb4d0fa-198e-4747-8902-b67961f6b67a/tasks/b8yv1ek1i.output; echo "---running?"; pgrep -af "python3 -c" | head; sleep 10; echo "=== output ==="; cat /tmp/claude-0/-workspace/4bb4d0fa-198e-4747-8902-b67961f6b67a/tasks/b8yv1ek1i.output' < /dev/null && pwd -P >| /tmp/claude-7013-cwd
=== output ===
[stdout]
-rw-r--r-- 1 root root 0 Aug 4 03:34 /tmp/claude-0/-workspace/4bb4d0fa-198e-4747-8902-b67961f6b67a/tasks/b8yv1ek1i.output
---running?
1223 /bin/bash -c source /logs/agent/sessions/shell-snapshots/snapshot-bash-1785813778825-pa4rq7.sh 2>/dev/null || true && shopt -u extglob 2>/dev/null || true && { \builtin unalias -- 'unsetenv'; \builtin unset -f -- 'unsetenv'; } >/dev/null 2>&1 || true && eval 'cd /workspace; python3 -c " import json, numpy as np sel=json.load(open('"'"'submission/selection.json'"'"')) print('"'"'n selected:'"'"', len(sel), '"'"'unique:'"'"', len(set(sel)), '"'"'in-range:'"'"', min(sel)>=0 and max(sel)<182016) selset=set(sel[:8]) # load a few top + a few NOT-selected docs top=set(sel[:5]); worst_candidates=set() import itertools texts={} with open('"'"'data/pool.jsonl'"'"') as f: for line in f: r=json.loads(line) texts[r['"'"'id'"'"']]=r['"'"'text'"'"'] print('"'"'=== TOP-5 SELECTED (best first) ==='"'"') for i in sel[:5]: print('"'"'--- id'"'"',i,'"'"'---'"'"'); print(texts[i][:350].replace(chr(10),'"'"' '"'"')); print() # show some low-ranked (near cut) and some never-selected notsel=[i for i in range(182016) if i not in set(sel)] print('"'"'=== 3 NOT-SELECTED (rejected) ==='"'"') for i in notsel[:3]: print('"'"'--- id'"'"',i,'"'"'---'"'"'); print(texts[i][:300].replace(chr(10),'"'"' '"'"')); print() " ' < /dev/null && pwd -P >| /tmp/claude-9687-cwd
1225 python3 -c import json, numpy as np sel=json.load(open('submission/selection.json')) print('n selected:', len(sel), 'unique:', len(set(sel)), 'in-range:', min(sel)>=0 and max(sel)<182016) selset=set(sel[:8]) # load a few top + a few NOT-selected docs top=set(sel[:5]); worst_candidates=set() import itertools texts={} with open('data/pool.jsonl') as f: for line in f: r=json.loads(line) texts[r['id']]=r['text'] print('=== TOP-5 SELECTED (best first) ===') for i in sel[:5]: print('--- id',i,'---'); print(texts[i][:350].replace(chr(10),' ')); print() # show some low-ranked (near cut) and some never-selected notsel=[i for i in range(182016) if i not in set(sel)] print('=== 3 NOT-SELECTED (rejected) ===') for i in notsel[:3]: print('--- id',i,'---'); print(texts[i][:300].replace(chr(10),' ')); print()
1416 /bin/bash -c source /logs/agent/sessions/shell-snapshots/snapshot-bash-1785813778825-pa4rq7.sh 2>/dev/null || true && shopt -u extglob 2>/dev/null || true && { \builtin unalias -- 'unsetenv'; \builtin unset -f -- 'unsetenv'; } >/dev/null 2>&1 || true && eval 'ls -la /tmp/claude-0/-workspace/4bb4d0fa-198e-4747-8902-b67961f6b67a/tasks/b8yv1ek1i.output; echo "---running?"; pgrep -af "python3 -c" | head; sleep 10; echo "=== output ==="; cat /tmp/claude-0/-workspace/4bb4d0fa-198e-4747-8902-b67961f6b67a/tasks/b8yv1ek1i.output' < /dev/null && pwd -P >| /tmp/claude-7013-cwd
=== output ===
[metadata] {"noOutputExpected": false}Output is block-buffered (still running). Let me wait for it.
args
{
"command": "sleep 15; cat /tmp/claude-0/-workspace/4bb4d0fa-198e-4747-8902-b67961f6b67a/tasks/b8yv1ek1i.output",
"description": "Wait for buffered inspection output"
}Bash result
(Bash completed with no output)
[metadata] {"noOutputExpected": false}encrypted chain-of-thought — recorded, not exposed
args
{
"command": "pkill -f \"python3 -c\" 2>/dev/null; sleep 1; echo \"killed; re-running with flush\"; cd /workspace\npython3 -u -c \"\nimport json\nsel=json.load(open('submission/selection.json'))\nprint('n',len(sel),'unique',len(set(sel)),'range',min(sel),max(sel),flush=True)\nselset=set(sel)\ntexts={}\nwith open('data/pool.jsonl') as f:\n for line in f:\n r=json.loads(line); texts[r['id']]=r['text']\nprint('=== TOP-4 SELECTED ===',flush=True)\nfor i in sel[:4]:\n print('id',i,'::',texts[i][:280].replace(chr(10),' '),flush=True)\nprint('=== 4 REJECTED ===',flush=True)\nc=0\nfor i in range(182016):\n if i not in selset:\n print('id',i,'::',texts[i][:220].replace(chr(10),' '),flush=True); c+=1\n if c>=4: break\n\"",
"description": "Re-run inspection unbuffered"
}Bash result · error
Exit code 144
[error] tool reported failure