Giter VIP home page Giter VIP logo

Comments (4)

jjallaire avatar jjallaire commented on August 26, 2024

Good one! On the same instance type w/ GPU I get 55 seconds for R and 40 seconds for Python. I have one pretty good theory about what might be going on (it has to do with how we convert R matrices to NumPy arrays and if I'm correct it will be straightforward to resolve). More soon!

from keras.

szilard avatar szilard commented on August 26, 2024

Cool, thanks for looking into it.

from keras.

jjallaire avatar jjallaire commented on August 26, 2024

Thanks again for reporting this, fix is here: 1d6c9f2

The problem was caused by the fact that when R matrices and arrays are marshaled to Python we convert them to NumPy arrays that map directly to the R managed memory (i.e. no copy is made and NumPy just uses the already allocated R array/matrix). This implies that the NumPy array will be Fortran-ordered (since that's the default for R) rather than C-ordered (the default for NumPy).

In the case of Keras training, between shuffling, drawing batches, copying to the GPU, and 10 epochs there are a ton of accesses to the Fortran-ordered array which add up to a ~ 40% performance penalty for training this dataset.

This change ensures that we do a single re-ordering of arrays/matrices to C-column order before we pass them to Keras, which eliminates the penalty we were paying for the accesses to the Fortran-ordered array.

@bwlewis Do you think the reticulate behavior of preserving R Fortran-ordered array memory when marshaling to NumPy is an anti-pattern? Alternatively it could be that this particular scenario of hundreds of accesses + GPU copying is problematic but that for most cases it's a performance win. Let me know what you think.

from keras.

szilard avatar szilard commented on August 26, 2024

@jjallaire Nice :)

from keras.

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.