fix the two actual bugs

This commit is contained in:
2026-09-06 22:16:30 -04:00
parent 0513d2fcc9
commit 2b57998de6
4 changed files with 19 additions and 15 deletions
+6 -6
View File
@@ -8,12 +8,12 @@ To use: `go run cmd/main.go input.txt`
Differences between the Go and the Python, as well as notes more generally:
* The GPT is implemented as a package and, separately, as a command-line wrapper that calls it, just to keep the algorithm separate from the invocation details.
* The Value class is more type-safe in go, using values everywhere as opposed to mingling floats and values in the localgrad tuple.
* The Value struct has actual tests confirming the backward propagation logic.
* When writing the Value struct and its methods, I accidentally swapped the order of the values in the `localGrads` slice in `Mul` and tore my hair out trying to figure out where the bug was. When I broke down and asked copilot to "compare these two implementations and tell me how they differ," it managed to find the error -- but also reported three non-existent differences and told me that `slices.Backward()` doesn't exist.
* Initial pass translating the linear algebra functions has me worried that all those value structs aren't going to be very fast...
* Had to implement weighted random choice. <https://cybernetist.com/2019/01/24/random-weighted-draws-in-go/> made that relatively straightforward; it's a neat algorithm.
- The GPT is implemented as a package and, separately, as a command-line wrapper that calls it, just to keep the algorithm separate from the invocation details.
- The Value class is more type-safe in go, using values everywhere as opposed to mingling floats and values in the localgrad tuple.
- The Value struct has actual tests confirming the backward propagation logic.
- When writing the Value struct and its methods, I accidentally swapped the order of the values in the `localGrads` slice in `Mul` and tore my hair out trying to figure out where the bug was. When I broke down and asked copilot to "compare these two implementations and tell me how they differ," it managed to find the error -- but also reported three non-existent differences and told me that `slices.Backward()` doesn't exist.
- Initial pass translating the linear algebra functions has me worried that all those value structs aren't going to be very fast...
- Had to implement weighted random choice. <https://cybernetist.com/2019/01/24/random-weighted-draws-in-go/> made that relatively straightforward; it's a neat algorithm.
First proper run: