Instructions to use HaadesX/Iconoclast with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use HaadesX/Iconoclast with Transformers:
# pip install -U transformers accelerate # Load model directly from transformers import AutoModel model = AutoModel.from_pretrained("HaadesX/Iconoclast", device_map="auto") - Notebooks
- Google Colab
- Kaggle
Download tests/test_direction.py from HaadesX/Iconoclast: direct link, hf CLI and curl.
- Browser
- Download file 1.5 kB
-
https://huggingface.co/HaadesX/Iconoclast/resolve/main/tests/test_direction.py
- Command line
-
hf download hf://HaadesX/Iconoclast/tests/test_direction.py
-
curl -L -o test_direction.py https://huggingface.co/HaadesX/Iconoclast/resolve/main/tests/test_direction.py
1.5 kB
| import sys | |
| import unittest | |
| from pathlib import Path | |
| import torch | |
| sys.path.insert(0, str(Path(__file__).resolve().parents[1] / "src")) | |
| from iconoclast.direction import ( | |
| compute_benign_subspace_basis, | |
| project_directions_out_of_subspace, | |
| ) | |
| class DirectionTests(unittest.TestCase): | |
| def test_benign_subspace_projection_removes_principal_good_direction(self): | |
| good_residuals = torch.tensor( | |
| [ | |
| [[3.0, 0.0, 0.0]], | |
| [[1.0, 0.0, 0.0]], | |
| [[-1.0, 0.0, 0.0]], | |
| [[-3.0, 0.0, 0.0]], | |
| ] | |
| ) | |
| basis = compute_benign_subspace_basis(good_residuals, rank=1) | |
| directions = torch.tensor([[1.0, 1.0, 0.0]]) | |
| projected = project_directions_out_of_subspace(directions, basis) | |
| self.assertAlmostEqual(projected[0, 0].item(), 0.0, places=5) | |
| self.assertAlmostEqual(projected[0, 1].item(), 1.0, places=5) | |
| self.assertAlmostEqual(projected[0, 2].item(), 0.0, places=5) | |
| def test_zero_rank_benign_subspace_is_disabled(self): | |
| good_residuals = torch.tensor( | |
| [ | |
| [[1.0, 0.0]], | |
| [[-1.0, 0.0]], | |
| ] | |
| ) | |
| basis = compute_benign_subspace_basis(good_residuals, rank=0) | |
| directions = torch.tensor([[0.6, 0.8]]) | |
| projected = project_directions_out_of_subspace(directions, basis) | |
| self.assertTrue(torch.equal(projected, directions)) | |
| if __name__ == "__main__": | |
| unittest.main() | |