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.pngartifacts/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
- Low-rank safety sensitivity subspace from empirical Fisher geometry.
- Initial overlap risk (projection of first update into sensitive subspace).
- Curvature coupling risk (second-order drift signal).
- 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_Bby 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 (default0.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.mddocs/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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9415ea1a6240dc3a02e6d09380b2e796ee4c9df8b01bb9bca8e69ec6270f92cc
|
|
| MD5 |
41b163bc12b7bcc0d272770d861516fb
|
|
| BLAKE2b-256 |
e9b430696c3539426c57ce5665da97c12d7878a6843b99e7a0e73b0f286eafdc
|
Provenance
The following attestation bundles were made for alignment_risk-1.14.0.tar.gz:
Publisher:
publish.yml on Sirhan1/modelFineTuneRiskAssessment
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
alignment_risk-1.14.0.tar.gz -
Subject digest:
9415ea1a6240dc3a02e6d09380b2e796ee4c9df8b01bb9bca8e69ec6270f92cc - Sigstore transparency entry: 992454611
- Sigstore integration time:
-
Permalink:
Sirhan1/modelFineTuneRiskAssessment@0d2d03a567f64b806cc971962e6988b63d2800cb -
Branch / Tag:
refs/tags/v1.14.0 - Owner: https://github.com/Sirhan1
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@0d2d03a567f64b806cc971962e6988b63d2800cb -
Trigger Event:
push
-
Statement type:
File details
Details for the file alignment_risk-1.14.0-py3-none-any.whl.
File metadata
- Download URL: alignment_risk-1.14.0-py3-none-any.whl
- Upload date:
- Size: 26.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f7eab6fabea39331363fe3dd3e0f4974129d3fcfbc14a1686b3e20efaf56511c
|
|
| MD5 |
781a5e53e85d874241936479bba1a7f1
|
|
| BLAKE2b-256 |
be378cba54ad21c87e89590d262452d3327cf62775c1f156b8a233dba5bce2d5
|
Provenance
The following attestation bundles were made for alignment_risk-1.14.0-py3-none-any.whl:
Publisher:
publish.yml on Sirhan1/modelFineTuneRiskAssessment
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
alignment_risk-1.14.0-py3-none-any.whl -
Subject digest:
f7eab6fabea39331363fe3dd3e0f4974129d3fcfbc14a1686b3e20efaf56511c - Sigstore transparency entry: 992454614
- Sigstore integration time:
-
Permalink:
Sirhan1/modelFineTuneRiskAssessment@0d2d03a567f64b806cc971962e6988b63d2800cb -
Branch / Tag:
refs/tags/v1.14.0 - Owner: https://github.com/Sirhan1
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@0d2d03a567f64b806cc971962e6988b63d2800cb -
Trigger Event:
push
-
Statement type: