AboutWorkProjectsNotes
PT

say hi

 © 2026

  • SAPSAPSoftware Developer
    • Fine-tuning
    • Agents & knowledge graph
    • Long-context training data
      • The problem
      • What I built
      • Compaction
      • Sequence parallelism
      • Recompression
      • Fair comparison
  • MiHINMiHINSoftware Engineer

SAPSAPSFT · 2026

Training on agent runs too long to fit.

SAP wanted Gemma-4-12B fine-tuned on real software-engineering agent runs, and the runs were 50K–100K+ tokens. The whole project was one question: how do we fit them under our budget? Compaction was one answer, sequence parallelism the other. The fine-tuned model's agent pass rate went from 65% to 80.8%.

Company
SAP
Team
Research & Innovation
Role
Software Developer
Timeline
2026
65% →
80.8%
agent pass rate
16K →
63K
longest sample trained
279
trajectories converted
8× B200
sequence-parallel
01

Runs too long, too noisy, too lossy.

The source traces had three problems before any training could start. Length was the big one: the question for the whole project was how to fit runs this long under our context and memory budget.

  • Too longRuns were 50K–100K+ tokens, far past what a 16K proof of concept could hold.
  • Too noisyTraces mixed in LLM spans that had nothing to do with the agent's work.
  • Too lossyNotebook preprocessing was silently dropping tool calls, IDs, names and reasoning.
02

From raw traces to a benchmark score.

Two halves: building the data, and evaluating the trained model as an agent. Switch between them, or click any step.

idle
CAP-Bench taskOpenHandsagentLiteLLMsagemaker_chatSageMakerinference componentScoreAWS Batchsecrets

OpenHandsagent

The benchmark's agent, now able to run on a SageMaker-hosted model.

Click any step for details · Run walks a request through each step

03

Lever one: cut the run, keep the meaning.

A tool call and its result are one unit, so a cut never lands between them. When the history won't fit, Kimi summarizes what came before, and the next sample starts from that summary.

Pick a window size. Smaller windows mean more samples, and more compactions to learn from.

this run → 9 samples, 8 compactions

one agent run · 103K tokens

  1. sample 115.8K/16K
  2. sample 214.6K/16K
  3. sample 314.6K/16K
  4. sample 413.1K/16K
  5. sample 516.0K/16K
  6. sample 614.2K/16K
  7. sample 712.7K/16K
  8. sample 814.8K/16K
  9. sample 913.4K/16K
system Kimi summary call + tool result, never split
16K dataset
1,908 samples
1,630 compactions
32K dataset
660 samples
381 compactions
64K dataset
361 samples
82 compactions

The run above is illustrative. The dataset totals are real, from 279 trajectories.

04

Lever two: split the sequence across GPUs.

Compaction shrinks what the model sees. Sequence parallelism handles what's left: one long sample is split across eight B200s, so a 63K-token sample trains where one GPU would run out of memory.

That took us from a 16K proof of concept to samples up to 63,263 tokens. Toggle to compare.

one sample · 63,263 tokens

  • GPU 07.9K tok
  • GPU 17.9K tok
  • GPU 27.9K tok
  • GPU 37.9K tok
  • GPU 47.9K tok
  • GPU 57.9K tok
  • GPU 67.9K tok
  • GPU 77.9K tok

Each GPU holds one eighth of the sequence. They exchange what attention needs, so every token still sees the whole run.

ml.p6-b200.48xlarge · 8× B200 · SP=8, DP=1 · the proof of concept was 16K. Memory fills are illustrative.

05

When the summarizer ignores the limit.

Kimi didn't reliably respect the requested output length. Instead of dropping those samples, the converter retries with a tighter budget. Final summary-length failures: zero.

compact.py · simplified
1def summarize(history, budget):
2 if (hit := cache.get(key(history, budget))):
3 return hit
4 target = budget
5 for attempt in range(5):
6 summary = kimi(history, max_tokens=target)
7 n = count_tokens(summary)
8 if n <= budget:
9 return cache.put(key(history, budget), summary)
10 target = int(target * budget / n * 0.9)
11 raise SummaryTooLong(n, budget)

line 2Summaries are cached, so an interrupted run reused 379 finished calls.

06

Keeping the comparison honest.

Training runs are expensive, so the risks had to be caught before them. I also partnered on a second approach that trains a condenser (history to summary) separately from the agent (summary to next action), to compare against the summary-in-context data.

  • No leakageTask-level, deterministic splits. The 64K set split exactly 326 train to 35 eval.
  • Nothing droppedAll 13,958 agent actions and 15,375 tool calls in the 64K set survived preprocessing.
  • Caught earlyCohort-dependent splits, a missing fuser transform and a notebook config mismatch, found before training.
next case studyMiHIN · Getting healthcare data where it needs to go.