Skip to main content

Template toolkit for AIC-based alignment collapse diagnostics

Project description

alignment-risk

alignment-risk is a Python package for pre-flight alignment risk diagnostics during fine-tuning. It estimates whether updates are likely to drift into safety-sensitive directions before you commit to a run.

Full documentation site: sirhan1.github.io/modelFineTuneRiskAssessment

Quick Start (1 minute)

Install:

pip install alignment-risk

Run the built-in demo:

alignment-risk demo --output-dir artifacts

Outputs:

  • artifacts/sensitivity_map.png
  • artifacts/safety_decay_forecast.png

Installation

PyPI:

pip install alignment-risk

Local development (Apple Silicon convenience):

make setup
source .venv/bin/activate

Local development (manual, cross-platform):

python -m venv .venv
source .venv/bin/activate
pip install -e ".[dev]"

Basic Usage (Python API)

from alignment_risk import AlignmentRiskPipeline, PipelineConfig

config = PipelineConfig(mode="lora")  # "full" or "lora"
pipeline = AlignmentRiskPipeline(config)

report = pipeline.run(
    model=model,
    safety_dataloader=safety_loader,
    safety_loss_fn=safety_loss_fn,
    fine_tune_dataloader=ft_loader,
    fine_tune_loss_fn=ft_loss_fn,
)

print(report.warning)
print(report.forecast.collapse_step)

CLI

alignment-risk --help
alignment-risk demo --output-dir artifacts
alignment-risk demo --mode lora --output-dir artifacts

What It Computes

  1. Low-rank safety sensitivity subspace from empirical Fisher geometry.
  2. Initial overlap risk (projection of first update into sensitive subspace).
  3. Curvature coupling risk (second-order drift signal).
  4. Quartic-style stability forecast and collapse-step estimate.

Modes

  • full: analyze all selected trainable parameters.
  • lora: analyze only trainable LoRA adapter parameters (lora_, lora_A, lora_B by default).

LoRA Mitigation (AlignGuard-style)

After mode="lora" risk analysis, attach a regularizer to penalize drift in sensitive directions:

from alignment_risk import AlignmentRiskPipeline, PipelineConfig, AlignGuardConfig

config = PipelineConfig(mode="lora")
pipeline = AlignmentRiskPipeline(config)

report = pipeline.run(
    model=model,
    safety_dataloader=safety_loader,
    safety_loss_fn=safety_loss_fn,
    fine_tune_dataloader=ft_loader,
    fine_tune_loss_fn=ft_loss_fn,
)

mitigator = pipeline.build_lora_mitigator(
    model,
    report.subspace,
    config=AlignGuardConfig(lambda_a=0.25, lambda_t=0.5, lambda_nc=0.1, alpha=0.5),
)

task_loss = ft_loss_fn(model, batch)
breakdown = mitigator.regularized_loss(task_loss)
breakdown.total_loss.backward()

Use mitigator.reset_reference() to re-anchor regularization at the current adapter state.

Performance / Accuracy Controls

FisherConfig supports speed/accuracy tradeoffs:

  • gradient_collection: "loop" (default), "auto", "vmap".
  • subspace_method: "svd", "randomized_svd", "diag_topk".
  • vmap_chunk_size: optional chunking for lower memory.
  • target_explained_variance: auto-rank selection (default 0.9).

Example:

from alignment_risk import AlignmentRiskPipeline, PipelineConfig

config = PipelineConfig()
config.fisher.gradient_collection = "vmap"
config.fisher.subspace_method = "randomized_svd"
config.fisher.vmap_chunk_size = 16

Theory and Math References

  • [AIC-2026] Springer, Max, et al. (2026). The Geometry of Alignment Collapse: When Fine-Tuning Breaks Safety. arXiv:2602.15799v1. PDF: https://arxiv.org/pdf/2602.15799
  • [ALIGNGUARD-2025] Das, Amitava, et al. (2025). AlignGuard-LoRA: Alignment-Preserving Fine-Tuning via Fisher-Guided Decomposition and Riemannian-Geodesic Collision Regularization. arXiv:2508.02079v1. PDF: https://arxiv.org/pdf/2508.02079

Detailed internal mappings and equations:

  • docs/SOURCES.md
  • docs/MATH.md

Development

make install
make test
make lint
make typecheck
make build
make check-dist

See CONTRIBUTING.md for contribution workflow details.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

alignment_risk-1.14.0.tar.gz (30.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

alignment_risk-1.14.0-py3-none-any.whl (26.5 kB view details)

Uploaded Python 3

File details

Details for the file alignment_risk-1.14.0.tar.gz.

File metadata

  • Download URL: alignment_risk-1.14.0.tar.gz
  • Upload date:
  • Size: 30.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for alignment_risk-1.14.0.tar.gz
Algorithm Hash digest
SHA256 9415ea1a6240dc3a02e6d09380b2e796ee4c9df8b01bb9bca8e69ec6270f92cc
MD5 41b163bc12b7bcc0d272770d861516fb
BLAKE2b-256 e9b430696c3539426c57ce5665da97c12d7878a6843b99e7a0e73b0f286eafdc

See more details on using hashes here.

Provenance

The following attestation bundles were made for alignment_risk-1.14.0.tar.gz:

Publisher: publish.yml on Sirhan1/modelFineTuneRiskAssessment

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file alignment_risk-1.14.0-py3-none-any.whl.

File metadata

File hashes

Hashes for alignment_risk-1.14.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f7eab6fabea39331363fe3dd3e0f4974129d3fcfbc14a1686b3e20efaf56511c
MD5 781a5e53e85d874241936479bba1a7f1
BLAKE2b-256 be378cba54ad21c87e89590d262452d3327cf62775c1f156b8a233dba5bce2d5

See more details on using hashes here.

Provenance

The following attestation bundles were made for alignment_risk-1.14.0-py3-none-any.whl:

Publisher: publish.yml on Sirhan1/modelFineTuneRiskAssessment

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page