rope.go 1.07 KB
Newer Older
1
2
3
4
5
6
7
8
package rope

import "github.com/ollama/ollama/ml"

// Options contains optional parameters for RoPE function
type Options struct {
	Type                  int
	Factors               ml.Tensor
Michael Yang's avatar
Michael Yang committed
9
10
11
12
13
14
15
	OriginalContextLength int

	// YaRN options
	ExtrapolationFactor,
	AttentionFactor,
	BetaFast,
	BetaSlow float32
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
}

// WithOriginalContextLength sets a custom context length
func WithOriginalContextLength(n int) func(*Options) {
	return func(opts *Options) {
		opts.OriginalContextLength = n
	}
}

// WithType sets RoPE type to NeoX
func WithTypeNeoX() func(*Options) {
	return func(opts *Options) {
		opts.Type = 2
	}
}

// WithFactors sets custom rope factors
func WithFactors(factors ml.Tensor) func(*Options) {
	return func(opts *Options) {
		if factors != nil {
			opts.Factors = factors
		}
	}
}
Michael Yang's avatar
Michael Yang committed
40
41
42
43
44
45
46
47
48
49
50
51

func WithExtrapolationFactor(extrapolationFactor float32) func(*Options) {
	return func(opts *Options) {
		opts.ExtrapolationFactor = extrapolationFactor
	}
}

func WithAttentionFactor(attentionFactor float32) func(*Options) {
	return func(opts *Options) {
		opts.AttentionFactor = attentionFactor
	}
}