@@ -20,6 +20,22 @@ identity and SVF patch operations, manifest/checksum emission, resume/force
2020rules, backend label round trips, and stage comparison. It intentionally avoids
2121provider, tracing, and orchestration dependencies.
2222
23+ ## What It Provides
24+
25+ - ` CrucibleTensorPatch.Plan ` loads and validates patch plans from maps or JSON
26+ files.
27+ - ` CrucibleTensorPatch.Apply ` applies identity and SVF patch operations and
28+ writes deterministic safetensors outputs.
29+ - ` CrucibleTensorPatch.ParamTree ` patches nested parameter trees using manifest
30+ selected-tensor entries.
31+ - ` CrucibleTensorPatch.Manifest ` emits deterministic operation manifests.
32+ - ` CrucibleTensorPatch.BackendLabel ` round-trips known Nx/EXLA backend labels.
33+ - ` CrucibleTensorPatch.StageCheck ` compares stage reports using shared tensor
34+ comparison behavior.
35+
36+ The package does not fetch models, load provider credentials, run coordination
37+ loops, or own application runtime configuration.
38+
2339## Installation
2440
2541If [ available in Hex] ( https://hex.pm/docs/publish ) , the package can be installed
@@ -37,6 +53,112 @@ Documentation can be generated with [ExDoc](https://github.com/elixir-lang/ex_do
3753and published on [ HexDocs] ( https://hexdocs.pm ) . Once published, the docs can
3854be found at < https://hexdocs.pm/crucible_tensor_patch > .
3955
56+ ## Plan Schema
57+
58+ A plan contains a ` schema ` string and an ordered ` operations ` list:
59+
60+ ``` elixir
61+ plan_doc = %{
62+ " schema" => " example.v1" ,
63+ " operations" => [
64+ %{
65+ " id" => " copy_layer" ,
66+ " operation" => " identity" ,
67+ " source_path" => " layers.0.kernel" ,
68+ " output_path" => " layers/0000_kernel.safetensors" ,
69+ " expected_shape" => [2 , 2 ],
70+ " expected_dtype" => " f32"
71+ }
72+ ]
73+ }
74+
75+ {:ok , plan} = CrucibleTensorPatch .Plan .load (plan_doc)
76+ ```
77+
78+ Supported operations are:
79+
80+ - ` "identity" ` : copies a source tensor to a safetensors output.
81+ - ` "svf_apply" ` : reconstructs a tensor from SVD/SVF components and scale
82+ offsets before writing the output.
83+
84+ Supported dtype strings are ` bf16 ` , ` f16 ` , ` f32 ` , ` i32 ` , and ` i64 ` .
85+
86+ ## Applying Identity Operations
87+
88+ ``` elixir
89+ source = %{
90+ " layers.0.kernel" => Nx .tensor ([[1.0 , 2.0 ], [3.0 , 4.0 ]], type: :f32 )
91+ }
92+
93+ {:ok , manifest} =
94+ CrucibleTensorPatch .Apply .apply (
95+ plan,
96+ source,
97+ " out/patch" ,
98+ force: false
99+ )
100+ ```
101+
102+ The result manifest includes operation status, output paths, skip state, and
103+ SHA-256 checksums. ` manifest.json ` is written by default.
104+
105+ ## Applying SVF Operations
106+
107+ SVF operations reference component tensors by name:
108+
109+ ``` elixir
110+ operation = %{
111+ " id" => " svf_layer" ,
112+ " operation" => " svf_apply" ,
113+ " source_path" => " layers.0.kernel" ,
114+ " output_path" => " layers/0000_kernel.safetensors" ,
115+ " inputs" => %{
116+ " u" => " layer_0_u" ,
117+ " s" => " layer_0_s" ,
118+ " v" => " layer_0_v" ,
119+ " scale_offsets" => " layer_0_offsets"
120+ },
121+ " expected_shape" => [2 , 2 ],
122+ " expected_dtype" => " f32"
123+ }
124+ ```
125+
126+ Pass the component tensors through the ` :components ` option:
127+
128+ ``` elixir
129+ CrucibleTensorPatch .Apply .apply (plan, source, " out/patch" ,
130+ components: %{
131+ " layer_0_u" => u,
132+ " layer_0_s" => s,
133+ " layer_0_v" => v,
134+ " layer_0_offsets" => offsets
135+ }
136+ )
137+ ```
138+
139+ ## Patching Parameter Trees
140+
141+ ``` elixir
142+ patched =
143+ CrucibleTensorPatch .Apply .patch_params! (
144+ params,
145+ manifest,
146+ tensors,
147+ cast_tensors: true
148+ )
149+ ```
150+
151+ The patcher accepts maps or structs with a ` :data ` field. Manifest entries may
152+ include explicit ` segments ` ; otherwise the path string is split into traversal
153+ segments.
154+
155+ ## Resume And Force
156+
157+ When an operation has ` expected_output_sha256 ` and the output file already
158+ exists, the applier verifies the checksum and skips completed output. A checksum
159+ mismatch raises. Pass ` force: true ` to rewrite outputs regardless of existing
160+ files.
161+
40162## CI
41163
42164``` sh
@@ -46,6 +168,10 @@ mix ci
46168Large local fixture checks are opt-in:
47169
48170``` sh
49- TRINITY_ARTIFACT_DIR=~ /p/g/n/trinity_coordinator/priv/sakana_trinity/adapted_qwen3_0_6b_layer26 \
50- mix test --only large_tensor_patch
171+ mkdir -p tmp
172+ ln -s /path/to/artifact_bundle tmp/crucible_tensor_patch_fixture
173+ mix test --only large_tensor_patch
51174```
175+
176+ ` mix ci ` runs dependency fetch, format check, warning-as-error compile, tests,
177+ Credo strict, Dialyzer, and docs generation.
0 commit comments