Comments (4)
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.
Cool, thanks for looking into it.
from keras.
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.
@jjallaire Nice :)
from keras.
Related Issues (20)
- RuntimeError: invalid 'type' (environment) of argument HOT 8
- Conflict Arguments Between R and Python: Error in py_call_impl(callable, call_args$unnamed, call_args$named) HOT 20
- ValueError: Only input tensors may be passed as positional arguments HOT 5
- Release keras3 0.2.0
- Release keras 2.15.0
- Erreur dans UseMethod("compile") HOT 7
- Can't load the LSTM model pre-trained in Python to R HOT 1
- Difference between R and Python output HOT 7
- Segmentation models HOT 2
- Lack of methods text_tokenizer(), fit_text_tokenizer() and texts_to_sequences() HOT 5
- compile function does not work HOT 3
- keras layer dense problem HOT 2
- Whe I have tried to fit model I got a problem that I could not understand. Can you look at it?
- Release keras3 0.3.0
- Release keras3 1.0.0
- Support for keras-tcn HOT 1
- GPU is not detected in R, but appears in python. HOT 9
- Link doesn't work HOT 2
- Support Torch for R as backend in keras? HOT 1
- Release keras3 1.1.0
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 keras.