Comments (6)
@dcslin can you help check this issue?
from singa.
hi @Shashankwer I am looking into this.
from singa.
Hi @Shashankwer , Understand that the error code is not clear enough, but I could not replicate the error without further details(inputs, outputs), would you like to refer to following working example transformed from your code to help you debugging?
from singa import autograd
from singa import module
from singa import opt
from singa import tensor
class MLP():
def __init__(self):
self.linear1 = autograd.Linear(3,4)
self.linear2 = autograd.Linear(4,3)
def forward(self,x):
y = self.linear1(x)
return self.linear2(y)
def loss(self, out, ty):
return autograd.softmax_cross_entropy(out, ty)
def optim(self, loss):
self.optimizer.backward_and_update(loss)
def set_optimizer(self, optimizer):
self.optimizer = optimizer
if __name__ == '__main__':
x=tensor.Tensor((3,3)).gaussian(1,1)
y=tensor.Tensor((3,3)).gaussian(1,1)
autograd.training = True
m = MLP()
sgd = opt.SGD()
m.set_optimizer(sgd)
out = m.forward(x)
loss = m.loss(out, y)
m.optim(loss)
print(loss)
from singa.
Hi,
Issue reported here is for handling the error on the python API side and is particularly noticed for autograd.backward function.
Consider the below example
from singa import autograd
from singa import module
from singa import opt
from singa import tensor
from singa import device
class MLP():
def __init__(self):
self.linear1 = autograd.Linear(3, 4)
self.linear2 = autograd.Linear(4, 3)
def forward(self,x):
y = self.linear1(x)
return self.linear2(y)
def loss(self, out, ty):
return autograd.softmax_cross_entropy(out, ty)
def optim(self, loss):
self.optimizer.backward_and_update(loss)
def set_optimizer(self, optimizer):
self.optimizer = optimizer
def train(model, x, t, dev=device.get_default_device(), epochs=100):
for i in range(epochs):
y = model.forward(x)
loss = autograd.mse_loss(y, t)
print("loss: ", loss)
sgd = opt.SGD()
for p, gp in autograd.backward(loss):
sgd.update(p, gp)
sgd.step()
if __name__ == '__main__':
x=tensor.Tensor((3,3)).gaussian(1,1)
y=tensor.Tensor((3,3)).gaussian(1,1)
autograd.training = True
m = MLP()
sgd = opt.SGD()
m.set_optimizer(sgd)
out = m.forward(x)
loss = m.loss(out, y)
m.optim(loss)
print(loss)
train(m,x,y)
The above code will execute without any issues. However if we change the dimension of output tensor such that it does not match the model constructed, the error is noticed. For example
from singa import autograd
from singa import module
from singa import opt
from singa import tensor
from singa import device
class MLP():
def __init__(self):
self.linear1 = autograd.Linear(3, 4)
self.linear2 = autograd.Linear(4, 3)
def forward(self,x):
y = self.linear1(x)
return self.linear2(y)
def loss(self, out, ty):
return autograd.softmax_cross_entropy(out, ty)
def optim(self, loss):
self.optimizer.backward_and_update(loss)
def set_optimizer(self, optimizer):
self.optimizer = optimizer
def train(model, x, t, dev=device.get_default_device(), epochs=100):
for i in range(epochs):
y = model.forward(x)
loss = autograd.mse_loss(y, t)
print("loss: ", loss)
sgd = opt.SGD()
for p, gp in autograd.backward(loss):
sgd.update(p, gp)
sgd.step()
if __name__ == '__main__':
x=tensor.Tensor((3,3)).gaussian(1,1)
y=tensor.Tensor((3,4)).gaussian(1,1)
autograd.training = True
m = MLP()
sgd = opt.SGD()
m.set_optimizer(sgd)
out = m.forward(x)
loss = m.loss(out, y)
m.optim(loss)
print(loss)
train(m,x,y)
from singa.
Yes We should add input shape check all necessary operators in autograd.py
for example, we should raise exception if input shapes are different:
autograd.softmax_cross_entropy(tx, ty)
autograd.mse_loss(tx, ty)
autograd.equal(tx,ty)
from singa.
addressed in pr #751
from singa.
Related Issues (20)
- Switch between CPU and GPU devices for cnn example HOT 4
- Save the downloaded datasets to local directory HOT 2
- Add running scripts for cnn and cifar_distributed_cnn examples HOT 4
- Intermediate information printing HOT 3
- Adding arguments for weight decay and momentum HOT 2
- Increase max epoch for cnn example for better convergence HOT 2
- Update CMakeLists.txt for release 4.0.0 HOT 1
- Check Apache license header for release 4.0.0
- OpenCL Compilation Fails
- Upload Release 4.0.0 Package to SVN HOT 1
- Update the NOTICE file for images HOT 1
- gitignore and gitmodules should be removed from the release tar file HOT 2
- Create a new branch dev-postgresql HOT 2
- Create the SumError New Loss Function HOT 1
- Dynamic Creation of Models HOT 2
- Need to return the gradients from optimizer HOT 4
- Maximum recursion depth exceeded in comparison for string HOT 1
- can sparse all-reduce keep efficiency with large number of gpu workers?
- Python 3.11, Model, ImportError HOT 9
- Update documentation for distributed training HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from singa.