Skip to content

feat(optim): add auditable parameter-group coverage - #186

Open
PinkTulips139 wants to merge 1 commit into
Tencent:mainfrom
PinkTulips139:feat-peft-optimizer-group-audit
Open

feat(optim): add auditable parameter-group coverage#186
PinkTulips139 wants to merge 1 commit into
Tencent:mainfrom
PinkTulips139:feat-peft-optimizer-group-audit

Conversation

@PinkTulips139

Copy link
Copy Markdown
Contributor

Summary

Adds a read-only optimizer parameter-group audit for validating how model parameters are assigned to optimizer.param_groups.

The audit makes optimizer construction more observable by checking trainable-parameter coverage, duplicate assignments, frozen parameters present in the optimizer, and optimizer parameters that cannot be mapped back to the model.

Changes

  • Add audit_optimizer_param_groups(model, optimizer, strict=False).
  • Add the structured OptimizerGroupAuditError.
  • Report:
    • missing trainable parameters;
    • parameters assigned more than once;
    • frozen parameters present in optimizer groups;
    • optimizer parameters not owned by the model;
    • exactly-once trainable coverage;
    • tensor and element counts per group;
    • current lr, optional initial_lr, weight_decay, and explicit group metadata.
  • Preserve explicit optimizer group semantics such as group_name, name, and role.
  • Avoid guessing Adapter, Router, or Head roles from parameter-name substrings.
  • Integrate the read-only audit after adapter/PEFT optimizer configuration and before scheduler construction.
  • Store the resulting structured snapshot on the Trainer and emit a compact main-rank summary.

Strictness

With strict=False, all findings are returned as structured data without interrupting training.

With strict=True, missing trainable parameters, duplicate assignments, and unknown optimizer parameters raise OptimizerGroupAuditError.

Frozen parameters in optimizer groups are reported but are not automatically removed.

Behavior guarantees

This PR does not change:

  • optimizer group contents or order;
  • learning rates or learning-rate multipliers;
  • initial_lr or weight decay;
  • scheduler or warmup behavior;
  • checkpoint or resume topology;
  • model outputs;
  • LoRA, Adapter, or Router defaults.

The audit is a read-only snapshot of the current optimizer state.

Validation

  • 20 passed in optimizer-group audit tests
  • 9 passed in PEFT optimizer-policy tests
  • 3 passed in LoRA layer-decay tests
  • Ruff passed
  • Ruff format check passed
  • Python compilation passed
  • git diff --check passed

The tests cover exactly-once coverage, missing and duplicate parameters, frozen and unknown parameters, strict versus reporting modes, JSON serialization, group statistics, scheduler-updated learning rates, and non-PEFT optimizers.

@PinkTulips139

Copy link
Copy Markdown
Contributor Author

CI note: the only failing job is the legacy Python 3.8 / PyTorch 1.8.0 environment, which fails in the existing Mixture tests because torch.autocast is unavailable. This compatibility issue is addressed separately by #185. PR #186 changes only optimizer parameter-group auditing and does not modify the shared autocast helper or Mixture computation.

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.

1 participant