mirror of
https://github.com/kvcache-ai/ktransformers.git
synced 2026-11-05 01:07:28 +00:00
[GH-ISSUE #2150] kt-sft: chunked_prefill_size sized from cutoff_len, never scaled by batch — any per_device_train_batch_size>1 hard-errors #1293
Labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
kvcache-ai/ktransformers#1293
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @PUMA-SPz on GitHub (Aug 8, 2026).
Original GitHub issue: https://github.com/kvcache-ai/ktransformers/issues/2150
chunked_prefill_sizeis sized fromcutoff_lenand never scaled by batch sizeComponent:
kt_kernel.sft(kt-kernel 0.6.4) + LLaMA-Factory 0.9.6.dev0Severity: medium — silently caps kt-sft at
per_device_train_batch_size: 1unless the userhappens to inflate
cutoff_len, leaving most of the AMX tile width unused.Summary
kt sizes its prefill buffer from
kt_model_max_length, which LLaMA-Factory populates withcutoff_len— a per-sequence bound. The trainer flattens a batch into a singleqlen, so thebuffer is undersized by exactly the batch factor and any
per_device_train_batch_size > 1raises:with
cutoff_len: 1024,per_device_train_batch_size: 2. Reproduced identically at batch 2, 4 and 8.Chain
wrapper.py:382scales bydistributed_world_sizebut not by per-device batch size — yet batchis precisely what grows
qlenon each rank.The env-var override does not work
ACCELERATE_KT_MODEL_MAX_LENGTHlooks like the escape hatch and is not one:model_args.py:~525-527unconditionally doesos.environ["ACCELERATE_KT_MODEL_MAX_LENGTH"] = str(cutoff_len)~532then doeshf_kt._kt_config.update(...)config.py:228-229only consults the env var when the field is stillNoneSo the user's value is overwritten before kt reads it. A YAML
model_max_length:is likewiseclobbered at
parser.py:609. The only working lever iscutoff_lenitself.(Noting this explicitly because it is the natural thing to try, and it fails silently — the run
proceeds with the old buffer and raises the same error, which reads as if the override did nothing
rather than as if it was overwritten.)
Impact
The AMX consequence is the substantive one. With 256 experts and
num_experts_per_tok: 8, a batch of1 gives each expert's GEMM roughly
against
_AMX_M_STEP = 32(amx.py:46) — so the tile runs ~80% padded. The hardware is being fed6 rows of a 32-row unit. Batch 8 brings M to ~48 and fills it.
Measured on the reporting system (Ornith-1.0-35B, 40 layers, 256 experts, 1x RTX 3090): batch 1 is
0.142 samples/s with the GPU at 9 GB of 24 GB. The idle VRAM is not the constraint; this buffer is.
Suggested fix
Scale by the per-device batch size:
passing
per_device_train_batch_sizethroughget_kt_config_dictalongsidemodel_max_length.Failing that, two cheaper improvements:
ACCELERATE_KT_MODEL_MAX_LENGTHinsteadof overwriting it from
cutoff_len.within bounds. Something like:
"qlen (1168) exceeds chunked_prefill_size (1024); this buffer is sized from cutoff_len and does not account for per_device_train_batch_size=2 — set cutoff_len >= 2048".Workaround
Raise
cutoff_lento at leastbatch_size * longest_padded_sample, rounded up to a multiple of 32so
_aligned_max_len(amx.py:443) is a no-op:Sizing at
batch * cutoff_lenalso works but over-allocates the kt host pools by roughly 50% whensamples are shorter than the cap.
Environment
kt-kernel 0.6.4 · transformers-kt 5.6.0 · accelerate-kt 1.14.0 · torch 2.9.1 · LLaMA-Factory 0.9.6.dev0
FSDP2, 1x RTX 3090, CPU experts on AMX (Xeon Max 9480),
kt_threadpool_count: 2.@yyj6666667 commented on GitHub (Aug 8, 2026):
We will soon deliver the cookbook . please wait.