Practical overview
When it fits
Use Optipfair when you want a Python workflow to analyze layer importance and experiment with depth or width pruning, optionally followed by distillation to recover performance.
Who it is for
- Practitioners experimenting with structured compression of transformer language models.
- Researchers comparing model structure and performance before and after pruning.
- Developers seeking a composable Python workflow for pruning followed by knowledge distillation.
Documented uses
- Estimate which model layers contribute least using a model and dataloader.
- Remove selected transformer layers or reduce MLP neuron counts.
- Fine-tune a pruned student model against a teacher with task and logits losses.
- Explore fairness or bias analysis using the optional visualization dependencies.
Requirements & limits
The repository is public and identifies Optipfair as open source under the Apache-2.0 license. The README provides pip installation instructions.
- Depth pruning removes complete layers; width pruning reduces neuron counts within MLP layers.
- The project recommends knowledge distillation after aggressive pruning, but distillation is optional.
- Layer analysis requires a model and dataloader; distillation requires a student model, teacher model and training dataloader.
- The README reports benchmark results for a specific Qwen3.5-0.8B-Base experiment, which should not be treated as a prediction for other models or datasets.
Check current requirements in the official documentation. Source-based guidance does not mean OpenViST has run or independently tested this project.
Install Optipfair for pruning and distillation
Install the library, with the optional visualization dependency used for bias analysis.
Before you start
- Python package installation with pip.
Steps
Install the core package with the command below.
pip install optipfairFor visualization dependencies used in bias analysis, install the command below.
pip install optipfair[viz]
Expected outcome
The Optipfair package is installed, with visualization dependencies included if the optional extra was selected.
Guide limitations
- The installation instructions do not specify Python or dependency version requirements.
- Installation alone does not perform model analysis, pruning or distillation.
Analyze layer importance and prune a model
Use layer-importance scores to select layers for depth pruning.
Before you start
- A model and dataloader to pass to
analyze_layer_importance. - Optipfair installed and imported as
optipfair.
Steps
Call
optipfair.analyze_layer_importance(model, dataloader)to obtain layer-importance scores.Sort the returned scores and select the indices of the least important layers.
Pass the selected indices to
optipfair.prune_modelwithpruning_type="DEPTH".
Expected outcome
A model with the selected transformer layers removed; the README example also requests pruning statistics.
Guide limitations
- The README does not define a universal layer-selection threshold or guarantee the resulting model’s performance.
- The recipe covers depth pruning; it does not include distillation or deployment.
Sources & review
Source record details
- Source availability
- Active
- Sources checked
- 14 October 2026
- Original website title
- peremartra/optipfair · Official homepage title · retained in its source language

