feat: undersample episodes by loss distribution#250
Open
naidenovaleksei wants to merge 11 commits into
Open
Conversation
felixmaximilian
left a comment
Contributor
There was a problem hiding this comment.
- *_loss_only config default to datamodule: yaak/predict. But predict.yaml has no meta/sample_id , only datamodule=yaak/train_debug has it. If used as is, will likely fail.
- (Latent) In-place += in LogitBias* losses. input += self.logit_bias mutates a tensor that, on the LOSS path, is a Rearrange view sharing storage with raw_logits. use input = input + self.logit_bias instead.
- (Nice-to-have) No unit tests for left_join_parquet / drop_overrepresented_by_loss — pure, correctness-critical, testable with in-memory polars frames.
| -- spurious simultaneous brake+gas presses. | ||
| IF( | ||
| "meta/VehicleMotion/brake_pedal_normalized" < 0.05 | ||
| ${oc.select:clamp_brake_pedal,1} = 1 |
Contributor
There was a problem hiding this comment.
Please collect statistics how the new filter affects the number of episodes to ensure we are not accidentally dropping high signal datapoints
| pair_weights * (gram_pred - gram_gt).pow(2) | ||
| ).sum(dim=(1, 2)) | ||
|
|
||
| if self.reduction == "none": |
Contributor
There was a problem hiding this comment.
Make the loss modules honor the full reduction contract they're imitating (Gram: handle "sum"; Focal: expose a real reduction instead of hardcoded .mean()), so reduction_none behaves uniformly and there are no silent fall-throughs (applies to GaussianNLLLoss, LogitBiasCrossEntropyLoss)
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.
Loss-Based Dataset Resampling
This PR adds infrastructure to resample training data based on per-sample loss scores from a previously trained model, flattening the loss distribution so the model sees harder examples more often.
How it works
Score the dataset — run a trained model in inference-only mode using the new
policy_loss_only/pretrained_loss_onlyconfigs. These write a parquet file of per-sample losses indexed bymeta/sample_id.Resample at training time — the training dataset pipeline now has two new steps:
left_join_parquet— joins the sample list with the scores parquet onmeta/sample_iddrop_overrepresented_by_loss— bins samples by mean loss and caps each bin tomax_bin_freq × N, discarding overrepresented low-loss samplesWhat changed
New utilities (
src/rmind/utils/pipeline.py)left_join_parquet: attaches external parquet columns to a DataFrame by keydrop_overrepresented_by_loss: caps loss bins to flatten the loss distribution; no-op if scores aren't presentPer-sample loss in objectives (
components/objectives/)LOSSas a newObjectivePredictionKeycomputed withreduction="none"(per sample, not aggregated)reduction_nonecontext manager inbase.pyto temporarily switch all loss modulespolicy,forward_dynamics,inverse_dynamics, andmemory_extractionpolicy.py:score_logprobwas computing log-prob against the predicted mean instead of the ground truthNew configs
config/inference/yaak/control_transformer/policy_loss_only.yaml— run policy model to score datasetconfig/inference/yaak/control_transformer/pretrained_loss_only.yaml— run pretrained model to score datasetconfig/resampling/policy.yaml/pretrained.yaml— which loss columns to use for resamplingconfig/datamodule/yaak/predict_train.yaml— predict dataloader over the training splitDataset pipeline (
config/_templates/dataset/yaak/train.yaml,train_debug.yaml)clamp_brake_pedalanddrop_pedal_conflict_episodesare now opt-out flags (default on) instead of hardcodedheadings_denoised/headingmoved to the flat SELECT output (was only in spatial join args before)Loss module fixes (
components/loss.py)LogitBiasFocalLoss/LogitBiasCrossEntropyLoss: registerlogit_biasas a proper buffer (survives device moves and serialization); handleNonebias correctlyGramAnchoringLoss: refactored to compute per-sample losses and addedreductionattributePrediction writer (
callbacks/prediction/dataframe.py)final_pathparameter to move the consolidated parquet to a specific output locationUsage