Update finetuning parameters and improve data splitting logic#1101
Conversation
- Increased NUM_EPOCHS from 30 to 100 and N_FINETUNE_CTX_PLUS_QUERY_SAMPLES from 30,000 to 50,000 in finetune_classifier.py. - Added EARLY_STOPPING_PATIENCE parameter to enhance training control. - Modified data_util.py to clarify chunk size handling in dataset preprocessing. - Introduced _ratio_ctx_query_split function in finetuned_base.py for better context and query set splitting based on chunk size. - Updated finetuned_classifier.py to reflect changes in finetuning sample sizes and inference subsampling logic.
There was a problem hiding this comment.
Code Review
This pull request updates training hyperparameters and introduces a dynamic context-query splitting mechanism (_ratio_ctx_query_split) to handle variable chunk sizes during finetuning. Feedback on these changes highlights three critical issues: first, _ratio_ctx_query_split can raise a ValueError on small datasets if test_size is not capped; second, the docstring reference to min_chunk_size in get_preprocessed_dataset_chunks is missing an actual parameter implementation, which silently drops small datasets; and third, the learning rate scheduler resets to step 0 when resuming training from a checkpoint instead of initializing with the correct last_epoch.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
- Increased NUM_ESTIMATORS for finetuning, validation, and final inference from 2 to 4 in finetune_classifier.py. - Updated validation_split_ratio documentation in finetuned_base.py, finetuned_classifier.py, and finetuned_regressor.py to clarify its role in early stopping and evaluation. - Improved validation handling logic in finetuned_base.py to allow disabling validation and adjust early stopping behavior accordingly. -Fixed the bug in LR schedular when resuming training.
- Increased NUM_EPOCHS from 30 to 100 in finetune_regressor.py to improve training duration. - Reduced N_FINETUNE_CTX_PLUS_QUERY_SAMPLES from 20,000 to 5,000 to mitigate overfitting. - Added EARLY_STOPPING_PATIENCE parameter to allow for more controlled training termination. - Updated documentation in finetuned_base.py, finetuned_classifier.py, and finetuned_regressor.py to reflect changes in sample sizes and clarify inference subsampling behavior.
There was a problem hiding this comment.
Pull request overview
This PR updates TabPFN fine-tuning defaults and refines the fine-tuning data splitting logic so context/query splits scale with per-epoch chunk sizes, while also allowing validation (and thus early stopping) to be disabled.
Changes:
- Updated fine-tuning defaults (e.g.,
n_finetune_ctx_plus_query_samples=50_000,n_inference_subsample_samples=None) and clarifiedvalidation_split_ratiobehavior (including disabling validation). - Introduced
_ratio_ctx_query_splitto compute query size per chunk (ratio-based) with stratification fallback logic. - Updated examples to use new hyperparameters and revised inference subsampling usage.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| src/tabpfn/finetuning/finetuned_regressor.py | Aligns regressor fine-tuning defaults/docs with new sample sizing and optional validation/subsampling. |
| src/tabpfn/finetuning/finetuned_classifier.py | Aligns classifier fine-tuning defaults/docs with new sample sizing and optional validation/subsampling. |
| src/tabpfn/finetuning/finetuned_base.py | Adds ratio-based per-chunk ctx/query split, optional validation path, scheduler resume tweaks, and adjusted evaluation flow. |
| src/tabpfn/finetuning/data_util.py | Clarifies docstring around chunk remainder handling and min_chunk_size. |
| examples/finetune_regressor.py | Updates example hyperparameters and removes explicit inference subsampling config. |
| examples/finetune_classifier.py | Updates example hyperparameters/ensemble sizes and removes explicit inference subsampling config. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Updated documentation for early stopping in finetuned_base.py to clarify its functionality and impact on model checkpointing. - Improved logic in the training process to ensure that when validation is disabled, only interval checkpoints are saved, and the "best model" concept is not applied. - Added a new test case to validate the behavior of the classifier when fitting without validation, ensuring proper logging and checkpointing behavior. - Adjusted tests for the regressor to reflect similar changes in early stopping and checkpointing logic.
bejaeger
left a comment
There was a problem hiding this comment.
LGTM!
Just one thing, can you please document in the PR description what the new performance gain is for the examples?
I've updated the PR description to include the performance gains for the example scripts. |
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Motivation and Context
examples/finetune_classifier.py(Higgs) andexamples/finetune_regressor.py(California housing): LR 1e-5 withlr_warmup_only=True,NUM_EPOCHS=100withEARLY_STOPPING_PATIENCE=15, ctx+query 50k (classifier) / 5k (regressor), and inference subsampling set to the full training set (the previous 50k default is a v2.5 legacy that silently caps context on large datasets)._ratio_ctx_query_splitso the context/query split is sized per chunk instead of using a fixed absolute query size, which crashed on legitimate remainder chunks smaller than the configured query size.validation_split_ratio=None/0now cleanly disables validation: training uses all data, per-epoch evaluation is skipped, and early stopping is downgraded with a log message.checkpoint_best.pth) now exists only when early stopping is active; without it, the last epoch is the result and only interval checkpoints are saved, recording train loss instead of placeholder validation metrics.Performance of the example scripts
examples/finetune_classifier.py(Higgs):examples/finetune_regressor.py(California housing):Public API Changes
validation_split_rationow acceptsNone/0to disable validation;early_stoppingis documented to also control best-checkpoint saving and best-weights restoration.How Has This Been Tested?
Example scripts run locally on a 4-GPU DDP setup (results above). New/updated unit tests cover the no-validation fit path (evaluation skipped, early stopping downgraded, checkpoint contents), best-checkpoint gating under
early_stopping=False, and checkpoint resumption.