Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions tests/tools/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
matplotlib
nbclient
nbformat
psutil
pytest
pandas
Expand Down
46 changes: 46 additions & 0 deletions tests/tools/test_profiler.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# Copyright (c) 2025 Intel Corporation
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# http://www.apache.org/licenses/LICENSE-2.0
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import os
import tempfile
from pathlib import Path

import nbformat
from nbclient import NotebookClient


def test_tiny_llama_profiling_notebook():
"""Test that the tiny_llama_profiling.ipynb notebook runs successfully."""
notebook_path = Path(__file__).parent.parent.parent / "tools" / "profiler" / "tiny_llama_profiling.ipynb"
profiler_dir = Path(__file__).parent.parent.parent / "tools" / "profiler"

# Check if notebook exists
assert notebook_path.exists(), f"Notebook not found at {notebook_path}"

# Read the notebook
with open(notebook_path) as f:
nb = nbformat.read(f, as_version=4)

# Execute the notebook using nbclient with a temporary IPython config directory
with tempfile.TemporaryDirectory() as tmpdir:
os.environ['IPYTHONDIR'] = tmpdir
# Save original working directory
original_cwd = os.getcwd()
try:
# Change to profiler directory for notebook execution
os.chdir(str(profiler_dir))
client = NotebookClient(nb, timeout=600)
client.execute()
finally:
# Clean up: restore working directory and environment variable
os.chdir(original_cwd)
if 'IPYTHONDIR' in os.environ:
del os.environ['IPYTHONDIR']
14 changes: 14 additions & 0 deletions tools/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -153,3 +153,17 @@ The input file should contain the following columns:
```shell
python visualize_compression_results.py --input-file data/llama2_asym.csv --output-dir output_dir
```

## Profiler

The Profiler is a tool for collecting and analyzing activation statistics from OpenVINO models. It enables layer-by-layer profiling of model activations using NNCF infrastructure, making it useful for debugging quantization and compression issues, comparing model variants, and understanding activation distributions.

Key features:

- Collect raw activations at input and output of specific layers using regex pattern matching
- Calculate custom statistics (min, max, mean, std, percentiles, etc.) on collected activations
- Compare activations between two model variants (e.g., FP32 vs INT8) with built-in and custom metrics
- Visualize activation distributions and comparison results with matplotlib
- Extensible architecture allowing registration of custom statistics, comparators, and visualizers

See [tiny_llama_profiling.ipynb](profiler/tiny_llama_profiling.ipynb) for a complete usage example demonstrating how to profile an OpenVino model, collect activation statistics, and compare FP32 vs INT8 quantized variants.
Loading