Skip to content

0.3.1a3: segment clustering, MLX multimodal (all stages), tool calls, cache limit - #47

Merged
FonaTech merged 3 commits into
devfrom
router-mask-fix
Nov 8, 2026
Merged

FonaTech merged 3 commits into
devfrom
router-mask-fix

Conversation

@FonaTech

@FonaTech FonaTech commented Nov 8, 2026 •

Copy link
Copy Markdown
Owner

Summary

  • Router fixes: padding is masked from routing and the cluster losses. Telemetry averages all micro-batches. The MLX lazy decode uses the grouped kernel, so it matches full memory exactly.
  • Segment clustering: cluster_locality_mode="segment" scores each document, split at token-0 separators, as 1 − I(segment; cluster)/log C. The default stays "window".
  • MLX cache limit: min(RAM/8, 16 GiB) is applied when an MLX model is constructed. A recipe or env setting can only lower it.
  • MLX multimodal, all six stages:
    • Pretrain, SFT and distill use multimodal_collate. A text-only teacher is accepted.
    • In DPO and ORPO, chosen and rejected share the prompt's media through MultimodalStreamingDPODataset and preference_collate.
    • In GRPO, rollouts condition on the media. It is encoded once and reused per decode step, with identical logits. The update step re-encodes it, so the encoders train.
    • The PyTorch DPO, ORPO and GRPO trainers are text-only. With media, auto routes these stages to MLX, and an explicit PyTorch backend raises an error.
  • Tool calls:
    • Training: the template renders <tools> and <tool_call>, and .lmask carries per-token supervision.
    • Serving: <tool_call> output is parsed into Ollama message.tool_calls and OpenAI tool_calls with finish_reason: "tool_calls", streaming and non-streaming. The stream never leaks partial tags, and requests without tools are unchanged.
  • Monitor and WebUI: ETAs come from measured progress. A stopped run shows its state.
  • Fix: under NumPy 2, .lmask context labels came out as 65436 instead of -100. Labels are now built in int32.

Tests

  • Full suite with MLX on CPU: 489 passed, 1 skipped, 1 deselected. The deselected test (six_stage_loss_paths) segfaults on the MLX CPU backend. Run separately on the GPU, it passes.
  • No-MLX simulation under the CI pins (Python 3.11, numpy 2.4.6, torch 2.10.0): 374 passed, 66 skipped, 0 failed.
  • ruff==0.17.4: clean.
  • New tests:
    • test_tool_call_serving: chunking-invariant parsing, a template round-trip, and both APIs streamed and non-streamed.
    • test_mlx_multimodal_stages: data path, tiling parity, a check that media change the loss, rollout encoder reuse, and run_mlx_stage end to end for dpo, orpo, grpo and distill with checks that fusion and encoder weights move.

🤖 Generated with Claude Code

FonaTech and others added 3 commits November 8, 2026 13:23
… limit

- Router: padding mask, telemetry over all micro-batches, lazy decode
  uses the grouped kernel (fidelity 1.0 at every budget).
- Cluster locality: cluster_locality_mode="segment" learns domain
  clusters per document from content alone (default stays "window").
- MLX: cache limit min(RAM/8, 16 GiB) applied in the kernel; recipe/env
  can only lower it. Multimodal fusion port with Torch parity and
  checkpoint round-trip; pretrain/SFT accept multimodal batches.
- Tools: chat template renders <tools>/<tool_call>; chat_records writes
  per-token .lmask supervision read by SFTRecords; serve passes tools.
- Monitor/WebUI: progress-based ETA per phase; stopped runs show their
  state instead of a clock ETA.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
np.where(mask, uint16_seq, -100) stays uint16 under NEP 50 and wraps
-100 to 65436; cast the sequence to int32 first.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Tool-call inference
- chronos.serving.tool_calls: streaming <tool_call> parser that never
  leaks a partial tag; invalid blocks stay content.
- /api/chat returns Ollama message.tool_calls; /v1/chat/completions
  returns OpenAI tool_calls (string arguments, finish_reason
  "tool_calls"), streamed or not. Requests without tools are unchanged.

Multimodal preference stages on MLX
- DPO/ORPO: chosen and rejected condition on the prompt's media.
- GRPO: rollouts condition on the prompt's media (encoded once, same
  logits); the policy update re-encodes so encoders train.
- Distill: media reach the student; a text-only teacher is accepted.
- Data: MultimodalStreamingDPODataset + preference_collate,
  load_grpo_prompt_records, shared record_media resolver.
- Workbench: media data in DPO/ORPO/GRPO selects MLX under auto; an
  explicit PyTorch backend raises instead of dropping the media.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@FonaTech FonaTech changed the title 0.3.1a3: segment clustering, MLX multimodal, tool-call SFT, cache limit 0.3.1a3: segment clustering, MLX multimodal (all stages), tool calls, cache limit Nov 8, 2026
@FonaTech
FonaTech merged commit 4e5214c into dev Nov 8, 2026
2 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.

1 participant