> For clean Markdown content of this page, append .md to this URL.

# Just-in-Time Inspect Guide

Just-in-time inspection captures module hierarchy and input/output signatures during real model execution, without tuning or compilation. Use it to understand what JIT tuning would see before you commit to a tuning strategy.

## Overview

Just-in-time inspection provides:

- **Module Discovery**: Capture modules that execute at runtime
- **Hierarchy View**: See parent/child relationships and depth
- **Input/Output Signatures**: Record tensor shapes, dtypes, and argument structure
- **HTML Report**: Generate a shareable inspection report

## Quick Start

### Enable inspection

Add a single import at the top of your script to enable inspection mode:

```python
import aitune.torch.jit.enable_inspection as inspection  # noqa: F401
```

### Run a real workload and save a report

The example below mirrors the Stable Diffusion inspection workflow used in
`tests/functional/pytorch/jit/006_jit_sd15_inspect.py`:

```python
import os
from logging import INFO, basicConfig
from pathlib import Path

import torch
from diffusers import StableDiffusionPipeline

import aitune.torch.jit.enable_inspection as inspection  # noqa: F401


def create_model():
    pipe = StableDiffusionPipeline.from_pretrained(
        "stable-diffusion-v1-5/stable-diffusion-v1-5", torch_dtype=torch.float16
    )
    pipe.to("cuda")
    return pipe


def main():
    basicConfig(level=INFO)
    prompt = (
        "A fluffy, orange tabby cat with bright green eyes is captured mid-air, "
        "pouncing playfully on a vibrant red ball of yarn"
    )
    pipe = create_model()

    def batch():
        with torch.no_grad():
            pipe([prompt] * 1, num_inference_steps=1)
            pipe([prompt] * 2, num_inference_steps=1)

    for _ in range(5):
        batch()

    html_path = "inspect_sd15.html"
    inspection.save_report(html_path, "SD15")


if __name__ == "__main__":
    main()
```

### Open the report

```bash
firefox inspect_sd15.html
# or
google-chrome inspect_sd15.html
```

## What the report shows

- **Module summary**: Total modules and basic statistics
- **Module hierarchy**: Tree view of the executed module structure
- **Module details**: Name, type, depth, parameter counts, call counts, execution times
- **Inputs/outputs**: Shapes, dtypes, and detected batch axes for each executed module

### Example screenshots

The main view gives a top-level summary of discovered modules and quick navigation across the report sections.

![JIT inspect module main](https://fdr-prod-docs-files-public.s3.us-east-1.amazonaws.com/aitune.docs.buildwithfern.com/aitune/05c6be7996f33aaab8e67ef49e2ce66e23fd8342fe3f580d970876d849a52ea8/pages-v0.5.0/assets/jit_inspect_main.png?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Content-Sha256=UNSIGNED-PAYLOAD&X-Amz-Credential=AKIA6KXJSKKNFOCF7G4B%2F20260806%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20260806T161652Z&X-Amz-Expires=604800&X-Amz-Signature=4ee485082ae55b14072df713e8012570385ffaf334e4bf386d7475eeb024a8cc&X-Amz-SignedHeaders=host&x-amz-checksum-mode=ENABLED&x-id=GetObject)

If you click on a particular module, the detailed view shows execution stats and its recorded input/output signatures.

![JIT inspect module details](https://fdr-prod-docs-files-public.s3.us-east-1.amazonaws.com/aitune.docs.buildwithfern.com/aitune/db700563c0312ccacaa83c58925aebec5c68e8ae34a6bec0e6bc2293ba8117be/pages-v0.5.0/assets/jit_inspect_details.png?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Content-Sha256=UNSIGNED-PAYLOAD&X-Amz-Credential=AKIA6KXJSKKNFOCF7G4B%2F20260806%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20260806T161652Z&X-Amz-Expires=604800&X-Amz-Signature=d61401b549ffa565048640742befe991a380f2e6b1d960684a90e14b7f3a2f6a&X-Amz-SignedHeaders=host&x-amz-checksum-mode=ENABLED&x-id=GetObject)

## Notes

- Inspection data is collected only for modules that actually execute.
- Running multiple batches with different shapes helps capture dynamic behavior.
- The report is generated from in-memory inspection data at `save_report` time.

## Next Steps

- Learn about [Just-in-Time Tuning](/aitune/guides/just-in-time-tuning) to actually tune models
- Compare with [AOT Inspect](/aitune/guides/ahead-of-time-inspect) for more control