Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
912049d
Added autogenerated classes which create observable streams of TorchS…
ncguilbeault Oct 8, 2025
7261825
Added learning rate schedulers
ncguilbeault Oct 8, 2025
eefefea
Updated with improved naming
ncguilbeault Oct 9, 2025
7aecc5d
Adding changes which include renaming files and improving doc strings
ncguilbeault Oct 14, 2025
20d4cea
Added XmlIgnore attribute to device property on modules
ncguilbeault Oct 15, 2025
96e5611
Added operator to explicitly allow setting the modules training mode
ncguilbeault Nov 1, 2025
bc1e4bb
Updated forward method to handle both `Module` and `ScriptModule` types
ncguilbeault Nov 10, 2025
7457b0b
Testing inference expression builder
ncguilbeault Nov 20, 2025
a7d3a62
Organized modules into categories that better describe the module's f…
ncguilbeault Dec 3, 2025
8c0a1b2
Added correctly typed overloads to loading/saving modules and to sett…
ncguilbeault Dec 3, 2025
f11a427
Added a type converter for converting module operator classes
ncguilbeault Dec 3, 2025
6c4fe96
Added an abstract class for module combinator builders
ncguilbeault Dec 3, 2025
349b4f5
Added a convolution module builder class and modified convolution mod…
ncguilbeault Dec 3, 2025
d84c277
Added module combinator property descriptor and updated builder to co…
ncguilbeault Dec 4, 2025
de16d5d
Added operator to collect module parameters
ncguilbeault Dec 4, 2025
1b3fa2a
Updated convolution module builder
ncguilbeault Dec 4, 2025
a5f5d80
Refactored sequential container to only support inputs instead of usi…
ncguilbeault Dec 4, 2025
32ad837
Added pooling module builder
ncguilbeault Dec 4, 2025
2d2a1a5
Updated modules to support module combinator builder pattern
ncguilbeault Dec 8, 2025
0a22aaa
Fixed issue with `TransformerDecoder` and `TransformerEncoder` module…
ncguilbeault Jan 15, 2026
b3da5e7
Refactored modules into `ActivationFunction` namespace and changed to…
ncguilbeault Jan 15, 2026
8d3b49f
Refactored module builders to use name of builder
ncguilbeault Jan 15, 2026
cfd257e
Refactored forward method into a builder class to support derived mod…
ncguilbeault Jan 15, 2026
5c8904f
Refactored `LoadModule` into builder class to support derived modules
ncguilbeault Jan 16, 2026
e9f4d09
Updated modules to return derived class which allows easy access to m…
ncguilbeault Jan 19, 2026
aa457e5
Refactored save module into a builder class and renamed to save modul…
ncguilbeault Jan 29, 2026
18d8107
Added operator to merge derived modules into a common module base cla…
ncguilbeault Jan 29, 2026
291d6a1
Updated base module builder class to set argument range
ncguilbeault Feb 2, 2026
f2cc9bf
Updated to support correct sink behavior
ncguilbeault Feb 2, 2026
a11b3de
Fixed sequential container to correctly receive input from `MergeModu…
ncguilbeault Feb 2, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions src/Bonsai.ML.Torch/NeuralNets/ActivationFunction/Celu.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
using System;
using System.ComponentModel;
using System.Reactive.Linq;
using static TorchSharp.torch;
using static TorchSharp.torch.nn;

namespace Bonsai.ML.Torch.NeuralNets.ActivationFunction;

/// <summary>
/// Represents an operator that creates a continuously differentiable exponential linear unit (CELU) activation function.
/// </summary>
/// <remarks>
/// See <see href="https://pytorch.org/docs/stable/generated/torch.nn.CELU.html"/> for more information.
/// </remarks>
[Description("Creates a continuously differentiable exponential linear unit (CELU) activation function.")]
[DisplayName("CELU")]

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have on occasion changed the display name for dynamic operators, but usually I try to avoid doing it for casing reasons, since on XML the actual class name will persist, and may create confusion between diffs and the visual editor.

I do agree this is a strange acronym, I looked elsewhere and couldn't find a better name, but would still keep the C# naming conventions.

public class Celu
{
/// <summary>
/// The alpha value for the CELU activation function.
/// </summary>
[Description("The alpha value for the CELU activation function.")]
public double Alpha { get; set; } = 1D;

/// <summary>
/// If set to true, will do this operation in-place.
/// </summary>
[Description("If set to true, will do this operation in-place.")]
public bool Inplace { get; set; } = false;

/// <summary>
/// Creates a continuously differentiable exponential linear unit (CELU) module.
/// </summary>
/// <returns></returns>
public IObservable<TorchSharp.Modules.CELU> Process()
{
return Observable.Return(CELU(Alpha, Inplace));
}

/// <summary>
/// Creates a continuously differentiable exponential linear unit (CELU) module.
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="source"></param>
/// <returns></returns>
public IObservable<TorchSharp.Modules.CELU> Process<T>(IObservable<T> source)
{
return source.Select(_ => CELU(Alpha, Inplace));
}
}
50 changes: 50 additions & 0 deletions src/Bonsai.ML.Torch/NeuralNets/ActivationFunction/Elu.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
using System;
using System.ComponentModel;
using System.Reactive.Linq;
using static TorchSharp.torch;
using static TorchSharp.torch.nn;

namespace Bonsai.ML.Torch.NeuralNets.ActivationFunction;

/// <summary>
/// Represents an operator that creates an exponential linear unit (ELU) activation function.
/// </summary>
/// <remarks>
/// See <see href="https://pytorch.org/docs/stable/generated/torch.nn.ELU.html"/> for more information.
/// </remarks>
[Description("Creates an exponential linear unit (ELU) activation function.")]
[DisplayName("ELU")]

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment as above.

public class Elu
{
/// <summary>
/// The alpha value for the ELU activation function.
/// </summary>
[Description("The alpha value for the ELU activation function")]
public double Alpha { get; set; } = 1D;

/// <summary>
/// If set to true, will do this operation in-place.
/// </summary>
[Description("If set to true, will do this operation in-place")]
public bool Inplace { get; set; } = false;

/// <summary>
/// Creates an exponential linear unit (ELU) module.
/// </summary>
/// <returns></returns>
public IObservable<TorchSharp.Modules.ELU> Process()
{
return Observable.Return(ELU(Alpha, Inplace));
}

/// <summary>
/// Creates an exponential linear unit (ELU) module.
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="source"></param>
/// <returns></returns>
public IObservable<TorchSharp.Modules.ELU> Process<T>(IObservable<T> source)
{
return source.Select(_ => ELU(Alpha, Inplace));
}
}
44 changes: 44 additions & 0 deletions src/Bonsai.ML.Torch/NeuralNets/ActivationFunction/Gelu.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
using System;
using System.ComponentModel;
using System.Reactive.Linq;
using static TorchSharp.torch;
using static TorchSharp.torch.nn;

namespace Bonsai.ML.Torch.NeuralNets.ActivationFunction;

/// <summary>
/// Represents an operator that creates a gaussian error linear unit (GELU) activation function.
/// </summary>
/// <remarks>
/// See <see href="https://pytorch.org/docs/stable/generated/torch.nn.GELU.html"/> for more information.
/// </remarks>
[Description("Creates a gaussian error linear unit (GELU) activation function.")]
[DisplayName("GELU")]

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above.

public class Gelu
{
/// <summary>
/// If set to true, will do this operation in-place.
/// </summary>
[Description("If set to true, will do this operation in-place.")]
public bool InPlace { get; set; } = false;

/// <summary>
/// Creates a gaussian error linear unit (GELU) module.
/// </summary>
/// <returns></returns>
public IObservable<TorchSharp.Modules.GELU> Process()
{
return Observable.Return(GELU(InPlace));
}

/// <summary>
/// Creates a gaussian error linear unit (GELU) module.
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="source"></param>
/// <returns></returns>
public IObservable<TorchSharp.Modules.GELU> Process<T>(IObservable<T> source)
{
return source.Select(_ => GELU(InPlace));
}
}
44 changes: 44 additions & 0 deletions src/Bonsai.ML.Torch/NeuralNets/ActivationFunction/Glu.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
using System;
using System.ComponentModel;
using System.Reactive.Linq;
using static TorchSharp.torch;
using static TorchSharp.torch.nn;

namespace Bonsai.ML.Torch.NeuralNets.ActivationFunction;

/// <summary>
/// Represents an operator that creates a gated linear unit (GLU) module.
/// </summary>
/// <remarks>
/// See <see href="https://pytorch.org/docs/stable/generated/torch.nn.GLU.html"/> for more information.
/// </remarks>
[Description("Creates a gated linear unit (GLU) module.")]
[DisplayName("GLU")]
public class Glu

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above. Alternatively, we could emulate our decision in the Torch package and simply expand all acronyms into their full long names to favor readability, as these acronyms are impenetrable to cursory reading, and easily confused with each other.

{
/// <summary>
/// The dimension on which to split the input tensor.
/// </summary>
[Description("The dimension on which to split the input tensor.")]
public long Dim { get; set; } = -1;

/// <summary>
/// Creates a gated linear unit (GLU) module.
/// </summary>
/// <returns></returns>
public IObservable<TorchSharp.Modules.GLU> Process()
{
return Observable.Return(GLU(Dim));
}

/// <summary>
/// Creates a gated linear unit (GLU) module.
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="source"></param>
/// <returns></returns>
public IObservable<TorchSharp.Modules.GLU> Process<T>(IObservable<T> source)
{
return source.Select(_ => GLU(Dim));
}
}
43 changes: 43 additions & 0 deletions src/Bonsai.ML.Torch/NeuralNets/ActivationFunction/Hardshrink.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
using System;
using System.ComponentModel;
using System.Reactive.Linq;
using static TorchSharp.torch;
using static TorchSharp.torch.nn;

namespace Bonsai.ML.Torch.NeuralNets.ActivationFunction;

/// <summary>
/// Represents an operator that creates a Hardshrink module.
/// </summary>
/// <remarks>
/// See <see href="https://pytorch.org/docs/stable/generated/torch.nn.Hardshrink.html"/> for more information.
/// </remarks>
[Description("Creates a Hardshrink module.")]
public class Hardshrink
{
/// <summary>
/// The lambda parameter for the Hardshrink function.
/// </summary>
[Description("The lambda parameter for the Hardshrink function")]
public double Lambda { get; set; } = 0.5D;

/// <summary>
/// Creates a Hardshrink module.
/// </summary>
/// <returns></returns>
public IObservable<TorchSharp.Modules.Hardshrink> Process()
{
return Observable.Return(Hardshrink(Lambda));
}

/// <summary>
/// Creates a Hardshrink module.
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="source"></param>
/// <returns></returns>
public IObservable<TorchSharp.Modules.Hardshrink> Process<T>(IObservable<T> source)
{
return source.Select(_ => Hardshrink(Lambda));
}
}
43 changes: 43 additions & 0 deletions src/Bonsai.ML.Torch/NeuralNets/ActivationFunction/Hardsigmoid.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
using System;
using System.ComponentModel;
using System.Reactive.Linq;
using static TorchSharp.torch;
using static TorchSharp.torch.nn;

namespace Bonsai.ML.Torch.NeuralNets.ActivationFunction;

/// <summary>
/// Represents an operator that creates a Hardsigmoid module.
/// </summary>
/// <remarks>
/// See <see href="https://pytorch.org/docs/stable/generated/torch.nn.Hardsigmoid.html"/> for more information.
/// </remarks>
[Description("Creates a Hardsigmoid module.")]
public class Hardsigmoid
{
/// <summary>
/// If set to true, will do this operation in-place.
/// </summary>
[Description("If set to true, will do this operation in-place")]
public bool Inplace { get; set; } = false;

/// <summary>
/// Creates a Hardsigmoid module.
/// </summary>
/// <returns></returns>
public IObservable<TorchSharp.Modules.Hardsigmoid> Process()
{
return Observable.Return(Hardsigmoid(Inplace));
}

/// <summary>
/// Creates a Hardsigmoid module.
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="source"></param>
/// <returns></returns>
public IObservable<TorchSharp.Modules.Hardsigmoid> Process<T>(IObservable<T> source)
{
return source.Select(_ => Hardsigmoid(Inplace));
}
}
43 changes: 43 additions & 0 deletions src/Bonsai.ML.Torch/NeuralNets/ActivationFunction/Hardswish.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
using System;
using System.ComponentModel;
using System.Reactive.Linq;
using static TorchSharp.torch;
using static TorchSharp.torch.nn;

namespace Bonsai.ML.Torch.NeuralNets.ActivationFunction;

/// <summary>
/// Represents an operator that creates a Hardswish module.
/// </summary>
/// <remarks>
/// See <see href="https://pytorch.org/docs/stable/generated/torch.nn.Hardswish.html"/> for more information.
/// </remarks>
[Description("Creates a Hardswish module.")]
public class Hardswish
{
/// <summary>
/// If set to true, will do this operation in-place.
/// </summary>
[Description("If set to true, will do this operation in-place")]
public bool Inplace { get; set; } = false;

/// <summary>
/// Creates a Hardswish module.
/// </summary>
/// <returns></returns>
public IObservable<TorchSharp.Modules.Hardswish> Process()
{
return Observable.Return(Hardswish(Inplace));
}

/// <summary>
/// Creates a Hardswish module.
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="source"></param>
/// <returns></returns>
public IObservable<TorchSharp.Modules.Hardswish> Process<T>(IObservable<T> source)
{
return source.Select(_ => Hardswish(Inplace));
}
}
55 changes: 55 additions & 0 deletions src/Bonsai.ML.Torch/NeuralNets/ActivationFunction/Hardtanh.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
using System;
using System.ComponentModel;
using System.Reactive.Linq;
using static TorchSharp.torch;
using static TorchSharp.torch.nn;

namespace Bonsai.ML.Torch.NeuralNets.ActivationFunction;

/// <summary>
/// Represents an operator that creates a Hardtanh module.
/// </summary>
/// <remarks>
/// See <see href="https://pytorch.org/docs/stable/generated/torch.nn.Hardtanh.html"/> for more information.
/// </remarks>
[Description("Creates a Hardtanh module.")]
public class Hardtanh
{
/// <summary>
/// The minimum value of the linear region range.
/// </summary>
[Description("The minimum value of the linear region range.")]
public double MinVal { get; set; } = -1D;

/// <summary>
/// The maximum value of the linear region range.
/// </summary>
[Description("The maximum value of the linear region range.")]
public double MaxVal { get; set; } = 1D;

/// <summary>
/// If set to true, will do this operation in-place.
/// </summary>
[Description("If set to true, will do this operation in-place")]
public bool Inplace { get; set; } = false;

/// <summary>
/// Creates a Hardtanh module.
/// </summary>
/// <returns></returns>
public IObservable<TorchSharp.Modules.Hardtanh> Process()
{
return Observable.Return(Hardtanh(MinVal, MaxVal, Inplace));
}

/// <summary>
/// Creates a Hardtanh module.
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="source"></param>
/// <returns></returns>
public IObservable<TorchSharp.Modules.Hardtanh> Process<T>(IObservable<T> source)
{
return source.Select(_ => Hardtanh(MinVal, MaxVal, Inplace));
}
}
Loading
Loading