/tt-model-bringup:optimizefrom Tenstorrent Model Bring-up
Optimizes per-device performance of runnable TTNN code, improving layout, precision, sharding, program configs, and data movement while preserving correctness. Requires passing tests and uses tt-perf-report evidence.
Ships in Tenstorrent Model Bring-up. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them.
Before using this workflow, follow the dependency and environment setup in the model-bringup entrypoint. Resolve its package root from this installed skill's location; do not assume this plugin is copied into the target tt-metal checkout.
This skill assumes you have runnable TTNN code with passing correctness tests. If not, first use the appropriate bringup or debugging skill. This guide is written for autoregressive LLMs with prefill and decode phases. If the target model differs, map each requirement to the nearest equivalent path and record that mapping; do not drop correctness or performance evidence.
This guide does not choose a completely new model-level parallelization strategy from scratch, such as TP vs DP vs EP for the whole model. But if you are optimizing an existing multi-device TTNN path, changing activation layout, residual layout, collective placement, fused CCL+matmul use, and helper-module decomposition is in scope. Do not treat the inherited multichip implementation as fixed when the perf report shows material collectives, resharding, or layout movement.
Read the advice in tech_reports/LLMs/llms.md, particularly section 4 "Best practices and optimizations". In this skill we will strive to optimize on-device performance. For decode it is required to always measure the performance of a traced execution run; untraced/eager decode performance is not acceptable optimized evidence. Teacher-forcing decode must also use the traced path. For complete model or serving paths, avoidable host gaps are part of the optimization target and must be removed rather than merely noted. Always perform optimization using real tensor shapes, sequence shapes, batch size, sharding, and dtypes. Do not shrink hidden sizes, head counts, sequence lengths, or weight shapes just to make evidence easier to collect.
Optimize primarily for batch-1 single-user latency, with prefill latency and time-to-first-token (TTFT) as explicit targets alongside decode. Prioritize the measured bottleneck in the requested workload. Preserve larger-batch correctness: do not hard-code batch 1 into the optimized path, trace inputs, cache/page-table handling, sampling, or output formatting. For complete model and serving optimization, keep or add evidence that larger batches/concurrency still work, normally up to 32 when the target hardware, memory, and harness allow it.
Optimization must preserve the model's capability and context contract. If a change affects KV-cache dtype, cache layout, trace buffers, activation memory, CCL buffers, or any other persistent allocation, update models/autoports/<model>/doc/context_contract.json. Do not improve performance by lowering max_model_len, benchmark context, eval context, or any other advertised capability. A reduction is acceptable only when a hard physical device limit prevents the advertised capability from fitting or running, such as device DRAM capacity for weights + KV/cache/state + required persistent buffers. If reduced, record the byte calculation or failed capacity probe, the largest feasible supported value, and the exact construction/serving setting that uses it.
Optimization must also preserve valid non-aligned logical sequence lengths. Faster code that only works when prompt or prefill length is divisible by a chunk, tile, block, page, or trace size is not complete; keep padding, masking, cache fill, position handling, and output slicing inside the model path.
When direct traced generator decode is already fast but vLLM/serving decode is slower, treat the gap as orchestration overhead before retuning decoder math. First fix the adapter/generator path: async decode split, nonblocking trace replay, on-device traced sampling, host readbacks, page-table/input refreshes, and fallback sampling. Keep same-harness primary single-user and CI serving-burst before/after metrics.
A note on the term "sharding" - tt-metal uses this to mean two things. On-device sharding means sharding across the cores or DRAM banks of one device, such as L1-sharded activations or DRAM-sharded weights. Multi-chip sharding means distributing tensors across devices in a mesh. On-device sharding is in scope for this skill. When tt-perf-report mentions sharding, it usually means on-device sharding.
Profile warmed prefill and decode separately. Use tt-perf-report to find bottlenecks and suggestions for decoder, module, and non-serving full-model optimization. Try applicable advice. Keep changes that improve the target without unacceptable correctness or complexity cost. Record why rejected advice was rejected. If advice seems wrong, incomplete, or misleading, call that out as a candidate improvement to tt-perf-report.
Before local knob tuning, do an operation-topology audit of the measured path. Read the code and perf report together, then write a small table with the current operation sequence, material repeated matmuls, material collectives, reshard/layout conversions, candidate fused or lower-movement replacements, dtype/fidelity constraints for each candidate, and the action taken. This is not a comparison to any one existing model. Derive it from the target model's dataflow: if multiple projections consume the same activation, if a collective feeds a matmul, if a matmul is immediately followed by a collective, or if tensors gather/reshard only to satisfy a local helper, that is optimization work.
For multi-device decode, audit topology as coherent families, not isolated knobs. For every material row/column-parallel boundary, compare the feasible families:
For each candidate, record residual layout before and after, collective axis and dtype, expected bytes moved, ops removed or added, persistent-buffer use, and next-layer compatibility. If a fused or lower-movement candidate is slower, prove it was tried under a compatible residual/layout contract. Otherwise redesign the contract and remeasure before rejecting the family.
Do not measure a lower-movement collective family only after restoring the old replicated residual layout. That is a useful compatibility candidate, but it does not reject the family whose purpose is to carry a sharded or fractured residual forward. If a reduce-scatter, fused matmul+reduce-scatter, or fused all-gather-matmul candidate should win by changing the residual contract, adapt the next residual, norm, attention, or MLP boundary to consume that layout and measure the stack-compatible path. For single-layer correctness comparison, gather or convert only in the test harness outside the measured layer path, and label that boundary cost separately. Reject the lower-movement family only after this adapted path is measured slower or a minimal repro proves the required next op cannot consume the layout.
Optimize against the best correct measured path you have, not only against the original functional path. If this checkout or run already contains an earlier optimized artifact, read its compact perf summary and tt-perf-report tables before accepting a new candidate. If there is no earlier optimized artifact, keep a candidate table during this stage. A candidate is not accepted just because it has fewer ops or a nicer topology; it must beat the best correct candidate for the target workload, prefill/TTFT and traced warmed decode as applicable. If a topology change forces a worse dtype, fidelity, layout, or program config, compare that full candidate against the dtype-compatible separate path and keep the faster correct path. Do not reject a dtype, fidelity, fusion, or CCL candidate only because it loses in isolation; if the candidate changes communication volume or residual layout, measure it as part of the compatible topology family.
Before finalizing, rerun the selected default path with the same evidence harness used for candidates. The headline optimized numbers are the final default-run numbers, not the best candidate run copied from an earlier environment. If the final default run is materially slower than the candidate it is meant to preserve, fix the default wiring or explain the difference before completing the stage.
When this skill is invoked as part of vLLM integration or optimized-vLLM, do not collect Tracy, tt-perf-report, or TT_METAL_DEVICE_PROFILER metrics from the live vLLM server or serving adapter. The profiler/table requirement does not apply to vLLM serving stages. Use same-harness run_vllm_server benchmark JSON for before/after serving performance: primary single-user 128/128/1 for headline decode t/s/u and CI serving-burst 100/100/32 for vLLM-nightly parity and serving-capacity context. Also keep sampling, qualitative, degenerate-output, async-split, stale-input, and no-host-fallback evidence. Use earlier full-model or reduced non-serving profiles for device-op context if available; if not, record that evidence gap instead of profiling the vLLM stage.
Every optimization stage that can generate text must preserve prompt-correct qualitative behavior. From optimized-full-model onward, use $qualitative-check to rerun the shared qualitative prompt suite after selecting the optimized path. If text quality changes after an optimization, compare against a prompt-correct HF or previous-stage control before blaming the checkpoint.
Do not run Tracy or device-profiler collection on a full-model stack with every layer present. Full-stack profiling can create multi-GB profiler dumps, overflow device-profiler buffers, and distort the measurement. For full-model profiling, build a reduced profiling variant with one real layer of each layer kind and the real surrounding path: embeddings or input projection, the representative layers, final norm, LM head, sampling or token feedback when relevant, real KV-cache/page-table shapes, and the same trace path. Capture one warmed traced decode replay, or the smallest signposted prefill/decode window that answers the question. Use this reduced-layer profile for tt-perf-report; use the complete model only for end-to-end timing and correctness.
Run watcher and profiler evidence as separate hardware runs for non-vLLM optimization. Do not combine TT_METAL_WATCHER with device-profiler collection. Do not run profiler evidence in vLLM serving stages at all. Use $tt-device-usage for general TT command serialization, reset/list retries, hang triage, and ARC/ERISC/remote-Ethernet recovery. On T3K, the dangerous pattern seen in Phi-3.5 Mini experiments was: a vLLM/serving profiler failure or watcher failure, followed by a full in-process 32-layer serving-adapter profile under device-profiler env such as TT_METAL_DEVICE_PROFILER=1, TT_METAL_PROFILER_CPP_POST_PROCESS=1, TT_METAL_PROFILER_MID_RUN_DUMP=1, TT_METAL_PROFILER_TRACE_TRACKING=1, and TT_METAL_PROFILER_PROGRAM_SUPPORT_COUNT=5000, then explicit ttnn.ReadDeviceProfiler(mesh) readback. With signatures such as Timeout waiting for Ethernet core service remote IO request, ETH core heartbeat check failed, Unexpected ERISC Response Flags, Read 0xffffffff from ARC scratch, or ARC lock/readback waits, this can leave the T3K undiscoverable: tt-smi -ls --local hangs and tt-smi -r may hang. If this happens, stop profiler collection, preserve the logs, mark the evidence hardware-profiler-limited, and run the T3K reset recovery procedure below before declaring the optimization stage blocked.
ARC, ERISC, remote Ethernet, or tt-smi discovery/reset failures during optimization are recoverable infrastructure events until the recovery steps below fail. Do not mark the model implementation blocked just because a board is temporarily undiscoverable after watcher, profiler, serving, or reset trouble.
When you see signatures such as Timeout waiting for Ethernet core service remote IO request, ETH core heartbeat check failed, Unexpected ERISC Response Flags, Read 0xffffffff from ARC scratch, ARC lock/readback waits, tt-smi -ls --local hanging, or a failed tt-smi reset:
CODEX_HOME, repo state, multigoal logs, work logs, README files, benchmark JSON, and reduced profiler outputs. Do not delete authenticated config or successful stage evidence.ttnn.ReadDeviceProfiler(mesh) evidence while the card is unhealthy.timeout 60 tt-smi -ls --local
timeout 180 tt-smi -r
timeout 60 tt-smi -ls --local
python - <<'PY'
import ttnn
mesh = ttnn.open_mesh_device(ttnn.MeshShape(2, 4), trace_region_size=0)
ttnn.close_mesh_device(mesh)
print("MESH_SMOKE_OK")
PY
CODEX_HOME, and repeat the device list plus mesh smoke check.--resume-stage <stage_number> instead of restarting earlier completed stages. Verify the resumed objective still names the exact target model and expected stage skill.tt-smi -ls --local health, mesh smoke result, and resumed stage/thread. This is infrastructure evidence, not a model correctness or performance result.Keep large raw Tracy/profiler dumps and generated tensor artifacts out of copied-back artifacts after a recovery. Preserve code/docs/tests plus compact evidence such as *_perf_report.txt, *_perf_report.csv, reduced summaries, benchmark JSON, logs, and READMEs. Exclude *.tensorbin, *.pt, *.refpt, ops_perf_results.csv, prefill_decode_ops.csv, *_decode_ops.csv, and raw multi-GB Tracy CSVs; they are not worth destabilizing the node or evidence copy unless Mark explicitly asks for a specific raw artifact.
For decoder or module-level optimization, do not use a blunt global dtype policy. Start with a named precision/fidelity policy and tune tensor groups separately: attention weights, MLP/expert weights, KV cache, activations/residuals, CCL communication, norms, logits, and layer exceptions. Use the fallback policy below as the starting point unless an earlier stage has already selected a faster correct policy. Move one tensor group at a time.
Then tune precision and fidelity one group at a time so regressions can be assigned. For precision tuning always use real weights and recorded input activations; synthetic weights and activations are not representative enough to veto a policy. A test named "representative semantics" is still synthetic if it uses random or synthetic tensors. Synthetic/random-weight tests may catch op crashes, shape bugs, trace replay bugs, and numerical explosions, but they cannot by themselves make a slower higher-precision policy "best correct" when the lower-precision policy passes real-weight evidence for the target model. If synthetic coverage fails while real-weight coverage passes, treat that as a discrepancy to debug: inspect the synthetic distribution and threshold, add real-weight non-aligned/paged/trace replay coverage for the same contract, and reject the lower-precision policy only on model-visible correctness loss, trace/runtime failure, unacceptable latency, or an exact op-contract blocker. A common fallback starting point, when no prior policy exists, is BF16 activations and norms, BFP8 attention/MLP weights, BFP8 KV cache if PCC allows it, and selective BFP4 trials for MLP/expert weights.
If a prior-good policy fails in the generated code, debug the mismatch before discarding it. Check loader grouping, tensor layout, KV-cache update math, scale/transpose handling, and whether the validation harness is exercising the same full-model policy. For KV-cache precision, compare cache shape and mapper as well as dtype. Local-head replicated caches, global-head sharded caches, page-table distribution, and paged_fill_cache/paged_update_cache input dtype restrictions are different contracts. Lower-precision cache fill should cast the prefill K/V fill tensors to the cache dtype before paged_fill_cache; decode update tensors should stay BF16/FLOAT32 for paged_update_cache.
When optimizing a complete full model in the repo-local autonomous bringup flow, keep the main focus on full-model parallelism, tracing, sharding, data movement, program configs, compute-kernel configs, and removing host boundaries. $datatype-sweep owns the final accuracy/performance frontier, but this pass must still try targeted precision/fidelity changes when the measured full-model decode is materially below a credible target and the decoder-layer roofline says reduced precision could be the difference. Do not reject such work as "datatype sweep" by default. Try small, evidence-backed policies such as MLP gate/up BFP4, selected layer exceptions, KV/cache/CCL dtype changes, or compute-fidelity changes, then validate on the same traced full-model token-out path. Leave broad Pareto exploration to $datatype-sweep.
Before finishing non-vLLM optimization, review a current tt-perf-report output. If an applicable optimization remains untried, try it. If it fails, debug the failure. If a TTNN op or runtime limitation blocks the optimization, keep a small repro or exact failure evidence. Do not leave a known optimization for a later stage unless another skill explicitly owns it. For vLLM serving optimization, review the serving benchmark and contract evidence instead; do not create a profiler run to satisfy this paragraph.
Sometimes you will encounter a ttnn limitation or a bug. If, for example, you try an optimization and find that L1 buffers overlap (insufficient L1 space) do not take this as an excuse to give up on that optimization entirely. Instead, dive in to the code of the op and its shapes and configs and understand how you can reduce the L1 requirements in this part of the model. Or perhaps your specific shapes is not supported by the op and you need another one. Or the op does not support padding -> change the model contract so the tensors are manually padded in torch before conversion - all these things are in scope. If the failure crosses several ops, kernels, layouts, or planner/runtime boundaries and you are not making progress, use $autofix; it will run $autodebug if needed, then verify or refute each proposed bug before keeping any fix. Solve problems. Be curious. Be tenacious. Be creative. Be brilliant!
Use the existing decoder, multichip, and full-model optimization stages to improve prefill. Record before/after warmed prefill latency at the relevant logical prompt lengths, including a short prompt, a long prompt, and chunk boundaries/tails when used. Report physical chunk/bucket sizes and chunk counts beside the numbers. Keep first-use compilation/capture separate from warmed execution. At full-model and serving stages, also measure host TTFT with the same request workload; state the timing boundary and whether it includes input preparation, all chunks, final norm/LM head, sampling, and first-token readback. A faster matmul or chunk is only useful if the complete prefill/TTFT target improves without an unexplained decode regression.
Use reduced non-serving profiles as described above to identify whether time goes into projections, attention/cache operations, layout conversions, collectives, or dispatch between chunks. In serving stages use the existing benchmark JSON, without adding profiler collection. For slow prefill matmuls:
M x K x N, logical versus padded work, dtype/fidelity, active compute cores, memory placement, and kernel time. Large-M prefill often needs compute throughput; short chunks and tails may be bandwidth- or dispatch-limited. Check the selected kernel before trusting a generic utilization estimate, especially if the report confuses activation storage cores with DRAM reader/compute cores.minimal_matmul, interleaved copy), device time and the kept choice. Winners differ by row count; one row count does not select the kernel for the others. Give the non-matmul prefill ops (norms, head split and concat, RoPE, activation) the same candidate treatment when they are material at short chunks.ttnn.experimental.minimal_matmul as a candidate. Read the DiT linear implementation and matmul configuration helper, which derive MinimalMatmulConfig from padded M/K/N and the device grid. Compare it with the tuned existing kernel at the target LLM's shapes, layouts and accuracy bar; a DiT result alone is not evidence of an LLM win. Inspect its config= argument when profiler advice reports a missing program_config.M == 1 tile in its validation), so it cannot serve a prefill chunk. Short prefill chunks that measure DRAM-bound use the 1D multicast or 2D program configs over interleaved or width-sharded weights; the per-bank reader guidance in OPT-015 applies to decode. Retain the one-reader decode control and measure the target prefill path before adopting a setting.Batched prefill belongs to the optimized-vLLM stage (stage 10), not to optimized full model (stage 7). Serving admits several requests per prefill step; a per-row loop over the full decoder reads every weight once per row. Stage 6 proves the multi-row contract (one prefill_forward call with mixed rows equals the solo result per row); stage 7 keeps that contract intact and calibrates the bucket sizes against measured single-row prefill; stage 10 runs the dense work once for all short rows (equal padded length or packed rows), keeps attention and cache fill per row, warms every bucket before the first trace capture, and proves batched equals solo and a burst TTFT gain against the serial path with single-user latency unchanged. Prefill features holds the design and the gates. A batched dense pass with a wide output (N above about 8192) runs in row pieces through the batch dimension (1D program config with fuse_batch off): one 2D block overflows L1 above 512 rows.
If chunking is useful, follow the functional-decoder guidance. Compare feasible chunk sizes against the same logical request: smaller chunks bound temporary memory but add dispatch, repeated weight traffic and reads of the growing KV prefix; larger chunks may improve compute efficiency but increase memory demand and tail padding. Keep repeated-request correctness and prefill-to-decode cache behavior intact. When dispatch dominates, consider traced chunk variants using $tt-enable-tracing, rather than assuming one trace supports every shape or offset.
Every optimized non-vLLM decode result must reconcile three numbers from the same run:
tt-perf-report window.Report all three and use the gaps to drive implementation work: end-to-end = device time + dispatch gap + host work. Remove avoidable non-device terms before accepting the result. "The device math is fast but the loop is slow" is an unfinished optimization, not a result; a large unexplained gap between device time and end-to-end usually means an untraced path, per-step synchronization, host readback, or input-refresh overhead. Only name a ttnn/runtime/API limitation after you have tried the targeted fix and have evidence that the limitation blocks the optimized path.
The roofline fraction achieved varies legitimately by architecture - modules built from many small ops sit lower - so the explanation, not a fixed percentage, is the requirement. Name the limitations precisely; they feed the ttnn improvement backlog.
When optimizing a complete model or serving path, also write doc/<stage>/perf_summary.json with this shape. For vLLM serving stages, set device-time fields to null and name the reason, for example vllm_serving_profiler_disabled_to_protect_hardware.
{
"workload": {"profile": "single_user_decode", "prompt_len": 128, "gen_len": 128, "batch": 1},
"ttft_ms": 0.0,
"decode_ms_per_token_e2e": 0.0,
"decode_ms_per_token_device": 0.0,
"roofline_ms_per_token_estimate": 0.0,
"named_limitations": ["..."]
}
When the profile comes from a reduced-layer variant, decode_ms_per_token_device is the per-layer decode window times the layer count (summed per layer kind) plus the terminal path (final norm, LM head, sampling) from the same profile; the host gap is decode_ms_per_token_e2e minus that device figure. State the derivation and the variant beside the number.
For optimized full-model work, first compute a target budget from the best decoder-layer evidence:
layer_stack_ms = sum(layer_count[kind] * optimized_multichip_decode_ms[kind]);layer_stack_tps = 1000 / layer_stack_ms for batch-1 single-user decode;full_model_overhead_ms = measured_full_model_ms_per_token - layer_stack_ms.If the layer-stack estimate is already slower than the target, return to decoder optimization before spending time on generator orchestration. If the layer-stack estimate can meet the target but the full model cannot, optimize the overhead explicitly before changing the mathematical core: final norm, LM head, logits movement, sampling trace, token/current-position/RoPE/page-table refresh, trace replay blocking, synchronizations, host readbacks, cache management, and CCL buffer lifetime. For token/current-position/RoPE/page-table refresh specifically, the optimized steady-state loop should use persistent device tensors, tt_out_tok feedback, device-side position advance for fixed-step decode, and page-table copies only when the page table changes.
For models with an LM head and token sampling, treat the terminal path as part of optimized decode. A fast decoder layer stack is not enough if final norm, LM head, logits movement, sampling, or token feedback add avoidable per-token work.
Before accepting full-model token-out decode performance:
models.common.modules.lm_head.LMHead1D if you can. It is already well optimized for 1D mesh LM heads. If, after debugging shapes, sharding, and weight loading, you cannot make it support the target model, use it as the template for how to optimize your implementation.>= vocab_size. Zero-padding LM-head weights is not a sampling mask, because those padded columns produce zero logits that can beat negative real logits.TopKDeviceOperation. After invalid vocab IDs are masked, pad each local logits shard to a power-of-two width before TopK when needed, using very negative values and invalid indices for the extra power-of-two tail. Do not accept a multi-ms, one-core TopK as a final decode path. Read the routing rule in the TopK op source for the target architecture before padding: on Blackhole a k above 64 routes to the large-indices composite regardless of width, and on one model that full-row composite measured faster than every power-of-two chunking. Measure both paths; padding is a candidate, not a default.models/common/sampling/ and models/common/modules/sampling/sampling_1d.py, choose the one that fits this model's state, seed, topology, trace, and logprob requirements, and record the choice. Trace the chosen sampling path or a correct generator-owned wrapper around it. Pass tt_out_tok=<persistent decode token input tensor> so the sampled token becomes the next token input on device.topk(..., k=max_top_k), usually max_top_k=32, on each vocab shard; all-gather those candidates; then pass sampling params that are semantically greedy (k=1, p=0, temp=1). Do not build a physical top_k=1 per-shard path if it creates a gathered width smaller than a tile or forces a fallback. This keeps greedy behavior while avoiding full-vocab all-gather plus global argmax.top_k=32 or top-p-capable path as the only comparison against force-argmax. If top_k=1 or equivalent greedy split sampling fails because of sampler shape, layout, or tiling requirements, fix that contract or keep a minimal repro and leave the stage incomplete.ArgMaxDeviceOperation, full-vocab all-gather, generic TopKDeviceOperation, or sampling trace replay dominates token-out decode, fix the LM-head/sampling contract before retuning decoder dtypes or CCLs. Do not mark the optimization complete with this bottleneck still in the measured path.For vLLM serving performance, do not profile the live server or serving adapter to split these terminal costs. Reuse the full-model or reduced non-serving terminal evidence above, then prove the serving adapter uses that path with same-harness benchmark JSON and contract checks.
The same measured path must be used for before/after comparisons. A teacher-forcing or device-logit replay number is useful, but it does not prove a token-out generator or vLLM path is fast unless it includes the same sampling and token-feedback work. Record both when they differ.
If a decoder optimization was disabled in the full model because the stacked model hit L1, semaphore, trace, or CCL limits, do not accept the fallback as final until you have tried to reduce or pool that resource. Examples include persistent CCL buffers, output buffers, ring buffers, semaphores, trace input tensors, and page-table buffers. If it still cannot fit, record the exact allocation or runtime failure and the measured cost of the fallback.
Preserve the multichip decoder's data-layout contract across the stack. If the decoder was optimized around a sharded/fractured residual stream, do not insert a layer-to-layer all-gather merely to simplify the full-model wrapper. Try fused collective/matmul or sharded-output patterns first and find a way to make the performant solution work. $autofix can help you if you are running into bugs here.
Final optimized evidence checklist - these items MUST be completed:
tt-perf-report output with advice enabled and the main performance conclusions, collected from representative decoder/module tests or a reduced full-model profiling variant, not a full all-layer model trace. This requirement does not apply to vLLM serving stages.TT_METAL_WATCHER=10, don't skip asserts or anything. The watcher battery covers every prefill and decode path this stage changed (continuation at nonzero start, lead rows, block-size groups, multi-row prefill), not only the main prefill and decode. A watcher assert raised inside a tt-metal op the model only calls is reproduced in isolation, recorded as a tt-metal item with the repro path, and the stage ships a watcher-clean alternative; shipping the asserting path needs an operator waiver recorded in the work log. For vLLM serving stages, a watcher run of the changed path on a reduced-layer generator probe satisfies this when the probe covers every prepared shape; the reduced test fixture caps its warmup buckets, so the pytest selection alone does not reach the batched row counts. Do not attach the watcher to the live server. Keep watcher runs separate from device-profiler runs. If watcher/profiler collection produces remote Ethernet, ARC, or ERISC errors and tt-smi starts hanging, do not retry more profiler collection; preserve compact evidence, run T3K reset recovery, and resume the same stage if the node returns healthy.tt-perf-report, live-server device profiler, or serving-adapter profiler collection was attempted; if profiler evidence is absent, record that this is intentional.$qualitative-check evidence for the shared qualitative prompt suite after the selected optimization, with HF or previous-stage controls.tt-perf-report row or an equivalent profiler artifact must show the expected input/weight dtype and math fidelity. If the row shows BF16 or BFP8 where the selected policy claims BFP4, the policy did not reach the measured op and the stage is incomplete.
-[ ] Used SDPA and other optimized composite ttnn ops instead of hand-built attention primitives where the target model fits their contracts.
-[ ] Fused or packed repeated same-input projections where legal and beneficial, such as Q/K/V-style projections, paired gate/up projections in 3-matmul MLPs, or other model-specific projection groups. If kept separate, there is measured evidence or a specific unresolved TTNN/runtime blocker after adapting layout, rank, padding, weight packing, and output splitting. If kept packed, it wins against a well-tuned legal separate candidate after counting split, activation, binary elementwise, and layout overhead, or the evidence explains why the separate candidate is invalid.
-[ ] Explicitly configured memory_config, program_config, and compute_kernel_config for important ops.
-[ ] For any matmul or repeated matmul group that is one of the largest decode-time consumers: swept legal program configs separately for each dominant role, including core grid, larger legal in0_block_w values, output subblocks, output blocks, memory configs, and compute kernel config where applicable. The stage is incomplete without a before/after evidence table or an exact TTNN/runtime blocker.
-[ ] Decode compute fidelity was swept as a real performance knob for each dominant projection group. Do not assume BFP8 implies HiFi2 is fastest; try legal LoFi and HiFi2 candidates with the same dtype and real traced decode evidence, then keep the fastest policy that passes correctness.
-[ ] Attention projection weight dtype/fidelity was swept separately from MLP weight dtype/fidelity when QKV, Q/K/V, output projection, or fused attention matmul rows are material. If attention projections remain BFP8 or BF16, the report names the BFP4 attention candidate tried on real weights or recorded real activations, plus the precise correctness, latency, or op-contract blocker.
-[ ] If dense MLP or expert matmuls are among the largest decode-time consumers: BFP4/LoFi trials for FF1/FF3 or equivalent gate/up projections were run. FF2/down BFP4 was also tried or rejected with PCC/runtime evidence. Order this work against prefill tuning by the measured latency target.
-[ ] Shard specs and core grids that divide tensor dimensions cleanly into tiles where possible, code grids as large as this and the model/hardware allows.
-[ ] DRAM-sharded decode matmuls. On Blackhole builds with multi-reader support, every material role was measured with one reader and each legal two- or three-reader candidate. The final count is explicit in the model's per-role configuration; the generic default remains one.
-[ ] Collective topology minimized. Avoidable gather, reshard, all-reduce, reduce-scatter, and all-gather operations have been removed, moved to cheaper boundaries, or justified with before/after evidence.
-[ ] Fused matmul-CCL ops used where possible, including fused all-gather-matmul or matmul-reduce-scatter patterns when a collective and matmul are adjacent or can be made adjacent. If rejected, the rejection includes an adapted attempt, not only the first API error.
-[ ] Repeated decode CCLs use persistent or preallocated intermediate/output buffers where the API supports it. If unavailable or slower, the reason and measurement are recorded.
-[ ] For MoE models: optimized the routed active-expert path with ttnn.sparse_matmul where the model/hardware fits, correct nnz handling, separate gate/up and down tuning, correct sparse-input handling where applicable, routing-score weighting, expert reduction, no dense all-expert runtime path, and no avoidable DRAM round trips through decode intermediates.
-[ ] For models with an LM head and sampling: final norm, LM head, logits movement, sampling, and token feedback are included in the optimized token-out path; terminal costs are profiled separately in full-model or reduced non-serving evidence, not in vLLM serving stages; LM-head weights are padded when needed for legal/fast DRAM-sharded or vocab-sharded matmuls; padded vocab IDs are masked in local logits shards before force-argmax or TopK; split-sampling TopK input widths are padded to avoid the slow single-core TopK fallback where the measured routing makes padding win; avoidable ArgMaxDeviceOperation, full-vocab all-gather, generic TopKDeviceOperation, host argmax, and full-logits readback have been removed. If a TTNN/runtime limitation blocks removal, the stage remains incomplete until there is a minimal repro or a lower-level fix.
-[ ] LM Head is optimized for DRAM-sharded matmuls if present.
-[ ] Reduced precision/fidelity experiments appropriate to this module-level optimization stage have been carried out and documented using real weights and input activations. For complete full-model top-k tuning, final datatype frontier selection is deferred to $datatype-sweep.
-[ ] Performance accounting reconciled: roofline estimate, device-time decode, and end-to-end decode reported from the same run; avoidable gaps optimized away, and any remaining gap named as a ttnn/runtime/API limitation only after a targeted fix attempt; perf_summary.json written when optimizing a complete model or serving path. For vLLM serving stages, use same-harness primary single-user and CI serving-burst serving metrics and set device-time/profile fields to null with the no-profiler reason.
-[ ] Batch capability preserved: batch-1 is the primary optimized latency target, and larger-batch or concurrent-serving correctness was tested up to 32 where hardware and memory allow it.
-[ ] For the optimized full-model stage: the multi-row prefill contract from full-model still equals the single-row output per row, every prefill bucket is warmed before capture with program-cache counts recorded, and prefix-cache resumed prefill still passes run_prefill_resume_check on the optimized path.
-[ ] For the optimized-vLLM stage: batched prefill runs the dense work once for all short rows, batched output equals the single-row output per row, the prefill_burst TTFT ratio against the serial path meets its gate, and the primary single-user TTFT and TPOT are within 5 percent of the pre-change values.If this checklist is not completed, go back and perform those optimization steps. For decoder/module-level work the main focus is on-device performance. For complete model and serving work, host orchestration, synchronizations, readbacks, and input-refresh overhead are also in scope and must be driven out of the measured path where the runtime contract allows it.
Use this reference while optimizing functional TTNN code. It captures repo-local optimization patterns and the strongest current LLM guidance. If you are not optimizing an LLM, use your best judgement about what applies in your case.
tech_reports/LLMs/llms.md: LLM memory configs, matmul variants, DRAM-sharded matmul guidance, and perf-report interpretation.models/common/modules/attention/attention_1d.py: reusable attention configs with BFP8 attention weights, BFP8 KV cache, DRAM-sharded decode matmuls, SDPA configs, and L1-sharded decode residual paths.models/common/modules/mlp/mlp_1d.py: decode/prefill MLP split, DRAM-sharded decode matmuls, sharded outputs, and precision knobs.models/common/modules/lm_head/lm_head_1d.py: reusable LM-head output projection with vocab splitting, LM-head dtype, DRAM-sharded weight memory config, input/output memory configs, and decode program config.models/common/tests/modules/lm_head/test_lm_head_1d.py: expected LM-head construction, weight splitting, memory config, and PCC checks.models/common/tensor_utils.py: helpers to serialize program and compute-kernel configs for artifact reporting.ttnn/cpp/ttnn/operations/matmul/device/factory/matmul_multicore_reuse_mcast_dram_sharded_program_factory.cpp, ttnn/cpp/ttnn/operations/matmul/device/utilities/matmul_utilities.cpp, and tests/ttnn/nightly/unit_tests/operations/matmul/test_matmul_dram_sharded.py: Blackhole multi-reader DRAM-sharded matmul implementation, legality checks, and focused coverage.models/common/sampling/generator.py and models/common/modules/sampling/sampling_1d.py: common on-device sampling implementations to compare before optimizing token-out sampling.models/demos/gpt_oss/tt/experts/README.md, models/demos/gpt_oss/tt/experts/decode.py, models/demos/gpt_oss/tt/experts/prefill.py, models/demos/gpt_oss/tt/experts/weights.py, models/demos/gpt_oss/tt/experts/config.py, and models/demos/gpt_oss/tt/topk.py: default routed MoE active-expert path using ttnn.sparse_matmul.models/demos/gpt_oss/tt/, models/demos/gemma4/tt/, and models/demos/deepseek_v3/tt/: model-specific examples where common modules do not fully fit.memory_config, program_config, and compute_kernel_config for important ops. Defaults are often correct but suboptimal.ttnn.sparse_matmul path for sparse expert projections plus score weighting and expert reduction. Dense all-expert execution is a debug baseline, not the optimized target.When optimizing decoder attention and the measured path has separate Q, K, and V matmuls that consume the same post-norm activation, first test a packed QKV projection before spending time on local program-config tuning for the split projections. This applies when the model's Q, K, and V projections are ordinary linear projections of the same hidden state and there is no per-projection operation, dtype, bias, adapter, normalization, quantization, or device-placement contract that requires them to stay separate.
This is a special case of the rule that fewer larger matmuls are generally better than more smaller matmuls when the larger matmul preserves dtype, layout, program-config quality, and downstream consumption.
The packed candidate should pack or concatenate the Q, K, and V weights at load time, run one decode matmul for the combined output width, then use the target's legal on-device QKV-head creation path before rotary, KV-cache update, and SDPA or FlashDecode. For grouped-query attention, compute the packed width from the real head counts: q_heads * head_dim + 2 * kv_heads * head_dim. Preserve any required weight permutation or reverse-permutation convention from the reference implementation; a fast packed path with wrong Q/K ordering is a correctness bug, not an optimization.
Verify the topology in the final tt-perf-report, not only in code. A successful packed decode path should show one material QKV projection matmul in the attention block, not three Q/K/V matmuls, and it should not contain a cluster of reshapes, slices, and layout conversions whose only purpose is to repair the split projection outputs before rotary. If the path remains split, leave measured evidence or a precise blocker after adapting weight packing, output splitting/head creation, memory configs, rank, padding, and dtype/fidelity. "The functional implementation was already split" is not a blocker.
Compare packed and split candidates under the same traced warmed decode harness, context shape, precision policy, and correctness checks. Keep the faster correct path. If packing loses because it forces worse dtype, fidelity, memory layout, program config, or extra output movement, record that full-path comparison; do not infer the answer from op count alone.
When optimizing decoder attention, treat SDPA or FlashDecode time as part of the attention contract, not a downstream detail. Before accepting a change to QKV packing, head creation, rotary, cache update, page-table handling, cache dtype, cache layout, or attention input memory config, compare the candidate against the strongest prior correct attention path at the same traced decode context.
The comparison must include the tt-perf-report row for SDPA or FlashDecode, the KV-cache dtype, cache layout, page-table shape/distribution, Q/K/V head layout, attention op program_config, chunk sizes, block size, num_kv_heads, output memory config, and the final attention-block topology. Do not accept an attention candidate only because the projection matmul got faster if SDPA, cache update, or layout-conversion time moved the cost elsewhere. A lower total layer time can justify a local SDPA regression only when the report names the regression, quantifies it, and shows the whole traced decoder is still faster under the same context and correctness checks.
When the final candidate still uses a BF16 KV cache and SDPA or FlashDecode is a material cost, a reduced-cache candidate is mandatory before accepting the stage. Try the architecture-appropriate reduced cache dtype, usually BFP8/BFLOAT8_B, with the same context length, page table, head layout, trace path, and correctness checks. This requirement applies even when the functional baseline used BF16 cache; a functional baseline is not proof that BF16 is the optimized cache policy.
Preserve a lower-precision KV cache when the prior correct path used one and PCC still passes. If BFP8 or another reduced cache dtype fails, debug the fill/update contract before falling back to BF16: prefill fill-cache tensors may need an explicit cast to the cache dtype, while decode paged_update_cache inputs may need to remain BF16 or FLOAT32. Also compare cache shape, local/global head mapping, page-table distribution, and whether packing QKV forced a different Q/K/V head creation path. A BF16 cache fallback is acceptable only with a correctness failure, op-contract blocker, or measured same-context win that includes the SDPA/cache cost.
When SDPA or FlashDecode is material, do not rely on the op default configuration. Create an explicit architecture-appropriate decode attention program config and measure it against the default under the same cache dtype and head/page contract. For Wormhole paged decode, the usual first candidate is ttnn.SDPAProgramConfig(compute_with_storage_grid_size=(8, 8), exp_approx_mode=False, q_chunk_size=0, k_chunk_size=0) when legal. If a default attention op is kept, record the explicit config tried, its SDPA row, and why it lost or failed.
The final report for an optimized decoder must list the SDPA or FlashDecode row, KV-cache dtype/layout, attention program config, reduced-cache candidate result, and kept/rejected decision. If SDPA or FlashDecode is one of the largest regressions versus the prior same-context correct candidate, if BF16 cache remains without a reduced-cache trial or precise blocker, or if a material SDPA path uses default program config without an explicit-config candidate, the stage is not optimized.
For decoder optimization, the residual stream is a contract across the layer, not a temporary tensor between ops. Before tuning local matmul or attention knobs, choose the decode residual memory config and carry it through input RMSNorm, attention residual add, post-attention RMSNorm, MLP input, and final residual add when the ops legally support it. A residual path that repeatedly falls back to DRAM interleaved because it is convenient is not optimized.
When RMSNorm or LayerNorm is material, use a sharded norm program config with sharded L1 input and output. The common single-chip Wormhole starting point is a width-sharded L1 residual over a clean core grid, paired with ttnn.LayerNormShardedMultiCoreProgramConfig; adapt the grid, shard shape, and subblocks to the model shape and hardware. If the norm output is DRAM interleaved, or if a residual add writes DRAM interleaved before the next norm or matmul, measure a sharded-residual candidate before accepting the stage.
Do not let an attention or MLP helper force the whole layer back to DRAM. Pay required layout conversions only at the narrow API boundary, then restore the residual contract before the next residual add or norm. If a candidate keeps a slower residual layout because a downstream op rejects the sharded tensor, record the exact op, shape, memory config, error or PCC failure, and the measured cost of the fallback.
The final report for an optimized decoder must list both norm rows, norm program configs, residual-add output memory configs, residual memory config before attention and MLP, and any InterleavedToSharded, ShardedToInterleaved, or reshape/slice rows used to cross helper boundaries. If norm rows are one of the largest regressions versus the prior same-context correct path, or if norms/residual adds use DRAM interleaved without a measured sharded candidate or precise blocker, the stage is not optimized.
For dominant DRAM-sharded decode matmuls, do not assume the largest available compute-core count is fastest. The logical program core count, activation shard grid, in0_block_w, per_core_N, and output subblock fields are part of the performance contract. More cores can shrink the legal K block or per-core output block enough to lose to a smaller coherent grid. This is a block-geometry version of the rule that fewer larger work chunks can beat more smaller chunks.
When a DRAM-sharded matmul or repeated matmul role is material, measure at least one candidate tied to the residual or intermediate sharded layout grid, one larger-core candidate when legal, and any helper/default candidate already in the code. Keep dtype, math fidelity, weight memory config, input/output memory config, and surrounding residual layout fixed while sweeping geometry, unless the candidate requires a coherent layout change; if it does, measure the whole compatible layer path. A geometry sweep is invalid if it silently changes precision, fidelity, or weight layout from the best prior correct path or from the mandatory precision policy for that tensor group.
Treat the producer's activation shard width as part of the matmul program config. A residual or norm path that uses more cores can make each shard too narrow, forcing in0_block_w=1 or 2 for the next DRAM-sharded matmul. Treat in0_block_w=2 as a minimum floor, not a success condition, and do not encode an old expectation that 2 to 4 is enough. For dominant DRAM-sharded rows, especially BFP4/LoFi decode gate/up, QKV, output, down, expert, and LM-head matmuls, sweep larger legal divisors of the tiled K dimension and the input shard's K-tile width. Values do not need to be powers of two: try larger legal values such as 3, 5, 7, 8, 10, 14, 16, or higher when L1 capacity, divisibility, and op contracts allow them. Experiment 22 Llama 3.1 8B showed in0_block_w=16 beating 8 for material MLP rows, so 8 is not a default stopping point. If a dominant matmul is stuck at in0_block_w<=2, or a larger value fails with a divisibility error such as (shard_shape[1] / tile_width) % in0_block_w != 0, do not accept that as a matmul-only blocker until you have tried a coherent upstream shard grid with fewer cores and wider shards, or mathematically inert padding that makes larger divisors legal and slices/masks padded channels before they affect outputs. Measure the whole layer: a slightly slower norm or residual add can be the right choice if it unlocks a much faster QKV, output, gate/up, down, or LM-head matmul.
For dense MLP or expert gate/up/down geometry work, include the best legal reduced-weight policy in the geometry sweep, usually BFP4/LoFi for MLP weights. A BFP8/HiFi2 geometry sweep is useful as a baseline, but it cannot justify accepting the MLP geometry when BFP4/LoFi was never tried, failed without diagnosis, or was not measured under the same geometry candidates. If the final MLP path uses higher precision than the best prior correct path or the mandatory BFP4/LoFi trial, record the lower-precision candidate result and the exact correctness or op-contract blocker. A random-weight or synthetic-activation PCC failure is not an exact blocker when real target-model weights pass; reconcile that discrepancy with real-weight coverage before accepting the higher-precision fallback.
For each dominant matmul role, the final report must list shape, dtype/fidelity, program class, logical program core count or grid source, input shard shape in tiles, in0_block_w, per_core_M, per_core_N, output subblock fields when exposed, input and output memory configs, bandwidth classification, traced latency, correctness result, and kept/rejected decision. If tt-perf-report marks a dominant DRAM-sharded matmul SLOW, reports low DRAM utilization, reports missing output subblock information, or shows a small in0_block_w on a material row, do not accept the stage until a precision-locked block-geometry sweep has tried larger legal in0_block_w divisors, including non-powers-of-two and 16 when legal, or recorded a precise L1/divisibility/op-contract blocker.
Decoder kernels often use tile-padded activation rows, such as one logical token padded to 32 rows. Those padded rows are a tensor-layout contract, not extra active users. Do not change logical batch, active user count, page-table semantics, or KV-cache indexing just to satisfy an op shape check. A result with the right matmul shape but the wrong active batch is a different workload.
When reporting or comparing decode attention, list logical user batch, tile-padded activation rows, current-position tensor shape, page-table shape/distribution, KV-cache shape, page block size, active cache slots updated, and SDPA/FlashDecode row time. Compare SDPA or FlashDecode only against a prior path with the same logical batch and context length. If a helper requires padded RoPE, current-position, or head-layout metadata, create padded metadata that preserves the original logical batch semantics instead of treating padding rows as real users.
If an optimized decoder candidate changes logical batch from the target workload, the stage is not optimized for that target, even if PCC passes and the matmul rows look good. Such a run can be kept only as a separate throughput-scaling experiment, clearly labeled with active batch and excluded from single-user decoder signoff.
Optimized decoder work is cumulative. Before a new focused experiment, write the strongest prior correct candidate's required contracts: projection topology, weight dtypes and math fidelity by tensor group, KV-cache dtype/layout, logical batch and tile padding, attention program config, residual/norm memory layout, dominant matmul geometry, and known required layout transitions. The new candidate must preserve those contracts unless the experiment is explicitly testing one of them.
A focused experiment may vary one contract to answer a local question, but it is not an optimized-decoder signoff if it regresses another previously validated material contract. For example, fixing SDPA while losing MLP precision, fixing MLP geometry while changing logical batch, or fixing logical batch while reverting attention weights to BF16 are local evidence, not final optimized evidence. Either integrate the old and new contracts in one candidate and remeasure, or record the conflict as a blocker with exact rows.
The final report for an optimized decoder must include a cumulative contract table: packed/fused projections and head path, attention weight dtype/fidelity, KV-cache dtype/layout, logical active batch versus tile-padded rows, SDPA/FlashDecode config and row, residual/norm layout and norm rows, MLP/expert dtype/fidelity and geometry rows, total device time, op-to-op gap, correctness, and any intentional deviations. Use the strongest cumulative correct candidate as the baseline for the next step, not the latest focused run that happened to pass its local target.
Do not limit reduced-weight trials to MLP or expert projections. In decode, attention QKV and output projections are small-M, large-weight matmuls; if they are material or DRAM-bound, BFP4 attention-weight candidates are mandatory before accepting BFP8 or BF16 attention weights. This applies to packed QKV, separate Q/K/V, output projection, and fused CCL+matmul forms that consume attention weights.
Test attention weight dtype and math fidelity independently from activation dtype, KV-cache dtype, CCL payload dtype, and MLP weight dtype. At minimum compare the strongest prior attention path with the current/default attention weight dtype and fidelity, then with BFP4 attention weights and each legal fidelity that could plausibly win for that op. Keep residual/norm, cache, and topology contracts fixed unless the candidate deliberately tests a compatible topology family; if topology changes are required, compare the BFP4 attention policy inside that compatible family, not only in isolation. A BFP4 attention trial on a weaker split-Q/K/V or BF16-output topology is screening evidence only; it can prove feasibility, but it does not accept or reject BFP4 for the optimized stage when a packed, fused, or lower-movement attention topology is legal and material. After screening passes, remeasure the BFP4 policy on the lowest-op-count compatible topology before making the final optimized-stage decision. This is a special case of the rule that fewer larger matmuls are generally better than more small ones: precision and fidelity must be tested on the matmul topology the final decoder should use.
Do not reject BFP4 attention because BFP4 MLP failed, because BFP8 activations were selected, or because a prefill row got slower when the optimization target is decode. Do not reject it on synthetic weights or synthetic activations alone; synthetic runs can catch crashes and op-contract failures, but precision vetoes need real weights or recorded real activations. For attention-weight changes, raw K/V cache PCC against a higher-precision baseline is a diagnostic, not an automatic rejection, because changing K/V projection precision legitimately changes the cached intermediate. If layer output PCC passes but raw cache PCC fails, run a follow-on decode, multi-token replay, top-k/readiness check, or other cache-consuming real-weight test before rejecting the policy. Reject BFP4 attention when it causes model-visible correctness loss, trace replay failure, generation/readiness failure, unacceptable latency, extra typecasts or layout conversions that lose whole-layer traced decode, or a precise unsupported fused-op/shape/L1 blocker.
The final report must list QKV/output-projection dtype and fidelity, weight memory config, row times, SDPA/cache side effects, correctness, follow-on cache-use evidence when cache PCC is the concern, and kept/rejected decision. If attention projections remain BFP8 or BF16 while QKV, Q/K/V, output projection, or fused attention matmul rows are material, the stage is not optimized without a real-weight BFP4 attention trial or a precise op/correctness blocker.
For tensor-parallel row-parallel output projections, choose the algebra before choosing the CCL primitive. Compare the two main legal decompositions: local-input/full-output matmul followed by reduce or reduce-scatter, and gathered-input/local-output matmul followed by all-gather when the residual boundary needs replicated hidden state. The second family often appears as fused all-gather plus matmul with output-sharded weights. Do not reject it because a matmul-reduce-scatter candidate failed, because a sharded-residual carry-forward probe failed, or because the functional implementation uses local full-output weights.
When testing fused all-gather plus output projection, repack or reshard the projection weight for local output width, adapt tensors to the fused op's rank and layout contract, and set the CCL axis, transfer count, input/output memory configs, and matmul program config explicitly. The expected perf report should show a fused CCL+matmul row whose matmul N is the local output width, followed by a gather only if the next residual/norm contract requires replicated hidden. A local-input/full-output matmul plus RS/AG is a different decomposition, not a failed version of this one.
The final report for a material row-parallel output projection must list which decomposition was selected, the weight sharding/layout for each candidate, fused op rank/layout requirements, CCL transfer count, program config, row times, whole-layer latency, correctness, and exact blocker for rejected decompositions. If the fused all-gather-matmul path fails with L1 circular-buffer allocation, report the requested and available bytes plus the tensor shapes and program config that produced them; then try the smallest legal local-output candidate before treating the fused family as blocked.
For repeated traced decode collectives, async CCL is not complete by itself. If an all-gather, reduce-scatter, all-reduce, or fused CCL+matmul row is material and runs every token or every layer, try the API's persistent or preallocated output, intermediate, and ring buffers when available. This applies to hidden all-gathers after output projections, reduce-scatters after row-parallel matmuls, LM-head or logits collectives, expert collectives, and fused CCL+matmul rows.
Keep the CCL algorithm, payload dtype, collective dimension, topology, link count, worker count, buffers per channel, and memory configs fixed while testing persistence unless the API requires a coupled change. Compare the persistent-buffer candidate against the best non-persistent candidate in the same traced warmed decode window. If persistence cannot be used, report the exact API limitation, tensor shape, memory config, buffer size, trace constraint, L1/DRAM allocation failure, or correctness failure; do not leave the field implicit.
The final report must list every material decode CCL row with payload dtype, input/output memory configs, CCL axis/dim, topology, chunks_per_sync, num_workers_per_link, num_buffers_per_channel, persistent output buffer status, persistent intermediate buffer status, row time, and kept/rejected decision. A stage with repeated decode CCL rows using default non-persistent buffers is incomplete unless a persistent/preallocated candidate was measured or a precise blocker is recorded.
For 3-matmul MLPs, such as gate/up/down or FF1/FF3/FF2 blocks, "pack the gate and up weights and run one larger matmul" is a strong first candidate, not a proof. If the gate/up group is material and both families are legal, compare packed gate-up against separate gate plus up while holding dtype/fidelity, input memory config, residual layout, downstream elementwise contract, and row-parallel output contract fixed. This is a special case of the "fewer larger matmuls are generally better than more small ones" rule: the usual bias is toward packing, but the measured whole-MLP winner is the optimization target.
A packed gate/up candidate must include the cost of splitting or reshaping the packed output before activation, plus the activation, binary elementwise combine, and any layout movement before the down matmul. A split candidate must include both matmul launches and any extra layout movement. Do not keep packed gate/up merely because it has fewer matmul launches or a faster packed matmul row if the doubled output width forces a worse per_core_N, in0_block_w, output subblock, L1 allocation, slice/layout row, or precision policy.
Also compare against the best legal fused-elementwise form of the split path. For SwiGLU-style MLPs, the activation may be fused into the gate matmul or into the following binary elementwise op; for other MLPs the analogous activation/add/multiply fusion can change the balance. Packed gate/up must beat that best separate-family implementation, not just an untuned separate baseline. If packed saves a few microseconds on the matmul but adds more split, unary, binary, or layout time, keep the separate path.
The final report for a material gate/up group must list packed and split candidate rows, program configs, input/output memory configs, weight memory configs, dtype/fidelity, split/slice/layout rows, activation rows, binary elementwise rows, downstream down-matmul and reduce-scatter or all-gather rows, whole-MLP and whole-layer traced latency, correctness, and kept/rejected decision. If one family is impossible, report the exact API, shape, memory, program-config, L1, trace, or correctness blocker.
Do not force one residual or norm shard grid to be the working input shard for every decoder sub-block. A layout that is good for a boundary, norm, or one projection can make another material matmul group slower by giving each core too few inner-dimension tiles for a larger in0_block_w or output subblock. When a material matmul is stuck at a small block size because the producer shard is too narrow, try a phase-specific working shard for that sub-block: usually fewer cores with wider shards, immediately before the projections that share that input.
Keep the model-visible boundary contract fixed while testing the working shard. Restore or preserve the residual layout only where it is actually required: residual adds, following norms, layer boundaries, cache/head helpers, or collective contracts. Compare the full traced sub-block, not the isolated matmul: include the added reshard/layout rows, all matmuls that consume the working shard, elementwise rows, downstream collectives, and any saved conversions. If the same working shard feeds multiple projections, account for the reshard cost once across the group.
The final report must list the boundary memory config, candidate working memory configs, shard shapes in tiles, legal and rejected in0_block_w/subblock values, exact divisibility or L1 errors, added layout rows, row times, whole-layer latency, correctness, and kept/rejected decision. A dominant matmul group blocked by an error like "shard inner tiles must be divisible by in0_block_w" is not optimized until a wider working-shard candidate has been measured or a precise blocker is recorded.
Random-weight and synthetic-activation precision cases are stress probes, not the definition of the optimized dtype/fidelity policy. When a lower-precision or lower-fidelity candidate is faster on real target-model weights plus recorded or real target activations, and it passes the stage's real-weight PCC, trace replay, and runtime checks, do not reject it only because a synthetic/random-weight "representative semantics" check falls below a PCC threshold against a higher-precision reference. That result may mean the synthetic distribution is adversarial or not representative of the target model.
If synthetic coverage fails while real target-model evidence passes, either keep the faster lower-precision policy or add a same-contract real-weight check that reproduces the failure under the disputed condition: non-aligned lengths, paged prefill/decode transition, traced replay, larger batch/concurrency, cache-consuming output, or generation/readiness evidence. Rejection requires one of: model-visible output PCC, generation, or readiness failure on target weights; real-weight trace/runtime failure; final default latency not winning; or an exact op-contract blocker.
The final report must list the real-weight PCCs, synthetic PCCs if run, traced latencies, and which evidence actually decided the policy. Do not create a passing test suite by marking the lower-precision synthetic case as an expected diagnostic failure while selecting the slower fallback. If such a test exists, its purpose is diagnostic coverage; it is not an acceptance gate.
A dtype/fidelity policy is not implemented until the measured runtime rows show it. Policy names, dataclass defaults, JSON summaries, and constructor arguments are only intent. Before accepting a reduced-precision candidate, inspect tt-perf-report or an equivalent profiler artifact for each dominant matmul row and confirm the row's input dtype, weight dtype, output dtype, and math fidelity match the selected policy.
This is especially important when weights are lazy-loaded, cached, rewrapped, or passed through helper modules. A stale tensor cache, fallback constructor, convenience weight_dtype argument, replicated load path, or helper default can silently turn a claimed BFP4/LoFi policy into BF16 or BFP8 at the actual matmul. If the profiler row says BF16 x BF16, the matmul is not using BFP4 weights no matter what the policy object says.
When the row dtypes do not match the policy, debug the materialization path before timing or ranking that candidate: cache key and cache directory, LazyWeight dtype, mesh mapper, memory config, helper defaults, explicit dtype= arguments to ttnn.matmul, and whether a precomputed device tensor is reused across policies. The final report must include the dominant matmul rows that prove the kept policy was actually exercised.
For a dominant matmul group, dtype/fidelity and block geometry are not independent checkboxes. A sweep that measures one core grid, activation shard width, in0_block_w, or per_core_N under BFP8/HiFi2 does not prove the same geometry under BFP4/LoFi, and a BFP4/LoFi run on one geometry does not reject the other material geometries. Measure the best reduced-precision policy on the geometry candidates that matter.
This matters especially when more cores shrink the activation shard and reduce the legal K block. Fewer cores with wider shards can unlock a larger in0_block_w or output block and beat a larger-core run even though it uses fewer workers. When tt-perf-report marks a dominant row SLOW, reports low DRAM utilization, reports no output subblock, shows in0_block_w<=2, or the code records a blocker for a larger-core geometry, run a precision-locked smaller-core or residual-grid candidate before accepting the stage.
The final report must make the cross-product explicit: for each material geometry candidate, list dtype/fidelity, core/grid source, input shard shape, in0_block_w, per_core_N, row latency, whole-layer latency, correctness, and kept/rejected decision. If a candidate is impossible, record the exact TTNN/op-contract blocker. Do not mix evidence from different dtype/fidelity policies to declare a geometry optimized.
On tt-metal revisions that include #54242, ttnn.MatmulMultiCoreReuseMultiCastDRAMShardedProgramConfig accepts num_workers_per_dram_bank=1, 2, or 3. Values above one are Blackhole-only. Each additional worker reads and computes a disjoint slice of the same DRAM bank shard through the firmware-approved NOC0 endpoint. This increases the reader/compute worker count; it does not add DRAM channels or use a second physical endpoint.
Set the count directly on the existing DRAM-sharded program config:
program_config = ttnn.MatmulMultiCoreReuseMultiCastDRAMShardedProgramConfig(
in0_block_w=in0_block_w,
per_core_M=per_core_M,
per_core_N=per_core_N,
num_workers_per_dram_bank=2,
)
Use this as an explicit per-projection optimization, not a new primitive default. For each material Blackhole decode projection, compare one reader with every legal two- and three-reader candidate under the same real M x K x N, weight layout, input shard grid, dtype, math fidelity, program geometry, firmware, trace, and warmed workload. Keep the selected count in the model's existing performance configuration by operation role and validated SKU. Do not infer one count from the architecture, datatype, model family, or another projection, and do not add an exact-shape allowlist to the generic matmul operation.
Check these conditions before running a candidate:
dram_bank_count * reader_count; input-A storage cores are excluded from reader placement. Treat a placement failure as an illegal candidate, not a reason to change the global default.Use the production precision pairing when ranking candidates. For LLM decode this normally includes BFP8/HiFi2 and BFP4/LoFi; do not compare a one-reader result at one dtype or fidelity with a multi-reader result at another. Verify the measured profiler row shows the intended weight dtype, fidelity, and reader count.
Measure in two layers. First, run an isolated, alternating-order one/two/three-reader microbenchmark with the exact model tensor and shard geometry; record device time, physical and logical GB/s, percent of the target SKU's declared DRAM peak, output PCC or exact agreement, and repeated-run stability. If a candidate is unexpectedly flat or slow, record per-bank tiles, per-reader physical row bytes, NOC burst splitting, input multicast cores, and math-versus-reader time before classifying the cause. Second, integrate the winner and rerun traced layer and full-model timing plus the focused model/SKU CI. An isolated matmul win is not accepted if surrounding layout, multicast, or end-to-end time regresses.
Llama 3.1 8B on P150 is a reference integration, not a universal selector: explicit two-reader settings for its decode QKV, attention output, gate/up, and down projections improved the batch-32 full-model result from 32.75 to 42.08 t/s/u with flat TTFT. Adjacent Llama and Qwen projection shapes also produced flat and regressing cases in broad sweeps. Therefore always keep the one-reader control and choose the reader count from same-shape evidence.
ttnn.MatmulMultiCoreReuseMultiCastDRAMShardedProgramConfig. It is decode-only: the op rejects an activation taller than one tile row, so prefill rows of any chunk size use the 1D multicast or 2D program configs. Its num_workers_per_dram_bank is limited to 1 to 3 (the op rejects 4), so a reader sweep covers exactly those values.ttnn.MatmulMultiCoreReuseMultiCastProgramConfig over a large 2D grid.per_core_M, per_core_N, in0_block_w, out_subblock_h, out_subblock_w, out_block_h, out_block_w, memory configs, and compute kernel config where the op supports them. Measure traced warmed decode with real model shapes, weights, activations, dtypes, sharding, and batch/sequence settings.in0_block_w>=2 is only a floor. For dominant DRAM-sharded matmuls, sweep upward through legal divisors of the tiled K dimension and the input shard's K-tile width. These candidates do not need to be powers of two; 3, 5, 7, 10, 14, or other divisors can be legal and should be considered when larger than the current setting. Do not satisfy this item by trying 1 and keeping 2, or by stopping at 4/8 because of old expectations. in0_block_w must divide the tiled K dimension; if the current shard spec makes only small values legal, try a different shard-spec core count or working activation shard that enables larger divisors, even if it uses fewer cores. For DRAM-sharded matmuls, the compute core count is fixed by the op, so the input/output shard grid may be more flexible than it first appears. Padding weights or hidden/intermediate channels can be worth trying when it enables a better block size, but the padding must be mathematically inert: padded channels must be sliced, masked, or reduced away before they affect outputs. Changing the shard spec is usually preferable when it preserves the surrounding layout contract.2x1 or 1x2 when legal - again, larger is often better so check the matmul validation code and try larger valid sizes too.in0_block_w<=2 or output subblock sizes are <2 for a matmul that is a non-trivial percentage of the runtime, call them out explicitly in your final output summary and list the exhaustive set of things you tried to enable a larger legal value and why they failed. There's probably a better matmul setting and you should find and use it.in0_block_w, out_subblock_h, or out_subblock_w and see which combination preserves the most performance whilst avoiding the L1 OOM issue.tt-perf-report says a decode matmul (one tile row of activations) is DRAM-bound and it is not DRAM-sharded, trying DRAM-sharded matmul is mandatory. You can usually figure out a way to make it work with resharding if necessary and it's also usually worth it. If you find it is not a performance win, record that you tried and why it was not in your final output summary.ttnn.sparse_matmul groups, keep routed active-expert execution and sweep legal in0_block_w and output-subblock candidates separately for each sparse projection role. Dense all-expert execution is a debug baseline, not an optimized result. The down path often has a different K/N shape and may need is_input_a_sparse=True when it consumes sparse expert activations. Also try input/output memory placement. Sparse weights may live in DRAM, but decode outputs and elementwise/reduction intermediates should stay in L1 or sharded L1 unless a measured L1-capacity blocker prevents it. Explicit ttnn.DRAM_MEMORY_CONFIG on decode intermediates is a performance smell; keep it only with a failed L1 attempt and before/after perf evidence. If tt-perf-report shows slow BinaryNg, Unary, Slice, Reduce, or other non-matmul ops around MoE, first check whether tensors are round-tripping through DRAM before retuning matmul configs. If one candidate hangs, wedges hardware, or fails PCC, reject that candidate, recover the device, and continue with other legal candidates instead of abandoning sparse program-config search.nnzttnn.sparse_matmul(..., nnz=N) selects a faster fixed-count path. The sparse sender skips zero sparsity entries, while receiver and compute kernels loop exactly N times. This is only correct when every invocation has exactly N non-zero entries in the sparsity tensor.
nnz as an exact invariant, not an upper bound. top_k=4 does not prove nnz=4.nnz when the sparsity tensor is constructed or validated so count_nonzero(sparsity) == nnz for every token and batch item. This avoids the runtime inference path and can matter: GPT-OSS Blackhole decode measured about 13-16% faster with a valid static nnz path than with runtime inference.nnz when router weights, masking, dtype conversion, duplicate routes, expert remapping, or Blackhole zero-flush can change the actual non-zero count. The runtime inference path is slower but robust.nnz can hang or wedge the device. With watcher enabled it may fail loudly; without watcher it can look like a hardware hang.nnz, record the reason and the measured decode cost. If that cost is material, try to make the exact-count invariant true without changing model semantics, then remeasure.paged_update_cache inputs should remain BF16/FLOAT32.$autodebug with the failing command, logs, tensor shapes, dtype policy, and first bad tensor; use $autofix when the suspected bug is concrete. Reject the dtype only after the debug loop shows model-visible precision loss, an exact op-contract blocker, or an unfixed bug with preserved evidence.Common Wormhole-style starting points:
compute_kernel_config_lofi = ttnn.WormholeComputeKernelConfig(
math_fidelity=ttnn.MathFidelity.LoFi,
math_approx_mode=False,
fp32_dest_acc_en=False,
packer_l1_acc=True,
)
compute_kernel_config_hifi2_fp16 = ttnn.WormholeComputeKernelConfig(
math_fidelity=ttnn.MathFidelity.HiFi2,
math_approx_mode=False,
fp32_dest_acc_en=False,
packer_l1_acc=True,
)
compute_kernel_config_hifi4 = ttnn.WormholeComputeKernelConfig(
math_fidelity=ttnn.MathFidelity.HiFi4,
math_approx_mode=False,
fp32_dest_acc_en=True,
packer_l1_acc=True,
)
Use the architecture-appropriate config class when optimizing non-Wormhole targets.
For larger-core devices, do not hard-code a Wormhole-shaped 8x4 or 32-core decode layout as the only optimized layout. Sweep legal core grids as a coherent layout: residual/intermediate memory configs, norm program grids, matmul program configs, and shard specs must agree. A first validation error such as a shard grid not fitting an op's program grid means adapt the layout/program-grid contract or use $autofix; it is not enough evidence to reject the larger grid.
tt-perf-reportDo not use this section to collect vLLM serving-stage evidence. vLLM and optimized-vLLM stages intentionally skip Tracy, tt-perf-report, and device-profiler collection to protect T3K hardware.
Install and verify in the active tt-metal environment:
python -m pip install tt-perf-report
tt-perf-report --help
python -m tt_perf_report.perf_report --help
Some environments install only the module form; use python -m tt_perf_report.perf_report with the same arguments.
Generate a Tracy ops CSV for a signposted window:
python -m tracy -r -p -v -m pytest <test-path> -k "<selector>"
If Tracy collection fails, use the device-profiler fallback and post-process:
TT_METAL_DEVICE_PROFILER=1 pytest <test-path> -k "<selector>"
python tools/tracy/process_ops_logs.py --date
Known tooling-failure signatures and prescribed actions - do not burn hours rediscovering these:
EngineCore/server processes and run at most one bounded health check. If tt-smi -ls --local or reset hangs, or if logs show remote Ethernet/ARC/ERISC failures (Timeout waiting for Ethernet core service remote IO request, ETH core heartbeat check failed, Unexpected ERISC Response Flags, Read 0xffffffff from ARC scratch, ARC lock/readback waits), stop profiler collection and run the T3K reset recovery procedure. Do not run a full serving-adapter profile followed by ttnn.ReadDeviceProfiler(mesh). Preserve the logs as hardware-profiler-limited; reboot/re-acquire is a fallback after reset fails, not the first blocker conclusion.TT_METAL_WATCHER_DISABLE_ETH=1 and record the scoped limitation.Copy the final CSV into the artifact directory and run:
export ARTIFACT_DIR="models/autoports/<model>/doc/optimized_decoder"
cp <ops_perf_results_*.csv> "$ARTIFACT_DIR/tracy/<layer_kind_id>/decode_ops.csv"
tt-perf-report "$ARTIFACT_DIR/tracy/<layer_kind_id>/decode_ops.csv" \
--start-signpost PERF_DECODE \
--end-signpost PERF_DECODE_END \
--csv "$ARTIFACT_DIR/tracy/<layer_kind_id>/decode_perf_report.csv" \
> "$ARTIFACT_DIR/tracy/<layer_kind_id>/decode_perf_report.console.log"
tt-perf-report "$ARTIFACT_DIR/tracy/<layer_kind_id>/decode_ops.csv" \
--start-signpost PERF_DECODE \
--end-signpost PERF_DECODE_END \
--no-summary \
> "$ARTIFACT_DIR/tracy/<layer_kind_id>/decode_perf_report.txt"
Use the same pattern for prefill with PERF_PREFILL signposts and prefill_* filenames. If your installed tt-perf-report version uses different flags, run tt-perf-report --help, use the equivalent flags, and record the exact command. You'll have to add these signposts to your code, of course.
The *_perf_report.txt file is for the human-readable table. Do not redirect the stdout from a --csv run into that filename; --csv mode prints command/status boilerplate such as "Writing CSV output..." rather than the rendered report table. Keep that chatter in *_perf_report.console.log if it is useful for provenance.
tt-perf-report runs should keep advice enabled. If you also need a compact no-advice table, run that as a secondary command with a distinct filename and keep the advice-backed table in your work log and final reports.
Check time units before computing latency. Filtered tt-perf-report CSVs may expose Device Time in microseconds; raw Tracy ops CSVs often expose DEVICE KERNEL DURATION [ns].
Sanity-check profiler durations against the benchmark wall time before computing roofline percentages. If a filtered tt-perf-report table claims multi-second device ops inside a sub-millisecond traced decode window, the duration data is invalid. Preserve the raw CSV and report the profiler failure explicitly. When the raw ops CSV has sane performance-model bandwidth columns, you may compute a labeled modeled roofline fallback from sum(PM BANDWIDTH [ns] for decode matmuls) / measured traced decode window; otherwise leave DRAM utilization unreported rather than publishing a bogus percentage.
For every actionable tt-perf-report recommendation:
Avoid suppressing advice in the report used to guide optimization. When applicable advice remains untried, call that out as remaining work rather than implying the optimization pass is complete.
InterleavedToSharded, ShardedToInterleaved, reshard, tilize, untilize, to_torch, or from_torch in the optimized runtime path.TT_METAL_TRACE_ALLOC_TRACKING=1 as specified by $tt-enable-tracing. An optimized path with an unresolved unsafe allocation, an unexplained corruptible-buffer acknowledgment, or acceptance evidence that skips program-cache allocations is incomplete.$tt-enable-tracing. Follow that skill for exact-tensor acknowledgments and minimal allocation scopes. Include any deferred first-capture cost in request latency, not just warmed inner-loop timing.supports_async_decode=True is advertised, the split vLLM path has been exercised: decode_forward(read_from_device=False), read_decode_output(async_read=True), and process_decode_output_host.What SKILL.md sets; muted values are Claude Code's defaults
14 skills in this plugin
/benchmark-modelReport a text model's accuracy on fixed lm-eval subsets and 4K-input vLLM serving performance at concurrency 1 and 32. Use after optimized-vLLM for the final model-bringup report or to benchmark a supported model./datatype-sweepSweep and select TTNN model weight, activation, KV-cache, CCL datatype, and compute-fidelity policies for the fastest configuration that satisfies minimum full-model top-1 and top-5 accuracy. Use after optimized-full-model and before vLLM, or whenever a runnable TTNN full model needs evidence-backed precision selection./full-modelBuild a complete TTNN autoregressive model and generator from a HuggingFace model plus one or more working TTNN block or decoder implementations. Use when assembling embeddings, block stack, final norm, logits, KV-cache handling, and generation into a full model, validating end-to-end behavior, and reporting full-model accuracy plus generator-level performance. Repo-specific file contracts belong in a project orchestration skill such as model-bringup.npx claudepluginhub tenstorrent/skills --plugin tt-model-bringupOther plugins' skills for the same job