sony / model_optimization

Model Compression Toolkit (MCT) is an open source project for neural network model optimization under efficient, constrained hardware. This project provides researchers, developers, and engineers advanced quantization and compression tools for deploying state-of-the-art neural networks.
https://sony.github.io/model_optimization/
Apache License 2.0
297 stars 49 forks source link

Cannot import model_compression_toolkit as mct in Post-Training Quantization Example of MobileViT-XS PyTorch Model - Quantization for IMX500 #1176

Closed freke closed 2 weeks ago

freke commented 3 weeks ago

Issue Type

Bug

Source

pip (model-compression-toolkit)

MCT Version

Running on Google Colab

OS Platform and Distribution

Running on Google Colab

Python version

3.10

Describe the issue

Error trying to run the example in colab, get the error "cannot import name 'TFOpLambda' from 'keras.src.layers.core'" Most if not all PyTorch examples have the same issue, same error as #1144 (for Keras)

Expected behaviour

To be able to run the example code with out issues.

Code to reproduce the issue

https://colab.research.google.com/github/sony/model_optimization/blob/main/tutorials/notebooks/imx500_notebooks/pytorch/pytorch_mobilevit_xs_for_imx500.ipynb

Log output

ImportError Traceback (most recent call last) in <cell line: 1>() ----> 1 import model_compression_toolkit as mct 2 from model_compression_toolkit.core.pytorch.pytorch_device_config import get_working_device 3 from timm.data import create_loader, resolve_data_config 4 from typing import Iterator, Tuple, List 5 import torchvision

8 frames /usr/local/lib/python3.10/dist-packages/model_compression_toolkit/core/keras/back2framework/keras_model_builder.py in 23 if version.parse(tf.version) >= version.parse("2.13"): 24 from keras import Input ---> 25 from keras.src.layers.core import TFOpLambda 26 from keras.src.engine.base_layer import TensorFlowOpLayer, Layer 27 else:

ImportError: cannot import name 'TFOpLambda' from 'keras.src.layers.core' (/usr/local/lib/python3.10/dist-packages/keras/src/layers/core/init.py)

lapid92 commented 3 weeks ago

Hi, @freke thank you for bringing this to our attention. The issue was that Google Colab's default TensorFlow version was recently updated to 2.17, while MCT supports versions up to 2.15.x. We resolved this in #1154 by updating the package version verification process. This update will be included in MCT v2.2.0. In the meantime, you can use pip install mct-nightly instead of pip install model-compression-toolkit.