Ask HN: 用 Mojo 完全构建了一个张量 + 神经网络框架——求反馈?
1 分•作者: ratulb•6 个月前
Tenmo
一个用纯 Mojo 编写的轻量级张量库和神经网络框架。<p>https://github.com/ratulb/tenmo<p>Tenmo 专注于:<p>SIMD 优化
显式内存布局
零拷贝视图
一个极简但实用的自动求导系统
状态:Tenmo 与 Mojo 本身同步发展。
API 可能会更改。 尚未准备好用于生产。<p>性能
MNIST(4 层 MLP,10.5 万个参数,15 个 epoch)
平台 设备 平均每个 epoch 总时间 测试准确率
Tenmo CPU (Mojo) 11.4 秒 171 秒 97.44%
PyTorch CPU 14.5 秒 218 秒 98.26%
PyTorch GPU (Tesla T4) 15.2 秒 227 秒 97.87%
备注<p>Tenmo 在连续缓冲区上使用 SIMD 向量化内核。
MNIST 运行中未使用 BLAS — 所有操作都作为纯 Mojo 代码执行。
对于这种规模的模型,GPU 开销占主导地位;更大的模型将从 GPU 加速中获益更多。
快速示例
from testing import assert_true
from tenmo import Tensor<p>fn main() raises:
var a = Tensor.d1([1.0, 2.0, 3.0], requires_grad=True)<p><pre><code> var b = a * 2
var c = a * 3
var d = b + c
d.backward()
assert_true(a.grad().all_close(Tensor.d1([5.0, 5.0, 5.0])))
</code></pre>
非常欢迎反馈!
查看原文
Tenmo
A lightweight tensor library and neural network framework written in pure Mojo.<p>https://github.com/ratulb/tenmo<p>Tenmo focuses on:<p>SIMD-optimization
explicit memory layout
zero-copy views
a minimal but practical autograd system
Status: Tenmo evolves alongside Mojo itself.
APIs may change. Not production-ready yet.<p>Performance
MNIST (4-layer MLP, 105K params, 15 epochs)
Platform Device Avg Epoch Total Test Acc
Tenmo CPU (Mojo) 11.4s 171s 97.44%
PyTorch CPU 14.5s 218s 98.26%
PyTorch GPU (Tesla T4) 15.2s 227s 97.87%
Notes<p>Tenmo uses SIMD-vectorized kernels on contiguous buffers.
No BLAS was used in the MNIST run — everything executes as pure Mojo code.
GPU overhead dominates for models of this size; larger models benefit more from GPU acceleration.
Quick Example
from testing import assert_true
from tenmo import Tensor<p>fn main() raises:
var a = Tensor.d1([1.0, 2.0, 3.0], requires_grad=True)<p><pre><code> var b = a * 2
var c = a * 3
var d = b + c
d.backward()
assert_true(a.grad().all_close(Tensor.d1([5.0, 5.0, 5.0])))
</code></pre>
Feedback highly appreciated!