feat: classifier_sft — a convention-based decision/classification-head harness #160
All Vouch review confidence checks passed
Residual risk 0.21 = Change Risk (0.52) × (1 − Review Confidence (0.60)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.52 · 650 lines diff across 8 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.388
Shallow Review Depth
shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #160"
general
weight: 0.35
xingliu-netizen
Summary
A
classifier_sftalgorithm: a thin, convention-based trainer that fine-tunes a decision/classification head on any recognized backbone — covering the growing OSS "decision model" space (Laya-class models) without vendoring packages or per-model code branches. Distinct fromembedding_sft(contrastive embedding space); this trains a head and produces per-class logits (calibration is an eval-time step). Best choice for a fixed, known label set.Design: extend by convention + config, not integrations
Layer 1 —
taskselector over native HF Auto classes (the decision primitives):|
task| Auto class | use ||---|---|---|
|
sequence_classification(default) |AutoModelForSequenceClassification| fixed-label classification, yes/no ||
multiple_choice|AutoModelForMultipleChoice| pick-one-of-K (dynamic options per example) ||
token_classification|AutoModelForTokenClassification| span / entity extraction (GLiNER-style) |Layer 2 — custom models out-of-the-box, vendoring nothing:
trust_remote_code+revisionpinning → a custom architecture whose hub repo ships its own classification-head code viaauto_map(works when that code supports the installed transformers version; see the out-of-the-box sweep below).model_class(dotted path) → a backbone distributed as a pip package (e.g. Laya) loads if the user installs it; this package takes on no dependency.loss_fn(dotted path) → a customloss_fn(logits, labels)callable or aTrainersubclass.Every extension point is a stable HF convention or a user-supplied import — coverage grows with the ecosystem at flat maintenance; nothing hard-coded expires.
Backbones: encoders full fine-tune; decoders via LoRA (
use_peft). String labels auto-encoded to ints; checkpoint savesid2label/label2id+task(label_mapping.json) → inference-ready.Validation (GA stack: transformers 5.17.0, torch 2.13.0, peft 0.20.0)
token_type_idscollation, custom-loss masking, nestedpad_token_id, column / negative / out-of-range label validation, loss-normalization opt-out, metrics entry, CLI wiring.use_pefton ModernBERT (seq + token classification) crash → trains; Qwen3.5-0.8B +use_peftpad-token crash → fits its training set (1.00); custom 2-argloss_fnon mixed-K multiple choice saw padded choices → masked; BERT multiple choicetoken_type_idsdropped → kept; negative label opaque CUDA assert → clear error (token-cls-100still allowed);training_metrics.jsonlmissing → written (strict JSON);seed→ bit-identical (CPU); column fallback/collision → named error / works; token-clsmax_lengthwarnings → 0.use_peftboth fit their training sets; PEFT's per-architecture targets are kept where they exist, elseall-linearwith the head excluded.thub classifier-sft --use-peft true --lora-target-modules Wqkv Wo …applies LoRA to exactly those modules and writes metrics.Out-of-the-box sweep (final pass, head
94204c7)Every family on the as-is support list trained end to end through
classifier_sft(train → reload with the Auto class → finite weights →label_mapping.json+training_metrics.jsonl→ accuracy on a learnable toy set; held-out for multiple choice):| Backbone family (checkpoint tested) | seq-cls | token-cls | multiple choice |
|---|---|---|---|
| ModernBERT (
answerdotai/ModernBERT-base) | ✅ 1.00 | ✅ 1.00 | ✅ 1.00 || BERT (
bert-base-uncased) | ✅ 1.00 | ✅ 1.00 | ✅ 1.00 || RoBERTa (
roberta-base) | ✅ 1.00 | ✅ 1.00 | ✅ 1.00 || DeBERTa-v3 (
deberta-v3-small) | ✅ 1.00 | ✅ 1.00 | ✅ 1.00 || DistilBERT | ✅ 1.00 | ✅ 1.00 | ✅ 1.00 |
| ELECTRA (
electra-small-discriminator) | ✅ 1.00 | ✅ 1.00 | — || XLM-R (
xlm-roberta-base) | ✅ 1.00 | ✅ 1.00 | — || ALBERT / MPNet | ✅ 1.00 / ✅ 1.00 | — | — |
| Qwen2.5 / Qwen3.5 (LoRA) | ✅ 1.00 / ✅ 1.00 | ✅ 1.00 / ✅ 1.00 | n/a (encoder-only) |
| Qwen3, Phi-1.5, OLMo-2, Gemma-3 (LoRA) | ✅ 1.00 each | — | n/a |
| SmolLM2 / Llama arch (LoRA and full FT) | ✅ 1.00 / ✅ 1.00 | — | n/a |
Expected not supported as-is — all fail with a clear error before training: decoder multiple choice (
Unrecognized configuration class …), GLiClass (vendor package →model_class), Jina v3 (its remote code has no classification head). Remote-code repos that don't yet support transformers 5: GTE-v1.5 and Jina v2 (call removed APIs), nomic-embed-text-v1.5 (fails during training).The sweep caught one real bug, fixed in
255cb78: DeBERTa-v3 trained to chance because transformers 5 loads checkpoints in their stored dtype (fp16 for DeBERTa-v3) and AdamW on fp16 weights NaNs on the first step. Optimized weights are now always fp32 (full fine-tune loads fp32; LoRA keeps the frozen base bf16 and upcasts adapters + head).Review items addressed
Round 4 (xingliu-netizen re-test, CodeRabbit outside-diff):
use_peft+ token classification no longer LoRA-wraps the head (all-linearfallback excludesclassifier/score).text_config) getspad_token_idon the text sub-config.loss_fnon multiple choice: padded choices reach the loss with-inflogits; a loss acceptingchoice_maskalso gets the mask.token_type_ids(BERT-family segment ids) through prep + collation.-100ignore marker preserved); multiple-choice labels must index an option.training_metrics.jsonlonly ever contains finite numbers (strict JSON).Round 3 (xingliu-netizen, CodeRabbit):
choice_maskstill excludes them from the softmax.model_accepts_loss_kwargs=Falseon every trainer (all losses here are per-batch means); aTrainersubclass that consumesnum_items_in_batchcan opt out with a class attribute.use_peftworks on ModernBERT / Qwen3.5 — PEFT defaults where they exist, elsetarget_modules="all-linear"; new--lora-target-modulesCLI flag.training_metrics.jsonlwritten (max_steps,global_step,train_loss,epoch,task) for Kubeflow progress.text_column="clean_text"alongside atextcolumn, or swapped names, work.seed—set_seedbefore the head / LoRA are initialized.max_length.is_bf16_supported), so pre-Ampere GPUs fall back to fp32.label_column="category"; LoRA target defaults and the metrics file documented; absolute links.Rounds 1–2: multiple-choice padded-choice masking; NaN/null labels rejected with a counted error; version-safe warmup (
warmup_ratioon 4.x,warmup_stepson 5.x);lora_target_modulesdeclared; lighter multiple-choicemax_k;_align_word_labelsextracted + tested; type hints / full docstring; dropped the never-shippedSequenceClassificationBackendalias.Docs
Algorithm guide (
docs/algorithms/classifier_sft.md), API reference (function/class/backend pages), and README support-matrix + section + sidebar nav.Follow-ups (non-blocking)
merge_default_callbacksintegration — not wired here, consistent withembedding_sft(the JIT/resume callbacks are currently only in the generative algorithmssft/osft/lora). Low priority for a head/embedding trainer.max_kfor very large multiple-choice datasets.🤖 Generated with Claude Code
<!-- This is an auto-generated comment: release notes by coderabbit.ai -->
<!-- coderabbit-ai-generated:v1 -->
Summary by CodeRabbit
New Features
Added classifier fine-tuning for sequence classification, multiple choice, and token classification.
Added the
classifier-sftcommand with options for training settings, task-specific data columns, and model configuration.Added optional LoRA support, custom model classes and loss functions, and automatic encoding of categorical labels.
Training outputs include the model, tokenizer, label mappings, and training metrics. Training is supported on CPU and single- or multi-GPU setups.
Documentation
* Added usage guides and API references for classifier fine-tuning.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->