Skip to content

Update finetuning parameters and improve data splitting logic#1101

Merged
anuragg1209 merged 6 commits into
mainfrom
anurag/fix_ft_example
Jul 14, 2026
Merged

Update finetuning parameters and improve data splitting logic#1101
anuragg1209 merged 6 commits into
mainfrom
anurag/fix_ft_example

Conversation

@anuragg1209

@anuragg1209 anuragg1209 commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

Motivation and Context

  • Retuned examples/finetune_classifier.py (Higgs) and examples/finetune_regressor.py (California housing): LR 1e-5 with lr_warmup_only=True, NUM_EPOCHS=100 with EARLY_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).
  • Introduced _ratio_ctx_query_split so 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/0 now cleanly disables validation: training uses all data, per-epoch evaluation is skipped, and early stopping is downgraded with a log message.
  • The "best model" concept (in-memory restore and 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):

Test ROC AUC ↑ Test Log Loss ↓
Default TabPFN 0.8247 0.5110
Finetuned TabPFN 0.8322 0.5003

examples/finetune_regressor.py (California housing):

Test MSE ↓ Test R² ↑
Default TabPFN 0.1350 0.9018
Finetuned TabPFN 0.1328 0.9034

Public API Changes

validation_split_ratio now accepts None/0 to disable validation; early_stopping is 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.

- 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.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread src/tabpfn/finetuning/finetuned_base.py
Comment thread src/tabpfn/finetuning/data_util.py Outdated
Comment thread src/tabpfn/finetuning/finetuned_base.py
- 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.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 clarified validation_split_ratio behavior (including disabling validation).
  • Introduced _ratio_ctx_query_split to 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.

Comment thread src/tabpfn/finetuning/finetuned_base.py
Comment thread src/tabpfn/finetuning/finetuned_base.py
Comment thread src/tabpfn/finetuning/finetuned_base.py
- 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.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 8 out of 8 changed files in this pull request and generated 2 comments.

Comment thread src/tabpfn/finetuning/finetuned_base.py
Comment thread src/tabpfn/finetuning/finetuned_base.py
@anuragg1209
anuragg1209 marked this pull request as ready for review July 14, 2026 10:39
@anuragg1209
anuragg1209 requested review from bejaeger and removed request for psinger-prior July 14, 2026 11:39
Comment thread src/tabpfn/finetuning/finetuned_base.py

@bejaeger bejaeger left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!
Just one thing, can you please document in the PR description what the new performance gain is for the examples?

@anuragg1209

Copy link
Copy Markdown
Contributor Author

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>
@anuragg1209
anuragg1209 enabled auto-merge July 14, 2026 12:54
@anuragg1209
anuragg1209 added this pull request to the merge queue Jul 14, 2026
Merged via the queue into main with commit 6fce03d Jul 14, 2026
17 checks passed
@anuragg1209
anuragg1209 deleted the anurag/fix_ft_example branch July 14, 2026 13:13
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.

3 participants