SAPSFT · 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
- 80.8%
- agent pass rate
- 63K
- longest sample trained
- 279
- trajectories converted
- 8× B200
- sequence-parallel
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.
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.
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
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
- sample 115.8K/16K
- sample 214.6K/16K
- sample 314.6K/16K
- sample 413.1K/16K
- sample 516.0K/16K
- sample 614.2K/16K
- sample 712.7K/16K
- sample 814.8K/16K
- sample 913.4K/16K
- 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.
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.
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.
1def summarize(history, budget):2if (hit := cache.get(key(history, budget))):3return hit4target = budget5for attempt in range(5):6summary = kimi(history, max_tokens=target)7n = count_tokens(summary)8if n <= budget:9return cache.put(key(history, budget), summary)10target = int(target * budget / n * 0.9)11raise SummaryTooLong(n, budget)
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.