summaryrefslogtreecommitdiff
path: root/gpt2
diff options
context:
space:
mode:
authorJonas Knobloch <jonas.knobloch@t-online.de>2026-04-04 22:33:22 +0200
committerJonas Knobloch <jonas.knobloch@t-online.de>2026-04-04 22:33:22 +0200
commit9349bdb0c5168caaa20e9a3df932a0c926592374 (patch)
tree3c94eb738a7e1b3a333871674a1624007613d975 /gpt2
parent60b71d9f78895d78a641b1109e2b0ca293835698 (diff)
Bind either logits or log probs
Diffstat (limited to 'gpt2')
-rw-r--r--gpt2/allocator.go34
-rw-r--r--gpt2/model.go2
2 files changed, 14 insertions, 22 deletions
diff --git a/gpt2/allocator.go b/gpt2/allocator.go
index 818fafc..575fac5 100644
--- a/gpt2/allocator.go
+++ b/gpt2/allocator.go
@@ -40,18 +40,14 @@ func (a *Allocator) InputNames() []string {
}
func (a *Allocator) OutputNames() []string {
- capacity := 1 + 2*a.config.nLayers
-
- if a.withLogProbs {
- capacity++
- }
+ capacity := 2*a.config.nLayers + 1
names := make([]string, 0, capacity)
- names = append(names, "logits")
-
if a.withLogProbs {
names = append(names, "log_probs")
+ } else {
+ names = append(names, "logits")
}
if a.withCache {
@@ -141,28 +137,24 @@ func (a *Allocator) initInputs(tokens []int64) error {
func (a *Allocator) initOutputs(tokens []int64) error {
capacity := 1
- if a.withLogProbs {
- capacity++
- }
-
if a.withCache {
capacity += 2 * a.config.nLayers
}
names := make([]string, 0, capacity)
- if err := a.logits(tokens, false); err != nil {
- return err
- }
-
- names = append(names, "logits")
-
if a.withLogProbs {
if err := a.logProbs(tokens, false); err != nil {
return err
}
names = append(names, "log_probs")
+ } else {
+ if err := a.logits(tokens, false); err != nil {
+ return err
+ }
+
+ names = append(names, "logits")
}
if !a.withCache {
@@ -205,14 +197,14 @@ func (a *Allocator) Step(token int64) error {
return err
}
- if err := a.logits(tokens, true); err != nil {
- return err
- }
-
if a.withLogProbs {
if err := a.logProbs(tokens, true); err != nil {
return err
}
+ } else {
+ if err := a.logits(tokens, true); err != nil {
+ return err
+ }
}
for i := range int64(a.config.nLayers) {
diff --git a/gpt2/model.go b/gpt2/model.go
index dd18c80..87a7e09 100644
--- a/gpt2/model.go
+++ b/gpt2/model.go
@@ -175,7 +175,7 @@ func (m *Model) Score(tokens []int64, logProbs *[]float32) error {
if logProbs != nil {
_, outputs := m.allocator.Outputs()
- d := outputs[1].(*ort.Tensor[float32]).GetData()
+ d := outputs[0].(*ort.Tensor[float32]).GetData()
*logProbs = append(*logProbs, d...)
}