Skip to content

Commit

Permalink
Initial commit for Memoraith v0.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
MEHDI342 committed Sep 29, 2024
0 parents commit fc1cb62
Show file tree
Hide file tree
Showing 54 changed files with 4,216 additions and 0 deletions.
36 changes: 36 additions & 0 deletions .github/workflows/ci.yml
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/
63 changes: 63 additions & 0 deletions .gitignore
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/
8 changes: 8 additions & 0 deletions .pypirc
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
45 changes: 45 additions & 0 deletions CONTRIBUTING.md
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
21 changes: 21 additions & 0 deletions LICENSE
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.
4 changes: 4 additions & 0 deletions Manifest.in
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
92 changes: 92 additions & 0 deletions README.md
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}
}
```
42 changes: 42 additions & 0 deletions blabla.py
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!")
1 change: 1 addition & 0 deletions examples/example_pytorch.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# PyTorch example
25 changes: 25 additions & 0 deletions examples/example_tensorflow.py
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)
10 changes: 10 additions & 0 deletions memoraith/__init__.py
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
5 changes: 5 additions & 0 deletions memoraith/analysis/__init__.py
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
Loading

0 comments on commit fc1cb62

Please sign in to comment.