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-0.1.3.tar.gz (29.1 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-0.1.3-py3-none-any.whl (25.9 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for alignment_risk-0.1.3.tar.gz
Algorithm Hash digest
SHA256 3cdd272d0d224b8ae0060d783b3f13fbcc64f2f31302536266d81dea171b6d64
MD5 301268075ecfc25c79689e5f5cfcc1cc
BLAKE2b-256 992b549be8e8968a9e003a2965a785550b61a4acd7a093539ca1c167b59341ce

See more details on using hashes here.

Provenance

The following attestation bundles were made for alignment_risk-0.1.3.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-0.1.3-py3-none-any.whl.

File metadata

  • Download URL: alignment_risk-0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 25.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for alignment_risk-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 6ffe312308244cc6a968c52e65354e537f039bc2dca268a242a91b77365ce80f
MD5 27388d54b3dfb087cb4afe03fe5c0de1
BLAKE2b-256 dbcd09dffdebcccbb4491307e7a35ddc4528b62400fc70bf8440764738df62d7

See more details on using hashes here.

Provenance

The following attestation bundles were made for alignment_risk-0.1.3-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