performance-tuning
Tune FFCV cache, traversal, loader concurrency, compilation, and measurement choices; diagnose RAM, disk, CPU, and GPU bottlenecks without unsafe benchmark-scale execution.
- License 许可
- Apache-2.0
- 最近更新
- 2026-09-03
- Stars
- ★ 351
- Forks
- 27
01 前言 Front Matter
- name
- performance-tuning
- license
- Apache 2.0
- metadata
- { "disco-role": "operating" }
- description
- Tune FFCV cache, traversal, loader concurrency, compilation, and measurement choices; diagnose RAM, disk, CPU, and GPU bottlenecks without unsafe benchmark-scale execution.
- disable-model-invocation
- true
02 资源文件 3
- 参考文档references/benchmarking.md5.8 KB
- 参考文档references/troubleshooting.md10.0 KB
- 参考文档references/tuning.md9.8 KB
03 SKILL.md 正文
FFCV performance tuning
Use this sub-skill when an FFCV Loader is correct but throughput, latency,
resource use, or distributed behavior needs diagnosis. It owns cache selection,
OrderOption selection, loader concurrency/prefetch knobs, compiler behavior,
small measurements, and resource-bottleneck recovery. It does not own
writer format design, decoder/transform semantics, or end-to-end model tuning.
Fast routing
- Establish a correct baseline on a tiny or already-available
.betondataset. Record dataset size, available RAM, storage type, CPU affinity, GPU count, batch size, pipeline, and whether the loader is distributed. - Choose cache and order together using tuning.md.
Do not choose
QUASI_RANDOMbefore checkingdistributed. - Change one of
num_workers,batches_ahead, orrecompileat a time. Keep the same seed, batch size, pipeline, and measurement window. - Diagnose the scarce resource with troubleshooting.md.
- Measure only after the hypothesis is explicit. Start with
python -m ffcv.benchmarks --help; the safe CLI procedure is in benchmarking.md. Never make the full benchmark matrix or a long training run the default validation path.
Decision rules
| Situation | Starting point | Guardrail |
|---|---|---|
| Dataset fits comfortably in RAM, or several processes share it | os_cache=True with RANDOM or QUASI_RANDOM |
The first epoch can be slower while the OS warms its cache. |
| Dataset is larger than RAM and randomness need not be perfectly uniform | os_cache=False plus OrderOption.QUASI_RANDOM |
This combination is specifically for process-level page reuse; it is unavailable with distributed=True. |
| Dataset is larger than RAM and exact distributed sampling is required | os_cache=False with SEQUENTIAL or RANDOM, distributed=True |
QUASI_RANDOM raises NotImplementedError in distributed mode. Test the I/O cost of RANDOM before adopting it. |
| Dataset order must be repeatable | SEQUENTIAL, or seeded RANDOM |
In non-distributed mode random order uses seed + epoch; in distributed mode PyTorch DistributedSampler is used. |
| CPU is saturated and the GPU is idle | Start at the physical-core count or fewer for num_workers; prefer FFCV JIT transforms |
num_workers controls compiler thread counts, not a pool of Python worker processes. |
| Prefetch causes memory pressure or no overlap benefit | Lower batches_ahead from its default of 3 |
It sizes the output queue/ring buffers; lowering trades overlap for RAM/GPU headroom. |
| An augmentation implementation changes between epochs | recompile=True |
It recompiles generated pipeline code each epoch; otherwise keep the default False. |
These are starting hypotheses, not throughput guarantees. Validate on the
actual storage and pipeline. os_cache=True uses a read-only numpy.memmap
backed by the operating system; os_cache=False creates a process-level page
schedule for each epoch and prefetches pages into reusable slots. The process
cache is not a second full-dataset cache.
Loader knobs that interact
num_workers=-1resolves to the process CPU affinity. A positive value is passed toCompiler.set_num_threads, which sets both Numba and PyTorch thread counts. FFCV is thread-based; do not interpret it as PyTorch's process worker count. More threads can hurt when JIT operations are already efficient.batches_aheaddefaults to3.EpochIteratoruses it for the bounded result queue, CUDA stream count (batches_ahead + 2), and rotating operation buffers. Increase only when the consumer is waiting for data and memory is available; decrease when host/device buffers or latency variance is the problem.recompile=Falsecompiles the graph when the loader is constructed and on the first iteration. WithTrue,Loader.__iter__regenerates code each epoch. Use it only when a stateful/dynamic augmentation really changes its implementation or generated code.seedis part of the reproducibility contract. With distributed random order and no seed,Loaderwarns and sets the seed to0to match PyTorch's sampler. For other missing-seed cases it generates a seed, so record the resulting loader configuration if comparing runs.Compileris enabled by default. When enabled,Compiler.compilewraps functions with Numbanjit(fastmath=True, nogil=True, error_model='numpy'); parallel functions useprangeonly when they advertiseis_paralleland the configured thread count is greater than one. Disabling compilation is a diagnostic/benchmark comparison, not a normal performance fix.
Safe operating procedure
- Verify the loader configuration and that all requested samples are seen. Do not use throughput changes to excuse ordering or distributed correctness failures.
- Capture one baseline with a bounded warm-up and a small number of timed iterations. Avoid comparing a cold OS cache to a warm process cache without labeling the state.
- Look for the symptom class: disk wait/GPU idle, CPU saturation, host RAM growth, GPU memory pressure, or model-side GPU saturation.
- Apply one reversible change, rerun the same bounded measurement, and retain the configuration plus result. If the change does not target the scarce resource, revert it.
- For a dataset larger than RAM, explicitly try the difficult-case baseline:
os_cache=False,order=OrderOption.QUASI_RANDOM,distributed=False. For distributed training, explicitly useSEQUENTIALorRANDOMinstead.
Verification boundary
The repository evidence supports CPU smoke checks, memory-reader/allocation checks, traversal-order tests, and a tiny CUDA allocation probe. Full benchmark matrices, ImageNet benchmark reproduction, and long training are excluded from routine verification. See the references for source anchors and hard cases.
04 同仓库更多 Skills
passnet-triton-opt
Make a single PassNet Triton kernel fast AND numerically faithful: performance model (when a replacement can win at all), block/grid/warp tuning, autotune policy, launch overhead, and per-op numeric recipes to pass the dtype baseline tolerances. Use when a pass matches and is correct but speedup below expected, or when correctness fails by small numeric margins.
passnet-solve
END-TO-END playbook for solving one PassNet sample: analyze the computation graphs, decide the optimization strategy (what to fuse, what to replace, what to leave alone), drive the iteration loop, and maximize the sample score. This is the ENTRY skill — invoke it first for any PassNet optimization task; it tells you when to use passnet-pattern-fusion, passnet-triton-opt and passnet-feedback.
passnet-skill
PassNet GPU kernel optimization via compiler passes. Design and implement Triton-based optimization passes, create pass files under ./pass_dir/, self-evaluate with pass_evaluator, and iterate to maximize GPU speedup.
passnet-pattern-fusion
Author PassNet pass files: write patterns that actually MATCH the FX graph, pick fusion regions (which ops to absorb into one Triton kernel), and structure multi-pass submissions with the mandatory shared-dispatch architecture. Use when creating or fixing pattern()/replacement_args()/replacement_func() files, when a pass "failed to match", or when deciding how to fuse multiple kernels/ops.
passnet-orchestrate
Round/batch planning and decision support for PassNet graph optimization. Use for multi-sample triage, worker allocation, eval-budget policy, and post-eval keep/revert decisions. For solving one concrete sample end to end, use passnet-solve as the entry skill; consult this skill only when you need broader planning or a specific decision gate.
passnet-feedback
Fast, deterministic feedback for PassNet work: pre-flight pattern/match verification WITHOUT burning a GPU evaluation, per-node bottleneck analysis of a sample's graphs, and eval-log parsing into per-variant status + estimated score + failure classification. Use BEFORE every GPU evaluation (check_pattern), at the START of a sample (analyze_graph), and AFTER every evaluation (parse_eval_log).