sjakek's picture
Update Hermes-tuned KXL naming and visuals
23a6592 verified
|
raw
history blame
11.3 kB
metadata
license: other
pretty_name: LFM2.5 Hermes Tool Trace Analysis
tags:
  - mlx
  - lfm2_moe
  - tool-use
  - hermes
  - apple-silicon
  - finetuning

LFM2.5 Hermes Tool Trace Analysis

This repository documents a local Mac fine-tuning run for LiquidAI/LFM2.5-8B-A1B aimed at Hermes-style agent tool use.

It contains compact, reproducible artifacts only: configs, manifests, eval JSON, logs, and the focused tool-call repair dataset. Large model checkpoints are released separately under sjakek/LFM-2.5-8B-1B-hermes-ft.

Visual Overview

These figures summarize the main mechanism and results. They are generated from the JSON reports in this repository with scripts/build_visual_assets.py, so the visuals are reproducible rather than hand-drawn.

End-to-end training and export flow

Pipeline overview

The project starts from the BF16 LFM2.5 MoE checkpoint, constructs an int8-expert/BF16-router mixed core, runs grouped MoE expert/router updates for three epochs, uses eval failures to build focused LoRA repair datasets, then validates both MLX and llama.cpp exports.

Why the mixed-quant runtime matters

Memory model

The core memory move is storing MoE experts as int8 while keeping routers and non-expert layers in BF16. This makes the checkpoint small enough to work with locally, but the chart also shows why a naive simultaneous gradient over all experts would still be expensive. The implemented route is grouped semi-full-gradient training: update multiple MoE layers together, then requantize before moving to the next group.

Selecting the grouped training size

Group sweep memory and time

The 10K-token group sweep showed the practical Mac tradeoff. Larger groups improved elapsed time, but group size 11 approached the 60 GB hard stop. The selected run used overlapping groups of four layers with stride three for stability, while the sweep demonstrated that larger grouped updates were mechanically possible on this 64 GB machine.

Dataset filtering at the 10K cap

Dataset filtering at 10K

The token cap is per example. The 10K artifact retained 582 train examples, 29 validation examples, and 26 test examples from the filtered Hermes trace pool after dropping longer rows from the earlier 16K artifact.

Reliability across repair stages

Eval progression

The broad colloquial router attempts preserved structured tool-call parsing but failed to fix terminal/file routing. The successful iter10 repair used structured chat rows with assistant.tool_calls, prompt masking, and the exact fixed Hermes tool schema.

Final fixed-Hermes coverage

Fixed Hermes category eval

The accepted fused MLX checkpoint passed the parser-disabled fixed-Hermes suite across browser, terminal, file, no-tool, and tool-result finalization categories with zero text-tool leaks.

GGUF quant export result

GGUF quant size and quality

The GGUF path exports from a dequantized BF16/HF source, then produces Hermes-tuned KXL quants using stock llama.cpp tensor-type policies and the Hermes/tool-router imatrix. All four released quants passed the same 43-case fixed-Hermes eval at 64K context.

What Was Trained

The run had two stages.

Stage 1 was a local MLX grouped MoE direct-weight fine-tune:

  • Base: LiquidAI/LFM2.5-8B-A1B.
  • Training data: filtered Hermes tool traces derived from DJLougen/hermes-agent-traces-filtered.
  • Token cap: 10K tokens per training example.
  • Train examples: 582.
  • Epochs: 3.
  • Steps: 1,746.
  • Trainable weights: MoE expert projections and routers.
  • Frozen weights: attention, conv layers, embeddings, norms, and dense non-MoE layers.
  • Expert representation: int8 grouped expert path with BF16 router/non-expert checkpoint materialization.
  • Peak observed memory: about 40.43 GB on this Mac.

This is not equivalent to a simultaneous whole-model full fine-tune. It is a grouped semi-full-gradient update over the MoE experts and routers.

Stage 2 was a local MLX LoRA repair pass focused on native LFM tool-call emission:

  • Base checkpoint: step_01746_final.
  • Adapter: rank-16 MLX LoRA.
  • Iterations: 300.
  • Max sequence length: 4K.
  • Learning rate: 5e-6.
  • Repair examples: 392 train / 32 valid / 32 test.
  • Target native tool syntax: <|tool_call_start|>[tool_name(arg="value")]<|tool_call_end|>.

Why The Repair Pass Was Needed

Hermes executes OpenAI-style structured tool_calls. During the first local setup, MLX returned native tool calls as assistant text because the exported tokenizer config did not declare the MLX tool parser:

<|tool_call_start|>[browser_navigate(url="https://www.google.com/search?q=weather+Austin+TX")]<|tool_call_end|>

That is semantically a tool call, but Hermes does not execute it if it arrives only as message.content. The fix is to set tool_parser_type: "pythonic" in tokenizer_config.json, which activates MLX's built-in parser for <|tool_call_start|>[fn(...)]<|tool_call_end|> and returns real message.tool_calls. A small Hermes parser patch remains useful as a safety net for runtimes or model variants that still return native tool syntax as plain text.

Key Eval Results

Model/checkpoint Parser patch Overall Tool cases Parseable tool calls Failures
grouped direct-weight checkpoint disabled 5/6 2/3 2/3 1 tool refusal
LoRA repair adapter disabled 6/6 3/3 3/3 0
fused repair checkpoint disabled 6/6 3/3 3/3 0
8-bit MLX variant disabled 6/6 3/3 3/3 0
6-bit MLX variant disabled 6/6 3/3 3/3 0

Both 8-bit and 6-bit variants also passed a five-prompt generation smoke test with no observed repetition collapse.

After adding tool_parser_type: "pythonic", a live MLX server call with a browser tool returned structured OpenAI-compatible message.tool_calls and finish_reason: "tool_calls" for the repaired fused model.

Colloquial Tool-Router Repair Loop

After the parser metadata fix, the model could return structured OpenAI message.tool_calls, but broader natural prompts still exposed a routing weakness: casual terminal and local-search requests often mapped to browser-style calls.

Three additional local LoRA repair attempts were run:

Attempt Dataset shape Training setup Result
iter02 2,608 train / 212 valid / 213 test text rows LoRA, 800 iters, 4K seq, LR 3e-6 Preserved 12/12 structured suite; colloquial eval stayed 16/20
iter03 same scale, server-shaped tool JSON prompt resumed LoRA, 800 iters, LR 4e-6 Same 16/20 colloquial result
iter04 chat JSONL with tools, prompt masking enabled resumed LoRA, 600 iters, LR 8e-6 Same 16/20 colloquial result

The final parser-disabled structured eval for iter04:

  • Overall: 16/20.
  • Structured tool-call cases: 9/13.
  • No-tool false-positive rate: 0%.
  • Finalization: 3/3.
  • Text-tool leakage: 0.

Persistent failures:

  • run echo hermes-tool-test -> browser_navigate(url="echo hermes-tool-test").
  • pwd in terminal -> browser_navigate(url="pwd").
  • list files here from shell -> non-Hermes bash(command="ls -la").
  • search this repo for browser_navigate -> browser_navigate(...).

Conclusion: the broad text-only adapter loop did not meet the release threshold for colloquial terminal/file routing. These adapters are retained as analysis artifacts only and should not be fused or advertised as final model behavior.

Fixed-Hermes Iter10 Repair

The successful repair was iter10_balanced_holdout_repair_r32. The key correction was training from structured chat rows with assistant.tool_calls, not from raw assistant text alone. This lets the LFM chat template render canonical pythonic tool-call syntax while --mask-prompt trains only assistant completions.

Final MLX fused result with the Hermes parser patch disabled:

Artifact Overall Structured tool calls No-tool cases Text-tool leaks
iter10_fused 43/43 28/28 10/10 0

The fixed-Hermes suite covers browser, terminal, file read/search/write, no-tool hard negatives, and tool-result finalization. The tool surface is the exact Hermes schema exported from the local Hermes checkout; tool names and descriptions were not renamed.

GGUF + llama.cpp Result

The accepted MLX fused checkpoint was dequantized to a BF16 HF/safetensors source and converted to GGUF with current llama.cpp. During conversion, llama.cpp needed a local LFM2/LFM2MoE converter patch for short-conv tensors:

if "conv.conv" in name:
    data_torch = data_torch.squeeze(-1)

Without that patch, conv.conv.weight stayed 3D and llama.cpp failed while loading the BF16 GGUF parent. With the patch, the BF16 parent loaded and generated normally.

Four Hermes-tuned KXL quants were generated from the BF16 parent using stock llama.cpp --tensor-type-file overrides plus a Hermes/tool-router imatrix. They target Unsloth-style XL size/behavior buckets, but are not a claim of byte-identical Unsloth Dynamic 2.0 generation.

GGUF artifact Size llama.cpp 64K fixed-Hermes eval
LFM-2.5-8B-1B-Hermes-Tuned-Q8KXL.gguf 8.6G 43/43
LFM-2.5-8B-1B-Hermes-Tuned-Q6KXL.gguf 7.1G 43/43
LFM-2.5-8B-1B-Hermes-Tuned-Q5KXL.gguf 6.5G 43/43
LFM-2.5-8B-1B-Hermes-Tuned-Q4KXL.gguf 5.7G 43/43

Each llama.cpp eval returned structured OpenAI-compatible message.tool_calls with finish_reason: "tool_calls" for all 28 tool-call cases, and produced no false-positive tool calls on the 10 no-tool cases.

Repository Contents

  • configs/: run configs and local hardware profile.
  • datasets/: dataset split and filtering manifests.
  • evals/: parser-disabled native LFM eval results and generation smoke output.
  • logs/: compact training/fusion/conversion logs.
  • repair_datasets/iter01/: focused native tool-call repair dataset.
  • repair_datasets/iter02_colloquial_router/: colloquial tool-router text dataset.
  • repair_datasets/iter03_colloquial_router_server_template/: server-shaped text dataset.
  • repair_datasets/iter04_colloquial_router_chat_masked/: chat JSONL dataset for prompt-masked LoRA.
  • gguf/: XL quant tensor policies and GGUF export plan.
  • reports/: earlier probes and grouped MoE training reports.
  • release_summary.json: short machine-readable release summary.

Known Limits

  • The eval suite is targeted. Passing it means the release gate was met; it does not prove broad agent reliability outside similar Hermes tool surfaces.
  • The grouped direct-weight stage updated MoE experts and routers, not every model weight simultaneously.
  • The 6-bit release uses MLX whole-checkpoint quantization because stock MLX conversion does not currently expose the exact expert-only mixed quant policy used in the experimental runtime.
  • The Hermes parser patch remains useful as a safety net for runtimes that return valid LFM native tool calls as text rather than structured OpenAI tool_calls.