1313 </a >
1414</p >
1515
16- Nx SVD/SVF factorization primitives for model surgery and TRINITY artifact
17- export.
16+ Nx SVD/SVF factorization primitives for model surgery and artifact export.
1817
19- This package intentionally owns the temporary Nx/EXLA git pin required for the
20- thin-SVD memory behavior used by the coordinator. Contract packages should not
21- inherit that pin directly.
18+ This package is intentionally narrow. It owns numerical factorization,
19+ reconstruction, tensor traversal, manifest helpers, and router-vector splitting.
20+ It avoids provider, tracing, orchestration, and application runtime dependencies.
21+ Callers that use product-specific artifact names should pass those names
22+ explicitly at the API boundary.
23+
24+ ## What It Provides
25+
26+ - ` CrucibleFactorization.SVD.thin/2 ` and ` thin!/2 ` run reduced SVD with timing,
27+ backend, rank, and sync metadata.
28+ - ` CrucibleFactorization.SVD.reconstruct/3 ` rebuilds tensors from SVD
29+ components and scale offsets.
30+ - ` CrucibleFactorization.SVD.decompose_tensors/2 ` ,
31+ ` reconstruct_tensors/3 ` , and ` adapt_tensors/3 ` operate on selected tensor
32+ entries from nested parameter trees.
33+ - ` CrucibleFactorization.SVF ` provides low-rank singular-vector-field helpers
34+ for ` base_tensor + low_rank_delta ` workflows.
35+ - ` CrucibleFactorization.StageCheck ` and ` ParityReport ` provide math-only
36+ tensor comparison summaries.
37+ - ` CrucibleFactorization.SVD.load_router_vector!/2 ` and
38+ ` split_router_vector/4 ` load and split a flat vector into scale offsets and
39+ dense head weights. The default tensor name is the generic ` "router_vector" ` .
2240
2341## Installation
2442
@@ -37,6 +55,78 @@ Documentation can be generated with [ExDoc](https://github.com/elixir-lang/ex_do
3755and published on [ HexDocs] ( https://hexdocs.pm ) . Once published, the docs can
3856be found at < https://hexdocs.pm/crucible_factorization > .
3957
58+ ## Thin SVD
59+
60+ ``` elixir
61+ alias CrucibleFactorization .SVD
62+
63+ matrix = Nx .tensor ([[2.0 , 4.0 ], [1.0 , 2.0 ]], type: :f32 )
64+
65+ {:ok , result} = SVD .thin (matrix, rank: 1 , compute_type: :f32 , force_sync?: true )
66+ reconstructed = SVD .reconstruct (result, Nx .broadcast (0.0 , {result.rank}))
67+ ```
68+
69+ ` result ` includes ` :u ` , ` :s ` , ` :v ` , ` :rank ` , source type, backend label,
70+ decompose timing, and optional force-sync timing.
71+
72+ ## SVF Delta Reconstruction
73+
74+ ``` elixir
75+ alias CrucibleFactorization .SVF
76+
77+ base = Nx .tensor ([[1.0 , 1.0 ], [1.0 , 1.0 ]], type: :f32 )
78+ delta = Nx .tensor ([[2.0 , 4.0 ], [1.0 , 2.0 ]], type: :f32 )
79+
80+ {:ok , svf} = SVF .decompose (delta, rank: 1 )
81+ {:ok , adapted} = SVF .reconstruct (base, svf)
82+ ```
83+
84+ ## Tensor Traversal
85+
86+ ``` elixir
87+ entries =
88+ params
89+ |> SVD .decomposable_tensor_entries (path_filter: SVD .layer_index_filter ([26 ]))
90+
91+ manifest = SVD .tensor_manifest (entries)
92+ count = SVD .singular_value_count (entries)
93+ ```
94+
95+ The helpers accept generic nested maps, lists, tuples, and structs with a
96+ ` :data ` field. They do not require a framework runtime struct.
97+
98+ ## Router Vector Helpers
99+
100+ ``` elixir
101+ vector = SVD .load_router_vector! (" router_vector.safetensors" )
102+
103+ split =
104+ SVD .split_router_vector (
105+ vector,
106+ scale_count,
107+ hidden_size,
108+ output_count
109+ )
110+
111+ split.scale_offsets
112+ split.head_weights
113+ ```
114+
115+ For product-specific safetensors keys, pass the key explicitly:
116+
117+ ``` elixir
118+ vector = SVD .load_router_vector! (" artifact.safetensors" , " product_router_vector" )
119+ ```
120+
121+ ## Backend And Sync Options
122+
123+ ` thin/2 ` accepts:
124+
125+ - ` :rank ` for reduced rank selection.
126+ - ` :compute_type ` , either ` :source ` or ` :f32 ` .
127+ - ` :backend ` for ` Nx.backend_transfer/2 ` .
128+ - ` :force_sync? ` and ` :sync_fun ` for timing asynchronous backends.
129+
40130## CI
41131
42132``` sh
@@ -48,3 +138,6 @@ CUDA is opt-in:
48138``` sh
49139XLA_TARGET=cuda12 mix test --only cuda
50140```
141+
142+ ` mix ci ` runs dependency fetch, format check, warning-as-error compile, tests,
143+ Credo strict, Dialyzer, and docs generation.
0 commit comments