feat(distill): add tablassert distill-weigh to emit weighted training rows - #183
Merged
Merged
Conversation
…ed training rows The captured corpus knew each run's outcome and could score it, but nothing composed the two into a trainable dataset — the owner had no command to turn `--distill` output into weighted rows for LoRA/QLoRA SFT. `tablassert distill-weigh --distill-dir <corpus> --out train.ndjson`: - Partitions the corpus by CONTENT (`is_outcome_file` reads the first line's `record_type`, so a renamed file still partitions correctly), joins records to outcomes on `run_id` with a consistent last-wins index for both flattening and reward, and refuses derived or mixed files already sitting in the corpus (a previous `train.ndjson` re-ingested would double every example). - Computes `reward` with the resolved RewardConfig and `edge_ref` (corpus median over the same deduped outcome pool unless `--edge-ref`/config overrides, so a superseded duplicate can no longer shift weights), applies the chosen policy (`--policy threshold|best-of-n|replication`), and writes exactly one row per input record with the canonical `TRAIN_ROW_KEYS` schema — `replicas` stays a count; rows are never physically duplicated. - `--purpose agent|all|<live>` filters which recorded calls train (judge and reflexion turns are error-recovery trajectories, not teaching signal); `--final-call-only` keeps each run's most complete conversation and RETAINS rows it cannot rank, warning and counting `unrankable_final_call` instead of silently dropping them. - Writes a deterministic manifest (atomic): resolved reward config, resolved `edge_ref` + source, policy knobs, join stats, `selected_count`, `selected_zero_weight` (best-of-n has no weight floor — an operator must see gated-failed trajectories it would select), `unmatched_count`, nested `distinct` diversity counters before/after selection (fixed to read the flattened `outcome_config_yaml_sha256` column), and absolute source paths. Two identical runs produce byte-identical output and manifest. - Fails loud (exit 2, actionable stderr) on every bad input: missing/empty corpus, malformed NDJSON naming file+line, `matched==0` with the pre-v2 hint, bad policy/knobs/purpose/config, `--out`/`--manifest` naming a directory or colliding or landing inside `--distill-dir`. - Zero-dependency (no `[distill]` extra): stdlib + pyyaml only. This is data selection for supervised fine-tuning, explicitly not RLHF — no reward model, no PPO/GRPO/DPO/KTO, no trainer import. Docs updated in the same commit per the repo's source-of-truth gates: `docs/cli.md` (seven commands, command-table row, full section with every flag/default and the manifest contents), `llms.txt` (token-count and module description), and the two sanctioned `test_docs_cli_coverage.py` registries. Testing: `uv run pytest tests/test_distill_weigh.py -q -n0 --no-cov` -> 36 passed, 0 skipped (base env, no extras); docs SSOT gate -> 167 passed; CLI regression -> 100 passed; `uv run pytest -q` -> 1491 passed, 15 skipped, 0 failed; `uv run pyright` -> 0 errors; ruff check + format --check clean; `mkdocs build --strict` clean. Independent Tier-2 review re-verified all ten repaired findings against source and reproduced the artifact exercises (exit-2 paths, retention counts, diversity counters, key-set invariants).
|
Important
This repository does not receive automatic reviews because it has fewer than 10 stars. ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Advanced Run ID: Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
SkyeAv
added this pull request to stack #186
September 15, 2026 17:55
tablassert distill-weigh to emit weighted training rows
SkyeAv
marked this pull request as ready for review
September 15, 2026 17:55
SkyeAv
added a commit
that referenced
this pull request
Sep 15, 2026
Cut 19.0.0 and bump the package version in pyproject.toml, CITATION.cff, and uv.lock. Major: five breaking changes ship. The `tablassert` console command now requires the optional `[cli]` extra, since `cyclopts` and `rich` left the base install (#187). Level-one normalization redefines fullmap keys as cleaned Unicode-lowercase, Porter2-normalized, byte-ordered token sets and moves the database to schema v6, so every schema-v5 fullmap is rejected and must be rebuilt (#171, #172, #174, #175, #176). `build-fullmap --aria2c` is gone -- aria2c is used automatically whenever the `[aria2]` extra is installed (#178) -- and `--taxon-allowlist` is gone because the built-in top-100 experimental-taxon allowlist now applies to every build, guarding both reuse paths by `META.taxon_allowlist` identity (#153). Logging now requires the `[log]` extra and is fully disabled without it (#152). Features: `tablassert.net` is a new stdlib-only transient/permanent classification and retry seam shared by the agent and the BABEL downloader (#163, #164), with one bounded jittered retry layer across the inner agent, reflexion, and judge (#167) and machine-readable `error_code` values on skipped checkpoint records (#166). `build-kg` gained an automatic ephemeral shared-prefix TCode cache keyed by content-addressed XXH64 op digests (#155-#159, #161). The `--distill` corpus became schema-uniform v2 with a sibling `outcomes.ndjson`, a deterministic `RewardConfig`-tunable reward, and the new zero-dependency `tablassert distill-weigh` command (#180-#183). `CLASS_FIELD_OVERRIDES` grants the DAKP sparse qualifier stack on the pinned association classes (#188). Fixes: `distill-export` partitions its corpus by content and unions the schema across record files, so a mixed v1/v2 directory no longer CastErrors or silently stringifies a column (#184); BABEL retry warnings survive the loguru sink; PMC downloads are idempotent, atomic, and bounded-parallel (#165); reflexion and judge prompts are hard-bounded (#168). Changelog: - versioned the Unreleased section as 19.0.0 - 2026-09-15 - merged three duplicate `### Added` blocks into one - moved the two `BREAKING:` entries from `### Changed` into `### Breaking Changes` and added a `**Migration:**` note to all five - added PR links to all 17 entries, which carried none - added the missing entries: the distill v2 corpus/reward/distill-weigh stack (#180-#183), the distill-export schema-drift fix (#184), the TCode run-cache detail (#155-#161), and the README badge removal (#154) Docs: none needed here. Every shipped doc change landed with its own PR, and the docs source-of-truth gate passes against the bumped tree. Testing: - make check -> exit 0 - uv run ruff check . -> All checks passed! - uv run pyright -> 0 errors, 0 warnings, 0 informations - uv run pytest -> 1622 passed, 52 skipped - cargo test --manifest-path rust/Cargo.toml -> 156 passed, 0 failed - cargo clippy --all-targets -- -D warnings -> clean - uv lock --check -> resolved 169 packages, lock current - uv run mkdocs build --strict -> exit 0 - docs SSOT + CLI coverage after the changelog edit -> 204 passed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds a seventh subcommand,
tablassert distill-weigh, that composes the corpus into a trainable dataset: joinrecords.ndjson+outcomes.ndjsononrun_id, score each matched row, apply a selection policy, and write flat training rows plus a reproducibility manifest. The missing step between--distilland LoRA/QLoRA SFT — until now nothing turned a recorded corpus into weighted rows.Weigh workflow
tablassert distill-weigh --distill-dir <corpus> --out train.ndjsonwith--policy threshold|best-of-n|replication(-p, defaultthreshold),--threshold0.75,--top-n2,--replication-k2,--reward-configYAML/JSON override,--edge-refbreadth-reference override,--manifest(default<out>.manifest.json).--purpose agent|all|<live>(judge and reflexion turns are error-recovery trajectories, not teaching signal);--final-call-onlykeeps each run's highestcall_indexand retains rows it cannot rank (warns + countsunrankable_final_callinstead of silently dropping them).--edge-ref> configedge_ref> corpus median over the same deduplicated outcome pool (a superseded duplicate can no longer shift weights); the resolved value and its source (derived/overridden/null + warning) land in the manifest.Output contract
TRAIN_ROW_KEYSin order (canonical record keys +outcome_matched+outcome_*columns + selection keys); unknown record keys append after the canonical set rather than being dropped.edge_ref+ source, policy knobs, join stats,selected_count,selected_zero_weight(best-of-n has no weight floor — an operator must see gated-failed trajectories it selects),unmatched_count, nesteddistinctdiversity counters before/after selection (fixed to read the flattenedoutcome_config_yaml_sha256column), absolutesource_files. Two identical runs produce byte-identical output and manifest — no timestamps.os.replace.Fail-loud guards (exit 2, actionable stderr)
--distill-dir(marker keys) and mixed record/outcome files are rejected by content, not filename — a priortrain.ndjsonre-ingested would double every example.--out/--manifestnaming a directory, colliding, or landing inside--distill-dir(export ingests every*.ndjsonthere).matched == 0with the pre-v2 hint, unknown policy/purpose/knob values, unreadable reward config.Docs
docs/cli.md: seven commands, table row, full## distill-weighsection with every flag/default and the manifest contents — same commit, per the repo's docs-SSOT gates.llms.txtupdated to match.Design
pyyamlonly; no[distill]extra required to weigh a corpus.Testing
uv run pytest tests/test_distill_weigh.py -q -n0 --no-cov→ 36 passed, 0 skipped (all three policies, bothedge_refoverride sources, retention counts, exit-2 paths, byte-reproducibility).tests/test_docs_cli_coverage.py tests/test_docs_source_of_truth.py tests/test_docs_examples.py tests/test_agent_docs.py→ 167 passed.uv run pytest -q→ 1512 passed, 15 skipped, 0 failed;uv run pyright→ 0 errors;mkdocs build --strict→ exit 0.