mirror of
https://github.com/ollama/ollama.git
synced 2026-11-12 03:46:14 -06:00
nn.go held every layer type in the package apart from attention, recurrence and rope: the Linear and Embedding interfaces with their dense and quantized types, Conv1d, RMSNorm, LayerNorm and MultiLinear, with one test file to match. Finding a layer meant scanning the file named after the package. Each layer kind gets its own file: linear.go and embedding.go hold the interface and the dense and quantized types, conv.go, norm.go and multilinear.go take the rest, and nn_test.go splits the same way. The Layer and MultiLinearLayer interfaces go; nothing implemented or accepted them. No code changes otherwise.
38 lines
708 B
Go
38 lines
708 B
Go
package nn
|
|
|
|
import "github.com/ollama/ollama/mlx"
|
|
|
|
// Conv1d applies 1D convolution over NLC input.
|
|
type Conv1d struct {
|
|
Weight *mlx.Array
|
|
Bias *mlx.Array
|
|
Stride int32
|
|
Padding int32
|
|
Dilation int32
|
|
Groups int32
|
|
}
|
|
|
|
func NewConv1d(weight, bias *mlx.Array, stride, padding, dilation, groups int32) *Conv1d {
|
|
if stride <= 0 {
|
|
stride = 1
|
|
}
|
|
if dilation <= 0 {
|
|
dilation = 1
|
|
}
|
|
if groups <= 0 {
|
|
groups = 1
|
|
}
|
|
return &Conv1d{
|
|
Weight: weight,
|
|
Bias: bias,
|
|
Stride: stride,
|
|
Padding: padding,
|
|
Dilation: dilation,
|
|
Groups: groups,
|
|
}
|
|
}
|
|
|
|
func (c *Conv1d) Forward(x *mlx.Array) *mlx.Array {
|
|
return mlx.Conv1d(x, c.Weight, c.Bias, c.Stride, c.Padding, c.Dilation, c.Groups)
|
|
}
|