Skip to content

Commit

Permalink
refactor packages to avoid confusion with environment packages with t…
Browse files Browse the repository at this point in the history
…he same name (#757)

* refactor packages to avoid confusion with environment packages with the same name

---------

Co-authored-by: elad cohen <elad.cohen@altair-semi.com>
  • Loading branch information
elad-c and elad cohen committed Aug 1, 2023
1 parent fd43f66 commit 5e98507
Show file tree
Hide file tree
Showing 15 changed files with 28 additions and 27 deletions.
10 changes: 5 additions & 5 deletions tutorials/quick_start/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,12 @@ The weights modification is done through a knowledge distillation technique sour

To execute the model compression with this approach, run the following Python script:
```python
python main.py --model_name mobilenet_v2 --model_library torchvision --gptq --validation_dataset_folder <my path> --representative_dataset_folder <my path>
python main.py --model_name mobilenet_v2 --model_library torchvision_lib --gptq --validation_dataset_folder <my path> --representative_dataset_folder <my path>
```

Please note that the Mixed-Precision and Gradient-based Post Training Quantization (GPTQ) strategies can be combined to achieve a more significant model compression while mitigating the impact on model performance.
#### More examples
More details and examples for using Ultrlytics models can be found in this [readme](./pytorch_fw/ultralytics/README.md)
More details and examples for using Ultrlytics models can be found in this [readme](./pytorch_fw/ultralytics_lib/README.md)

## Results
The latest performance results of MCT on various of models can be found in the [results CSV](./results/model_quantization_results.csv) table.
Expand All @@ -83,7 +83,7 @@ The following external packages were tested with this project:
This project is licensed under [Apache License 2.0](../../LICENSE.md).
However, please note that different external packages have their own licenses. When using this project, you have the option to choose one of the following external packages:

- torchvision: [license link](https://github.com/UiPath/torchvision/blob/master/LICENSE), [license copy](./pytorch_fw/torchvision/LICENSE)
- timm: [license link](https://github.com/huggingface/pytorch-image-models/blob/main/LICENSE), [license copy](./pytorch_fw/timm/LICENSE)
- ultralytics: [license link](https://github.com/ultralytics/ultralytics/blob/main/LICENSE), [license copy](./pytorch_fw/ultralytics/LICENSE)
- torchvision: [license link](https://github.com/UiPath/torchvision/blob/master/LICENSE), [license copy](./pytorch_fw/torchvision_lib/LICENSE)
- timm: [license link](https://github.com/huggingface/pytorch-image-models/blob/main/LICENSE), [license copy](./pytorch_fw/timm_lib/LICENSE)
- ultralytics: [license link](https://github.com/ultralytics/ultralytics/blob/main/LICENSE), [license copy](./pytorch_fw/ultralytics_lib/LICENSE)
- keras-applications: [license link](https://github.com/keras-team/keras-applications/blob/master/LICENSE), [license copy](./keras_fw/keras_applications/LICENSE)
4 changes: 2 additions & 2 deletions tutorials/quick_start/common/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@ def find_modules(lib: str) -> Tuple[str, str]:

# Search in PyTorch libraries
if importlib.util.find_spec('pytorch_fw.' + lib) is not None:
model_lib_module = 'pytorch_fw.' + lib + '.model_lib_' + lib
model_lib_module = 'pytorch_fw.' + lib + '.model_lib'
quant_module = 'pytorch_fw.quant'

# Search in Keras libraries
elif importlib.util.find_spec('keras_fw.' + lib) is not None:
model_lib_module = 'keras_fw.' + lib + '.model_lib_' + lib
model_lib_module = 'keras_fw.' + lib + '.model_lib'
quant_module = 'keras_fw.quant'
else:
raise Exception(f'Error: model library {lib} is not supported')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@
import timm
from timm.data import create_dataset, create_loader, resolve_data_config

from common.model_lib import BaseModelLib
from pytorch_fw.utils import classification_eval, get_representative_dataset
from common.constants import MODEL_NAME, BATCH_SIZE, VALIDATION_SET_LIMIT, VALIDATION_DATASET_FOLDER, \
IMAGENET_DATASET
from common.results import DatasetInfo
from tutorials.quick_start.common.model_lib import BaseModelLib
from tutorials.quick_start.pytorch_fw.utils import classification_eval, get_representative_dataset
from tutorials.quick_start.common.constants import MODEL_NAME, BATCH_SIZE, VALIDATION_SET_LIMIT, \
VALIDATION_DATASET_FOLDER, IMAGENET_DATASET
from tutorials.quick_start.common.results import DatasetInfo


class ModelLib(BaseModelLib):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,12 @@
from torchvision.models import list_models, get_model, get_model_weights, get_weight
from torch.utils.data import Subset

from common.model_lib import BaseModelLib
from pytorch_fw.utils import classification_eval, get_representative_dataset
from common.constants import MODEL_NAME, BATCH_SIZE, VALIDATION_SET_LIMIT, VALIDATION_DATASET_FOLDER, IMAGENET_DATASET
from tutorials.quick_start.common.model_lib import BaseModelLib
from tutorials.quick_start.pytorch_fw.utils import classification_eval, get_representative_dataset
from tutorials.quick_start.common.constants import MODEL_NAME, BATCH_SIZE, VALIDATION_SET_LIMIT, \
VALIDATION_DATASET_FOLDER, IMAGENET_DATASET

from common.results import DatasetInfo
from tutorials.quick_start.common.results import DatasetInfo


class ModelLib(BaseModelLib):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ setenv PYTHONPATH /path/to/model_optimization/folder
```

```csh
python main.py --model_name yolov8n --model_library ultralytics --representative_dataset_folder <download_location>/datasets/coco/images/train2017 --num_representative_images 64 --batch_size 1
python main.py --model_name yolov8n --model_library ultralytics_lib --representative_dataset_folder <download_location>/datasets/coco/images/train2017 --num_representative_images 64 --batch_size 1
```
In this example, we are running the main.py script with the following parameters:
- `--model_name`: Specifies the name of the model to be used out of Ultralytics models (yolov8n in this case).
- `--model_library`: Specifies the package of the pre-trained models from which the model name is taken (in this case, ultralytics).
- `--model_library`: Specifies the package of the pre-trained models from which the model name is taken (in this case, ultralytics_lib).
- `--representative_dataset_folder`: Specifies the path to the local copy of the dataset to be used for quantization. In this case, we use the 'train' split of the downloaded dataset provided by Ultralytics.
- `--num_representative_images`: Specifies the number of representative images to be used for quantization.
- `--batch_size`: Specifies the batch size to be used.
Expand Down
18 changes: 9 additions & 9 deletions tutorials/quick_start/results/model_quantization_results.csv
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
ModelName,ModelLibrary,DatasetName,TotalImages,FloatAcc,QuantAcc,Size[MB],BitsConfig,QuantTechnique,TPC
mobilenet_v2,torchvision,ImageNet,50000,0.7215,0.7188,3.47,W8A8,PTQ,default_pytorch_tpc-v4
regnet_y_400mf,torchvision,ImageNet,50000,0.7578,0.7542,4.31,W8A8,PTQ,default_pytorch_tpc-v4
shufflenet_v2_x0_5,torchvision,ImageNet,50000,0.6055,0.597,1.36,W8A8,PTQ,default_pytorch_tpc-v4
squeezenet1_0,torchvision,ImageNet,50000,0.581,0.5767,1.24,W8A8,PTQ,default_pytorch_tpc-v4
regnetx_002,timm,ImageNet,50000,0.6876,0.6827,2.67,W8A8,PTQ,default_pytorch_tpc-v4
regnety_008,timm,ImageNet,50000,0.7632,0.7598,6.23,W8A8,PTQ,default_pytorch_tpc-v4
resnet10t,timm,ImageNet,50000,0.6656,0.6643,5.43,W8A8,PTQ,default_pytorch_tpc-v4
resnet18,timm,ImageNet,50000,0.6976,0.6961,11.68,W8A8,PTQ,default_pytorch_tpc-v4
efficientnet_es,timm,ImageNet,50000,0.7808,0.7774,5.39,W8A8,PTQ,default_pytorch_tpc-v4
mobilenet_v2,torchvision_lib,ImageNet,50000,0.7215,0.7188,3.47,W8A8,PTQ,default_pytorch_tpc-v4
regnet_y_400mf,torchvision_lib,ImageNet,50000,0.7578,0.7542,4.31,W8A8,PTQ,default_pytorch_tpc-v4
shufflenet_v2_x0_5,torchvision_lib,ImageNet,50000,0.6055,0.597,1.36,W8A8,PTQ,default_pytorch_tpc-v4
squeezenet1_0,torchvision_lib,ImageNet,50000,0.581,0.5767,1.24,W8A8,PTQ,default_pytorch_tpc-v4
regnetx_002,timm_lib,ImageNet,50000,0.6876,0.6827,2.67,W8A8,PTQ,default_pytorch_tpc-v4
regnety_008,timm_lib,ImageNet,50000,0.7632,0.7598,6.23,W8A8,PTQ,default_pytorch_tpc-v4
resnet10t,timm_lib,ImageNet,50000,0.6656,0.6643,5.43,W8A8,PTQ,default_pytorch_tpc-v4
resnet18,timm_lib,ImageNet,50000,0.6976,0.6961,11.68,W8A8,PTQ,default_pytorch_tpc-v4
efficientnet_es,timm_lib,ImageNet,50000,0.7808,0.7774,5.39,W8A8,PTQ,default_pytorch_tpc-v4
yolov8n,ultralytics,COCO,5000,0.3704,0.3617,3.15,W8A8,PTQ,default_pytorch_tpc-v4
yolov8m,ultralytics,COCO,5000,0.4999,0.494,25.9,W8A8,PTQ,default_pytorch_tpc-v4
mobilenet_v2.MobileNetV2,keras_applications,ImageNet,50000,0.7185,0.7157,3.47,W8A8,PTQ,default_keras_tpc-v4
Expand Down

0 comments on commit 5e98507

Please sign in to comment.