Skip to content

Py vs R implementations of torch: speed benchmarking #1435

Description

@Artur-man

Hello there,

I am new to torch and mostly program R. I am interested in the performance differences between this implementation and pytorch.

I did a quick benchmarking with the bench/nn-small.R here: https://github.com/Artur-man/py_r_torch_benchmarking. It seems local GPU accelerates quite well, but there is a small performance gap between languages. I would really love to get your opinion on this, is it expected ?

(py_r_torch_benchmarking) LANDTHALER57:py_r_torch_benchmarking amanuky$ python benchmark_device_simple/benchmark_device_simple.py 
{'load': 0.0013628005981445312, 'setup': 0.0018796920776367188, 'mps': 1.6316609382629395, 'cpu': 6.573911190032959}
{'load': 0.0011260509490966797, 'setup': 0.0017371177673339844, 'mps': 1.5132861137390137, 'cpu': 6.622015953063965}
{'load': 0.0011050701141357422, 'setup': 0.002045869827270508, 'mps': 1.5158348083496094, 'cpu': 6.62052583694458}
{'load': 0.0010769367218017578, 'setup': 0.0025539398193359375, 'mps': 1.518923044204712, 'cpu': 6.630447149276733}
{'load': 0.001125335693359375, 'setup': 0.002821207046508789, 'mps': 1.5086002349853516, 'cpu': 6.6927337646484375}
(py_r_torch_benchmarking) LANDTHALER57:py_r_torch_benchmarking amanuky$ Rscript benchmark_device_simple/benchmark_device_simple.R
  mps   cpu  load setup 
 1.77  9.83  0.00  0.07 
  mps   cpu  load setup 
 1.68  9.74  0.00  0.08 
  mps   cpu  load setup 
 1.78  9.73  0.00  0.07 
  mps   cpu  load setup 
 1.76  9.61  0.00  0.07 
  mps   cpu  load setup 
 1.77  9.80  0.00  0.07 
It seems there is native mps/cuda support in torch without python thats nice .... and it accelerates the model as much as the python version does. It is a bit small though but not surprising.

Note: I also left a short forum entry here, would love to know more about dev's opinion on mlverse/torch vs PyTorch:
https://forum.posit.co/t/torch-vs-pytorch/210730

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions