{"id":24061,"library":"model-compression-toolkit","title":"Model Compression Toolkit","description":"A Model Compression Toolkit (MCT) for neural networks, supporting quantization, pruning, and knowledge distillation. Current version is 2.6.0. Released monthly on PyPI.","status":"active","version":"2.6.0","language":"python","source_language":"en","source_url":"https://github.com/sony/model_optimization","tags":["quantization","pruning","distillation","compression","neural-networks"],"install":[{"cmd":"pip install model-compression-toolkit","lang":"bash","label":"Install from PyPI"}],"dependencies":[],"imports":[{"note":"MCT does not expose a top-level 'mct' module; import from package name with underscores.","wrong":"import mct","symbol":"pytorch_post_training_quantization","correct":"from model_compression_toolkit import pytorch_post_training_quantization"},{"note":"Common mistake: using 'mct' alias which is not defined.","wrong":"from mct import ptq","symbol":"ptq","correct":"from model_compression_toolkit import pytorch_post_training_quantization as ptq"}],"quickstart":{"code":"import torch\nfrom model_compression_toolkit import pytorch_post_training_quantization as ptq\n\ntmodel = torch.nn.Linear(10, 5)\ntmodel.eval()\nrepresentative_dataset = [torch.randn(1, 10) for _ in range(5)]\nquantized_model, quantization_info = ptq.pytorch_post_training_quantization(\n    model=tmodel,\n    representative_data_gen=representative_dataset,\n    target_platform_name='default'\n)\nprint('Quantization completed, model size saved.')\n","lang":"python","description":"Basic post-training quantization on a PyTorch model using representative data."},"warnings":[{"fix":"Update import to `from model_compression_toolkit import pytorch_post_training_quantization` and adjust function calls accordingly.","message":"In version 2.0+, the API changed from using `post_training_quantization` to `pytorch_post_training_quantization`. Old code will break.","severity":"breaking","affected_versions":"<=1.x -> 2.0+"},{"fix":"Use correct import: `from model_compression_toolkit import ...`","message":"The `model_compression_toolkit` package name uses underscores, but many users mistakenly import `mct`. The package does not provide a `mct` top-level module.","severity":"gotcha","affected_versions":"all"},{"fix":"Transition to the PyTorch or TensorFlow 2.x native API. Use `tensorflow_post_training_quantization` for TF2.","message":"The `keras`-related interfaces (e.g., `keras_post_training_quantization`) are deprecated as of v2.6 and may be removed in future versions.","severity":"deprecated","affected_versions":">=2.6"}],"env_vars":null,"last_verified":"2026-05-01T00:00:00.000Z","next_check":"2026-07-30T00:00:00.000Z","problems":[{"fix":"Upgrade: `pip install --upgrade model-compression-toolkit`. Ensure PyTorch is installed: `pip install torch`.","cause":"Installed old version (<2.0) or incorrect import due to missing dependencies (e.g., torch not installed).","error":"AttributeError: module 'model_compression_toolkit' has no attribute 'pytorch_post_training_quantization'"},{"fix":"Use `target_platform='default'` or `target_platform_name='default'` (both work, but preferred is `target_platform`).","cause":"Using old argument name; in v2.6 the correct argument is `target_platform` (but 'target_platform_name' is still accepted as alias).","error":"KeyError: 'target_platform_name'"},{"fix":"Wrap data in a function: `def rep_data(): yield input_tensor` and pass the function, not the data list.","cause":"Providing a list of tensors directly instead of a generator function.","error":"RuntimeError: Quantization failed: representative_data_gen must be a callable that returns an iterable."}],"ecosystem":"pypi","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}