eousphoros commited on
Commit
56e15af
·
verified ·
1 Parent(s): 4948b7d

Add Turnstone Lambda 671.1 (Patch 1), a LoRA for parallel tool calls, and merge_lora.py --fp32-sum to merge it bit for bit

Browse files
671.1/README.md ADDED
@@ -0,0 +1,69 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Turnstone Lambda 671.1 (Patch 1)
2
+
3
+ A rank-4 LoRA for Turnstone Lambda 671 against one habit: announcing several independent tool calls, making the
4
+ first, and ending the turn. 3.2M parameters on 48 matrices, the MLP and attention output projections of layers 40-63.
5
+
6
+ ## Use
7
+
8
+ Merge it into the FP32 masters in this repository:
9
+
10
+ python merge_lora.py . 671.1 ../turnstone-lambda-671.1-fp32 --round-bf16 --fp32-sum \
11
+ --check --sums 671.1/SHA256SUMS.fp32 \
12
+ --bf16 ../turnstone-lambda-671.1-bf16 --sums-bf16 671.1/SHA256SUMS.bf16 \
13
+ --fp8 ../turnstone-lambda-671.1-fp8 --sums-fp8 671.1/SHA256SUMS.fp8
14
+
15
+ `--round-bf16 --fp32-sum` reproduces bit for bit the BF16 weights the adapter was trained against and evaluated
16
+ with. Merged into BF16 weights instead, most of the update rounds away; running the adapter unmerged is untested.
17
+ The FP8 export has not been benchmarked separately. The draft head in `../dspark/` works with the merged model.
18
+
19
+ ## Layers
20
+
21
+ On an RL checkpoint with the habit, swapping blocks of stock Qwen3.8-27B weights back in placed it in the second
22
+ half of the model, mostly the MLPs, with no single block responsible. One direction per layer captured it: the top
23
+ eigenvector of how the layer's change from stock moves the stop-versus-continue log-odds, fitted on half of the probe
24
+ contexts. Undoing the change from stock along that direction in each MLP down_proj of layers 40-63 cut the
25
+ probability of stopping after the first call from 0.18 to 0.02 on the other half (a random rank-16 control did
26
+ nothing) and cut announced-then-abandoned replies by 88% when sampled, but left stopping more than 10x stock's. A
27
+ projection also cannot tell independent calls from dependent ones: applied to 671, it lowered the correct stops
28
+ before dependent calls from 0.896 to 0.821. So the adapter is trained, on the same layers plus the attention output
29
+ projections, starting from zero.
30
+
31
+ ## Training
32
+
33
+ - Data: 732 contexts (34.2M tokens) from the RL run's own agentic rollouts. The loss sits only on the end-of-turn
34
+ decision after each tool call: continue where the rollout had announced more calls and stopped (relabelled) or
35
+ went on; stop after single and last calls and before a call that needs the previous result.
36
+ - Loss on g = log P(end of turn) - log P(newline): a hinge pushing continue positions to g <= -3.5, and a one-sided
37
+ floor holding stop positions at or above 671's g (weight 8; 3 before dependent calls). GPQA answer text is held to
38
+ 671 by KL.
39
+ - Two epochs, 366 steps of 4 contexts, Adam at a peak learning rate of 3e-5 (20 warm-up steps, linear decay to
40
+ 3e-6), about 2.6 hours on one GPU.
41
+ - The forward used round_bf16(FP32 master + BA), the merged weights themselves, with a straight-through gradient, so
42
+ training, evaluation and the merge above all see the same bytes.
43
+
44
+ ## Results against 671
45
+
46
+ Tool calls, on held-out positions (P = probability of ending the turn after a tool call):
47
+
48
+ | | 671 | 671.1 |
49
+ |---|---|---|
50
+ | P after the first of several announced calls (short prompts) | 0.139 | 0.020 |
51
+ | First turn makes every call (short parallel prompts, sampled) | 77% | 96% |
52
+ | P where the rollout stopped too early (rollout positions) | 0.81 | 0.29 |
53
+ | P where the rollout went on (rollout positions) | 0.285 | 0.207 |
54
+ | P at correct stops: single / last / dependent call | 0.977 / 0.970 / 0.896 | 0.974 / 0.954 / 0.899 |
55
+
56
+ Benchmarks, same harness (671 is the mean of two runs):
57
+
58
+ | | 671 | 671.1 | Difference, 95% interval |
59
+ |---|---|---|---|
60
+ | GPQA Diamond (4 repeats) | 88.5 | 87.0 | -1.5 [-3.2, +0.1] |
61
+ | IFBench, prompt-level strict | 72.7 | 69.0 | -3.7 [-7.7, +0.2] |
62
+ | LiveCodeBench (175 problems) | 85.1 | 82.3 | -2.9 [-7.4, +1.1] |
63
+ | XSTest: full compliance, safe / full refusal, unsafe | 95.6 / 76.0 | 94.8 / 76.0 | one run each |
64
+
65
+ Gate: 671.1 fails the gate set before training (continue positions below 0.10 where the rollout stopped too early
66
+ and 0.04 where it went on; stop positions within 0.01-0.03 of 671). It misses both continue limits and one stop
67
+ criterion, by 0.003. No candidate passed; stock Qwen3.8-27B itself scores 0.26 against the 0.04 limit.
68
+
69
+ License: Apache-2.0, as the base.
671.1/SHA256SUMS ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ 0ed6a85a91efda9585e4fc18d3974cc9d61536e77b82476f010536fea7789795 README.md
2
+ 34a8bc2b8e460417ebc64738209fe11398e6cc909bab7f496c8bd6532565d0a8 SHA256SUMS.bf16
3
+ 1a97b703041783b007ac047abb67e44d6358f7fdb7b693330bd3e356fd1ba222 SHA256SUMS.fp32
4
+ 980fa616d4e4ecb5c519537a6bdaead69d32be6fb1fb4ee5c4db1ba17ad8211e SHA256SUMS.fp8
5
+ 5c3d3f1c716cd2f607e4da8d6ac1605e70bef40087d81f35c96cdfa8bc3e7b2e adapter_config.json
6
+ 8013b9462c55739a835e0917429f729adcbe3dc93e62bf25b4a38ce99721dbc3 adapter_model.safetensors
671.1/SHA256SUMS.bf16 ADDED
@@ -0,0 +1,64 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ c3cf9e34abf4f9e36c2d72165aa9c132d3e2a725b6c2586aaa3a8af9d7a81041 chat_template.jinja
2
+ 191e0af232104ed8b65258cf3fb2b842e288008baca7633c11b82a1ac7203aab config.json
3
+ e70c136c1b78ddc1fb0905bac8e733a4dc448d4f852a5dd75143fffc70be550e generation_config.json
4
+ a9d356d7bdf1ef4949e3e748e95b8e10ad9d4e2e838eddc38a0a7b6b94d1db8d merges.txt
5
+ 355e8ef5db712fc78cf66a83bb05c326327543a8656d237be9250468c630b80a model-part-00001.safetensors
6
+ 5d38d109779e8bd1217615cbfc12c6a12bb3ccb58914334f50050f74921cb147 model-part-00002.safetensors
7
+ 2425df3662d1e5e51f0f6df53627c8dd33a51c99a6c50098b5aae05849f6cfef model-part-00003.safetensors
8
+ 86c20299125a968445e3656026d3d55fcca8a8bdb6257e472eee811526de0520 model-part-00004.safetensors
9
+ 69a8675c1ee3d6c995f9ee22b34c4d3b42bc1ab94e15d677e09a4e40c901febc model-part-00005.safetensors
10
+ 8138bfce52c2ff894011a836beea56987a78bdd2d79a6d8c9c11faf9c699db5b model-part-00006.safetensors
11
+ 7d50194d48442c518f163953a30cee8462d142e70adb2849130a0723d773e5e5 model-part-00007.safetensors
12
+ cb327577eee3f16403d74b415c28985c4c0b206d56d026bb0eb0e65d5c025cad model-part-00008.safetensors
13
+ 4deec02ee9bf42b75355580cefcdac95b9c817dd76335b57e6ed7b5a8cc96ed8 model-part-00009.safetensors
14
+ 65c6a6767917c789f3860708c3fa045dac2db2d65247b861bd761c27d5113922 model-part-00010.safetensors
15
+ b601b68fc5191630cccae61aea2a1228f6e89260f57307a037bf4b084686dfb6 model-part-00011.safetensors
16
+ ca68b23539ee66a02e41cef4d358f315df4cf3326d89d2f5e48e7258207e83ef model-part-00012.safetensors
17
+ a5dc6a27a8bf1c918712c7960b5427903460308d707e91eb0dbe64fdc0dbd56b model-part-00013.safetensors
18
+ de944ba4f3e23aeef9ac3d2ca276501bf4d1d964e8c6c6d402e801e6a7bfb872 model-part-00014.safetensors
19
+ 3910a5ca7ddb52635862a7f96fc1443f936296f7c5abb37071a8e3105725890d model-part-00015.safetensors
20
+ 2740a1b30966d8bbdfe016b914569fb12f5f8fdedee483a0f84f222fef7cda5f model-part-00016.safetensors
21
+ 7ead010e4a0867b3b6f7456e68ae9e4e45f6aa8cb2b73b39a63ec1422fc483e1 model-part-00017.safetensors
22
+ 0c51e80e571d37e252a43a2ca3c227aff22cbad36f1d5028c2b29702040f4b2e model-part-00018.safetensors
23
+ 9c92d328c3fd6be184dd48304fc23755e420d0175a91baa2b43fc573a9e37499 model-part-00019.safetensors
24
+ aca2eb2fd929013d9311874bb7ad6e4cc2fe0ae5d822def0776eb2c67e4d1cb3 model-part-00020.safetensors
25
+ 44a623cffda80279819ccea3d0be8f0ff392d41351baaaa2b7a166da1b366281 model-part-00021.safetensors
26
+ 65206f3aa08f052790196d3dd44463df481ea1426046e4af08113fb432468412 model-part-00022.safetensors
27
+ e0c88e58e4c9dd4e2c16f1b5ec2115b3f16557b47af1d0609979722da4162076 model-part-00023.safetensors
28
+ a98fd93b3dd41b18e075ca858d25b1647b23285aa58f3d20995553fb3f710f70 model-part-00024.safetensors
29
+ 220e071ec484a434ca583dec6418dbc8e36aaf3f328fafc109049d07d8815a93 model-part-00025.safetensors
30
+ 6182e25c289fc9bc205375588d63dbdd5dadfcf76b14e33d3b1e17821c4a8fa6 model-part-00026.safetensors
31
+ 9800e60e910ce72fd14e46e08f4aa8a871aeaf85a87373bd2c80bf11c3c37ac4 model-part-00027.safetensors
32
+ abff8dffc00cc9c33b1c06a81d7062f1d0f9fe5e20bff0c1271fc892c60594cc model-part-00028.safetensors
33
+ 7b00f940b34ad6b16342400c935b4775eef89f50830ca31903e60aebe6a675fa model-part-00029.safetensors
34
+ 4a7fb2d5a1b9ae620d555d11fdbb357ad503ff23ea650c27d25882d11b00397b model-part-00030.safetensors
35
+ 89ca89296031c88856ad448193b0036e42edc022f267e7ab7c452ad3d672fd14 model-part-00031.safetensors
36
+ 5f132b8ecbe7b6730d41434dc4ac510d225f8f78b207e34008f45b8b9474a59a model-part-00032.safetensors
37
+ 4d29b4119ae03ee338bc9efcf5c8b803e13aad6622160f900d0e45bae523e212 model-part-00033.safetensors
38
+ 4172f2e31208e9362f2b463e5433d980d47ea51cb0865cc72e4c7846dbdc6edc model-part-00034.safetensors
39
+ 5aca5437678abce1865843e120e026da83d68396794a46f55c5e4a6b128b192f model-part-00035.safetensors
40
+ 9a8ef55fe17a015470020a83985543616c0303ca613c45bb84b19e4f8eed56bb model-part-00036.safetensors
41
+ 554af0a4d1e563102c08b6c6ebdc588429d1e06cbc195b542ff902b1dbc68e16 model-part-00037.safetensors
42
+ 9929571ffd307d37e8a66fdcb1e93e5f10be316a6f3f58feef86cd74d172d9d0 model-part-00038.safetensors
43
+ 54ae726de8139b62a4861fcbae4d193328f099180cb12df265a6ed382d317e1c model-part-00039.safetensors
44
+ 67215fa64d0262a0fa63bf99212b2a4099239021a957119162f5a983c81f5811 model-part-00040.safetensors
45
+ 0b2e3451b1f9c38a27ad25bedb928dcec96279b9acd9842d55fc20c3aaee39c6 model-part-00041.safetensors
46
+ a35274624883d3d6e22408564af243840a33136a037ae3c764ec50567f1b4525 model-part-00042.safetensors
47
+ d1368eaeb9484193d67b4c8e71e57b35441df4c0a3d6010c5d68b65f0e7009b5 model-part-00043.safetensors
48
+ a0e21ccdf4305c9fe3570ad69de3cdd2d62c8c6a5f5a217cb961f05ebe0e5913 model-part-00044.safetensors
49
+ 6f4e43766644f2c53384bdc5d71a4df38211bc4651bde65c359f6e29ebe857ec model-part-00045.safetensors
50
+ 951480f7575c31bf7c40c0f058e95dcbde3901eb885ba238d4c9816a50e1bafb model-part-00046.safetensors
51
+ 7d1e70e58fa7d96fcf3ec6e66dc2893530a2edccebb8ec5709f75d35e69939bb model-part-00047.safetensors
52
+ 86ea21314dfbb36cf5a1ab7c09935d74b8f54217690af99cbd83af03bfdbe2b6 model-part-00048.safetensors
53
+ e4a0df8161a90a08f2b100019b3e2fd8b89d2f39e07e26d6bc2759cbe432b244 model-part-00049.safetensors
54
+ 8b3ea91a522a097365b504d1c0db9c8ace76f388782537a6846bc509d40fd0c5 model-part-00050.safetensors
55
+ a1f4b57c4869af756a2904adfb4f437896c2cd541eee63d53c787ff261a7d25f model-part-00051.safetensors
56
+ 735b6935c937f87b5aebbf6a5a5eebe74f67afb51799b7957c66158f919dcbdd model-part-00052.safetensors
57
+ 36acf37f77f2f7643d6d28d014f6c94b99a8574fbe6445927c6098231117c84e model-part-00053.safetensors
58
+ c5d97acb0a6b998fb118c83d5061b2d817597b7bde0989daa85d6bc9c08242a9 model-part-00054.safetensors
59
+ 2bfb40b84b71e39d624c92693267ced4f66c9aee0ba72140130df2bdef19bbc7 model.safetensors.index.json
60
+ 27225450ac9c6529872ee1924fcb0962ff5634834f817040f444118116f4e516 preprocessor_config.json
61
+ 0997f410c57a1f4e53b09e4be8f4a172d90edd9564368fb0847030937229b9f3 tokenizer.json
62
+ b11349aafa7cdc6a320767cf7ceb29ed82f7eda5d65e8e0819e76f0ce947bf27 tokenizer_config.json
63
+ 7768af27c1fafa9cc9011c1dc20067e03f8915e03b63504550e11d5066986d13 video_preprocessor_config.json
64
+ ce99b4cb2983d118806ce0a8b777a35b093e2000a503ebde25853284c9dfa003 vocab.json
671.1/SHA256SUMS.fp32 ADDED
@@ -0,0 +1,67 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ c3cf9e34abf4f9e36c2d72165aa9c132d3e2a725b6c2586aaa3a8af9d7a81041 chat_template.jinja
2
+ 191e0af232104ed8b65258cf3fb2b842e288008baca7633c11b82a1ac7203aab config.json
3
+ ea429ed340e4ac9181ea548de2818de7c202841895885a73ae562a776316bb8d fp32-release.json
4
+ e70c136c1b78ddc1fb0905bac8e733a4dc448d4f852a5dd75143fffc70be550e generation_config.json
5
+ e237562c46237bb25ccc14c8b1a8ee2a7c9bba45aae1baf193126ef2e3d56cec lora-merge.json
6
+ a9d356d7bdf1ef4949e3e748e95b8e10ad9d4e2e838eddc38a0a7b6b94d1db8d merges.txt
7
+ 3b63ad07184a1fba566c5de37bde1cb67b639f4eb173fc42decf273f8b59ef9b model-part-00001.safetensors
8
+ a773f18b2ce598327aac20843ea2589e7d656e0ccabbdf5f71b1587018604b9e model-part-00002.safetensors
9
+ bdf9df3f826223b82a66469d2b4e98fc0036631d08deb2012482ad0e1d80fd91 model-part-00003.safetensors
10
+ 25ac351e4e294aecc3f162969be0dfe2274d7dd159ee4a01315ebee85c452665 model-part-00004.safetensors
11
+ 1c800dd082e55c356e9bbcc4dd6501d33bb007cd637500d52112de169d6e8202 model-part-00005.safetensors
12
+ 82f22b5686afc704be19ff7d2840118e9ab96d0261f0ed23ec6864de35a00831 model-part-00006.safetensors
13
+ 96073f636ccc950e643b91081152d41de2533c991ff876a40f8a5f0571e21de0 model-part-00007.safetensors
14
+ 716986ea6aab109bfd74fc0e9239420e32b5ac33b4950a8ba11f20b51baccbcb model-part-00008.safetensors
15
+ 973aeca6a6cb417053687dc25049f33442c04a902b5f5241849582f02b628ce4 model-part-00009.safetensors
16
+ 7677751226938a6e977d20bfa901189c821a2dc3c7332b2591e5d925627d4321 model-part-00010.safetensors
17
+ 949f4ea3075b5ecc03e4591229eb48273582dbdd5010534711003be4640051fc model-part-00011.safetensors
18
+ 54a4391c27541aaf695b5205e76dbebc09d4aaba099d16dc1da8bd6ff20c03bf model-part-00012.safetensors
19
+ c2ae678fe26319990d9ed2712dda707f2a3567312bb4fc4bdbc7e0cfac8e5c9b model-part-00013.safetensors
20
+ 15b95470dbe3bc413d0ba0037104d2ddf4e81dfc3b02067599020e9dfc109dae model-part-00014.safetensors
21
+ 130d646414d4129d822a24e514c55ad3b6f9d8ffbf7868a2e567d32a49e28ca1 model-part-00015.safetensors
22
+ 1625715a17d676346ea0ecfe089c2c26f58780f1198644732804661cb9b2b896 model-part-00016.safetensors
23
+ 2a61c57020da3b6a4cb9ee3b5344e52c5b37fd75fc1ede91563cf5c382633f22 model-part-00017.safetensors
24
+ 552958e1ea49ff2c5caeee254efe0e1219d47289d43144bc12a08c95d34ffd22 model-part-00018.safetensors
25
+ b15be5e18cbe73700ba9f8525187b94eb311b4c8e48b4c4b79c898195a8d4fd2 model-part-00019.safetensors
26
+ e6844984a8b5988a8795e8b7e2f15ff9ec217fffdce247b3f2ed2e51c3c4e4e5 model-part-00020.safetensors
27
+ c672b4020496230f5a35b47efa5b46d5a66e531b5b6e748831a54255250c1a74 model-part-00021.safetensors
28
+ 23a540c14698583389168be432281b23b16c3a715607408cf2f5ef42353fbf4b model-part-00022.safetensors
29
+ 628541f31c50c9d7e79ebfcc41b4c851b15ae2b487eeb5a7b3dca113c1d86bca model-part-00023.safetensors
30
+ 125f51ef46a335e62b5d4124d7e3c7d38ac442d9c2f619241036a660fd12952a model-part-00024.safetensors
31
+ dbbe74e032eaa89528532427a176ead28488038b98ce7a0a1a7c15d977b2e0c2 model-part-00025.safetensors
32
+ 4c7583b879f5b14e12f9ccbdc7b2222d054746cc854182f8155a0730fc596bdb model-part-00026.safetensors
33
+ 4df242169472c5172f66053c824b3a7d624ee8fe2598a96f0eb03e3491d12116 model-part-00027.safetensors
34
+ b41cacac783676e88a709360f890c3a38d80988ae1bfcfe2c53ca7d1273989c3 model-part-00028.safetensors
35
+ 25f58a16104fd08ae37971e22306cb0b9022aa32037a0d297821ed5975c636bf model-part-00029.safetensors
36
+ 190385635ad6f0890c665674ea01a0462c339a5e2071ef01cdfbe0e6a5e9d7c4 model-part-00030.safetensors
37
+ 0a14160649c5504bf5d21c96be02b56d1069b9bd335661ada4a6e9f65de93f4a model-part-00031.safetensors
38
+ 6dc940aff3f47a57682d619527b07ba4022408df8deb41c5256f024536c2cecb model-part-00032.safetensors
39
+ ad39bc53fc6542308032e919c3dafd1f638c9312b2f3e559c44267bef786b2a0 model-part-00033.safetensors
40
+ 9e92116bb742ff137443b5fbdb67b04a16d3131da013510bac5205d621031d2f model-part-00034.safetensors
41
+ fb4d8a4b15d3b950b446343439f72094a1cc8bba8d3c87e66ae9aef6e2d411cf model-part-00035.safetensors
42
+ daa677b94aec1802e5cb7ca3583d9dccff5120d5d020f7ca6d9c3246ae7fc8a0 model-part-00036.safetensors
43
+ 44c5379b03f2d15df87ae47e7276b7dd75fdcbc8e1380eacb803c769c34c10fc model-part-00037.safetensors
44
+ 37fcc45e6975faa34166b1fbf9a34f27f15f3c05649c153e82211f024542af09 model-part-00038.safetensors
45
+ c510a2cdfbb297cbcebbdbb53e345338c443f5b57cf81c0b56232345fff268a1 model-part-00039.safetensors
46
+ 112f1e30bedcbc8000c0adb62902e96af95eb2f3364fb371bf2a714c11352a49 model-part-00040.safetensors
47
+ c16eca95d297efa85d6523638589ef45dec7a2560dc24b63718ad605be7b209e model-part-00041.safetensors
48
+ da6fddafad2187752e8d91ee9a12e5be79cf815e910ad4b61e5e76c2fed89ccf model-part-00042.safetensors
49
+ 6c6318e1c9cad3b1a6bfe85d8a1702959772785296fd144ab347d90dacf50eb9 model-part-00043.safetensors
50
+ fb963754aa54710fe2ca4ef8273a521f85a057f495de210b375151d824aeccce model-part-00044.safetensors
51
+ 962b59ba6228aaf341c7d5e01d80c801c66f7c707e542c9ac1e7d3f3a98a370e model-part-00045.safetensors
52
+ 3e9b00d0bf656e04c83388a92fdcc6e639a3001f597e384bc7f4bfda060c0cae model-part-00046.safetensors
53
+ 90bb81304c00c4b4b95f96490172f0f11d06be3a2ce455796a159e181646d134 model-part-00047.safetensors
54
+ fa94933ada30c82f11c5a1fdf50a2f1049ed8f03999223d515cd2825db9f9f4e model-part-00048.safetensors
55
+ 70d3c04085c1566f0e5635fbd52675ce0f709729c38384cead69f02c958bc42e model-part-00049.safetensors
56
+ 4ae0d8a1bceac6efc500e5d75423c13ecd7a5f34bb51eff976f4c343668d980b model-part-00050.safetensors
57
+ c66e3952941ae4554fe04ddfab597032640de58c2e2d4a09e7e636d0a0c78f16 model-part-00051.safetensors
58
+ 14e857ed04f163706ea52bb42a72b51a21005737350db5e164e105fdb4aa6efc model-part-00052.safetensors
59
+ cee66a9bc518cec9b38cb02190f2e30f6063de6cfc0ca43599016a7d018d075a model-part-00053.safetensors
60
+ 23d541c6273e11b8090b0c2ecd66fdeca6783015f547087e5ee4ac47de20b1a1 model.safetensors.index.json
61
+ 7184b0652c9eef85291fee126646a9d7437e8b8050e5b0d0dd90b31370427518 mtp.json
62
+ 7454f34b3a0cf80ceb03adc97d48dfba7644bec0f44c3a5f06182b06df4b7e2b mtp.safetensors
63
+ 27225450ac9c6529872ee1924fcb0962ff5634834f817040f444118116f4e516 preprocessor_config.json
64
+ 0997f410c57a1f4e53b09e4be8f4a172d90edd9564368fb0847030937229b9f3 tokenizer.json
65
+ b11349aafa7cdc6a320767cf7ceb29ed82f7eda5d65e8e0819e76f0ce947bf27 tokenizer_config.json
66
+ 7768af27c1fafa9cc9011c1dc20067e03f8915e03b63504550e11d5066986d13 video_preprocessor_config.json
67
+ ce99b4cb2983d118806ce0a8b777a35b093e2000a503ebde25853284c9dfa003 vocab.json
671.1/SHA256SUMS.fp8 ADDED
@@ -0,0 +1,64 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ c3cf9e34abf4f9e36c2d72165aa9c132d3e2a725b6c2586aaa3a8af9d7a81041 chat_template.jinja
2
+ 74227dd615bf1ea975aa676bdf355a0379858c12f394b5365cd9dfa5fc2c70bc config.json
3
+ e70c136c1b78ddc1fb0905bac8e733a4dc448d4f852a5dd75143fffc70be550e generation_config.json
4
+ a9d356d7bdf1ef4949e3e748e95b8e10ad9d4e2e838eddc38a0a7b6b94d1db8d merges.txt
5
+ 355e8ef5db712fc78cf66a83bb05c326327543a8656d237be9250468c630b80a model-part-00001.safetensors
6
+ 5d38d109779e8bd1217615cbfc12c6a12bb3ccb58914334f50050f74921cb147 model-part-00002.safetensors
7
+ 2425df3662d1e5e51f0f6df53627c8dd33a51c99a6c50098b5aae05849f6cfef model-part-00003.safetensors
8
+ 986965ddf1cff20b45f3e741c82600bedbae3ccc9f3a6d26d28d3e8dd7711c4a model-part-00004.safetensors
9
+ 5be53ef313b590f6ac73c65fc172d8c757f84c2cfa9be5798a9abc2086bbb81a model-part-00005.safetensors
10
+ 12de5c97374a806ac6e702370eed2a8759dfba216f37ed306e17a5ac69a2de60 model-part-00006.safetensors
11
+ b415f6bcdf59f9e60f34b7b71dc820e375332cdb43f3e2a6d9827b80822739a0 model-part-00007.safetensors
12
+ c89b87885948dcadfe8d9415002ad2184ba282177483099f064ca69db885b844 model-part-00008.safetensors
13
+ b70e8be1d5e5d08ff5a1c9526f0ea7c7bed66655e0a8cf77160e1e733a160d8e model-part-00009.safetensors
14
+ 8a200d710b807511726df05937e9b0d434a42ccf0a4ed0f078b34cd4051da00a model-part-00010.safetensors
15
+ eb6624a1e5b8c67ce78b5894fde553562a4c9252b2199f3b13981489bd51b325 model-part-00011.safetensors
16
+ 5eb9704cd2fb68e01d713f661cdfa941f72f9069869793d2a2d4c704662ee2ba model-part-00012.safetensors
17
+ 1e3c6de9a410da04038a01f6940a2c06d24c5b3a64711661242d452bdab7141b model-part-00013.safetensors
18
+ c9b199fccae22bbf79f9f55092c889e36b133e6fc894f8f4d30816a4e255dea5 model-part-00014.safetensors
19
+ ae187404d4a7e1feea792d402b7e41a5f6e7daafff744f8ebb4e693ace0825d0 model-part-00015.safetensors
20
+ 00ebf3cc96941d1beabab8fe5c29b84d1ae55eb19fa83fb2626da498fb333c80 model-part-00016.safetensors
21
+ 1b7975b28cbf78c9cc47738ed708c040a9d4ba8cdc9a9e9ea89a7f8b53e0618a model-part-00017.safetensors
22
+ 0a939c537f395d2fa1001ada1c88e25f6c1db983a82de68159a058565fc17038 model-part-00018.safetensors
23
+ 02afa2b20661da671fd5414fdd35bdc6ae6aac7cea1d269a2051509c4ef451ad model-part-00019.safetensors
24
+ f94171afe4cc7e8a03c79832db12fde700e5b234970738c53df22d6afc271c97 model-part-00020.safetensors
25
+ 72b099e3f28a1828e8dd0cd2976c56e2c8c140d93c19f12007cc42fe2b2e11ef model-part-00021.safetensors
26
+ 431619aacfa0cc19b7f6445c9f8192db445a111d6c5bdf7459adaad4716df182 model-part-00022.safetensors
27
+ fa5ec7fde7bddbcf6bc3d0fda479680fa5edd42a8ccf5cf287e9b0e51176806c model-part-00023.safetensors
28
+ 4b195b5e07a9006fed7d8f40c8177d36b933dab6f6af85fbc00646652c2d2c50 model-part-00024.safetensors
29
+ d3319d7f18b3c896ce47b4bd61d3d6282fdf238f0c1d92f58dc438e4c4884eb0 model-part-00025.safetensors
30
+ 7cf74c251182e557479d1052821374e8fafb168a672ad545448853a688ac6a2d model-part-00026.safetensors
31
+ fce8ecdfb256f6a7a0bb3443079234ccd855a0f7a8e82e44e283629585069717 model-part-00027.safetensors
32
+ d63e3c3c3394650e2a0334ac43f9c4517082d0cde796e1c8382d7b839b5ac2f1 model-part-00028.safetensors
33
+ 9c87ecc62f3ec4697a9284300b077733af456a547f1a6200dc1fdcae05aeb374 model-part-00029.safetensors
34
+ c30547e6b9b59dd04dc68472517f047cf56e5163a7489be67323b0a60227305f model-part-00030.safetensors
35
+ 1342ac3f0ca9fa879752f443b23bd66bdd8f3110b060c4f68af8dd95bd20fab1 model-part-00031.safetensors
36
+ 6523332cc7215bc22633aea44f4e93fcd817be9e803f656f0d63a38f81f31eb1 model-part-00032.safetensors
37
+ 9cc0041e444b07f3996f99c97384826d4edcdc3f013f727216b12b1aa6777e6b model-part-00033.safetensors
38
+ b34351eaa9094fd0332f711a9fdb6347f59521ac0490b39895ae9c670282c80f model-part-00034.safetensors
39
+ 5df0115f977249061ca2987a15ec156f202f1201423aad226a4b00b173764c82 model-part-00035.safetensors
40
+ 5e2980bbea27d20391b7906f7ae727d1dad0151bdd8d8dc8e1980e3c1aa2ef40 model-part-00036.safetensors
41
+ 922ae35668e1aa57979e3975c3765c00da0bd6800f4355271d2016a73645aa3c model-part-00037.safetensors
42
+ e103c0075773390f39e8c3da9ef25d2fb3dd1edfa98a0d8575a76d86161c7ecb model-part-00038.safetensors
43
+ 1b47db865dc93bd22a0e99442585e6ea838016ca0362b59b7469f5b341438982 model-part-00039.safetensors
44
+ 41420784201c4e8fadf73fdc73ffdd4b21f741c7fc646ee25587676f0322017d model-part-00040.safetensors
45
+ edf39ed483f2b292f8b73b5aa1638a866a75643dd79dbdbf7d72a4b602257754 model-part-00041.safetensors
46
+ 0ea4285726fefe0936efff54046a5664554f71a78e7a462e1934ac86ed248e65 model-part-00042.safetensors
47
+ f9fd7505a4037f6612757c02ef8301ddfd9052c16d949c8e8f171dc374b8934f model-part-00043.safetensors
48
+ ffb31bc86ad819e2ee4b26cd7db8a8efac8563387a0ec5806337455a902ae8b4 model-part-00044.safetensors
49
+ 334f235e8233f1dfbeb7d33d4818b02445d73ad846c71b11c36488d81b1cc2b0 model-part-00045.safetensors
50
+ f89008c3de1527f97b86cb820b48027520cb1a9ee69efbe135a1c3366916b4c3 model-part-00046.safetensors
51
+ 944dffd984d7686aab8ef6f47e064d523ac2c11bdcbc1cb37885fd35a755de39 model-part-00047.safetensors
52
+ 6922b2a5768d04a2cf13e16588d3b3e349cd718ba5262b585197a3efa78a81df model-part-00048.safetensors
53
+ 15abe430b055aaafed8199414edb0e4524db8fd88300b89bf921403e2e0694e0 model-part-00049.safetensors
54
+ 1162f34b23f0fc7568d71e8492fe058cf15aaed495a35844b79a4578f8d11d46 model-part-00050.safetensors
55
+ 6236fa959f220e1dea3f4e0a498cc3eeddc0e714f6d684a3b0a96ee5b6a9b1c3 model-part-00051.safetensors
56
+ d828088d8c7985321b1667c42540b2533a5910a2fe3ca389a4f93dc37e897acc model-part-00052.safetensors
57
+ 015fac1d375da28687456ddb60f2cac4da880c736d5cf47dcec7d7f45fce356a model-part-00053.safetensors
58
+ 6c203693250b9fae7f95b161152f752a9f606f985a044de47480b7d14e32374e model-part-00054.safetensors
59
+ de4086d48817477d6aa434003f426d1f3cf3725cc0e7e57921e6036d698348c8 model.safetensors.index.json
60
+ 27225450ac9c6529872ee1924fcb0962ff5634834f817040f444118116f4e516 preprocessor_config.json
61
+ 0997f410c57a1f4e53b09e4be8f4a172d90edd9564368fb0847030937229b9f3 tokenizer.json
62
+ b11349aafa7cdc6a320767cf7ceb29ed82f7eda5d65e8e0819e76f0ce947bf27 tokenizer_config.json
63
+ 7768af27c1fafa9cc9011c1dc20067e03f8915e03b63504550e11d5066986d13 video_preprocessor_config.json
64
+ ce99b4cb2983d118806ce0a8b777a35b093e2000a503ebde25853284c9dfa003 vocab.json
671.1/adapter_config.json ADDED
@@ -0,0 +1,61 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "peft_type": "LORA",
3
+ "task_type": "CAUSAL_LM",
4
+ "r": 4,
5
+ "lora_alpha": 4,
6
+ "use_rslora": false,
7
+ "lora_dropout": 0.0,
8
+ "bias": "none",
9
+ "fan_in_fan_out": false,
10
+ "use_dora": false,
11
+ "target_modules": [
12
+ "model.language_model.layers.40.linear_attn.out_proj",
13
+ "model.language_model.layers.40.mlp.down_proj",
14
+ "model.language_model.layers.41.linear_attn.out_proj",
15
+ "model.language_model.layers.41.mlp.down_proj",
16
+ "model.language_model.layers.42.linear_attn.out_proj",
17
+ "model.language_model.layers.42.mlp.down_proj",
18
+ "model.language_model.layers.43.mlp.down_proj",
19
+ "model.language_model.layers.43.self_attn.o_proj",
20
+ "model.language_model.layers.44.linear_attn.out_proj",
21
+ "model.language_model.layers.44.mlp.down_proj",
22
+ "model.language_model.layers.45.linear_attn.out_proj",
23
+ "model.language_model.layers.45.mlp.down_proj",
24
+ "model.language_model.layers.46.linear_attn.out_proj",
25
+ "model.language_model.layers.46.mlp.down_proj",
26
+ "model.language_model.layers.47.mlp.down_proj",
27
+ "model.language_model.layers.47.self_attn.o_proj",
28
+ "model.language_model.layers.48.linear_attn.out_proj",
29
+ "model.language_model.layers.48.mlp.down_proj",
30
+ "model.language_model.layers.49.linear_attn.out_proj",
31
+ "model.language_model.layers.49.mlp.down_proj",
32
+ "model.language_model.layers.50.linear_attn.out_proj",
33
+ "model.language_model.layers.50.mlp.down_proj",
34
+ "model.language_model.layers.51.mlp.down_proj",
35
+ "model.language_model.layers.51.self_attn.o_proj",
36
+ "model.language_model.layers.52.linear_attn.out_proj",
37
+ "model.language_model.layers.52.mlp.down_proj",
38
+ "model.language_model.layers.53.linear_attn.out_proj",
39
+ "model.language_model.layers.53.mlp.down_proj",
40
+ "model.language_model.layers.54.linear_attn.out_proj",
41
+ "model.language_model.layers.54.mlp.down_proj",
42
+ "model.language_model.layers.55.mlp.down_proj",
43
+ "model.language_model.layers.55.self_attn.o_proj",
44
+ "model.language_model.layers.56.linear_attn.out_proj",
45
+ "model.language_model.layers.56.mlp.down_proj",
46
+ "model.language_model.layers.57.linear_attn.out_proj",
47
+ "model.language_model.layers.57.mlp.down_proj",
48
+ "model.language_model.layers.58.linear_attn.out_proj",
49
+ "model.language_model.layers.58.mlp.down_proj",
50
+ "model.language_model.layers.59.mlp.down_proj",
51
+ "model.language_model.layers.59.self_attn.o_proj",
52
+ "model.language_model.layers.60.linear_attn.out_proj",
53
+ "model.language_model.layers.60.mlp.down_proj",
54
+ "model.language_model.layers.61.linear_attn.out_proj",
55
+ "model.language_model.layers.61.mlp.down_proj",
56
+ "model.language_model.layers.62.linear_attn.out_proj",
57
+ "model.language_model.layers.62.mlp.down_proj",
58
+ "model.language_model.layers.63.mlp.down_proj",
59
+ "model.language_model.layers.63.self_attn.o_proj"
60
+ ]
61
+ }
671.1/adapter_model.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:8013b9462c55739a835e0917429f729adcbe3dc93e62bf25b4a38ce99721dbc3
3
+ size 12990296
merge_lora.py CHANGED
@@ -22,6 +22,14 @@ THE ARITHMETIC, exactly (so that the same adapter gives the same bytes everywher
22
  BF16-rounded weights, round_bf16(master + update), with a straight-through estimator. Tensors that are not
23
  targets stay as in SRC (FP32 masters) in this mode too.
24
 
 
 
 
 
 
 
 
 
25
  ADAPTER
26
  ADAPTER/adapter_config.json "peft_type": "LORA"; r, lora_alpha, use_rslora are read. Refused: use_dora, fan_in_fan_out,
27
  rank_pattern / alpha_pattern, bias other than "none", modules_to_save, lora_bias.
@@ -30,7 +38,7 @@ ADAPTER
30
  FP32 or BF16; <MODULE>.weight must be a matrix [out, in] in the masters folder.
31
  The draft head (a separate file) cannot be a target.
32
 
33
- usage: merge_lora.py SRC ADAPTER_DIR DST [--round-bf16] [--bf16 DIR] [--fp8 DIR] [--mtp FILE | --no-mtp]
34
  [--check --sums FILE] [--sums-bf16 FILE] [--sums-fp8 FILE]
35
  [--workers 8] [--threads 4] [--exact-rounding]
36
 
@@ -119,29 +127,41 @@ def read_adapter(folder):
119
  return out, scaling, record
120
 
121
 
122
- def merged(weight, a, b, scaling, round_bf16=False, exact=False):
123
- """W' of the module text (W'' with ROUND_BF16); row blocks keep the double-precision work small.
124
  Returns (the merged FP32 matrix, the squared Frobenius size of the update)."""
125
  rows, cols = weight.shape
126
  result = torch.empty_like(weight)
127
  a64 = a.double()
 
 
128
  step = max(1, ROWS_AT_A_TIME // cols)
129
  change = 0.0
130
  for start in range(0, rows, step):
131
- b64 = b[start:start + step].double()
132
- acc = torch.zeros(b64.shape[0], cols, dtype=torch.float64)
133
- for k in range(a64.shape[0]):
134
- product = b64[:, k:k + 1] * a64[k:k + 1, :]
135
- acc = acc + product
136
- delta = acc * scaling
137
- change += float((delta * delta).sum())
138
- block = (weight[start:start + step].double() + delta).float()
 
 
 
 
 
 
 
 
 
 
139
  result[start:start + step] = c.to_bf16(block, exact).float() if round_bf16 else block
140
  return result, change
141
 
142
 
143
  def merge_shard(job):
144
- shard, folder, partial, adapter, scaling, round_bf16, exact = job
145
  targets = [n for n in folder.names_in(shard) if n in adapter]
146
  if not targets:
147
  shutil.copyfile(os.path.join(folder.path, shard), os.path.join(partial, shard))
@@ -151,7 +171,7 @@ def merge_shard(job):
151
  x = folder.read(name)
152
  if name in adapter:
153
  a, b = adapter[name]
154
- y, change = merged(x, a, b, scaling, round_bf16, exact)
155
  c.finite(name + " after the merge", y)
156
  size = float(x.double().pow(2).sum())
157
  notes.append((name, math.sqrt(change / size) if size else float("nan"),
@@ -169,6 +189,8 @@ def main():
169
  parser.add_argument("output")
170
  parser.add_argument("--round-bf16", action="store_true",
171
  help="round each merged matrix to BF16 and store it as FP32 (for adapters trained against BF16-rounded weights)")
 
 
172
  parser.add_argument("--bf16", metavar="DIR")
173
  parser.add_argument("--fp8", metavar="DIR")
174
  parser.add_argument("--mtp", metavar="FILE")
@@ -188,7 +210,8 @@ def main():
188
  torch.set_grad_enabled(False)
189
  torch.set_num_threads(args.threads)
190
  mode = "round-bf16" if args.round_bf16 else "fp32"
191
- c.say("merge_lora:", c.versions(), "| mode", mode)
 
192
  if not args.exact_rounding:
193
  c.self_test()
194
  folder, manifest = c.open_masters(args.masters)
@@ -204,8 +227,8 @@ def main():
204
  c.fail("%s is %s but the adapter's update is %s" % (name, folder.shape(name), [b.shape[0], a.shape[1]]))
205
  c.say("adapter: %d target matrices, r = %d, scaling = %r" % (len(adapter), record["r"], scaling))
206
  out, partial = c.start_output(args.output)
207
- results = c.run_shards([(shard, folder, partial, adapter, scaling, args.round_bf16, args.exact_rounding)
208
- for shard in folder.shards()], merge_shard, args.workers)
209
  digests = {shard: digest for shard, digest, _ in results}
210
  for _, _, notes in results:
211
  for name, relative, changed in notes:
@@ -216,13 +239,14 @@ def main():
216
  for name in (c.MTP_FILE, c.MTP_NOTE):
217
  if os.path.isfile(os.path.join(args.masters, name)):
218
  shutil.copyfile(os.path.join(args.masters, name), os.path.join(partial, name))
219
- record = dict(record, mode=mode)
220
  earlier = list(manifest.get("lora_merges", []))
221
  manifest = dict(manifest, lora_merges=earlier + [record])
222
  with open(os.path.join(partial, c.MANIFEST), "w") as f:
223
  f.write(json.dumps(manifest, indent=1) + c.NL)
224
- note = {"mode": mode,
225
- "meaning": "merged = fp32(master + scaling * B A), the sum in double precision in a fixed order" + (
 
226
  ", then rounded to BF16 (nearest even) and stored as FP32" if args.round_bf16 else ""),
227
  "adapter_model_sha256": record["adapter_model_sha256"], "adapter_config_sha256": record["adapter_config_sha256"],
228
  "scaling": scaling, "r": record["r"], "lora_alpha": record["lora_alpha"], "use_rslora": record["use_rslora"],
@@ -231,7 +255,7 @@ def main():
231
  with open(os.path.join(partial, MERGE_NOTE), "w") as f:
232
  f.write(json.dumps(note, indent=1) + c.NL)
233
  c.finish(partial, out, digests, sums, args.workers)
234
- c.say("MERGE DONE %s: %d matrices merged, mode %s" % (out, len(adapter), mode))
235
  here = os.path.dirname(os.path.abspath(__file__))
236
  for script, target, check in (("masters_to_bf16.py", args.bf16, args.sums_bf16), ("to_fp8.py", args.fp8, args.sums_fp8)):
237
  if not target:
 
22
  BF16-rounded weights, round_bf16(master + update), with a straight-through estimator. Tensors that are not
23
  targets stay as in SRC (FP32 masters) in this mode too.
24
 
25
+ --fp32-sum: the update is summed in FP32 instead of double, in the same fixed order:
26
+ acc[i, j] = B[i, 0] * A[0, j], then acc[i, j] + B[i, k] * A[k, j] for k = 1 .. r-1
27
+ (each product one FP32 multiplication, each addition one FP32 addition)
28
+ W'[i, j] = fp32( W[i, j] + fp32(s) * acc[i, j] ) (one FP32 multiplication, one FP32 addition)
29
+ This is the arithmetic an adapter may have been trained and evaluated with (671.1/ was): with it, that adapter
30
+ merges to the evaluated weights bit for bit. The double sum is the more exact of the two; for 671.1/ the two
31
+ differ in 206 of 2.9 billion merged elements (rounding ties). With s = 1 the multiplication changes nothing.
32
+
33
  ADAPTER
34
  ADAPTER/adapter_config.json "peft_type": "LORA"; r, lora_alpha, use_rslora are read. Refused: use_dora, fan_in_fan_out,
35
  rank_pattern / alpha_pattern, bias other than "none", modules_to_save, lora_bias.
 
38
  FP32 or BF16; <MODULE>.weight must be a matrix [out, in] in the masters folder.
39
  The draft head (a separate file) cannot be a target.
40
 
41
+ usage: merge_lora.py SRC ADAPTER_DIR DST [--round-bf16] [--fp32-sum] [--bf16 DIR] [--fp8 DIR] [--mtp FILE | --no-mtp]
42
  [--check --sums FILE] [--sums-bf16 FILE] [--sums-fp8 FILE]
43
  [--workers 8] [--threads 4] [--exact-rounding]
44
 
 
127
  return out, scaling, record
128
 
129
 
130
+ def merged(weight, a, b, scaling, round_bf16=False, exact=False, fp32_sum=False):
131
+ """W' of the module text (W'' with ROUND_BF16; the FP32 sum with FP32_SUM); row blocks keep the work small.
132
  Returns (the merged FP32 matrix, the squared Frobenius size of the update)."""
133
  rows, cols = weight.shape
134
  result = torch.empty_like(weight)
135
  a64 = a.double()
136
+ a32 = a.float()
137
+ s32 = torch.tensor(scaling, dtype=torch.float32)
138
  step = max(1, ROWS_AT_A_TIME // cols)
139
  change = 0.0
140
  for start in range(0, rows, step):
141
+ if fp32_sum:
142
+ b32 = b[start:start + step].float()
143
+ acc = b32[:, 0:1] * a32[0:1, :]
144
+ for k in range(1, a32.shape[0]):
145
+ product = b32[:, k:k + 1] * a32[k:k + 1, :]
146
+ acc = acc + product
147
+ delta = acc * s32
148
+ change += float(delta.double().pow(2).sum())
149
+ block = weight[start:start + step] + delta
150
+ else:
151
+ b64 = b[start:start + step].double()
152
+ acc = torch.zeros(b64.shape[0], cols, dtype=torch.float64)
153
+ for k in range(a64.shape[0]):
154
+ product = b64[:, k:k + 1] * a64[k:k + 1, :]
155
+ acc = acc + product
156
+ delta = acc * scaling
157
+ change += float((delta * delta).sum())
158
+ block = (weight[start:start + step].double() + delta).float()
159
  result[start:start + step] = c.to_bf16(block, exact).float() if round_bf16 else block
160
  return result, change
161
 
162
 
163
  def merge_shard(job):
164
+ shard, folder, partial, adapter, scaling, round_bf16, exact, fp32_sum = job
165
  targets = [n for n in folder.names_in(shard) if n in adapter]
166
  if not targets:
167
  shutil.copyfile(os.path.join(folder.path, shard), os.path.join(partial, shard))
 
171
  x = folder.read(name)
172
  if name in adapter:
173
  a, b = adapter[name]
174
+ y, change = merged(x, a, b, scaling, round_bf16, exact, fp32_sum)
175
  c.finite(name + " after the merge", y)
176
  size = float(x.double().pow(2).sum())
177
  notes.append((name, math.sqrt(change / size) if size else float("nan"),
 
189
  parser.add_argument("output")
190
  parser.add_argument("--round-bf16", action="store_true",
191
  help="round each merged matrix to BF16 and store it as FP32 (for adapters trained against BF16-rounded weights)")
192
+ parser.add_argument("--fp32-sum", action="store_true",
193
+ help="sum the update in FP32 in the fixed order instead of in double (see the module text)")
194
  parser.add_argument("--bf16", metavar="DIR")
195
  parser.add_argument("--fp8", metavar="DIR")
196
  parser.add_argument("--mtp", metavar="FILE")
 
210
  torch.set_grad_enabled(False)
211
  torch.set_num_threads(args.threads)
212
  mode = "round-bf16" if args.round_bf16 else "fp32"
213
+ summed = "fp32" if args.fp32_sum else "double"
214
+ c.say("merge_lora:", c.versions(), "| mode", mode, "| sum", summed)
215
  if not args.exact_rounding:
216
  c.self_test()
217
  folder, manifest = c.open_masters(args.masters)
 
227
  c.fail("%s is %s but the adapter's update is %s" % (name, folder.shape(name), [b.shape[0], a.shape[1]]))
228
  c.say("adapter: %d target matrices, r = %d, scaling = %r" % (len(adapter), record["r"], scaling))
229
  out, partial = c.start_output(args.output)
230
+ results = c.run_shards([(shard, folder, partial, adapter, scaling, args.round_bf16, args.exact_rounding,
231
+ args.fp32_sum) for shard in folder.shards()], merge_shard, args.workers)
232
  digests = {shard: digest for shard, digest, _ in results}
233
  for _, _, notes in results:
234
  for name, relative, changed in notes:
 
239
  for name in (c.MTP_FILE, c.MTP_NOTE):
240
  if os.path.isfile(os.path.join(args.masters, name)):
241
  shutil.copyfile(os.path.join(args.masters, name), os.path.join(partial, name))
242
+ record = dict(record, mode=mode, sum=summed)
243
  earlier = list(manifest.get("lora_merges", []))
244
  manifest = dict(manifest, lora_merges=earlier + [record])
245
  with open(os.path.join(partial, c.MANIFEST), "w") as f:
246
  f.write(json.dumps(manifest, indent=1) + c.NL)
247
+ note = {"mode": mode, "sum": summed,
248
+ "meaning": "merged = fp32(master + scaling * B A), the sum in %s in a fixed order" % (
249
+ "FP32" if args.fp32_sum else "double precision") + (
250
  ", then rounded to BF16 (nearest even) and stored as FP32" if args.round_bf16 else ""),
251
  "adapter_model_sha256": record["adapter_model_sha256"], "adapter_config_sha256": record["adapter_config_sha256"],
252
  "scaling": scaling, "r": record["r"], "lora_alpha": record["lora_alpha"], "use_rslora": record["use_rslora"],
 
255
  with open(os.path.join(partial, MERGE_NOTE), "w") as f:
256
  f.write(json.dumps(note, indent=1) + c.NL)
257
  c.finish(partial, out, digests, sums, args.workers)
258
+ c.say("MERGE DONE %s: %d matrices merged, mode %s, sum %s" % (out, len(adapter), mode, summed))
259
  here = os.path.dirname(os.path.abspath(__file__))
260
  for script, target, check in (("masters_to_bf16.py", args.bf16, args.sums_bf16), ("to_fp8.py", args.fp8, args.sums_fp8)):
261
  if not target: