Toro 0.2.2
Prefix Reserved
There is a newer version of this package available.
See the version list below for details.
See the version list below for details.
dotnet add package Toro --version 0.2.2
NuGet\Install-Package Toro -Version 0.2.2
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Toro" Version="0.2.2" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Toro" Version="0.2.2" />
<PackageReference Include="Toro" />
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Toro --version 0.2.2
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: Toro, 0.2.2"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Toro@0.2.2
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Toro&version=0.2.2
#tool nuget:?package=Toro&version=0.2.2
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
Toro
PyTorch semantics, idiomatic F#. Powered by TorchSharp.
Define models with F# records and computation expressions.
Chain fallible operations with the result { } CE.
Installation
dotnet add package Toro
dotnet add package Toro.NN
dotnet add package TorchSharp-cpu
Quick Example
Train a two-layer network on the XOR problem:
open Toro
open Toro.NN
let r = result {
let! x = Tensor.ofList ([ [ 0f; 0f ]; [ 0f; 1f ]; [ 1f; 0f ]; [ 1f; 1f ] ], Cpu)
let! y = Tensor.ofList ([ [ 0f ]; [ 1f ]; [ 1f ]; [ 0f ] ], Cpu)
let! l1 = Linear.init 2 16 F32 Cpu
let! l2 = Linear.init 16 1 F32 Cpu
let model = sequential { l1; Relu; l2 }
let! opt = AdamW.createWithLr 0.01 (Model.trainableVars model)
for epoch in 1..500 do
opt.zeroGrad ()
let! pred = model.forward x
let! loss = Loss.mse pred y
do! loss.backward ()
do! opt.step ()
if epoch % 100 = 0 then
printfn "epoch %d loss=%.6f" epoch (loss.item ())
}
Features
- Tensor API -- Create, reshape, index, and compute with tensors. Arithmetic operators return
Tensordirectly. Shape and math methods returnResult<Tensor, ToroError>. - Indexing --
t[0],t[0..2], andt.at [ I 1; S(0, 3) ]for advanced patterns. - Neural network layers -- Linear, Conv1d/Conv2d, Embedding, LSTM, GRU, BatchNorm, Dropout, LayerNorm, MultiHeadAttention, TransformerBlock.
- Composition --
sequential { }andpipeline { }CEs,>=>Kleisli operator to build models without casts. - Training -- SGD, AdamW optimizers. MSE, cross-entropy, NLL, binary cross-entropy loss functions.
- Error handling --
result { }CE withlet!/do!forResultchaining.
Examples
| Example | Description |
|---|---|
| LinearRegression | Gradient descent with raw tensors |
| SimpleTraining | XOR with sequential { } CE |
| MnistTraining | MLP on MNIST |
| MnistCnn | CNN with BatchNorm, Dropout, Kleisli composition |
| MnistAutoencoder | Autoencoder with image output |
| MnistGan | GAN image generation |
| CharRnn | Character-level text generation with LSTM |
| TextClassifier | Transformer-based text classification |
| SimpleGcn | GNN node classification with GCNConv |
| HubSentiment | Load DistilBERT from Hugging Face Hub |
Development
Build and run tests:
dotnet build
dotnet test
Preview the documentation site locally:
cd docs
pnpm install
pnpm dev
License
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
net10.0
- FSharp.Core (>= 10.1.302)
- TorchSharp (>= 0.107.0)
NuGet packages (4)
Showing the top 4 NuGet packages that depend on Toro:
| Package | Downloads |
|---|---|
|
Toro.NN
Neural network building blocks for Toro |
|
|
Toro.GNN
Graph Neural Network layers for Toro |
|
|
Toro.Vision
Image transforms for Toro |
|
|
Toro.Text
Text tokenization bridge between Microsoft.ML.Tokenizers and Toro |
GitHub repositories
This package is not used by any popular GitHub repositories.