Skip to content

mp: add zero-hyperparameter auto-MP calibration#19

Open
Polarisyjr wants to merge 1 commit into
CrucibleComputingGroup:mainfrom
Polarisyjr:vit_mp
Open

mp: add zero-hyperparameter auto-MP calibration#19
Polarisyjr wants to merge 1 commit into
CrucibleComputingGroup:mainfrom
Polarisyjr:vit_mp

Conversation

@Polarisyjr
Copy link
Copy Markdown
Collaborator

Adds an offline, gradient-free mixed-precision calibrator that finds per-(block, op) free boundaries minimizing the post-QwT-compensation residual via forward-only coordinate descent.

  • config: FreeBoundaryMPConfig (per-(block,op) k-1 free boundaries, fixed-level pinning), per-block context (_CURRENT_BLOCK_IDX + set/get_current_block_idx), AutoMPBudgetLogger, and two new guarded branches in adaptive_classify_rows (free-boundary + target_fractions quantile path). AdaptiveMPConfig gains an optional target_fractions field. No existing default path changed (additive only).
  • auto_calibrator: oracle_search_op/oracle_search_block/auto_calibrate_mp plus RidgeFitter closed-form compensation fit.
  • init: export the new public API.

Adds an offline, gradient-free mixed-precision calibrator that finds
per-(block, op) free boundaries minimizing the post-QwT-compensation
residual via forward-only coordinate descent.

- config: FreeBoundaryMPConfig (per-(block,op) k-1 free boundaries,
  fixed-level pinning), per-block context (_CURRENT_BLOCK_IDX +
  set/get_current_block_idx), AutoMPBudgetLogger, and two new guarded
  branches in adaptive_classify_rows (free-boundary + target_fractions
  quantile path). AdaptiveMPConfig gains an optional target_fractions
  field. No existing default path changed (additive only).
- auto_calibrator: oracle_search_op/oracle_search_block/auto_calibrate_mp
  plus RidgeFitter closed-form compensation fit.
- __init__: export the new public API.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@Allenjin123
Copy link
Copy Markdown
Contributor

Is this for QwT or for Mixed precision?

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

@Polarisyjr Polarisyjr requested a review from Copilot May 27, 2026 23:52
@Polarisyjr
Copy link
Copy Markdown
Collaborator Author

Is this for QwT or for Mixed precision?

MP

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 6 comments.

Comment on lines +542 to +548
for it in range(comp_refit_iters):
tmp_comp = comp_factory(W.detach().cpu(),
b_vec.detach().cpu()).to(device)
with torch.no_grad():
c_actual_chunks = []
for s in range(0, X_flat.size(0), fwd_chunk * 257):
e = min(s + fwd_chunk * 257, X_flat.size(0))
Comment thread scmp_kernels/mp/config.py
Comment on lines +29 to +34
_CURRENT_BLOCK_IDX: int = 0


def set_current_block_idx(i: int) -> None:
global _CURRENT_BLOCK_IDX
_CURRENT_BLOCK_IDX = int(i)
Comment on lines +442 to +458
AutoMPBudgetLogger.enable()
try:
y0 = _run_block_sc()
finally:
AutoMPBudgetLogger.disable()
budget_entries = AutoMPBudgetLogger.snapshot(clear=True)
budget_stats = {
"baseline": sum(e["baseline"] for e in budget_entries),
"actual": sum(e["actual"] for e in budget_entries),
"entries": budget_entries,
}
if avg_sc_draws <= 1:
return y0, budget_stats
acc = y0
for _ in range(avg_sc_draws - 1):
acc = acc + _run_block_sc()
return acc / avg_sc_draws, budget_stats
Comment on lines +489 to +514
per_op: dict[str, dict[str, Any]] = {}
if search_objective == "raw_mse":
score_fn = lambda Y_sc_eval: float( # noqa: E731
(Y_fp_flat - Y_sc_eval).pow(2).mean().item())
else:
score_fn = None
for outer in range(n_outer_block):
for op in ops_per_block:
b_init = cfg.get_boundaries(op, i)
b_new, score = oracle_search_op(
run_block_sc=_run_block_sc_avg,
Y_fp=Y_fp_flat,
fitter=fitter,
cfg=cfg,
block_idx=i,
op=op,
init_boundaries=b_init,
n_candidates=n_candidates,
n_outer=n_outer_per_op,
run_block_sc_with_budget=(
_run_block_sc_avg_with_budget if budget_ratio is not None else None),
budget_target_actual=block_budget_target,
score_fn=score_fn,
log_fn=log_fn,
)
per_op[op] = {"boundaries": b_new.tolist(), "score": score}
Comment thread scmp_kernels/mp/config.py
Comment on lines +615 to +620
boundaries, so it sees the true block-local compute for that candidate.
"""

_enabled: bool = False
_log: list[dict] = []

Comment on lines +610 to +617
# pre-hook was attached to blk_sc; re-attach to new_block
# (old hook still fires on blk_sc if it's still referenced, but
# forwarding now goes through new_block; add a fresh hook).
def _make_hook(idx):
def _hook(_m, _args):
set_current_block_idx(idx)
return _hook
new_block.register_forward_pre_hook(_make_hook(i))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants