Mintro is a Python library designed for introspection and analysis of machine learning models, with a focus on providing primitives and reusable code to develop security focused applications. The library provides tools to examine models both statically and dynamically. The functionality is currently focused on torch models.
🚧 The
mintroproject does not have dedicated resource supporting its development. This means that this library is supported on an ad-hoc basis.
- Static Analysis: Extract module weights, metadata and computational graphs from models.
- Dynamic Analysis: Fine-grained collection of activation and loss information
- Modular Design: Built to be a foundational library for more advanced model analytics
- Reusable Metrics: Calculate metrics on extracted artifacts to aid fine-grained analysis
This project uses uv as its dependency manager. Please install uv for your platform by following the official installation guide.
# Pull the repo
git clone https://github.com/alan-turing-institute/mintro.git
# Navigate into the repository
cd mintro
# Create a virtual environment using uv
uv venv .venv
# Activate the venv
source .venv/bin/activate # On Windows: .venv\Scripts\activate
# Install all of the dependencies
uv syncimport mintro
# Initialise a simple MNIST model
model = mintro.models.example_models.MNISTNet()
# Create a static analyser
analyser = mintro.analyzer.static.TorchStaticAnalyzer(model, model_input_dim=(16, 1, 28, 28))
# Prepare and Execute the analyser
analyser.prep_and_execute()
# Access the metrics
print(analyser.metrics)
# Access the ExtractedWeights
print(analyser.extracted_weights[0])
# Access the computational graph
print(analyser.extracted_comp_graph.nodes(data=True))
# Access the extracted metadata
print(analyser.extracted_metadata)Mintro includes documentation built with MkDocs. To view the documentation locally:
mkdocs serveThe documentation covers:
- An overview of functionality
- API reference
- Contributing information
Note: Documentation is an area we are planning on developing but contributions are most welcome!
Usage examples and tutorials can be found in the notebooks/ directory. These Jupyter notebooks demonstrate:
- A more detailed guide for using the
TorchStaticAnalyzer - A guide for using the
TorchDynamicAnalyzer - A guide focused specifically on computational graph extraction using the
TorchStaticAnalyzer - A guide on using a custom developed
Analytic
We welcome contributions! Please see our Contributing Guidelines for details on:
- Setting up the development environment
- Code style and standards
- Submitting pull requests
- Reporting issues
This project is licensed under the Apache 2.0 License - see the LICENSE file for details.
- Documentation: Can be found with
docs/ - Issues: Please use GitHub Issues for bug reports and feature requests
- Security: For security-related concerns, please see our Security Policy
- Public PyPI release
- Add more advanced metrics and analysis
- Enhance documentation