aien-train
AIEN training programme: language-model history, GB10 constraints and the route to training on the project engine. Plans and runnable checks are distinguished.
Brought by drakestapleton
aien-train / native / ecosystem6 / affine.om
| 1 | note SPDX-License-Identifier: AGPL-3.0-only |
| 2 | note Bounded host FP32 consumer. Uses external pinned L720 add32/mul32 and M20 emcheck. |
| 3 | note Eight independent tensors X,W,b,T,Y,dX,dW,db in 16-cell slots. |
| 4 | note Values are IEEE binary32 bits in ulong carriers, not integer fixed-point values. |
| 5 | note AD/AS are trusted local descriptor and allocator snapshots, not wire records. |
| 6 | global AD ulong 192 |
| 7 | global AS ulong 64 |
| 8 | global AP ulong 128 |
| 9 | global AQ ulong 128 |
| 10 | global AL ulong 1 |
| 11 | |
| 12 | fn afcount t ulong to ulong |
| 13 | if or eq t 2 eq t 7 |
| 14 | ret 2 |
| 15 | end |
| 16 | if or eq t 3 eq t 4 |
| 17 | ret 4 |
| 18 | end |
| 19 | ret 6 |
| 20 | end |
| 21 | |
| 22 | fn afget t ulong i ulong to ulong |
| 23 | ret get AP add mul t 16 i |
| 24 | end |
| 25 | |
| 26 | fn afq t ulong i ulong to ulong |
| 27 | ret get AQ add mul t 16 i |
| 28 | end |
| 29 | |
| 30 | fn afput t ulong i ulong v ulong to void |
| 31 | put AQ add mul t 16 i v |
| 32 | end |
| 33 | |
| 34 | fn affinite x ulong to bool |
| 35 | if gt x 4294967295 |
| 36 | ret false |
| 37 | end |
| 38 | ret lt and x 2147483647 2139095040 |
| 39 | end |
| 40 | |
| 41 | fn afvalidate to int |
| 42 | for t ulong 8 |
| 43 | for i ulong 24 |
| 44 | put ED i get AD add mul t 24 i |
| 45 | end |
| 46 | for i ulong 8 |
| 47 | put ES i get AS add mul t 8 i |
| 48 | end |
| 49 | status = emcheck |
| 50 | if ne status 0 |
| 51 | ret status |
| 52 | end |
| 53 | note Contiguous owned local carriers only. This does not claim strided numeric kernels. |
| 54 | if or ne get ED 1 1 ne get ED 4 0 |
| 55 | ret -20 |
| 56 | end |
| 57 | if or ne get ED 5 add t 1 ne get ES 5 afcount t |
| 58 | ret -20 |
| 59 | end |
| 60 | rank = ulong 2 |
| 61 | rows = ulong 2 |
| 62 | cols = ulong 3 |
| 63 | if or eq t 1 eq t 6 |
| 64 | rows = 3 |
| 65 | cols = 2 |
| 66 | end |
| 67 | if or eq t 3 eq t 4 |
| 68 | cols = 2 |
| 69 | end |
| 70 | if or eq t 2 eq t 7 |
| 71 | rank = 1 |
| 72 | cols = 1 |
| 73 | end |
| 74 | if or ne get ED 2 rank ne get ED 8 rows |
| 75 | ret -21 |
| 76 | end |
| 77 | if ne get ED 16 cols |
| 78 | ret -21 |
| 79 | end |
| 80 | if eq rank 2 |
| 81 | if or ne get ED 9 cols ne get ED 17 1 |
| 82 | ret -21 |
| 83 | end |
| 84 | end |
| 85 | end |
| 86 | ret 0 |
| 87 | end |
| 88 | |
| 89 | fn afstep lr ulong to int |
| 90 | status = afvalidate |
| 91 | if ne status 0 |
| 92 | ret status |
| 93 | end |
| 94 | if not affinite lr |
| 95 | ret -22 |
| 96 | end |
| 97 | if ne and lr 2147483648 0 |
| 98 | ret -22 |
| 99 | end |
| 100 | for t ulong 4 |
| 101 | for i ulong afcount t |
| 102 | if not affinite afget t i |
| 103 | ret -22 |
| 104 | end |
| 105 | end |
| 106 | end |
| 107 | for i ulong 128 |
| 108 | put AQ i 0 |
| 109 | end |
| 110 | loss = ulong 0 |
| 111 | for row ulong 2 |
| 112 | for col ulong 2 |
| 113 | v = afget 2 col |
| 114 | for k ulong 3 |
| 115 | x = afget 0 add mul row 3 k |
| 116 | w = afget 1 add mul k 2 col |
| 117 | v = add32 v mul32 x w |
| 118 | end |
| 119 | pos = add mul row 2 col |
| 120 | afput 4 pos v |
| 121 | r = add32 v xor afget 3 pos 2147483648 |
| 122 | loss = add32 loss mul32 r r |
| 123 | g = mul32 1073741824 r |
| 124 | afput 7 col add32 afq 7 col g |
| 125 | for k ulong 3 |
| 126 | xp = add mul row 3 k |
| 127 | wp = add mul k 2 col |
| 128 | gx = mul32 g afget 1 wp |
| 129 | gw = mul32 g afget 0 xp |
| 130 | afput 5 xp add32 afq 5 xp gx |
| 131 | afput 6 wp add32 afq 6 wp gw |
| 132 | end |
| 133 | end |
| 134 | end |
| 135 | note Commit only after all finite-result checks; rejected steps preserve AP and AL. |
| 136 | for i ulong 6 |
| 137 | delta = mul32 lr afq 6 i |
| 138 | afput 1 i add32 afget 1 i xor delta 2147483648 |
| 139 | end |
| 140 | for i ulong 2 |
| 141 | delta = mul32 lr afq 7 i |
| 142 | afput 2 i add32 afget 2 i xor delta 2147483648 |
| 143 | end |
| 144 | if not affinite loss |
| 145 | ret -23 |
| 146 | end |
| 147 | for t ulong 8 |
| 148 | if and ne t 0 ne t 3 |
| 149 | for i ulong afcount t |
| 150 | if not affinite afq t i |
| 151 | ret -23 |
| 152 | end |
| 153 | end |
| 154 | end |
| 155 | end |
| 156 | for t ulong 8 |
| 157 | if and ne t 0 ne t 3 |
| 158 | for i ulong afcount t |
| 159 | put AP add mul t 16 i afq t i |
| 160 | end |
| 161 | end |
| 162 | end |
| 163 | put AL 0 loss |
| 164 | ret 0 |
| 165 | end |