Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unexpected behaviour with Add() and Sub() #547

Open
ouwe-knutselaar opened this issue Jun 1, 2023 · 1 comment
Open

Unexpected behaviour with Add() and Sub() #547

ouwe-knutselaar opened this issue Jun 1, 2023 · 1 comment

Comments

@ouwe-knutselaar
Copy link

I was investigating the Sub and Add functions to learn Gorgonia but I saw some strange behaviour.

I've this line of code:
sub := gorgonia.Must(gorgonia.Add(output, cnn.Pred))

Like in the tutorials, the cnn.Pred is the predicted value in the fwd() function.
The cnn.Pred is part of the Neural Network struct:

type CNN struct {
	g      *ExprGraph
	w0, w1 *Node
	Pred   *Node
}

It is executed it with a:

tvm := gorgonia.NewTapeMachine(g)
tvm.RunAll()`

I get this as an output:

+-Node------------------------------------------------+  
|output  
|Value  
 R[1  2  3]  
+-Node------------------------------------------------+  
|Pred  
|Value  
 R[ 0.7940061219206868  0.41289226342453217   0.7509017364247419]  
+-Node------------------------------------------------+  
|Sub  
|Value  
 R[0.20599387807931324   1.5871077365754678    2.249098263575258]  
+-----------------------------------------------------+  

Looks oké, this is a normal substraction of output minus cnn.Pred

But If I turn the parameters around:
sub := gorgonia.Must(gorgonia.Add(cnn.Pred, output))

Then I get this:

 +-Node------------------------------------------------+  
|output  
|Value  
 R[1  2  3]  
+-Node------------------------------------------------+  
|Pred  
|Value  
 R[-0.5419284398457198  -1.2216007991578186   -2.502871782543021]  
+-Node------------------------------------------------+  
|Sub  
|Value  
 R[-0.5419284398457198  -1.2216007991578186   -2.502871782543021]  
+-----------------------------------------------------+ 

The value of cnn.Pred is altered by the order of the Sub function.
This means that a substract function alters also the value of the cnn.Pred if it is in the first position.
The value of output in not altered if it is in the first position.
I saw the same behaviour with the Add function

Can someone explain what is happening here?

@zenoda
Copy link

zenoda commented Sep 8, 2024

same issue.
Sub, Add, etc. all have the same problem. The value of the first node in the params will be altered after vm.RunAll().

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants