yobx.helpers.stats_helper#

ModelStatistics#

class yobx.helpers.ModelStatistics(model: ModelProto | GraphBuilderExtendedProtocol, verbose: int = 0)[source]#

Computes statistics on an ONNX model, including node counts per op_type and estimated FLOPs.

model may be either an onnx.ModelProto or a GraphBuilderExtendedProtocol instance. When a graph builder is provided its already-computed shape information is used directly (no second shape-inference pass is run) and the ONNX model is obtained via to_onnx().

Parameters:
  • model – ONNX model or graph builder

  • verbose – verbosity level passed to BasicShapeBuilder (ignored when model is a graph builder)

Usage:

stats = ModelStatistics(model).compute()
compute() Dict[str, Any][source]#

Runs the full analysis and returns a statistics dictionary.

Returns:

dictionary with the following keys:

  • "n_nodes" – total number of nodes

  • "node_count_per_op_type" – dict mapping op_type → count

  • "total_estimated_flops" – total estimated FLOPs (int or None)

  • "flops_per_op_type" – dict mapping op_type → estimated FLOPs (None means the cost could not be estimated for some nodes)

  • "node_stats" – list of per-node dicts with keys op_type, name, inputs, outputs, estimated_flops

literal_fn(name: str) Tuple[int, ...] | None[source]#

Returns the integer values stored in a 1-D integer constant tensor (e.g. the shape input of a Reshape node), or None when name is not a known constant.

shape_fn(name: str) Tuple | None[source]#

Returns the inferred shape of name, or None if unknown.

model_statistics#

yobx.helpers.model_statistics(model: ModelProto | GraphBuilderExtendedProtocol, verbose: int = 0) Dict[str, Any][source]#

Computes statistics on an ONNX model.

This is a convenience wrapper around ModelStatistics.

Parameters:
  • model – ONNX model or graph builder

  • verbose – verbosity level

Returns:

statistics dictionary — see ModelStatistics.compute() for details

Module#

Functions to compute statistics on an ONNX model such as number of nodes per op_type and estimation of computational cost.

yobx.helpers.stats_helper.model_statistics(model: ModelProto | GraphBuilderExtendedProtocol, verbose: int = 0) Dict[str, Any][source]#

Computes statistics on an ONNX model.

This is a convenience wrapper around ModelStatistics.

Parameters:
  • model – ONNX model or graph builder

  • verbose – verbosity level

Returns:

statistics dictionary — see ModelStatistics.compute() for details