Repository navigation
MLX: keep GRPO/KTO/CPO loss_type defaults and export helpers notebooks import - #18069
Conversation
…_type The MLX trl configs are built with make_dataclass over (_MLXTRLConfig, zoo config). Dataclass fields are collected along the reversed MRO, so UnslothTrainingArguments' copy of every MLXTrainingConfig field hid the zoo config's own default. Since MLXTrainingConfig gained loss_type='nll', GRPOConfig without loss_type raises and KTOConfig / CPOConfig silently train with loss_type='nll'. Re-declare every zoo field whose default differs from MLXTrainingConfig's.
|
@codex review |
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
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". |
|
These are re-exports for the notebooks, so they are meant to be unused inside the module. The check exempts a re-export in a package |
…nsloth GRPO and RL-environment notebooks import check_python_modules, create_locked_down_function and execute_with_time_limit from unsloth, and some notebooks use to_sharegpt or FastQwen2Model. On MLX these raised ImportError. Export the same unsloth_zoo.rl_environments helpers the CUDA path does, a lazy to_sharegpt, and the architecture-specific Fast*Model names as FastLanguageModel aliases, since the MLX loader dispatches on the checkpoint config.
3d52907 to
f38b7fb
Compare
|
Thanks, fixed in |
|
@codex review |
|
Codex Review: Didn't find any major issues. Keep it up! 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". |
… fixed 0.1 s sleep (#18103) `studio/backend/tests/test_anthropic_admission.py` fails intermittently in the Studio `a-f` shard on unrelated PRs (#18045, #18006, #18069, #18075): ``` test_non_streaming_queued_then_admitted E AssertionError: assert 0 == 1 E + where 0 = LlamaAdmissionSnapshot(..., capacity=1, active=1, queued=0, ...).queued test_capacity_enforced_from_effective_parallel_slots E AssertionError: assert (3 == 3 and 3 == 3 and 0 == 1) ``` ## Cause Each of these tests occupies every slot, starts a request as a task, sleeps a fixed 0.1 s and then expects the request to be in the admission queue. On a loaded runner the handler sometimes has not reached the queue within 0.1 s, so the snapshot still shows `queued=0`. The admission code is not at fault; the test raced it. ## Fix `_until_queued(task)` polls the queue snapshot every 10 ms until the request is queued, for up to 5 s. It still fails if the request finishes without ever queueing (`task.done()`) or never queues within the deadline, so a request that skips admission is still caught. It replaces the fixed sleep at all five sites that assert `queued == 1` right after starting the task. The assertions themselves are unchanged. ## Verification - `tests/test_anthropic_admission.py`: 39 passed, twice. - Slow handler simulated locally (`await asyncio.sleep(0.25)` at the top of `anthropic_messages`, not committed): - main: the five queued checks fail (plus `test_uncontended_hot_path_is_fast`, which is meant to catch a slow handler). - this branch: only `test_uncontended_hot_path_is_fast` fails.
|
Review and CI summary for head
|
Summary
Two MLX fixes so more Unsloth notebooks run unchanged on Apple Silicon:
trl.GRPOConfig/KTOConfig/CPOConfigon MLX lost their ownloss_typedefault. Since unsloth-zoo added an SFTloss_type="nll"field toMLXTrainingConfig,GRPOConfig(...)without an explicitloss_typeraisesValueError: Unsloth MLX GRPO: loss_type='nll' is not one of grpo, bnpo, dr_grpo, dapo, andKTOConfig/CPOConfigsilently train withloss_type='nll'instead ofkto/sigmoid. Most GRPO notebooks don't setloss_type, so they all fail at the config cell.unslothon MLX:check_python_modules,create_locked_down_function,execute_with_time_limit,Benchmarker,is_port_open,launch_openenv(the sameunsloth_zoo.rl_environmentslist the CUDA path exports),to_sharegpt, and the architecture-specificFastLlamaModel/FastMistralModel/FastGraniteModel/FastQwen2Model/FastQwen3Model/FastQwen3MoeModel/FastFalconH1Modelnames. These raisedImportErroron MLX.Root cause
The MLX
trl.XConfigclasses are built withdataclasses.make_dataclass(bases=(_MLXTRLConfig, zoo_config)). Dataclass fields are collected along the reversed MRO, soUnslothTrainingArguments' inherited copy of everyMLXTrainingConfigfield is applied after the zoo config subclass and hides any default the zoo config overrides. This was latent untilMLXTrainingConfiggained a field (loss_type) that the preference/RL configs override. The fix re-declares every zoo config field whose default differs fromMLXTrainingConfig's, so the whole class is covered rather than onlyloss_type.The architecture-specific
Fast*Modelnames aliasFastLanguageModel, asFastModel/FastTextModelalready do on MLX: the MLX loader dispatches on the checkpoint config, not the class.Out of scope
from vllm import SamplingParams,model.fast_generate(..., sampling_params=, lora_request=),save_lora/load_lora,use_vllm,vllm_sampling_params) are handled separately.chat_template_kwargs/max_tool_calling_iterationsstay refused: the MLX GRPO trainer has no config-level support for them.Validation
test_trl_config_defaults_match_trl,test_trl_trainers_zoo_implements_are_mappedandtest_hf_argument_parser_builds_the_same_trl_configs(the same three fail on current main). Removing anrl_environmentsexport, mis-aliasingFastQwen2Model, or breakingto_sharegpteach failtest_trl_trainers_zoo_implements_are_mapped.from trl import ...onQwen/Qwen3-0.6B(4-bit + LoRA): GRPO resolvesloss_type='dapo', KTOkto, CPOsigmoid; all train to completion.tests/python/test_mlx_public_trainer_api.py::test_mlx_trainer_accepts_trl_style_positional_argsand::test_mlx_torch_cuda_compatibility_shimfail identically on main and are unrelated.