interplane.Get Omega
Read in your language

omega-mv

Omega: a language for verified programs, semantic identity and machine realization. Seed-born work and existing implementations have distinct provenance.

Brought by drakestapleton

branch main Branches Tags History

omega-mv / src / train / sgd_update.om

44 lines · 1466 bytes Raw Blame History
1note SPDX-License-Identifier: Apache-2.0
2note Scalar arguments and storage carry IEEE binary32 bits. Each multiply
3note and add or subtract is a separate operation, as specified by tg_sgd.h.
4om2
5
6export fn tg_sgd_mode learning ulong momentum ulong to long
7 note Finiteness is independent of FPCR. Ordered binary32 comparisons
8 note use the caller's flush-to-zero mode, including signed subnormals.
9 if or ge and learning 0x7fffffff 0x7f800000 ge and momentum 0x7fffffff 0x7f800000
10 ret -1
11 end
12 rate = bitcast f32 uint learning
13 weight = bitcast f32 uint momentum
14 zero = bitcast f32 uint 0
15 one = bitcast f32 uint 0x3f800000
16 if or le rate zero or lt weight zero ge weight one
17 ret -1
18 end
19 if eq weight zero
20 ret 0
21 end
22 ret 1
23end
24
25export fn tg_update_velocity velocity edit uint * gradient view uint * bits ulong to void
26requires eq len velocity len gradient
27 momentum = bitcast f32 uint bits
28 for i ulong len velocity
29 previous = bitcast f32 get velocity i
30 contribution = mul momentum previous
31 updated = add contribution bitcast f32 get gradient i
32 put velocity i bitcast uint updated
33 end
34end
35
36export fn tg_update_params params edit uint * direction view uint * bits ulong to void
37requires eq len params len direction
38 learning = bitcast f32 uint bits
39 for i ulong len params
40 value = bitcast f32 get params i
41 step = mul learning bitcast f32 get direction i
42 put params i bitcast uint sub value step
43 end
44end