# `Imp.Clients.MLXLMTrainer`
[🔗](https://github.com/deepfates/imp/blob/v0.18.1/lib/imp/clients/mlx_lm_trainer.ex#L1)

Optional synchronous SFT backend for a pinned local MLX-LM model snapshot.

The trainer ignores the deployment LM supplied to
`Imp.Clients.Trainer.finetune/4`. A successful job contains an official
MLX-LM fused model tree, not merely the LoRA adapter or a changed model name.
Both the adapter and complete fused tree are content-verified before success.

MLX-LM is an external optional dependency, pinned to `0.31.3`. Model inputs
are immutable Hugging Face snapshots: a remote repository name is recorded
for provenance, but the command receives only a local directory whose final
component is the configured 40-character revision.

The commands run through `:runner`: a module exporting `run/3` or a
three-argument function, called with the executable, its arguments and
`timeout:`, `kill_grace_ms:`, `max_output_bytes:` and `cwd:`, the directory
to run in. It returns `{:ok, result}` or `{:error, reason}`.

# `runner`

```elixir
@type runner() ::
  module()
  | (String.t(), [String.t()], keyword() -&gt; {:ok, map()} | {:error, term()})
```

# `t`

```elixir
@type t() :: %Imp.Clients.MLXLMTrainer{
  adapter: module(),
  batch_size: pos_integer(),
  executable: String.t(),
  executable_args: [String.t()],
  fuse_executable: String.t() | nil,
  fuse_executable_args: [String.t()] | nil,
  grad_accumulation_steps: pos_integer(),
  iters: pos_integer(),
  kill_grace_ms: non_neg_integer(),
  learning_rate: number(),
  mask_prompt: boolean(),
  max_output_bytes: pos_integer(),
  max_seq_length: pos_integer(),
  model: String.t(),
  model_path: String.t() | nil,
  model_revision: String.t(),
  num_layers: integer(),
  root: String.t(),
  runner: runner(),
  save_every: pos_integer(),
  seed: integer(),
  server_executable: String.t() | nil,
  server_executable_args: [String.t()] | nil,
  server_host: String.t(),
  server_max_tokens: pos_integer(),
  server_port: :inet.port_number(),
  server_startup_timeout: pos_integer(),
  signature: Imp.Signature.t() | nil,
  stratify_by: [atom() | String.t()],
  timeout: pos_integer(),
  validation_fraction: number()
}
```

# `new`

```elixir
@spec new(keyword()) :: t()
```

Builds a local MLX-LM trainer. No executable or model is loaded until `finetune/4`.

# `verify_job`

```elixir
@spec verify_job(Imp.Clients.TrainingJob.t()) :: {:ok, map()} | {:error, term()}
```

Verifies and returns the durable manifest for a completed MLX-LM training job.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
