-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit fc1cb62
Showing
54 changed files
with
4,216 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
name: Memoraith CI | ||
|
||
on: | ||
push: | ||
branches: [ main ] | ||
pull_request: | ||
branches: [ main ] | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
strategy: | ||
matrix: | ||
python-version: [3.7, 3.8, 3.9, '3.10'] | ||
|
||
steps: | ||
- uses: actions/checkout@v2 | ||
- name: Set up Python ${{ matrix.python-version }} | ||
uses: actions/setup-python@v2 | ||
with: | ||
python-version: ${{ matrix.python-version }} | ||
- name: Install dependencies | ||
run: | | ||
python -m pip install --upgrade pip | ||
pip install -r requirements.txt | ||
- name: Run tests | ||
run: | | ||
pytest tests/ | ||
- name: Lint with flake8 | ||
run: | | ||
pip install flake8 | ||
flake8 . | ||
- name: Check type hints with mypy | ||
run: | | ||
pip install mypy | ||
mypy memoraith/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
# Python | ||
__pycache__/ | ||
*.py[cod] | ||
*$py.class | ||
|
||
# Distribution / packaging | ||
.Python | ||
build/ | ||
develop-eggs/ | ||
dist/ | ||
downloads/ | ||
eggs/ | ||
.eggs/ | ||
lib/ | ||
lib64/ | ||
parts/ | ||
sdist/ | ||
var/ | ||
wheels/ | ||
*.egg-info/ | ||
.installed.cfg | ||
*.egg | ||
|
||
# PyInstaller | ||
*.manifest | ||
*.spec | ||
|
||
# Installer logs | ||
pip-log.txt | ||
pip-delete-this-directory.txt | ||
|
||
# Unit test / coverage reports | ||
htmlcov/ | ||
.tox/ | ||
.coverage | ||
.coverage.* | ||
.cache | ||
nosetests.xml | ||
coverage.xml | ||
*.cover | ||
.hypothesis/ | ||
.pytest_cache/ | ||
|
||
# Jupyter Notebook | ||
.ipynb_checkpoints | ||
|
||
# pyenv | ||
.python-version | ||
|
||
# Environment | ||
.env | ||
.venv | ||
env/ | ||
venv/ | ||
ENV/ | ||
|
||
# IDE | ||
.vscode/ | ||
.idea/ | ||
|
||
# Memoraith specific | ||
memoraith_reports/ | ||
*profiling_results/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
[distutils] | ||
index-servers = | ||
pypi | ||
|
||
[pypi] | ||
repository: https://upload.pypi.org/legacy/ | ||
username: __token__ | ||
password: AgEIcHlwaS5vcmcCJGM1MWFhNzNiLTEwYWMtNGY2NS05Y2IzLTY0ZWEwYWNiYmNjNAACKlszLCI5MjdjMzIwZC1mMzE3LTQ3N2YtYmQ2MC02OTQ4NjMyMWYwZTYiXQAABiDPAHUyjQvh2o5rbrII2gDJu6clMbqadbt3r0oCDy62Mw |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
# Contributing to Memoraith | ||
|
||
We welcome contributions to Memoraith! This document provides guidelines for contributing to the project. | ||
|
||
## Setting up the development environment | ||
|
||
1. Fork the repository on GitHub. | ||
2. Clone your fork locally: | ||
``` | ||
git clone https://github.com/your-username/memoraith.git | ||
cd memoraith | ||
``` | ||
3. Create a virtual environment and install dependencies: | ||
``` | ||
python -m venv venv | ||
source venv/bin/activate # On Windows, use `venv\Scripts\activate` | ||
pip install -r requirements.txt | ||
``` | ||
|
||
## Making Changes | ||
|
||
1. Create a new branch for your changes: | ||
``` | ||
git checkout -b your-feature-branch | ||
``` | ||
2. Make your changes and commit them with a clear commit message. | ||
3. Push your changes to your fork on GitHub: | ||
``` | ||
git push origin your-feature-branch | ||
``` | ||
4. Open a pull request from your fork to the main Memoraith repository. | ||
|
||
## Coding Standards | ||
|
||
- Follow PEP 8 guidelines for Python code. | ||
- Use type hints for all function arguments and return values. | ||
- Write clear, concise docstrings for all classes and functions. | ||
- Add unit tests for new functionality. | ||
|
||
## Running Tests | ||
|
||
Run the test suite using pytest: | ||
|
||
``` | ||
pytest |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2023 Your Name | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
include README.md | ||
include LICENSE | ||
recursive-include memoraith/templates *.html | ||
recursive-include examples *.py |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
# Memoraith | ||
|
||
Memoraith is a lightweight model profiler for deep learning frameworks, designed to help you optimize your neural network models by providing detailed insights into their performance characteristics. | ||
|
||
## Features | ||
|
||
- Supports PyTorch and TensorFlow models | ||
- Profiles memory usage (CPU and GPU) | ||
- Measures computation time for each layer | ||
- Detects bottlenecks and anomalies | ||
- Generates comprehensive reports with visualizations | ||
- Provides real-time visualization capabilities | ||
- Offers both programmatic and command-line interfaces | ||
|
||
## Installation | ||
|
||
You can install Memoraith using pip: | ||
|
||
```bash | ||
pip install memoraith | ||
``` | ||
|
||
For GPU support, install with: | ||
|
||
```bash | ||
pip install memoraith[gpu] | ||
``` | ||
|
||
## Quick Start | ||
|
||
Here's a simple example of how to use Memoraith with a PyTorch model: | ||
|
||
```python | ||
from memoraith import profile_model, set_output_path | ||
import torch | ||
import torch.nn as nn | ||
|
||
set_output_path('profiling_results/') | ||
|
||
class SimpleNet(nn.Module): | ||
def __init__(self): | ||
super(SimpleNet, self).__init__() | ||
self.fc = nn.Linear(10, 5) | ||
|
||
def forward(self, x): | ||
return self.fc(x) | ||
|
||
@profile_model(memory=True, computation=True, gpu=True) | ||
def train_model(model): | ||
optimizer = torch.optim.Adam(model.parameters()) | ||
for _ in range(100): | ||
input_data = torch.randn(32, 10) | ||
output = model(input_data) | ||
loss = output.sum() | ||
loss.backward() | ||
optimizer.step() | ||
|
||
if __name__ == "__main__": | ||
model = SimpleNet() | ||
train_model(model) | ||
``` | ||
|
||
This will generate a profiling report in the 'profiling_results/' directory. | ||
|
||
## Documentation | ||
|
||
For more detailed information on how to use Memoraith, please refer to our [documentation](https://memoraith.readthedocs.io). | ||
|
||
## Contributing | ||
|
||
We welcome contributions! Please see our [Contributing Guide](CONTRIBUTING.md) for more details. | ||
|
||
## License | ||
|
||
Memoraith is released under the MIT License. See the [LICENSE](LICENSE) file for more details. | ||
|
||
## Support | ||
|
||
If you encounter any issues or have questions, please file an issue on the [GitHub issue tracker](https://github.com/yourusername/memoraith/issues). | ||
|
||
## Citing Memoraith | ||
|
||
If you use Memoraith in your research, please cite it as follows: | ||
|
||
``` | ||
@software{memoraith, | ||
author = {Your Name}, | ||
title = {Memoraith: A Lightweight Model Profiler for Deep Learning}, | ||
year = {2023}, | ||
url = {https://github.com/yourusername/memoraith} | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import os | ||
import re | ||
|
||
def create_or_update_file(file_path, content): | ||
os.makedirs(os.path.dirname(file_path), exist_ok=True) | ||
with open(file_path, 'w', encoding='utf-8') as file: | ||
file.write(content) | ||
print(f"Created/Updated: {file_path}") | ||
|
||
def extract_classes(content): | ||
class_pattern = r'(class\s+\w+[\s\S]*?(?=\n\n|$))' | ||
return re.findall(class_pattern, content) | ||
|
||
def extract_functions(content): | ||
function_pattern = r'(def\s+\w+[\s\S]*?(?=\n\n|$))' | ||
return re.findall(function_pattern, content) | ||
|
||
def update_memoraith(base_path, content): | ||
# Extract file contents | ||
file_pattern = r'# (memoraith/.*?\.py)\n\n([\s\S]*?)(?=\n# memoraith/|\Z)' | ||
matches = re.findall(file_pattern, content) | ||
|
||
for file_path, file_content in matches: | ||
full_path = os.path.join(base_path, file_path) | ||
|
||
# Extract classes and functions | ||
classes = extract_classes(file_content) | ||
functions = extract_functions(file_content) | ||
|
||
# Combine classes and functions | ||
components = classes + functions | ||
|
||
# Create or update the file | ||
create_or_update_file(full_path, "\n\n".join(components)) | ||
|
||
if __name__ == "__main__": | ||
base_path = r"C:\Users\PC\Desktop\Leo-Major\Memoraith" | ||
with open(r"C:\Users\PC\Desktop\Leo-Major\alop.txt", 'r', encoding='utf-8') as f: | ||
content = f.read() | ||
|
||
update_memoraith(base_path, content) | ||
print("Memoraith project has been updated successfully!") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# PyTorch example |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import tensorflow as tf | ||
from memoraith import profile_model, set_output_path | ||
|
||
def create_model(): | ||
model = tf.keras.Sequential([ | ||
tf.keras.layers.Dense(64, activation='relu', input_shape=(10,)), | ||
tf.keras.layers.Dense(64, activation='relu'), | ||
tf.keras.layers.Dense(1) | ||
]) | ||
return model | ||
|
||
@profile_model(memory=True, computation=True, gpu=True) | ||
def train_model(model, epochs=5): | ||
model.compile(optimizer='adam', loss='mse') | ||
|
||
# Generate some dummy data | ||
x_train = tf.random.normal((1000, 10)) | ||
y_train = tf.random.normal((1000, 1)) | ||
|
||
model.fit(x_train, y_train, epochs=epochs, verbose=1) | ||
|
||
if __name__ == "__main__": | ||
set_output_path('tensorflow_profiling_results/') | ||
model = create_model() | ||
train_model(model) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
""" | ||
Memoraith: Lightweight Model Profiler | ||
""" | ||
|
||
__version__ = '0.3.0' | ||
|
||
from .profiler import profile_model, set_output_path | ||
from .config import Config | ||
from .exceptions import MemoraithError | ||
from .visualization.real_time_visualizer import RealTimeVisualizer |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
from .analyzer import Analyzer | ||
from .metrics import MetricsCalculator | ||
from .bottleneck import BottleneckDetector | ||
from .recommendations import RecommendationEngine | ||
from .anomaly_detection import AnomalyDetector |
Oops, something went wrong.