Skip to content

Route MLX trainer callbacks through UnslothTrainer - #6929

Merged
danielhanchen merged 1 commit into
unslothai:mainfrom
Lyxot:fix/mlx-hf-callbacks
Jul 8, 2026
Merged

danielhanchen merged 1 commit into
unslothai:mainfrom
Lyxot:fix/mlx-hf-callbacks

Conversation

@Lyxot

@Lyxot Lyxot commented Jul 7, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • Routes callbacks= through the public MLX UnslothTrainer wrapper when the installed unsloth-zoo MLXTrainer supports it.
  • Uses the installed zoo trainer signature to avoid forwarding newer wrapper kwargs to older zoo builds.
  • Keeps unsupported trainer hooks such as compute_metrics rejected 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.py
  • git diff --check

@Lyxot
Lyxot marked this pull request as ready for review July 7, 2026 08:03
@Lyxot
Lyxot requested a review from danielhanchen as a code owner July 7, 2026 08:03
Copilot AI review requested due to automatic review settings July 7, 2026 08:03

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

Comment thread unsloth/__init__.py Resolved

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

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 kwargs UnslothTrainer forwards (including callbacks).
  • 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 callbacks forwarding vs. compute_metrics rejection.

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.

Comment thread unsloth/__init__.py Resolved
Comment thread unsloth/__init__.py Resolved
Comment thread unsloth/__init__.py Resolved
@danielhanchen

Copy link
Copy Markdown
Member

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. 🎉

Reviewed commit: 4fa188bf82

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

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

@danielhanchen
danielhanchen merged commit 934f879 into unslothai:main Jul 8, 2026
47 checks passed
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