Repository navigation
Route MLX trainer callbacks through UnslothTrainer - #6929
Conversation
There was a problem hiding this comment.
Code Review
This pull request introduces dynamic inspection of MLXTrainer initialization parameters to determine supported keyword arguments at runtime, allowing UnslothTrainer to filter or reject arguments like callbacks based on the installed version of unsloth-zoo. The test suite has been updated to verify callback support and backward compatibility. Feedback recommends wrapping the signature inspection in a try-except block with pre-initialized defaults to prevent potential import-time failures.
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.
There was a problem hiding this comment.
Pull request overview
Note
Copilot couldn't run its full agentic review because no GitHub Actions runner was available. Make sure your repository has a runner available to run Copilot's review, or add a copilot-setup-steps.yml file specifying one with the runs-on attribute. See the docs for more details.
Routes callbacks= through the public MLX UnslothTrainer wrapper only when the installed unsloth-zoo MLXTrainer supports it, avoiding passing unsupported kwargs to older zoo builds while keeping unsupported hooks like compute_metrics rejected.
Changes:
- Introspects the installed
MLXTrainer.__init__signature to gate which kwargsUnslothTrainerforwards (includingcallbacks). - Filters unsupported MLX trainer kwargs: drops inert/empty values but raises for meaningful unsupported values with a clearer error.
- Expands MLX public trainer API tests to cover
callbacksforwarding vs.compute_metricsrejection.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
unsloth/__init__.py |
Adds MLXTrainer signature introspection + kwarg filtering to safely forward callbacks only when supported. |
tests/python/test_mlx_public_trainer_api.py |
Adds/updates tests for callbacks support gating and compute_metrics remaining unsupported. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
ba447e5 to
4fa188b
Compare
|
@codex review |
|
Codex Review: Didn't find any major issues. 🎉 Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
Summary
callbacks=through the public MLXUnslothTrainerwrapper when the installedunsloth-zooMLXTrainersupports it.compute_metricsrejected on MLX.Companion PR
Tests
PYTHONPATH=/Users/long/Github/unsloth/worktrees/unsloth-mlx-hf-callbacks:/Users/long/Github/unsloth/worktrees/unsloth-zoo-mlx-hf-callbacks python -m pytest tests/python/test_mlx_public_trainer_api.py -q -k 'callbacks or compute_metrics'python -m py_compile unsloth/__init__.py tests/python/test_mlx_public_trainer_api.pygit diff --check