Repository navigation
Commit fd50653
feat: Add support for Tinker for finetuning after data is generated with curator (#710)
* Code clean up
* feat: add Tinker SDK integration for LoRA fine-tuning with checkpointing
Integrate the Tinker SDK to enable real LoRA fine-tuning via the Tinker
API. When a TINKER_API_KEY is provided and the tinker package is installed,
training runs against the Tinker service with real forward_backward and
optim_step calls. Without the SDK or key, the trainer falls back to mock
mode for development and testing.
Key changes:
- Wire up ServiceClient, TrainingClient, and SamplingClient from tinker SDK
- Create proper tinker.Datum objects with tokenized chat templates and
assistant-only loss masking
- Add checkpointing support (per-epoch and per-N-steps) via save_state,
with checkpoint paths accessible on the Tinker dashboard
- Add tinker as an optional dependency under the "finetune" extra
- Add examples in examples/tinker/ and examples/poem_finetuning_example.py
- Add comprehensive tests for config, types, data formatter, and trainer
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
* fix: correct multiple Tinker training integration bugs
- Apply causal-LM shift (input=tokens[:-1], target=tokens[1:]) in data
formatter so fine-tunes train on the correct next-token objective
- Fix checkpoint resume: use create_lora_training_client_from_state()
instead of load_state_with_optimizer(), and skip already-completed
steps/epochs in the training loop
- Pass api_key to tinker.ServiceClient() so programmatic config
actually authenticates
- Wire LoRA alpha, dropout, and target_modules to the training client
- Implement gradient accumulation by deferring optim_step until the
configured number of batches have accumulated
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
* fix: use correct Tinker resume API, flush partial grad accum, fix poem example
- Use create_training_client_from_state_with_optimizer() which is the
documented Tinker API for resuming with optimizer state
- Fix end-of-epoch resume: compute loop start bounds upfront (cookbook
pattern) instead of skipping inside loops, preventing ZeroDivisionError
- Flush final partial gradient accumulation window so the last
microbatches are not silently dropped
- Normalize loss by effective target weight instead of total token count
- Fix NameError in poem_finetuning_example.py (dataset -> poem_data)
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
* docs: add Tinker fine-tuning section to README and deduplicate poem example
- Add Fine-Tuning with Tinker section covering basic usage, checkpoint
resume, and custom data formats
- Add poem fine-tuning example to the examples table
- Replace inline duplicate in poem example with call to convert_to_chat_format()
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
* fix: restrict tinker dependency to Python >=3.11
The tinker package requires Python >=3.11 but the project supports
>=3.10, causing poetry lock to fail in CI. Add a python version
marker so the dependency is only resolved for compatible versions.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
* fix: correct top_k=0 truthiness check and deduplicate loss_history entries
- Use `is not None` instead of truthiness check for top_k so that
top_k=0 is passed through correctly instead of being replaced with -1
- Skip appending to loss_history at epoch end when the last step was
already logged by per-step logging, preventing duplicate entries
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>1 parent 2b1904e commit fd50653
20 files changed
Lines changed: 3035 additions & 389 deletions
File tree
- examples
- tinker
- src/bespokelabs/curator
- finetune
- trainer
- tests/finetune
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
62 | 62 | | |
63 | 63 | | |
64 | 64 | | |
| 65 | + | |
65 | 66 | | |
66 | 67 | | |
67 | 68 | | |
| |||
296 | 297 | | |
297 | 298 | | |
298 | 299 | | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
299 | 370 | | |
300 | 371 | | |
301 | 372 | | |
| |||
0 commit comments