optipfair 0.2.2__tar.gz → 0.2.3__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (41) hide show
  1. {optipfair-0.2.2/optipfair.egg-info → optipfair-0.2.3}/PKG-INFO +1 -1
  2. {optipfair-0.2.2 → optipfair-0.2.3}/optipfair/__init__.py +1 -1
  3. {optipfair-0.2.2 → optipfair-0.2.3}/optipfair/pruning/mlp_glu.py +46 -0
  4. {optipfair-0.2.2 → optipfair-0.2.3/optipfair.egg-info}/PKG-INFO +1 -1
  5. {optipfair-0.2.2 → optipfair-0.2.3}/setup.py +1 -1
  6. {optipfair-0.2.2 → optipfair-0.2.3}/CONTRIBUTING.md +0 -0
  7. {optipfair-0.2.2 → optipfair-0.2.3}/LICENSE +0 -0
  8. {optipfair-0.2.2 → optipfair-0.2.3}/MANIFEST.in +0 -0
  9. {optipfair-0.2.2 → optipfair-0.2.3}/README.md +0 -0
  10. {optipfair-0.2.2 → optipfair-0.2.3}/docs/api.md +0 -0
  11. {optipfair-0.2.2 → optipfair-0.2.3}/docs/bias_visualization.md +0 -0
  12. {optipfair-0.2.2 → optipfair-0.2.3}/docs/contributing.md +0 -0
  13. {optipfair-0.2.2 → optipfair-0.2.3}/docs/examples.md +0 -0
  14. {optipfair-0.2.2 → optipfair-0.2.3}/docs/index.md +0 -0
  15. {optipfair-0.2.2 → optipfair-0.2.3}/docs/installation.md +0 -0
  16. {optipfair-0.2.2 → optipfair-0.2.3}/docs/roadmap.md +0 -0
  17. {optipfair-0.2.2 → optipfair-0.2.3}/docs/usage.md +0 -0
  18. {optipfair-0.2.2 → optipfair-0.2.3}/optipfair/bias/__init__.py +0 -0
  19. {optipfair-0.2.2 → optipfair-0.2.3}/optipfair/bias/activations.py +0 -0
  20. {optipfair-0.2.2 → optipfair-0.2.3}/optipfair/bias/bias_visualization_example.py +0 -0
  21. {optipfair-0.2.2 → optipfair-0.2.3}/optipfair/bias/defaults.py +0 -0
  22. {optipfair-0.2.2 → optipfair-0.2.3}/optipfair/bias/metrics.py +0 -0
  23. {optipfair-0.2.2 → optipfair-0.2.3}/optipfair/bias/utils.py +0 -0
  24. {optipfair-0.2.2 → optipfair-0.2.3}/optipfair/bias/visualization.py +0 -0
  25. {optipfair-0.2.2 → optipfair-0.2.3}/optipfair/cli/__init__.py +0 -0
  26. {optipfair-0.2.2 → optipfair-0.2.3}/optipfair/cli/commands.py +0 -0
  27. {optipfair-0.2.2 → optipfair-0.2.3}/optipfair/evaluation/__init__.py +0 -0
  28. {optipfair-0.2.2 → optipfair-0.2.3}/optipfair/evaluation/benchmarks.py +0 -0
  29. {optipfair-0.2.2 → optipfair-0.2.3}/optipfair/pruning/__init__.py +0 -0
  30. {optipfair-0.2.2 → optipfair-0.2.3}/optipfair/pruning/depth.py +0 -0
  31. {optipfair-0.2.2 → optipfair-0.2.3}/optipfair/pruning/future_extensions/__init__.py +0 -0
  32. {optipfair-0.2.2 → optipfair-0.2.3}/optipfair/pruning/future_extensions/attention.py +0 -0
  33. {optipfair-0.2.2 → optipfair-0.2.3}/optipfair/pruning/future_extensions/block.py +0 -0
  34. {optipfair-0.2.2 → optipfair-0.2.3}/optipfair/pruning/utils.py +0 -0
  35. {optipfair-0.2.2 → optipfair-0.2.3}/optipfair.egg-info/SOURCES.txt +0 -0
  36. {optipfair-0.2.2 → optipfair-0.2.3}/optipfair.egg-info/dependency_links.txt +0 -0
  37. {optipfair-0.2.2 → optipfair-0.2.3}/optipfair.egg-info/entry_points.txt +0 -0
  38. {optipfair-0.2.2 → optipfair-0.2.3}/optipfair.egg-info/requires.txt +0 -0
  39. {optipfair-0.2.2 → optipfair-0.2.3}/optipfair.egg-info/top_level.txt +0 -0
  40. {optipfair-0.2.2 → optipfair-0.2.3}/pyproject.toml +0 -0
  41. {optipfair-0.2.2 → optipfair-0.2.3}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: optipfair
3
- Version: 0.2.2
3
+ Version: 0.2.3
4
4
  Summary: A library for structured pruning & Bias visualization of large language models
5
5
  Home-page: https://github.com/peremartra/optipfair
6
6
  Author: Pere Martra
@@ -14,7 +14,7 @@ from .pruning.depth import prune_model_depth, analyze_layer_importance
14
14
 
15
15
  from .pruning.utils import get_pruning_statistics
16
16
 
17
- __version__ = "0.2.2"
17
+ __version__ = "0.2.3"
18
18
 
19
19
  # Configure logging
20
20
  logging.basicConfig(
@@ -261,6 +261,52 @@ def compute_neuron_pair_importance_maw_hybrid(
261
261
  X_d_norm: torch.Tensor
262
262
  ) -> torch.Tensor:
263
263
  """
264
+ Hybrid Importance: Static Range (Max-Min) * Dynamic Activation.
265
+
266
+ Adapts the metric from Chapter 5.1 (Weight Range) for use in the
267
+ hybrid pipeline of Chapter 5.2.
268
+ """
269
+ # 1. Convert to float32 for numerical stability
270
+ gate_weight = gate_weight.float()
271
+ up_weight = up_weight.float()
272
+ down_weight = down_weight.float()
273
+ # Ensure activations are on the same device
274
+ X_d_norm = X_d_norm.float().to(gate_weight.device)
275
+
276
+ # 2. Static Component: Range Metric (Max + Abs(Min))
277
+ # This metric values the amplitude of signal that the neuron can generate
278
+
279
+ # gate_proj and up_proj: Neurons are rows (dim=1)
280
+ gate_score = torch.max(gate_weight, dim=1).values + torch.abs(torch.min(gate_weight, dim=1).values)
281
+ up_score = torch.max(up_weight, dim=1).values + torch.abs(torch.min(up_weight, dim=1).values)
282
+ # down_proj: Neurons are columns (dim=0)
283
+ down_score = torch.max(down_weight, dim=0).values + torch.abs(torch.min(down_weight, dim=0).values)
284
+
285
+ # 3. Normalization
286
+ # Scale each component to [0, 1] so they have similar weight when summed
287
+ gate_norm = gate_score / (gate_score.max() + 1e-8)
288
+ up_norm = up_score / (up_score.max() + 1e-8)
289
+ down_norm = down_score / (down_score.max() + 1e-8)
290
+
291
+ # 4. Combined Structural Score
292
+ # Sum the importance of weights from the 3 layers
293
+ structural_score = down_norm + gate_norm + up_norm
294
+
295
+ # 5. Hybrid Fusion (Data-Driven)
296
+ # Multiply structural potential by captured real activation (X_d)
297
+ # If a neuron has large weights but zero activation, its score will be 0.
298
+ importance_scores = structural_score * X_d_norm
299
+
300
+ return importance_scores
301
+
302
+ def compute_neuron_pair_importance_maw_hybrid_cfsp(
303
+ gate_weight: torch.Tensor,
304
+ up_weight: torch.Tensor,
305
+ down_weight: torch.Tensor,
306
+ X_d_norm: torch.Tensor
307
+ ) -> torch.Tensor:
308
+ """
309
+ *****NOT IN USE. KEEP FOR REFERENCE ONLY.*****
264
310
  Compute neuron pair importance using hybrid data-driven method (MAW + Activations).
265
311
 
266
312
  Implements CFSP methodology (arXiv:2409.13199v2, Equation 8):
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: optipfair
3
- Version: 0.2.2
3
+ Version: 0.2.3
4
4
  Summary: A library for structured pruning & Bias visualization of large language models
5
5
  Home-page: https://github.com/peremartra/optipfair
6
6
  Author: Pere Martra
@@ -5,7 +5,7 @@ with open("README.md", "r", encoding="utf-8") as fh:
5
5
 
6
6
  setup(
7
7
  name="optipfair",
8
- version="0.2.2",
8
+ version="0.2.3",
9
9
  author="Pere Martra",
10
10
  author_email="peremartra@uadla.com",
11
11
  description="A library for structured pruning & Bias visualization of large language models",
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes