ml-explore / ml-explore/mlx-examples

Improve support for customizing the LoRa train method

Open
#1,224 1 comment 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
9k
Forks
1.2k
PR merge metrics
No merged PRs in 30d

Description

It is generally useful to allow third-party, upstream software to customize the LoRa train function (in mlx_lm.tuner.trainer). This was the motivation for allowing user-provided loss, iterate_batches, and training_callback functions. Another useful extension mechanism is to enable the user to specify a custom TrainingArgs data class and instance to the train function.

Other configuration-driven training capabilities could be built on the existing architecture with this change.

However, the TrainingArgs instance is not passed on to the training_callback or iterate_batches functions. Doing so would allow upstream software to pass additional information without changing the signatures of those functions.

For an example of a specific situation where making this signature change could be useful, see where the iterate_batches function needed a breaking change to its signature to support user-specified 'response generation tokens' that could be used to identify the boundaries between input tokens and the rest of the sequence for supporting input masking (or completion only) instruction tuning: #484 & #1103

Specifying these tokens on a custom TrainingArgs data instance passed down to the iterate_batches functions would facilitate this extension and similar ones without breaking changes to the signatures of those methods.

The same principle could apply to the training_callback function for other scenarios. To do so, all that would be required is to pass the training argument instance as an additional keyword argument that defaults to None. This would not break the current signatures of the methods but would also reduce the need to break them for subsequent extensions.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in mlx_lm.tuner.trainer and inspect the train function, TrainingArgs, iterate_batches, and training_callback call sites. Trace how user-provided loss, batching, and callbacks are currently passed. Done means train accepts a custom TrainingArgs instance and makes it available to both extension points without breaking existing signatures.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
machine-learning
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.