Nodejs vs python performance differences?

1,921 views
Skip to first unread message

Jeremy Chone

unread,
May 26, 2018, 1:14:20 AM5/26/18
to TensorFlow.js Discussion
A novice question.

Since both the nodejs and python API are binding to the tensorflow C engine, is there any performance differences between the two?

I understand that given the younger JS implementation, there might be at the beginning, but ultimately, does the JS/Node/V8 way to bind to the C engine has any performance advantages or disadvantages (for CPU or GPU mode)?


Jeremy

Nikos

unread,
May 26, 2018, 10:13:44 AM5/26/18
to TensorFlow.js Discussion
great question

Nikhil Thorat

unread,
May 29, 2018, 8:12:44 PM5/29/18
to nkats...@gmail.com, TensorFlow.js Discussion
With some preliminary tests for *inference* we're not seeing any major performance degradations.

We're working on checkpointing / training, which we'll have better benchmarks for, though we don't expect to see major performance decreases as the bottleneck will be in the linear algebra / writing to disk and not in the interpreter, for most tasks.

--
You received this message because you are subscribed to the Google Groups "TensorFlow.js Discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to tfjs+uns...@tensorflow.org.
Visit this group at https://groups.google.com/a/tensorflow.org/group/tfjs/.
To view this discussion on the web visit https://groups.google.com/a/tensorflow.org/d/msgid/tfjs/24c7caef-c85d-4f6d-9511-1433f1993473%40tensorflow.org.

Jeremy Chone

unread,
May 29, 2018, 8:44:29 PM5/29/18
to nsth...@google.com, nkats...@gmail.com, tf...@tensorflow.org
Thank you very much for the answer. tfjs/tfjs-node is very promising and a significant boost in productivity when using TypeScript vs Python. 

I am assuming the embedded "NumPy functionalities" (e.g., tf.tensor2d...) are pure JS and that might be a difference with the Python C NumPy. Is that correct?

I have done some preliminary testing with the standard mnist example, and strangely I see a 3x faster on tfjs-node than python (2s for each 100 steps in tfjs-node v.s. 7second for python), but I might have done something wrong (feels too good to be true).

Jeremy, 

---
Jeremy Chone
CEO & Principal Architect
http://britesnow.com/
(415) 699 9912
Dev Team As a Service 



You received this message because you are subscribed to a topic in the Google Groups "TensorFlow.js Discussion" group.
To unsubscribe from this topic, visit https://groups.google.com/a/tensorflow.org/d/topic/tfjs/4qIbyhrDZC0/unsubscribe.
To unsubscribe from this group and all its topics, send an email to tfjs+uns...@tensorflow.org.

Nikhil Thorat

unread,
May 29, 2018, 8:58:57 PM5/29/18
to jeremy...@gmail.com, nkats...@gmail.com, TensorFlow.js Discussion
For small models (MNIST), linear algebra is not the bottleneck, the interpreter is. JavaScript is much much faster than Python.

Make some predictions with the trained model in both environments if you want to do a sanity check that the model actually trained!

Loreto Parisi

unread,
May 30, 2018, 2:51:11 AM5/30/18
to Nikhil Thorat, jeremy...@gmail.com, nkats...@gmail.com, TensorFlow.js Discussion
I recently came across to this promising benchmark from a tfjs user on twitter...
Image


From: 'Nikhil Thorat' via TensorFlow.js Discussion <tf...@tensorflow.org>
Sent: Wednesday, May 30, 2018 2:58:43 AM
To: jeremy...@gmail.com
Cc: nkats...@gmail.com; TensorFlow.js Discussion
Subject: Re: Nodejs vs python performance differences?
 

Loreto Parisi

unread,
May 30, 2018, 2:51:18 AM5/30/18
to Nikhil Thorat, jeremy...@gmail.com, nkats...@gmail.com, TensorFlow.js Discussion
I recently came across to this promising benchmark from a tfjs user on twitter...
Image


From: 'Nikhil Thorat' via TensorFlow.js Discussion <tf...@tensorflow.org>
Sent: Wednesday, May 30, 2018 2:58:43 AM
To: jeremy...@gmail.com
Cc: nkats...@gmail.com; TensorFlow.js Discussion
Subject: Re: Nodejs vs python performance differences?
 

Nikos

unread,
May 30, 2018, 2:56:02 AM5/30/18
to TensorFlow.js Discussion
wow I'm so tempted to tweet and linkedIn this, people seem to think, including myself that python is faster for ML.


On Saturday, May 26, 2018 at 6:14:20 AM UTC+1, Jeremy Chone wrote:

Loreto Parisi

unread,
May 30, 2018, 3:10:05 AM5/30/18
to Nikos, TensorFlow.js Discussion
So, in production system I’m actually using Java or C++ bindings to Node.js or child_process for Tensorflow and other C++ ML libraries. Recent versions of TF had a great improvement in Java bindings and there is no reason to wrap python bindings into production systems typically built with enterprise platforms. So I think TFJs and its Swift counterpart (IBM did an amazing Swift HTTP server) are extremely powerful tools for the ML Life Cycle for production systems.
Can’t wait to have a stable npm version to integrate our current models like Tensor2Tensor and Transformers!


From: Nikos <nkats...@gmail.com>
Sent: Wednesday, May 30, 2018 8:56:01 AM
To: TensorFlow.js Discussion

Subject: Re: Nodejs vs python performance differences?
--
You received this message because you are subscribed to the Google Groups "TensorFlow.js Discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to tfjs+uns...@tensorflow.org.
Visit this group at https://groups.google.com/a/tensorflow.org/group/tfjs/.

Nikos

unread,
May 30, 2018, 6:01:17 AM5/30/18
to TensorFlow.js Discussion, nsth...@google.com, jeremy...@gmail.com, nkats...@gmail.com
Can you share the tweet?
To unsubscribe from this group and all its topics, send an email to tfjs+un...@tensorflow.org.

Loreto Parisi

unread,
May 30, 2018, 6:11:58 AM5/30/18
to TensorFlow.js Discussion, nsth...@google.com, jeremy...@gmail.com, nkats...@gmail.com

Jeremy Chone

unread,
May 31, 2018, 7:45:46 PM5/31/18
to Nikhil Thorat, Nikos Katsikanis, tf...@tensorflow.org
Thanks. 

Yes, did the test during training and at the end and I am getting a very similar result. 

tfjs-node: 
training step 0, training accuracy: 0.18 (0.1s)
training step 100, training accuracy: 0.92 (2.1s)
training step 200, training accuracy: 0.94 (2.1s)
training step 300, training accuracy: 1 (2s)
training step 400, training accuracy: 0.92 (2s)
training step 500, training accuracy: 0.98 (2s)
training step 600, training accuracy: 0.94 (2s)
training step 700, training accuracy: 0.98 (2s)
training step 800, training accuracy: 0.92 (2s)
training step 900, training accuracy: 0.98 (2s)

Test set accuracy (batch 1000): 97.00%


python: 
step 0, training accuracy 0.14 (0s)
step 100, training accuracy 0.88 (8s)
step 200, training accuracy 0.98 (8s)
step 300, training accuracy 0.94 (8s)
step 400, training accuracy 0.92 (8s)
step 500, training accuracy 0.96 (8s)
step 600, training accuracy 0.96 (8s)
step 700, training accuracy 0.96 (8s)
step 800, training accuracy 1 (8s)
step 900, training accuracy 0.96 (8s)

test accuracy 0.9665

---
Jeremy Chone
CEO & Principal Architect
http://britesnow.com/
(415) 699 9912
Dev Team As a Service 


Loreto Parisi

unread,
Jun 5, 2018, 2:18:20 PM6/5/18
to TensorFlow.js Discussion, nsth...@google.com, nkats...@gmail.com, jeremy...@gmail.com
hat is a huge result, thanks!
Reply all
Reply to author
Forward
0 new messages