[claude] LoRA trajectory export and fine-tune launcher (#1103) #1117

Merged
claude merged 1 commits from claude/issue-1103 into main 2026-03-23 18:15:46 +00:00
Collaborator

Fixes #1103

What this adds

AutoLoRA Step 4 of 7 — tooling to convert Timmy session logs into LoRA training data and launch fine-tuning on Apple Silicon.

scripts/export_trajectories.py

Converts session_*.jsonl logs (written by SessionLogger) into mlx-lm ChatML training examples:

  • Groups session entries into (user, assistant) turn pairs
  • Embeds tool calls as <tool_call> XML blocks in assistant turns (Hermes 4 format)
  • Filters trivially short responses
  • Writes ~/timmy-training-data.jsonl

scripts/lora_finetune.py

Wrapper around mlx_lm.lora with project-tuned defaults:

  • Pre-flight checks: Apple Silicon, mlx-lm installed, model path, train data present
  • --dry-run prints the exact command without executing
  • --test runs inference with the trained adapter
  • --fuse merges adapter into base model for Ollama import
  • Default: batch=1, lora-layers=16, iters=1000, lr=1e-5 (conservative for 36 GB M3 Max)

tests/scripts/test_export_trajectories.py

20 unit tests: all passing.

Workflow

# 1. Generate training data
python scripts/export_trajectories.py --verbose

# 2. Prepare training dir
mkdir -p ~/timmy-lora-training
cp ~/timmy-training-data.jsonl ~/timmy-lora-training/train.jsonl

# 3. Fine-tune (~2-8h on M3 Max)
python scripts/lora_finetune.py

# 4. Test
python scripts/lora_finetune.py --test

# 5. Fuse + import to Ollama
python scripts/lora_finetune.py --fuse
Fixes #1103 ## What this adds AutoLoRA Step 4 of 7 — tooling to convert Timmy session logs into LoRA training data and launch fine-tuning on Apple Silicon. ### `scripts/export_trajectories.py` Converts `session_*.jsonl` logs (written by `SessionLogger`) into `mlx-lm` ChatML training examples: - Groups session entries into `(user, assistant)` turn pairs - Embeds tool calls as `<tool_call>` XML blocks in assistant turns (Hermes 4 format) - Filters trivially short responses - Writes `~/timmy-training-data.jsonl` ### `scripts/lora_finetune.py` Wrapper around `mlx_lm.lora` with project-tuned defaults: - Pre-flight checks: Apple Silicon, mlx-lm installed, model path, train data present - `--dry-run` prints the exact command without executing - `--test` runs inference with the trained adapter - `--fuse` merges adapter into base model for Ollama import - Default: batch=1, lora-layers=16, iters=1000, lr=1e-5 (conservative for 36 GB M3 Max) ### `tests/scripts/test_export_trajectories.py` 20 unit tests: all passing. ## Workflow ```bash # 1. Generate training data python scripts/export_trajectories.py --verbose # 2. Prepare training dir mkdir -p ~/timmy-lora-training cp ~/timmy-training-data.jsonl ~/timmy-lora-training/train.jsonl # 3. Fine-tune (~2-8h on M3 Max) python scripts/lora_finetune.py # 4. Test python scripts/lora_finetune.py --test # 5. Fuse + import to Ollama python scripts/lora_finetune.py --fuse ```
claude added 1 commit 2026-03-23 18:15:30 +00:00
feat: add LoRA trajectory export and fine-tune launcher scripts (AutoLoRA Step 4)
Some checks failed
Tests / lint (pull_request) Failing after 16s
Tests / test (pull_request) Has been skipped
97c0d06204
Adds the tooling for Step 4 of the AutoLoRA Sovereignty Loop:
- scripts/export_trajectories.py: converts session JSONL logs into
  mlx-lm ChatML training data, embedding tool calls as <tool_call> blocks
  in assistant turns so the fine-tuned model learns structured tool use
- scripts/lora_finetune.py: wraps mlx_lm.lora/generate/fuse with
  project-specific defaults, pre-flight checks, and dry-run support
- tests/scripts/test_export_trajectories.py: 20 unit tests covering
  entry loading, grouping, tool-call formatting, and full export pipeline

Workflow:
  python scripts/export_trajectories.py --verbose
  cp ~/timmy-training-data.jsonl ~/timmy-lora-training/train.jsonl
  python scripts/lora_finetune.py
  python scripts/lora_finetune.py --test
  python scripts/lora_finetune.py --fuse

Fixes #1103

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
claude merged commit 32a5b092d0 into main 2026-03-23 18:15:46 +00:00
claude deleted branch claude/issue-1103 2026-03-23 18:15:46 +00:00
Sign in to join this conversation.
No Reviewers
No Label
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: Rockachopa/Timmy-time-dashboard#1117