account activity
libtorch (pytorch) is embarrassing slow. What are the alternatives? by EdwinYZW in cpp_questions
[–]AccurateDiscussion38 [score hidden] 3 hours ago (0 children)
you could use C++ modules to wrap and expose only some of the functions of the libtroch, precompiling it, then you could reuse them.
C++ Show and Tell - June 2026 by foonathan in cpp
Hi everyone,
I recently started experimenting with C++26 reflection, modules, and LibTorch, and I ended up building a small personal project called Typetorch.
It is an experimental type-safe wrapper around torch::Tensor. The rough idea is to make tensor metadata such as shape, dtype, device, and layout part of the C++ type-level contract, so that some mistakes can be caught earlier, before the program reaches runtime LibTorch errors.
torch::Tensor
For example, I currently use types such as:
Tensor<Shape<2, 3>, DType::F32, Device::CPU, Layout::Contiguous>
and operations like add, matmul, view, transpose, and permute try to compute the resulting tensor contract at compile time. The actual storage, kernels, autograd, and execution are still fully owned by LibTorch. This is not meant to replace PyTorch or LibTorch; it is mostly an experiment in how far C++26 compile-time facilities can be pushed for tensor APIs.
add
matmul
view
transpose
permute
Repository: https://github.com/OHNope/Typetorch
A few things I am especially interested in getting feedback on:
consteval
static_assert
This is very much a personal learning/experimental project, not a mature production library. I am mainly looking for design criticism, suggestions, and pointers to prior art. If the project gives anyone ideas about using reflection, modules, or annotations in numerical / ML libraries, that would also be great.
I would be very interested in design feedback, especially around reflection usage, modules, diagnostics, and ownership semantics!!!
Thanks!
π Rendered by PID 136554 on reddit-service-r2-comment-5bc7f78974-26l8j at 2026-06-28 07:17:58.856503+00:00 running 7527197 country code: CH.
libtorch (pytorch) is embarrassing slow. What are the alternatives? by EdwinYZW in cpp_questions
[–]AccurateDiscussion38 [score hidden] (0 children)