Created
April 27, 2023 03:44
-
-
Save eileen-code4fun/2a4db9c5980e3a9279bb99b09a97799a to your computer and use it in GitHub Desktop.
Autograd Incorrect add and mul in Golang
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func (v *Value) add(v1 *Value) *Value { | |
nv := newValue(v.data+v1.data, nil /* incorrect, should be []*Value{v, v1} */) | |
nv.backward = func() { | |
v.grad = /* incorrect, should be += */ nv.grad | |
v1.grad = /* incorrect, should be += */ nv.grad | |
} | |
return nv | |
} | |
func (v *Value) mul(v1 *Value) *Value { | |
nv := newValue(v.data*v1.data, nil /* incorrect, should be []*Value{v, v1} */) | |
nv.backward = func() { | |
v.grad = /* incorrect, should be += */ v1.data * nv.grad | |
v1.grad = /* incorrect, should be += */ v.data * nv.grad | |
} | |
return nv | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment