This repository aimed to provide the test models and test the pytorch pruning framework UniP.
This repository is based on the UniP, and help users of UniP to test the pruning framework. If you could not run the UniP with your own models, you should pull a request to this repository. Let's fix your problems and make UniP better.
torch
torchvision
UniP
git clone https://github.com/Nobreakfast/test_UniP.git
cd test_UniP
pip install -e .
test_UniP
├── test_unip
│ ├── models
│ │ ├── template_model.py
│ │ ├── example_model.py
│ │ └── ...
├── tests
│ ├── test_template_model.py
│ ├── test_example_model.py
│ └── ...
├── requirements
│ ├── template_requirements.txt
│ ├── example_requirements.txt
│ └── ...
├── requirements.txt
└── README.md
-
Fork
this repository to your github account. -
Clone your
forked repository
to your local machine.
cd /path/to/your/disired/directory
git clone https://github.com/your_github_account/test_UniP.git
-
🔥
Important
🔥 Put your model in themodels
directory, you could create any nick namedfolder
orfile
. You could refer to the template filetest_unip/models/template_model.py
-
🔥
Important
🔥 Add a simpletest script
in thetest
directory, you could create any nick namedfile
(tests/test_your_file.py
). You could refer to the template filetests/test_template.py
. The test script should provide two functions:test_inference()
and UniPtest_pruning()
:
import unip
from unip.core.pruner import BasePruner
from unip.utils.evaluation import cal_flops
from test_unip.models.example_model import ExampleModel
def test_inference():
# Your inference code here
example_input = torch.randn(1, 3, 224, 224)
model = ExampleModel()
out = model(example_input)
def test_pruning():
# Your pruning code here
example_input = torch.randn(1, 3, 224, 224)
model = ExampleModel()
pruner = BasePruner(model, example_input, "RandomRatio")
pruner.algorithm.run(0.8)
pruner.prune()
cal_flops(model, example_input, "cpu")
Make sure the test_inference()
could run successfully. If your model need some external library, you should add the requirements/example_requirements.txt
file to provide the requirements. You could refer to the template file requirements/template_requirements.txt
.
- Commit your changes and push to your forked repository.
git add .
git commit -m "add new model"
git push
-
Open your forked respository on github, and pull a request to this repository.
-
Wait for the test result. If the
test_inference()
function could run successfully, we will accept your request. If not, we will leave a comment on your pull request and you should fix the problem and pull a request again. -
Open the
UniP Issue Page
andcreate a new issue
. Describe your problem and provide the link of yourPR ID and Link
. We will fix your problem as soon as possible. -
Once your problem is fixed, we will close your issue and your
tests/test_your_file.py
will be changed totests/your_file_PRID.py
. If you still facing problems, you could rechange the file name, pull a request and reopen the issues.
- 2023-09-03: Optimize the test process.