Skip to content

feat(distill): add tablassert distill-weigh to emit weighted training rows - #183

Merged
SkyeAv merged 1 commit into
distill/reward-and-selectionfrom
distill/weigh-cli
Sep 15, 2026
Merged

SkyeAv merged 1 commit into
distill/reward-and-selectionfrom
distill/weigh-cli

Conversation

@SkyeAv

@SkyeAv SkyeAv commented Sep 15, 2026

Copy link
Copy Markdown
Owner

Adds a seventh subcommand, tablassert distill-weigh, that composes the corpus into a trainable dataset: join records.ndjson + outcomes.ndjson on run_id, score each matched row, apply a selection policy, and write flat training rows plus a reproducibility manifest. The missing step between --distill and LoRA/QLoRA SFT — until now nothing turned a recorded corpus into weighted rows.

Weigh workflow

  • tablassert distill-weigh --distill-dir <corpus> --out train.ndjson with --policy threshold|best-of-n|replication (-p, default threshold), --threshold 0.75, --top-n 2, --replication-k 2, --reward-config YAML/JSON override, --edge-ref breadth-reference override, --manifest (default <out>.manifest.json).
  • Filters: --purpose agent|all|<live> (judge and reflexion turns are error-recovery trajectories, not teaching signal); --final-call-only keeps each run's highest call_index and retains rows it cannot rank (warns + counts unrankable_final_call instead of silently dropping them).
  • Edge reference: --edge-ref > config edge_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

  • One row per filtered record, keys exactly TRAIN_ROW_KEYS in order (canonical record keys + outcome_matched + outcome_* columns + selection keys); unknown record keys append after the canonical set rather than being dropped.
  • Deterministic manifest: resolved reward config, 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, nested distinct diversity counters before/after selection (fixed to read the flattened outcome_config_yaml_sha256 column), absolute source_files. Two identical runs produce byte-identical output and manifest — no timestamps.
  • Atomic writes via sibling temp + os.replace.

Fail-loud guards (exit 2, actionable stderr)

  • Corpus integrity: derived training output already inside --distill-dir (marker keys) and mixed record/outcome files are rejected by content, not filename — a prior train.ndjson re-ingested would double every example.
  • Path validation: --out/--manifest naming a directory, colliding, or landing inside --distill-dir (export ingests every *.ndjson there).
  • Input validation: missing/empty corpus, malformed NDJSON naming file + line, matched == 0 with the pre-v2 hint, unknown policy/purpose/knob values, unreadable reward config.

Docs

  • docs/cli.md: seven commands, table row, full ## distill-weigh section with every flag/default and the manifest contents — same commit, per the repo's docs-SSOT gates. llms.txt updated to match.

Design

  • Zero optional dependencies — stdlib + pyyaml only; no [distill] extra required to weigh a corpus.
  • Not RLHF: this is data selection for supervised fine-tuning; no trainer, reward model, or RL import exists anywhere in the command.

Testing

  • uv run pytest tests/test_distill_weigh.py -q -n0 --no-cov → 36 passed, 0 skipped (all three policies, both edge_ref override sources, retention counts, exit-2 paths, byte-reproducibility).
  • Docs gates: 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.
  • Full gate at the stack tip: uv run pytest -q → 1512 passed, 15 skipped, 0 failed; uv run pyright → 0 errors; mkdocs build --strict → exit 0.

…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).
@coderabbitai

coderabbitai Bot commented Sep 15, 2026

Copy link
Copy Markdown

Important

  • 🔍 Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Advanced

Run ID: 57d933e0-0980-418e-92fc-968bc93c449c


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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@SkyeAv
SkyeAv added this pull request to stack #186 September 15, 2026 17:55
@SkyeAv SkyeAv changed the title feat(distill): [US-006] add tablassert distill-weigh to emit weighted training rows feat(distill): add tablassert distill-weigh to emit weighted training rows Sep 15, 2026
@SkyeAv
SkyeAv marked this pull request as ready for review September 15, 2026 17:55
@SkyeAv
SkyeAv merged commit bb338c2 into main Sep 15, 2026
5 checks passed
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant