Add model analyzer scripts and setup#146
Conversation
Introduce Python scripts for analyzing ONNX and TFLite models to help understand their structure and features. Added a local virtual environment setup to manage dependencies without affecting the global system.
| echo "" | ||
| echo "Setup complete! To run the scripts, use the following command:" | ||
| echo " source script/model-analyzer/venv/bin/activate" | ||
| echo " python script/model-analyzer/analyze_onnx.py" |
There was a problem hiding this comment.
Maybe add (or onnx files path in this example) here at the end for more clarity?
rmahdav
left a comment
There was a problem hiding this comment.
Interesting add-on to the benchmark! Do you have any sample analysis result? And how do you think the analysis result will help us improving the benchmark?
|
I'm planning to run this on more of the models that we're thinking of adding to see if they cover anything new. I was also curious what are the most common operations and data types. Here's a sample from one: I've also collected some overall data: |
|
Letting gemini do some analysis: prompt: Model Analysis ReportOverviewThis report summarizes the analysis of ONNX and TFLite models found in the repository, specifically within the Well Covered OperationsONNX ModelsThe ONNX models are heavily dominated by Transformer architectures and attention mechanisms, leading to high coverage of the following operations:
TFLite ModelsThe TFLite models are primarily vision-based (MediaPipe and MobileNet), showing high coverage of:
Well Covered Data TypesONNX Models
TFLite Models
Models with High OverlapONNX TransformersThere is massive overlap among the Transformer-based models:
These models all share the same basic building blocks: large numbers of TFLite Vision Models
Interesting Observations
|
tflite as subgraphs.
|
I would also be fine with this living in my branch only, since it's largely vibe coded and for research only. |
| try: | ||
| # Load the model and allocate tensors. | ||
| interpreter = tf.lite.Interpreter(model_path=model_path) | ||
| interpreter.allocate_tensors() |
There was a problem hiding this comment.
Do we need this allocation for the analysis? I think this line will fail for models with dynamic shapes e.g. [?, 224, 224, 3]. Maybe we can remove it if it is not necessary/needed, or somehow handle the dynamic shape?
|
|
||
| utils.print_op_breakdown(op_counts, show_all_ops) | ||
|
|
||
| has_quantization = any(op.startswith("Quantize") or "MatMulInteger" in op or "DynamicQuantize" in op or op == "MatMulNBits" for op in op_counts) |
There was a problem hiding this comment.
I think there are more quantization related operations, meybe we have have a more comprehensive list? The below is AI suggested list, I haven't check to see if it is complete and correct:
| has_quantization = any(op.startswith("Quantize") or "MatMulInteger" in op or "DynamicQuantize" in op or op == "MatMulNBits" for op in op_counts) | |
| quant_ops = { | |
| "QuantizeLinear", "DequantizeLinear", "QLinearConv", | |
| "QLinearMatMul", "MatMulInteger", "ConvInteger", | |
| "DynamicQuantizeLinear", "MatMulNBits" | |
| } | |
| has_quantization = any( | |
| any(q_op in op for q_op in quant_ops) | |
| for op in op_counts | |
| ) |
|
I added a few comments. The output and analysis are so interesting and I would love to have the script merged into the repository. |
Introduce Python scripts for analyzing ONNX and TFLite models to help understand their structure and features.
Added a local virtual environment setup to manage dependencies without affecting the global system.