Binozo Binozo commited on
Commit
5b36f0b
·
unverified ·
1 Parent(s): aa93432

go : add temperature options (#2417)

Browse files

* Fixed go cuda bindings building

* Added note to go bindings Readme to build using cuda support

* Added temperature bindings for Go

---------

Co-authored-by: Binozo <[email protected]>

bindings/go/params.go CHANGED
@@ -131,6 +131,16 @@ func (p *Params) SetEntropyThold(t float32) {
131
  p.entropy_thold = C.float(t)
132
  }
133
 
 
 
 
 
 
 
 
 
 
 
134
  // Set initial prompt
135
  func (p *Params) SetInitialPrompt(prompt string) {
136
  p.initial_prompt = C.CString(prompt)
@@ -162,6 +172,8 @@ func (p *Params) String() string {
162
  str += fmt.Sprintf(" audio_ctx=%d", p.audio_ctx)
163
  str += fmt.Sprintf(" initial_prompt=%s", C.GoString(p.initial_prompt))
164
  str += fmt.Sprintf(" entropy_thold=%f", p.entropy_thold)
 
 
165
  str += fmt.Sprintf(" beam_size=%d", p.beam_search.beam_size)
166
  if p.translate {
167
  str += " translate"
 
131
  p.entropy_thold = C.float(t)
132
  }
133
 
134
+ func (p *Params) SetTemperature(t float32) {
135
+ p.temperature = C.float(t)
136
+ }
137
+
138
+ // Sets the fallback temperature incrementation
139
+ // Pass -1.0 to disable this feature
140
+ func (p *Params) SetTemperatureFallback(t float32) {
141
+ p.temperature_inc = C.float(t)
142
+ }
143
+
144
  // Set initial prompt
145
  func (p *Params) SetInitialPrompt(prompt string) {
146
  p.initial_prompt = C.CString(prompt)
 
172
  str += fmt.Sprintf(" audio_ctx=%d", p.audio_ctx)
173
  str += fmt.Sprintf(" initial_prompt=%s", C.GoString(p.initial_prompt))
174
  str += fmt.Sprintf(" entropy_thold=%f", p.entropy_thold)
175
+ str += fmt.Sprintf(" temperature=%f", p.temperature)
176
+ str += fmt.Sprintf(" temperature_inc=%f", p.temperature_inc)
177
  str += fmt.Sprintf(" beam_size=%d", p.beam_search.beam_size)
178
  if p.translate {
179
  str += " translate"
bindings/go/pkg/whisper/context.go CHANGED
@@ -140,6 +140,17 @@ func (context *context) SetEntropyThold(t float32) {
140
  context.params.SetEntropyThold(t)
141
  }
142
 
 
 
 
 
 
 
 
 
 
 
 
143
  // Set initial prompt
144
  func (context *context) SetInitialPrompt(prompt string) {
145
  context.params.SetInitialPrompt(prompt)
 
140
  context.params.SetEntropyThold(t)
141
  }
142
 
143
+ // Set Temperature
144
+ func (context *context) SetTemperature(t float32) {
145
+ context.params.SetTemperature(t)
146
+ }
147
+
148
+ // Set the fallback temperature incrementation
149
+ // Pass -1.0 to disable this feature
150
+ func (context *context) SetTemperatureFallback(t float32) {
151
+ context.params.SetTemperatureFallback(t)
152
+ }
153
+
154
  // Set initial prompt
155
  func (context *context) SetInitialPrompt(prompt string) {
156
  context.params.SetInitialPrompt(prompt)
bindings/go/pkg/whisper/interface.go CHANGED
@@ -38,20 +38,22 @@ type Context interface {
38
  IsMultilingual() bool // Return true if the model is multilingual.
39
  Language() string // Get language
40
 
41
- SetOffset(time.Duration) // Set offset
42
- SetDuration(time.Duration) // Set duration
43
- SetThreads(uint) // Set number of threads to use
44
- SetSplitOnWord(bool) // Set split on word flag
45
- SetTokenThreshold(float32) // Set timestamp token probability threshold
46
- SetTokenSumThreshold(float32) // Set timestamp token sum probability threshold
47
- SetMaxSegmentLength(uint) // Set max segment length in characters
48
- SetTokenTimestamps(bool) // Set token timestamps flag
49
- SetMaxTokensPerSegment(uint) // Set max tokens per segment (0 = no limit)
50
- SetAudioCtx(uint) // Set audio encoder context
51
- SetMaxContext(n int) // Set maximum number of text context tokens to store
52
- SetBeamSize(n int) // Set Beam Size
53
- SetEntropyThold(t float32) // Set Entropy threshold
54
- SetInitialPrompt(prompt string) // Set initial prompt
 
 
55
 
56
  // Process mono audio data and return any errors.
57
  // If defined, newly generated segments are passed to the
 
38
  IsMultilingual() bool // Return true if the model is multilingual.
39
  Language() string // Get language
40
 
41
+ SetOffset(time.Duration) // Set offset
42
+ SetDuration(time.Duration) // Set duration
43
+ SetThreads(uint) // Set number of threads to use
44
+ SetSplitOnWord(bool) // Set split on word flag
45
+ SetTokenThreshold(float32) // Set timestamp token probability threshold
46
+ SetTokenSumThreshold(float32) // Set timestamp token sum probability threshold
47
+ SetMaxSegmentLength(uint) // Set max segment length in characters
48
+ SetTokenTimestamps(bool) // Set token timestamps flag
49
+ SetMaxTokensPerSegment(uint) // Set max tokens per segment (0 = no limit)
50
+ SetAudioCtx(uint) // Set audio encoder context
51
+ SetMaxContext(n int) // Set maximum number of text context tokens to store
52
+ SetBeamSize(n int) // Set Beam Size
53
+ SetEntropyThold(t float32) // Set Entropy threshold
54
+ SetInitialPrompt(prompt string) // Set initial prompt
55
+ SetTemperature(t float32) // Set temperature
56
+ SetTemperatureFallback(t float32) // Set temperature incrementation
57
 
58
  // Process mono audio data and return any errors.
59
  // If defined, newly generated segments are passed to the