Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions modelopt/torch/sparsity/state_sparsity/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,9 +142,9 @@ def validate_wmax_candidates(cls, candidates: object) -> object:
@field_validator("min_perplexity_retention")
@classmethod
def validate_perplexity_gate(cls, value: float) -> float:
"""Require a finite retention gate in (0, 1]."""
if not math.isfinite(value) or not 0.0 < value <= 1.0:
raise ValueError("min_perplexity_retention must be finite and in (0, 1]")
"""Require a finite positive retention gate."""
if not math.isfinite(value) or value <= 0.0:
raise ValueError("min_perplexity_retention must be finite and positive")
return value

@field_validator("min_top1_agreement")
Expand Down
14 changes: 11 additions & 3 deletions tests/unit/torch/sparsity/state_sparsity/test_dasc.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,12 +160,20 @@ def test_config_fails_closed(override):


def test_perplexity_retention_accepts_parity_improvements():
"""Allow an observed DASC perplexity improvement instead of requiring clamping."""
measurement = mtss.DASCCalibrationMeasurement(**_candidate(7))
measurement.quality[0].perplexity_retention = 1.0004
"""Allow improvement measurements and thresholds instead of requiring clamping."""
candidate = _candidate(7)
candidate["quality"][0]["perplexity_retention"] = 1.0004
measurement = mtss.DASCCalibrationMeasurement(**candidate)

assert measurement.quality[0].perplexity_retention == 1.0004

model = mtss.calibrate(
TinyGatedDeltaNetForCausalLM(),
_config(wmax_candidates=[7], min_perplexity_retention=1.0002),
[candidate],
)
assert mtss.export_policy(model)["selected_wmax"] == 7


def test_calibration_fails_closed_on_measurements_and_model_mismatch():
"""Reject incomplete evidence, failing gates, wrong geometry, and unsupported layers."""
Expand Down
Loading