l0-python 0.4.3__py3-none-any.whl → 0.5.0__py3-none-any.whl
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.
- l0/__init__.py +1 -1
- l0/calibration.py +50 -2
- {l0_python-0.4.3.dist-info → l0_python-0.5.0.dist-info}/METADATA +1 -1
- l0_python-0.5.0.dist-info/RECORD +12 -0
- {l0_python-0.4.3.dist-info → l0_python-0.5.0.dist-info}/WHEEL +1 -1
- l0_python-0.4.3.dist-info/RECORD +0 -12
- {l0_python-0.4.3.dist-info → l0_python-0.5.0.dist-info}/licenses/LICENSE +0 -0
- {l0_python-0.4.3.dist-info → l0_python-0.5.0.dist-info}/top_level.txt +0 -0
l0/__init__.py
CHANGED
|
@@ -5,7 +5,7 @@ A PyTorch implementation of L0 regularization for neural network sparsification
|
|
|
5
5
|
and intelligent sampling, based on Louizos, Welling, & Kingma (2017).
|
|
6
6
|
"""
|
|
7
7
|
|
|
8
|
-
__version__ = "0.
|
|
8
|
+
__version__ = "0.5.0"
|
|
9
9
|
|
|
10
10
|
from .distributions import HardConcrete
|
|
11
11
|
from .gates import FeatureGate, HybridGate, L0Gate, SampleGate
|
l0/calibration.py
CHANGED
|
@@ -60,6 +60,7 @@ class SparseCalibrationWeights(nn.Module):
|
|
|
60
60
|
log_weight_jitter_sd: float = 0.0,
|
|
61
61
|
log_alpha_jitter_sd: float = 0.01,
|
|
62
62
|
device: str | torch.device = "cpu",
|
|
63
|
+
use_gates: bool = True,
|
|
63
64
|
):
|
|
64
65
|
super().__init__()
|
|
65
66
|
self.n_features = n_features
|
|
@@ -69,6 +70,7 @@ class SparseCalibrationWeights(nn.Module):
|
|
|
69
70
|
self.log_weight_jitter_sd = log_weight_jitter_sd
|
|
70
71
|
self.log_alpha_jitter_sd = log_alpha_jitter_sd
|
|
71
72
|
self.device = torch.device(device)
|
|
73
|
+
self.use_gates = use_gates
|
|
72
74
|
|
|
73
75
|
# Initialize weights (on original scale)
|
|
74
76
|
if init_weights is None:
|
|
@@ -193,6 +195,10 @@ class SparseCalibrationWeights(nn.Module):
|
|
|
193
195
|
torch.Tensor
|
|
194
196
|
Positive calibration weights with L0 sparsity applied
|
|
195
197
|
"""
|
|
198
|
+
if not self.use_gates:
|
|
199
|
+
# No gates - just return positive weights
|
|
200
|
+
return torch.exp(self.log_weight)
|
|
201
|
+
|
|
196
202
|
# Sample or get deterministic gates
|
|
197
203
|
if deterministic:
|
|
198
204
|
gates = self.get_deterministic_gates()
|
|
@@ -453,6 +459,46 @@ class SparseCalibrationWeights(nn.Module):
|
|
|
453
459
|
1 - active_info["count"] / self.n_features
|
|
454
460
|
)
|
|
455
461
|
|
|
462
|
+
# Weight distribution diagnostic
|
|
463
|
+
if active_weights.numel() > 0:
|
|
464
|
+
w_tiny = (active_weights < 0.01).sum().item()
|
|
465
|
+
w_small = (
|
|
466
|
+
((active_weights >= 0.01) & (active_weights < 0.1))
|
|
467
|
+
.sum()
|
|
468
|
+
.item()
|
|
469
|
+
)
|
|
470
|
+
w_med = (
|
|
471
|
+
((active_weights >= 0.1) & (active_weights < 1.0))
|
|
472
|
+
.sum()
|
|
473
|
+
.item()
|
|
474
|
+
)
|
|
475
|
+
w_normal = (
|
|
476
|
+
((active_weights >= 1.0) & (active_weights < 10.0))
|
|
477
|
+
.sum()
|
|
478
|
+
.item()
|
|
479
|
+
)
|
|
480
|
+
w_large = (
|
|
481
|
+
(
|
|
482
|
+
(active_weights >= 10.0)
|
|
483
|
+
& (active_weights < 1000.0)
|
|
484
|
+
)
|
|
485
|
+
.sum()
|
|
486
|
+
.item()
|
|
487
|
+
)
|
|
488
|
+
w_huge = (active_weights >= 1000.0).sum().item()
|
|
489
|
+
|
|
490
|
+
total_active = active_weights.numel()
|
|
491
|
+
weight_dist = (
|
|
492
|
+
f"[<0.01: {100*w_tiny/total_active:.1f}%, "
|
|
493
|
+
f"0.01-0.1: {100*w_small/total_active:.1f}%, "
|
|
494
|
+
f"0.1-1: {100*w_med/total_active:.1f}%, "
|
|
495
|
+
f"1-10: {100*w_normal/total_active:.1f}%, "
|
|
496
|
+
f"10-1000: {100*w_large/total_active:.1f}%, "
|
|
497
|
+
f">1000: {100*w_huge/total_active:.1f}%]"
|
|
498
|
+
)
|
|
499
|
+
else:
|
|
500
|
+
weight_dist = "[no active weights]"
|
|
501
|
+
|
|
456
502
|
# Calculate components of the actual loss being minimized
|
|
457
503
|
actual_data_loss = data_loss.item()
|
|
458
504
|
actual_l0_loss = l0_loss.item()
|
|
@@ -464,7 +510,8 @@ class SparseCalibrationWeights(nn.Module):
|
|
|
464
510
|
f"mean_group_mare={mean_group_mare:.4%}, "
|
|
465
511
|
f"max_error={max_rel_err:.1%}, "
|
|
466
512
|
f"total_loss={actual_total_loss:.3f}, "
|
|
467
|
-
f"active={active_info['count']:4d}/{self.n_features} ({sparsity_pct:.1f}% sparse)"
|
|
513
|
+
f"active={active_info['count']:4d}/{self.n_features} ({sparsity_pct:.1f}% sparse)\n"
|
|
514
|
+
f" Weight dist: {weight_dist}"
|
|
468
515
|
)
|
|
469
516
|
else:
|
|
470
517
|
print(
|
|
@@ -472,7 +519,8 @@ class SparseCalibrationWeights(nn.Module):
|
|
|
472
519
|
f"mean_error={mean_rel_err:.4%}, "
|
|
473
520
|
f"max_error={max_rel_err:.1%}, "
|
|
474
521
|
f"total_loss={actual_total_loss:.3f}, "
|
|
475
|
-
f"active={active_info['count']:4d}/{self.n_features} ({sparsity_pct:.1f}% sparse)"
|
|
522
|
+
f"active={active_info['count']:4d}/{self.n_features} ({sparsity_pct:.1f}% sparse)\n"
|
|
523
|
+
f" Weight dist: {weight_dist}"
|
|
476
524
|
)
|
|
477
525
|
|
|
478
526
|
return self
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
l0/__init__.py,sha256=ImRgZfVg-RJhLoqNaLc8ysjddZ7CYGHJPJbRUyfSoHY,1192
|
|
2
|
+
l0/calibration.py,sha256=1-C6B6O47l6qlEcQl3N8waAPAyj5PFlzBHl17KbXqGo,20018
|
|
3
|
+
l0/distributions.py,sha256=GvVoDasdxoDlPPdzt33lFzkuJgQsfkEn9e-abxru3nM,6325
|
|
4
|
+
l0/gates.py,sha256=54OORMg9qSsdbIyzYIL9t9CCHWsKbumSKl_d4-YFuNU,11443
|
|
5
|
+
l0/layers.py,sha256=j_DPEFdfUc37ojtoK2ufGzVYzZ_DwusqTcJXCVxZS68,13785
|
|
6
|
+
l0/penalties.py,sha256=okqXgX2eGUmg5prcDclicTQALPPPF9FA5eQP09V4GTE,9569
|
|
7
|
+
l0/sparse.py,sha256=UVpkrrJBnQ9iSNDoWK5F_sr43tQareWXzYHyMq_cKss,9726
|
|
8
|
+
l0_python-0.5.0.dist-info/licenses/LICENSE,sha256=LoyFJ8qmpwWPp5RmxFGHhdBxsemvp_BqGyiCgNAZHlk,1069
|
|
9
|
+
l0_python-0.5.0.dist-info/METADATA,sha256=zoUDdaSbSAWeWtWW-K_5Wgl6RbTqGHfGIyfYobvxEBQ,7095
|
|
10
|
+
l0_python-0.5.0.dist-info/WHEEL,sha256=qELbo2s1Yzl39ZmrAibXA2jjPLUYfnVhUNTlyF1rq0Y,92
|
|
11
|
+
l0_python-0.5.0.dist-info/top_level.txt,sha256=brP2SoElgmGhNJk-qRFEQZ5UE-d1e87Tr60hSSh8n34,3
|
|
12
|
+
l0_python-0.5.0.dist-info/RECORD,,
|
l0_python-0.4.3.dist-info/RECORD
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
l0/__init__.py,sha256=ezGVLGbdU_jAElAJSdLKjSWCnZRILAZi8qMBPjcHwQc,1192
|
|
2
|
-
l0/calibration.py,sha256=3VM-28M1yp-DM6AlHX7sqZCaE7OJevpY9Ey-syjSPik,17838
|
|
3
|
-
l0/distributions.py,sha256=GvVoDasdxoDlPPdzt33lFzkuJgQsfkEn9e-abxru3nM,6325
|
|
4
|
-
l0/gates.py,sha256=54OORMg9qSsdbIyzYIL9t9CCHWsKbumSKl_d4-YFuNU,11443
|
|
5
|
-
l0/layers.py,sha256=j_DPEFdfUc37ojtoK2ufGzVYzZ_DwusqTcJXCVxZS68,13785
|
|
6
|
-
l0/penalties.py,sha256=okqXgX2eGUmg5prcDclicTQALPPPF9FA5eQP09V4GTE,9569
|
|
7
|
-
l0/sparse.py,sha256=UVpkrrJBnQ9iSNDoWK5F_sr43tQareWXzYHyMq_cKss,9726
|
|
8
|
-
l0_python-0.4.3.dist-info/licenses/LICENSE,sha256=LoyFJ8qmpwWPp5RmxFGHhdBxsemvp_BqGyiCgNAZHlk,1069
|
|
9
|
-
l0_python-0.4.3.dist-info/METADATA,sha256=gN2ufd7zkVDielkTS2iGbUeKkf9bIMTiGZtvCkpc960,7095
|
|
10
|
-
l0_python-0.4.3.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
11
|
-
l0_python-0.4.3.dist-info/top_level.txt,sha256=brP2SoElgmGhNJk-qRFEQZ5UE-d1e87Tr60hSSh8n34,3
|
|
12
|
-
l0_python-0.4.3.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|