Add AGENTS.md: verified Tesla T4 (16GB) inference notes - #1306
Open
moduvoice wants to merge 2 commits into
Open
Conversation
Documents that the documented CLI OOMs on a 16GB GPU before generating a single token, even for a short input with no reference audio. Root cause (confirmed by reading the code, not guessed): model.setup_caches() always pre-allocates the KV cache sized to config.json's text_config.max_seq_len (32768 for s2-pro), regardless of input length or --max-new-tokens. A config-only fix (lowering that value in the downloaded checkpoint's config.json, no code change) resolves it, verified with 2 successful reproductions after 2 confirmed OOM reproductions with the default config. Also documents the T4 acceleration checklist (dtype, attention backend, int8, CUDA Graphs), all measured on real hardware rather than assumed. No code changes - new documentation file only.
Verified directly: uv sync --extra cu126 correctly resolves torch+cu126, but a subsequent plain 'uv run' (without repeating --extra cu126) silently re-syncs to a different default build (+cu128 in this case). The extra isn't sticky across invocations — pyproject.toml's base dependencies pin bare torch==2.8.0 with no CUDA index, so [tool.uv.sources] only applies while the matching extra flag is present on that specific command.
6 tasks
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
Adds
AGENTS.md— inference notes verified end-to-end on a real Tesla T4 (16GB, Turing,sm_75). No code or behavior changes; this is a new documentation file only.
Why
The docs (
docs/en/install.md,docs/en/inference.md) recommend "at least 24GB" but don't saywhat actually happens on a 16GB card, or why. We ran the documented CLI (
fish_speech/models/text2semantic/inference.py)against the
fishaudio/s2-procheckpoint on a real T4 and found:reference audio. Reproduced twice, identical error both times.
model.setup_caches(..., max_seq_len=model.config.max_seq_len, ...)is called unconditionally right after model load,and
model.config.max_seq_lencomes from the checkpoint'sconfig.json(32768forS2-Pro) — independent of your actual prompt length or
--max-new-tokens. Thispre-allocates a ~4.5GB KV cache (36 layers × 8 heads × 32768 × 128 × 2 bytes × 2 for K+V, bf16)
before any text is even tokenized, on top of the ~8.5GB of bf16 weights.
text_config.max_seq_lenin the downloadedcheckpoint's
config.json(e.g. to4096, still far more than any single-utterance TTSrequest needs) avoids the OOM entirely and runs comfortably in ~9.9GB. We verified this twice
— same output, same timing both times.
(sm80+ only):
Attention.forward()has a branch that would forcesdpa_kernel(SDPBackend.FLASH_ATTENTION)when
mask is None, which would crash on T4 — but tracing the actual call path shows theinference loop's
forward_generate()always builds an explicit mask, so that branch is deadcode here, not a live risk. Actual generation is deliberately forced through
SDPBackend.MATHby
decode_n_tokens()— already T4-safe by the repo's own design.--half(fp16) explicitly: it does not crash (confirmed no NaN/Inf, unlike someother bf16-trained TTS models we've tested where forcing fp16 breaks sampling), but it also
doesn't help the OOM or speed at all — fp16 and the default bf16 are both 2 bytes/param (same
VRAM), and the decode loop is memory-bandwidth-bound rather than compute-bound (confirmed via
the
Bandwidth achievedlog line, ~27.5-27.7 GB/s either way), so Turing's missing bf16Tensor Core path never becomes the bottleneck.
--halfis safe but not a useful lever here.int8/int4quantization handlers intools/llama/quantize.pyare only reachable if thecheckpoint directory path contains the literal substring
int8/int4(no CLI flag), targetthe older single-file checkpoint format rather than S2-Pro's sharded safetensors, and
wouldn't touch the KV-cache allocation anyway — consistent with community reports in
#1168 that even a third-party
quantized checkpoint still used 21GB+.
None of this is a code bug — it's a legitimate design choice (simplicity of always allocating
for the declared max context) that just isn't documented anywhere, and the fix is a one-line
config edit rather than a code change, so we're contributing it as a note rather than a PR
against the inference code.
Verification (Tesla T4 16GB)
Environment: Tesla T4 16GB, driver 550.163.01, Python 3.10.12, torch 2.8.0+cu128, transformers 4.57.3.
max_seq_len=32768(checkpoint default)max_seq_len=4096(config edit only)Exact OOM error (reproduced twice, verbatim):
Full details, raw metrics, and the T4 acceleration checklist (dtype/attention backend/int8/CUDA
graphs, each measured not assumed) are in
AGENTS.md.Test plan
max_seq_lenworkaround (succeeds, 2x reproduced, deterministic output both times due to--seed 42default)llama.py/inference.pyto confirm root cause and attention-backend behavior rather than assume