liveBook · Manning

Profiling

As explained in Domain-Specific Small Language Models

The practice of collecting runtime measurements for model execution to identify bottlenecks and optimization opportunities.

Profiling collects runtime measurements from model execution to expose bottlenecks and guide optimization. In ONNX Runtime, profiling is disabled by default; enabling it produces JSON data covering threading and per-operator latency. section 10.0 section 10.1

A practical profiling workflow is:

  • Enable profiling on the inference session and run representative inference workloads. section 10.1
  • Call end_profiling to retrieve the generated JSON file, whose records identify operators, execution providers, durations, shapes, and thread information. section 10.1
  • Transform raw records into tables and aggregate total duration, invocation count, and percentage of inference time by operator. section 10.2
  • Use Ort_perf_view or custom visualizations to locate expensive operators and prioritize model or runtime changes against latency, throughput, and memory KPIs. section 10.1 section 10.2

From regression model to operator report

A scikit-learn linear regression model converted to ONNX can be profiled over a test set. Processing the resulting JSON with mlprodict and plotting it with Plotly reveals which operators consume the most total and proportional inference time; the same process applies to larger ONNX models and LLMs. section 10.2

import onnxruntime as rt

sess_options = rt.SessionOptions()
sess_options.enable_profiling = True

Shows the minimal ONNX Runtime session configuration needed to enable runtime profiling. section 10.1

How Domain-Specific Small Language Models covers it

How deep it goes
Descends from session configuration through raw JSON extraction, operator aggregation, and visualization, but defers specific optimization remedies.
Examples
Uses linear regression, ONNX conversion, test-set inference, Ort_perf_view, mlprodict tables, and Plotly operator charts.
What it assumes
Assumes an ONNX model and an ONNX Runtime inference session, while demonstrating profiling setup and data interpretation.
What you can do after
Diagnose/debug with it by producing profiling reports that rank operators by duration, invocation count, and share of inference time.
How it connects
Connects ONNX Runtime, ONNX models, execution providers, operator latency, model optimization, and performance visualization.

Also explained in

Compare how 11 books explain profiling →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Domain-Specific Small Language Models. The section links point to the parts of the book it draws on.