Code Monkey home page Code Monkey logo

Comments (7)

tqchen avatar tqchen commented on May 18, 2024

You can not direct read scalar from GPU tensor. Currently, one thing you can possibly do is store the result to a Tensor2D and copy to CPU to read it. There was a performance reason why we did not support summing over all the elements in GPU.

If you are implementing neural nets, usually copy to CPU to evaluate the statistics won't harm the overall performance, because this was a cheap operation

from mshadow.

Kublai-Jing avatar Kublai-Jing commented on May 18, 2024

Hi tq,
Actually I am only going to do this on CPU, so do you suggest I should just do thing like this?

for(unsigned int i = 0 ; i < outgrad.shape[1] ; i ++){
for(unsigned int j = 0 ; j < outgrad.shape[2] ; j ++){
err += outgrad[i][j] * outgrad[i][j];
}
}

Thanks a lot !

from mshadow.

tqchen avatar tqchen commented on May 18, 2024

If it was a 2D tensor, remember C++ index starts from 0, so it should be shape[1] and shape[0].. If you use master version of mshadow.

for(unsigned int i = 0 ; i < outgrad.size(0) ; i ++){
    for(unsigned int j = 0 ; j < outgrad.size(1) ; j ++){
        err += outgrad[i][j] * outgrad[i][j];
     }
}

The shape convention in master was reversed from numpy and a bit weird. There is going to be a major refactor to solve the problem

from mshadow.

Kublai-Jing avatar Kublai-Jing commented on May 18, 2024

so shape[0] is the number of columns in a 2D tensor
and shape[1] is the number of rows, Is this correct ? What if we have a 3D Tensor ?
I am kind of confused by this phrase in the tutorial:
"shape_[0] gives the lowest dimension, shape_[1] gives the second dimension, etc. This is different from numpy."

what does it mean by "the lowest dimension"

Thanks!

from mshadow.

tqchen avatar tqchen commented on May 18, 2024

Sorry about the confusion, this is a deprecated convention that will be changed. For temporal solution, you can use tensor.size(i), updated in master, which follows the same convention as numpy. I have updated the example

from mshadow.

Kublai-Jing avatar Kublai-Jing commented on May 18, 2024

Got it.

Thanks !

from mshadow.

WallSky avatar WallSky commented on May 18, 2024

you are welcome

from mshadow.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.