feat(mac): gemma-4 interactive CLI chat on the Kakeya-for-Mac (MLX) engine - #143
Merged
Merged
Conversation
…ngine scripts/chat_mlx_kakeya.py — single-stream (B=1) gemma-4 chat over the Kakeya S5 bounded cache (SinkWindowKVCache): sliding layers bounded to sink+window, full- attn (exact) layers keep full context (S5 free lunch, no f_theta/proposer needed on gemma-4). B=1 sidesteps the MLX B>1,L=1 batched-decode bug. Interactive REPL + --scripted mode (for non-interactive bridge verification) + transcript JSON. Adds mac-bridge preset mlx-kakeya-chat-smoke (scripted 3-turn run) + manifest test (100% coverage, 29 presets). Operator runs the same script without --scripted for a real interactive chat on the Mac. Co-authored-by: FluffyAIcode <FluffyAIcode@users.noreply.github.com>
…rker Smoke run showed the injected <|channel>content marker leaked 'thought' text and caused greedy looping (turns 1/3 repeated). Replace with the chat template's enable_thinking flag (default off → clean direct answers), with a TypeError fallback for templates that don't accept the kwarg. Co-authored-by: FluffyAIcode <FluffyAIcode@users.noreply.github.com>
…ON loops enable_thinking=False gave correct answers but greedy decoding looped on a repeated JSON wrapper. Add mlx_lm repetition penalty via logits_processors (with a TypeError fallback for older mlx_lm signatures). Co-authored-by: FluffyAIcode <FluffyAIcode@users.noreply.github.com>
…es into a repeat The 4-bit gemma-4-it checkpoint appends a repeating json answer-wrapper under greedy; repetition_penalty alone didn't stop it. Add a generic guard: break when a 24-char tail recurs 3+ times, and _trim_loop() keeps only the first occurrence for the stored/displayed text. The (correct) answer is always first. Co-authored-by: FluffyAIcode <FluffyAIcode@users.noreply.github.com>
…swers) _trim_loop over-cut (dropped 'Paris' because the answer text recurs inside the model's json echo). Replace with _is_degenerate_loop: stop ONLY on a true back-to-back repeat (same 16-char block 3x consecutively); never trim stored text. Answer + a single echo is preserved. Co-authored-by: FluffyAIcode <FluffyAIcode@users.noreply.github.com>
…eason (eos/max/loop)
User hit truncation ('断掉') on a long PoW explanation: exactly 256 tokens =
the old default cap. Raise default to 1024 and surface the stop reason each turn
(WARN when it's the max-new-tokens cap), so truncation is obvious and tunable.
Co-authored-by: FluffyAIcode <FluffyAIcode@users.noreply.github.com>
…— output length must not be a user knob
User correctly noted: needing --max-new-tokens to avoid truncation = unusable.
Root cause: <end_of_turn> was dropped from the stop set (old code used encode()+
single-token check on a special token), so the model ran PAST its turn (verbose
JSON echoes / self-correction) until the max-tokens cap — that IS the '断掉' and
the verbosity, same bug. Now resolve stops via tokenizer.eos_token_ids +
convert_tokens_to_ids('<end_of_turn>'/'<eos>'); the cap is only a backstop.
Report eos_token_ids + per-turn stop_reason; smoke now includes a long-answer
prompt to confirm it stops on eos, not max.
Co-authored-by: FluffyAIcode <FluffyAIcode@users.noreply.github.com>
…natural EOS stops first) Co-authored-by: FluffyAIcode <FluffyAIcode@users.noreply.github.com>
… need it; natural EOS stops first) Co-authored-by: FluffyAIcode <FluffyAIcode@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Interactive CLI chat with gemma-4 on the Kakeya-for-Mac engine — the full verifier/proposer/f_θ bounded-memory architecture, on
scripts/research/k3_integrated_niah_eval_mac.py --chat(reuses the validatedfused_specdecode_generate_mlx_trimper-turn sequence; NIAH evidence loop untouched).f_θ runs by DEFAULT in chat (
--force-f-thetaauto-enabled unless--all-mlx-drafter):--chat(no--all-mlx-drafter)--all-mlx-drafter --cuda-trimscripts/chat_mlx_kakeya.pyVerified on Mac M4 (git-bus bridge) — proposer AND f_θ both live, f_θ DEFAULT-on
Without any explicit
--force-f-theta:On gemma-4 the restored sliding K/V are recall-irrelevant (exact layers carry recall — S5 free lunch), yet f_θ executes, exercising the full pipeline. On full-attention models the same f_θ path is load-bearing.
mac_gemma4_kakeya_ftheta_chat.log
ADR
ADR 0015 gains a section "Mac (MLX) interactive engine — full pipeline, f_θ default-ON": documents the engine, the gemma-4 recall-irrelevant-but-runs caveat, the forensic timeline (f_θ S5-bypassed 2026-06-12 by
b3a04d0"Optimize MLX adaptive S5 native smoke path"; proposerblocks=0silent bypass caught by0a6fb19evidence gate), and the measured result.Changes
scripts/research/k3_integrated_niah_eval_mac.py—--chat/--chat-scriptedfull-engine REPL;--force-f-theta(default-ON in chat) bypasses the S5 short-circuit so f_θ runs;_gen_turnbranches over all-MLX + torch paths; reportsf_theta_ran/f_theta_layers/blocks/mean_accept_len.scripts/chat_mlx_kakeya.py— lightweight verifier-only AR chat.inference_engine/bridge/manifest.py— presetsmlx-kakeya-fused-chat-{smoke,ftheta},mlx-kakeya-chat-smoke;MAX_NEW_TOKENS512→2048.docs/adr/0015-…md— Mac interactive engine + f_θ default-on + forensics.tests/inference_engine/bridge/test_manifest.py— preset coverage (31 presets, 100%).Testing
pytest tests/inference_engine/bridge/test_manifest.py— 30 passed, 100% coverage.f_theta_ran=TRUE, 25 sliding layers, no explicit flag), proposerblocks>0, correct answers, bounded KV.To show artifacts inline, enable in settings.