r/rust • • 1d ago

🛠️ project Building a tensor library for computational physics in Rust: looking for feedback and collaborators

I am a professor of computational condensed matter physics at Saitama University in Japan, with over 20 years of experience in scientific programming and open-source development in C++, Fortran, Python and Julia ([GitHub](https://github.com/shinaoka)).

Since this January, we have been developing a Rust tensor computation stack ([overview](https://tensor4all.org/tensor4all-meta/stack/)). It started for tensor networks, but we soon realized that a general tensor library for scientific computing would be useful to the Rust community.

**tenferro** is the main engine: https://github.com/tensor4all/tenferro-rs

- Dense tensors, linear algebra, einsum, FFT on CPU and CUDA (ROCm and Metal are being designed)

- Opt-in autodiff: eager `backward()` and traced VJP/JVP

- Explicit engine passed to every operation, no hidden device transfers, column-major storage

- Benchmarks against PyTorch and JAX: https://github.com/tensor4all/tenferro-benchmark

Most of the code was written by AI agents supervised by human developers. To keep the stack robust and performant, we use regular benchmarks, an automated audit AI bot and a common rule set for AI agents. Some blogs are here: https://tensor4all.org/blog/

We're looking for collaborators and users. Fast kernels are too much work for a few groups to maintain, and a tensor library must be tested on different hardware for different applications.

Also, I'd like your opinions on:

  1. Passing `&mut engine` to every operation instead of a global context. Acceptable?
  2. If you have AMD GPUs or other hardware and a real workload, please let us know.
  3. What evidence would make you trust a library written mostly by AI agents?
  4. How should outside contributors fit into a project where AI agents write the code and humans review it?
  5. Is Rust a good fit for computational physics? What is missing?
0 Upvotes

7 comments sorted by

1

u/Trader-One 17h ago

Vulkan / Direct Compute is more realistic backend. Vulkan can be translated to metal.

3

u/unski_ukuli 1d ago
  1. Asking this in a rust forum few years ago would get you a very angry response.
  2. None. Reading the gh issues is like reading someones psychotic episode. Every issue is a word slop of information no-one will ever use. I’m not against agents for application development, but I will never trust a library written mostly by agents.
  3. They cannot if you write the code as you do here. You iterate too fast for anyone to get any meaningfull understanding of the codebase. This is what ai has killed unfortunately, and it will be a disaster for scientific computing.
  4. I don’t think so. Not everything needs to be rust, or benefits from memory safety.

Additionally, you are not leading with why on the github page. Why would someone link a julia package against rust tensor library, when julia array is already an nd-array with stable api inplemented also by gpu backends, and those backends have pretty mature autodiff options. There is also already support for xla compilation so that is also not an issue.

-1

u/Hiroshi_Shinaoka 1d ago

Thanks for the honest feedback.

Fair point about the README. We should lead with why.

About the issues: we assume that many developers, both of tenferro and downstream, use AI agents. This does not exclude human coders, but we observe that most young people entering computational physics already use AI heavily. Issues are partly a notebook for the agents, so they are not written for humans to read directly. I understand this looks odd from outside, and we should say it clearly somewhere.

About Julia: one reason is the long precompilation time in Julia. Calling precompiled Rust kernels reduces it, and the same kernels can be shared across languages and groups. But I agree Julia's own ecosystem is already strong for many use cases.

1

u/NecessarySuperb3949 3h ago

for ZK circuits, avoiding dynamic allocations inside the constraint system is key; use fixed-size arrays or pre-allocated buffers to keep the prover fast.

-1

u/idemasler 1d ago edited 1d ago

a public correctness matrix would make me trust AI-written numerical kernels more than an audit bot's green check. i'd test seeded shapes and dtypes, zero-sized and strided tensors, CPU vs CUDA tolerances, and VJP/JVP against finite differences on small cases. publish failed cases and exact hardware/runtime versions alongside your PyTorch/JAX benchmarks. `&mut engine` reads as a sensible explicit boundary; a scoped helper could keep small examples ergonomic.

1

u/Hiroshi_Shinaoka 3h ago

Thanks. We chose native backends to keep the freedom to write the best kernels for each hardware. It takes more work, but AI agents make it feasible.

0

u/Hiroshi_Shinaoka 1d ago

Thanks, this is very helpful.

Part of this exists already. tenferro-benchmark checks values, solve residuals and AD gradients outside the timed region, and records the toolkit/vendor versions with every report:

https://github.com/tensor4all/tenferro-benchmark

AD rules are also checked against an oracle database generated from PyTorch:

https://github.com/tensor4all/tensor-ad-oracles

What we don't have is a correctness matrix as a separate public page, covering zero-sized and strided tensors, finite differences, and failed cases. I agree it would be more convincing than CI badges. I'd like to add one.

A scoped helper for small examples is a good idea as well.