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.1.tar.gz (31.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-1.14.1-py3-none-any.whl (26.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: alignment_risk-1.14.1.tar.gz
  • Upload date:
  • Size: 31.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-1.14.1.tar.gz
Algorithm Hash digest
SHA256 32d7b840b9cd877cc3a0efa04ad21d8be86fd44e8791c211d39ca2b07302b5be
MD5 f4a13e7f8da536cca591cd2265c824fb
BLAKE2b-256 88dcc688c7a9032e563ec02c54108f9de8bd085638eb08e6fd62451538eb222e

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for alignment_risk-1.14.1-py3-none-any.whl
Algorithm Hash digest
SHA256 3d1c4f68dc999aecfcb5e91dc1905f38d074a80619221795eda444333c9425be
MD5 294d1377b98d416577bc29f3b3da17b2
BLAKE2b-256 3d7f032d1aff0599bf4fbf9d13b576ff716180ac4b80cdab019d3d77572af36b

See more details on using hashes here.

Provenance

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