mlx-commander 0.3.19__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (35) hide show
  1. mlx_commander-0.3.19/.gitignore +58 -0
  2. mlx_commander-0.3.19/LICENSE +21 -0
  3. mlx_commander-0.3.19/PKG-INFO +437 -0
  4. mlx_commander-0.3.19/README.md +397 -0
  5. mlx_commander-0.3.19/docs/images/screenshot1.png +0 -0
  6. mlx_commander-0.3.19/docs/images/screenshot2.png +0 -0
  7. mlx_commander-0.3.19/mlx_commander/__init__.py +12 -0
  8. mlx_commander-0.3.19/mlx_commander/__main__.py +10 -0
  9. mlx_commander-0.3.19/mlx_commander/bin/mac_picker.m +69 -0
  10. mlx_commander-0.3.19/mlx_commander/cli.py +463 -0
  11. mlx_commander-0.3.19/mlx_commander/converter.py +177 -0
  12. mlx_commander-0.3.19/mlx_commander/exceptions.py +39 -0
  13. mlx_commander-0.3.19/mlx_commander/formats.py +379 -0
  14. mlx_commander-0.3.19/mlx_commander/gui_picker.py +246 -0
  15. mlx_commander-0.3.19/mlx_commander/loader.py +1192 -0
  16. mlx_commander-0.3.19/mlx_commander/lora/__init__.py +57 -0
  17. mlx_commander-0.3.19/mlx_commander/lora/config.py +249 -0
  18. mlx_commander-0.3.19/mlx_commander/lora/estimator.py +232 -0
  19. mlx_commander-0.3.19/mlx_commander/lora/model_info.py +401 -0
  20. mlx_commander-0.3.19/mlx_commander/lora/queue.py +212 -0
  21. mlx_commander-0.3.19/mlx_commander/lora/runner.py +168 -0
  22. mlx_commander-0.3.19/mlx_commander/lora/tracking.py +235 -0
  23. mlx_commander-0.3.19/mlx_commander/mcp_server.py +308 -0
  24. mlx_commander-0.3.19/mlx_commander/splitter.py +110 -0
  25. mlx_commander-0.3.19/mlx_commander/terminal_spawner.py +212 -0
  26. mlx_commander-0.3.19/mlx_commander/tui/__init__.py +7 -0
  27. mlx_commander-0.3.19/mlx_commander/tui/app.py +1504 -0
  28. mlx_commander-0.3.19/mlx_commander/tui/state.py +547 -0
  29. mlx_commander-0.3.19/mlx_commander/tui/widgets.py +1985 -0
  30. mlx_commander-0.3.19/mlx_commander/tui/wizard_fallback.py +631 -0
  31. mlx_commander-0.3.19/mlx_commander.py +24 -0
  32. mlx_commander-0.3.19/pyproject.toml +76 -0
  33. mlx_commander-0.3.19/requirements.txt +2 -0
  34. mlx_commander-0.3.19/run.py +27 -0
  35. mlx_commander-0.3.19/smithery.yaml +14 -0
@@ -0,0 +1,58 @@
1
+ # Byte-compiled / optimized / DLL files
2
+ __pycache__/
3
+ *.py[cod]
4
+ *$py.class
5
+
6
+ # C extensions
7
+ *.so
8
+
9
+ # Distribution / packaging
10
+ .Python
11
+ build/
12
+ develop-eggs/
13
+ dist/
14
+ downloads/
15
+ eggs/
16
+ .eggs/
17
+ lib/
18
+ lib64/
19
+ parts/
20
+ sdist/
21
+ var/
22
+ wheels/
23
+ share/python-wheels/
24
+ *.egg-info/
25
+ .installed.cfg
26
+ *.egg
27
+ MANIFEST
28
+
29
+ # Virtual environments
30
+ .venv/
31
+ venv/
32
+ ENV/
33
+ env/
34
+
35
+ # macOS system files
36
+ .DS_Store
37
+ .AppleDouble
38
+ .LSOverride
39
+ ._*
40
+
41
+ # Temporary test/scratch files & local datasets
42
+ *.scpt
43
+ func-calling-singleturn.json
44
+ mlx_dataset/
45
+ mlx_out*/
46
+
47
+ # Unit test / coverage
48
+ .coverage
49
+ .coverage.*
50
+ .pytest_cache/
51
+ htmlcov/
52
+
53
+ # IDE & Editor configs
54
+ .idea/
55
+ .vscode/
56
+ *.swp
57
+ *.swo
58
+ *~
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 tomkubik
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,437 @@
1
+ Metadata-Version: 2.5
2
+ Name: mlx-commander
3
+ Version: 0.3.19
4
+ Summary: Convert Hugging Face datasets into Apple MLX formats, configure parameters, and run training and fine-tuning via interactive TUI and CLI
5
+ Project-URL: Homepage, https://github.com/tomkubik/mlx_commander
6
+ Project-URL: Repository, https://github.com/tomkubik/mlx_commander.git
7
+ Author: Tom Kubik
8
+ License-Expression: MIT
9
+ License-File: LICENSE
10
+ Classifier: License :: OSI Approved :: MIT License
11
+ Classifier: Operating System :: MacOS
12
+ Classifier: Operating System :: POSIX :: Linux
13
+ Classifier: Programming Language :: Python :: 3
14
+ Classifier: Programming Language :: Python :: 3.10
15
+ Classifier: Programming Language :: Python :: 3.11
16
+ Classifier: Programming Language :: Python :: 3.12
17
+ Classifier: Programming Language :: Python :: 3.13
18
+ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
19
+ Requires-Python: >=3.10
20
+ Provides-Extra: all
21
+ Requires-Dist: datasets>=2.14.0; extra == 'all'
22
+ Requires-Dist: duckdb>=0.9.0; extra == 'all'
23
+ Requires-Dist: mcp>=1.0.0; (python_version >= '3.10') and extra == 'all'
24
+ Requires-Dist: pyarrow>=12.0.0; extra == 'all'
25
+ Requires-Dist: pylance>=0.10.0; extra == 'all'
26
+ Requires-Dist: wandb>=0.16.0; extra == 'all'
27
+ Provides-Extra: arrow
28
+ Requires-Dist: pyarrow>=12.0.0; extra == 'arrow'
29
+ Provides-Extra: duckdb
30
+ Requires-Dist: duckdb>=0.9.0; extra == 'duckdb'
31
+ Provides-Extra: lance
32
+ Requires-Dist: pylance>=0.10.0; extra == 'lance'
33
+ Provides-Extra: mcp
34
+ Requires-Dist: mcp>=1.0.0; (python_version >= '3.10') and extra == 'mcp'
35
+ Provides-Extra: parquet
36
+ Requires-Dist: pyarrow>=12.0.0; extra == 'parquet'
37
+ Provides-Extra: wandb
38
+ Requires-Dist: wandb>=0.16.0; extra == 'wandb'
39
+ Description-Content-Type: text/markdown
40
+
41
+ # MLX_Commander ๐Ÿš€
42
+
43
+ A fast, persistent dual-panel TUI (Norton Commander style) & CLI converter for preparing Hugging Face datasets into Apple Silicon MLX fine-tuning formats (`mlx-lm`).
44
+
45
+ Built entirely with Python's standard library `curses` with zero mandatory dependencies and zero pre-compiled binaries.
46
+
47
+ ![Orthodox TUI which makes MLX defaults explicit](docs/images/screenshot1.png)
48
+
49
+ *Orthodox TUI which makes MLX defaults explicit*
50
+
51
+ ---
52
+
53
+ ## ๐ŸŒŸ Key Features
54
+
55
+ - **Persistent Multi-Panel TUI (Norton Commander style)**: Full keyboard navigation (`Tab` to switch panels, `โ†‘`/`โ†“` to navigate, `Enter` to edit/open dropdowns, `F5` to convert).
56
+ - **AI Agent Skill & TUI Pre-Population**: Coding agents (Antigravity, Claude, Cursor) can inspect dataset schemas, pre-populate format, column mappings, and splits, and launch the TUI for split-second visual confirmation.
57
+ - **macOS Terminal.app Spawner**: Seamless handoff from non-interactive agent environments to an interactive TUI window via AppleScript.
58
+ - **Model Context Protocol (MCP) Server**: Native stdio MCP server exposing dataset inspection, TUI launching, and headless conversions to Claude Desktop and Cursor.
59
+ - **Machine-Readable Manifest (`mlx_manifest.json`)**: Emits structured output with file paths, row counts, and copy-paste `mlx_lm.lora` commands for automated downstream pipelines.
60
+ - **Multi-File Selection & Dataset Merging**: Select multiple dataset files at once (e.g. combining pre-split `train.jsonl` and `test.jsonl`). Verifies that all files have identical column schemas and merges them so you can randomize fresh Train / Validation / Test sets from scratch with a custom seed.
61
+ - **Multi-Column Concatenation**: Tap `Space` to multi-select and order columns from the original dataset (e.g. `instruction + input`) to concatenate them seamlessly with `\n\n`.
62
+ - **Live Reactive Preview**: Sample records format in real time as you change target formats or adjust column mappings.
63
+ - **Instantaneous ESC Response**: Curses escape delay configured to 25ms (< 1 frame), making modal dismissal instantaneous while preserving arrow and function keys.
64
+ - **Native macOS Cocoa Finder Picker**: Seamlessly select dataset folders or files via native macOS dialogs (compiled on the fly in `/tmp` with zero checked-in binaries).
65
+ - **Supported MLX Formats**:
66
+ 1. **Text Format**: `{"text": "..."}` โ€” Causal LM / pre-training (single column, concatenated columns, or custom template).
67
+ 2. **Chat / Messages Format**: `{"messages": [{"role": "system|user|assistant", "content": "..."}]}` โ€” Supports message lists (standard role/content or ShareGPT `from`/`value`), or separate role columns.
68
+ 3. **Prompt & Completion Format**: `{"prompt": "...", "completion": "..."}` โ€” Q&A / instruction fine-tuning (`mlx_lm.lora --mask-prompt` compatible).
69
+ 4. **DPO / Preference Format**: `{"prompt": "...", "chosen": "...", "rejected": "..."}` โ€” Direct Preference Optimization.
70
+ - **Flexible Data Loader**: Parquet (`.parquet`), Arrow (`.arrow`), Hugging Face `save_to_disk` directories, JSONL (`.jsonl`), JSON arrays (`.json`), CSV (`.csv`), TSV (`.tsv`), SQLite (`.sqlite`, `.db`), and WebDataset (`.tar`).
71
+ - **Deterministic Splits & Random Seed**: Customizable Train / Validation / Test percentages with 100% reproducible shuffling via random seed.
72
+ - **Ready-to-Use `mlx_lm.lora` Command**: Generates the exact training command ready to copy-paste.
73
+ - **CLI Wizard & Headless Modes**: Run line-by-line via `--wizard` or fully automated via headless CLI flags.
74
+
75
+ ![Inspired by Norton Commander, with a classic color scheme available in TUI](docs/images/screenshot2.png)
76
+
77
+ *Inspired by Norton Commander, with a classic color scheme available in TUI*
78
+
79
+ ---
80
+
81
+ ## ๐Ÿ“ฆ Quick Start
82
+
83
+ ### 1. Launch MLX Commander (Default)
84
+
85
+ Launch the interactive dashboard using any of these equivalent commands:
86
+
87
+ ```bash
88
+ # Install via pip from PyPI and run anywhere:
89
+ pip install mlx_commander
90
+ mlx_commander
91
+
92
+ # Or install with all format extras (Parquet, Arrow, DuckDB, Lance, MCP):
93
+ pip install "mlx_commander[all]"
94
+ mlx_commander
95
+
96
+ # Or run instantly without installation via uvx:
97
+ uvx mlx_commander
98
+
99
+ # Or install globally as a tool via uv:
100
+ uv tool install mlx_commander
101
+ mlx_commander
102
+
103
+ # Recommended for local repository execution (Primary):
104
+ python3 mlx_commander.py
105
+
106
+ # Or via secondary compatibility alias:
107
+ python3 run.py
108
+
109
+ # Or as a Python package module:
110
+ python3 -m mlx_commander
111
+ ```
112
+
113
+ You can also pass arguments directly (e.g. pre-loading a dataset or multiple files):
114
+ ```bash
115
+ python3 mlx_commander.py -d /path/to/my_hf_dataset
116
+ # Or combine multiple files:
117
+ python3 mlx_commander.py -d train.jsonl test.jsonl
118
+ # (python3 run.py accepts all the same arguments)
119
+ ```
120
+
121
+ ### 2. Line-by-Line Wizard Mode
122
+
123
+ For SSH sessions or non-curses environments:
124
+
125
+ ```bash
126
+ python3 mlx_commander.py --wizard
127
+ ```
128
+
129
+ ### 3. Direct Command-Line Conversion (Automated / Headless)
130
+
131
+ You can pass all options via flags for direct scripted conversions:
132
+
133
+ ```bash
134
+ python3 mlx_commander.py \
135
+ --dataset /path/to/my_hf_dataset \
136
+ --format prompt_completion \
137
+ --prompt-col instruction \
138
+ --completion-col output \
139
+ --output ./mlx_data \
140
+ --train 80 \
141
+ --valid 10 \
142
+ --test 10 \
143
+ --seed 42
144
+ ```
145
+
146
+ ---
147
+
148
+ ## ๐Ÿ–ฅ๏ธ Command Line Reference
149
+
150
+ ```
151
+ usage: mlx_commander [-h] [-v] [-d DATASET [DATASET ...]]
152
+ [-f {text,chat,prompt_completion,dpo}]
153
+ [-o OUTPUT] [--train TRAIN] [--valid VALID] [--test TEST]
154
+ [--seed SEED] [--keep-splits] [--mapping MAPPING]
155
+ [--text-col TEXT_COL] [--text-template TEXT_TEMPLATE]
156
+ [--prompt-col PROMPT_COL] [--completion-col COMPLETION_COL]
157
+ [--messages-col MESSAGES_COL] [--user-col USER_COL]
158
+ [--assistant-col ASSISTANT_COL] [--system-col SYSTEM_COL]
159
+ [--chosen-col CHOSEN_COL] [--rejected-col REJECTED_COL]
160
+ [--commander] [--wizard]
161
+ ```
162
+
163
+ ### Key Flags:
164
+
165
+ | Flag | Description |
166
+ |---|---|
167
+ | `-d`, `--dataset` | Path to HF dataset directory or file on disk (`.arrow`, `.parquet`, `.jsonl`, `.json`, `.csv`). |
168
+ | `-f`, `--format` | Target MLX format (`text`, `chat`, `prompt_completion`, `dpo`). |
169
+ | `-o`, `--output` | Destination directory where `train.jsonl`, `valid.jsonl`, and `test.jsonl` are saved. |
170
+ | `--train` | Percentage of data for training (e.g. `80.0`). |
171
+ | `--valid` | Percentage of data for validation (e.g. `10.0`). |
172
+ | `--test` | Percentage of data for test (e.g. `10.0`, or `0` to omit). |
173
+ | `--seed` | Integer random seed for reproducible random shuffling. |
174
+ | `--keep-splits` | Preserve existing dataset splits without re-splitting. |
175
+ | `--text-col` | Column to use as `text` for `text` format. |
176
+ | `--text-template`| Template string with `{column_name}` variables for `text` format. |
177
+ | `--prompt-col` | Column to map to `prompt`. |
178
+ | `--completion-col` | Column to map to `completion`. |
179
+ | `--messages-col` | Column containing conversation turns list for `chat` format. |
180
+ | `--user-col` | Column for user turn in multi-column `chat` format. |
181
+ | `--assistant-col`| Column for assistant turn in multi-column `chat` format. |
182
+ | `--system-col` | Column for system prompt in multi-column `chat` format. |
183
+ | `--chosen-col` | Column for preferred response in `dpo` format. |
184
+ | `--rejected-col`| Column for dispreferred response in `dpo` format. |
185
+ | `--manifest-file`| Custom file path where machine-readable `mlx_manifest.json` will be saved. |
186
+ | `--prefill-state`| Pre-populate TUI state from a JSON string or path to JSON file. |
187
+ | `--spawn-terminal`| Launch interactive TUI in an external macOS Terminal window. |
188
+ | `--lora` | Launch TUI directly into LoRA Fine-Tuning mode (Mode 2). |
189
+ | `--run-queue [DIR]`| Execute queued LoRA fine-tuning runs sequentially (default: `mlx_runs`). |
190
+ | `--mcp` | Start Model Context Protocol (MCP) server over stdio. |
191
+ | `--tui` | Force launch full-screen curses TUI. |
192
+ | `--no-tui`, `--cli` | Run line-by-line CLI wizard instead of curses TUI. |
193
+
194
+ ---
195
+
196
+ ## ๐Ÿฆ™ Apple MLX LoRA Fine-Tuning & Queue Orchestration (Mode 2)
197
+
198
+ MLX Commander features a dedicated **LoRA Fine-Tuning Dashboard** alongside Dataset Conversion. Press **`[F2]`** inside the TUI or pass `--lora` from the command line to switch modes.
199
+
200
+ ```bash
201
+ # Launch directly into Mode 2 (LoRA Fine-Tuning):
202
+ mlx_commander --lora
203
+ ```
204
+
205
+ ### 1. Dual-Panel Fine-Tuning Setup
206
+ - **Top Left Panel (Model & Dataset Setup)**:
207
+ - **Base Model Picker**: Instant select from curated 4-bit Apple MLX models (`Llama-3.2-3B`, `Llama-3.1-8B`, `Qwen2.5-7B`, `Mistral-7B`, `Phi-3.5-mini`, etc.) or input custom Hugging Face model IDs and local weights.
208
+ - **Dataset Directory**: Auto-synced from Mode 1 conversion output, or selected via macOS Finder / local path entry.
209
+ - **Method**: Select `lora`, `dora` (Weight-Decomposed Low-Rank Adaptation), or `full`.
210
+ - **Optimizer**: Pick `adamw` or `adam`.
211
+ - **Run Name**: Custom label or auto-generated descriptive run title.
212
+
213
+ - **Top Right Panel (Explicit Hyperparameters & Hardware Estimators)**:
214
+ - **Explicit Hyperparameters**: All 22 MLX fine-tuning parameters made explicit with production defaults: `iters`, `batch_size`, `learning_rate`, `lora_rank`, `lora_alpha`, `lora_dropout`, `max_seq_length`, `num_layers`, `grad_checkpoint`, `mask_prompt`, `save_every`, `steps_per_eval`, and `adapter_path`.
215
+ - **Reactive Implied Number of Epochs**: Automatically calculated via `(iters * batch_size) / total_train_records`.
216
+ - **Unified Memory Estimator**: Detects your exact Apple Silicon chip and physical RAM via `sysctl hw.memsize` and computes peak memory consumption:
217
+ - **`[SAFE]`** (<70% RAM): Ideal headroom for macOS window server and applications.
218
+ - **`[TIGHT]`** (70โ€“85% RAM): Viable, but close to memory pressure thresholds.
219
+ - **`[OOM RISK]`** (>85% RAM): Flags configuration risk and recommends enabling gradient checkpointing or reducing batch size/sequence length before you start training.
220
+ - **Duration & Clock ETA**: Estimates wall-clock training time based on hardware throughput and step count.
221
+
222
+ ### 2. Central Queue & Config Browser
223
+ Queue up multiple experiments (e.g. testing 3 learning rates across 2 models) in a persistent FIFO queue:
224
+ - **`[F6]` Add Run**: Saves current configuration to the queue (`mlx_runs/configs/<run_id>.yaml` and `mlx_runs/queue.json`).
225
+ - **`[c]` Clone**: Duplicate the highlighted run to quickly tweak a single parameter like learning rate or rank.
226
+ - **`[d]` Delete**: Remove a run from the queue.
227
+ - **`[x]` Clear**: Empty the queue.
228
+ - **`[Enter]` Load**: Load any queued run back into the editor form to inspect or modify it.
229
+
230
+ ### 3. Sequential Queue Execution
231
+ > [!IMPORTANT]
232
+ > **Sequential Execution Only**: Running multiple LLM fine-tuning runs simultaneously causes severe unified memory thrashing, swap exhaustion, and macOS `SIGKILL` kernel panics. MLX Commander strictly enforces sequential execution (FIFO).
233
+
234
+ Press **`[F5 Run Queue]`**:
235
+ - MLX Commander automatically spawns an independent macOS Terminal.app window running `mlx_commander --run-queue mlx_runs`.
236
+ - Training stdout, iteration loss, and throughput stream live in the external window.
237
+ - **You may safely close MLX Commander at any time** without interrupting background training.
238
+ - You can also run the queue headless on headless servers or subshells:
239
+ ```bash
240
+ python3 -m mlx_commander --run-queue ./mlx_runs
241
+ ```
242
+
243
+ ---
244
+
245
+ ## ๐Ÿค– AI Agent Integration & MCP Support
246
+
247
+ MLX Commander is designed for the modern AI agent era (**Antigravity**, **Claude Desktop**, **Cursor**, **Zed**, **Cline**).
248
+
249
+ Instead of an agent interrogating users with 10 sequential chat prompts or guessing schemas blindly, agents can **inspect schemas, formulate recommended settings, and launch MLX Commander with pre-populated values**.
250
+
251
+ The user gets a 3-second tactile review with live JSONL preview in the Norton Commander TUI, presses **[F5 Convert]**, and hands control back to the agent with a machine-readable manifest.
252
+
253
+ ### ๐Ÿ”„ The End-to-End Workflow
254
+
255
+ ```mermaid
256
+ sequenceDiagram
257
+ autonumber
258
+ actor User as User (Human Developer)
259
+ participant Agent as AI Agent (Antigravity / Claude / Cursor)
260
+ participant TUI as MLX Commander TUI (macOS Terminal)
261
+ actor MLX as MLX Engine (mlx_lm.lora)
262
+
263
+ User->>Agent: "Convert dataset.parquet and fine-tune Llama 3 on it."
264
+ Agent->>Agent: Inspects schema, picks target format, maps columns & splits
265
+ Agent->>TUI: Launches TUI with pre-populated arguments (--tui --spawn-terminal)
266
+ Note over User,TUI: TUI pops up in macOS Terminal with fields pre-filled & live preview rendered.<br/>User reviews with arrow keys, presses [F5 Convert].
267
+ TUI->>TUI: Converts dataset, writes mlx_dataset/ & mlx_manifest.json
268
+ TUI-->>Agent: Closes window & returns exit code 0
269
+ Agent->>Agent: Reads mlx_manifest.json (split counts, paths, lora command)
270
+ Agent->>User: "Dataset converted (8,000 train / 1,000 valid / 1,000 test). Starting LoRA training..."
271
+ Agent->>MLX: Executes mlx_lm.lora training run
272
+ ```
273
+
274
+ ---
275
+
276
+ ### The Three Architectural Hand-offs
277
+
278
+ #### 1. Hand-off 1: TUI State Pre-Population
279
+ Agents can pre-populate every field of `CommanderState` via CLI flags or a JSON payload:
280
+ - **Via CLI Flags**:
281
+ ```bash
282
+ mlx_commander --tui --spawn-terminal \
283
+ --dataset "./data.parquet" \
284
+ --format chat \
285
+ --messages-col conversations \
286
+ --train 85 --valid 15 \
287
+ --output "./mlx_dataset"
288
+ ```
289
+ - **Via JSON (`--prefill-state`)**:
290
+ ```bash
291
+ mlx_commander --tui --spawn-terminal \
292
+ --prefill-state '{"dataset": "./data.parquet", "format": "prompt_completion", "prompt_col": "question", "completion_col": "answer", "train": 80, "valid": 20}'
293
+ ```
294
+ When launched with pre-fill data, the TUI opens directly with focus on the mappings panel and renders the reactive JSONL preview immediately.
295
+
296
+ #### 2. Hand-off 2: Machine-Readable Manifest Handshake (`mlx_manifest.json`)
297
+ Every conversion automatically outputs `output_dir/mlx_manifest.json` (or to a custom path specified with `--manifest-file <path>`):
298
+
299
+ ```json
300
+ {
301
+ "status": "success",
302
+ "format": "prompt_completion",
303
+ "source_path": "/path/to/source.parquet",
304
+ "output_dir": "/path/to/mlx_dataset",
305
+ "files": {
306
+ "train": {
307
+ "path": "/path/to/mlx_dataset/train.jsonl",
308
+ "filename": "train.jsonl",
309
+ "records": 8000,
310
+ "size_bytes": 1048576
311
+ },
312
+ "valid": {
313
+ "path": "/path/to/mlx_dataset/valid.jsonl",
314
+ "filename": "valid.jsonl",
315
+ "records": 1000,
316
+ "size_bytes": 131072
317
+ },
318
+ "test": {
319
+ "path": "/path/to/mlx_dataset/test.jsonl",
320
+ "filename": "test.jsonl",
321
+ "records": 1000,
322
+ "size_bytes": 131072
323
+ }
324
+ },
325
+ "splits": { "train": 8000, "valid": 1000, "test": 1000 },
326
+ "total_records": 10000,
327
+ "seed_used": 42,
328
+ "mlx_lora_command": "mlx_lm.lora --model mlx-community/Llama-3.2-3B-Instruct-4bit --train --data /path/to/mlx_dataset --mask-prompt --iters 600 --batch-size 4",
329
+ "manifest_path": "/path/to/mlx_dataset/mlx_manifest.json"
330
+ }
331
+ ```
332
+
333
+ - **Exit Code 0**: Conversion succeeded; manifest written.
334
+ - **Exit Code 130**: User cancelled/closed the TUI without converting. If `--manifest-file` was set, writes `{"status": "cancelled"}`.
335
+
336
+ #### 3. Hand-off 3: macOS Terminal.app Spawner
337
+ When invoked by background agent runners (such as IDE extensions, subshells, or MCP daemons) without an active TTY:
338
+ - Passing `--spawn-terminal` (or auto-detected on macOS in non-interactive sessions) executes the TUI in a dedicated macOS `Terminal.app` window via AppleScript.
339
+ - The calling process blocks synchronously until the user converts or exits, then unblocks and returns the exit code and manifest.
340
+
341
+ ---
342
+
343
+ ### Model Context Protocol (MCP) Server
344
+
345
+ MLX Commander includes a built-in MCP server that works over `stdio`.
346
+
347
+ #### 1. Claude Desktop Setup (`claude_desktop_config.json`):
348
+ ```json
349
+ {
350
+ "mcpServers": {
351
+ "mlx_commander": {
352
+ "command": "python3",
353
+ "args": ["-m", "mlx_commander", "--mcp"]
354
+ }
355
+ }
356
+ }
357
+ ```
358
+ *Or via zero-install `uvx`:*
359
+ ```json
360
+ {
361
+ "mcpServers": {
362
+ "mlx_commander": {
363
+ "command": "uvx",
364
+ "args": ["--from", "git+https://github.com/tomkubik/mlx_commander.git", "--with", "mcp", "mlx_commander", "--mcp"]
365
+ }
366
+ }
367
+ }
368
+ ```
369
+
370
+ #### 2. Cursor Setup (`.cursor/mcp.json`):
371
+ ```json
372
+ {
373
+ "mcpServers": {
374
+ "mlx_commander": {
375
+ "command": "python3",
376
+ "args": ["-m", "mlx_commander", "--mcp"]
377
+ }
378
+ }
379
+ }
380
+ ```
381
+
382
+ #### 3. Exposed MCP Tools:
383
+
384
+ | MCP Tool | Description | Arguments |
385
+ |---|---|---|
386
+ | `inspect_dataset` | Inspects columns, total rows, split names, sample records, and auto-detects candidate mappings. | `dataset_path: str` |
387
+ | `launch_conversion_tui` | Pre-populates and opens the TUI in macOS Terminal.app for user review. Returns conversion manifest. | `dataset_path`, `format`, `prompt_col`, `completion_col`, `messages_col`, `train_pct`, `valid_pct`, `test_pct`, `output_dir` |
388
+ | `convert_dataset_headless` | Runs direct headless conversion in background without opening TUI. Returns conversion manifest. | Same arguments as `launch_conversion_tui` |
389
+
390
+ #### 4. Exposed MCP Prompt:
391
+ - **`prepare_dataset_for_mlx`**: Instructs the model on the optimal workflow to inspect the schema, formulate column mappings, and launch the conversion TUI.
392
+
393
+ ---
394
+
395
+ ### Agent Skill (`SKILL.md`)
396
+
397
+ A standardized skill specification is included in the repository:
398
+ - Skill path: [`.agents/skills/mlx-dataset-prep/SKILL.md`](.agents/skills/mlx-dataset-prep/SKILL.md)
399
+
400
+ AI agents that support skill discovery (like **Antigravity**) automatically read this file when users ask to convert datasets or fine-tune models with Apple MLX.
401
+
402
+ ---
403
+
404
+ ## ๐Ÿ› ๏ธ Step-by-Step Wizard Walkthrough
405
+
406
+ 1. **Step 1: Dataset Source**: Select your dataset folder or file on your drive. The tool validates the file, inspects column names, row counts, and existing splits.
407
+ 2. **Step 2: MLX Format**: Choose your target format (`Text`, `Chat / Messages`, `Prompt & Completion`, `DPO / Preference`).
408
+ 3. **Step 3: Column Mapping**: Match dataset columns to MLX fields or enter a formatting template. The tool automatically detects candidate columns.
409
+ 4. **Step 4: Splitting & Seed**: Configure Train / Valid / Test percentages. A random seed is automatically generated, and you can accept it or provide your own.
410
+ 5. **Step 5: Output & Preview**: Specify the destination folder, review a live preview of the formatted JSONL lines, and confirm to write the files.
411
+ 6. **Step 6: Ready to Fine-Tune**: Review written file sizes, row counts, and copy the generated `mlx_lm.lora` fine-tuning command.
412
+
413
+ ---
414
+
415
+ ## ๐Ÿš€ Running Fine-Tuning with Apple MLX
416
+
417
+ Once your dataset is converted, fine-tune an LLM on Apple Silicon with `mlx-lm`:
418
+
419
+ ```bash
420
+ mlx_lm.lora \
421
+ --model mlx-community/Llama-3.2-3B-Instruct-4bit \
422
+ --train \
423
+ --data ./mlx_dataset \
424
+ --mask-prompt \
425
+ --iters 600 \
426
+ --batch-size 4
427
+ ```
428
+
429
+ ---
430
+
431
+ ## ๐Ÿงช Running Unit Tests
432
+
433
+ Run the test suite with Python's built-in `unittest`:
434
+
435
+ ```bash
436
+ .venv/bin/python -m unittest discover -s tests -p "test_*.py" -v
437
+ ```