Skip to main content

HaoLine (皓线) - Universal Model Inspector. See what's really inside your models.

Project description

HaoLine (皓线)

Universal Model Inspector — See what's really inside your neural networks.

PyPI version Python 3.10+ License: MIT

HaoLine analyzes neural network architectures and generates comprehensive reports with metrics, visualizations, and AI-powered summaries. Works with ONNX, PyTorch, and TensorFlow models.


Complete Beginner Guide

Don't have a model yet? No problem. Follow these steps to analyze your first model in under 5 minutes.

Step 1: Install HaoLine

pip install haoline[llm]

This installs HaoLine with chart generation and AI summary support.

Step 2: Get a Model to Analyze

Option A: Download a pre-trained model from Hugging Face

# Install huggingface_hub if you don't have it
pip install huggingface_hub

# Download a small image classification model (MobileNet, ~14MB)
python -c "from huggingface_hub import hf_hub_download; hf_hub_download('onnx/models', 'validated/vision/classification/mobilenet/model/mobilenetv2-7.onnx', local_dir='.')"

Option B: Use your own model

If you have a .onnx, .pt, .pth, or TensorFlow SavedModel, you can analyze it directly.

Option C: Convert a PyTorch model

# HaoLine can convert PyTorch models on the fly
haoline --from-pytorch your_model.pt --input-shape 1,3,224,224 --out-html report.html

Step 3: Set Up AI Summaries (Optional but Recommended)

To get AI-generated executive summaries, set your OpenAI API key:

# Linux/macOS
export OPENAI_API_KEY="sk-..."

# Windows PowerShell
$env:OPENAI_API_KEY = "sk-..."

# Or create a .env file in your working directory
echo "OPENAI_API_KEY=sk-..." > .env

Get your API key at: https://platform.openai.com/api-keys

Step 4: Generate Your Full Report

haoline mobilenetv2-7.onnx \
  --out-html report.html \
  --include-graph \
  --llm-summary \
  --hardware auto

This generates report.html containing:

  • Model architecture overview
  • Parameter counts and FLOPs analysis
  • Memory requirements
  • Interactive neural network graph (zoomable, searchable)
  • AI-generated executive summary
  • Hardware performance estimates for your GPU

Open report.html in your browser to explore your model!


Installation Options

Command What You Get
pip install haoline Core analysis + charts
pip install haoline[llm] + AI-powered summaries
pip install haoline[full] + PDF export, GPU metrics, runtime profiling

Common Commands

# Basic analysis (prints to console)
haoline model.onnx

# Generate HTML report with charts
haoline model.onnx --out-html report.html --with-plots

# Full analysis with interactive graph and AI summary
haoline model.onnx --out-html report.html --include-graph --llm-summary

# Specify hardware for performance estimates
haoline model.onnx --hardware rtx4090 --out-html report.html

# Auto-detect your GPU
haoline model.onnx --hardware auto --out-html report.html

# List all available hardware profiles
haoline --list-hardware

# Convert and analyze a PyTorch model
haoline --from-pytorch model.pt --input-shape 1,3,224,224 --out-html report.html

# Convert and analyze a TensorFlow SavedModel
haoline --from-tensorflow ./saved_model_dir --out-html report.html

# Generate JSON for programmatic use
haoline model.onnx --out-json report.json

Compare Model Variants

Compare different quantizations or architectures side-by-side:

haoline compare \
  --models resnet_fp32.onnx resnet_fp16.onnx resnet_int8.onnx \
  --baseline-precision fp32 \
  --out-html comparison.html \
  --with-charts

CLI Reference

Output Options

Flag Description
--out-json PATH Write JSON report
--out-md PATH Write Markdown model card
--out-html PATH Write HTML report (single shareable file)
--out-pdf PATH Write PDF report (requires playwright)
--html-graph PATH Write standalone interactive graph HTML
--layer-csv PATH Write per-layer metrics CSV

Report Options

Flag Description
--include-graph Embed interactive D3.js graph in HTML report
--include-layer-table Include sortable per-layer table in HTML
--with-plots Generate matplotlib visualization charts
--assets-dir PATH Directory for chart PNG files

Hardware Options

Flag Description
--hardware PROFILE GPU profile (auto, rtx4090, a100, h100, etc.)
--list-hardware Show all 50+ available GPU profiles
--precision {fp32,fp16,bf16,int8} Precision for estimates
--batch-size N Batch size for estimates
--gpu-count N Multi-GPU scaling (2, 4, 8)
--cloud INSTANCE Cloud instance (e.g., aws-p4d-24xlarge)
--list-cloud Show available cloud instances
--system-requirements Generate Steam-style min/recommended specs
--sweep-batch-sizes Find optimal batch size
--sweep-resolutions Analyze resolution scaling

LLM Options

Flag Description
--llm-summary Generate AI-powered executive summary
--llm-model MODEL Model to use (default: gpt-4o-mini)

Conversion Options

Flag Description
--from-pytorch PATH Convert PyTorch model to ONNX
--from-tensorflow PATH Convert TensorFlow SavedModel
--from-keras PATH Convert Keras .h5/.keras model
--from-jax PATH Convert JAX/Flax model
--input-shape SHAPE Input shape for conversion (e.g., 1,3,224,224)
--keep-onnx PATH Save converted ONNX to path

Other Options

Flag Description
--quiet Suppress console output
--progress Show progress for large models
--log-level {debug,info,warning,error} Logging verbosity

Python API

from haoline import ModelInspector

inspector = ModelInspector()
report = inspector.inspect("model.onnx")

# Access metrics
print(f"Parameters: {report.params.total:,}")
print(f"FLOPs: {report.flops.total:,}")
print(f"Peak Memory: {report.memory.peak_activation_bytes / 1e9:.2f} GB")

# Export reports
report.to_json("report.json")
report.to_markdown("model_card.md")
report.to_html("report.html")

Features

Feature Description
Parameter Counts Per-node, per-block, and total parameter analysis
FLOP Estimates Identify compute hotspots in your model
Memory Analysis Peak activation memory and VRAM requirements
Risk Signals Detect problematic architecture patterns
Hardware Estimates GPU utilization predictions for 30+ NVIDIA profiles
Runtime Profiling Actual inference benchmarks with ONNX Runtime
Visualizations Operator histograms, parameter/FLOPs distribution charts
Interactive Graph Zoomable D3.js neural network visualization
AI Summaries GPT-powered executive summaries of your architecture
Multiple Formats Export to HTML, Markdown, PDF, JSON, or CSV

Supported Model Formats

Format Support Notes
ONNX (.onnx) ✅ Full Native support
PyTorch (.pt, .pth) ✅ Full Auto-converts to ONNX
TensorFlow SavedModel ✅ Full Requires tf2onnx
Keras (.h5, .keras) ✅ Full Requires tf2onnx
TensorRT Engine 🔜 Coming Planned
SafeTensors 🔜 Coming Planned

LLM Providers

HaoLine supports multiple AI providers for generating summaries:

Provider Environment Variable Get API Key
OpenAI OPENAI_API_KEY platform.openai.com
Anthropic ANTHROPIC_API_KEY console.anthropic.com
Google Gemini GOOGLE_API_KEY aistudio.google.com
xAI Grok XAI_API_KEY console.x.ai

Where to Find Models

Source URL Notes
Hugging Face ONNX huggingface.co/onnx Pre-converted ONNX models
ONNX Model Zoo github.com/onnx/models Official ONNX examples
Hugging Face Hub huggingface.co/models PyTorch/TF models (convert with HaoLine)
TorchVision torchvision.models Classic vision models
Timm github.com/huggingface/pytorch-image-models State-of-the-art vision models

Security Notice

⚠️ Loading untrusted models is inherently risky.

Like PyTorch's torch.load(), HaoLine uses pickle when loading certain model formats. These can execute arbitrary code if the model file is malicious.

Best practices:

  • Only analyze models from trusted sources
  • Run in a sandboxed environment (Docker, VM) when analyzing unknown models
  • Review model provenance before loading

License

MIT License - See LICENSE for details.


Etymology

HaoLine (皓线) combines:

  • 皓 (hào) = "bright, luminous" in Chinese
  • Line = the paths through your neural network

"Illuminating the architecture of your models."

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

haoline-0.2.3.tar.gz (379.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

haoline-0.2.3-py3-none-any.whl (212.3 kB view details)

Uploaded Python 3

File details

Details for the file haoline-0.2.3.tar.gz.

File metadata

  • Download URL: haoline-0.2.3.tar.gz
  • Upload date:
  • Size: 379.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.8

File hashes

Hashes for haoline-0.2.3.tar.gz
Algorithm Hash digest
SHA256 b0994918a888e58a029a944906bb6f5566395d2ca36a50e7cdd427d26d9f3422
MD5 352aa477bd5bd43baf63689f0e2f6a15
BLAKE2b-256 c8b3d4a3239a93e06a145188d948c61b2237202c297b37f0a08b871a2f9ec032

See more details on using hashes here.

File details

Details for the file haoline-0.2.3-py3-none-any.whl.

File metadata

  • Download URL: haoline-0.2.3-py3-none-any.whl
  • Upload date:
  • Size: 212.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.8

File hashes

Hashes for haoline-0.2.3-py3-none-any.whl
Algorithm Hash digest
SHA256 c34c26faa2f9dfa80662da0ae44b2978e15732708ba0ee807ec8087449284621
MD5 b960c2b195ef2b5127341e49f67fcff0
BLAKE2b-256 25272179b4af25faa0a3ed4dc21796031b3a49dbdbb85878b3493372ef72f3fe

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page