Download code/README.md from Palaestra/pocket-math-ops: direct link, hf CLI and curl.
- Browser
- Download file 9.65 kB
-
https://huggingface.co/datasets/Palaestra/pocket-math-ops/resolve/main/code/README.md
- Command line
-
hf download hf://datasets/Palaestra/pocket-math-ops/code/README.md
-
curl -L -o README.md https://huggingface.co/datasets/Palaestra/pocket-math-ops/resolve/main/code/README.md
Pocket Math
Pocket Math trains VibeThinker-1.5B into the strongest laptop-sized math model we can make on free Kaggle T4s. It uses on-policy distillation from a stronger teacher, then GRPO, then voting with a Python tool. docs/PLAN.md has the goals and the schedule. docs/DECISIONS.md records every design decision and why. docs/PAPER_NOTES.md records every number that may reach the paper.
How a job runs
Each training run, evaluation and check is a job in a queue. A Kaggle session runs whichever job is next, for up to 11 h 15 min. It saves everything to Hugging Face and stops cleanly before Kaggle's 12-hour limit. The next session, on any account, continues from the last save.
queue.yaml (ops repo) ──> Kaggle session picks the first runnable job
│ claims the job's lease (only one session writes a job)
▼
one round = generate (vLLM) → score (teacher) or grade (Math-Verify) → train (LoRA, 2 GPUs)
│ each finished phase is one commit to the job's own HF repo
▼
pm-<job> repo: state.json, ckpt/, metrics.jsonl, round/, milestones/, final/, results/
A crash or a Kaggle timeout loses at most the phase that was running. Two sessions can never write the same job: the lease is a compare-and-swap on the repo's head commit, so a session whose lease expired fails its next write and stops.
Who does what
| Who | Does what | How often |
|---|---|---|
| You | Create the HF organisation, invite friends, review every number before it goes in the paper | Once, then at each gate |
| Friends | Open their copy of the runner notebook and click Save Version | When a session ends, about twice a day per running chain |
| Claude | Queues jobs, publishes code, launches sessions on your account, reads results, makes the gate decisions in docs/PLAN.md, keeps docs/DECISIONS.md current |
Throughout |
Set up once
- Create a Hugging Face organisation. Ours is
Palaestra. - Invite each friend to the organisation with the write role. A write member can write to every repo in the organisation, so any friend can continue a job another friend started.
- Give Claude a classic Write token through the secret prompt. It is kept at
~/.pocket-math-secrets/hf_token, outside the repo. A fine-grained token can't write to repos in a new organisation. - Tell Claude the organisation name and which Kaggle account is yours.
Claude then runs the commands in the next section.
Start the project
These are the first commands, in order. PM_OPS_REPO saves typing.
cd projects/pocket-math
export PM_OPS_REPO=Palaestra/pocket-math-ops HF_TOKEN=$(cat ~/.pocket-math-secrets/hf_token)
python -m pocket_math ops init --org Palaestra # creates the ops and data repos
python -m pocket_math ops publish-code # code snapshot, tagged with the git SHA
python kaggle/make_notebook.py --ops-repo $PM_OPS_REPO # the notebook friends copy
python -m pocket_math ops add data-build data-build.yaml # dev, fast-dev and the pool, built on a GPU
python -m pocket_math ops add smoke smoke.yaml
python -m pocket_math ops add opd-smoke opd-smoke.yaml --needs smoke
python -m pocket_math ops add grpo-smoke grpo-smoke.yaml --needs smoke
python kaggle/launch_own.py secrets # once: token to a private Kaggle dataset
python kaggle/launch_own.py push --ops-repo $PM_OPS_REPO
The data-build job publishes dev.jsonl, fastdev.jsonl, pool.jsonl and the decontamination report to <org>/pocket-math-data. Its manifest (row counts, sha256 values, dataset revisions) is in the job repo under results/manifest.json, and the sha256 values go in docs/PAPER_NOTES.md. To build on a laptop instead, run python -m pocket_math.data build --out data_out --embed-limit 20000 and ops upload-data.
The SFT trace sets for steps 3.1 and 3.4 are built on a laptop (no GPU, about 2 hours, mostly downloads and answer checks) and uploaded where sft-warmup.yaml and sft-tool.yaml read them. Their row counts, filters and sha256 values are in data_out/sft/manifest.json:
python -m pocket_math.traces build --out data_out/sft
python -m pocket_math ops upload-data data_out/sft/warmup.jsonl data_out/sft/tool.jsonl data_out/sft/manifest.json --prefix sft/
After the smoke jobs, Gate 0 picks the teacher. Then the baselines and the training chain go in the queue:
python -m pocket_math ops add eval-vt15-dev eval.yaml --set k=4
python -m pocket_math ops add opd-8k opd-8k.yaml --needs opd-smoke
python -m pocket_math ops add opd-16k opd-16k.yaml --needs opd-8k
python -m pocket_math ops add grpo-16k grpo-16k.yaml --needs opd-16k
Run and watch jobs
python -m pocket_math ops status # every job: status, round, who holds it, last error
python -m pocket_math ops compare eval-a eval-b --cap 32768 # paired bootstrap between two eval jobs
python -m pocket_math ops reset opd-8k # after fixing the cause of a failed job
python -m pocket_math ops set opd-8k optim.lr=3e-5 # change a started job's config (only while no session holds it)
A job that fails twice in a row is marked failed, so no session wastes quota on it. Its traceback is in logs/last_error.txt in the job repo.
To evaluate a training checkpoint while training continues, point an eval job at a milestone:
python -m pocket_math ops add eval-opd8k-r40 eval.yaml \
--set model=Palaestra/pm-opd-8k:milestones/r0040 --set problems=Palaestra/pocket-math-data:fastdev.jsonl
To split a long evaluation across accounts, queue one job per shard with --set shard=[0,4], --set shard=[1,4], and so on.
Add a friend
Send them docs/FRIENDS.md. It takes about 10 minutes once, then one click per session.
Reproduce a result
Every job repo holds what you need to rerun it:
config.jsonis the exact config, frozen when the job first started. Changes made withops setare listed instate.jsonunderconfig_changes.- Every row of
metrics.jsonland everystate.jsonrecordscode_sha, the git commit of the code that wrote it. env/<session>/holdspip freezefor both Python environments andnvidia-smifor every session that ran the job.- Prompts for round
rare a pure function ofseed,epochandcursorinstate.json. Rerunning a round picks the same problems.
The data files are identified by the sha256 values in docs/PAPER_NOTES.md.
Run the tests
pip install -e ".[train,data,dev]"
python -m pytest -q # offline tests, about 5 minutes on a laptop CPU
python -m pytest -q -m network # also downloads dev sets and real tokenizers
ruff check pocket_math tests kaggle
The CPU tests run complete jobs through the real runner with tiny random models: distillation to a final model, a crash in the middle of a round followed by a resume in a new session, and GRPO. They don't cover vLLM, fp16 on a T4 or two-GPU training. The smoke, opd-smoke and grpo-smoke jobs cover those on Kaggle.
Files
pocket_math/runner.pypicks a job, holds its lease and runs it.context.pygives each job its config, repo writer, work directory and deadline.pocket_math/hub.pyholds the job repo store (Hugging Face or local), the lease and the heartbeat.queue.pyreadsqueue.yamland decides what can run.pocket_math/rounds.pyruns the training jobs (opd,grpo,sft,loopfix).phases.pyturns each phase into one subprocess per GPU.pocket_math/generate.py(vLLM or HF, with the Python-tool loop),score.py(teacher log-probs) andtrain.py(one LoRA step undertorchrun) are those subprocesses.pocket_math/losses.pyandmodeling.pyhold the loss and the chunked log-probs.pocket_math/evaluate.pyruns eval jobs.system.pyruns the voting system.smoke.pyandbench.pyrun the Phase 0 checks.pocket_math/grading.py,data.py,decontam.py,voting.py,loops.py,stats.pyandsandbox.pyare the leaf modules.pocket_math/traces.pybuilds the SFT trace sets: it converts each source's traces to our response and tool-call format and filters them.sft_data.pyturns those rows into token rows for training.configs/models.yamlholds how to prompt and sample each model.configs/jobs/*.yamlholds one file per job type.kaggle/bootstrap.pyis the notebook's only code.session.pysets up a session.make_notebook.pywritesrunner.ipynb.launch_own.pystarts sessions on your account.
When something goes wrong
- A job shows
failed. Readlogs/last_error.txtin its repo, fix the cause, publish the code, then runops reset <job>. - A job stays
runningbut nobody runs it. The session died without releasing the lease. The lease expires 45 minutes after the last heartbeat, and then any session can take the job. - vLLM does not start on a T4. The generation phase tries four attention-backend settings in turn and records the one that works in the session log. If all four fail, set
PM_VLLM_SPEC(for examplevllm==0.11.0) inkaggle/session.py's environment and rerun the smoke job. - A session runs out of time. This is normal. The job pauses after its last finished phase, and the next session continues it.