Skip to content
Back to skills

Runtime Optimization

ASecurity

"Use this sub-skill for Torch-TensorRT runtime performance

  • 247 stars
  • 0 votes
  • 0 copies
  • 2 views
  • Added September 9, 2026
businesspythongoc++railsdebuggingapiperformance

Works with

  • api

Security analysis

A100/100

Pro scans all 7 files and shows the line behind each finding

Scanned September 9, 2026

npx -y skills add VectorSpaceLab/AREX-Skill --skill runtime-optimization --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Runtime Optimization?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Runtime Optimization
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/vectorspacelab-runtime-optimization/badge)](https://www.skillsdirectory.com/skills/vectorspacelab-runtime-optimization)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: runtime-optimization
description: "Use this sub-skill for Torch-TensorRT runtime performance
  controls, CUDA Graphs, output allocation, caches, TensorRT-RTX runtime
  settings, mutable modules, refit, weight streaming, and benchmark triage."
metadata:
  disco-role: operating
disable-model-invocation: true
license: BSD 3-Clause
---

# Torch-TensorRT Runtime Optimization

Use this sub-skill after a model compiles, or when a user asks about runtime latency, memory, caches, CUDA Graphs, output buffers, TensorRT-RTX settings, mutable modules, refit, or benchmark methodology.

## Start with correctness and observability

1. Confirm the compiled module produces correct outputs for representative inputs.
2. Verify `torch_tensorrt.ENABLED_FEATURES`; runtime APIs are gated by standard TensorRT vs TensorRT-RTX and by whether C++ runtime libraries are present.
3. Benchmark with warmups and CUDA synchronization/events. Do not time only the first call, because it may include engine build, lazy initialization, or TensorRT-RTX JIT work.
4. Use `references/performance-and-memory.md` for memory/latency triage before changing many knobs at once.

## Route by runtime need

| User goal | Read/run |
| --- | --- |
| Apply CUDA Graphs, output allocator, preallocated outputs, weight streaming, runtime config, or TensorRT-RTX settings | `references/workflows.md` |
| Need exact runtime API names and signatures | `references/api-reference.md` |
| Diagnose high latency, OOM, compile/runtime cache behavior, dynamic shape profile choice, or benchmark design | `references/performance-and-memory.md` |
| Debug runtime errors, cache/load failures, CUDAGraph invalidation, allocator issues, or RTX-only setting surprises | `references/troubleshooting.md` |
| Need a safe script to inspect runtime feature availability | `scripts/runtime_feature_probe.py --help` |
| Need a benchmarking template | `scripts/benchmark_latency_template.py --help` |

## Main workflows

### CUDA Graphs

Use CUDA Graphs only after shapes and memory addresses are stable enough for capture.

```python
from torch_tensorrt import runtime

with runtime.enable_cudagraphs(compiled) as graph_module:
    for _ in range(10):
        _ = graph_module(*example_inputs)
```

For TensorRT-RTX, CUDA graph strategy may also be set through `RuntimeSettings` or `runtime_config`.

### TensorRT-RTX runtime settings

```python
from torch_tensorrt.runtime import RuntimeSettings

compiled.runtime_settings = RuntimeSettings(
    runtime_cache="trt_rtx_cache.bin",
    dynamic_shapes_kernel_specialization_strategy="eager",
    cuda_graph_strategy="whole_graph_capture",
)
```

These fields are no-ops or unavailable outside TensorRT-RTX. Apply settings before first execution when the execution context is lazily created.

### Engine and timing caches

Use compile-time `timing_cache_path`, `cache_built_engines`, `reuse_cached_engines`, `engine_cache_dir`, and `engine_cache_size` when repeated builds or dynamic variants dominate latency. Cache paths should be writable, stable for the workload, and isolated per incompatible model/settings pair.

### Mutable modules and refit

Use `MutableTorchTensorRTModule` or `refit_module_weights` when weights change and recompiling every time would be expensive. Compile with `immutable_weights=False` when refit/mutability is required.

### Weight streaming and resource controls

Use weight streaming, `offload_module_to_cpu`, resource partitioning, or smaller max dynamic shapes for memory pressure. Validate latency after each change; some memory-saving settings trade off performance.

## Guardrails

- Runtime settings do not fix unsupported operators; route unsupported-op work to `../extensibility-and-debugging/SKILL.md`.
- Cache hits are only valid for compatible engine settings, target device properties, TensorRT versions, and model weights where applicable.
- CUDA Graph capture can fail when input shapes, allocation patterns, data-dependent behavior, or unsupported operations change between captures.
- Do not promise TensorRT-RTX cache/strategy behavior in a standard TensorRT build.
- Do not promise C++ runtime or TorchScript behavior from a Python-only wheel.

Files in this skill

  • SKILL.md4.1 KB
  • references/api-reference.md3.7 KB
  • references/performance-and-memory.md3.6 KB
  • references/troubleshooting.md3.1 KB
  • references/workflows.md4.1 KB
  • scripts/benchmark_latency_template.py3.4 KB
  • scripts/runtime_feature_probe.py2.2 KB

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.